Skip to content

Commit 69476d6

Browse files
committed
feat: add @Property annotation to decouple class field names from property names
1 parent 726e898 commit 69476d6

7 files changed

Lines changed: 158 additions & 92 deletions

File tree

src/it/java/io/weaviate/containers/Weaviate.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,12 @@ public static Weaviate.Builder custom() {
9292
public static class Builder {
9393
private String versionTag;
9494
private Set<String> enableModules = new HashSet<>();
95-
private boolean telemetry;
9695

9796
private Map<String, String> environment = new HashMap<>();
9897

9998
public Builder() {
10099
this.versionTag = VERSION;
101-
this.telemetry = false;
100+
enableAutoSchema(false);
102101
}
103102

104103
public Builder withVersion(String version) {
@@ -143,6 +142,11 @@ public Builder enableTelemetry(boolean enable) {
143142
return this;
144143
}
145144

145+
public Builder enableAutoSchema(boolean enable) {
146+
environment.put("AUTOSCHEMA_ENABLED", Boolean.toString(!enable));
147+
return this;
148+
}
149+
146150
public Builder enableAnonymousAccess(boolean enable) {
147151
environment.put("AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED", Boolean.toString(enable));
148152
return this;

src/it/java/io/weaviate/integration/ORMITest.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
import io.weaviate.ConcurrentTest;
1414
import io.weaviate.client6.v1.api.WeaviateClient;
1515
import io.weaviate.client6.v1.api.collections.CollectionConfig;
16-
import io.weaviate.client6.v1.api.collections.Property;
1716
import io.weaviate.client6.v1.api.collections.WeaviateObject;
1817
import io.weaviate.client6.v1.api.collections.annotations.Collection;
18+
import io.weaviate.client6.v1.api.collections.annotations.Property;
1919
import io.weaviate.containers.Container;
2020

2121
public class ORMITest extends ConcurrentTest {
2222
private static WeaviateClient client = Container.WEAVIATE.getClient();
2323

24-
@Collection("Things")
24+
@Collection("ORMITest")
2525
static record Thing(
2626
// text / text[]
2727
String text,
@@ -39,39 +39,39 @@ static record Thing(
3939
List<UUID> uuidList,
4040

4141
// int / int[]
42-
short short_,
42+
@Property("short") short short_,
4343
Short shortBoxed,
4444
short[] shortArray,
4545
Short[] shortBoxedArray,
4646
List<Short> shortBoxedList,
4747

48-
int int_,
48+
@Property("int") int int_,
4949
Integer intBoxed,
5050
int[] intArray,
5151
Integer[] intBoxedArray,
5252
List<Integer> intBoxedList,
5353

54-
long long_,
54+
@Property("long") long long_,
5555
Long longBoxed,
5656
long[] longArray,
5757
Long[] longBoxedArray,
5858
List<Long> longBoxedList,
5959

6060
// number / number[]
61-
float float_,
61+
@Property("float") float float_,
6262
Float floatBoxed,
6363
float[] floatArray,
6464
Float[] floatBoxedArray,
6565
List<Float> floatBoxedList,
6666

67-
double double_,
67+
@Property("double") double double_,
6868
Double doubleBoxed,
6969
double[] doubleArray,
7070
Double[] doubleBoxedArray,
7171
List<Double> doubleBoxedList,
7272

7373
// boolean / boolean[]
74-
boolean boolean_,
74+
@Property("boolean") boolean boolean_,
7575
Boolean booleanBoxed,
7676
boolean[] booleanArray,
7777
Boolean[] booleanBoxedArray,
@@ -93,8 +93,9 @@ public void test_createCollection() throws Exception {
9393

9494
// Assert
9595
Assertions.assertThat(config).get()
96-
.returns("Things", CollectionConfig::collectionName)
97-
.extracting(CollectionConfig::properties, InstanceOfAssertFactories.list(Property.class))
96+
.returns("ORMITest", CollectionConfig::collectionName)
97+
.extracting(CollectionConfig::properties,
98+
InstanceOfAssertFactories.list(io.weaviate.client6.v1.api.collections.Property.class))
9899
.extracting(p -> Map.entry(
99100
p.propertyName(),
100101
p.dataTypes().get(0)))
@@ -111,37 +112,37 @@ public void test_createCollection() throws Exception {
111112
Map.entry("uuidArray", "uuid[]"),
112113
Map.entry("uuidList", "uuid[]"),
113114

114-
Map.entry("short_", "int"),
115+
Map.entry("short", "int"),
115116
Map.entry("shortBoxed", "int"),
116117
Map.entry("shortArray", "int[]"),
117118
Map.entry("shortBoxedArray", "int[]"),
118119
Map.entry("shortBoxedList", "int[]"),
119120

120-
Map.entry("int_", "int"),
121+
Map.entry("int", "int"),
121122
Map.entry("intBoxed", "int"),
122123
Map.entry("intArray", "int[]"),
123124
Map.entry("intBoxedArray", "int[]"),
124125
Map.entry("intBoxedList", "int[]"),
125126

126-
Map.entry("long_", "int"),
127+
Map.entry("long", "int"),
127128
Map.entry("longBoxed", "int"),
128129
Map.entry("longArray", "int[]"),
129130
Map.entry("longBoxedArray", "int[]"),
130131
Map.entry("longBoxedList", "int[]"),
131132

132-
Map.entry("float_", "number"),
133+
Map.entry("float", "number"),
133134
Map.entry("floatBoxed", "number"),
134135
Map.entry("floatArray", "number[]"),
135136
Map.entry("floatBoxedArray", "number[]"),
136137
Map.entry("floatBoxedList", "number[]"),
137138

138-
Map.entry("double_", "number"),
139+
Map.entry("double", "number"),
139140
Map.entry("doubleBoxed", "number"),
140141
Map.entry("doubleArray", "number[]"),
141142
Map.entry("doubleBoxedArray", "number[]"),
142143
Map.entry("doubleBoxedList", "number[]"),
143144

144-
Map.entry("boolean_", "boolean"),
145+
Map.entry("boolean", "boolean"),
145146
Map.entry("booleanBoxed", "boolean"),
146147
Map.entry("booleanArray", "boolean[]"),
147148
Map.entry("booleanBoxedArray", "boolean[]"),
@@ -221,4 +222,6 @@ public void test_insertAndQuery() throws Exception {
221222

222223
// TODO: add assertions;
223224
}
225+
226+
// TODO: insertMany (batch)
224227
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.weaviate.client6.v1.api.collections.annotations;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Retention(RetentionPolicy.RUNTIME)
9+
@Target(ElementType.FIELD)
10+
public @interface Property {
11+
String value();
12+
}

src/main/java/io/weaviate/client6/v1/internal/json/JSON.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.google.gson.GsonBuilder;
55
import com.google.gson.reflect.TypeToken;
66

7+
import io.weaviate.client6.v1.internal.orm.PropertyFieldNamingStrategy;
8+
79
public final class JSON {
810
private static final Gson gson;
911

@@ -42,6 +44,9 @@ public final class JSON {
4244
gsonBuilder.registerTypeAdapter(
4345
io.weaviate.client6.v1.api.collections.data.ReferenceAddManyResponse.class,
4446
io.weaviate.client6.v1.api.collections.data.ReferenceAddManyResponse.CustomJsonDeserializer.INSTANCE);
47+
48+
// ORM FieldNaminsStrategy ------------------------------------------------
49+
gsonBuilder.setFieldNamingStrategy(PropertyFieldNamingStrategy.INSTANCE);
4550
gson = gsonBuilder.create();
4651
}
4752

0 commit comments

Comments
 (0)