diff --git a/hugegraph-api/pom.xml b/hugegraph-api/pom.xml
index 51536b53c..f3070d533 100644
--- a/hugegraph-api/pom.xml
+++ b/hugegraph-api/pom.xml
@@ -86,7 +86,7 @@
- 0.44.0.0
+ 0.45.0.0
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/BatchAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/BatchAPI.java
index fc430a4a0..2fecbe8e8 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/BatchAPI.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/graph/BatchAPI.java
@@ -112,11 +112,16 @@ public class BatchAPI extends API {
for (Map.Entry kv : strategies.entrySet()) {
String key = kv.getKey();
UpdateStrategy updateStrategy = kv.getValue();
- if (oldElement.properties.get(key) != null) {
+ if (oldElement.properties.get(key) != null &&
+ newElement.properties.get(key) != null) {
Object value = updateStrategy.checkAndUpdateProperty(
oldElement.properties.get(key),
newElement.properties.get(key));
newElement.properties.put(key, value);
+ } else if (oldElement.properties.get(key) != null &&
+ newElement.properties.get(key) == null) {
+ // If new property is null & old is present, use old property
+ newElement.properties.put(key, oldElement.properties.get(key));
}
}
}
@@ -134,12 +139,16 @@ public class BatchAPI extends API {
String key = kv.getKey();
UpdateStrategy updateStrategy = kv.getValue();
if (oldElement.property(key).isPresent() &&
- newElement.properties.containsKey(key)) {
+ newElement.properties.get(key) != null) {
Object value = updateStrategy.checkAndUpdateProperty(
oldElement.property(key).value(),
newElement.properties.get(key));
value = g.propertyKey(key).convValue(value, false);
newElement.properties.put(key, value);
+ } else if (oldElement.property(key).isPresent() &&
+ newElement.properties.get(key) == null) {
+ // If new property is null & old is present, use old property
+ newElement.properties.put(key, oldElement.property(key).value());
}
}
}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/GraphsAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/GraphsAPI.java
index 429505c54..2e54e410e 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/GraphsAPI.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/GraphsAPI.java
@@ -66,7 +66,7 @@ public class GraphsAPI extends API {
@Context SecurityContext sc) {
Set graphs = manager.graphs();
String role = sc.getUserPrincipal().getName();
- if (role.equals("admin")) {
+ if ("admin".equals(role)) {
return ImmutableMap.of("graphs", graphs);
} else {
// Filter by user role
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/define/UpdateStrategy.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/define/UpdateStrategy.java
index f71739d36..deb314d28 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/define/UpdateStrategy.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/define/UpdateStrategy.java
@@ -139,6 +139,18 @@ public enum UpdateStrategy {
void checkPropertyType(Object oldProperty, Object newProperty) {
this.checkCollectionType(oldProperty, newProperty);
}
+ },
+
+ OVERRIDE {
+ @Override
+ Object updatePropertyValue(Object oldProperty, Object newProperty) {
+ return newProperty;
+ }
+
+ @Override
+ void checkPropertyType(Object oldProperty, Object newProperty) {
+ // Allow any type
+ }
};
abstract Object updatePropertyValue(Object oldProperty, Object newProperty);
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/license/LicenseVerifier.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/license/LicenseVerifier.java
index 567fff60e..6aaf302db 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/license/LicenseVerifier.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/license/LicenseVerifier.java
@@ -32,7 +32,6 @@ import com.baidu.hugegraph.HugeException;
import com.baidu.hugegraph.HugeGraph;
import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.core.GraphManager;
-import com.baidu.hugegraph.util.JsonUtil;
import com.baidu.hugegraph.util.Log;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -125,10 +124,10 @@ public class LicenseVerifier {
}
private static LicenseVerifyParam buildVerifyParam(String path) {
- InputStream stream = LicenseVerifier.class.getResourceAsStream(path);
// NOTE: can't use JsonUtil due to it bind tinkerpop jackson
ObjectMapper mapper = new ObjectMapper();
- try {
+ try (InputStream stream =
+ LicenseVerifier.class.getResourceAsStream(path)) {
return mapper.readValue(stream, LicenseVerifyParam.class);
} catch (IOException e) {
throw new HugeException("Failed to read json stream to %s",
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/version/ApiVersion.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/version/ApiVersion.java
index 173bdf238..e538f1eed 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/version/ApiVersion.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/version/ApiVersion.java
@@ -90,13 +90,14 @@ public final class ApiVersion {
* [0.40] Issue-523: Add source_in_ring args for rings RESTful API
* [0.41] Issue-493: Support batch updating properties by multiple strategy
* [0.42] Issue-176: Let gremlin error response consistent with RESTful's
- * [0.43] Issue-270 & 398: support shard-index and vertex + sortke prefix,
+ * [0.43] Issue-270 & 398: support shard-index and vertex + sortkey prefix,
* and split range to rangeInt, rangeFloat, rangeLong and rangeDouble
* [0.44] Issue-633: Support unique index
+ * [0.45] Issue-673: Add 'OVERRIDE' update strategy
*/
// The second parameter of Version.of() is for IDE running without JAR
- public static final Version VERSION = Version.of(ApiVersion.class, "0.44");
+ public static final Version VERSION = Version.of(ApiVersion.class, "0.45");
public static final void check() {
// Check version of hugegraph-core. Firstly do check from version 0.3
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java
index 2e8e81344..7d20646fa 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java
@@ -110,7 +110,7 @@ public final class CachedGraphTransaction extends GraphTransaction {
this.graph(), event);
event.checkArgs(String.class, Id.class);
Object[] args = event.args();
- if (args[0].equals("invalid")) {
+ if ("invalid".equals(args[0])) {
Id id = (Id) args[1];
if (this.verticesCache.get(id) != null) {
// Invalidate vertex cache
@@ -120,7 +120,7 @@ public final class CachedGraphTransaction extends GraphTransaction {
this.edgesCache.invalidate(id);
}
return true;
- } else if (args[0].equals("clear")) {
+ } else if ("clear".equals(args[0])) {
this.verticesCache.clear();
this.edgesCache.clear();
return true;
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedSchemaTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedSchemaTransaction.java
index db7d32ab4..2715b72c7 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedSchemaTransaction.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedSchemaTransaction.java
@@ -102,7 +102,7 @@ public final class CachedSchemaTransaction extends SchemaTransaction {
this.graph(), event);
event.checkArgs(String.class, Id.class);
Object[] args = event.args();
- if (args[0].equals("invalid")) {
+ if ("invalid".equals(args[0])) {
Id id = (Id) args[1];
Object value = this.idCache.get(id);
if (value != null) {
@@ -116,7 +116,7 @@ public final class CachedSchemaTransaction extends SchemaTransaction {
this.nameCache.invalidate(prefixedName);
}
return true;
- } else if (args[0].equals("clear")) {
+ } else if ("clear".equals(args[0])) {
this.idCache.clear();
this.nameCache.clear();
this.cachedTypes.clear();
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/EdgeId.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/EdgeId.java
index 7ceb89b13..7a6eab741 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/EdgeId.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/id/EdgeId.java
@@ -206,7 +206,8 @@ public class EdgeId implements Id {
String[] idParts = split(id);
if (!(idParts.length == 4 || idParts.length == 5)) {
throw new NotFoundException("Edge id must be formatted as 4~5 " +
- "parts, but got '%s'", id);
+ "parts, but got %s parts, '%s'",
+ idParts.length, id);
}
try {
if (idParts.length == 4) {
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SerializerFactory.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SerializerFactory.java
index 7b51ebad3..bf9ff7adb 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SerializerFactory.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/SerializerFactory.java
@@ -34,11 +34,11 @@ public class SerializerFactory {
public static AbstractSerializer serializer(String name) {
name = name.toLowerCase();
- if (name.equals("binary")) {
+ if ("binary".equals(name)) {
return new BinarySerializer();
- } else if (name.equals("binaryinline")) {
+ } else if ("binaryinline".equals(name)) {
return new BinaryInlineSerializer();
- } else if (name.equals("text")) {
+ } else if ("text".equals(name)) {
return new TextSerializer();
}
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendEntry.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendEntry.java
index 966cfe626..3ba24ef13 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendEntry.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendEntry.java
@@ -72,6 +72,7 @@ public interface BackendEntry extends Idfiable {
public HugeType type();
+ @Override
public Id id();
public Id subId();
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/PropertyKey.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/PropertyKey.java
index b5f3d3094..c3a75c627 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/PropertyKey.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/PropertyKey.java
@@ -278,7 +278,7 @@ public class PropertyKey extends SchemaElement implements Propfiable {
Builder asDate();
- Builder asUuid();
+ Builder asUUID();
Builder asBoolean();
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/PropertyKeyBuilder.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/PropertyKeyBuilder.java
index fdfc0a741..9dad1c1a8 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/PropertyKeyBuilder.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/schema/builder/PropertyKeyBuilder.java
@@ -166,7 +166,7 @@ public class PropertyKeyBuilder implements PropertyKey.Builder {
}
@Override
- public PropertyKeyBuilder asUuid() {
+ public PropertyKeyBuilder asUUID() {
this.dataType = DataType.UUID;
return this;
}
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeScriptTraversal.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeScriptTraversal.java
index 2aed83044..6c9d653b3 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeScriptTraversal.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeScriptTraversal.java
@@ -77,7 +77,7 @@ public final class HugeScriptTraversal extends DefaultTraversal {
bindings.putAll(this.bindings);
@SuppressWarnings("rawtypes")
- TraversalStrategy strategies[] = this.getStrategies().toList()
+ TraversalStrategy[] strategies = this.getStrategies().toList()
.toArray(new TraversalStrategy[0]);
bindings.put("g", this.factory.createTraversalSource(this.graph)
.withStrategies(strategies));
diff --git a/hugegraph-example/src/main/java/com/baidu/hugegraph/example/Example1.java b/hugegraph-example/src/main/java/com/baidu/hugegraph/example/Example1.java
index eee707978..560056f27 100644
--- a/hugegraph-example/src/main/java/com/baidu/hugegraph/example/Example1.java
+++ b/hugegraph-example/src/main/java/com/baidu/hugegraph/example/Example1.java
@@ -122,7 +122,7 @@ public class Example1 {
schema.propertyKey("lived").asText().create();
schema.propertyKey("country").asText().valueSet().create();
schema.propertyKey("city").asText().create();
- schema.propertyKey("sensor_id").asUuid().create();
+ schema.propertyKey("sensor_id").asUUID().create();
schema.propertyKey("versions").asInt().valueList().create();
LOG.info("=============== vertexLabel ================");
diff --git a/hugegraph-mysql/src/main/java/com/baidu/hugegraph/backend/store/mysql/MysqlSessions.java b/hugegraph-mysql/src/main/java/com/baidu/hugegraph/backend/store/mysql/MysqlSessions.java
index c8a2c19ca..9b723f63b 100644
--- a/hugegraph-mysql/src/main/java/com/baidu/hugegraph/backend/store/mysql/MysqlSessions.java
+++ b/hugegraph-mysql/src/main/java/com/baidu/hugegraph/backend/store/mysql/MysqlSessions.java
@@ -56,6 +56,7 @@ public class MysqlSessions extends BackendSessionPool {
this.opened = false;
}
+ @Override
public HugeConfig config() {
return this.config;
}
diff --git a/hugegraph-postgresql/src/main/java/com/baidu/hugegraph/backend/store/postgresql/PostgresqlSerializer.java b/hugegraph-postgresql/src/main/java/com/baidu/hugegraph/backend/store/postgresql/PostgresqlSerializer.java
index aa152b75c..d3e9623f1 100644
--- a/hugegraph-postgresql/src/main/java/com/baidu/hugegraph/backend/store/postgresql/PostgresqlSerializer.java
+++ b/hugegraph-postgresql/src/main/java/com/baidu/hugegraph/backend/store/postgresql/PostgresqlSerializer.java
@@ -41,7 +41,7 @@ public class PostgresqlSerializer extends MysqlSerializer {
entry.column(HugeKeys.INDEX_LABEL_ID, index.indexLabel().longId());
} else {
Object value = index.fieldValues();
- if (value != null && value.equals("\u0000")) {
+ if (value != null && "\u0000".equals(value)) {
value = Strings.EMPTY;
}
entry.column(HugeKeys.FIELD_VALUES, value);
diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/MetricsApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/MetricsApiTest.java
index 7175785e8..f92fd9531 100644
--- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/MetricsApiTest.java
+++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/MetricsApiTest.java
@@ -82,7 +82,7 @@ public class MetricsApiTest extends BaseApiTest {
for (Map.Entry, ?> e : graph.entrySet()) {
String key = (String) e.getKey();
value = e.getValue();
- if (key.equals("backend")) {
+ if ("backend".equals(key)) {
continue;
}
Assert.assertTrue(String.format(
diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/TaskApiTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/TaskApiTest.java
index 75663669f..1e44e549d 100644
--- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/TaskApiTest.java
+++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/TaskApiTest.java
@@ -98,6 +98,6 @@ public class TaskApiTest extends BaseApiTest {
Response r = client().get(path, String.valueOf(task));
String content = assertResponseStatus(200, r);
status = assertJsonContains(content, "task_status");
- } while (!status.equals("success"));
+ } while (!"success".equals(status));
}
}
diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/PropertyCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/PropertyCoreTest.java
index fe55396dc..e8298ff0c 100644
--- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/PropertyCoreTest.java
+++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/PropertyCoreTest.java
@@ -43,7 +43,7 @@ public abstract class PropertyCoreTest extends BaseCoreTest {
SchemaManager schema = graph().schema();
schema.propertyKey("id").asInt().create();
- schema.propertyKey("uid").asUuid().create();
+ schema.propertyKey("uid").asUUID().create();
schema.propertyKey("name").asText().create();
schema.propertyKey("gender").asBoolean().create();
schema.propertyKey("time").asDate().create();
@@ -171,7 +171,7 @@ public abstract class PropertyCoreTest extends BaseCoreTest {
}
@Test
- public void testTypeUuid() {
+ public void testTypeUUID() {
UUID uid = UUID.randomUUID();
Assert.assertEquals(uid, property("uid", uid));
}
diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/TestGraph.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/TestGraph.java
index 3d1535c36..13f1af491 100644
--- a/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/TestGraph.java
+++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/tinkerpop/TestGraph.java
@@ -177,7 +177,7 @@ public class TestGraph implements Graph {
this.initBasicSchema(idStrategy, defaultVL);
this.tx().commit();
if (!this.autoPerson &&
- defaultVL.equals("person") &&
+ "person".equals(defaultVL) &&
idStrategy == IdStrategy.AUTOMATIC) {
this.autoPerson = true;
}
@@ -626,7 +626,7 @@ public class TestGraph implements Graph {
schema.propertyKey("xxx").ifNotExist().create();
schema.propertyKey("yyy").ifNotExist().create();
schema.propertyKey("favoriteColor").ifNotExist().create();
- schema.propertyKey("uuid").asUuid().ifNotExist().create();
+ schema.propertyKey("uuid").asUUID().ifNotExist().create();
schema.propertyKey("myId").asInt().ifNotExist().create();
schema.propertyKey("myEdgeId").asInt().ifNotExist().create();
schema.propertyKey("state").ifNotExist().create();