forked from hugegraph/hugegraph
Optimize update logic & add a new strategy (#673)
1. if original data is not null but new data is null, use original data instead of null 2. add update strategy "OVERRIDE"
This commit is contained in:
parent
4ee38fa79b
commit
9d8ceb4dfc
|
|
@ -86,7 +86,7 @@
|
|||
</addDefaultSpecificationEntries>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Implementation-Version>0.44.0.0</Implementation-Version>
|
||||
<Implementation-Version>0.45.0.0</Implementation-Version>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
|
|
|
|||
|
|
@ -112,11 +112,16 @@ public class BatchAPI extends API {
|
|||
for (Map.Entry<String, UpdateStrategy> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class GraphsAPI extends API {
|
|||
@Context SecurityContext sc) {
|
||||
Set<String> 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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ public interface BackendEntry extends Idfiable {
|
|||
|
||||
public HugeType type();
|
||||
|
||||
@Override
|
||||
public Id id();
|
||||
|
||||
public Id subId();
|
||||
|
|
|
|||
|
|
@ -278,7 +278,7 @@ public class PropertyKey extends SchemaElement implements Propfiable {
|
|||
|
||||
Builder asDate();
|
||||
|
||||
Builder asUuid();
|
||||
Builder asUUID();
|
||||
|
||||
Builder asBoolean();
|
||||
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ public class PropertyKeyBuilder implements PropertyKey.Builder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PropertyKeyBuilder asUuid() {
|
||||
public PropertyKeyBuilder asUUID() {
|
||||
this.dataType = DataType.UUID;
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public final class HugeScriptTraversal<S, E> extends DefaultTraversal<S, E> {
|
|||
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));
|
||||
|
|
|
|||
|
|
@ -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 ================");
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ public class MysqlSessions extends BackendSessionPool {
|
|||
this.opened = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HugeConfig config() {
|
||||
return this.config;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue