From 93232ed23418434161f47dae0d85ac157dfd1ba5 Mon Sep 17 00:00:00 2001 From: Yossi Mesika Date: Thu, 28 Nov 2019 16:15:36 +0200 Subject: [PATCH 1/3] Various fixes, performance improvements and updated dependencies versions --- libs.properties | 2 +- rxrepo-orientdb/libs.properties | 2 +- .../orientdb/OrientDbSchemaProvider.java | 19 ++++---- .../rxrepo/test/AbstractRepositoryTest.java | 43 ++++++++++++++++++- .../rxrepo/test/UniqueIdPrototype.java | 6 ++- 5 files changed, 59 insertions(+), 13 deletions(-) diff --git a/libs.properties b/libs.properties index 28969837..68f21eb1 100644 --- a/libs.properties +++ b/libs.properties @@ -26,7 +26,7 @@ autoValueVer = 1.6.5 autoValue = com.google.auto.value:auto-value:$autoValueVer autoValueAnnotations = com.google.auto.value:auto-value-annotations:$autoValueVer -rxJava = io.reactivex.rxjava2:rxjava:2.2.11 +rxJava = io.reactivex.rxjava2:rxjava:2.2.14 jsr305 = com.google.code.findbugs:jsr305:3.0.2 javaxAnnotationApi = javax.annotation:javax.annotation-api:1.3.2 diff --git a/rxrepo-orientdb/libs.properties b/rxrepo-orientdb/libs.properties index 2d71e2de..8307171f 100644 --- a/rxrepo-orientdb/libs.properties +++ b/rxrepo-orientdb/libs.properties @@ -1,6 +1,6 @@ # suppress inspection "UnusedProperty" for whole file -orientDbVer = 3.0.24 +orientDbVer = 3.0.25 orientDbGroup = com.orientechnologies orientDbCore = $orientDbGroup:orientdb-core:$orientDbVer orientDbClient = $orientDbGroup:orientdb-client:$orientDbVer diff --git a/rxrepo-orientdb/src/main/java/com/slimgears/rxrepo/orientdb/OrientDbSchemaProvider.java b/rxrepo-orientdb/src/main/java/com/slimgears/rxrepo/orientdb/OrientDbSchemaProvider.java index ce4ad43a..a8cff053 100644 --- a/rxrepo-orientdb/src/main/java/com/slimgears/rxrepo/orientdb/OrientDbSchemaProvider.java +++ b/rxrepo-orientdb/src/main/java/com/slimgears/rxrepo/orientdb/OrientDbSchemaProvider.java @@ -141,7 +141,7 @@ private void addProperty(ODatabaseDocument dbSession, OClass oClass, Propert OType propertyOType = toOType(propertyMeta.type()); log.trace("{}: Adding property {} of type {} ({})", oClass.getName(), propertyMeta.name(), propertyMeta.type().getRawType().getSimpleName(), propertyOType); - if (propertyOType.isLink()) { + if (propertyOType.isLink() || propertyOType.isEmbedded()) { OClass linkedOClass = dbSession.getClass(toClassName(propertyMeta.type())); if (oClass.existsProperty(propertyMeta.name())) { OProperty oProperty = oClass.getProperty(propertyMeta.name()); @@ -153,6 +153,9 @@ private void addProperty(ODatabaseDocument dbSession, OClass oClass, Propert } } else { oClass.createProperty(propertyMeta.name(), propertyOType, linkedOClass); + if (PropertyMetas.isEmbedded(propertyMeta)) { + oClass.createProperty(propertyMeta.name() + "AsString", OType.STRING); + } } } else { if (oClass.existsProperty(propertyMeta.name())) { @@ -162,20 +165,18 @@ private void addProperty(ODatabaseDocument dbSession, OClass oClass, Propert } } else { oClass.createProperty(propertyMeta.name(), propertyOType); - if (PropertyMetas.isEmbedded(propertyMeta)) { - oClass.createProperty(propertyMeta.name() + "AsString", OType.STRING); - } } } } private static OType toOType(TypeToken token) { Class cls = token.getRawType(); - return Optional - .ofNullable(OType.getTypeByClass(cls)) - .orElseGet(() -> HasMetaClass.class.isAssignableFrom(cls) - ? (HasMetaClassWithKey.class.isAssignableFrom(cls) ? OType.LINK : OType.CUSTOM) - : OType.ANY); + if (PropertyMetas.isReference(token)) { + return OType.LINK; + } else if (PropertyMetas.isEmbedded(token)) { + return OType.EMBEDDED; + } + return OType.getTypeByClass(cls); } private static String toClassName(MetaClass metaClass) { diff --git a/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/AbstractRepositoryTest.java b/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/AbstractRepositoryTest.java index aad58378..8e8d8a30 100644 --- a/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/AbstractRepositoryTest.java +++ b/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/AbstractRepositoryTest.java @@ -43,13 +43,16 @@ public abstract class AbstractRepositoryTest { @Before public void setUp() { this.repository = createRepository(); + Assert.assertEquals(Long.valueOf(0), this.repository.entities(Product.metaClass).query().count().blockingGet()); System.out.println("Starting test: " + testNameRule.getMethodName()); } @After public void tearDown() { System.out.println("Test finished: " + testNameRule.getMethodName()); - this.repository.clearAndClose(); + Observable.fromIterable(repository.allEntitySets()) + .flatMapCompletable(EntitySet::clear) + .blockingAwait(); } protected abstract Repository createRepository(); @@ -1217,4 +1220,42 @@ public void testUpdatingDeletedObjectShouldNotAddObjectIntoRepo() throws Interru .await() .assertValue(0L); } + + @Test @Ignore + public void testMassiveInsertBatch() { + long count = 10000; + + Stopwatch stopwatch = Stopwatch.createStarted(); + + EntitySet products = repository.entities(Product.metaClass); + Observable + .fromIterable(Products.createMany((int)count)) + .buffer(1000) + .flatMapSingle(products::update) + .ignoreElements() + .blockingAwait(); + + stopwatch.stop(); + System.out.println("Elapsed time: " + stopwatch.elapsed().toMillis() / 1000 + "s"); + + Assert.assertEquals(Long.valueOf(count), repository.entities(Product.metaClass).query().count().blockingGet()); + } + + @Test @Ignore + public void testMassiveUpdateOneByOne() { + long count = 10000; + + Stopwatch stopwatch = Stopwatch.createStarted(); + + EntitySet products = repository.entities(Product.metaClass); + Observable.fromIterable(Products.createMany((int)count)) + .flatMapSingle(products::update) + .ignoreElements() + .blockingAwait(); + + stopwatch.stop(); + System.out.println("Elapsed time: " + stopwatch.elapsed().toMillis() / 1000 + "s"); + + Assert.assertEquals(Long.valueOf(count), repository.entities(Product.metaClass).query().count().blockingGet()); + } } diff --git a/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/UniqueIdPrototype.java b/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/UniqueIdPrototype.java index d21d6713..305b3427 100644 --- a/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/UniqueIdPrototype.java +++ b/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/UniqueIdPrototype.java @@ -16,7 +16,7 @@ public interface UniqueIdPrototype extends Serializable { @Filterable @JsonProperty int id(); @Filterable @JsonProperty int areaId(); - @Filterable @JsonProperty Class type(); + @Filterable @JsonProperty String type(); static UniqueIdPrototype productDescriptionId(int id) { return UniqueId.create(id, 0, ProductDescription.class); @@ -37,4 +37,8 @@ static UniqueIdPrototype inventoryId(int id) { static UniqueIdPrototype vendorId(int id) { return UniqueId.create(id, 0, Vendor.class); } + + static UniqueIdPrototype create(int id, int areaId, Class type) { + return UniqueId.create(id, areaId, type.getName()); + } } From 5e350080ebf350bc2dd9b70ddf2f7496fe6065ab Mon Sep 17 00:00:00 2001 From: Yossi Mesika Date: Thu, 28 Nov 2019 16:38:52 +0200 Subject: [PATCH 2/3] Test fix --- .../com/slimgears/rxrepo/test/AbstractRepositoryTest.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/AbstractRepositoryTest.java b/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/AbstractRepositoryTest.java index 8e8d8a30..ded6462f 100644 --- a/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/AbstractRepositoryTest.java +++ b/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/AbstractRepositoryTest.java @@ -43,16 +43,12 @@ public abstract class AbstractRepositoryTest { @Before public void setUp() { this.repository = createRepository(); - Assert.assertEquals(Long.valueOf(0), this.repository.entities(Product.metaClass).query().count().blockingGet()); System.out.println("Starting test: " + testNameRule.getMethodName()); } @After public void tearDown() { System.out.println("Test finished: " + testNameRule.getMethodName()); - Observable.fromIterable(repository.allEntitySets()) - .flatMapCompletable(EntitySet::clear) - .blockingAwait(); } protected abstract Repository createRepository(); From 69dcebf764fb3452dfc0f04609ade2bf4545ce6c Mon Sep 17 00:00:00 2001 From: Yossi Mesika Date: Thu, 28 Nov 2019 16:44:23 +0200 Subject: [PATCH 3/3] Put back a removed line --- .../java/com/slimgears/rxrepo/test/AbstractRepositoryTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/AbstractRepositoryTest.java b/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/AbstractRepositoryTest.java index ded6462f..c9b7932d 100644 --- a/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/AbstractRepositoryTest.java +++ b/rxrepo-test/src/main/java/com/slimgears/rxrepo/test/AbstractRepositoryTest.java @@ -49,6 +49,7 @@ public void setUp() { @After public void tearDown() { System.out.println("Test finished: " + testNameRule.getMethodName()); + this.repository.clearAndClose(); } protected abstract Repository createRepository();