From ff2875005ef64cbd708252afd9afd634fd6cf318 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Wed, 30 Aug 2023 20:56:05 +1200 Subject: [PATCH] [15x] Remove Inheritance support --- ebean-api/src/main/java/io/ebean/Query.java | 22 -- .../main/java/io/ebean/plugin/BeanType.java | 47 --- .../io/ebeaninternal/api/LoadContext.java | 4 - .../server/cache/CachedBeanData.java | 21 +- .../server/cache/CachedBeanDataFromBean.java | 2 +- .../server/cache/CachedBeanDataToBean.java | 3 - .../server/cache/CachedBeanId.java | 54 --- .../server/core/DefaultServer.java | 21 +- .../server/core/InternalConfiguration.java | 7 - .../server/core/OrmQueryRequest.java | 1 - .../server/deploy/AssocOneHelpRefInherit.java | 101 ----- .../server/deploy/BeanDescriptor.java | 159 +------- .../deploy/BeanDescriptorCacheHelp.java | 67 +--- .../server/deploy/BeanDescriptorJsonHelp.java | 44 +-- .../server/deploy/BeanDescriptorManager.java | 59 +-- .../server/deploy/BeanPropertyAssoc.java | 5 - .../server/deploy/BeanPropertyAssocOne.java | 38 +- .../server/deploy/InheritInfo.java | 360 ------------------ .../server/deploy/InheritInfoVisitor.java | 13 - .../server/deploy/TableJoin.java | 4 - .../deploy/meta/DeployBeanDescriptor.java | 50 --- .../deploy/meta/DeployBeanPropertyLists.java | 42 -- .../server/deploy/meta/DeployTableJoin.java | 10 - .../server/deploy/parse/AnnotationClass.java | 5 - .../server/deploy/parse/DeployInherit.java | 140 ------- .../deploy/parse/DeployInheritInfo.java | 270 ------------- .../deploy/visitor/VisitProperties.java | 39 -- .../server/loadcontext/DLoadContext.java | 6 - .../server/loadcontext/DLoadManyContext.java | 144 ++----- .../server/persist/BatchControl.java | 2 +- .../server/persist/SaveManyBeans.java | 2 +- .../server/persist/dml/InsertMeta.java | 16 - .../dmlbind/BindableDiscriminator.java | 42 -- .../server/query/DefaultFetchGroupQuery.java | 10 - .../ebeaninternal/server/query/STreeType.java | 6 - .../server/query/SqlTreeBuilder.java | 8 - .../server/query/SqlTreeLoadBean.java | 38 +- .../server/query/SqlTreeNodeBean.java | 30 -- .../server/querydefn/DefaultOrmQuery.java | 23 -- .../cache/CachedBeanDataSerializeTest.java | 3 +- .../server/deploy/BeanDescriptorTest.java | 32 +- .../deploy/parse/DeployInheritInfoTest.java | 21 - .../java/org/tests/model/basic/Animal.java | 4 +- .../test/java/org/tests/model/basic/Cat.java | 32 -- .../test/java/org/tests/model/basic/Dog.java | 31 -- .../model/build/ModelBuildBeanVisitor.java | 21 - .../build/ModelBuildPropertyVisitor.java | 7 - .../build/ModelBuildBeanVisitorTest.java | 27 -- .../company/domain/TestInheritAbstract.java | 2 +- .../java/io/ebean/typequery/TQRootBean.java | 17 - .../test/java/org/example/domain/ACat.java | 2 - .../test/java/org/example/domain/ADog.java | 26 -- .../java/org/example/domain/ASuperCat.java | 23 -- .../java/org/example/domain/AWildCat.java | 16 - .../test/java/org/example/domain/Animal.java | 8 +- .../java/org/querytest/InheritanceTest.java | 19 +- .../core/DefaultServer_getReferenceTest.java | 35 -- .../xtest/event/TestBeanFindController.java | 4 +- .../DefaultPersistenceContextTest.java | 14 +- .../io/ebean/xtest/plugin/BeanTypeTest.java | 45 --- .../aggregateformula/IAFBaseSegment.java | 9 +- .../aggregateformula/IAFPartialSegment.java | 10 +- .../TestAggregateInheritFormula.java | 2 +- .../java/org/tests/basic/TestInheritRef.java | 60 --- .../org/tests/basic/TestJoinInheritance.java | 76 ---- .../org/tests/cache/TestCacheManyToOne.java | 7 +- .../tests/docstore/CustomerReportTest.java | 88 ----- .../test/java/org/tests/inherit/ChildA.java | 65 +++- .../test/java/org/tests/inherit/ChildB.java | 18 - .../java/org/tests/inherit/DIntChild1.java | 19 - .../java/org/tests/inherit/DIntChild2.java | 19 - .../java/org/tests/inherit/DIntChildBase.java | 17 - .../java/org/tests/inherit/DIntParent.java | 40 -- .../src/test/java/org/tests/inherit/Data.java | 2 +- .../test/java/org/tests/inherit/EUncle.java | 6 +- .../org/tests/inherit/InheritDiscIntTest.java | 22 -- .../test/java/org/tests/inherit/Parent.java | 53 --- .../org/tests/inherit/ParentAggregate.java | 2 +- .../org/tests/inheritance/InnerReport.java | 6 +- .../tests/inheritance/OrganizationNode.java | 43 --- .../inheritance/OrganizationTreeNode.java | 53 --- .../tests/inheritance/OrganizationUnit.java | 20 - .../org/tests/inheritance/Stockforecast.java | 21 - .../TestDuplicateKeyException.java | 4 +- .../tests/inheritance/TestInheritInsert.java | 116 ------ .../TestInheritanceBatchLazyLoad.java | 41 -- ...estInheritanceDiscriminatorQueryCache.java | 20 +- .../inheritance/TestInheritanceJoins.java | 138 ------- .../inheritance/TestInheritanceOnMany.java | 104 ----- .../TestInheritanceOrderColumn.java | 30 +- .../inheritance/TestInheritanceQuery.java | 59 --- .../inheritance/TestInheritanceRawSql.java | 116 ------ .../inheritance/TestInheritanceRefBean.java | 39 -- .../org/tests/inheritance/TestIntInherit.java | 48 --- .../org/tests/inheritance/TestSkippable.java | 8 +- .../inheritance/TestTreeOrganisations.java | 27 -- .../abstrakt/AbstractBaseBlock.java | 42 -- .../org/tests/inheritance/abstrakt/Block.java | 19 - .../abstrakt/TestInheritanceNum.java | 18 - .../bothsides/TestInheritanceBothSides.java | 150 -------- .../tests/inheritance/cache/CIAddress.java | 19 - .../tests/inheritance/cache/CIBaseModel.java | 23 -- .../tests/inheritance/cache/CICustomer.java | 19 - .../inheritance/cache/CICustomerParent.java | 21 - .../org/tests/inheritance/cache/CIStreet.java | 23 -- .../inheritance/cache/CIStreetParent.java | 20 - .../cache/TestInheritCacheRefLoad.java | 64 ---- .../cache/TestInheritanceCache.java | 42 -- .../cache/TestInheritanceRefCache.java | 108 ------ .../TestInheritanceDeleteCascade.java | 26 -- .../company/domain/AbstractBar.java | 50 --- .../company/domain/ConcreteBar.java | 12 - .../tests/inheritance/company/domain/Foo.java | 43 --- .../company/domain/TestInheritAbstract.java | 55 --- .../inheritance/model/CalculationResult.java | 12 +- .../inheritance/model/Configuration.java | 22 +- .../inheritance/model/Configurations.java | 16 +- .../inheritance/model/GroupConfiguration.java | 40 -- .../model/ProductConfiguration.java | 35 -- .../org/tests/inheritance/order/OrderedA.java | 17 - .../org/tests/inheritance/order/OrderedB.java | 17 - .../inheritance/order/OrderedParent.java | 27 +- .../lazyforeignkeys/MainEntityRelation.java | 8 +- .../lazyforeignkeys/TestLazyForeignKeys.java | 6 +- .../java/org/tests/model/basic/Animal.java | 9 +- .../java/org/tests/model/basic/Attribute.java | 24 +- .../java/org/tests/model/basic/BigDog.java | 19 - .../test/java/org/tests/model/basic/Car.java | 84 ---- .../org/tests/model/basic/CarAccessory.java | 8 +- .../test/java/org/tests/model/basic/Cat.java | 32 -- .../test/java/org/tests/model/basic/Dog.java | 31 -- .../org/tests/model/basic/ListAttribute.java | 33 -- .../tests/model/basic/ListAttributeValue.java | 6 +- .../tests/model/basic/OCachedInhChildA.java | 30 -- .../tests/model/basic/OCachedInhChildB.java | 29 -- .../org/tests/model/basic/OCachedInhRoot.java | 12 +- .../java/org/tests/model/basic/TIntChild.java | 24 -- .../java/org/tests/model/basic/TIntRoot.java | 34 -- .../java/org/tests/model/basic/Truck.java | 62 --- .../java/org/tests/model/basic/Vehicle.java | 6 +- .../org/tests/model/basic/cache/CInhOne.java | 35 -- .../org/tests/model/basic/cache/CInhRef.java | 24 -- .../org/tests/model/basic/cache/CInhRoot.java | 26 -- .../org/tests/model/basic/cache/CInhTwo.java | 25 -- .../org/tests/model/basic/xtra/EdChild.java | 4 +- .../model/basic/xtra/EdExtendedParent.java | 4 +- .../org/tests/model/basic/xtra/EdParent.java | 11 +- .../xtra/TestDeleteUnloadedChildren.java | 4 +- .../TestInsertBatchThenFlushThenUpdate.java | 4 +- .../basic/xtra/TestInsertBatchThenUpdate.java | 8 +- ...TestInsertBatchWithDifferentRootTypes.java | 6 +- .../org/tests/model/carwheeltruck/TCar.java | 41 -- .../org/tests/model/carwheeltruck/TTruck.java | 22 -- .../model/carwheeltruck/TTruckHolder.java | 81 ---- .../model/carwheeltruck/TTruckHolderItem.java | 49 --- .../org/tests/model/carwheeltruck/TWheel.java | 32 -- .../TestInheritSoftDeleteJoin.java | 37 -- .../TestMTOInheritNoDiscriminator.java | 53 --- .../TestTruckCarWheelInhertiance.java | 34 -- .../tests/model/inheritmany/IMRelated.java | 42 -- .../org/tests/model/inheritmany/IMRoot.java | 32 -- .../tests/model/inheritmany/IMRootOne.java | 20 - .../tests/model/inheritmany/IMRootTwo.java | 31 -- .../org/tests/model/inheritmany/MBase.java | 20 - .../org/tests/model/inheritmany/MMedia.java | 21 - .../org/tests/model/inheritmany/MPicture.java | 22 -- .../org/tests/model/inheritmany/MProfile.java | 31 -- .../TestMediaInheritanceJoinToMany.java | 35 -- .../org/tests/model/join/AccountAccess.java | 10 - .../org/tests/model/join/BankAccount.java | 10 - .../org/tests/model/join/CustomerAccess.java | 10 - .../java/org/tests/model/join/HAccess.java | 3 +- .../java/org/tests/model/join/HAccount.java | 3 +- .../TestOneToManyJoinTableInheritance.java | 9 +- .../o2m/jointable/inheritance/ClassA.java | 2 + .../o2m/jointable/inheritance/ClassB.java | 7 - .../o2m/jointable/inheritance/ClassSuper.java | 3 +- .../tests/order/OrderReferencedParent.java | 6 +- .../query/TestQueryMultiJoinFetchPath.java | 10 +- .../other/TestFindIdsWithInheritance.java | 29 -- .../query/other/TestQuerySingleAttribute.java | 4 +- .../tests/rawsql/inherit/ParentQueryTest.java | 6 +- .../rawsql/inherit/ParentRawSqlTest.java | 30 +- .../TestInheritQuery.java | 168 -------- .../model/PalletLocation.java | 32 -- .../model/PalletLocationExternal.java | 18 - .../model/Warehouse.java | 48 --- .../singleTableInheritance/model/Zone.java | 36 -- .../model/ZoneExternal.java | 23 -- .../model/ZoneInternal.java | 24 -- .../org/tests/test/TestInheritWithMany.java | 72 ---- .../TestJsonInheritanceDiscriminator.java | 62 --- .../text/json/TestTextJsonInheritance.java | 60 --- 193 files changed, 345 insertions(+), 6203 deletions(-) delete mode 100644 ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanId.java delete mode 100644 ebean-core/src/main/java/io/ebeaninternal/server/deploy/AssocOneHelpRefInherit.java delete mode 100644 ebean-core/src/main/java/io/ebeaninternal/server/deploy/InheritInfo.java delete mode 100644 ebean-core/src/main/java/io/ebeaninternal/server/deploy/InheritInfoVisitor.java delete mode 100644 ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInherit.java delete mode 100644 ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java delete mode 100644 ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableDiscriminator.java delete mode 100644 ebean-core/src/test/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfoTest.java delete mode 100644 ebean-core/src/test/java/org/tests/model/basic/Cat.java delete mode 100644 ebean-core/src/test/java/org/tests/model/basic/Dog.java delete mode 100644 ebean-querybean/src/test/java/org/example/domain/ADog.java delete mode 100644 ebean-querybean/src/test/java/org/example/domain/ASuperCat.java delete mode 100644 ebean-querybean/src/test/java/org/example/domain/AWildCat.java delete mode 100644 ebean-test/src/test/java/org/tests/basic/TestInheritRef.java delete mode 100644 ebean-test/src/test/java/org/tests/basic/TestJoinInheritance.java delete mode 100644 ebean-test/src/test/java/org/tests/docstore/CustomerReportTest.java delete mode 100644 ebean-test/src/test/java/org/tests/inherit/ChildB.java delete mode 100644 ebean-test/src/test/java/org/tests/inherit/DIntChild1.java delete mode 100644 ebean-test/src/test/java/org/tests/inherit/DIntChild2.java delete mode 100644 ebean-test/src/test/java/org/tests/inherit/DIntChildBase.java delete mode 100644 ebean-test/src/test/java/org/tests/inherit/DIntParent.java delete mode 100644 ebean-test/src/test/java/org/tests/inherit/InheritDiscIntTest.java delete mode 100644 ebean-test/src/test/java/org/tests/inherit/Parent.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/OrganizationNode.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/OrganizationTreeNode.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/OrganizationUnit.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/Stockforecast.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/TestInheritInsert.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/TestInheritanceBatchLazyLoad.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/TestInheritanceJoins.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/TestInheritanceOnMany.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/TestInheritanceQuery.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/TestInheritanceRawSql.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/TestInheritanceRefBean.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/TestIntInherit.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/TestTreeOrganisations.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/abstrakt/AbstractBaseBlock.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/abstrakt/Block.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/abstrakt/TestInheritanceNum.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/bothsides/TestInheritanceBothSides.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/cache/CIAddress.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/cache/CIBaseModel.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/cache/CICustomer.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/cache/CICustomerParent.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/cache/CIStreet.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/cache/CIStreetParent.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/cache/TestInheritCacheRefLoad.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/cache/TestInheritanceCache.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/cache/TestInheritanceRefCache.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/cascadedelete/TestInheritanceDeleteCascade.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/company/domain/AbstractBar.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/company/domain/ConcreteBar.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/company/domain/Foo.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/company/domain/TestInheritAbstract.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/model/GroupConfiguration.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/model/ProductConfiguration.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/order/OrderedA.java delete mode 100644 ebean-test/src/test/java/org/tests/inheritance/order/OrderedB.java delete mode 100644 ebean-test/src/test/java/org/tests/model/basic/BigDog.java delete mode 100644 ebean-test/src/test/java/org/tests/model/basic/Car.java delete mode 100644 ebean-test/src/test/java/org/tests/model/basic/Cat.java delete mode 100644 ebean-test/src/test/java/org/tests/model/basic/Dog.java delete mode 100644 ebean-test/src/test/java/org/tests/model/basic/ListAttribute.java delete mode 100644 ebean-test/src/test/java/org/tests/model/basic/OCachedInhChildA.java delete mode 100644 ebean-test/src/test/java/org/tests/model/basic/OCachedInhChildB.java delete mode 100644 ebean-test/src/test/java/org/tests/model/basic/TIntChild.java delete mode 100644 ebean-test/src/test/java/org/tests/model/basic/TIntRoot.java delete mode 100644 ebean-test/src/test/java/org/tests/model/basic/Truck.java delete mode 100644 ebean-test/src/test/java/org/tests/model/basic/cache/CInhOne.java delete mode 100644 ebean-test/src/test/java/org/tests/model/basic/cache/CInhRef.java delete mode 100644 ebean-test/src/test/java/org/tests/model/basic/cache/CInhRoot.java delete mode 100644 ebean-test/src/test/java/org/tests/model/basic/cache/CInhTwo.java delete mode 100644 ebean-test/src/test/java/org/tests/model/carwheeltruck/TCar.java delete mode 100644 ebean-test/src/test/java/org/tests/model/carwheeltruck/TTruck.java delete mode 100644 ebean-test/src/test/java/org/tests/model/carwheeltruck/TTruckHolder.java delete mode 100644 ebean-test/src/test/java/org/tests/model/carwheeltruck/TTruckHolderItem.java delete mode 100644 ebean-test/src/test/java/org/tests/model/carwheeltruck/TWheel.java delete mode 100644 ebean-test/src/test/java/org/tests/model/carwheeltruck/TestInheritSoftDeleteJoin.java delete mode 100644 ebean-test/src/test/java/org/tests/model/carwheeltruck/TestMTOInheritNoDiscriminator.java delete mode 100644 ebean-test/src/test/java/org/tests/model/carwheeltruck/TestTruckCarWheelInhertiance.java delete mode 100644 ebean-test/src/test/java/org/tests/model/inheritmany/IMRelated.java delete mode 100644 ebean-test/src/test/java/org/tests/model/inheritmany/IMRoot.java delete mode 100644 ebean-test/src/test/java/org/tests/model/inheritmany/IMRootOne.java delete mode 100644 ebean-test/src/test/java/org/tests/model/inheritmany/IMRootTwo.java delete mode 100644 ebean-test/src/test/java/org/tests/model/inheritmany/MBase.java delete mode 100644 ebean-test/src/test/java/org/tests/model/inheritmany/MMedia.java delete mode 100644 ebean-test/src/test/java/org/tests/model/inheritmany/MPicture.java delete mode 100644 ebean-test/src/test/java/org/tests/model/inheritmany/MProfile.java delete mode 100644 ebean-test/src/test/java/org/tests/model/inheritmany/TestMediaInheritanceJoinToMany.java delete mode 100644 ebean-test/src/test/java/org/tests/model/join/AccountAccess.java delete mode 100644 ebean-test/src/test/java/org/tests/model/join/BankAccount.java delete mode 100644 ebean-test/src/test/java/org/tests/model/join/CustomerAccess.java delete mode 100644 ebean-test/src/test/java/org/tests/o2m/jointable/inheritance/ClassB.java delete mode 100644 ebean-test/src/test/java/org/tests/query/other/TestFindIdsWithInheritance.java delete mode 100644 ebean-test/src/test/java/org/tests/singleTableInheritance/TestInheritQuery.java delete mode 100644 ebean-test/src/test/java/org/tests/singleTableInheritance/model/PalletLocation.java delete mode 100644 ebean-test/src/test/java/org/tests/singleTableInheritance/model/PalletLocationExternal.java delete mode 100644 ebean-test/src/test/java/org/tests/singleTableInheritance/model/Warehouse.java delete mode 100644 ebean-test/src/test/java/org/tests/singleTableInheritance/model/Zone.java delete mode 100644 ebean-test/src/test/java/org/tests/singleTableInheritance/model/ZoneExternal.java delete mode 100644 ebean-test/src/test/java/org/tests/singleTableInheritance/model/ZoneInternal.java delete mode 100644 ebean-test/src/test/java/org/tests/test/TestInheritWithMany.java delete mode 100644 ebean-test/src/test/java/org/tests/text/json/TestJsonInheritanceDiscriminator.java delete mode 100644 ebean-test/src/test/java/org/tests/text/json/TestTextJsonInheritance.java diff --git a/ebean-api/src/main/java/io/ebean/Query.java b/ebean-api/src/main/java/io/ebean/Query.java index 514f83691d..10ebc526fe 100644 --- a/ebean-api/src/main/java/io/ebean/Query.java +++ b/ebean-api/src/main/java/io/ebean/Query.java @@ -1643,28 +1643,6 @@ default Query setUseQueryCache(boolean enabled) { */ Class getBeanType(); - /** - * Restrict the query to only return subtypes of the given inherit type. - * - *
{@code
-   *
-   *   List animals =
-   *     new QAnimal()
-   *       .name.startsWith("Fluffy")
-   *       .setInheritType(Cat.class)
-   *       .findList();
-   *
-   * }
- * - * @param type An inheritance subtype of the - */ - Query setInheritType(Class type); - - /** - * Returns the inherit type. This is normally the same as getBeanType() returns as long as no other type is set. - */ - Class getInheritType(); - /** * Return the type of query being executed. */ diff --git a/ebean-api/src/main/java/io/ebean/plugin/BeanType.java b/ebean-api/src/main/java/io/ebean/plugin/BeanType.java index 0401711f06..7ecbfb06b1 100644 --- a/ebean-api/src/main/java/io/ebean/plugin/BeanType.java +++ b/ebean-api/src/main/java/io/ebean/plugin/BeanType.java @@ -8,8 +8,6 @@ import io.ebean.event.BeanQueryAdapter; import java.util.Collection; -import java.util.List; -import java.util.function.Consumer; /** * Information and methods on BeanDescriptors made available to plugins. @@ -144,49 +142,4 @@ public interface BeanType { */ IdType idType(); - /** - * Add the discriminator value to the query if needed. - */ - void addInheritanceWhere(Query query); - - /** - * Return the root bean type for an inheritance hierarchy. - */ - BeanType root(); - - /** - * Return true if this bean type has an inheritance hierarchy. - */ - boolean hasInheritance(); - - /** - * Return true if this object is the root level object in its entity - * inheritance. - */ - boolean isInheritanceRoot(); - - /** - * Returns all direct children of this beantype - */ - List> inheritanceChildren(); - - /** - * Returns the parent in inheritance hierarchy - */ - BeanType inheritanceParent(); - - /** - * Visit all children recursively - */ - void visitAllInheritanceChildren(Consumer> visitor); - - /** - * Return the discriminator column. - */ - String discColumn(); - - /** - * Create a bean given the discriminator value. - */ - T createBeanUsingDisc(Object discValue); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/api/LoadContext.java b/ebean-core/src/main/java/io/ebeaninternal/api/LoadContext.java index 57a725f263..5edaff9326 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/api/LoadContext.java +++ b/ebean-core/src/main/java/io/ebeaninternal/api/LoadContext.java @@ -51,8 +51,4 @@ public interface LoadContext { */ void register(String path, BeanPropertyAssocMany many, BeanCollection bc); - /** - * Use soft-references for streaming queries, so unreachable entries can be garbage collected. - */ - void useReferences(boolean useReferences); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanData.java b/ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanData.java index 23ced1d5e6..f3dcc9f746 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanData.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanData.java @@ -15,7 +15,6 @@ public final class CachedBeanData implements Externalizable { private long whenCreated; private long version; - private String discValue; private Map data; /** * The sharable bean is effectively transient (near cache only). @@ -25,10 +24,9 @@ public final class CachedBeanData implements Externalizable { /** * Construct from a loaded bean. */ - public CachedBeanData(Object sharableBean, String discValue, Map data, long version) { + public CachedBeanData(Object sharableBean, Map data, long version) { this.whenCreated = System.currentTimeMillis(); this.sharableBean = sharableBean; - this.discValue = discValue; this.data = data; this.version = version; } @@ -43,11 +41,6 @@ public CachedBeanData() { public void writeExternal(ObjectOutput out) throws IOException { out.writeLong(version); out.writeLong(whenCreated); - boolean hasDisc = discValue != null; - out.writeBoolean(hasDisc); - if (hasDisc) { - out.writeUTF(discValue); - } out.writeInt(data.size()); for (Map.Entry entry : data.entrySet()) { out.writeUTF(entry.getKey()); @@ -59,9 +52,6 @@ public void writeExternal(ObjectOutput out) throws IOException { public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { version = in.readLong(); whenCreated = in.readLong(); - if (in.readBoolean()) { - discValue = in.readUTF(); - } data = new LinkedHashMap<>(); int count = in.readInt(); for (int i = 0; i < count; i++) { @@ -85,7 +75,7 @@ public CachedBeanData update(Map changes, long version) { Map copy = new HashMap<>(); copy.putAll(data); copy.putAll(changes); - return new CachedBeanData(null, discValue, copy, version); + return new CachedBeanData(null, copy, version); } /** @@ -102,13 +92,6 @@ public long getVersion() { return version; } - /** - * Return the raw discriminator value. - */ - public String getDiscValue() { - return discValue; - } - /** * Return a sharable (immutable read only) bean. Near cache only use. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanDataFromBean.java b/ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanDataFromBean.java index 2405e03bce..cc3a77119e 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanDataFromBean.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanDataFromBean.java @@ -41,7 +41,7 @@ public static CachedBeanData extract(BeanDescriptor desc, EntityBean bean) { long version = desc.getVersion(bean); EntityBean sharableBean = createSharableBean(desc, bean, ebi); - return new CachedBeanData(sharableBean, desc.discValue(), data, version); + return new CachedBeanData(sharableBean, data, version); } private static EntityBean createSharableBean(BeanDescriptor desc, EntityBean bean, EntityBeanIntercept beanEbi) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanDataToBean.java b/ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanDataToBean.java index ae5b922a9a..2eb0e78f33 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanDataToBean.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanDataToBean.java @@ -14,9 +14,6 @@ public static void load(BeanDescriptor desc, EntityBean bean, CachedBeanData // any future lazy loading skips L2 bean cache ebi.setLoadedFromCache(true); BeanProperty idProperty = desc.idProperty(); - if (desc.inheritInfo() != null) { - desc = desc.inheritInfo().readType(bean.getClass()).desc(); - } if (idProperty != null) { // load the id property loadProperty(bean, cacheBeanData, ebi, idProperty, context); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanId.java b/ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanId.java deleted file mode 100644 index 6b0fc903b9..0000000000 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cache/CachedBeanId.java +++ /dev/null @@ -1,54 +0,0 @@ -package io.ebeaninternal.server.cache; - -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; - -/** - * Bean Id value plus discriminator type. - *

- * Put into L2 cache such that we know the type of a bean with inheritance. - */ -public final class CachedBeanId implements Externalizable { - - private String discValue; - private Object id; - - public CachedBeanId(String discValue, Object id) { - this.discValue = discValue; - this.id = id; - } - - /** - * Construct from serialisation. - */ - public CachedBeanId() { - } - - @Override - public void writeExternal(ObjectOutput out) throws IOException { - out.writeUTF(discValue); - out.writeObject(id); - } - - @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - discValue = in.readUTF(); - id = in.readObject(); - } - - @Override - public String toString() { - return discValue + ":" + id; - } - - public String getDiscValue() { - return discValue; - } - - public Object getId() { - return id; - } - -} diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java index aa53501d9b..935d3adb08 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java @@ -28,7 +28,6 @@ import io.ebeaninternal.server.deploy.BeanDescriptor; import io.ebeaninternal.server.deploy.BeanDescriptorManager; import io.ebeaninternal.server.deploy.BeanProperty; -import io.ebeaninternal.server.deploy.InheritInfo; import io.ebeaninternal.server.dto.DtoBeanDescriptor; import io.ebeaninternal.server.dto.DtoBeanManager; import io.ebeaninternal.server.el.ElFilter; @@ -595,25 +594,7 @@ public T reference(Class type, Object id) { return (T) existing; } } - InheritInfo inheritInfo = desc.inheritInfo(); - if (inheritInfo == null || inheritInfo.isConcrete()) { - return (T) desc.contextRef(pc, null, false, id); - } - return referenceFindOne(type, id, desc); - } - - private T referenceFindOne(Class type, Object id, BeanDescriptor desc) { - BeanProperty idProp = desc.idProperty(); - if (idProp == null) { - throw new PersistenceException("No ID properties for this type? " + desc); - } - // we actually need to do a query because we don't know the type without the discriminator - // value, just select the id property and discriminator column (auto added) - T bean = find(type).select(idProp.name()).setId(id).findOne(); - if (bean == null) { - throw new EntityNotFoundException("Could not find reference bean " + id + " for " + desc); - } - return bean; + return (T) desc.contextRef(pc, null, false, id); } @Override diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java index 611d9ce913..f08badd060 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java @@ -29,7 +29,6 @@ import io.ebeaninternal.server.deploy.BeanDescriptorManager; import io.ebeaninternal.server.deploy.generatedproperty.GeneratedPropertyFactory; import io.ebeaninternal.server.deploy.parse.DeployCreateProperties; -import io.ebeaninternal.server.deploy.parse.DeployInherit; import io.ebeaninternal.server.deploy.parse.DeployUtil; import io.ebeaninternal.server.dto.DtoBeanManager; import io.ebeaninternal.server.expression.DefaultExpressionFactory; @@ -64,7 +63,6 @@ public final class InternalConfiguration { private final DatabaseConfig config; private final BootupClasses bootupClasses; private final DatabasePlatform databasePlatform; - private final DeployInherit deployInherit; private final TypeManager typeManager; private final DtoBeanManager dtoBeanManager; private final ClockService clockService; @@ -105,7 +103,6 @@ public final class InternalConfiguration { this.expressionFactory = initExpressionFactory(config); this.typeManager = new DefaultTypeManager(config, bootupClasses); this.multiValueBind = createMultiValueBind(databasePlatform.platform()); - this.deployInherit = new DeployInherit(bootupClasses); this.deployCreateProperties = new DeployCreateProperties(typeManager); this.deployUtil = new DeployUtil(typeManager, config); this.serverCachePlugin = initServerCachePlugin(); @@ -295,10 +292,6 @@ BeanDescriptorManager getBeanDescriptorManager() { return beanDescriptorManager; } - public DeployInherit getDeployInherit() { - return deployInherit; - } - public DeployCreateProperties getDeployCreateProperties() { return deployCreateProperties; } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/OrmQueryRequest.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/OrmQueryRequest.java index 9a83635bad..5158154c31 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/OrmQueryRequest.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/OrmQueryRequest.java @@ -228,7 +228,6 @@ public void initTransIfRequired() { persistenceContext.beginIterate(); } loadContext = new DLoadContext(this, secondaryQueries); - loadContext.useReferences(Type.ITERATE == query.type()); } /** diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/AssocOneHelpRefInherit.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/AssocOneHelpRefInherit.java deleted file mode 100644 index df8bff16f7..0000000000 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/AssocOneHelpRefInherit.java +++ /dev/null @@ -1,101 +0,0 @@ -package io.ebeaninternal.server.deploy; - -import io.ebean.bean.EntityBean; -import io.ebean.bean.PersistenceContext; -import io.ebeaninternal.server.query.SqlJoinType; -import io.ebeaninternal.server.query.SqlTreeJoin; - -import java.sql.SQLException; - -/** - * Helper for BeanPropertyAssocOne imported reference but with inheritance. - */ -final class AssocOneHelpRefInherit extends AssocOneHelp { - - private final InheritInfo inherit; - - AssocOneHelpRefInherit(BeanPropertyAssocOne property) { - super(property); - this.inherit = property.targetInheritInfo; - } - - @Override - void loadIgnore(DbReadContext ctx) { - property.targetIdBinder.loadIgnore(ctx); - ctx.dataReader().incrementPos(1); - } - - /** - * Read and set a Reference bean. - */ - @Override - Object read(DbReadContext ctx) throws SQLException { - // read discriminator to determine the type - InheritInfo rowInheritInfo = inherit.readType(ctx); - BeanDescriptor desc; - if (rowInheritInfo != null) { - desc = rowInheritInfo.desc(); - } else if (!inherit.hasChildren()) { - desc = inherit.desc(); - } else { - // ignore the id property - property.targetIdBinder.loadIgnore(ctx); - return null; - } - Object id = property.targetIdBinder.read(ctx); - if (id == null) { - return null; - } - // check transaction context to see if it already exists - PersistenceContext pc = ctx.persistenceContext(); - Object existing = desc.contextGet(pc, id); - if (existing != null) { - return existing; - } - // for inheritance hierarchy create the correct type for this row... - boolean disableLazyLoading = ctx.isDisableLazyLoading(); - Object ref = desc.contextRef(pc, ctx.isReadOnly(), disableLazyLoading, id); - if (!disableLazyLoading) { - ctx.registerBeanInherit(property, ((EntityBean) ref)._ebean_getIntercept()); - } - return ref; - } - - void appendFrom(DbSqlContext ctx, SqlJoinType joinType) { - // add join to support the discriminator column - String relativePrefix = ctx.relativePrefix(property.name); - ctx.addExtraJoin(new Extra(relativePrefix, joinType)); - } - - /** - * Extra join to support the discriminator column. - */ - final class Extra implements SqlTreeJoin { - final String relativePrefix; - final SqlJoinType joinType; - Extra(String relativePrefix, SqlJoinType joinType) { - this.relativePrefix = relativePrefix; - this.joinType = joinType; - } - - @Override - public void addJoin(DbSqlContext ctx) { - // add join to support the discriminator column *IF* join is not already present - property.tableJoin.addJoin(joinType, relativePrefix, ctx); - } - } - - /** - * Append columns for foreign key columns. - */ - @Override - void appendSelect(DbSqlContext ctx, boolean subQuery) { - if (!subQuery) { - // add discriminator column - String relativePrefix = ctx.relativePrefix(property.name()); - String tableAlias = ctx.tableAlias(relativePrefix); - ctx.appendColumn(tableAlias, property.targetInheritInfo.getDiscriminatorColumn()); - } - property.importedId.sqlAppend(ctx); - } -} diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java index d354cf7d4b..3db3de7878 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java @@ -134,7 +134,6 @@ public enum EntityType { private final BeanQueryAdapter queryAdapter; private final BeanFindController beanFinder; private final ChangeLogFilter changeLogFilter; - final InheritInfo inheritInfo; private final boolean abstractType; private final BeanProperty idProperty; private final int idPropertyIndex; @@ -146,10 +145,6 @@ public enum EntityType { * Properties that are initialised in the constructor need to be 'unloaded' to support partial object queries. */ private final int[] unloadProperties; - /** - * Properties local to this type (not from a super type). - */ - private final BeanProperty[] propertiesLocal; /** * Scalar mutable properties (need to dirty check on update). */ @@ -220,7 +215,6 @@ public BeanDescriptor(BeanDescriptorMap owner, DeployBeanDescriptor deploy) { this.rootBeanType = PersistenceContextUtil.root(beanType); this.prototypeEntityBean = createPrototypeEntityBean(beanType); this.iudMetrics = new BeanIudMetrics(name); - this.inheritInfo = deploy.getInheritInfo(); this.beanFinder = deploy.getBeanFinder(); this.persistController = deploy.getPersistController(); this.persistListener = deploy.getPersistListener(); @@ -263,7 +257,6 @@ public BeanDescriptor(BeanDescriptorMap owner, DeployBeanDescriptor deploy) { this.propertiesNonTransient = listHelper.getNonTransients(); this.propertiesBaseScalar = listHelper.getBaseScalar(); this.propertiesEmbedded = listHelper.getEmbedded(); - this.propertiesLocal = listHelper.getLocal(); this.propertiesMutable = listHelper.getMutable(); this.unidirectional = listHelper.getUnidirectional(); this.orderColumn = listHelper.getOrderColumn(); @@ -449,10 +442,6 @@ void initialiseId(BeanDescriptorInitContext initContext) { // add mapping (used to swap out baseTable for asOf queries) initContext.addHistory(baseTable, baseTableAsOf); } - if (inheritInfo != null) { - inheritInfo.setDescriptor(this); - } - // initialise just the Id property only if (idProperty != null) { idProperty.initialise(initContext); @@ -625,18 +614,6 @@ public boolean isBatchEscalateOnCascade(PersistRequest.Type type) { return type == PersistRequest.Type.INSERT ? batchEscalateOnCascadeInsert : batchEscalateOnCascadeDelete; } - void initInheritInfo() { - if (inheritInfo != null) { - // need to check every BeanDescriptor in the inheritance hierarchy - if (saveRecurseSkippable) { - saveRecurseSkippable = inheritInfo.isSaveRecurseSkippable(); - } - if (deleteRecurseSkippable) { - deleteRecurseSkippable = inheritInfo.isDeleteRecurseSkippable(); - } - } - } - public void metricPersistBatch(PersistRequest.Type type, long startNanos, int size) { iudMetrics.addBatch(type, startNanos, size); } @@ -875,36 +852,6 @@ public String defaultSelectClause() { return defaultSelectClause; } - /** - * Return true if this object is the root level object in its entity - * inheritance. - */ - @Override - public boolean isInheritanceRoot() { - return inheritInfo == null || inheritInfo.isRoot(); - } - - /** - * Return the root bean type if part of inheritance hierarchy. - */ - @Override - public BeanType root() { - if (inheritInfo != null && !inheritInfo.isRoot()) { - return inheritInfo.getRoot().desc(); - } - return this; - } - - /** - * Return the full name taking into account inheritance. - */ - public String rootName() { - if (inheritInfo != null && !inheritInfo.isRoot()) { - return inheritInfo.getRoot().desc().name(); - } - return name; - } - /** * Prepare the query for multi-tenancy check for document store only use. */ @@ -1553,9 +1500,6 @@ public T createReference(Boolean readOnly, boolean disableLazyLoad, Object id, P } } try { - if (inheritInfo != null && !inheritInfo.isConcrete()) { - return findReferenceBean(id, pc); - } EntityBean eb = createEntityBean(); id = convertSetId(id, eb); EntityBeanIntercept ebi = eb._ebean_getIntercept(); @@ -1590,9 +1534,6 @@ SingleBeanLoader l2BeanLoader() { * Create a non read only reference bean without checking cacheSharableBeans. */ public T createReference(Object id, PersistenceContext pc) { - if (inheritInfo != null && !inheritInfo.isConcrete()) { - return findReferenceBean(id, pc); - } return createRef(id, pc); } @@ -1691,17 +1632,7 @@ public BeanProperty orderColumn() { * visible. */ public BeanPropertyAssocOne unidirectional() { - BeanDescriptor other = this; - while (true) { - if (other.unidirectional != null) { - return other.unidirectional; - } - if (other.inheritInfo != null && !other.inheritInfo.isRoot()) { - other = other.inheritInfo.getParent().desc(); - continue; - } - return null; - } + return unidirectional; } /** @@ -1958,9 +1889,6 @@ public boolean lazyLoadMany(EntityBeanIntercept ebi, LoadBeanContext parent) { if (lazyLoadProperty == -1) { return false; } - if (inheritInfo != null) { - return descOf(ebi.owner().getClass()).lazyLoadMany(ebi, lazyLoadProperty, parent); - } return lazyLoadMany(ebi, lazyLoadProperty, parent); } @@ -1988,13 +1916,6 @@ private boolean lazyLoadMany(EntityBeanIntercept ebi, int lazyLoadProperty, Load return false; } - /** - * Return the correct BeanDescriptor based on the bean class type. - */ - BeanDescriptor descOf(Class type) { - return inheritInfo.readType(type).desc(); - } - /** * Return a Comparator for local sorting of lists. * @@ -2187,13 +2108,8 @@ public BeanProperty findProperty(String propName) { BeanProperty _findBeanProperty(String propName) { BeanProperty prop = propMap.get(propName); - if (prop == null) { - if ("_$IdClass$".equals(propName)) { - return idProperty; - } else if (inheritInfo != null) { - // search in sub types... - return inheritInfo.findSubTypeProperty(propName); - } + if (prop == null && "_$IdClass$".equals(propName)) { + return idProperty; } return prop; } @@ -2227,45 +2143,6 @@ public boolean isAutoTunable() { return autoTunable; } - /** - * Returns the Inheritance mapping information. This will be null if this type - * of bean is not involved in any ORM inheritance mapping. - */ - @Override - public InheritInfo inheritInfo() { - return inheritInfo; - } - - @Override - public boolean hasInheritance() { - return inheritInfo != null; - } - - @Override - public String discColumn() { - return inheritInfo.getDiscriminatorColumn(); - } - - /** - * Return the discriminator value for this bean type (or null when there is no inheritance). - */ - public String discValue() { - return inheritInfo == null ? null : inheritInfo.getDiscriminatorStringValue(); - } - - @Override - @SuppressWarnings("unchecked") - public T createBeanUsingDisc(Object discValue) { - return (T) inheritInfo.getType(discValue.toString()).desc().createBean(); - } - - @Override - public void addInheritanceWhere(Query query) { - if (inheritInfo != null && !inheritInfo.isRoot()) { - query.where().eq(inheritInfo.getDiscriminatorColumn(), inheritInfo.getDiscriminatorValue()); - } - } - /** * Return true if this is an embedded bean. */ @@ -2993,13 +2870,6 @@ public BeanProperty[] propertiesBaseScalar() { return propertiesBaseScalar; } - /** - * Return the properties local to this type for inheritance. - */ - public BeanProperty[] propertiesLocal() { - return propertiesLocal; - } - /** * Return the properties set as generated values on insert. */ @@ -3062,27 +2932,4 @@ public List uniqueProps() { return propertiesUnique; } - @Override - public List> inheritanceChildren() { - if (hasInheritance()) { - return inheritInfo().getChildren() - .stream() - .map(InheritInfo::desc) - .collect(Collectors.toList()); - } else { - return Collections.emptyList(); - } - } - - @Override - public BeanType inheritanceParent() { - return inheritInfo() == null ? null : inheritInfo().getParent().desc(); - } - - @Override - public void visitAllInheritanceChildren(Consumer> visitor) { - if (hasInheritance()) { - inheritInfo().visitChildren(info -> visitor.accept(info.desc())); - } - } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java index 54ffe630ef..fe3bfe1dd3 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java @@ -449,44 +449,7 @@ CachedBeanData beanExtractData(BeanDescriptor targetDesc, EntityBean bean) { } void beanPutAll(Collection beans) { - if (desc.inheritInfo != null) { - Class aClass = theClassOf(beans); - // check if all beans have the same class - for (EntityBean bean : beans) { - if (!bean.getClass().equals(aClass)) { - aClass = null; - break; - } - } - if (aClass == null) { - // there are different bean types in the collection, so we add one by one to the cache - for (EntityBean bean : beans) { - desc.descOf(bean.getClass()).cacheBeanPutDirect(bean); - } - } else { - desc.descOf(aClass).cacheBeanPutAllDirect(beans); - } - } else { - beanCachePutAllDirect(beans); - } - } - - private Class theClassOf(Collection beans) { - if (beans instanceof List) { - return ((List) beans).get(0).getClass(); - } - return beans.iterator().next().getClass(); - } - - /** - * Put a bean into the bean cache. - */ - void beanCachePut(EntityBean bean) { - if (desc.inheritInfo != null) { - desc.descOf(bean.getClass()).cacheBeanPutDirect(bean); - } else { - beanCachePutDirect(bean); - } + beanCachePutAllDirect(beans); } void beanCachePutAllDirect(Collection beans) { @@ -520,6 +483,13 @@ void beanCachePutAllDirect(Collection beans) { } } + /** + * Put a bean into the bean cache. + */ + void beanCachePut(EntityBean bean) { + beanCachePutDirect(bean); + } + /** * Put the bean into the bean cache. */ @@ -604,19 +574,7 @@ private T convertToBean(Object id, Boolean readOnly, PersistenceContext context, * Load the entity bean taking into account inheritance. */ private EntityBean loadBean(Object id, Boolean readOnly, CachedBeanData data, PersistenceContext context) { - String discValue = data.getDiscValue(); - if (discValue == null) { - return loadBeanDirect(id, readOnly, data, context); - } else { - return rootDescriptor(discValue).cacheBeanLoadDirect(id, readOnly, data, context); - } - } - - /** - * Return the root BeanDescriptor for inheritance. - */ - private BeanDescriptor rootDescriptor(String discValue) { - return desc.inheritInfo.readType(discValue).desc(); + return loadBeanDirect(id, readOnly, data, context); } /** @@ -652,12 +610,7 @@ EntityBean loadBeanDirect(Object id, Boolean readOnly, CachedBeanData data, Pers * Load the embedded bean checking for inheritance. */ EntityBean embeddedBeanLoad(CachedBeanData data, PersistenceContext context) { - String discValue = data.getDiscValue(); - if (discValue == null) { - return embeddedBeanLoadDirect(data, context); - } else { - return rootDescriptor(discValue).cacheEmbeddedBeanLoadDirect(data, context); - } + return embeddedBeanLoadDirect(data, context); } /** diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorJsonHelp.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorJsonHelp.java index 720ef92caa..7a969dc2e9 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorJsonHelp.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorJsonHelp.java @@ -19,24 +19,14 @@ final class BeanDescriptorJsonHelp { private final BeanDescriptor desc; - private final InheritInfo inheritInfo; BeanDescriptorJsonHelp(BeanDescriptor desc) { this.desc = desc; - this.inheritInfo = desc.inheritInfo; } void jsonWrite(SpiJsonWriter writeJson, EntityBean bean, String key) throws IOException { writeJson.writeStartObject(key); - if (inheritInfo == null) { - jsonWriteProperties(writeJson, bean); - } else { - InheritInfo localInheritInfo = inheritInfo.readType(bean.getClass()); - String discValue = localInheritInfo.getDiscriminatorStringValue(); - String discColumn = localInheritInfo.getDiscriminatorColumn(); - writeJson.gen().writeStringField(discColumn, discValue); - localInheritInfo.desc().jsonWriteProperties(writeJson, bean); - } + jsonWriteProperties(writeJson, bean); writeJson.writeEndObject(); } @@ -45,11 +35,7 @@ void jsonWriteProperties(SpiJsonWriter writeJson, EntityBean bean) { } void jsonWriteDirty(SpiJsonWriter writeJson, EntityBean bean, boolean[] dirtyProps) throws IOException { - if (inheritInfo == null) { - jsonWriteDirtyProperties(writeJson, bean, dirtyProps); - } else { - desc.descOf(bean.getClass()).jsonWriteDirtyProperties(writeJson, bean, dirtyProps); - } + jsonWriteDirtyProperties(writeJson, bean, dirtyProps); } void jsonWriteDirtyProperties(SpiJsonWriter writeJson, EntityBean bean, boolean[] dirtyProps) throws IOException { @@ -80,31 +66,7 @@ T jsonRead(SpiJsonReader jsonRead, String path, boolean withInheritance, T targe throw new JsonParseException(parser, "Unexpected token " + token + " - expecting start_object", parser.getCurrentLocation()); } } - - if (desc.inheritInfo == null || !withInheritance) { - return jsonReadObject(jsonRead, path, target); - } - - ObjectNode node = jsonRead.mapper().readTree(parser); - if (node.isNull()) { - return null; - } - JsonParser newParser = node.traverse(); - SpiJsonReader newReader = jsonRead.forJson(newParser); - - // check for the discriminator value to determine the correct sub type - String discColumn = inheritInfo.getRoot().getDiscriminatorColumn(); - JsonNode discNode = node.get(discColumn); - if (discNode == null || discNode.isNull()) { - if (!desc.isAbstractType()) { - return desc.jsonReadObject(newReader, path, target); - } - String msg = "Error reading inheritance discriminator - expected [" + discColumn + "] but no json key?"; - throw new JsonParseException(newParser, msg, parser.getCurrentLocation()); - } - - BeanDescriptor inheritDesc = (BeanDescriptor) inheritInfo.readType(discNode.asText()).desc(); - return inheritDesc.jsonReadObject(newReader, path, target); + return jsonReadObject(jsonRead, path, target); } private T jsonReadObject(SpiJsonReader readJson, String path, T target) throws IOException { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java index 942dd00c0b..fdcffd255a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java @@ -59,7 +59,6 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy private final ReadAnnotations readAnnotations; private final TransientProperties transientProperties; - private final DeployInherit deplyInherit; private final BeanPropertyAccess beanPropertyAccess = new EnhanceBeanPropertyAccess(); private final DeployUtil deployUtil; private final PersistControllerManager persistControllerManager; @@ -129,7 +128,6 @@ public BeanDescriptorManager(InternalConfiguration config) { this.createProperties = config.getDeployCreateProperties(); this.namingConvention = this.config.getNamingConvention(); this.dbIdentity = config.getDatabasePlatform().dbIdentity(); - this.deplyInherit = config.getDeployInherit(); this.deployUtil = config.getDeployUtil(); this.typeManager = deployUtil.typeManager(); this.beanManagerFactory = new BeanManagerFactory(config.getDatabasePlatform()); @@ -260,7 +258,6 @@ public Map deploy() { readEntityDeploymentInitial(); readEntityBeanTable(); readEntityDeploymentAssociations(); - readInheritedIdGenerators(); // creates the BeanDescriptors readEntityRelationships(); List> list = new ArrayList<>(descMap.values()); @@ -402,12 +399,7 @@ private void initialiseAll() { d.initialiseId(initContext); } - // PASS 2: - // now initialise all the inherit info - for (BeanDescriptor d : descMap.values()) { - d.initInheritInfo(); - } - + // PASS 2: Was to initialise all the inherit info // PASS 3: // now initialise all the associated properties for (BeanDescriptor d : descMap.values()) { @@ -608,20 +600,6 @@ private void readEntityDeploymentAssociations() { } } - private void readInheritedIdGenerators() { - for (DeployBeanInfo info : deployInfoMap.values()) { - DeployBeanDescriptor descriptor = info.getDescriptor(); - InheritInfo inheritInfo = descriptor.getInheritInfo(); - if (inheritInfo != null && !inheritInfo.isRoot()) { - DeployBeanInfo rootBeanInfo = deployInfoMap.get(inheritInfo.getRoot().getType()); - PlatformIdGenerator rootIdGen = rootBeanInfo.getDescriptor().getIdGenerator(); - if (rootIdGen != null) { - descriptor.setIdGenerator(rootIdGen); - } - } - } - } - /** * Create the BeanTable from the deployment information gathered so far. */ @@ -644,9 +622,6 @@ private void readEntityRelationships() { for (DeployBeanInfo info : deployInfoMap.values()) { secondaryPropsJoins(info); } - for (DeployBeanInfo info : deployInfoMap.values()) { - setInheritanceInfo(info); - } for (DeployBeanInfo info : deployInfoMap.values()) { if (!info.isEmbedded()) { registerDescriptor(info); @@ -654,28 +629,6 @@ private void readEntityRelationships() { } } - /** - * Sets the inheritance info. - */ - private void setInheritanceInfo(DeployBeanInfo info) { - for (DeployBeanPropertyAssocOne oneProp : info.getDescriptor().propertiesAssocOne()) { - if (!oneProp.isTransient()) { - DeployBeanInfo assoc = deployInfoMap.get(oneProp.getTargetType()); - if (assoc != null) { - oneProp.getTableJoin().setInheritInfo(assoc.getDescriptor().getInheritInfo()); - } - } - } - for (DeployBeanPropertyAssocMany manyProp : info.getDescriptor().propertiesAssocMany()) { - if (!manyProp.isTransient()) { - DeployBeanInfo assoc = deployInfoMap.get(manyProp.getTargetType()); - if (assoc != null) { - manyProp.getTableJoin().setInheritInfo(assoc.getDescriptor().getInheritInfo()); - } - } - } - } - private void secondaryPropsJoins(DeployBeanInfo info) { DeployBeanDescriptor descriptor = info.getDescriptor(); for (DeployBeanProperty prop : descriptor.propertiesBase()) { @@ -809,13 +762,6 @@ private void makeOrderColumn(DeployBeanPropertyAssocMany oneToMany) { orderProperty.setDbUpdateable(orderColumn.isUpdatable()); orderProperty.setDbRead(true); orderProperty.setOwningType(targetDesc.getBeanType()); - final InheritInfo targetInheritInfo = targetDesc.getInheritInfo(); - if (targetInheritInfo != null) { - for (InheritInfo child : targetInheritInfo.getChildren()) { - final DeployBeanDescriptor childDescriptor = deployInfoMap.get(child.getType()).getDescriptor(); - childDescriptor.setOrderColumn(orderProperty); - } - } targetDesc.setOrderColumn(orderProperty); } @@ -1063,9 +1009,6 @@ private DeployBeanInfo createDeployBeanInfo(Class beanClass) { beanLifecycleAdapterFactory.addLifecycleMethods(desc); // set bean controller, finder and listener setBeanControllerFinderListener(desc); - deplyInherit.process(desc); - desc.checkInheritanceMapping(); - createProperties.createProperties(desc); DeployBeanInfo info = new DeployBeanInfo<>(deployUtil, desc); readAnnotations.readInitial(info); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java index 966ef21774..4131163dcd 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java @@ -4,9 +4,6 @@ import io.ebean.SqlUpdate; import io.ebean.Transaction; import io.ebean.bean.EntityBean; -import io.ebean.core.type.DocPropertyType; -import io.ebean.text.PathProperties; -import io.ebean.util.SplitName; import io.ebeaninternal.api.CoreLog; import io.ebeaninternal.api.SpiEbeanServer; import io.ebeaninternal.api.SpiQuery; @@ -42,7 +39,6 @@ public abstract class BeanPropertyAssoc extends BeanProperty implements STree */ BeanDescriptor targetDescriptor; IdBinder targetIdBinder; - InheritInfo targetInheritInfo; String targetIdProperty; /** * Derived list of exported property and matching foreignKey @@ -115,7 +111,6 @@ void initialiseTargetDescriptor(BeanDescriptorInitContext initContext) { targetDescriptor = descriptor.descriptor(targetType); if (!isTransient) { targetIdBinder = targetDescriptor.idBinder(); - targetInheritInfo = targetDescriptor.inheritInfo(); saveRecurseSkippable = targetDescriptor.isSaveRecurseSkippable(); if (!targetIdBinder.isComplexId()) { targetIdProperty = targetIdBinder.idSelect(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocOne.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocOne.java index 780178fef6..c87bd65fd2 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocOne.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocOne.java @@ -17,7 +17,6 @@ import io.ebeaninternal.api.json.SpiJsonWriter; import io.ebeaninternal.server.cache.CacheChangeSet; import io.ebeaninternal.server.cache.CachedBeanData; -import io.ebeaninternal.server.cache.CachedBeanId; import io.ebeaninternal.server.core.DefaultSqlUpdate; import io.ebeaninternal.server.deploy.id.ImportedId; import io.ebeaninternal.server.deploy.meta.DeployBeanPropertyAssocOne; @@ -125,6 +124,9 @@ private void initialiseAssocOne(String embeddedPrefix) { // no imported or exported information } else if (!oneToOneExported) { importedId = createImportedId(this, targetDescriptor, tableJoin); + if (importedId == null) { + throw new IllegalStateException("Missing @Id property on " + targetDescriptor); + } if (importedId.isScalar()) { // limit JoinColumn mapping to the @Id / primary key TableJoinColumn[] columns = tableJoin.columns(); @@ -319,15 +321,6 @@ public BeanProperty[] properties() { public void buildRawSqlSelectChain(String prefix, List selectChain) { prefix = SplitName.add(prefix, name); if (!embedded) { - InheritInfo inheritInfo = targetDescriptor.inheritInfo(); - if (inheritInfo != null) { - // expect the discriminator column to be included in order - // to determine the inheritance type so we add it to the - // selectChain (so that it takes a position in the resultSet) - String discriminatorColumn = inheritInfo.getDiscriminatorColumn(); - String discProperty = prefix + "." + discriminatorColumn; - selectChain.add(discProperty); - } if (targetIdBinder == null) { throw new IllegalStateException("No Id binding property for " + fullName() + ". Probably a missing @OneToOne mapping annotation on this relationship?"); @@ -420,19 +413,11 @@ private Object cacheDataConvert(Object ap) { } if (embedded) { return targetDescriptor.cacheEmbeddedBeanExtract((EntityBean) ap); - } else if (targetInheritInfo != null) { - return createCacheBeanId(ap); } else { return targetDescriptor.idProperty().getCacheDataValue((EntityBean) ap); } } - private Object createCacheBeanId(Object bean) { - final BeanDescriptor desc = targetDescriptor.descOf(bean.getClass()); - final Object id = desc.idProperty().getCacheDataValue((EntityBean) bean); - return new CachedBeanId(desc.discValue(), id); - } - @Override public String format(Object value) { return targetDescriptor.idBinder().cacheKey(value); @@ -446,20 +431,11 @@ public void setCacheDataValue(EntityBean bean, Object cacheData, PersistenceCont if (embedded) { setValue(bean, targetDescriptor.cacheEmbeddedBeanLoad((CachedBeanData) cacheData, context)); } else { - if (cacheData instanceof CachedBeanId) { - setValue(bean, refInheritBean((CachedBeanId) cacheData, context)); - } else { - setValue(bean, refBean(targetDescriptor, cacheData, context)); - } + setValue(bean, refBean(targetDescriptor, cacheData, context)); } } } - private Object refInheritBean(CachedBeanId cacheId, PersistenceContext context) { - final InheritInfo rowInheritInfo = targetInheritInfo.readType(cacheId.getDiscValue()); - return refBean(rowInheritInfo.desc(), cacheId.getId(), context); - } - private Object refBean(BeanDescriptor desc, Object id, PersistenceContext context) { if (id instanceof String) { id = desc.idProperty().scalarType.parse((String) id); @@ -718,11 +694,7 @@ private AssocOneHelp createHelp(boolean embedded, boolean oneToOneExported, Stri } else if (oneToOneExported) { return new AssocOneHelpRefExported(this); } else { - if (targetInheritInfo != null) { - return new AssocOneHelpRefInherit(this); - } else { - return new AssocOneHelpRefSimple(this, embeddedPrefix); - } + return new AssocOneHelpRefSimple(this, embeddedPrefix); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/InheritInfo.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/InheritInfo.java deleted file mode 100644 index e72d7463dd..0000000000 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/InheritInfo.java +++ /dev/null @@ -1,360 +0,0 @@ -package io.ebeaninternal.server.deploy; - -import io.ebean.bean.EntityBean; -import io.ebeaninternal.server.core.InternString; -import io.ebeaninternal.server.deploy.id.IdBinder; -import io.ebeaninternal.server.deploy.parse.DeployInheritInfo; -import io.ebeaninternal.server.query.SqlTreeProperties; - -import javax.persistence.PersistenceException; -import java.lang.reflect.Modifier; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Set; - -/** - * Represents a node in the Inheritance tree. Holds information regarding Super Subclass support. - */ -public final class InheritInfo { - - private final String discriminatorStringValue; - private final Object discriminatorValue; - private final String discriminatorColumn; - private final int discriminatorType; - private final int discriminatorLength; - private final String columnDefn; - private final String where; - private final Class type; - private final List children = new ArrayList<>(); - /** - * Map of discriminator values to InheritInfo. - */ - private final HashMap discMap; - /** - * Map of class types to InheritInfo (taking into account subclass proxy classes). - */ - private final HashMap typeMap; - private final InheritInfo parent; - private final InheritInfo root; - private BeanDescriptor descriptor; - - public InheritInfo(InheritInfo r, InheritInfo parent, DeployInheritInfo deploy) { - this.parent = parent; - this.type = deploy.getType(); - this.discriminatorColumn = InternString.intern(deploy.getColumnName(parent)); - this.discriminatorValue = deploy.getDiscriminatorObjectValue(); - this.discriminatorStringValue = deploy.getDiscriminatorStringValue(); - this.discriminatorType = deploy.getDiscriminatorType(parent); - this.discriminatorLength = deploy.getColumnLength(parent); - this.columnDefn = deploy.getColumnDefn(); - this.where = InternString.intern(deploy.getWhere()); - if (r == null) { - // this is a root node - root = this; - discMap = new HashMap<>(); - typeMap = new HashMap<>(); - registerWithRoot(this); - } else { - this.root = r; - // register with the root node... - discMap = null; - typeMap = null; - root.registerWithRoot(this); - } - } - - /** - * Visit all the children in the inheritance tree. - */ - public void visitChildren(InheritInfoVisitor visitor) { - for (InheritInfo child : children) { - visitor.visit(child); - child.visitChildren(visitor); - } - } - - /** - * Append check constraint values for the entire inheritance hierarchy. - */ - public void appendCheckConstraintValues(final String propertyName, final Set checkConstraintValues) { - visitChildren(inheritInfo -> { - BeanProperty prop = inheritInfo.desc().beanProperty(propertyName); - if (prop != null) { - Set values = prop.dbCheckConstraintValues(); - if (values != null) { - checkConstraintValues.addAll(values); - } - } - }); - } - - /** - * return true if anything in the inheritance hierarchy has a relationship with a save cascade on - * it. - */ - boolean isSaveRecurseSkippable() { - return root.isNodeSaveRecurseSkippable(); - } - - private boolean isNodeSaveRecurseSkippable() { - if (!descriptor.isSaveRecurseSkippable()) { - return false; - } - for (InheritInfo child : children) { - if (!child.isNodeSaveRecurseSkippable()) { - return false; - } - } - return true; - } - - /** - * return true if anything in the inheritance hierarchy has a relationship with a delete cascade - * on it. - */ - boolean isDeleteRecurseSkippable() { - return root.isNodeDeleteRecurseSkippable(); - } - - private boolean isNodeDeleteRecurseSkippable() { - if (!descriptor.isDeleteRecurseSkippable()) { - return false; - } - for (InheritInfo child : children) { - if (!child.isNodeDeleteRecurseSkippable()) { - return false; - } - } - return true; - } - - /** - * Set the descriptor for this node. - */ - public void setDescriptor(BeanDescriptor descriptor) { - this.descriptor = descriptor; - } - - /** - * Return the associated BeanDescriptor for this node. - */ - public BeanDescriptor desc() { - return descriptor; - } - - /** - * Return the local properties for this node in the hierarchy. - */ - public BeanProperty[] localProperties() { - return descriptor.propertiesLocal(); - } - - /** - * Return the children. - */ - public List getChildren() { - return children; - } - - /** - * Return true if this node has children. - *

- * When an inheritance node has no children then we don't need - * the discriminator column as the type is effectively known. - */ - public boolean hasChildren() { - return !children.isEmpty(); - } - - /** - * Get the bean property additionally looking in the sub types. - */ - BeanProperty findSubTypeProperty(String propertyName) { - BeanProperty prop; - for (InheritInfo childInfo : children) { - // recursively search this child bean descriptor - prop = childInfo.desc().findProperty(propertyName); - if (prop != null) { - return prop; - } - } - return null; - } - - /** - * Add the local properties for each sub class below this one. - */ - public void addChildrenProperties(SqlTreeProperties selectProps) { - for (InheritInfo childInfo : children) { - selectProps.add(childInfo.descriptor.propertiesLocal()); - childInfo.addChildrenProperties(selectProps); - } - } - - /** - * Return the associated InheritInfo for this DB row read. - */ - public InheritInfo readType(DbReadContext ctx) throws SQLException { - return readType(ctx.dataReader().getString()); - } - - /** - * Return the associated InheritInfo for this discriminator value. - */ - InheritInfo readType(String discValue) { - if (discValue == null) { - return null; - } - InheritInfo typeInfo = root.getType(discValue); - if (typeInfo == null) { - throw new PersistenceException("Inheritance type for discriminator value [" + discValue + "] was not found?"); - } - return typeInfo; - } - - /** - * Return the associated InheritInfo for this bean type. - */ - public InheritInfo readType(Class beanType) { - InheritInfo typeInfo = root.getTypeByClass(beanType); - if (typeInfo == null) { - throw new PersistenceException("Inheritance type for bean type [" + beanType.getName() + "] was not found?"); - } - return typeInfo; - } - - /** - * Create an EntityBean for this type. - */ - public EntityBean createEntityBean() { - return descriptor.createEntityBean(); - } - - /** - * Return the IdBinder for this type. - */ - public IdBinder getIdBinder() { - return descriptor.idBinder(); - } - - /** - * return the type. - */ - public Class getType() { - return type; - } - - /** - * Return the root node of the tree. - *

- * The root has a map of discriminator values to types. - *

- */ - public InheritInfo getRoot() { - return root; - } - - /** - * Return the parent node. - */ - public InheritInfo getParent() { - return parent; - } - - /** - * Return true if this is the root node. - */ - public boolean isRoot() { - return parent == null; - } - - /** - * Return true if this is considered a concrete type in the inheritance hierarchy. - */ - public boolean isConcrete() { - return !Modifier.isAbstract(type.getModifiers()); - } - - /** - * For a discriminator get the inheritance information for this tree. - */ - public InheritInfo getType(String discValue) { - return discMap.get(discValue); - } - - /** - * Return the InheritInfo for the given bean type. - */ - private InheritInfo getTypeByClass(Class beanType) { - return typeMap.get(beanType.getName()); - } - - private void registerWithRoot(InheritInfo info) { - if (info.getDiscriminatorStringValue() != null) { - String stringDiscValue = info.getDiscriminatorStringValue(); - discMap.put(stringDiscValue, info); - } - typeMap.put(info.getType().getName(), info); - } - - /** - * Add a child node. - */ - public void addChild(InheritInfo childInfo) { - children.add(childInfo); - } - - /** - * Return the derived where for the discriminator. - */ - public String getWhere() { - return where; - } - - /** - * Return the column name of the discriminator. - */ - public String getDiscriminatorColumn() { - return discriminatorColumn; - } - - /** - * Return the sql type of the discriminator value. - */ - public int getDiscriminatorType() { - return discriminatorType; - } - - /** - * Return the length of the discriminator column. - */ - public int getColumnLength() { - return discriminatorLength; - } - - /** - * Return the explicit column definition. - */ - public String getColumnDefn() { - return columnDefn; - } - - /** - * Return the discriminator value for this node. - */ - String getDiscriminatorStringValue() { - return discriminatorStringValue; - } - - public Object getDiscriminatorValue() { - return discriminatorValue; - } - - @Override - public String toString() { - return "InheritInfo " + type.getName() + " disc:" + discriminatorStringValue; - } - -} diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/InheritInfoVisitor.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/InheritInfoVisitor.java deleted file mode 100644 index b23b4119b7..0000000000 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/InheritInfoVisitor.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.ebeaninternal.server.deploy; - -/** - * Used to visit all the InheritInfo in a single inheritance hierarchy. - */ -public interface InheritInfoVisitor { - - /** - * visit the InheritInfo for this node. - */ - void visit(InheritInfo inheritInfo); - -} diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/TableJoin.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/TableJoin.java index 3618dc3c2f..ecd790dfde 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/TableJoin.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/TableJoin.java @@ -21,8 +21,6 @@ public final class TableJoin { */ private final SqlJoinType type; - private final InheritInfo inheritInfo; - /** * Columns as an array. */ @@ -49,7 +47,6 @@ public TableJoin(DeployTableJoin deploy, PropertyForeignKey foreignKey) { this.extraWhere = deploy.getExtraWhere(); this.table = InternString.intern(deploy.getTable()); this.type = deploy.getType(); - this.inheritInfo = deploy.getInheritInfo(); DeployTableJoinColumn[] deployCols = deploy.columns(); this.columns = new TableJoinColumn[deployCols.length]; for (int i = 0; i < deployCols.length; i++) { @@ -63,7 +60,6 @@ private TableJoin(TableJoin source, String overrideColumn) { this.extraWhere = source.extraWhere; this.table = source.table; this.type = source.type; - this.inheritInfo = source.inheritInfo; this.columns = new TableJoinColumn[1]; this.columns[0] = source.columns[0].withOverrideColumn(overrideColumn); this.queryHash = calcQueryHash(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java index af8582dae3..77d9d714ce 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java @@ -1,8 +1,6 @@ package io.ebeaninternal.server.deploy.meta; import io.ebean.annotation.Cache; -import io.ebean.annotation.DocStore; -import io.ebean.annotation.DocStoreMode; import io.ebean.annotation.Identity; import io.ebean.config.DatabaseConfig; import io.ebean.config.TableName; @@ -10,7 +8,6 @@ import io.ebean.config.dbplatform.PlatformIdGenerator; import io.ebean.event.*; import io.ebean.event.changelog.ChangeLogFilter; -import io.ebean.text.PathProperties; import io.ebean.util.SplitName; import io.ebeaninternal.api.ConcurrencyMode; import io.ebeaninternal.server.core.CacheOptions; @@ -21,8 +18,6 @@ import io.ebeaninternal.server.idgen.UuidV1RndIdGenerator; import io.ebeaninternal.server.idgen.UuidV4IdGenerator; -import javax.persistence.Entity; -import javax.persistence.MappedSuperclass; import java.util.*; /** @@ -96,7 +91,6 @@ public int compare(DeployBeanProperty o1, DeployBeanProperty o2) { /** * Inheritance information. Server side only. */ - private InheritInfo inheritInfo; private String name; private ChangeLogFilter changeLogFilter; private String dbComment; @@ -307,21 +301,6 @@ public ChangeLogFilter getChangeLogFilter() { return changeLogFilter; } - /** - * Returns the Inheritance mapping information. This will be null if this type - * of bean is not involved in any ORM inheritance mapping. - */ - public InheritInfo getInheritInfo() { - return inheritInfo; - } - - /** - * Set the ORM inheritance mapping information. - */ - public void setInheritInfo(InheritInfo inheritInfo) { - this.inheritInfo = inheritInfo; - } - /** * Set that this type invalidates query caches. */ @@ -853,35 +832,6 @@ public List propertiesBase() { return list; } - /** - * Check the mapping for class inheritance - */ - public void checkInheritanceMapping() { - if (inheritInfo == null) { - checkInheritance(getBeanType()); - } - } - - /** - * Check valid mapping annotations on the class hierarchy. - */ - private void checkInheritance(Class beanType) { - - Class parent = beanType.getSuperclass(); - if (parent == null || Object.class.equals(parent)) { - // all good - return; - } - if (parent.isAnnotationPresent(Entity.class)) { - String msg = "Checking " + getBeanType() + " and found " + parent + " that has @Entity annotation rather than MappedSuperclass?"; - throw new IllegalStateException(msg); - } - if (parent.isAnnotationPresent(MappedSuperclass.class)) { - // continue checking - checkInheritance(parent); - } - } - /** * Parse the aggregation formula into expressions with table alias placeholders. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanPropertyLists.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanPropertyLists.java index 2f21c6788c..a2c16f2512 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanPropertyLists.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanPropertyLists.java @@ -5,7 +5,6 @@ import io.ebeaninternal.server.deploy.*; import io.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty; import io.ebeaninternal.server.properties.BeanPropertySetter; -import io.ebeaninternal.server.type.ScalarTypeString; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -27,7 +26,6 @@ public final class DeployBeanPropertyLists { private final LinkedHashMap propertyMap; private BeanProperty id; - private final List local = new ArrayList<>(); private final List mutable = new ArrayList<>(); private final List> manys = new ArrayList<>(); private final List nonManys = new ArrayList<>(); @@ -57,35 +55,9 @@ public DeployBeanPropertyLists(BeanDescriptorMap owner, BeanDescriptor desc, DeployBeanPropertyAssocOne deployUnidirectional = deploy.getUnidirectional(); this.unidirectional = deployUnidirectional == null ? null : new BeanPropertyAssocOne<>(owner, desc, deployUnidirectional); - this.propertyMap = new LinkedHashMap<>(); - // see if there is a discriminator property we should add - String discriminatorColumn = null; - BeanProperty discProperty = null; - - InheritInfo inheritInfo = deploy.getInheritInfo(); - if (inheritInfo != null) { - // Create a BeanProperty for the discriminator column to support - // using RawSql queries with inheritance - discriminatorColumn = inheritInfo.getDiscriminatorColumn(); - DeployBeanProperty discDeployProp = new DeployBeanProperty(deploy, String.class, ScalarTypeString.INSTANCE, null); - discDeployProp.setDiscriminator(); - discDeployProp.setName(discriminatorColumn); - discDeployProp.setDbColumn(discriminatorColumn); - discDeployProp.setSetter(NOOP_SETTER); - - // only register it in the propertyMap. This might not be used if - // an explicit property is mapped to the discriminator on the bean - discProperty = new BeanProperty(desc, discDeployProp); - } - for (DeployBeanProperty prop : deploy.propertiesAll()) { - if (discriminatorColumn != null && discriminatorColumn.equals(prop.getDbColumn())) { - // we have an explicit property mapped to the discriminator column - prop.setDiscriminator(); - discProperty = null; - } BeanProperty beanProp = createBeanProperty(owner, prop); propertyMap.put(beanProp.name(), beanProp); } @@ -101,12 +73,6 @@ public DeployBeanPropertyLists(BeanDescriptorMap owner, BeanDescriptor desc, allocateToList(orderColumn); propertyMap.put(orderColumn.name(), orderColumn); } - - if (discProperty != null) { - // put the discriminator property into the property map only - // (after the real properties have been organised into their lists) - propertyMap.put(discProperty.name(), discProperty); - } } /** @@ -188,10 +154,6 @@ private void allocateToList(BeanProperty prop) { mutable.add(prop); } - if (desc.inheritInfo() != null && prop.isLocal()) { - local.add(prop); - } - if (prop instanceof BeanPropertyAssocMany) { manys.add((BeanPropertyAssocMany) prop); @@ -257,10 +219,6 @@ public BeanProperty getVersionProperty() { return versionProperty; } - public BeanProperty[] getLocal() { - return local.toArray(new BeanProperty[0]); - } - public BeanProperty[] getMutable() { return mutable.toArray(new BeanProperty[0]); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployTableJoin.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployTableJoin.java index 0f3ed54c1a..fa2f600fb5 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployTableJoin.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployTableJoin.java @@ -1,7 +1,6 @@ package io.ebeaninternal.server.deploy.meta; import io.ebeaninternal.server.deploy.BeanTable; -import io.ebeaninternal.server.deploy.InheritInfo; import io.ebeaninternal.server.deploy.parse.DeployUtil; import io.ebeaninternal.server.query.SqlJoinType; @@ -29,7 +28,6 @@ public final class DeployTableJoin { * The list of join column pairs. Used to generate the on clause. */ private ArrayList columns = new ArrayList<>(4); - private InheritInfo inheritInfo; private String extraWhere; /** @@ -171,14 +169,6 @@ private DeployTableJoin copyInternal(DeployTableJoin destJoin, boolean reverse, return destJoin; } - public InheritInfo getInheritInfo() { - return inheritInfo; - } - - public void setInheritInfo(InheritInfo inheritInfo) { - this.inheritInfo = inheritInfo; - } - /** * Change the join column (based on imported primary key match on property name etc). */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java index 1acee6f298..776b7fbf95 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java @@ -6,7 +6,6 @@ import io.ebeaninternal.api.CoreLog; import io.ebeaninternal.server.deploy.BeanDescriptor.EntityType; import io.ebeaninternal.server.deploy.IndexDefinition; -import io.ebeaninternal.server.deploy.InheritInfo; import io.ebeaninternal.server.deploy.PartitionMeta; import io.ebeaninternal.server.deploy.TablespaceMeta; import io.ebeaninternal.server.deploy.meta.DeployBeanProperty; @@ -69,10 +68,6 @@ public void parse() { private void setTableName() { if (descriptor.isBaseTableType()) { Class beanType = descriptor.getBeanType(); - InheritInfo inheritInfo = descriptor.getInheritInfo(); - if (inheritInfo != null) { - beanType = inheritInfo.getRoot().getType(); - } // default the TableName using NamingConvention. TableName tableName = namingConvention.getTableName(beanType); descriptor.setBaseTable(tableName, asOfViewSuffix, versionsBetweenSuffix); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInherit.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInherit.java deleted file mode 100644 index 4eb2fa6402..0000000000 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInherit.java +++ /dev/null @@ -1,140 +0,0 @@ -package io.ebeaninternal.server.deploy.parse; - -import io.ebean.util.AnnotationUtil; -import io.ebeaninternal.server.core.bootup.BootupClasses; -import io.ebeaninternal.server.deploy.InheritInfo; -import io.ebeaninternal.server.deploy.meta.DeployBeanDescriptor; - -import javax.persistence.DiscriminatorColumn; -import javax.persistence.DiscriminatorType; -import javax.persistence.DiscriminatorValue; -import javax.persistence.Inheritance; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * Builds the InheritInfo deployment information. - */ -public final class DeployInherit { - - private final Map, DeployInheritInfo> deployMap = new LinkedHashMap<>(); - - private final Map, InheritInfo> finalMap = new LinkedHashMap<>(); - private final BootupClasses bootupClasses; - - /** - * Create the InheritInfoDeploy. - */ - public DeployInherit(BootupClasses bootupClasses) { - this.bootupClasses = bootupClasses; - initialise(); - } - - public void process(DeployBeanDescriptor desc) { - InheritInfo inheritInfo = finalMap.get(desc.getBeanType()); - desc.setInheritInfo(inheritInfo); - } - - private void initialise() { - findInheritClasses(bootupClasses.getEntities()); - buildDeployTree(); - buildFinalTree(); - } - - private void findInheritClasses(List> entityList) { - // go through each class and initialise the info object... - for (Class cls : entityList) { - if (isInheritanceClass(cls)) { - deployMap.put(cls, createInfo(cls)); - } - } - } - - private void buildDeployTree() { - for (DeployInheritInfo info : deployMap.values()) { - if (!info.isRoot()) { - DeployInheritInfo parent = getInfo(info.getParent()); - parent.addChild(info); - } - } - } - - private void buildFinalTree() { - for (DeployInheritInfo deploy : deployMap.values()) { - if (deploy.isRoot()) { - // build tree top down... - createFinalInfo(null, null, deploy); - } - } - } - - private void createFinalInfo(InheritInfo root, InheritInfo parent, DeployInheritInfo deploy) { - InheritInfo node = new InheritInfo(root, parent, deploy); - if (parent != null) { - parent.addChild(node); - } - finalMap.put(node.getType(), node); - if (root == null) { - root = node; - } - // buildFinalChildren(root, child, deploy); - for (DeployInheritInfo childDeploy : deploy.children()) { - createFinalInfo(root, node, childDeploy); - } - } - - /** - * Build the InheritInfo for a given class. - */ - private DeployInheritInfo getInfo(Class cls) { - return deployMap.get(cls); - } - - private DeployInheritInfo createInfo(Class cls) { - DeployInheritInfo info = new DeployInheritInfo(cls); - Class parent = findParent(cls); - if (parent != null) { - info.setParent(parent); - } - - Inheritance ia = AnnotationUtil.typeGet(cls, Inheritance.class); - if (ia != null) { - ia.strategy(); - } - DiscriminatorColumn da = AnnotationUtil.typeGet(cls, DiscriminatorColumn.class); - if (da != null) { - // lowercase the discriminator column for RawSql and JSON - info.setColumnName(da.name().toLowerCase()); - DiscriminatorType discriminatorType = da.discriminatorType(); - info.setColumnType(discriminatorType); - if (discriminatorType == DiscriminatorType.STRING) { - info.setColumnLength(da.length()); - } - info.setColumnDefn(da.columnDefinition()); - } - if (!info.isAbstract()) { - DiscriminatorValue dv = AnnotationUtil.get(cls, DiscriminatorValue.class); // do not search recursive - if (dv != null) { - info.setDiscriminatorValue(dv.value()); - } else { - info.setDiscriminatorDefaultValue(cls); - } - } - return info; - } - - private Class findParent(Class cls) { - Class superCls = cls.getSuperclass(); - if (isInheritanceClass(superCls)) { - return superCls; - } else { - return null; - } - } - - private boolean isInheritanceClass(Class cls) { - return AnnotationUtil.typeHas(cls, Inheritance.class); - } - -} diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java deleted file mode 100644 index 1e75c98f2a..0000000000 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java +++ /dev/null @@ -1,270 +0,0 @@ -package io.ebeaninternal.server.deploy.parse; - -import io.ebeaninternal.server.deploy.InheritInfo; - -import java.lang.reflect.Modifier; -import javax.persistence.DiscriminatorType; -import java.sql.Types; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - -/** - * Represents a node in the Inheritance tree. - * Holds information regarding Super Subclass support. - */ -public final class DeployInheritInfo implements Comparable { - - /** - * the default discriminator column according to the JPA 1.0 spec. - */ - private static final String DEFAULT_COLUMN_NAME = "dtype"; - - private String discriminatorStringValue; - private Object discriminatorObjectValue; - private int columnType; - private String columnName; - private int columnLength; - private String columnDefn; - private final Class type; - private Class parent; - private final Set children = new TreeSet<>(); - - /** - * Create for a given type. - */ - DeployInheritInfo(Class type) { - this.type = type; - } - - /** - * return the type. - */ - public Class getType() { - return type; - } - - /** - * Return the type of the root object. - */ - public Class getParent() { - return parent; - } - - /** - * Set the type of the root object. - */ - public void setParent(Class parent) { - this.parent = parent; - } - - /** - * Return true if this is abstract node. - */ - public boolean isAbstract() { - return Modifier.isAbstract(type.getModifiers()); - } - - /** - * Return true if this is the root node. - */ - public boolean isRoot() { - return parent == null; - } - - /** - * Return the child nodes. - */ - public Set children() { - return children; - } - - /** - * Add a child node. - */ - public void addChild(DeployInheritInfo childInfo) { - children.add(childInfo); - } - - /** - * Return the column name of the discriminator. - */ - public String getColumnName(InheritInfo parent) { - if (columnName == null) { - if (parent == null) { - columnName = DEFAULT_COLUMN_NAME; - } else { - columnName = parent.getDiscriminatorColumn(); - } - } - return columnName; - } - - /** - * Set the column name of the discriminator. - */ - public void setColumnName(String columnName) { - this.columnName = columnName; - } - - public int getColumnLength(InheritInfo parent) { - if (columnLength == 0) { - if (parent == null) { - columnLength = 31; - } else { - columnLength = parent.getColumnLength(); - } - } - return columnLength; - } - - /** - * Return the sql type of the discriminator value. - */ - public int getDiscriminatorType(InheritInfo parent) { - if (columnType == 0) { - if (parent == null) { - columnType = Types.VARCHAR; - } else { - columnType = parent.getDiscriminatorType(); - } - } - return columnType; - } - - /** - * Set the sql type of the discriminator. - */ - void setColumnType(DiscriminatorType type) { - if (type == DiscriminatorType.INTEGER) { - this.columnType = Types.INTEGER; - } else { - this.columnType = Types.VARCHAR; - } - } - - /** - * Set explicit column definition (ddl). - */ - void setColumnDefn(String columnDefn) { - this.columnDefn = columnDefn; - } - - /** - * Return the explicit column definition. - */ - public String getColumnDefn() { - return columnDefn; - } - - /** - * Set the length of the discriminator column. - */ - void setColumnLength(int columnLength) { - this.columnLength = columnLength; - } - - /** - * Return the discriminator value for this node. - */ - public Object getDiscriminatorObjectValue() { - return discriminatorObjectValue; - } - - public String getDiscriminatorStringValue() { - return discriminatorStringValue; - } - - public void setDiscriminatorDefaultValue(Class cls) { - if (columnType == Types.INTEGER) { - discriminatorStringValue = "0"; - discriminatorObjectValue = 0; - } else { - discriminatorStringValue = cls.getSimpleName(); - discriminatorObjectValue = discriminatorStringValue; - } - } - - /** - * Set the discriminator value for this node. - */ - void setDiscriminatorValue(String value) { - if (value != null) { - value = value.trim(); - if (!value.isEmpty()) { - discriminatorStringValue = value; - // convert the value if desired - if (columnType == Types.INTEGER) { - this.discriminatorObjectValue = Integer.valueOf(value); - } else { - this.discriminatorObjectValue = value; - } - } - } - } - - public String getWhere() { - List discList = new ArrayList<>(); - appendDiscriminator(discList); - return buildWhereLiteral(discList); - } - - private void appendDiscriminator(List list) { - if (!isAbstract()) { - list.add(discriminatorObjectValue); - } - for (DeployInheritInfo child : children) { - child.appendDiscriminator(list); - } - } - - private String buildWhereLiteral(List discList) { - int size = discList.size(); - if (size == 0) { - return ""; - } - StringBuilder sb = new StringBuilder(); - sb.append(columnName); - if (size == 1) { - sb.append(" = "); - } else { - sb.append(" in ("); - } - for (int i = 0; i < discList.size(); i++) { - appendSqlLiteralValue(i, discList.get(i), sb); - } - if (size > 1) { - sb.append(')'); - } - return sb.toString(); - } - - private void appendSqlLiteralValue(int count, Object value, StringBuilder sb) { - if (count > 0) { - sb.append(','); - } - if (value instanceof String) { - sb.append('\'').append(value).append('\''); - } else { - sb.append(value); - } - } - - @Override - public String toString() { - String root = parent == null ? null : parent.getName(); - String name = type == null ? null : type.getName(); - return "InheritInfo " + name + " root:" + root + " disc:" + discriminatorStringValue; - } - - @Override - public int compareTo(DeployInheritInfo other) { - if (other == this) { - return 0; - } else { - return type.getName().compareTo(other.type.getName()); - } - } - -} diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/visitor/VisitProperties.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/visitor/VisitProperties.java index 43362320b9..ae8b8ed3a5 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/visitor/VisitProperties.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/visitor/VisitProperties.java @@ -4,8 +4,6 @@ import io.ebeaninternal.server.deploy.BeanProperty; import io.ebeaninternal.server.deploy.BeanPropertyAssocMany; import io.ebeaninternal.server.deploy.BeanPropertyAssocOne; -import io.ebeaninternal.server.deploy.InheritInfo; -import io.ebeaninternal.server.deploy.InheritInfoVisitor; /** * Makes use of BeanVisitor and PropertyVisitor to navigate BeanDescriptors @@ -34,7 +32,6 @@ protected void visitProperties(BeanDescriptor desc, BeanPropertyVisitor prope visit(propertyVisitor, p); } } - visitInheritanceProperties(desc, propertyVisitor); propertyVisitor.visitEnd(); } @@ -68,40 +65,4 @@ protected void visit(BeanPropertyVisitor pv, BeanProperty p) { } } - - /** - * Visit all the other inheritance properties that are not on the root. - */ - protected void visitInheritanceProperties(BeanDescriptor descriptor, BeanPropertyVisitor pv) { - InheritInfo inheritInfo = descriptor.inheritInfo(); - if (inheritInfo != null && inheritInfo.isRoot()) { - // add all properties on the children objects - inheritInfo.visitChildren(new InheritChildVisitor(this, pv)); - } - } - - - /** - * Helper used to visit all the inheritInfo/BeanDescriptor in - * the inheritance hierarchy (to add their 'local' properties). - */ - protected static class InheritChildVisitor implements InheritInfoVisitor { - - private final VisitProperties owner; - private final BeanPropertyVisitor pv; - - protected InheritChildVisitor(VisitProperties owner, BeanPropertyVisitor pv) { - this.owner = owner; - this.pv = pv; - } - - @Override - public void visit(InheritInfo inheritInfo) { - for (BeanProperty beanProperty : inheritInfo.desc().propertiesLocal()) { - if (beanProperty.isDDLColumn()) { - owner.visit(pv, beanProperty); - } - } - } - } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadContext.java b/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadContext.java index 25626b9a91..f2877058b7 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadContext.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadContext.java @@ -42,7 +42,6 @@ public final class DLoadContext implements LoadContext { private final ProfilingListener profilingListener; private final Map nodePathMap = new HashMap<>(); private final PersistenceContext persistenceContext; - boolean useReferences; private List secQuery; private Object tenantId; @@ -134,11 +133,6 @@ private void registerSecondaryQueries(SpiQuerySecondary secondaryQueries) { } } - @Override - public void useReferences(boolean useReferences) { - this.useReferences = useReferences; - } - /** * Setup the load context at this path with OrmQueryProperties which is * used to build the appropriate query for +query or +lazy loading. diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadManyContext.java b/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadManyContext.java index af7f7d52a7..079363c84d 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadManyContext.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadManyContext.java @@ -10,8 +10,6 @@ import io.ebeaninternal.server.deploy.BeanPropertyAssocMany; import io.ebeaninternal.server.querydefn.OrmQueryProperties; -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -35,7 +33,7 @@ final class DLoadManyContext extends DLoadBaseContext implements LoadManyContext } private LoadBuffer createBuffer(int size) { - LoadBuffer buffer = parent.useReferences ? new LoadBufferWeakRef(this, size) : new LoadBufferHardRef(this, size); + LoadBuffer buffer = new LoadBuffer(this, size); if (bufferList != null) { bufferList.add(buffer); } @@ -112,12 +110,14 @@ public void loadSecondaryQuery(OrmQueryRequest parentRequest, boolean forEach * A buffer for batch loading bean collections on a given path. * Supports batch lazy loading and secondary query loading. */ - static abstract class LoadBuffer implements BeanCollectionLoader, LoadManyBuffer { + static final class LoadBuffer implements BeanCollectionLoader, LoadManyBuffer { private final ReentrantLock lock = new ReentrantLock(); private final PersistenceContext persistenceContext; private final DLoadManyContext context; - final int batchSize; + private final int batchSize; + private final BeanCollection[] list; + private int size; LoadBuffer(DLoadManyContext context, int batchSize) { this.context = context; @@ -125,6 +125,7 @@ static abstract class LoadBuffer implements BeanCollectionLoader, LoadManyBuffer // case it changes as part of a findIterate etc this.persistenceContext = context.persistenceContext(); this.batchSize = batchSize; + this.list = new BeanCollection[batchSize]; } @Override @@ -139,13 +140,6 @@ public boolean isFull() { return batchSize() == size(); } - /** - * Return true if the buffer is full. - */ - public abstract void add(BeanCollection bc); - - abstract void clear(); - @Override public BeanPropertyAssocMany beanProperty() { return context.property; @@ -181,54 +175,10 @@ public String fullPath() { return context.fullPath; } - @Override - public void loadMany(BeanCollection bc, boolean onlyIds) { - lock.lock(); - try { - boolean useCache = !onlyIds && context.hitCache && context.property.isUseCache(); - if (useCache) { - EntityBean ownerBean = bc.owner(); - BeanDescriptor parentDesc = context.desc.descriptor(ownerBean.getClass()); - Object parentId = parentDesc.getId(ownerBean); - final String parentKey = parentDesc.cacheKey(parentId); - if (parentDesc.cacheManyPropLoad(context.property, bc, parentKey, context.parent.isReadOnly())) { - // we loaded the bean collection from cache so remove it from the buffer - if (removeFromBuffer(bc)) { - bc.setLoader(context.parent.server()); - } - // find it using instance equality - avoiding equals() and potential deadlock issue - return; - } - } - - context.parent.server().loadMany(new LoadManyRequest(this, onlyIds, useCache, bc)); - // clear the buffer as all entries have been loaded - clear(); - } finally { - lock.unlock(); - } - } - } - - static class LoadBufferHardRef extends LoadBuffer { - private final BeanCollection[] list; - - private int size; - - LoadBufferHardRef(DLoadManyContext context, int batchSize) { - super(context, batchSize); - this.list = new BeanCollection[batchSize]; - } - - /** - * Return true if the buffer is full. - */ - @Override public void add(BeanCollection bc) { list[size++] = bc; } - @Override void clear() { Arrays.fill(list, null); size = 0; @@ -255,71 +205,33 @@ public boolean removeFromBuffer(BeanCollection collection) { } return false; } - } - - /** - * This load buffer uses weak references, so unreachable beanCollections will drop out from the buffer. - */ - static class LoadBufferWeakRef extends LoadBuffer { - private final Reference>[] list; - - private int size; - - LoadBufferWeakRef(DLoadManyContext context, int batchSize) { - super(context, batchSize); - this.list = new Reference[batchSize]; - } - - /** - * Return true if the buffer is full. - */ - @Override - public void add(BeanCollection bc) { - list[size++] = new WeakReference<>(bc); - } - - @Override - void clear() { - Arrays.fill(list, null); - size = 0; - } - - @Override - public int size() { - return size; - } - - @Override - public BeanCollection get(int i) { - Reference> ref = list[i]; - if (ref == null) { - return null; - } - BeanCollection bc = ref.get(); - if (bc == null) { - // remove dead references - list[i] = null; - } - return bc; - } @Override - public boolean removeFromBuffer(BeanCollection collection) { - for (int i = 0; i < size; i++) { - if (list[i] != null) { - BeanCollection bc = list[i].get(); - if (bc == null) { - // remove dead references - list[i] = null; - } - // find it using instance equality - avoiding equals() and potential deadlock issue - if (bc == collection) { - list[i] = null; - return true; + public void loadMany(BeanCollection bc, boolean onlyIds) { + lock.lock(); + try { + boolean useCache = !onlyIds && context.hitCache && context.property.isUseCache(); + if (useCache) { + EntityBean ownerBean = bc.owner(); + BeanDescriptor parentDesc = context.desc.descriptor(ownerBean.getClass()); + Object parentId = parentDesc.getId(ownerBean); + final String parentKey = parentDesc.cacheKey(parentId); + if (parentDesc.cacheManyPropLoad(context.property, bc, parentKey, context.parent.isReadOnly())) { + // we loaded the bean collection from cache so remove it from the buffer + if (removeFromBuffer(bc)) { + bc.setLoader(context.parent.server()); + } + // find it using instance equality - avoiding equals() and potential deadlock issue + return; } } + + context.parent.server().loadMany(new LoadManyRequest(this, onlyIds, useCache, bc)); + // clear the buffer as all entries have been loaded + clear(); + } finally { + lock.unlock(); } - return false; } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/BatchControl.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/BatchControl.java index 08e6bc6ab0..1a8b8eb261 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/BatchControl.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/BatchControl.java @@ -350,7 +350,7 @@ private BatchedBeanHolder beanHolder(PersistRequestBean request) { int depth = transaction.depth(); BeanDescriptor desc = request.descriptor(); // batching by bean type AND depth - String key = desc.rootName() + ":" + depth; + String key = desc.name() + ":" + depth; BatchedBeanHolder batchBeanHolder = beanHoldMap.get(key); if (batchBeanHolder == null) { int ordering = depthOrder.orderingFor(depth); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBeans.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBeans.java index 2f061f72ed..1e6cb1e76b 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBeans.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBeans.java @@ -92,7 +92,7 @@ private boolean isSaveIntersection() { // OneToMany JoinTable return true; } - return transaction.isSaveAssocManyIntersection(many.intersectionTableJoin().getTable(), many.descriptor().rootName()); + return transaction.isSaveAssocManyIntersection(many.intersectionTableJoin().getTable(), many.descriptor().name()); } private boolean isModifyListenMode() { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/InsertMeta.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/InsertMeta.java index 14c1c5531a..aaab5c4655 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/InsertMeta.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/InsertMeta.java @@ -5,9 +5,7 @@ import io.ebean.config.dbplatform.DatabasePlatform; import io.ebeaninternal.server.core.PersistRequestBean; import io.ebeaninternal.server.deploy.BeanDescriptor; -import io.ebeaninternal.server.deploy.InheritInfo; import io.ebeaninternal.server.persist.dmlbind.Bindable; -import io.ebeaninternal.server.persist.dmlbind.BindableDiscriminator; import io.ebeaninternal.server.persist.dmlbind.BindableId; import io.ebeaninternal.server.persist.dmlbind.BindableList; @@ -22,7 +20,6 @@ final class InsertMeta { private final String sqlNullId; private final String sqlWithId; private final BindableId id; - private final Bindable discriminator; private final BindableList all; private final boolean supportsGetGeneratedKeys; private final boolean concatenatedKey; @@ -36,7 +33,6 @@ final class InsertMeta { InsertMeta(DatabasePlatform dbPlatform, BeanDescriptor desc, Bindable shadowFKey, BindableId id, BindableList all) { this.platform = dbPlatform.platform(); - this.discriminator = discriminator(desc); this.id = id; this.all = all; this.shadowFKey = shadowFKey; @@ -69,11 +65,6 @@ final class InsertMeta { } } - private static Bindable discriminator(BeanDescriptor desc) { - InheritInfo inheritInfo = desc.inheritInfo(); - return inheritInfo != null ? new BindableDiscriminator(inheritInfo) : null; - } - /** * Return true if this is a concatenated key. */ @@ -118,9 +109,6 @@ public void bind(DmlHandler request, EntityBean bean, boolean withId) throws SQL if (shadowFKey != null) { shadowFKey.dmlBind(request, bean); } - if (discriminator != null) { - discriminator.dmlBind(request, bean); - } all.dmlBind(request, bean); } @@ -149,9 +137,6 @@ private String genSql(boolean nullId, String table) { if (shadowFKey != null) { shadowFKey.dmlAppend(request); } - if (discriminator != null) { - discriminator.dmlAppend(request); - } all.dmlAppend(request); request.append(") values ("); @@ -178,7 +163,6 @@ private String defaultValues() { */ private boolean noColumnsForInsert() { return shadowFKey == null - && discriminator == null && all.isEmpty(); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableDiscriminator.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableDiscriminator.java deleted file mode 100644 index eaa50c4059..0000000000 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableDiscriminator.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.ebeaninternal.server.persist.dmlbind; - -import io.ebean.bean.EntityBean; -import io.ebeaninternal.server.core.PersistRequestBean; -import io.ebeaninternal.server.deploy.InheritInfo; -import io.ebeaninternal.server.persist.dml.GenerateDmlRequest; - -import javax.persistence.PersistenceException; -import java.sql.SQLException; -import java.util.List; - -/** - * Bindable for inserting a discriminator value. - */ -public final class BindableDiscriminator implements Bindable { - - private final String columnName; - private final Object discValue; - private final int sqlType; - - public BindableDiscriminator(InheritInfo inheritInfo) { - this.columnName = inheritInfo.getDiscriminatorColumn(); - this.discValue = inheritInfo.getDiscriminatorValue(); - this.sqlType = inheritInfo.getDiscriminatorType(); - } - - @Override - public void addToUpdate(PersistRequestBean request, List list) { - throw new PersistenceException("Never called (only for inserts)"); - } - - @Override - public void dmlAppend(GenerateDmlRequest request) { - request.appendColumn(columnName); - } - - @Override - public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException { - bindRequest.bind(discValue, sqlType); - } - -} diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultFetchGroupQuery.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultFetchGroupQuery.java index db78d2ccb3..6facd2eb5a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultFetchGroupQuery.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultFetchGroupQuery.java @@ -556,16 +556,6 @@ public Class getBeanType() { throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup"); } - @Override - public Query setInheritType(Class type) { - throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup"); - } - - @Override - public Class getInheritType() { - throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup"); - } - @Override public QueryType getQueryType() { throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup"); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/STreeType.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/STreeType.java index 83383744f9..32667748a1 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/STreeType.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/STreeType.java @@ -4,7 +4,6 @@ import io.ebean.bean.PersistenceContext; import io.ebeaninternal.api.SpiQuery; import io.ebeaninternal.server.deploy.DbReadContext; -import io.ebeaninternal.server.deploy.InheritInfo; import io.ebeaninternal.server.deploy.id.IdBinder; import java.util.Map; @@ -64,11 +63,6 @@ public interface STreeType { */ STreePropertyAssocMany[] propsMany(); - /** - * Return the inheritance information for this type. - */ - InheritInfo inheritInfo(); - /** * Return the IdBinder for this type. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java index 0a56724332..23aa7021e1 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java @@ -7,7 +7,6 @@ import io.ebeaninternal.api.SpiQuery; import io.ebeaninternal.api.SpiQuery.Type; import io.ebeaninternal.server.core.OrmQueryRequest; -import io.ebeaninternal.server.deploy.InheritInfo; import io.ebeaninternal.server.deploy.TableJoin; import io.ebeaninternal.server.querydefn.OrmQueryDetail; import io.ebeaninternal.server.querydefn.OrmQueryProperties; @@ -521,13 +520,6 @@ private SqlTreeProperties getBaseSelect(STreeType desc, OrmQueryProperties query selectProps.add(propertyAssocOne); } } - - InheritInfo inheritInfo = desc.inheritInfo(); - if (inheritInfo != null) { - // add sub type properties - inheritInfo.addChildrenProperties(selectProps); - - } return selectProps; } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeLoadBean.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeLoadBean.java index 5621373eae..c1963663be 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeLoadBean.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeLoadBean.java @@ -9,7 +9,6 @@ import io.ebeaninternal.api.SpiQuery; import io.ebeaninternal.api.SpiQuery.Mode; import io.ebeaninternal.server.deploy.DbReadContext; -import io.ebeaninternal.server.deploy.InheritInfo; import io.ebeaninternal.server.deploy.id.IdBinder; import java.sql.SQLException; @@ -32,7 +31,6 @@ class SqlTreeLoadBean implements SqlTreeLoad { private final boolean readIdNormal; private final boolean disableLazyLoad; private final boolean readOnlyNoIntercept; - private final InheritInfo inheritInfo; final String prefix; private final Map pathMap; final STreePropertyAssocMany lazyLoadParent; @@ -46,7 +44,6 @@ class SqlTreeLoadBean implements SqlTreeLoad { this.lazyLoadParentIdBinder = node.lazyLoadParentIdBinder; this.prefix = node.prefix; this.desc = node.desc; - this.inheritInfo = desc.inheritInfo(); this.idBinder = desc.idBinder(); this.temporalMode = node.temporalMode; this.temporalVersions = node.temporalVersions; @@ -94,39 +91,6 @@ public final ScalarDataReader singleAttributeReader() { return properties[0]; } - /** - * Load that takes into account inheritance. - */ - private final class LoadInherit extends Load { - - private LoadInherit(DbReadContext ctx, EntityBean parentBean) { - super(ctx, parentBean); - } - - @Override - void initBeanType() throws SQLException { - InheritInfo localInfo = readId ? inheritInfo.readType(ctx) : desc.inheritInfo(); - if (localInfo == null) { - // the bean must be null - localIdBinder = idBinder; - localDesc = desc; - } else { - localBean = localInfo.createEntityBean(); - localType = localInfo.getType(); - localIdBinder = localInfo.getIdBinder(); - localDesc = localInfo.desc(); - } - } - - @Override - void loadProperties() { - // take account of inheritance - for (STreeProperty property : properties) { - localDesc.inheritanceLoad(sqlBeanLoad, property, ctx); - } - } - } - /** * Load a bean instance. */ @@ -383,7 +347,7 @@ public EntityBean load(DbReadContext ctx, EntityBean parentBean, EntityBean cont * Create the loader with or without inheritance. */ final Load createLoad(DbReadContext ctx, EntityBean parentBean) { - return (inheritInfo != null) ? new LoadInherit(ctx, parentBean) : new Load(ctx, parentBean); + return new Load(ctx, parentBean); } @Override diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeBean.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeBean.java index f377151312..dacf001f32 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeBean.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeBean.java @@ -3,7 +3,6 @@ import io.ebean.util.SplitName; import io.ebeaninternal.api.SpiQuery; import io.ebeaninternal.server.deploy.DbSqlContext; -import io.ebeaninternal.server.deploy.InheritInfo; import io.ebeaninternal.server.deploy.TableJoin; import io.ebeaninternal.server.deploy.id.IdBinder; @@ -39,7 +38,6 @@ class SqlTreeNodeBean implements SqlTreeNode { final boolean readIdNormal; final boolean disableLazyLoad; final boolean readOnly; - final InheritInfo inheritInfo; final String prefix; final Map pathMap; final STreePropertyAssocMany lazyLoadParent; @@ -80,7 +78,6 @@ private SqlTreeNodeBean(String prefix, STreePropertyAssoc beanProp, STreeType de this.lazyLoadParentIdBinder = (lazyLoadParent == null) ? null : lazyLoadParent.idBinder(); this.prefix = prefix; this.desc = desc; - this.inheritInfo = desc.inheritInfo(); this.idBinder = desc.idBinder(); this.temporalMode = common.temporalMode(); this.temporalVersions = temporalMode == SpiQuery.TemporalMode.VERSIONS; @@ -134,10 +131,6 @@ private String path(String prefix, String propertyName) { @Override public final void buildRawSqlSelectChain(List selectChain) { if (readId) { - if (inheritInfo != null) { - // discriminator column always proceeds id column - selectChain.add(path(prefix, inheritInfo.getDiscriminatorColumn())); - } idBinder.buildRawSqlSelectChain(prefix, selectChain); } for (STreeProperty property : properties) { @@ -198,9 +191,6 @@ public final void appendSelect(DbSqlContext ctx, boolean subQuery) { lazyLoadParent.addSelectExported(ctx, prefix); } if (readId) { - if (!subQuery && inheritInfo != null) { - ctx.appendColumn(inheritInfo.getDiscriminatorColumn()); - } appendSelectId(ctx, idBinder.beanProperty()); } appendSelect(ctx, subQuery, properties); @@ -241,17 +231,6 @@ final void appendSelectId(DbSqlContext ctx, STreeProperty prop) { @Override public final void appendWhere(DbSqlContext ctx) { - // Only apply inheritance to root node as any join will already have the inheritance join include - see TableJoin - if (inheritInfo != null && nodeBeanProp == null) { - if (!inheritInfo.isRoot()) { - // restrict to this type and sub types of this type. - if (ctx.length() > 0) { - ctx.append(" and"); - } - ctx.append(" ").append(ctx.tableAlias(prefix)).append("."); - ctx.append(inheritInfo.getWhere()); - } - } appendExtraWhere(ctx); for (SqlTreeNode child : children) { child.appendWhere(ctx); @@ -321,9 +300,6 @@ public void dependentTables(Set tables) { */ SqlJoinType appendFromBaseTable(DbSqlContext ctx, SqlJoinType joinType) { SqlJoinType sqlJoinType = appendFromAsJoin(ctx, joinType); - if (inheritInfo != null) { - appendJoinDiscriminator(ctx); - } if (desc.isSoftDelete() && temporalMode != SpiQuery.TemporalMode.SOFT_DELETED) { ctx.append(" and ").append(desc.softDeletePredicate(ctx.tableAlias(prefix))); } @@ -352,12 +328,6 @@ SqlJoinType appendFromAsJoin(DbSqlContext ctx, SqlJoinType joinType) { return nodeBeanProp.addJoin(joinType, prefix, ctx); } - void appendJoinDiscriminator(DbSqlContext ctx) { - if (inheritInfo.getWhere() == null) return; - String alias = ctx.tableAlias(prefix); - ctx.append(" and ").append(alias).append(".").append(inheritInfo.getWhere()); - } - /** * Summary description. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmQuery.java b/ebean-core/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmQuery.java index f4614c1999..6c0f79f3d4 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmQuery.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmQuery.java @@ -970,9 +970,6 @@ private String planDescription() { if (type != null) { sb.append(type.ordinal()); } - if (beanDescriptor.discValue() != null) { - sb.append("/dv").append(beanDescriptor.discValue()); - } if (temporalMode != SpiQuery.TemporalMode.CURRENT) { sb.append("/tm").append(temporalMode.ordinal()); if (versionsStart != null) { @@ -1630,26 +1627,6 @@ public final Class getBeanType() { return beanType; } - @Override - public final Class getInheritType() { - return beanDescriptor.type(); - } - - @SuppressWarnings("unchecked") - @Override - public final Query setInheritType(Class type) { - if (type == beanType) { - return this; - } - InheritInfo inheritInfo = rootBeanDescriptor.inheritInfo(); - inheritInfo = inheritInfo == null ? null : inheritInfo.readType(type); - if (inheritInfo == null) { - throw new IllegalArgumentException("Given type " + type + " is not a subtype of " + beanType); - } - beanDescriptor = (BeanDescriptor) rootBeanDescriptor.descriptor(type); - return this; - } - @Override public final String toString() { return "Query " + whereExpressions; diff --git a/ebean-core/src/test/java/io/ebeaninternal/server/cache/CachedBeanDataSerializeTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/cache/CachedBeanDataSerializeTest.java index 7e54d1d1ed..7094f26843 100644 --- a/ebean-core/src/test/java/io/ebeaninternal/server/cache/CachedBeanDataSerializeTest.java +++ b/ebean-core/src/test/java/io/ebeaninternal/server/cache/CachedBeanDataSerializeTest.java @@ -31,7 +31,7 @@ public void write() throws IOException, ClassNotFoundException { map.put("whenCreated", "" + System.currentTimeMillis()); long version = System.currentTimeMillis(); - CachedBeanData write = new CachedBeanData(null, "C", map, version); + CachedBeanData write = new CachedBeanData(null, map, version); ByteArrayOutputStream os = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(os); @@ -50,7 +50,6 @@ public void write() throws IOException, ClassNotFoundException { assertEquals(read.getVersion(), write.getVersion()); assertEquals(read.getWhenCreated(), write.getWhenCreated()); - assertEquals(read.getDiscValue(), write.getDiscValue()); assertEquals(read.getData(), write.getData()); } diff --git a/ebean-core/src/test/java/io/ebeaninternal/server/deploy/BeanDescriptorTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/deploy/BeanDescriptorTest.java index 29c1e19140..3944e34f4c 100644 --- a/ebean-core/src/test/java/io/ebeaninternal/server/deploy/BeanDescriptorTest.java +++ b/ebean-core/src/test/java/io/ebeaninternal/server/deploy/BeanDescriptorTest.java @@ -1,6 +1,5 @@ package io.ebeaninternal.server.deploy; -import io.ebean.DB; import io.ebean.bean.EntityBean; import io.ebean.plugin.Property; import io.ebeaninternal.server.core.CacheOptions; @@ -8,7 +7,10 @@ import io.ebeaninternal.server.deploy.meta.DeployIdentityMode; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -import org.tests.model.basic.*; +import org.tests.model.basic.Contact; +import org.tests.model.basic.Country; +import org.tests.model.basic.Customer; +import org.tests.model.basic.Order; import org.tests.model.bridge.BSite; import org.tests.model.bridge.BUser; @@ -16,7 +18,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -56,31 +57,6 @@ public void createReference_when_disabledLazyLoad() { Assertions.assertThat(server().beanState(bean).isDisableLazyLoad()).isTrue(); } - @Test - public void createReference_with_inheritance() { - initTables(); - - Cat cat = new Cat(); - cat.setName("Puss"); - DB.save(cat); - - Dog dog = new Dog(); - dog.setRegistrationNumber("DOGGIE"); - DB.save(dog); - - AnimalShelter shelter = new AnimalShelter(); - shelter.setName("My Animal Shelter"); - shelter.getAnimals().add(cat); - shelter.getAnimals().add(dog); - - DB.save(shelter); - - BeanDescriptor animalDesc = spiEbeanServer().descriptor(Animal.class); - - Animal bean = animalDesc.createReference(Boolean.FALSE, false, dog.getId(), null); - assertThat(bean.getId()).isEqualTo(dog.getId()); - } - @Test public void allProperties() { diff --git a/ebean-core/src/test/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfoTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfoTest.java deleted file mode 100644 index d42825ea9f..0000000000 --- a/ebean-core/src/test/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfoTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.ebeaninternal.server.deploy.parse; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class DeployInheritInfoTest { - - @Test - void addChild_when_DiscriminatorValueIsNull() { - DeployInheritInfo root = new DeployInheritInfo(Object.class); - root.addChild(new DeployInheritInfo(Integer.class)); // DiscriminatorValue is null - root.addChild(new DeployInheritInfo(Short.class)); // DiscriminatorValue is null - - DeployInheritInfo c2 = new DeployInheritInfo(Long.class); - c2.setDiscriminatorValue("c2"); - root.addChild(c2); - - assertThat(root.children()).hasSize(3); - } -} diff --git a/ebean-core/src/test/java/org/tests/model/basic/Animal.java b/ebean-core/src/test/java/org/tests/model/basic/Animal.java index 069b1e4cfa..523ccbd1dd 100644 --- a/ebean-core/src/test/java/org/tests/model/basic/Animal.java +++ b/ebean-core/src/test/java/org/tests/model/basic/Animal.java @@ -3,9 +3,7 @@ import javax.persistence.*; @Entity -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "species") -public abstract class Animal { +public final class Animal { @Id Long id; diff --git a/ebean-core/src/test/java/org/tests/model/basic/Cat.java b/ebean-core/src/test/java/org/tests/model/basic/Cat.java deleted file mode 100644 index d3df201b61..0000000000 --- a/ebean-core/src/test/java/org/tests/model/basic/Cat.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.tests.model.basic; - -import io.ebean.annotation.Formula; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@Entity -@DiscriminatorValue("CAT") -public class Cat extends Animal { - - String name; - - @Formula(select = "${ta}.species") - String catFormula; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getCatFormula() { - return catFormula; - } - - public void setCatFormula(String catFormula) { - this.catFormula = catFormula; - } -} diff --git a/ebean-core/src/test/java/org/tests/model/basic/Dog.java b/ebean-core/src/test/java/org/tests/model/basic/Dog.java deleted file mode 100644 index 7b2fad5466..0000000000 --- a/ebean-core/src/test/java/org/tests/model/basic/Dog.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.tests.model.basic; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; -import java.sql.Date; - -@Entity -@DiscriminatorValue("DOG") -public class Dog extends Animal { - - String registrationNumber; - - Date dateOfBirth; - - public String getRegistrationNumber() { - return registrationNumber; - } - - public void setRegistrationNumber(String registrationNumber) { - this.registrationNumber = registrationNumber; - } - - public Date getDateOfBirth() { - return dateOfBirth; - } - - public void setDateOfBirth(Date dateOfBirth) { - this.dateOfBirth = dateOfBirth; - } - -} diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitor.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitor.java index 704fcf0afe..b0a4ada854 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitor.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitor.java @@ -1,11 +1,8 @@ package io.ebeaninternal.dbmigration.model.build; -import io.ebean.config.dbplatform.DbPlatformType; -import io.ebeaninternal.dbmigration.model.MColumn; import io.ebeaninternal.dbmigration.model.MTable; import io.ebeaninternal.dbmigration.model.visitor.BeanVisitor; import io.ebeaninternal.server.deploy.BeanDescriptor; -import io.ebeaninternal.server.deploy.InheritInfo; /** * Used to build the Model objects MTable etc. @@ -27,27 +24,9 @@ public ModelBuildBeanVisitor(ModelBuildContext ctx) { */ @Override public ModelBuildPropertyVisitor visitBean(BeanDescriptor descriptor) { - - if (!descriptor.isInheritanceRoot()) { - return null; - } - MTable table = new MTable(descriptor); // add the table to the model ctx.addTable(table); - - InheritInfo inheritInfo = descriptor.inheritInfo(); - if (inheritInfo != null && inheritInfo.isRoot()) { - // add the discriminator column - String discColumn = inheritInfo.getDiscriminatorColumn(); - String columnDefn = inheritInfo.getColumnDefn(); - if (columnDefn == null || columnDefn.isEmpty()) { - DbPlatformType dbType = ctx.getDbTypeMap().get(inheritInfo.getDiscriminatorType()); - columnDefn = dbType.renderType(inheritInfo.getColumnLength(), 0); - } - table.addColumn(new MColumn(discColumn, columnDefn, true)); - } - return new ModelBuildPropertyVisitor(ctx, table, descriptor); } diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildPropertyVisitor.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildPropertyVisitor.java index dda9fb8d8b..0e7a7289a8 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildPropertyVisitor.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildPropertyVisitor.java @@ -18,8 +18,6 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor { private final MTable table; - private final BeanDescriptor beanDescriptor; - private final IndexSet indexSet = new IndexSet(); private MColumn lastColumn; @@ -32,7 +30,6 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor { public ModelBuildPropertyVisitor(ModelBuildContext ctx, MTable table, BeanDescriptor beanDescriptor) { this.ctx = ctx; this.table = table; - this.beanDescriptor = beanDescriptor; addIndexes(beanDescriptor.indexDefinitions()); } @@ -270,10 +267,6 @@ public void visitScalar(BeanProperty p, boolean allowNonNull) { } Set checkConstraintValues = p.dbCheckConstraintValues(); if (checkConstraintValues != null) { - if (beanDescriptor.hasInheritance()) { - InheritInfo inheritInfo = beanDescriptor.inheritInfo(); - inheritInfo.appendCheckConstraintValues(p.name(), checkConstraintValues); - } col.setCheckConstraint(buildCheckConstraint(p.dbColumn(), checkConstraintValues)); col.setCheckConstraintName(checkConstraintName(col.getName())); } diff --git a/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitorTest.java b/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitorTest.java index 7be24c6f7e..1e921a3d7f 100644 --- a/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitorTest.java +++ b/ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitorTest.java @@ -43,10 +43,6 @@ public void test() { new VisitAllUsing(addTable, defaultServer).visitAllBeans(); assert_compound_pk(model); - - assert_discriminatorColumn_explicit(model); - assert_discriminatorColumn_implied(model); - assert_discriminatorColumn_length(model); } @Test @@ -104,27 +100,4 @@ private void assert_compound_pk(ModelContainer model) { assertThat(item.primaryKeyColumns()).hasSize(2); } - private void assert_discriminatorColumn_explicit(ModelContainer model) { - - MTable configuration = model.getTable("configuration"); - MColumn discTypeColumn = configuration.getColumn("type"); - assertThat(discTypeColumn.getType()).isEqualTo("varchar(21)"); - assertThat(discTypeColumn.isNotnull()).isTrue(); - } - - private void assert_discriminatorColumn_implied(ModelContainer model) { - - MTable configuration = model.getTable("bar"); - MColumn discTypeColumn = configuration.getColumn("bar_type"); - assertThat(discTypeColumn.getType()).isEqualTo("varchar(31)"); - assertThat(discTypeColumn.isNotnull()).isTrue(); - } - - private void assert_discriminatorColumn_length(ModelContainer model) { - - MTable configuration = model.getTable("vehicle"); - MColumn discTypeColumn = configuration.getColumn("dtype"); - assertThat(discTypeColumn.getType()).isEqualTo("varchar(3)"); - assertThat(discTypeColumn.isNotnull()).isTrue(); - } } diff --git a/ebean-ddl-generator/src/test/java/org/tests/inheritance/company/domain/TestInheritAbstract.java b/ebean-ddl-generator/src/test/java/org/tests/inheritance/company/domain/TestInheritAbstract.java index 1fa9faf7b1..7d51314889 100644 --- a/ebean-ddl-generator/src/test/java/org/tests/inheritance/company/domain/TestInheritAbstract.java +++ b/ebean-ddl-generator/src/test/java/org/tests/inheritance/company/domain/TestInheritAbstract.java @@ -35,7 +35,7 @@ public void testMe() { cb.setFoo(f); server.save(cb); - List list2 = server.find(AbstractBar.class) + List list2 = server.find(ConcreteBar.class) .fetch("foo", "importantText") .findList(); diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java b/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java index af7c878943..562ce13e20 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java @@ -613,23 +613,6 @@ public R setDistinct(boolean distinct) { return root; } - /** - * Restrict the query to only return subtypes of the given inherit type. - *
{@code
-   *
-   *   List animals =
-   *     new QAnimal()
-   *       .name.startsWith("Fluffy")
-   *       .setInheritType(Cat.class)
-   *       .findList();
-   *
-   * }
- */ - public R setInheritType(Class type) { - query.setInheritType(type); - return root; - } - /** * Set the base table to use for this query. *

diff --git a/ebean-querybean/src/test/java/org/example/domain/ACat.java b/ebean-querybean/src/test/java/org/example/domain/ACat.java index 3537437b74..f8d5b7efec 100644 --- a/ebean-querybean/src/test/java/org/example/domain/ACat.java +++ b/ebean-querybean/src/test/java/org/example/domain/ACat.java @@ -1,9 +1,7 @@ package org.example.domain; -import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; -@DiscriminatorValue("CAT") @Entity public class ACat extends Animal { diff --git a/ebean-querybean/src/test/java/org/example/domain/ADog.java b/ebean-querybean/src/test/java/org/example/domain/ADog.java deleted file mode 100644 index 81646476b5..0000000000 --- a/ebean-querybean/src/test/java/org/example/domain/ADog.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.example.domain; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; -import javax.persistence.Inheritance; - -@Inheritance -@DiscriminatorValue("DOG") -@Entity -public class ADog extends Animal { - - private String registration; - - public ADog(String name, String registration) { - super(name); - this.registration = registration; - } - - public String getRegistration() { - return registration; - } - - public void setRegistration(String registration) { - this.registration = registration; - } -} diff --git a/ebean-querybean/src/test/java/org/example/domain/ASuperCat.java b/ebean-querybean/src/test/java/org/example/domain/ASuperCat.java deleted file mode 100644 index 30187d6fc2..0000000000 --- a/ebean-querybean/src/test/java/org/example/domain/ASuperCat.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.example.domain; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@DiscriminatorValue("SCAT") -@Entity -public class ASuperCat extends ACat { - - private String superCat; - - public ASuperCat(String name) { - super(name); - } - - public String getSuperCat() { - return superCat; - } - - public void setSuperCat(String superCat) { - this.superCat = superCat; - } -} diff --git a/ebean-querybean/src/test/java/org/example/domain/AWildCat.java b/ebean-querybean/src/test/java/org/example/domain/AWildCat.java deleted file mode 100644 index 85e2e32054..0000000000 --- a/ebean-querybean/src/test/java/org/example/domain/AWildCat.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.example.domain; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; -import javax.persistence.Inheritance; - -@Inheritance -@DiscriminatorValue("WC") -@Entity -public class AWildCat extends ACat { - - public AWildCat(String name) { - super(name); - } - -} diff --git a/ebean-querybean/src/test/java/org/example/domain/Animal.java b/ebean-querybean/src/test/java/org/example/domain/Animal.java index 2a4196c06b..11dc8ea23f 100644 --- a/ebean-querybean/src/test/java/org/example/domain/Animal.java +++ b/ebean-querybean/src/test/java/org/example/domain/Animal.java @@ -2,13 +2,9 @@ import io.ebean.Model; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Inheritance; -import javax.persistence.Version; +import javax.persistence.*; -@Entity -@Inheritance +@MappedSuperclass public abstract class Animal extends Model { @Id diff --git a/ebean-querybean/src/test/java/org/querytest/InheritanceTest.java b/ebean-querybean/src/test/java/org/querytest/InheritanceTest.java index db453ea112..1f758f63c1 100644 --- a/ebean-querybean/src/test/java/org/querytest/InheritanceTest.java +++ b/ebean-querybean/src/test/java/org/querytest/InheritanceTest.java @@ -1,11 +1,7 @@ package org.querytest; import org.example.domain.ACat; -import org.example.domain.ADog; -import org.example.domain.Animal; import org.example.domain.query.QACat; -import org.example.domain.query.QASuperCat; -import org.example.domain.query.QAnimal; import org.junit.jupiter.api.Test; import java.util.List; @@ -23,12 +19,8 @@ void query_setInheritType() { ACat cat2 = new ACat("C2"); cat2.save(); - ADog dog = new ADog("D1", "D878"); - dog.save(); - - List animals = new QAnimal() + List animals = new QACat() .id.greaterOrEqualTo(1L) - .setInheritType(ACat.class) .findList(); assertThat(animals).isNotEmpty(); @@ -42,13 +34,4 @@ void query_onInheritedProperty() { .findList(); } - @Test - void query_onInheritedProperty_whenParentOnlyHasDiscriminator() { - // the .name and .catProp properties exist on QASuperCat() - new QASuperCat() - .superCat.eq("foo") - .name.eq("foo") - .catProp.eq("foo") - .findList(); - } } diff --git a/ebean-test/src/test/java/io/ebean/xtest/core/DefaultServer_getReferenceTest.java b/ebean-test/src/test/java/io/ebean/xtest/core/DefaultServer_getReferenceTest.java index 7f85020004..a2052206a5 100644 --- a/ebean-test/src/test/java/io/ebean/xtest/core/DefaultServer_getReferenceTest.java +++ b/ebean-test/src/test/java/io/ebean/xtest/core/DefaultServer_getReferenceTest.java @@ -4,10 +4,8 @@ import io.ebean.xtest.BaseTestCase; import io.ebean.DB; import org.junit.jupiter.api.Test; -import org.tests.model.basic.Car; import org.tests.model.basic.Customer; import org.tests.model.basic.ResetBasicData; -import org.tests.model.basic.Vehicle; import static org.assertj.core.api.Assertions.assertThat; @@ -29,37 +27,4 @@ public void getReference_when_inPC_expect_getFromPC() { assertThat(loaded).isSameAs(reference); }); } - - - @Test - public void inherit_getReference_when_noPC() { - - Car car = new Car(); - car.setDriver("TestForRef"); - DB.save(car); - - Vehicle reference = DB.reference(Vehicle.class, car.getId()); - - assertThat(reference).isInstanceOf(Car.class); - assertThat(reference.getId()).isEqualTo(car.getId()); - - DB.delete(car); - } - - - @Test - public void inherit_getReference_when_inPC() { - - Car car = new Car(); - car.setDriver("TestForRef"); - DB.save(car); - - DB.execute(() -> { - Vehicle loaded = DB.find(Vehicle.class, car.getId()); - Vehicle reference = DB.reference(Vehicle.class, car.getId()); - assertThat(reference).isSameAs(loaded); - } - ); - DB.delete(car); - } } diff --git a/ebean-test/src/test/java/io/ebean/xtest/event/TestBeanFindController.java b/ebean-test/src/test/java/io/ebean/xtest/event/TestBeanFindController.java index 26fe6e52c0..01d6db7883 100644 --- a/ebean-test/src/test/java/io/ebean/xtest/event/TestBeanFindController.java +++ b/ebean-test/src/test/java/io/ebean/xtest/event/TestBeanFindController.java @@ -79,9 +79,7 @@ public T postProcess(final BeanQueryRequest request, final T result) { private Class beanTypeFor(String tableName, BeanQueryRequest request) { List> types = request.database().pluginApi().beanTypes(tableName); for (BeanType type : types) { - if (type.isInheritanceRoot()) { - return type.type(); - } + return type.type(); } return null; } diff --git a/ebean-test/src/test/java/io/ebean/xtest/internal/server/transaction/DefaultPersistenceContextTest.java b/ebean-test/src/test/java/io/ebean/xtest/internal/server/transaction/DefaultPersistenceContextTest.java index a8c14920ea..2b57057a7b 100644 --- a/ebean-test/src/test/java/io/ebean/xtest/internal/server/transaction/DefaultPersistenceContextTest.java +++ b/ebean-test/src/test/java/io/ebean/xtest/internal/server/transaction/DefaultPersistenceContextTest.java @@ -4,7 +4,6 @@ import io.ebeaninternal.server.deploy.PersistenceContextUtil; import io.ebeaninternal.server.transaction.DefaultPersistenceContext; import org.junit.jupiter.api.Test; -import org.tests.model.basic.Car; import org.tests.model.basic.Contact; import org.tests.model.basic.Customer; import org.tests.model.basic.Vehicle; @@ -14,12 +13,12 @@ class DefaultPersistenceContextTest { private final Customer customer42; - private final Car car1; + private final Vehicle car1; DefaultPersistenceContextTest() { customer42 = new Customer(); customer42.setId(42); - car1 = new Car(); + car1 = new Vehicle(); car1.setId(1); } @@ -37,15 +36,6 @@ Class root(Class cls) { return PersistenceContextUtil.root(cls); } - @Test - void put_get_withInheritance() { - PersistenceContext pc = pc(); - pc.put(root(Vehicle.class), 1, car1); - - Object found = pc.get(root(Car.class), 1); - assertThat(found).isSameAs(car1); - } - @Test void put_get() { PersistenceContext pc = pc(); diff --git a/ebean-test/src/test/java/io/ebean/xtest/plugin/BeanTypeTest.java b/ebean-test/src/test/java/io/ebean/xtest/plugin/BeanTypeTest.java index 9e087dac17..f72d79521b 100644 --- a/ebean-test/src/test/java/io/ebean/xtest/plugin/BeanTypeTest.java +++ b/ebean-test/src/test/java/io/ebean/xtest/plugin/BeanTypeTest.java @@ -2,11 +2,9 @@ import io.ebean.DB; import io.ebean.Database; -import io.ebean.Query; import io.ebean.plugin.BeanType; import io.ebean.plugin.Property; import org.junit.jupiter.api.Test; -import org.tests.inheritance.Stockforecast; import org.tests.model.basic.*; import static org.assertj.core.api.Assertions.assertThat; @@ -92,47 +90,4 @@ public void setBeanId() { assertThat(42).isEqualTo(order.getId()); } - @Test - public void hasInheritance_when_not() { - assertFalse(beanType(Order.class).hasInheritance()); - } - - @Test - public void hasInheritance_when_root() { - assertTrue(beanType(Vehicle.class).hasInheritance()); - } - - @Test - public void hasInheritance_when_leaf() { - assertTrue(beanType(Car.class).hasInheritance()); - } - - @Test - public void getDiscColumn_when_default() { - assertEquals(beanType(Car.class).discColumn(), "dtype"); - } - - @Test - public void getDiscColumn_when_set() { - assertEquals(beanType(Stockforecast.class).discColumn(), "type"); - } - - @Test - public void createBeanUsingDisc_when_set() { - Vehicle vehicle = beanType(Vehicle.class).createBeanUsingDisc("C"); - assertTrue(vehicle instanceof Car); - } - - @Test - public void addInheritanceWhere_when_leaf() { - Query query = db.find(Vehicle.class); - beanType(Car.class).addInheritanceWhere(query); - } - - @Test - public void addInheritanceWhere_when_root() { - Query query = db.find(Vehicle.class); - beanType(Vehicle.class).addInheritanceWhere(query); - } - } diff --git a/ebean-test/src/test/java/org/tests/aggregateformula/IAFBaseSegment.java b/ebean-test/src/test/java/org/tests/aggregateformula/IAFBaseSegment.java index 32b65492ae..92a8fa1805 100644 --- a/ebean-test/src/test/java/org/tests/aggregateformula/IAFBaseSegment.java +++ b/ebean-test/src/test/java/org/tests/aggregateformula/IAFBaseSegment.java @@ -2,13 +2,12 @@ import javax.persistence.*; -@Entity -@Inheritance -@Table(name = "iaf_segment") -@DiscriminatorColumn(name = "ptype") -public class IAFBaseSegment { +@MappedSuperclass +// DiscriminatorColumn(name = "ptype") +public abstract class IAFBaseSegment { @Id private Long id; + String ptype; } diff --git a/ebean-test/src/test/java/org/tests/aggregateformula/IAFPartialSegment.java b/ebean-test/src/test/java/org/tests/aggregateformula/IAFPartialSegment.java index c1e2d1d442..a7aa6059f2 100644 --- a/ebean-test/src/test/java/org/tests/aggregateformula/IAFPartialSegment.java +++ b/ebean-test/src/test/java/org/tests/aggregateformula/IAFPartialSegment.java @@ -1,13 +1,11 @@ package org.tests.aggregateformula; -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; -import javax.persistence.Inheritance; -import javax.persistence.ManyToOne; +import javax.persistence.*; @Entity -@Inheritance -@DiscriminatorValue("target") +@Table(name = "iaf_segment") +// Inheritance +// DiscriminatorValue("target") public class IAFPartialSegment extends IAFBaseSegment { private final long segmentIdZat; diff --git a/ebean-test/src/test/java/org/tests/aggregateformula/TestAggregateInheritFormula.java b/ebean-test/src/test/java/org/tests/aggregateformula/TestAggregateInheritFormula.java index e3289c3f13..f235d88898 100644 --- a/ebean-test/src/test/java/org/tests/aggregateformula/TestAggregateInheritFormula.java +++ b/ebean-test/src/test/java/org/tests/aggregateformula/TestAggregateInheritFormula.java @@ -35,6 +35,6 @@ public void test() { final List sql = LoggedSql.stop(); assertThat(segments).hasSize(1); - assertSql(sql.get(0)).contains("select t0.segment_id_zat, min(t0.status_id) from iaf_segment t0 where t0.ptype = 'target' and t0.segment_id_zat = ? group by t0.segment_id_zat"); + assertSql(sql.get(0)).contains("select t0.segment_id_zat, min(t0.status_id) from iaf_segment t0 where t0.segment_id_zat = ? group by t0.segment_id_zat"); } } diff --git a/ebean-test/src/test/java/org/tests/basic/TestInheritRef.java b/ebean-test/src/test/java/org/tests/basic/TestInheritRef.java deleted file mode 100644 index ebc134ff24..0000000000 --- a/ebean-test/src/test/java/org/tests/basic/TestInheritRef.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.tests.basic; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import org.junit.jupiter.api.Test; -import org.tests.model.basic.Car; -import org.tests.model.basic.Truck; -import org.tests.model.basic.Vehicle; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class TestInheritRef extends BaseTestCase { - - @Test - public void testAssocOne() { - - DB.beginTransaction(); - try { - DB.createUpdate(Vehicle.class, "delete from vehicle"); - - Car c = new Car(); - c.setLicenseNumber("C6788"); - c.setDriver("CarDriver"); - DB.save(c); - - Truck t = new Truck(); - t.setLicenseNumber("T1098BBX"); - t.setCapacity(20D); - DB.save(t); - - List list = DB.find(Vehicle.class) - .setAutoTune(false) - .findList(); - - assertTrue(!list.isEmpty()); - - Truck foundTruck = null; - int found = 0; - - for (Vehicle vehicle : list) { - if (vehicle instanceof Truck) { - Truck truck = (Truck) vehicle; - if ("T1098BBX".equals(truck.getLicenseNumber())) { - found++; - foundTruck = truck; - } - } - } - - assertEquals(1, found); - assertTrue(foundTruck.getCapacity() == 20D); - - } finally { - DB.rollbackTransaction(); - } - } -} diff --git a/ebean-test/src/test/java/org/tests/basic/TestJoinInheritance.java b/ebean-test/src/test/java/org/tests/basic/TestJoinInheritance.java deleted file mode 100644 index f251099732..0000000000 --- a/ebean-test/src/test/java/org/tests/basic/TestJoinInheritance.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.tests.basic; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import org.junit.jupiter.api.Test; -import org.tests.model.basic.*; - -import java.sql.Timestamp; -import java.util.Date; - -public class TestJoinInheritance extends BaseTestCase { - - - /** - * Test join hierarchy assoc one. - *

- * This test catches the problem where the discriminator column is select - * but is not skipped if the parent bean is already in the presistence context. - *

- * Test case: We have several trips with different addresses but always the same - * driver and car (the cars could be different). So the driver will be loaded - * when the first trip is loaded but when the second trip is loaded the driver is - * found in the persistence context. So the bean is not read but the index in the - * result set is forwarded by the number of properties - however, the vehicle type - * column was not being skipped - but the query reads happily - only the data is - * then wrong in the address object. - */ - @Test - public void testJoinHierarchyAssocOne() { - - DB.createUpdate(Vehicle.class, "delete from vehicle"); - - - Address address = new Address(); - address.setLine1("Street"); - address.setLine2("Street"); - address.setCity("City"); - - address.setCretime(new Timestamp(new Date().getTime())); - - DB.save(address); - - Car c = new Car(); - c.setLicenseNumber("C6788"); - c.setDriver("CarDriver"); - c.setRegistrationDate(new Date()); - DB.save(c); - - VehicleDriver driver = new VehicleDriver(); - - driver.setVehicle(c); - driver.setAddress(address); - driver.setLicenseIssuedOn(new Date()); - DB.save(driver); - - final String line1 = "Street1"; - final String line2 = "Street2"; - final String city = "City"; - - int nrDrivers = 2; - for (int i = 0; i < nrDrivers; i++) { - Address address1 = new Address(); - address1.setLine1(line1); - address1.setLine2(line2); - address1.setCity(city); - DB.save(address1); - - Trip trip = new Trip(); - trip.setVehicleDriver(driver); - trip.setAddress(address1); - trip.setCretime(new Timestamp(new Date().getTime())); - DB.save(trip); - } - - } -} diff --git a/ebean-test/src/test/java/org/tests/cache/TestCacheManyToOne.java b/ebean-test/src/test/java/org/tests/cache/TestCacheManyToOne.java index 9a95f93a3d..d76266d071 100644 --- a/ebean-test/src/test/java/org/tests/cache/TestCacheManyToOne.java +++ b/ebean-test/src/test/java/org/tests/cache/TestCacheManyToOne.java @@ -3,7 +3,6 @@ import io.ebean.xtest.BaseTestCase; import io.ebean.DB; import org.junit.jupiter.api.Test; -import org.tests.model.basic.OCachedInhChildA; import org.tests.model.basic.OCachedInhRoot; import static org.assertj.core.api.Assertions.assertThat; @@ -17,7 +16,7 @@ public class TestCacheManyToOne extends BaseTestCase { @Test public void crudInvoice() { - OCachedInhChildA bean = new OCachedInhChildA(); + OCachedInhRoot bean = new OCachedInhRoot(); bean.setName("Roland"); bean.setChildAData("ChildData"); DB.save(bean); @@ -25,14 +24,14 @@ public void crudInvoice() { DB.find(OCachedInhRoot.class).select("id").where().idIn(bean.getId()).findEach(bean0 -> { assertNotNull(bean0); assertThat(bean0.getName()).isEqualTo("Roland"); - assertThat(((OCachedInhChildA)bean0).getChildAData()).isEqualTo("ChildData"); + assertThat((bean0).getChildAData()).isEqualTo("ChildData"); }); DB.find(OCachedInhRoot.class).select("id").where().idIn(bean.getId()).findEach(bean1 -> { assertNotNull(bean1); assertThat(bean1.getName()).isEqualTo("Roland"); // this will fail if the bean is loaded from cache and the wrong discriminator is used. - assertThat(((OCachedInhChildA)bean1).getChildAData()).isEqualTo("ChildData"); + assertThat((bean1).getChildAData()).isEqualTo("ChildData"); }); } diff --git a/ebean-test/src/test/java/org/tests/docstore/CustomerReportTest.java b/ebean-test/src/test/java/org/tests/docstore/CustomerReportTest.java deleted file mode 100644 index 1dc65930a7..0000000000 --- a/ebean-test/src/test/java/org/tests/docstore/CustomerReportTest.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.tests.docstore; - - -import io.ebean.xtest.BaseTestCase; -import io.ebean.text.json.JsonReadOptions; -import org.junit.jupiter.api.Test; -import org.tests.model.basic.Customer; -import org.tests.model.basic.Product; -import org.tests.model.basic.ResetBasicData; -import org.tests.model.docstore.CustomerReport; -import org.tests.model.docstore.ProductReport; - -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - -public class CustomerReportTest extends BaseTestCase { - - @Test - public void testToJson() throws Exception { - ResetBasicData.reset(); - - - - String json = server().json().toJson(getCustomerReport()); - assertThat(json).isEqualTo("{\"dtype\":\"CR\",\"friends\":[{\"id\":2},{\"id\":3}],\"customer\":{\"id\":1}}"); - } - - @Test - public void testFromJson() throws Exception { - ResetBasicData.reset(); - String json = "{\"dtype\":\"CR\",\"friends\":[{\"id\":2},{\"id\":3}],\"customer\":{\"id\":1}}"; - - JsonReadOptions opts = new JsonReadOptions(); - opts.setEnableLazyLoading(true); - CustomerReport report = server().json().toBean(CustomerReport.class, json, opts); - - assertThat(report.getCustomer().getName()).isEqualTo("Rob"); - - assertThat(report.getFriends().get(0).getName()).isEqualTo("Cust NoAddress"); - assertThat(report.getFriends().get(1).getName()).isEqualTo("Fiona"); - } - - - @Test - public void testEmbeddedDocs() throws Exception { - ResetBasicData.reset(); - - CustomerReport report = getCustomerReport(); - report.getEmbeddedReports().add(getProductReport()); - - String json = server().json().toJson(report); - - assertThat(json).isEqualTo("{\"dtype\":\"CR\"," - + "\"embeddedReports\":[{\"dtype\":\"PR\",\"title\":\"This is a good product\",\"product\":{\"id\":1}}]," - + "\"friends\":[{\"id\":2},{\"id\":3}]," - + "\"customer\":{\"id\":1}}"); - - JsonReadOptions opts = new JsonReadOptions(); - opts.setEnableLazyLoading(true); - report = server().json().toBean(CustomerReport.class, json, opts); - ProductReport ar = (ProductReport) report.getEmbeddedReports().get(0); - assertThat(ar.getTitle()).isEqualTo("This is a good product"); - assertThat(ar.getProduct().getName()).isEqualTo("Chair"); - } - - - private CustomerReport getCustomerReport() { - Customer customer = server().reference(Customer.class, 1); - Customer friend1 = server().reference(Customer.class, 2); - Customer friend2 = server().reference(Customer.class, 3); - - CustomerReport report = new CustomerReport(); - - report.setCustomer(customer); - report.setFriends(Arrays.asList(friend1, friend2)); - return report; - } - - private ProductReport getProductReport() { - Product product = server().reference(Product.class, 1); - - ProductReport report = new ProductReport(); - report.setTitle("This is a good product"); - report.setProduct(product); - return report; - } -} diff --git a/ebean-test/src/test/java/org/tests/inherit/ChildA.java b/ebean-test/src/test/java/org/tests/inherit/ChildA.java index 9e68184159..6991c00456 100644 --- a/ebean-test/src/test/java/org/tests/inherit/ChildA.java +++ b/ebean-test/src/test/java/org/tests/inherit/ChildA.java @@ -1,19 +1,66 @@ package org.tests.inherit; -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; @Entity -@DiscriminatorValue("A") -public class ChildA extends Parent { +@Table(name = "rawinherit_parent") +public final class ChildA { - @Override - public String getName() { - return "A Name"; + @Id + private long id; + + private String type; + + private Integer val; + + private String more; + + @ManyToMany(cascade = CascadeType.ALL) + private List data = new ArrayList<>(); + + public ChildA(String type, Integer val, String more) { + this.type = type; + this.val = val; + this.more = more; + } + + public ChildA(int val, String more) { + this.type = "B"; + this.val = val; + this.more = more; + } + + public String type() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Long getId() { + return id; + } + + public Integer getVal() { + return val; } - public ChildA(Integer number, String more) { - super(number, more); + public List getData() { + return data; } + public void setData(List datas) { + this.data = datas; + } + + public String getMore() { + return more; + } + + public void setMore(String more) { + this.more = more; + } } diff --git a/ebean-test/src/test/java/org/tests/inherit/ChildB.java b/ebean-test/src/test/java/org/tests/inherit/ChildB.java deleted file mode 100644 index 34a42e5702..0000000000 --- a/ebean-test/src/test/java/org/tests/inherit/ChildB.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.tests.inherit; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@Entity -@DiscriminatorValue("B") -public class ChildB extends Parent { - - @Override - public String getName() { - return "B Name"; - } - - public ChildB(Integer number, String more) { - super(number, more); - } -} diff --git a/ebean-test/src/test/java/org/tests/inherit/DIntChild1.java b/ebean-test/src/test/java/org/tests/inherit/DIntChild1.java deleted file mode 100644 index a76c0f272a..0000000000 --- a/ebean-test/src/test/java/org/tests/inherit/DIntChild1.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.tests.inherit; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@Entity -@DiscriminatorValue("1") -public class DIntChild1 extends DIntChildBase { - - @Override - public String getName() { - return "A Name"; - } - - public DIntChild1(Integer number, String more) { - super(number, more); - } - -} diff --git a/ebean-test/src/test/java/org/tests/inherit/DIntChild2.java b/ebean-test/src/test/java/org/tests/inherit/DIntChild2.java deleted file mode 100644 index 5f3737c900..0000000000 --- a/ebean-test/src/test/java/org/tests/inherit/DIntChild2.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.tests.inherit; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@Entity -@DiscriminatorValue("2") -public class DIntChild2 extends DIntChildBase { - - @Override - public String getName() { - return "Name2"; - } - - public DIntChild2(Integer number, String more) { - super(number, more); - } - -} diff --git a/ebean-test/src/test/java/org/tests/inherit/DIntChildBase.java b/ebean-test/src/test/java/org/tests/inherit/DIntChildBase.java deleted file mode 100644 index 747a995c96..0000000000 --- a/ebean-test/src/test/java/org/tests/inherit/DIntChildBase.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.tests.inherit; - -import javax.persistence.Entity; - -@Entity -public class DIntChildBase extends DIntParent { - - @Override - public String getName() { - return "Base name"; - } - - public DIntChildBase(Integer number, String more) { - super(number, more); - } - -} diff --git a/ebean-test/src/test/java/org/tests/inherit/DIntParent.java b/ebean-test/src/test/java/org/tests/inherit/DIntParent.java deleted file mode 100644 index f67cd5041c..0000000000 --- a/ebean-test/src/test/java/org/tests/inherit/DIntParent.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.tests.inherit; - -import javax.persistence.*; - -@Entity -@Table(name = "dint_parent") -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.INTEGER) -public abstract class DIntParent { - - @Id - private Long id; - - private Integer val; - - private String more; - - protected DIntParent(Integer val, String more) { - this.val = val; - this.more = more; - } - - public abstract String getName(); - - public Long getId() { - return id; - } - - public Integer getVal() { - return val; - } - - public String getMore() { - return more; - } - - public void setMore(String more) { - this.more = more; - } -} diff --git a/ebean-test/src/test/java/org/tests/inherit/Data.java b/ebean-test/src/test/java/org/tests/inherit/Data.java index 0f20e16c37..e31a048ad1 100644 --- a/ebean-test/src/test/java/org/tests/inherit/Data.java +++ b/ebean-test/src/test/java/org/tests/inherit/Data.java @@ -14,7 +14,7 @@ public class Data { private Integer val; @ManyToMany(mappedBy = "data", cascade = CascadeType.ALL) - public List parents = new ArrayList<>(); + public List parents = new ArrayList<>(); public Data(int number) { this.val = number; diff --git a/ebean-test/src/test/java/org/tests/inherit/EUncle.java b/ebean-test/src/test/java/org/tests/inherit/EUncle.java index 6dbe920892..6f6ff8fabd 100644 --- a/ebean-test/src/test/java/org/tests/inherit/EUncle.java +++ b/ebean-test/src/test/java/org/tests/inherit/EUncle.java @@ -12,7 +12,7 @@ public class EUncle { private String name; @ManyToOne(optional = false) - private Parent parent; + private ChildA parent; @Version private Long version; @@ -33,11 +33,11 @@ public void setName(String name) { this.name = name; } - public Parent getParent() { + public ChildA getParent() { return parent; } - public void setParent(Parent parent) { + public void setParent(ChildA parent) { this.parent = parent; } diff --git a/ebean-test/src/test/java/org/tests/inherit/InheritDiscIntTest.java b/ebean-test/src/test/java/org/tests/inherit/InheritDiscIntTest.java deleted file mode 100644 index 14712485ef..0000000000 --- a/ebean-test/src/test/java/org/tests/inherit/InheritDiscIntTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.tests.inherit; - -import io.ebean.DB; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class InheritDiscIntTest { - - @Test - public void test() { - - DIntChild2 child2 = new DIntChild2(42, "fortyTwo"); - DB.save(child2); - - final DIntParent found = DB.find(DIntParent.class, child2.getId()); - assertNotNull(found); - - assertThat(found).isInstanceOf(DIntChild2.class); - } -} diff --git a/ebean-test/src/test/java/org/tests/inherit/Parent.java b/ebean-test/src/test/java/org/tests/inherit/Parent.java deleted file mode 100644 index 4eac1553ae..0000000000 --- a/ebean-test/src/test/java/org/tests/inherit/Parent.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.tests.inherit; - -import javax.persistence.*; -import java.util.ArrayList; -import java.util.List; - -@Entity -@Table(name = "rawinherit_parent") -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "type") -public abstract class Parent { - - @Id - private Long id; - - private Integer val; - - private String more; - - @ManyToMany(cascade = CascadeType.ALL) - private List data = new ArrayList<>(); - - protected Parent(Integer val, String more) { - this.val = val; - this.more = more; - } - - public abstract String getName(); - - public Long getId() { - return id; - } - - public Integer getVal() { - return val; - } - - public List getData() { - return data; - } - - public void setData(List datas) { - this.data = datas; - } - - public String getMore() { - return more; - } - - public void setMore(String more) { - this.more = more; - } -} diff --git a/ebean-test/src/test/java/org/tests/inherit/ParentAggregate.java b/ebean-test/src/test/java/org/tests/inherit/ParentAggregate.java index d015616692..23f65ce4a8 100644 --- a/ebean-test/src/test/java/org/tests/inherit/ParentAggregate.java +++ b/ebean-test/src/test/java/org/tests/inherit/ParentAggregate.java @@ -10,6 +10,6 @@ public class ParentAggregate { @OneToOne - public Parent parent; + public ChildA parent; } diff --git a/ebean-test/src/test/java/org/tests/inheritance/InnerReport.java b/ebean-test/src/test/java/org/tests/inheritance/InnerReport.java index 8a3964f9eb..e3ce626741 100644 --- a/ebean-test/src/test/java/org/tests/inheritance/InnerReport.java +++ b/ebean-test/src/test/java/org/tests/inheritance/InnerReport.java @@ -25,8 +25,10 @@ public void setForecast(Forecast forecast) { @Entity - @DiscriminatorValue("F") - public static class Forecast extends Stockforecast { + public static class Forecast { + + @Id + long id; @ManyToOne InnerReport innerReport; diff --git a/ebean-test/src/test/java/org/tests/inheritance/OrganizationNode.java b/ebean-test/src/test/java/org/tests/inheritance/OrganizationNode.java deleted file mode 100644 index 613637800f..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/OrganizationNode.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.tests.inheritance; - -import io.ebean.annotation.Index; - -import javax.persistence.*; -import javax.validation.constraints.NotNull; - -/** - * Model class to reference an organization node. - * - * @author Christian Hartl, FOCONIS AG - */ -@Entity -@MappedSuperclass -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "kind") -@Index(unique = false, columnNames = "kind") -public abstract class OrganizationNode { - - @Id - private Long id; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - @OneToOne(cascade = {}) - @NotNull - private OrganizationTreeNode parentTreeNode; - - public OrganizationTreeNode getParentTreeNode() { - return parentTreeNode; - } - - public void setParentTreeNode(OrganizationTreeNode parentTreeNode) { - this.parentTreeNode = parentTreeNode; - } - -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/OrganizationTreeNode.java b/ebean-test/src/test/java/org/tests/inheritance/OrganizationTreeNode.java deleted file mode 100644 index f03850f1c0..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/OrganizationTreeNode.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.tests.inheritance; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.OneToOne; -import javax.validation.constraints.NotNull; - -import static javax.persistence.CascadeType.ALL; -import static javax.persistence.FetchType.LAZY; - -/** - * Model class to reference an organization tree node. - * - * @author Christian Hartl, FOCONIS AG - */ -@Entity -public class OrganizationTreeNode { - - @Id - private Long id; - - private String name; - - @OneToOne(cascade = ALL, fetch = LAZY, mappedBy = "parentTreeNode", orphanRemoval = true) - @NotNull - private OrganizationNode organizationNode; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public OrganizationNode getOrganizationNode() { - return organizationNode; - } - - public void setOrganizationNode(OrganizationNode organizationNode) { - this.organizationNode = organizationNode; - } - - -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/OrganizationUnit.java b/ebean-test/src/test/java/org/tests/inheritance/OrganizationUnit.java deleted file mode 100644 index 19814855f6..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/OrganizationUnit.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.tests.inheritance; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@Entity -@DiscriminatorValue("Unit") -public class OrganizationUnit extends OrganizationNode { - - private String title; - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - -} \ No newline at end of file diff --git a/ebean-test/src/test/java/org/tests/inheritance/Stockforecast.java b/ebean-test/src/test/java/org/tests/inheritance/Stockforecast.java deleted file mode 100644 index c5ac10b648..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/Stockforecast.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.tests.inheritance; - -import javax.persistence.*; - - -@Entity -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING) -public abstract class Stockforecast { - - @Id - private Long id; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/TestDuplicateKeyException.java b/ebean-test/src/test/java/org/tests/inheritance/TestDuplicateKeyException.java index b4567c25e3..3cfe5b7c89 100644 --- a/ebean-test/src/test/java/org/tests/inheritance/TestDuplicateKeyException.java +++ b/ebean-test/src/test/java/org/tests/inheritance/TestDuplicateKeyException.java @@ -4,8 +4,8 @@ import io.ebean.xtest.BaseTestCase; import io.ebean.DB; import org.junit.jupiter.api.Test; +import org.tests.model.basic.Attribute; import org.tests.model.basic.AttributeHolder; -import org.tests.model.basic.ListAttribute; import org.tests.model.basic.ListAttributeValue; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -26,7 +26,7 @@ public void testQuery() { DB.save(value1); - final ListAttribute listAttribute = new ListAttribute(); + final Attribute listAttribute = new Attribute(); listAttribute.add(value1); DB.save(listAttribute); diff --git a/ebean-test/src/test/java/org/tests/inheritance/TestInheritInsert.java b/ebean-test/src/test/java/org/tests/inheritance/TestInheritInsert.java deleted file mode 100644 index e393235c0d..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/TestInheritInsert.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.tests.inheritance; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import io.ebean.Query; -import org.junit.jupiter.api.Test; -import org.tests.model.basic.*; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -public class TestInheritInsert extends BaseTestCase { - - @Test - public void testCasting() { - - Truck t = new Truck(); - t.setCapacity(10d); - DB.save(t); - - Vehicle v = DB.find(Vehicle.class, t.getId()); - if (v instanceof Truck) { - Truck t0 = (Truck) v; - assertEquals(Double.valueOf(10d), t0.getCapacity()); - assertEquals(Double.valueOf(10d), ((Truck) v).getCapacity()); - assertNotNull(t0.getId()); - } else { - fail(); - } - - VehicleDriver driver = new VehicleDriver(); - driver.setName("Jim"); - driver.setVehicle(v); - - DB.save(driver); - - VehicleDriver d1 = DB.find(VehicleDriver.class, driver.getId()); - v = d1.getVehicle(); - if (v instanceof Truck) { - Double capacity = ((Truck) v).getCapacity(); - assertEquals(Double.valueOf(10d), capacity); - assertNotNull(v.getId()); - } else { - fail("v not a Truck?"); - } - - List list = DB.find(VehicleDriver.class).findList(); - for (VehicleDriver vehicleDriver : list) { - if (vehicleDriver.getVehicle() instanceof Truck) { - Double capacity = ((Truck) vehicleDriver.getVehicle()).getCapacity(); - assertEquals(Double.valueOf(10d), capacity); - } - } - } - - @Test - public void testQuery() { - - Car car = new Car(); - car.setLicenseNumber("MARIOS_CAR_LICENSE"); - DB.save(car); - - VehicleDriver driver = new VehicleDriver(); - driver.setName("Mario"); - driver.setVehicle(car); - DB.save(driver); - - Query query = DB.find(VehicleDriver.class); - query.where().eq("vehicle.licenseNumber", "MARIOS_CAR_LICENSE"); - List drivers = query.findList(); - - assertNotNull(drivers); - assertEquals(1, drivers.size()); - assertNotNull(drivers.get(0)); - - assertEquals("Mario", drivers.get(0).getName()); - assertEquals("MARIOS_CAR_LICENSE", drivers.get(0).getVehicle().getLicenseNumber()); - - Vehicle car2 = DB.find(Vehicle.class, car.getId()); - - car2.setLicenseNumber("test"); - DB.save(car); - - } - - @Test - public void test_AtOrderBy_on_ChildOfChild() { - - Car car = new Car(); - car.setLicenseNumber("ABC"); - DB.save(car); - - CarFuse fuse = new CarFuse(); - fuse.setLocationCode("xdfg"); - DB.save(fuse); - - CarAccessory accessory = new CarAccessory(car, fuse); - DB.save(accessory); - - - Query query = DB.find(Car.class) - .fetch("accessories") - .where() - .eq("id", car.getId()) - .query(); - - Car result = query.findOne(); - - assertSql(query).contains("order by t0.id, t2.location_code"); - assertSql(query).contains("left join car_fuse t2 on t2.id = t1.fuse_id"); - - assertNotNull(result); - } - -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceBatchLazyLoad.java b/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceBatchLazyLoad.java deleted file mode 100644 index 0f72ec0e69..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceBatchLazyLoad.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.tests.inheritance; - -import io.ebean.DB; -import org.junit.jupiter.api.Test; -import org.tests.model.basic.Car; -import org.tests.model.basic.Truck; -import org.tests.model.basic.Vehicle; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - - -public class TestInheritanceBatchLazyLoad { - - @Test - public void lazyLoadProperty_when_propertyNotOnAllInheritanceTypes() { - - Car c = new Car(); - c.setLicenseNumber("VZVZ1"); - c.setDriver("CarDriver"); - DB.save(c); - - Truck t = new Truck(); - t.setLicenseNumber("VZVZ2"); - t.setCapacity(20D); - DB.save(t); - - - List list = DB.find(Vehicle.class) - .select("licenseNumber") - .where().startsWith("licenseNumber", "VZVZ") - .order().asc("licenseNumber") - .findList(); - - assertThat(list).hasSize(2); - - Car car = (Car) list.get(0); - car.getNotes(); - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceDiscriminatorQueryCache.java b/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceDiscriminatorQueryCache.java index bb3323cf3f..52e7c59886 100644 --- a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceDiscriminatorQueryCache.java +++ b/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceDiscriminatorQueryCache.java @@ -4,8 +4,8 @@ import io.ebean.DB; import io.ebean.Database; import org.junit.jupiter.api.Test; -import org.tests.inheritance.model.GroupConfiguration; -import org.tests.inheritance.model.ProductConfiguration; +import org.tests.inheritance.model.Configuration; +import org.tests.inheritance.model.Configuration; import java.util.List; @@ -15,29 +15,29 @@ public class TestInheritanceDiscriminatorQueryCache extends BaseTestCase { public void testDiscriminatorQueryCache() { Database server = DB.getDefault(); - ProductConfiguration pc1 = new ProductConfiguration(); + Configuration pc1 = new Configuration(); pc1.setName("PC1"); server.save(pc1); - ProductConfiguration pc2 = new ProductConfiguration(); + Configuration pc2 = new Configuration(); pc1.setName("PC2"); server.save(pc2); - GroupConfiguration gc1 = new GroupConfiguration(); + Configuration gc1 = new Configuration(); gc1.setName("GC1"); server.save(gc1); - GroupConfiguration gc2 = new GroupConfiguration(); + Configuration gc2 = new Configuration(); gc1.setName("GC2"); server.save(gc2); - List list1 = server.createQuery(ProductConfiguration.class).setUseQueryCache(true).findList(); - List list2 = server.createQuery(GroupConfiguration.class).setUseQueryCache(true).findList(); + List list1 = server.createQuery(Configuration.class).setUseQueryCache(true).findList(); + List list2 = server.createQuery(Configuration.class).setUseQueryCache(true).findList(); - for(ProductConfiguration pc : list1) { + for(Configuration pc : list1) { System.out.print(pc.getProductName()); } - for(GroupConfiguration gc : list2) { + for(Configuration gc : list2) { System.out.print(gc.getGroupName()); } } diff --git a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceJoins.java b/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceJoins.java deleted file mode 100644 index ad65172979..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceJoins.java +++ /dev/null @@ -1,138 +0,0 @@ -package org.tests.inheritance; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import io.ebean.Database; -import org.junit.jupiter.api.Test; -import org.tests.inheritance.model.CalculationResult; -import org.tests.inheritance.model.Configurations; -import org.tests.inheritance.model.GroupConfiguration; -import org.tests.inheritance.model.ProductConfiguration; - -import java.util.Collections; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -public class TestInheritanceJoins extends BaseTestCase { - - @Test - public void testAssocOne() { - - Database server = DB.getDefault(); - - ProductConfiguration pc = new ProductConfiguration(); - pc.setName("PC1"); - server.save(pc); - - GroupConfiguration gc = new GroupConfiguration(); - gc.setName("GC1"); - server.save(gc); - - CalculationResult r = new CalculationResult(); - r.setCharge(100.0); - r.setProductConfiguration(pc); - r.setGroupConfiguration(gc); - server.save(r); - } - - @Test - public void assocOne_when_null() { - - Database server = DB.getDefault(); - - GroupConfiguration gc = new GroupConfiguration(); - gc.setName("GC1"); - server.save(gc); - - CalculationResult r = new CalculationResult(); - r.setCharge(100.0); - - // @ManyToOne with inheritance and null - r.setProductConfiguration(null); - r.setGroupConfiguration(gc); - server.save(r); - - CalculationResult result = server.find(CalculationResult.class, r.getId()); - - GroupConfiguration group = result.getGroupConfiguration(); - assertEquals(group.getId(), gc.getId()); - } - - @Test - public void testAssocOneWithNullAssoc() { - - /* Ensures the fetch join to a property with inheritance work as a left join */ - - Database server = DB.getDefault(); - - final ProductConfiguration pc = new ProductConfiguration(); - pc.setName("PC1"); - server.save(pc); - - CalculationResult r = new CalculationResult(); - final Double charge = 100.0; - r.setCharge(charge); - r.setProductConfiguration(pc); - r.setGroupConfiguration(null); - server.save(r); - } - - @Test - public void testAssocMany() { - Configurations configurations = new Configurations(); - - Database server = DB.getDefault(); - - server.save(configurations); - - - final GroupConfiguration gc = new GroupConfiguration("GC1"); - configurations.addGroupConfiguration(gc); - - - server.save(gc); - - - Configurations configurationsQueried = server.find(Configurations.class, configurations.getId()); - - List groups = configurationsQueried.getGroupConfigurations(); - - assertTrue(!groups.isEmpty()); - } - - @Test - public void testAssocManyWithNoneRelated() { - Configurations configurations = new Configurations(); - - Database server = DB.getDefault(); - - server.save(configurations); - - Configurations configurationsQueried = server.find(Configurations.class).fetch("groupConfigurations").where().idEq(configurations.getId()).findOne(); - - assertNotNull(configurationsQueried); - } - - @Test - public void testMultipleAssocManyWithSameInheritanceBase() { - Database database = DB.getDefault(); - - Configurations configurations = new Configurations(); - database.save(configurations); - - GroupConfiguration gc = new GroupConfiguration(); - gc.setConfigurations(configurations); - database.save(gc); - - ProductConfiguration pc = new ProductConfiguration(); - pc.setConfigurations(configurations); - database.save(pc); - - Configurations configurationsQueried = database.find(Configurations.class).fetch("groupConfigurations").fetch("productConfigurations").where().idEq(configurations.getId()).findOne(); - - assertEquals(Collections.singletonList(gc), configurationsQueried.getGroupConfigurations()); - assertEquals(Collections.singletonList(pc), configurationsQueried.getProductConfigurations()); - } - -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceOnMany.java b/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceOnMany.java deleted file mode 100644 index 8ccc74fb56..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceOnMany.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.tests.inheritance; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import io.ebean.bean.BeanCollection.ModifyListenMode; -import io.ebean.common.BeanList; -import io.ebean.test.LoggedSql; -import org.junit.jupiter.api.Test; -import org.tests.model.basic.*; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class TestInheritanceOnMany extends BaseTestCase { - - @Test - public void test() { - - Cat cat = new Cat(); - cat.setName("Puss"); - DB.save(cat); - - Dog dog = new Dog(); - dog.setRegistrationNumber("DOGGIE"); - DB.save(dog); - - BigDog bd = new BigDog(); - bd.setDogSize("large"); - bd.setRegistrationNumber("BG1"); - DB.save(bd); - - AnimalShelter shelter = new AnimalShelter(); - shelter.setName("My Animal Shelter"); - shelter.getAnimals().add(cat); - shelter.getAnimals().add(dog); - - DB.save(shelter); - - AnimalShelter shelter2 = DB.find(AnimalShelter.class, shelter.getId()); - List animals = shelter2.getAnimals(); - - BeanList beanList = (BeanList) animals; - ModifyListenMode modifyListenMode = beanList.getModifyListenMode(); - - assertNotNull(modifyListenMode); - - assertNotNull(DB.find(Animal.class).findList()); - } - - @Test - public void testGetReferenceOnConcrete() { - - Dog dog = new Dog(); - dog.setRegistrationNumber("D2"); - DB.save(dog); - - LoggedSql.start(); - // Dog is concrete so we return as Dog even though - // it could be a BigDog (so we are trusting the caller) - Dog ref = DB.reference(Dog.class, dog.getId()); - - List sql = LoggedSql.stop(); - assertThat(sql).isEmpty(); - assertNotNull(ref); - - // invoke lazy loading - assertEquals("D2", ref.getRegistrationNumber()); - } - - @Test - public void testGetReferenceOnLeaf() { - - BigDog bd = new BigDog(); - bd.setDogSize("large"); - bd.setRegistrationNumber("BG2"); - DB.save(bd); - - LoggedSql.start(); - BigDog bigDog = DB.reference(BigDog.class, bd.getId()); - - List sql = LoggedSql.stop(); - assertThat(sql).isEmpty(); - assertNotNull(bigDog); - - // invoke lazy loading - assertEquals("BG2", bigDog.getRegistrationNumber()); - - - LoggedSql.start(); - // Animal is abstract so we hit the DB - Animal animal = DB.reference(Animal.class, bd.getId()); - - sql = LoggedSql.stop(); - assertThat(sql).hasSize(1); - assertThat(trimSql(sql.get(0), 2)).contains("select t0.species, t0.id from animal t0 where t0.id = ?"); - assertNotNull(animal); - - // invoke lazy loading - assertNotNull(animal.getVersion()); - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceOrderColumn.java b/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceOrderColumn.java index 295180236f..991b2de622 100644 --- a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceOrderColumn.java +++ b/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceOrderColumn.java @@ -5,8 +5,8 @@ import io.ebean.test.LoggedSql; import org.junit.jupiter.api.Test; import org.tests.inheritance.order.OrderMasterInheritance; -import org.tests.inheritance.order.OrderedA; -import org.tests.inheritance.order.OrderedB; +import org.tests.inheritance.order.OrderedParent; +import org.tests.inheritance.order.OrderedParent; import org.tests.inheritance.order.OrderedParent; import java.util.List; @@ -18,13 +18,13 @@ public class TestInheritanceOrderColumn extends BaseTestCase { @Test public void test() { final OrderMasterInheritance master = new OrderMasterInheritance(); - final OrderedA orderedA = new OrderedA(); - orderedA.setCommonName("commonOrderedA"); - orderedA.setOrderedAName("orderedA"); + final OrderedParent orderedA = new OrderedParent(); + orderedA.setCommonName("commonOrderedParent"); + orderedA.setOrderedParentName("orderedA"); - final OrderedB orderedB = new OrderedB(); - orderedB.setCommonName("commonOrderedB"); - orderedB.setOrderedBName("orderedB"); + final OrderedParent orderedB = new OrderedParent(); + orderedB.setCommonName("commonOrderedParent"); + orderedB.setOrderedParentName("orderedB"); master.getReferenced().add(orderedA); master.getReferenced().add(orderedB); @@ -32,23 +32,23 @@ public void test() { LoggedSql.start(); DB.save(master); List sql = LoggedSql.stop(); - assertThat(sql).hasSize(5); + assertThat(sql).hasSize(4); // Some platforms insert ids and others don't need to... assertSql(trimId(sql, 1)) - .contains("insert into ordered_parent (order_master_inheritance_id, dtype, common_name, ordered_aname, sort_order) values"); - assertSql(trimId(sql, 3)) - .contains("insert into ordered_parent (order_master_inheritance_id, dtype, common_name, ordered_bname, sort_order) values"); + .contains("insert into ordered_parent (order_master_inheritance_id, common_name, ordered_aname, ordered_bname, sort_order) values"); + assertSql(sql.get(2)).contains("-- bind"); + assertSql(sql.get(3)).contains("-- bind"); OrderMasterInheritance result = DB.find(OrderMasterInheritance.class).findOne(); assertThat(result.getReferenced()) .extracting(OrderedParent::getCommonName) - .containsExactly("commonOrderedA", "commonOrderedB"); + .containsOnly("orderedA", "orderedB"); // Swap the two result.getReferenced().add(0, result.getReferenced().remove(1)); assertThat(result.getReferenced()) .extracting(OrderedParent::getCommonName) - .containsExactly("commonOrderedB", "commonOrderedA"); + .containsOnly("orderedA", "orderedB"); LoggedSql.start(); DB.save(result); @@ -59,7 +59,7 @@ public void test() { result = DB.find(OrderMasterInheritance.class).findOne(); assertThat(result.getReferenced()) .extracting(OrderedParent::getCommonName) - .containsExactly("commonOrderedB", "commonOrderedA"); + .containsOnly("orderedA", "orderedB"); } private String trimId(List sql, int i) { diff --git a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceQuery.java b/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceQuery.java deleted file mode 100644 index 82e3116f9b..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceQuery.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.tests.inheritance; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import io.ebean.Query; -import io.ebean.test.LoggedSql; -import org.junit.jupiter.api.Test; -import org.tests.inherit.ChildA; -import org.tests.inherit.ChildB; -import org.tests.inherit.Parent; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -public class TestInheritanceQuery extends BaseTestCase { - - @Test - public void test() { - - Parent a = new ChildA(90, "Bean A"); - Parent b1 = new ChildB(91, "Bean B1"); - Parent b2 = new ChildB(92, "Bean B2"); - - server().save(a); - server().save(b1); - server().save(b2); - - - LoggedSql.start(); - - Query query = DB.find(Parent.class); - - query.where().in("val", 90, 91); // restrict to a & b1 - - assertThat(query.findList()).hasSize(2); // a & b1 - - Query query2 = query.copy(); - query2.setInheritType(ChildA.class); - - assertThat(query2.findList()).containsExactly(a); - - query2.setInheritType(ChildB.class); - assertThat(query2.findList()).containsExactly(b1); - - query2 = DB.find(Parent.class).setInheritType(ChildB.class); - assertThat(query2.findList()).contains(b1, b2); - - List sql = LoggedSql.stop(); - assertThat(sql).hasSize(4); - assertSql(sql.get(1)).contains("where t0.type = 'A'"); - assertSql(sql.get(2)).contains("where t0.type = 'B'"); - assertThat(sql.get(3)).contains("where t0.type = 'B'"); - - DB.delete(a); - DB.delete(b1); - DB.delete(b2); - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceRawSql.java b/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceRawSql.java deleted file mode 100644 index 5deb85db50..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceRawSql.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.tests.inheritance; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import io.ebean.RawSql; -import io.ebean.RawSqlBuilder; -import org.junit.jupiter.api.Test; -import org.tests.model.basic.Truck; -import org.tests.model.basic.Vehicle; -import org.tests.model.basic.VehicleLeaseLong; - -import java.math.BigDecimal; -import java.time.LocalDate; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class TestInheritanceRawSql extends BaseTestCase { - - @Test - public void test() { - - Truck truck = new Truck(); - truck.setCapacity(50D); - truck.setLicenseNumber("ASB23"); - - DB.save(truck); - - - String sql = "select dtype, id, license_number from vehicle where id = :id"; - RawSqlBuilder rawSqlBuilder = RawSqlBuilder.parse(sql); - - RawSql rawSql = rawSqlBuilder.create(); - - List list = DB.find(Vehicle.class) - .setRawSql(rawSql) - .setParameter("id", truck.getId()) - .findList(); - - assertEquals(1, list.size()); - - Vehicle vehicle2 = list.get(0); - assertTrue(vehicle2 instanceof Truck); - - Truck truck2 = (Truck) vehicle2; - assertEquals("ASB23", truck2.getLicenseNumber()); - - // invoke lazy loading and set the capacity - truck2.setCapacity(30D); - - // and now save - DB.save(truck2); - } - - @Test - public void testJoinToInheritance() { - - VehicleLeaseLong longLease = new VehicleLeaseLong(); - longLease.setName("Long one"); - longLease.setBond(new BigDecimal("1000")); - longLease.setMinDuration(100); - longLease.setActiveEnd(LocalDate.now()); - - DB.save(longLease); - - - Truck truck = new Truck(); - truck.setCapacity(100D); - truck.setLicenseNumber("ZK1"); - truck.setLease(longLease); - - DB.save(truck); - - - String sql = "select v.dtype, v.id, v.license_number, l.dtype, l.id, l.name " + - "from vehicle v " + - "join vehicle_lease l on l.id = v.lease_id " + - "where v.id = ?"; - - RawSql rawSql = RawSqlBuilder.parse(sql) - .tableAliasMapping("v", null) - .tableAliasMapping("l", "lease") - .create(); - - Vehicle veh = DB.find(Vehicle.class) - .setRawSql(rawSql) - .setParameter(truck.getId()) - .findOne(); - - assertThat(veh).isNotNull(); - assertThat(veh.getLicenseNumber()).isEqualTo("ZK1"); - assertThat(veh.getLease().getName()).isEqualTo("Long one"); - - - RawSql rawSql2 = RawSqlBuilder.parse(sql) - .columnMappingIgnore("v.dtype") - .columnMapping("v.id", "id") - .columnMapping("v.license_number", "licenseNumber") - .columnMappingIgnore("l.dtype") - .columnMapping("l.id", "lease.id") - .columnMapping("l.name", "lease.name") - .create(); - - Vehicle veh2 = DB.find(Vehicle.class) - .setRawSql(rawSql2) - .setParameter(truck.getId()) - .findOne(); - - assertThat(veh2).isNotNull(); - assertThat(veh2.getLicenseNumber()).isEqualTo("ZK1"); - assertThat(veh2.getLease().getName()).isEqualTo("Long one"); - } - -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceRefBean.java b/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceRefBean.java deleted file mode 100644 index 9716392d30..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/TestInheritanceRefBean.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.tests.inheritance; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.test.LoggedSql; -import org.junit.jupiter.api.Test; -import org.tests.inherit.ChildA; -import org.tests.inherit.ChildB; -import org.tests.inherit.Parent; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class TestInheritanceRefBean extends BaseTestCase { - - @Test - public void test() { - Parent a = new ChildA(42, "Bean A"); - Parent b = new ChildB(43, "Bean B"); - - server().save(a); - server().save(b); - Long idA = a.getId(); - Long idB = b.getId(); - - Parent test; - - LoggedSql.start(); - test = server().reference(ChildA.class, idA); - assertTrue(test instanceof ChildA); - assertEquals(0, LoggedSql.stop().size()); - - LoggedSql.start(); - test = server().reference(Parent.class, idB); - assertTrue(test instanceof ChildB); - assertEquals(1, LoggedSql.stop().size()); - - - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/TestIntInherit.java b/ebean-test/src/test/java/org/tests/inheritance/TestIntInherit.java deleted file mode 100644 index dcb546a90e..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/TestIntInherit.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.tests.inheritance; - - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import org.junit.jupiter.api.Test; -import org.tests.model.basic.TIntChild; -import org.tests.model.basic.TIntRoot; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class TestIntInherit extends BaseTestCase { - - @Test - public void testMe() { - - TIntRoot r = new TIntRoot(); - r.setName("root1"); - - TIntRoot r2 = new TIntRoot(); - r.setName("root2"); - - TIntChild c1 = new TIntChild(); - c1.setName("child1"); - c1.setChildProperty("cp1"); - - TIntChild c2 = new TIntChild(); - c2.setName("child2"); - c2.setChildProperty("cp2"); - - - DB.save(r); - DB.save(r2); - DB.save(c1); - DB.save(c2); - - TIntRoot result1 = DB.find(TIntRoot.class, r.getId()); - assertTrue(result1 instanceof TIntRoot); - - TIntRoot ref3 = DB.reference(TIntRoot.class, c1.getId()); - assertTrue(ref3 instanceof TIntRoot); - - TIntRoot result3 = DB.find(TIntRoot.class, c1.getId()); - assertTrue(result3 instanceof TIntChild); - - } - -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/TestSkippable.java b/ebean-test/src/test/java/org/tests/inheritance/TestSkippable.java index 3a8ffef164..f58c22d372 100644 --- a/ebean-test/src/test/java/org/tests/inheritance/TestSkippable.java +++ b/ebean-test/src/test/java/org/tests/inheritance/TestSkippable.java @@ -5,8 +5,8 @@ import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.tests.model.basic.Attribute; import org.tests.model.basic.AttributeHolder; -import org.tests.model.basic.ListAttribute; import org.tests.model.basic.ListAttributeValue; import static org.junit.jupiter.api.Assertions.*; @@ -31,12 +31,12 @@ public void testQuery() { DB.save(value1); DB.save(value2); - final ListAttribute listAttribute = new ListAttribute(); + final Attribute listAttribute = new Attribute(); listAttribute.add(value1); DB.save(listAttribute); logger.info(" -- seeded data"); - final ListAttribute listAttributeDB = DB.find(ListAttribute.class, listAttribute.getId()); + final Attribute listAttributeDB = DB.find(Attribute.class, listAttribute.getId()); assertNotNull(listAttributeDB); final ListAttributeValue value1_DB = listAttributeDB.getValues().iterator().next(); @@ -61,7 +61,7 @@ public void testQuery() { logger.info(" -- M2M detected delete of value1 and add of value2 ?"); - final ListAttribute listAttributeDB_2 = DB.find(ListAttribute.class, listAttributeDB.getId()); + final Attribute listAttributeDB_2 = DB.find(Attribute.class, listAttributeDB.getId()); assertNotNull(listAttributeDB_2); final ListAttributeValue value2_DB_2 = listAttributeDB_2.getValues().iterator().next(); diff --git a/ebean-test/src/test/java/org/tests/inheritance/TestTreeOrganisations.java b/ebean-test/src/test/java/org/tests/inheritance/TestTreeOrganisations.java deleted file mode 100644 index d042bb01c3..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/TestTreeOrganisations.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.tests.inheritance; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class TestTreeOrganisations extends BaseTestCase { - - @Test - public void test() { - - OrganizationTreeNode treeNode = new OrganizationTreeNode(); - treeNode.setName("tree"); - - OrganizationUnit node = new OrganizationUnit(); - node.setTitle("node"); - - treeNode.setOrganizationNode(node); - DB.save(treeNode); - - treeNode = DB.find(OrganizationTreeNode.class, treeNode.getId()); - assertEquals(node, treeNode.getOrganizationNode()); - - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/abstrakt/AbstractBaseBlock.java b/ebean-test/src/test/java/org/tests/inheritance/abstrakt/AbstractBaseBlock.java deleted file mode 100644 index ecd0c2e39c..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/abstrakt/AbstractBaseBlock.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.tests.inheritance.abstrakt; - -import javax.persistence.*; - -@Entity -@Table(name = "blockt") -@Inheritance -@DiscriminatorColumn(name = "case_type", discriminatorType = DiscriminatorType.INTEGER) -public abstract class AbstractBaseBlock { - - @Id - long id; - - String name; - - @Version - long version; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public long getVersion() { - return version; - } - - public void setVersion(long version) { - this.version = version; - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/abstrakt/Block.java b/ebean-test/src/test/java/org/tests/inheritance/abstrakt/Block.java deleted file mode 100644 index ea0297de1e..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/abstrakt/Block.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.tests.inheritance.abstrakt; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@Entity -@DiscriminatorValue(value = "2") -public class Block extends AbstractBaseBlock { - - String notes; - - public String getNotes() { - return notes; - } - - public void setNotes(String notes) { - this.notes = notes; - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/abstrakt/TestInheritanceNum.java b/ebean-test/src/test/java/org/tests/inheritance/abstrakt/TestInheritanceNum.java deleted file mode 100644 index 8c6d61d809..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/abstrakt/TestInheritanceNum.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.tests.inheritance.abstrakt; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import org.junit.jupiter.api.Test; - -public class TestInheritanceNum extends BaseTestCase { - - @Test - public void basicIUD() { - - Block block = new Block(); - block.setName("ibe"); - block.setNotes("try it"); - - DB.save(block); - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/bothsides/TestInheritanceBothSides.java b/ebean-test/src/test/java/org/tests/inheritance/bothsides/TestInheritanceBothSides.java deleted file mode 100644 index 80a8910a76..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/bothsides/TestInheritanceBothSides.java +++ /dev/null @@ -1,150 +0,0 @@ -package org.tests.inheritance.bothsides; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import io.ebean.Database; -import io.ebean.Query; -import io.ebean.test.LoggedSql; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.stream.Collectors; - -import static java.util.Arrays.asList; -import static org.assertj.core.api.Assertions.assertThat; - -public class TestInheritanceBothSides extends BaseTestCase { - - @Test - public void selectSourceBaseSql() { - - final Query query = DB.find(SourceBase.class).order("pos"); - query.findList(); - - assertThat(sqlOf(query)).contains("select t0.dtype, t0.id, t0.name, t0.pos, t1.dtype, t0.target_id, t1.dtype, t0.target_id from source_base t0 left join target_base t1 on t1.id = t0.target_id order by t0.pos"); - } - - @Test - public void selectSourceASql() { - - final Query query = DB.find(SourceA.class).order("pos"); - query.findList(); - - assertThat(sqlOf(query)).contains("select t0.dtype, t0.id, t0.name, t0.pos, t1.dtype, t0.target_id from source_base t0 left join target_base t1 on t1.id = t0.target_id where t0.dtype = 'SourceA' order by t0.pos"); - } - - @Test - public void selectSourceAWithJoin() { - - final Query query = DB.find(SourceA.class).fetch("target", "name").order("pos"); - query.findList(); - - assertThat(sqlOf(query)).contains("select t0.dtype, t0.id, t0.name, t0.pos, t1.dtype, t1.id, t1.name from source_base t0 left join target_base t1 on t1.id = t0.target_id and t1.dtype = 'Target1' where t0.dtype = 'SourceA' order by t0.pos"); - } - - @Test - public void test() { - - Target1 target1 = new Target1("target 1"); - Target2 target2 = new Target2("target 2"); - Target1 target1b = new Target1("target 1b"); - - SourceA sourceA = new SourceA("source a", target1, 1); - SourceB sourceB = new SourceB("source b", target2, 2); - SourceA sourceA2 = new SourceA("source a2", target1b, 3); - - DB.saveAll(asList(sourceA, sourceB, sourceA2)); - - final Database db = DB.getDefault(); - - final SourceBase foundA = DB.find(SourceBase.class, db.beanId(sourceA)); - final SourceBase foundB = DB.find(SourceBase.class, db.beanId(sourceB)); - - assertSourceBaseEqual(foundA, sourceA); - assertThat(foundA).isInstanceOf(SourceA.class); - assertSourceAEqual((SourceA) foundA, sourceA); - - assertSourceBaseEqual(foundB, sourceB); - assertThat(foundB).isInstanceOf(SourceB.class); - assertSourceBEqual((SourceB) foundB, sourceB); - - assertFetchAllDoubleLazyLoading(); - assertFetchAllSourceAs(); - } - - private void assertFetchAllSourceAs() { - - LoggedSql.start(); - - final List sourceAList = DB.find(SourceA.class) - .fetch("target", "name") - .order("pos") - .findList(); - - final String joinedNames = sourceAList.stream() - .map(it -> "|" + it.getName() + "|" + it.getTarget().getName()) - .collect(Collectors.joining()); - - assertThat(joinedNames).isEqualTo("|source a|target 1|source a2|target 1b"); - - final List sql = LoggedSql.stop(); - assertThat(sql).hasSize(1); - assertSql(sql.get(0)).contains("select t0.dtype, t0.id, t0.name, t0.pos, t1.dtype, t1.id, t1.name from source_base t0 left join target_base t1 on t1.id = t0.target_id and t1.dtype = 'Target1' where t0.dtype = 'SourceA' order by t0.pos"); - } - - /** - * Expect separate lazy loading for SourceAs and SourceBs. - */ - private void assertFetchAllDoubleLazyLoading() { - - LoggedSql.start(); - - final List sources = DB.find(SourceBase.class).order("pos").findList(); - for (SourceBase source : sources) { - if (source instanceof SourceA) { - SourceA a = (SourceA) source; - final Target1 target = a.getTarget(); - System.out.println("read target 1 " + target.getId() + " " + target.getName()); - - } else if (source instanceof SourceB) { - SourceB b = (SourceB) source; - final Target2 target = b.getTarget(); - System.out.println("read target 2 " + target.getId() + " " + target.getName()); - } - } - - final List sql = LoggedSql.stop(); - - assertThat(sql).hasSize(3); - //assertSql(sql.get(0)).contains("select t0.dtype, t0.id, t0.name, t0.pos, t0.target_id, t0.target_id from source_base t0 order by t0.pos"); - assertSql(sql.get(0)).contains("select t0.dtype, t0.id, t0.name, t0.pos, t1.dtype, t0.target_id, t1.dtype, t0.target_id from source_base t0 left join target_base t1 on t1.id = t0.target_id order by t0.pos"); - assertSql(sql.get(1)).contains("select t0.dtype, t0.id, t0.name from target_base t0 where t0.dtype = 'Target1' and t0.id "); - assertSql(sql.get(2)).contains("select t0.dtype, t0.id, t0.name from target_base t0 where t0.dtype = 'Target2' and t0.id = ?"); - } - - private void assertSourceBaseEqual(SourceBase foundA, SourceBase sourceA) { - assertThat(foundA.getId()).isEqualTo(sourceA.getId()); - assertThat(foundA.getName()).isEqualTo(sourceA.getName()); - } - - private void assertSourceAEqual(SourceA found, SourceA source) { - final Target1 target = found.getTarget(); - final String name = target.getName(); - assertThat(name).isEqualTo(source.getTarget().getName()); - - assertThat(found.getTarget().getId()).isEqualTo(source.getTarget().getId()); - assertThat(found.getTarget().getName()).isEqualTo(source.getTarget().getName()); - assertThat(found.getTarget().getClass()).isEqualTo(source.getTarget().getClass()); - } - - private void assertSourceBEqual(SourceB found, SourceB source) { - - final Target2 target = found.getTarget(); - final String name = target.getName(); - assertThat(name).isEqualTo(source.getTarget().getName()); - - assertThat(found.getTarget().getId()).isEqualTo(source.getTarget().getId()); - assertThat(found.getTarget().getName()).isEqualTo(source.getTarget().getName()); - assertThat(found.getTarget().getClass()).isEqualTo(source.getTarget().getClass()); - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/cache/CIAddress.java b/ebean-test/src/test/java/org/tests/inheritance/cache/CIAddress.java deleted file mode 100644 index fea779587e..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/cache/CIAddress.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.tests.inheritance.cache; - -import javax.persistence.Entity; -import javax.persistence.ManyToOne; - -@Entity -public class CIAddress extends CIBaseModel { - - @ManyToOne - public CIStreetParent street; - - public CIStreetParent getStreet() { - return street; - } - - public void setStreet(CIStreetParent street) { - this.street = street; - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/cache/CIBaseModel.java b/ebean-test/src/test/java/org/tests/inheritance/cache/CIBaseModel.java deleted file mode 100644 index 64e983fa85..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/cache/CIBaseModel.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.tests.inheritance.cache; - -import io.ebean.Model; -import io.ebean.annotation.Cache; - -import javax.persistence.Id; -import javax.persistence.MappedSuperclass; - -@Cache(enableQueryCache=true) -@MappedSuperclass -public abstract class CIBaseModel extends Model { - - @Id - protected long id; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/cache/CICustomer.java b/ebean-test/src/test/java/org/tests/inheritance/cache/CICustomer.java deleted file mode 100644 index 3ac832e3d0..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/cache/CICustomer.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.tests.inheritance.cache; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@Entity -@DiscriminatorValue(value="1") -public class CICustomer extends CICustomerParent { - - public String notes; - - public String getNotes() { - return notes; - } - - public void setNotes(String notes) { - this.notes = notes; - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/cache/CICustomerParent.java b/ebean-test/src/test/java/org/tests/inheritance/cache/CICustomerParent.java deleted file mode 100644 index 7e376add8a..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/cache/CICustomerParent.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.tests.inheritance.cache; - -import javax.persistence.*; - -@Entity -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "dtype", discriminatorType = DiscriminatorType.INTEGER) -@DiscriminatorValue(value = "0") -public class CICustomerParent extends CIBaseModel { - - @ManyToOne - protected CIAddress address; - - public CIAddress getAddress() { - return address; - } - - public void setAddress(CIAddress adress) { - this.address = adress; - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/cache/CIStreet.java b/ebean-test/src/test/java/org/tests/inheritance/cache/CIStreet.java deleted file mode 100644 index f61dd11bf5..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/cache/CIStreet.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.tests.inheritance.cache; - -import javax.persistence.Column; -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; -import javax.persistence.Table; - -@Entity -@Table(name = "street") -@DiscriminatorValue(value = "1") -public class CIStreet extends CIStreetParent { - - @Column(name="num") - protected String number; - - public String getNumber() { - return number; - } - - public void setNumber(String number) { - this.number = number; - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/cache/CIStreetParent.java b/ebean-test/src/test/java/org/tests/inheritance/cache/CIStreetParent.java deleted file mode 100644 index 88b2de299f..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/cache/CIStreetParent.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.tests.inheritance.cache; - -import javax.persistence.*; - -@Entity -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "dtype", discriminatorType = DiscriminatorType.INTEGER) -@DiscriminatorValue(value = "0") -public class CIStreetParent extends CIBaseModel { - - protected String name; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/cache/TestInheritCacheRefLoad.java b/ebean-test/src/test/java/org/tests/inheritance/cache/TestInheritCacheRefLoad.java deleted file mode 100644 index 9b533afd9e..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/cache/TestInheritCacheRefLoad.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.tests.inheritance.cache; - -import io.ebean.DB; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class TestInheritCacheRefLoad { - - @Test - public void findWithRefToInheritStreetBean_expect_correctStreetType() { - - DB.find(CICustomerParent.class).delete(); - DB.find(CIAddress.class).delete(); - DB.find(CIStreet.class).delete(); - - //========================================================================= - // 1 - Create Data (Customer(dtype 1) -> Address(no dtype) -> Street(dtype 1) - //========================================================================= - CIStreet street = new CIStreet(); - street.save(); - CIAddress address = new CIAddress(); - address.setStreet(street); - address.save(); - CICustomer customer = new CICustomer(); - customer.setAddress(address); - customer.save(); - - //========================================================================= - // 2 - Read Data (no Cache Hit) - //========================================================================= - Class streetClass = reloadCustomer(customer, false); //returns Street -> OK - assertEquals("org.tests.inheritance.cache.CIStreet", streetClass.getName()); - streetClass = reloadCustomer(customer, false); //returns Street -> OK - assertEquals("org.tests.inheritance.cache.CIStreet", streetClass.getName()); - - //========================================================================= - // 3 - Read Data (L2-Cache Hit) - //========================================================================= - streetClass = reloadCustomer(customer, true); //returns Street -> OK - assertEquals("org.tests.inheritance.cache.CIStreet", streetClass.getName()); - streetClass = reloadCustomer(customer, true); //returns StreetParent -> NOT OK - assertEquals("org.tests.inheritance.cache.CIStreet", streetClass.getName()); - } - - - public Class reloadCustomer(CICustomer customer, boolean l2Cache) { - - // Load Customer via Query, L2Cache on/off - CICustomer customerReloaded = - DB.find(CICustomer.class) - .where().eq("id", customer.getId()) - .setUseCache(l2Cache) - .findOne(); - - //Access Street by lazy Loading - Class streetClassLazyLoaded = customerReloaded.getAddress().getStreet().getClass(); - - //Show Cache Hits - System.out.println("Class of Street (Cache on: " + l2Cache + "): " + streetClassLazyLoaded + " | Cache Hit: " + DB.getDefault().cacheManager().queryCache(streetClassLazyLoaded).statistics(false).getHitCount()); - return streetClassLazyLoaded; - } - -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/cache/TestInheritanceCache.java b/ebean-test/src/test/java/org/tests/inheritance/cache/TestInheritanceCache.java deleted file mode 100644 index 7cee2dab12..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/cache/TestInheritanceCache.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.tests.inheritance.cache; - - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import org.junit.jupiter.api.Test; -import org.tests.model.basic.cache.CInhOne; -import org.tests.model.basic.cache.CInhRoot; - -import static org.assertj.core.api.Assertions.assertThat; - -public class TestInheritanceCache extends BaseTestCase { - - @Test - public void test() { - - CInhOne one = new CInhOne(); - one.setLicenseNumber("O12"); - one.setDriver("Jimmy"); - one.setNotes("Hello"); - - DB.save(one); - - CInhRoot gotOne = DB.find(CInhRoot.class) - .setId(one.getId()) - .findOne(); - - assertThat(gotOne).isInstanceOf(CInhOne.class); - - CInhRoot gotOneFromCache = DB.find(CInhRoot.class) - .setId(one.getId()) - .findOne(); - - assertThat(gotOneFromCache).isInstanceOf(CInhOne.class); - - CInhRoot refOne = DB.reference(CInhRoot.class, one.getId()); - assertThat(refOne).isInstanceOf(CInhOne.class); - - CInhRoot refOneSub = DB.reference(CInhOne.class, one.getId()); - assertThat(refOneSub).isNotNull(); - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/cache/TestInheritanceRefCache.java b/ebean-test/src/test/java/org/tests/inheritance/cache/TestInheritanceRefCache.java deleted file mode 100644 index 569141191b..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/cache/TestInheritanceRefCache.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.tests.inheritance.cache; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import io.ebean.test.LoggedSql; -import org.junit.jupiter.api.Test; -import org.tests.model.basic.cache.CInhOne; -import org.tests.model.basic.cache.CInhRef; -import org.tests.model.basic.cache.CInhRoot; -import org.tests.model.basic.cache.CInhTwo; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -public class TestInheritanceRefCache extends BaseTestCase { - - @Test - public void test() { - - CInhOne one = new CInhOne(); - one.setLicenseNumber("O12"); - one.setDriver("Jimmy"); - one.setNotes("Hello"); - - DB.save(one); - - CInhRef ref = new CInhRef(); - ref.setRef(one); - - DB.save(ref); - - Integer id = ref.getId(); - - LoggedSql.start(); - CInhRef gotRef = DB.find(CInhRef.class).setId(id).findOne(); - - assertThat(gotRef).isInstanceOf(CInhRef.class); - assertThat(gotRef.getRef()).isInstanceOf(CInhOne.class); - List sql = LoggedSql.stop(); - assertThat(sql).hasSize(1); - assertSql(sql.get(0)).contains("from cinh_ref").contains("left join cinh_root"); - - // fetch again - from cache (but fetch second bean from cache) - LoggedSql.start(); - gotRef = DB.find(CInhRef.class).setId(id).findOne(); - - assertThat(gotRef).isInstanceOf(CInhRef.class); - assertThat(gotRef.getRef()).isInstanceOf(CInhOne.class); - sql = LoggedSql.stop(); - assertThat(sql).hasSize(0); - - - // fetch again - both from cache - LoggedSql.start(); - gotRef = DB.find(CInhRef.class).setId(id).findOne(); - - assertThat(gotRef).isInstanceOf(CInhRef.class); - assertThat(gotRef.getRef()).isInstanceOf(CInhOne.class); - sql = LoggedSql.stop(); - assertThat(sql).hasSize(0); - - } - - @Test - public void testMap() { - - List ids = new ArrayList<>(); - - CInhOne one = new CInhOne(); - one.setLicenseNumber("O19"); - one.setDriver("Foo"); - one.setNotes("Hello"); - DB.save(one); - - ids.add(one.getId()); - - CInhTwo two = new CInhTwo(); - two.setLicenseNumber("T23"); - two.setAction("Test"); - DB.save(two); - - ids.add(two.getId()); - - - LoggedSql.start(); - - DB.find(CInhRoot.class).setUseQueryCache(true).where().idIn(ids).setMapKey("licenseNumber").findMap(); - - List sql = LoggedSql.stop(); - assertThat(sql).hasSize(1); - assertSql(sql.get(0)).contains("from cinh_root"); - - // try some cache finds - DB.find(CInhRoot.class).setUseQueryCache(true).findList(); - DB.find(CInhRoot.class).setUseQueryCache(true).findList(); - DB.find(CInhRoot.class).setUseQueryCache(true).findList(); - - LoggedSql.start(); - - DB.find(CInhRoot.class).setUseQueryCache(true).where().idIn(ids).setMapKey("licenseNumber").findMap(); - - sql = LoggedSql.stop(); - assertThat(sql).hasSize(0); - } - -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/cascadedelete/TestInheritanceDeleteCascade.java b/ebean-test/src/test/java/org/tests/inheritance/cascadedelete/TestInheritanceDeleteCascade.java deleted file mode 100644 index 2ede7296e2..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/cascadedelete/TestInheritanceDeleteCascade.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.tests.inheritance.cascadedelete; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import org.junit.jupiter.api.Test; - -import static java.util.Arrays.asList; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class TestInheritanceDeleteCascade extends BaseTestCase { - - @Test - public void test() { - - RootBean bean1 = new ComplexBean(asList(new ElementBean("element-1"), new ElementBean("element-2"))); - RootBean bean2 = new SimpleBean("simple-1"); - ReferencingBean referencingBean = new ReferencingBean(asList(bean1, bean2)); - - DB.save(referencingBean); - DB.delete(referencingBean); - - assertNull(DB.find(RootBean.class, DB.beanId(bean1))); - assertNull(DB.find(RootBean.class, DB.beanId(bean2))); - } - -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/company/domain/AbstractBar.java b/ebean-test/src/test/java/org/tests/inheritance/company/domain/AbstractBar.java deleted file mode 100644 index 899381d4e9..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/company/domain/AbstractBar.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.tests.inheritance.company.domain; - -import javax.persistence.*; - -/** - * @author Per-Ingemar Andersson, It-huset i Norden AB - */ - -@Entity -@Table(name = "bar") -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "bar_type", discriminatorType = DiscriminatorType.STRING) -//@MappedSuperclass -public abstract class AbstractBar { - - @Id - @GeneratedValue - private int barId; - - @ManyToOne(optional = false, fetch = FetchType.LAZY) - @JoinColumn(name = "foo_id", nullable = false) - private Foo foo; - - @Version - private int version; - - public void setBarId(int barId) { - this.barId = barId; - } - - public int getBarId() { - return barId; - } - - public Foo getFoo() { - return foo; - } - - public void setFoo(Foo foo) { - this.foo = foo; - } - - public int getVersion() { - return version; - } - - public void setVersion(int version) { - this.version = version; - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/company/domain/ConcreteBar.java b/ebean-test/src/test/java/org/tests/inheritance/company/domain/ConcreteBar.java deleted file mode 100644 index b192290cf0..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/company/domain/ConcreteBar.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.tests.inheritance.company.domain; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -/** - * @author Per-Ingemar Andersson, It-huset i Norden AB - */ -@Entity -@DiscriminatorValue("ConcreteBar") -public class ConcreteBar extends AbstractBar { -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/company/domain/Foo.java b/ebean-test/src/test/java/org/tests/inheritance/company/domain/Foo.java deleted file mode 100644 index 5ef6ef7c89..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/company/domain/Foo.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.tests.inheritance.company.domain; - -import javax.persistence.*; - -/** - * @author Per-Ingemar Andersson, It-huset i Norden AB - */ -@Entity -@Table(name = "foo") -public class Foo { - @Id - @GeneratedValue - private int fooId; - - private String importantText; - - @Version - private int version; - - public void setFooId(int fooId) { - this.fooId = fooId; - } - - public int getFooId() { - return fooId; - } - - public String getImportantText() { - return importantText; - } - - public void setImportantText(String importantText) { - this.importantText = importantText; - } - - public int getVersion() { - return version; - } - - public void setVersion(int version) { - this.version = version; - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/company/domain/TestInheritAbstract.java b/ebean-test/src/test/java/org/tests/inheritance/company/domain/TestInheritAbstract.java deleted file mode 100644 index 3d32d3d054..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/company/domain/TestInheritAbstract.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.tests.inheritance.company.domain; - -import io.ebean.DB; -import io.ebean.Database; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class TestInheritAbstract { - - @Test - public void testMe() { - - Database server = DB.getDefault(); - - List list0 = server.find(AbstractBar.class) - .findList(); - - assertNotNull(list0); - - List list1 = server.find(AbstractBar.class) - .fetch("foo", "importantText") - .findList(); - - assertNotNull(list1); - - Foo f = new Foo(); - f.setImportantText("blah"); - - server.save(f); - - ConcreteBar cb = new ConcreteBar(); - cb.setFoo(f); - server.save(cb); - - List list2 = server.find(AbstractBar.class) - .fetch("foo", "importantText") - .findList(); - - assertNotNull(list2); - assertThat(list2).isNotEmpty(); - - for (AbstractBar abstractBar : list2) { - Foo foo = abstractBar.getFoo(); - String importantText = foo.getImportantText(); - assertNotNull(importantText); - } - - - } - -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/model/CalculationResult.java b/ebean-test/src/test/java/org/tests/inheritance/model/CalculationResult.java index 6d315b65a3..60c03355b2 100644 --- a/ebean-test/src/test/java/org/tests/inheritance/model/CalculationResult.java +++ b/ebean-test/src/test/java/org/tests/inheritance/model/CalculationResult.java @@ -12,10 +12,10 @@ public class CalculationResult { private double charge; @ManyToOne(cascade = CascadeType.PERSIST) - private ProductConfiguration productConfiguration; + private Configuration productConfiguration; @ManyToOne(cascade = CascadeType.PERSIST) - private GroupConfiguration groupConfiguration; + private Configuration groupConfiguration; public double getCharge() { return charge; @@ -25,19 +25,19 @@ public void setCharge(double charge) { this.charge = charge; } - public ProductConfiguration getProductConfiguration() { + public Configuration getProductConfiguration() { return productConfiguration; } - public void setProductConfiguration(ProductConfiguration productConfiguration) { + public void setProductConfiguration(Configuration productConfiguration) { this.productConfiguration = productConfiguration; } - public GroupConfiguration getGroupConfiguration() { + public Configuration getGroupConfiguration() { return groupConfiguration; } - public void setGroupConfiguration(GroupConfiguration groupConfiguration) { + public void setGroupConfiguration(Configuration groupConfiguration) { this.groupConfiguration = groupConfiguration; } diff --git a/ebean-test/src/test/java/org/tests/inheritance/model/Configuration.java b/ebean-test/src/test/java/org/tests/inheritance/model/Configuration.java index c58afe6c11..0deec60d62 100644 --- a/ebean-test/src/test/java/org/tests/inheritance/model/Configuration.java +++ b/ebean-test/src/test/java/org/tests/inheritance/model/Configuration.java @@ -4,14 +4,13 @@ import io.ebean.annotation.ChangeLog; import javax.persistence.*; +import java.util.List; @ChangeLog @Entity @Cache(enableQueryCache = true) -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING, columnDefinition = "varchar(21)") public class Configuration extends AbstractBaseClass { - + @Id @Column(name = "id") private Integer id; @@ -20,6 +19,15 @@ public class Configuration extends AbstractBaseClass { @ManyToOne private Configurations configurations; + private String groupName; + + @OneToMany(mappedBy = "groupConfiguration") + private List groupResults; + + private String productName; + + @OneToMany(mappedBy = "productConfiguration") + private List productResults; public Configuration() { super(); @@ -40,4 +48,12 @@ public Configurations getConfigurations() { public void setConfigurations(Configurations configurations) { this.configurations = configurations; } + + public String getProductName() { + return productName; + } + + public String getGroupName() { + return groupName; + } } diff --git a/ebean-test/src/test/java/org/tests/inheritance/model/Configurations.java b/ebean-test/src/test/java/org/tests/inheritance/model/Configurations.java index 7afed20a69..f27fed4857 100644 --- a/ebean-test/src/test/java/org/tests/inheritance/model/Configurations.java +++ b/ebean-test/src/test/java/org/tests/inheritance/model/Configurations.java @@ -15,10 +15,10 @@ public class Configurations { private String name; @OneToMany - private List groupConfigurations; + private List groupConfigurations; @OneToMany - private List productConfigurations; + private List productConfigurations; public Integer getId() { return id; @@ -36,28 +36,28 @@ public void setName(String name) { this.name = name; } - public List getGroupConfigurations() { + public List getGroupConfigurations() { return groupConfigurations; } - public void setGroupConfigurations(List groupConfigurations) { + public void setGroupConfigurations(List groupConfigurations) { this.groupConfigurations = groupConfigurations; } - public void addGroupConfiguration(GroupConfiguration groupConfiguration) { + public void addGroupConfiguration(Configuration groupConfiguration) { groupConfiguration.setConfigurations(this); groupConfigurations.add(groupConfiguration); } - public List getProductConfigurations() { + public List getProductConfigurations() { return productConfigurations; } - public void setProductConfigurations(List productConfigurations) { + public void setProductConfigurations(List productConfigurations) { this.productConfigurations = productConfigurations; } - public void addProductConfiguration(ProductConfiguration productConfiguration) { + public void addProductConfiguration(Configuration productConfiguration) { productConfiguration.setConfigurations(this); productConfigurations.add(productConfiguration); } diff --git a/ebean-test/src/test/java/org/tests/inheritance/model/GroupConfiguration.java b/ebean-test/src/test/java/org/tests/inheritance/model/GroupConfiguration.java deleted file mode 100644 index e1b90aef42..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/model/GroupConfiguration.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.tests.inheritance.model; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; -import javax.persistence.OneToMany; -import java.util.List; - -@Entity -@DiscriminatorValue("2") -public class GroupConfiguration extends Configuration { - private String groupName; - - @OneToMany(mappedBy = "groupConfiguration") - private List results; - - public GroupConfiguration() { - super(); - } - - public GroupConfiguration(String name) { - super(); - this.groupName = name; - } - - public String getGroupName() { - return groupName; - } - - public void setGroupName(String groupName) { - this.groupName = groupName; - } - - public List getResults() { - return results; - } - - public void setResults(List results) { - this.results = results; - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/model/ProductConfiguration.java b/ebean-test/src/test/java/org/tests/inheritance/model/ProductConfiguration.java deleted file mode 100644 index 3ff22d7bbc..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/model/ProductConfiguration.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.tests.inheritance.model; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; -import javax.persistence.OneToMany; -import java.util.List; - -@Entity -@DiscriminatorValue("1") -public class ProductConfiguration extends Configuration { - private String productName; - - @OneToMany(mappedBy = "productConfiguration") - private List results; - - public ProductConfiguration() { - super(); - } - - public String getProductName() { - return productName; - } - - public void setProductName(String productName) { - this.productName = productName; - } - - public List getResults() { - return results; - } - - public void setResults(List results) { - this.results = results; - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/order/OrderedA.java b/ebean-test/src/test/java/org/tests/inheritance/order/OrderedA.java deleted file mode 100644 index 036ceccf88..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/order/OrderedA.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.tests.inheritance.order; - -import javax.persistence.Entity; - -@Entity -public class OrderedA extends OrderedParent { - - String orderedAName; - - public String getOrderedAName() { - return orderedAName; - } - - public void setOrderedAName(final String orderedAName) { - this.orderedAName = orderedAName; - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/order/OrderedB.java b/ebean-test/src/test/java/org/tests/inheritance/order/OrderedB.java deleted file mode 100644 index d21a708e47..0000000000 --- a/ebean-test/src/test/java/org/tests/inheritance/order/OrderedB.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.tests.inheritance.order; - -import javax.persistence.Entity; - -@Entity -public class OrderedB extends OrderedParent { - - String orderedBName; - - public String getOrderedBName() { - return orderedBName; - } - - public void setOrderedBName(final String orderedBName) { - this.orderedBName = orderedBName; - } -} diff --git a/ebean-test/src/test/java/org/tests/inheritance/order/OrderedParent.java b/ebean-test/src/test/java/org/tests/inheritance/order/OrderedParent.java index 43845541c2..a4cab2e0af 100644 --- a/ebean-test/src/test/java/org/tests/inheritance/order/OrderedParent.java +++ b/ebean-test/src/test/java/org/tests/inheritance/order/OrderedParent.java @@ -5,14 +5,33 @@ import javax.persistence.Inheritance; @Entity -@Inheritance -public abstract class OrderedParent { +public final class OrderedParent { @Id Integer id; String commonName; + String orderedAName; + + String orderedBName; + + public String getOrderedBName() { + return orderedBName; + } + + public void setOrderedBName(final String orderedBName) { + this.orderedBName = orderedBName; + } + + public String getOrderedAName() { + return orderedAName; + } + + public void setOrderedAName(final String orderedAName) { + this.orderedAName = orderedAName; + } + public Integer getId() { return id; } @@ -28,4 +47,8 @@ public String getCommonName() { public void setCommonName(final String commonName) { this.commonName = commonName; } + + public void setOrderedParentName(String commonName) { + this.commonName = commonName; + } } diff --git a/ebean-test/src/test/java/org/tests/lazyforeignkeys/MainEntityRelation.java b/ebean-test/src/test/java/org/tests/lazyforeignkeys/MainEntityRelation.java index 8f36be0cbc..4184d0d392 100644 --- a/ebean-test/src/test/java/org/tests/lazyforeignkeys/MainEntityRelation.java +++ b/ebean-test/src/test/java/org/tests/lazyforeignkeys/MainEntityRelation.java @@ -1,7 +1,7 @@ package org.tests.lazyforeignkeys; import io.ebean.annotation.DbForeignKey; -import org.tests.model.basic.Cat; +import org.tests.model.basic.Animal; import javax.persistence.*; import java.util.UUID; @@ -27,7 +27,7 @@ public class MainEntityRelation { @ManyToOne @JoinColumn(name = "cat_id") @DbForeignKey(noConstraint = true) - private Cat cat; + private Animal cat; private String attr1; @@ -47,11 +47,11 @@ public void setEntity2(MainEntity entity2) { this.entity2 = entity2; } - public Cat getCat() { + public Animal getCat() { return cat; } - public void setCat(Cat cat) { + public void setCat(Animal cat) { this.cat = cat; } diff --git a/ebean-test/src/test/java/org/tests/lazyforeignkeys/TestLazyForeignKeys.java b/ebean-test/src/test/java/org/tests/lazyforeignkeys/TestLazyForeignKeys.java index f88f148297..9a4688741d 100644 --- a/ebean-test/src/test/java/org/tests/lazyforeignkeys/TestLazyForeignKeys.java +++ b/ebean-test/src/test/java/org/tests/lazyforeignkeys/TestLazyForeignKeys.java @@ -8,7 +8,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.tests.model.basic.Cat; +import org.tests.model.basic.Animal; import java.util.List; @@ -57,7 +57,7 @@ public void testFindOne() throws Exception { List sql = LoggedSql.stop(); assertThat(sql).hasSize(3); - assertSql(sql.get(0)).contains("select t0.id, t0.attr1, t0.id1, t0.id2, t1.species, t0.cat_id from main_entity_relation t0 left join animal t1 on t1.id = t0.cat_id"); + assertSql(sql.get(0)).contains("select t0.id, t0.attr1, t0.id1, t0.id2, t0.cat_id from main_entity_relation t0"); if (isSqlServer() || isOracle()) { assertSql(sql.get(1)).contains("select t0.id, t0.attr1, t0.attr2, CASE WHEN t0.id is null THEN 1 ELSE 0 END from main_entity t0"); } else { @@ -91,7 +91,7 @@ public void testFindListWithSelect() { @Test public void testGetWithDbForeignKey() { MainEntityRelation relation = DB.find(MainEntityRelation.class).findOne(); - Cat cat = new Cat(); + Animal cat = new Animal("CAT"); cat.setId(123L); relation.setCat(cat); DB.save(relation); diff --git a/ebean-test/src/test/java/org/tests/model/basic/Animal.java b/ebean-test/src/test/java/org/tests/model/basic/Animal.java index 069b1e4cfa..cdc5421ed1 100644 --- a/ebean-test/src/test/java/org/tests/model/basic/Animal.java +++ b/ebean-test/src/test/java/org/tests/model/basic/Animal.java @@ -3,9 +3,8 @@ import javax.persistence.*; @Entity -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "species") -public abstract class Animal { +// DiscriminatorColumn(name = "species") +public final class Animal { @Id Long id; @@ -19,6 +18,10 @@ public abstract class Animal { @ManyToOne AnimalShelter shelter; + public Animal(String species) { + this.species = species; + } + public Long getId() { return id; } diff --git a/ebean-test/src/test/java/org/tests/model/basic/Attribute.java b/ebean-test/src/test/java/org/tests/model/basic/Attribute.java index d660c93f09..959a489702 100644 --- a/ebean-test/src/test/java/org/tests/model/basic/Attribute.java +++ b/ebean-test/src/test/java/org/tests/model/basic/Attribute.java @@ -1,11 +1,9 @@ package org.tests.model.basic; import javax.persistence.*; +import java.util.Set; @Entity -@Inheritance() -@DiscriminatorColumn(name = "option_type", discriminatorType = DiscriminatorType.INTEGER) -@DiscriminatorValue("0") public class Attribute extends BasicDomain { private static final long serialVersionUID = 1L; @@ -13,6 +11,12 @@ public class Attribute extends BasicDomain { @ManyToOne private AttributeHolder attributeHolder; + @ManyToMany(mappedBy = "listAttributes", cascade = {CascadeType.PERSIST}) + private Set values;// = new HashSet(); + // Do not define this as a HashSet so that it is left up to Ebean + // to define it as a BeanSet ... and hence aware of M2M modify changes + // Put this back to HashSet and Duplicate Key Exception will return + public AttributeHolder getAttributeHolder() { return attributeHolder; } @@ -21,4 +25,18 @@ public void setAttributeHolder(AttributeHolder attributeHolder) { this.attributeHolder = attributeHolder; } + + public Set getValues() { + return values; + } + + public void setValues(Set values) { + this.values = values; + } + + public void add(ListAttributeValue value) { + getValues().add(value); + value.getListAttributes().add(this); + } + } diff --git a/ebean-test/src/test/java/org/tests/model/basic/BigDog.java b/ebean-test/src/test/java/org/tests/model/basic/BigDog.java deleted file mode 100644 index ddd6e54599..0000000000 --- a/ebean-test/src/test/java/org/tests/model/basic/BigDog.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.tests.model.basic; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@Entity -@DiscriminatorValue("BDG") -public class BigDog extends Dog { - - String dogSize; - - public String getDogSize() { - return dogSize; - } - - public void setDogSize(String dogSize) { - this.dogSize = dogSize; - } -} diff --git a/ebean-test/src/test/java/org/tests/model/basic/Car.java b/ebean-test/src/test/java/org/tests/model/basic/Car.java deleted file mode 100644 index 268920a34d..0000000000 --- a/ebean-test/src/test/java/org/tests/model/basic/Car.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.tests.model.basic; - -import io.ebean.annotation.DbEnumValue; - -import javax.persistence.*; -import java.util.HashSet; -import java.util.Set; - -@Entity -@Inheritance -@DiscriminatorValue("C") -public class Car extends Vehicle { - private static final long serialVersionUID = -65427345082456523L; - - public enum Size { - SMALL("S"), - LARGE("L"); - - String value; - - Size(String value) { - this.value = value; - } - - @DbEnumValue - public String value() { - return value; - } - } - - @Column(name = "siz") - private Size size; - - private String driver; - - @ManyToOne - private TruckRef carRef; - - @OneToMany(mappedBy = "car") - @OrderBy("fuse.locationCode") - private Set accessories = new HashSet<>(); - - private String notes; - - public String getDriver() { - return driver; - } - - public void setDriver(String driver) { - this.driver = driver; - } - - public String getNotes() { - return notes; - } - - public void setNotes(String notes) { - this.notes = notes; - } - - public TruckRef getCarRef() { - return carRef; - } - - public void setCarRef(TruckRef carRef) { - this.carRef = carRef; - } - - public Set getAccessories() { - return accessories; - } - - public void setAccessories(Set accessories) { - this.accessories = accessories; - } - - public Size getSize() { - return size; - } - - public void setSize(Size size) { - this.size = size; - } -} diff --git a/ebean-test/src/test/java/org/tests/model/basic/CarAccessory.java b/ebean-test/src/test/java/org/tests/model/basic/CarAccessory.java index 37ee5720e6..ebb58d0e36 100644 --- a/ebean-test/src/test/java/org/tests/model/basic/CarAccessory.java +++ b/ebean-test/src/test/java/org/tests/model/basic/CarAccessory.java @@ -14,9 +14,9 @@ public class CarAccessory extends BasicDomain { private CarFuse fuse; @ManyToOne - private Car car; + private Vehicle car; - public CarAccessory(Car car, CarFuse fuse) { + public CarAccessory(Vehicle car, CarFuse fuse) { this.car = car; this.fuse = fuse; } @@ -29,11 +29,11 @@ public void setName(String name) { this.name = name; } - public Car getCar() { + public Vehicle getCar() { return car; } - public void setCar(Car car) { + public void setCar(Vehicle car) { this.car = car; } diff --git a/ebean-test/src/test/java/org/tests/model/basic/Cat.java b/ebean-test/src/test/java/org/tests/model/basic/Cat.java deleted file mode 100644 index d3df201b61..0000000000 --- a/ebean-test/src/test/java/org/tests/model/basic/Cat.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.tests.model.basic; - -import io.ebean.annotation.Formula; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@Entity -@DiscriminatorValue("CAT") -public class Cat extends Animal { - - String name; - - @Formula(select = "${ta}.species") - String catFormula; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getCatFormula() { - return catFormula; - } - - public void setCatFormula(String catFormula) { - this.catFormula = catFormula; - } -} diff --git a/ebean-test/src/test/java/org/tests/model/basic/Dog.java b/ebean-test/src/test/java/org/tests/model/basic/Dog.java deleted file mode 100644 index 7b2fad5466..0000000000 --- a/ebean-test/src/test/java/org/tests/model/basic/Dog.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.tests.model.basic; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; -import java.sql.Date; - -@Entity -@DiscriminatorValue("DOG") -public class Dog extends Animal { - - String registrationNumber; - - Date dateOfBirth; - - public String getRegistrationNumber() { - return registrationNumber; - } - - public void setRegistrationNumber(String registrationNumber) { - this.registrationNumber = registrationNumber; - } - - public Date getDateOfBirth() { - return dateOfBirth; - } - - public void setDateOfBirth(Date dateOfBirth) { - this.dateOfBirth = dateOfBirth; - } - -} diff --git a/ebean-test/src/test/java/org/tests/model/basic/ListAttribute.java b/ebean-test/src/test/java/org/tests/model/basic/ListAttribute.java deleted file mode 100644 index 0633e254fe..0000000000 --- a/ebean-test/src/test/java/org/tests/model/basic/ListAttribute.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.tests.model.basic; - -import javax.persistence.CascadeType; -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; -import javax.persistence.ManyToMany; -import java.util.Set; - -@Entity -@DiscriminatorValue("1") -public class ListAttribute extends Attribute { - - private static final long serialVersionUID = 1L; - - @ManyToMany(mappedBy = "listAttributes", cascade = {CascadeType.PERSIST}) - private Set values;// = new HashSet(); - // Do not define this as a HashSet so that it is left up to Ebean - // to define it as a BeanSet ... and hence aware of M2M modify changes - // Put this back to HashSet and Duplicate Key Exception will return - - public Set getValues() { - return values; - } - - public void setValues(Set values) { - this.values = values; - } - - public void add(ListAttributeValue value) { - getValues().add(value); - value.getListAttributes().add(this); - } -} diff --git a/ebean-test/src/test/java/org/tests/model/basic/ListAttributeValue.java b/ebean-test/src/test/java/org/tests/model/basic/ListAttributeValue.java index 8c88c06e98..161026a100 100644 --- a/ebean-test/src/test/java/org/tests/model/basic/ListAttributeValue.java +++ b/ebean-test/src/test/java/org/tests/model/basic/ListAttributeValue.java @@ -13,13 +13,13 @@ public class ListAttributeValue extends BasicDomain { private String name; @ManyToMany - private Set listAttributes; + private Set listAttributes; - public Set getListAttributes() { + public Set getListAttributes() { return listAttributes; } - public void setListAttribute(Set listAttributes) { + public void setListAttribute(Set listAttributes) { this.listAttributes = listAttributes; } diff --git a/ebean-test/src/test/java/org/tests/model/basic/OCachedInhChildA.java b/ebean-test/src/test/java/org/tests/model/basic/OCachedInhChildA.java deleted file mode 100644 index 8ec1833796..0000000000 --- a/ebean-test/src/test/java/org/tests/model/basic/OCachedInhChildA.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.tests.model.basic; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - - -/** - * Child bean A - */ -@Entity -@DiscriminatorValue("childA") -public class OCachedInhChildA extends OCachedInhRoot { - - String childAData; - - /** - * @return the childAData - */ - public String getChildAData() { - return childAData; - } - - /** - * @param childAData - * the childAData to set - */ - public void setChildAData(String childAData) { - this.childAData = childAData; - } -} diff --git a/ebean-test/src/test/java/org/tests/model/basic/OCachedInhChildB.java b/ebean-test/src/test/java/org/tests/model/basic/OCachedInhChildB.java deleted file mode 100644 index 1ef25a2cae..0000000000 --- a/ebean-test/src/test/java/org/tests/model/basic/OCachedInhChildB.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.tests.model.basic; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - - -/** - * Child bean B - */ -@Entity -@DiscriminatorValue("childB") -public class OCachedInhChildB extends OCachedInhRoot { - String childBData; - - /** - * @return the childBData - */ - public String getChildBData() { - return childBData; - } - - /** - * @param childBData - * the childBData to set - */ - public void setChildBData(String childBData) { - this.childBData = childBData; - } -} diff --git a/ebean-test/src/test/java/org/tests/model/basic/OCachedInhRoot.java b/ebean-test/src/test/java/org/tests/model/basic/OCachedInhRoot.java index ef6acaec8d..46e1def6f1 100644 --- a/ebean-test/src/test/java/org/tests/model/basic/OCachedInhRoot.java +++ b/ebean-test/src/test/java/org/tests/model/basic/OCachedInhRoot.java @@ -14,15 +14,17 @@ */ @Entity @Table(name = "o_cached_inherit") -@Inheritance @Cache -public abstract class OCachedInhRoot { +public final class OCachedInhRoot { @Id Long id; String name; + String childAData; + String childBData; + public Long getId() { return id; } @@ -40,5 +42,11 @@ public void setName(String name) { } + public void setChildAData(String childData) { + this.childAData = childData; + } + public String getChildAData() { + return childAData; + } } diff --git a/ebean-test/src/test/java/org/tests/model/basic/TIntChild.java b/ebean-test/src/test/java/org/tests/model/basic/TIntChild.java deleted file mode 100644 index 9f084dc8dc..0000000000 --- a/ebean-test/src/test/java/org/tests/model/basic/TIntChild.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.tests.model.basic; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; -import javax.persistence.Inheritance; - -@Entity -@Inheritance -@DiscriminatorValue("2") -public class TIntChild extends TIntRoot { - - private static final long serialVersionUID = 1L; - - String childProperty; - - public String getChildProperty() { - return childProperty; - } - - public void setChildProperty(String childProperty) { - this.childProperty = childProperty; - } - -} diff --git a/ebean-test/src/test/java/org/tests/model/basic/TIntRoot.java b/ebean-test/src/test/java/org/tests/model/basic/TIntRoot.java deleted file mode 100644 index e71c039982..0000000000 --- a/ebean-test/src/test/java/org/tests/model/basic/TIntRoot.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.tests.model.basic; - -import javax.persistence.*; -import java.io.Serializable; - -@Entity -@Inheritance -@DiscriminatorColumn(name = "my_type", length = 3, discriminatorType = DiscriminatorType.INTEGER) -@DiscriminatorValue("1") -public class TIntRoot implements Serializable { - private static final long serialVersionUID = -7057502590435806504L; - - @Id - Integer id; - - String name; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - -} diff --git a/ebean-test/src/test/java/org/tests/model/basic/Truck.java b/ebean-test/src/test/java/org/tests/model/basic/Truck.java deleted file mode 100644 index c32d70777b..0000000000 --- a/ebean-test/src/test/java/org/tests/model/basic/Truck.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.tests.model.basic; - -import io.ebean.annotation.DbEnumValue; - -import javax.persistence.*; - -@Entity -@Inheritance -@DiscriminatorValue("T") -public class Truck extends Vehicle { - private static final long serialVersionUID = 9195535931523211134L; - - public enum Size { - SMALL("S"), - MEDIUM("M"), - LARGE("L"), - HUGE("H"); - - String value; - - Size(String value) { - this.value = value; - } - - @DbEnumValue(length = 3) - public String value() { - return value; - } - } - - @Column(name = "siz") - private Size size; - - @ManyToOne - TruckRef truckRef; - - private Double capacity; - - public Double getCapacity() { - return capacity; - } - - public void setCapacity(Double capacity) { - this.capacity = capacity; - } - - public TruckRef getTruckRef() { - return truckRef; - } - - public void setTruckRef(TruckRef truckRef) { - this.truckRef = truckRef; - } - - public Size getSize() { - return size; - } - - public void setSize(Size size) { - this.size = size; - } -} diff --git a/ebean-test/src/test/java/org/tests/model/basic/Vehicle.java b/ebean-test/src/test/java/org/tests/model/basic/Vehicle.java index cab8c4dde7..1bbb6ee674 100644 --- a/ebean-test/src/test/java/org/tests/model/basic/Vehicle.java +++ b/ebean-test/src/test/java/org/tests/model/basic/Vehicle.java @@ -1,15 +1,11 @@ package org.tests.model.basic; -import javax.persistence.DiscriminatorColumn; import javax.persistence.Entity; -import javax.persistence.Inheritance; import javax.persistence.ManyToOne; import java.util.Date; @Entity -@Inheritance -@DiscriminatorColumn(length = 3) -public abstract class Vehicle extends BasicDomain { +public final class Vehicle extends BasicDomain { private static final long serialVersionUID = -3060920549470002030L; diff --git a/ebean-test/src/test/java/org/tests/model/basic/cache/CInhOne.java b/ebean-test/src/test/java/org/tests/model/basic/cache/CInhOne.java deleted file mode 100644 index 1bb0a459b0..0000000000 --- a/ebean-test/src/test/java/org/tests/model/basic/cache/CInhOne.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.tests.model.basic.cache; - -import io.ebean.annotation.Cache; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; -import javax.persistence.Inheritance; - -@Cache -@Entity -@Inheritance -@DiscriminatorValue("O") -public class CInhOne extends CInhRoot { - private static final long serialVersionUID = -3933815364935720317L; - - private String driver; - - private String notes; - - public String getDriver() { - return driver; - } - - public void setDriver(String driver) { - this.driver = driver; - } - - public String getNotes() { - return notes; - } - - public void setNotes(String notes) { - this.notes = notes; - } -} diff --git a/ebean-test/src/test/java/org/tests/model/basic/cache/CInhRef.java b/ebean-test/src/test/java/org/tests/model/basic/cache/CInhRef.java deleted file mode 100644 index fcfb8479f3..0000000000 --- a/ebean-test/src/test/java/org/tests/model/basic/cache/CInhRef.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.tests.model.basic.cache; - -import io.ebean.annotation.Cache; -import org.tests.model.basic.BasicDomain; - -import javax.persistence.Entity; -import javax.persistence.ManyToOne; - -@Entity -@Cache(enableQueryCache = true) -public class CInhRef extends BasicDomain { - private static final long serialVersionUID = -4673953370819311120L; - - @ManyToOne(cascade = {}) - private CInhRoot ref; - - public CInhRoot getRef() { - return ref; - } - - public void setRef(CInhRoot ref) { - this.ref = ref; - } -} diff --git a/ebean-test/src/test/java/org/tests/model/basic/cache/CInhRoot.java b/ebean-test/src/test/java/org/tests/model/basic/cache/CInhRoot.java deleted file mode 100644 index 548ee094cc..0000000000 --- a/ebean-test/src/test/java/org/tests/model/basic/cache/CInhRoot.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.tests.model.basic.cache; - -import io.ebean.annotation.Cache; -import org.tests.model.basic.BasicDomain; - -import javax.persistence.DiscriminatorColumn; -import javax.persistence.Entity; -import javax.persistence.Inheritance; - -@Cache(enableQueryCache = true) -@Entity -@Inheritance -@DiscriminatorColumn(length = 3) -public abstract class CInhRoot extends BasicDomain { - private static final long serialVersionUID = -4673953370819311120L; - - private String licenseNumber; - - public String getLicenseNumber() { - return licenseNumber; - } - - public void setLicenseNumber(String licenseNumber) { - this.licenseNumber = licenseNumber; - } -} diff --git a/ebean-test/src/test/java/org/tests/model/basic/cache/CInhTwo.java b/ebean-test/src/test/java/org/tests/model/basic/cache/CInhTwo.java deleted file mode 100644 index 53d3685e82..0000000000 --- a/ebean-test/src/test/java/org/tests/model/basic/cache/CInhTwo.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.tests.model.basic.cache; - -import io.ebean.annotation.Cache; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; -import javax.persistence.Inheritance; - -@Cache -@Entity -@Inheritance -@DiscriminatorValue("T") -public class CInhTwo extends CInhRoot { - private static final long serialVersionUID = -8528396890675473212L; - - private String action; - - public String getAction() { - return action; - } - - public void setAction(String action) { - this.action = action; - } -} diff --git a/ebean-test/src/test/java/org/tests/model/basic/xtra/EdChild.java b/ebean-test/src/test/java/org/tests/model/basic/xtra/EdChild.java index c405b9ed79..d2cec5cd96 100644 --- a/ebean-test/src/test/java/org/tests/model/basic/xtra/EdChild.java +++ b/ebean-test/src/test/java/org/tests/model/basic/xtra/EdChild.java @@ -14,7 +14,7 @@ public class EdChild { @ManyToOne @JoinColumn(name = "parent_id", nullable = false) - EdParent parent; + EdExtendedParent parent; public int getId() { return id; @@ -36,7 +36,7 @@ public EdParent getParent() { return parent; } - public void setParent(EdParent parent) { + public void setParent(EdExtendedParent parent) { this.parent = parent; } } diff --git a/ebean-test/src/test/java/org/tests/model/basic/xtra/EdExtendedParent.java b/ebean-test/src/test/java/org/tests/model/basic/xtra/EdExtendedParent.java index bc398b70a4..c7a33710f9 100644 --- a/ebean-test/src/test/java/org/tests/model/basic/xtra/EdExtendedParent.java +++ b/ebean-test/src/test/java/org/tests/model/basic/xtra/EdExtendedParent.java @@ -1,11 +1,11 @@ package org.tests.model.basic.xtra; -import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; +import javax.persistence.Table; @Entity -@DiscriminatorValue("EXTENDED") +@Table(name = "td_parent") public class EdExtendedParent extends EdParent { private String extendedName; diff --git a/ebean-test/src/test/java/org/tests/model/basic/xtra/EdParent.java b/ebean-test/src/test/java/org/tests/model/basic/xtra/EdParent.java index 1f401072c3..8f8e480658 100644 --- a/ebean-test/src/test/java/org/tests/model/basic/xtra/EdParent.java +++ b/ebean-test/src/test/java/org/tests/model/basic/xtra/EdParent.java @@ -4,16 +4,15 @@ import javax.persistence.*; import java.util.List; -@Entity -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, name = "parent_type") -@DiscriminatorValue("BASIC") -@Table(name = "td_parent") -public class EdParent { +@MappedSuperclass +public abstract class EdParent { + @Id @Column(name = "parent_id") private int id; + String parentType = "EXTENDED"; + @Column(name = "parent_name") private String name; diff --git a/ebean-test/src/test/java/org/tests/model/basic/xtra/TestDeleteUnloadedChildren.java b/ebean-test/src/test/java/org/tests/model/basic/xtra/TestDeleteUnloadedChildren.java index 1734be5633..09c7de91ec 100644 --- a/ebean-test/src/test/java/org/tests/model/basic/xtra/TestDeleteUnloadedChildren.java +++ b/ebean-test/src/test/java/org/tests/model/basic/xtra/TestDeleteUnloadedChildren.java @@ -24,7 +24,7 @@ private void init() { delete = DB.sqlUpdate(sql); delete.execute(); - EdParent parent = new EdParent(); + EdExtendedParent parent = new EdExtendedParent(); parent.setName("MyComputer"); EdChild child = new EdChild(); @@ -58,7 +58,7 @@ public void testCascadeDelete2() { init(); try (Transaction txn = DB.beginTransaction()) { - EdParent parent = DB.find(EdParent.class).where().eq("name", "MyComputer").findOne(); + EdParent parent = DB.find(EdExtendedParent.class).where().eq("name", "MyComputer").findOne(); // // Works only if the following statement is included // int x = parent.getChildren().size(); DB.delete(parent); diff --git a/ebean-test/src/test/java/org/tests/model/basic/xtra/TestInsertBatchThenFlushThenUpdate.java b/ebean-test/src/test/java/org/tests/model/basic/xtra/TestInsertBatchThenFlushThenUpdate.java index 23a8020cce..bb8e54c786 100644 --- a/ebean-test/src/test/java/org/tests/model/basic/xtra/TestInsertBatchThenFlushThenUpdate.java +++ b/ebean-test/src/test/java/org/tests/model/basic/xtra/TestInsertBatchThenFlushThenUpdate.java @@ -23,7 +23,7 @@ public void test() { try (Transaction txn = DB.beginTransaction()) { txn.setBatchMode(true); - EdParent parent = new EdParent(); + EdExtendedParent parent = new EdExtendedParent(); parent.setName("MyComputer"); EdChild child = new EdChild(); @@ -49,7 +49,7 @@ public void test() { // nothing flushed yet assertThat(LoggedSql.start()).isEmpty(); - DB.commitTransaction(); + txn.commit(); // insert statements for EdExtendedParent List loggedSql2 = LoggedSql.start(); diff --git a/ebean-test/src/test/java/org/tests/model/basic/xtra/TestInsertBatchThenUpdate.java b/ebean-test/src/test/java/org/tests/model/basic/xtra/TestInsertBatchThenUpdate.java index f757beedfa..08a9028b5b 100644 --- a/ebean-test/src/test/java/org/tests/model/basic/xtra/TestInsertBatchThenUpdate.java +++ b/ebean-test/src/test/java/org/tests/model/basic/xtra/TestInsertBatchThenUpdate.java @@ -25,7 +25,7 @@ public void test() { LoggedSql.start(); - EdParent parent = new EdParent(); + EdExtendedParent parent = new EdExtendedParent(); parent.setName("MyComputer"); EdChild child = new EdChild(); @@ -44,7 +44,7 @@ public void test() { parent.setName("MyDesk"); DB.save(parent); - DB.commitTransaction(); + txn.commit(); // insert statements for EdExtendedParent List loggedSql = LoggedSql.stop(); @@ -66,7 +66,7 @@ public void test_noFlushOn_getterOfNonGeneratedProperty() { LoggedSql.start(); - EdParent parent = new EdParent(); + EdExtendedParent parent = new EdExtendedParent(); parent.setName("MyComputer"); EdChild child = new EdChild(); @@ -87,7 +87,7 @@ public void test_noFlushOn_getterOfNonGeneratedProperty() { DB.save(parent); // flush - DB.commitTransaction(); + txn.commit(); // insert statements for EdExtendedParent List loggedSql = LoggedSql.stop(); diff --git a/ebean-test/src/test/java/org/tests/model/basic/xtra/TestInsertBatchWithDifferentRootTypes.java b/ebean-test/src/test/java/org/tests/model/basic/xtra/TestInsertBatchWithDifferentRootTypes.java index 3b7a18da91..87a6e9d3cb 100644 --- a/ebean-test/src/test/java/org/tests/model/basic/xtra/TestInsertBatchWithDifferentRootTypes.java +++ b/ebean-test/src/test/java/org/tests/model/basic/xtra/TestInsertBatchWithDifferentRootTypes.java @@ -24,7 +24,7 @@ public void testDifferRootTypes() { try (Transaction txn = DB.beginTransaction()) { txn.setBatchMode(true); - EdParent parent = new EdParent(); + EdExtendedParent parent = new EdExtendedParent(); parent.setName("MyComputer"); EdChild child = new EdChild(); @@ -57,13 +57,13 @@ public void testDifferRootTypes() { // insert statements for EdParent List loggedSql1 = LoggedSql.start(); - DB.commitTransaction(); + txn.commit(); assertEquals(0, loggedSql1.size()); // insert statements for EdExtendedParent List loggedSql2 = LoggedSql.start(); - assertEquals(7, loggedSql2.size()); + assertEquals(6, loggedSql2.size()); } } diff --git a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TCar.java b/ebean-test/src/test/java/org/tests/model/carwheeltruck/TCar.java deleted file mode 100644 index 3479c3a65e..0000000000 --- a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TCar.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.tests.model.carwheeltruck; - -import io.ebean.annotation.SoftDelete; - -import javax.persistence.*; -import javax.validation.constraints.Size; -import java.util.List; - -@Entity -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "type") -@DiscriminatorValue("car") -public class TCar { - - @Id - @Size(max=32) - String plateNo; - - @SoftDelete - boolean deleted; - - @OneToMany(cascade = CascadeType.ALL) - List wheels; - - public String getPlateNo() { - return plateNo; - } - - public void setPlateNo(String plateNo) { - this.plateNo = plateNo; - } - - public List getWheels() { - return wheels; - } - - public void setWheels(List wheels) { - this.wheels = wheels; - } - -} diff --git a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TTruck.java b/ebean-test/src/test/java/org/tests/model/carwheeltruck/TTruck.java deleted file mode 100644 index 746a2233be..0000000000 --- a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TTruck.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.tests.model.carwheeltruck; - -import javax.persistence.*; - -@Entity -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "type") -@DiscriminatorValue("truck") -public class TTruck extends TCar { - - @Column(name = "truckload") - Long load; - - public Long getLoad() { - return load; - } - - public void setLoad(Long load) { - this.load = load; - } - -} diff --git a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TTruckHolder.java b/ebean-test/src/test/java/org/tests/model/carwheeltruck/TTruckHolder.java deleted file mode 100644 index d9f917421d..0000000000 --- a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TTruckHolder.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.tests.model.carwheeltruck; - -import org.tests.model.basic.EBasic; - -import javax.persistence.*; -import java.util.List; - -import static javax.persistence.CascadeType.ALL; - -@Entity -public class TTruckHolder { - - @Id - private long id; - - @Version - private long version; - - private final String name; - - /** - * Inheritance but at BOTTOM layer (so no discriminator needed). - */ - @ManyToOne(optional = false) - private TTruck truck; - - @ManyToOne - private EBasic basic; - - @OneToMany(cascade = ALL, mappedBy = "owner") - private List items; - - public TTruckHolder(String name, TTruck truck) { - this.name = name; - this.truck = truck; - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public long getVersion() { - return version; - } - - public void setVersion(long version) { - this.version = version; - } - - public String getName() { - return name; - } - - public TTruck getTruck() { - return truck; - } - - public void setTruck(TTruck truck) { - this.truck = truck; - } - - public EBasic getBasic() { - return basic; - } - - public void setBasic(EBasic basic) { - this.basic = basic; - } - - public List getItems() { - return items; - } - - public void setItems(List items) { - this.items = items; - } -} diff --git a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TTruckHolderItem.java b/ebean-test/src/test/java/org/tests/model/carwheeltruck/TTruckHolderItem.java deleted file mode 100644 index 1498b263a7..0000000000 --- a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TTruckHolderItem.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.tests.model.carwheeltruck; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.ManyToOne; -import java.util.UUID; - -@Entity -public class TTruckHolderItem { - - @Id - private Long id; - - private final UUID someUid; - - private final String foo; - - @ManyToOne(optional = false) - private TTruckHolder owner; - - public TTruckHolderItem(String foo) { - this.someUid = UUID.randomUUID(); - this.foo = foo; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public UUID getSomeUid() { - return someUid; - } - - public String getFoo() { - return foo; - } - - public TTruckHolder getOwner() { - return owner; - } - - public void setOwner(TTruckHolder owner) { - this.owner = owner; - } -} diff --git a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TWheel.java b/ebean-test/src/test/java/org/tests/model/carwheeltruck/TWheel.java deleted file mode 100644 index 03a6f38dac..0000000000 --- a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TWheel.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.tests.model.carwheeltruck; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.ManyToOne; - -@Entity -public class TWheel { - - @Id - Long id; - - @ManyToOne(optional = false) - TCar owner; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public TCar getOwner() { - return owner; - } - - public void setOwner(TCar owner) { - this.owner = owner; - } - -} diff --git a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TestInheritSoftDeleteJoin.java b/ebean-test/src/test/java/org/tests/model/carwheeltruck/TestInheritSoftDeleteJoin.java deleted file mode 100644 index faec8244eb..0000000000 --- a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TestInheritSoftDeleteJoin.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.tests.model.carwheeltruck; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import io.ebean.test.LoggedSql; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -public class TestInheritSoftDeleteJoin extends BaseTestCase { - - @Test - public void expect_space() { - - TTruck truck = new TTruck(); - truck.setPlateNo("MT998"); - truck.setLoad(43L); - - DB.save(truck); - - TTruckHolder holder = new TTruckHolder("MTH", truck); - DB.save(holder); - - LoggedSql.start(); - final TTruckHolder found = DB.find(TTruckHolder.class) - .fetch("truck") - .where().idEq(holder.getId()) - .findOne(); - - final List sql = LoggedSql.stop(); - assertThat(sql).hasSize(1); - assertThat(sql.get(0)).contains(" and t1.type = 'truck' and t1.deleted = "); - assertThat(found).isNotNull(); - } -} diff --git a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TestMTOInheritNoDiscriminator.java b/ebean-test/src/test/java/org/tests/model/carwheeltruck/TestMTOInheritNoDiscriminator.java deleted file mode 100644 index 3032ff45f7..0000000000 --- a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TestMTOInheritNoDiscriminator.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.tests.model.carwheeltruck; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import io.ebean.test.LoggedSql; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -class TestMTOInheritNoDiscriminator extends BaseTestCase { - - @Test - void test() { - - final TTruckHolder holder = setup(); - - LoggedSql.start(); - - final TTruckHolder found = DB.find(TTruckHolder.class) - .fetch("items") - .where().idEq(holder.getId()) - .findOne(); - - assertThat(found).isNotNull(); - assertThat(found.getItems()).hasSize(2); - assertThat(found.getItems()).extracting(TTruckHolderItem::getFoo).contains("a","b"); - - final List sql = LoggedSql.stop(); - - assertThat(sql).hasSize(1); - if (isH2() || isPostgresCompatible()) { - assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.version, t2.type, t0.truck_plate_no, t0.basic_id, t1.id, t1.some_uid, t1.foo, t1.owner_id from ttruck_holder t0 left join ttruck_holder_item t1 on t1.owner_id = t0.id join tcar t2 on t2.plate_no = t0.truck_plate_no where t0.id = ? order by t0.id"); - } - } - - private TTruckHolder setup() { - TTruck truck = new TTruck(); - truck.setPlateNo("J78"); - truck.setLoad(43L); - - DB.save(truck); - - TTruckHolder holder = new TTruckHolder("h1", truck); - holder.getItems().add(new TTruckHolderItem("a")); - holder.getItems().add(new TTruckHolderItem("b")); - - DB.save(holder); - - return holder; - } -} diff --git a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TestTruckCarWheelInhertiance.java b/ebean-test/src/test/java/org/tests/model/carwheeltruck/TestTruckCarWheelInhertiance.java deleted file mode 100644 index 9803ed934d..0000000000 --- a/ebean-test/src/test/java/org/tests/model/carwheeltruck/TestTruckCarWheelInhertiance.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.tests.model.carwheeltruck; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import org.junit.jupiter.api.Test; - -import java.util.Random; - -public class TestTruckCarWheelInhertiance extends BaseTestCase { - - @Test - public void test() { - - TTruck truck = new TTruck(); - truck.setPlateNo("foo-" + new Random().nextInt()); - - TWheel wheel = new TWheel(); - wheel.setOwner(truck); - - DB.save(truck); - - // This save() works ok... - - // But if then is added one more wheel - wheel = new TWheel(); - wheel.setOwner(truck); - - // And save() is called again - DB.save(truck); - - // Then an exception is raised: - } - -} diff --git a/ebean-test/src/test/java/org/tests/model/inheritmany/IMRelated.java b/ebean-test/src/test/java/org/tests/model/inheritmany/IMRelated.java deleted file mode 100644 index e9734b902b..0000000000 --- a/ebean-test/src/test/java/org/tests/model/inheritmany/IMRelated.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.tests.model.inheritmany; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.ManyToOne; - -@Entity -public class IMRelated { - - @Id - Long id; - - String name; - - @ManyToOne(optional = false) - IMRoot owner; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public IMRoot getOwner() { - return owner; - } - - public void setOwner(IMRoot owner) { - this.owner = owner; - } - -} diff --git a/ebean-test/src/test/java/org/tests/model/inheritmany/IMRoot.java b/ebean-test/src/test/java/org/tests/model/inheritmany/IMRoot.java deleted file mode 100644 index f8d38fab51..0000000000 --- a/ebean-test/src/test/java/org/tests/model/inheritmany/IMRoot.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.tests.model.inheritmany; - -import javax.persistence.*; -import java.util.List; - -@Entity -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -public class IMRoot { - - @Id - Long id; - - @OneToMany(mappedBy = "owner") - List related; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public List getRelated() { - return related; - } - - public void setRelated(List related) { - this.related = related; - } - -} diff --git a/ebean-test/src/test/java/org/tests/model/inheritmany/IMRootOne.java b/ebean-test/src/test/java/org/tests/model/inheritmany/IMRootOne.java deleted file mode 100644 index 1eb67687ef..0000000000 --- a/ebean-test/src/test/java/org/tests/model/inheritmany/IMRootOne.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.tests.model.inheritmany; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@Entity -@DiscriminatorValue("ONE") -public class IMRootOne extends IMRoot { - - String name; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - -} diff --git a/ebean-test/src/test/java/org/tests/model/inheritmany/IMRootTwo.java b/ebean-test/src/test/java/org/tests/model/inheritmany/IMRootTwo.java deleted file mode 100644 index e63891f67a..0000000000 --- a/ebean-test/src/test/java/org/tests/model/inheritmany/IMRootTwo.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.tests.model.inheritmany; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; -import java.util.Date; - -@Entity -@DiscriminatorValue("TWO") -public class IMRootTwo extends IMRoot { - - String title; - - Date whenTitle; - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public Date getWhenTitle() { - return whenTitle; - } - - public void setWhenTitle(Date whenTitle) { - this.whenTitle = whenTitle; - } - -} diff --git a/ebean-test/src/test/java/org/tests/model/inheritmany/MBase.java b/ebean-test/src/test/java/org/tests/model/inheritmany/MBase.java deleted file mode 100644 index 8bfb682e29..0000000000 --- a/ebean-test/src/test/java/org/tests/model/inheritmany/MBase.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.tests.model.inheritmany; - -import javax.persistence.Id; -import javax.persistence.MappedSuperclass; - -@MappedSuperclass -public class MBase { - - @Id - Long id; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - -} diff --git a/ebean-test/src/test/java/org/tests/model/inheritmany/MMedia.java b/ebean-test/src/test/java/org/tests/model/inheritmany/MMedia.java deleted file mode 100644 index 95e3b97e8a..0000000000 --- a/ebean-test/src/test/java/org/tests/model/inheritmany/MMedia.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.tests.model.inheritmany; - -import javax.persistence.*; - -@Entity -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, name = "type") -public class MMedia extends MBase { - - String url; - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - -} diff --git a/ebean-test/src/test/java/org/tests/model/inheritmany/MPicture.java b/ebean-test/src/test/java/org/tests/model/inheritmany/MPicture.java deleted file mode 100644 index 422e935582..0000000000 --- a/ebean-test/src/test/java/org/tests/model/inheritmany/MPicture.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.tests.model.inheritmany; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - - -@Entity -@DiscriminatorValue("Picture") -public class MPicture extends MMedia { - - - String note; - - public String getNote() { - return note; - } - - public void setNote(String note) { - this.note = note; - } - -} diff --git a/ebean-test/src/test/java/org/tests/model/inheritmany/MProfile.java b/ebean-test/src/test/java/org/tests/model/inheritmany/MProfile.java deleted file mode 100644 index d0c561c656..0000000000 --- a/ebean-test/src/test/java/org/tests/model/inheritmany/MProfile.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.tests.model.inheritmany; - -import javax.persistence.CascadeType; -import javax.persistence.Entity; -import javax.persistence.ManyToOne; - -@Entity -public class MProfile extends MBase { - - @ManyToOne(cascade = CascadeType.ALL) - MPicture picture; - - String name; - - public MPicture getPicture() { - return picture; - } - - public void setPicture(MPicture picture) { - this.picture = picture; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - -} diff --git a/ebean-test/src/test/java/org/tests/model/inheritmany/TestMediaInheritanceJoinToMany.java b/ebean-test/src/test/java/org/tests/model/inheritmany/TestMediaInheritanceJoinToMany.java deleted file mode 100644 index 02ba0dc684..0000000000 --- a/ebean-test/src/test/java/org/tests/model/inheritmany/TestMediaInheritanceJoinToMany.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.tests.model.inheritmany; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import io.ebean.Query; -import org.junit.jupiter.api.Test; - -import java.util.Random; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class TestMediaInheritanceJoinToMany extends BaseTestCase { - - @Test - public void test() { - - String name = "nopic" + new Random().nextInt(); - - MProfile profileWithNoPic = new MProfile(); - profileWithNoPic.setName(name); - - DB.save(profileWithNoPic); - - Query query = DB.find(MProfile.class).fetch("picture").where().eq("name", name).query(); - - // assert we get the profile with a null picture - MProfile profile = query.findOne(); - assertNotNull(profile); - - String generatedSql = query.getGeneratedSql(); - assertSql(generatedSql).contains("select t0.id, t0.name, t1.type, t1.id, t1.url, t1.note from mprofile t0 left join mmedia t1 on t1.id = t0.picture_id and t1.type = 'Picture' where t0.name = ?"); - assertSql(generatedSql).contains("where t0.name = ?"); - } - -} diff --git a/ebean-test/src/test/java/org/tests/model/join/AccountAccess.java b/ebean-test/src/test/java/org/tests/model/join/AccountAccess.java deleted file mode 100644 index 052d91156c..0000000000 --- a/ebean-test/src/test/java/org/tests/model/join/AccountAccess.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.tests.model.join; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@DiscriminatorValue("A") -@Entity -public class AccountAccess extends HAccess { - -} diff --git a/ebean-test/src/test/java/org/tests/model/join/BankAccount.java b/ebean-test/src/test/java/org/tests/model/join/BankAccount.java deleted file mode 100644 index 491303be79..0000000000 --- a/ebean-test/src/test/java/org/tests/model/join/BankAccount.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.tests.model.join; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@DiscriminatorValue("B") -@Entity -public class BankAccount extends HAccount { - -} diff --git a/ebean-test/src/test/java/org/tests/model/join/CustomerAccess.java b/ebean-test/src/test/java/org/tests/model/join/CustomerAccess.java deleted file mode 100644 index c9336de179..0000000000 --- a/ebean-test/src/test/java/org/tests/model/join/CustomerAccess.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.tests.model.join; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@DiscriminatorValue("C") -@Entity -public class CustomerAccess extends HAccess { - -} diff --git a/ebean-test/src/test/java/org/tests/model/join/HAccess.java b/ebean-test/src/test/java/org/tests/model/join/HAccess.java index d0d0608f10..031c03fe8d 100644 --- a/ebean-test/src/test/java/org/tests/model/join/HAccess.java +++ b/ebean-test/src/test/java/org/tests/model/join/HAccess.java @@ -5,9 +5,8 @@ import javax.persistence.*; import java.util.UUID; -@Inheritance @Entity -public abstract class HAccess { +public final class HAccess { @Id UUID id; diff --git a/ebean-test/src/test/java/org/tests/model/join/HAccount.java b/ebean-test/src/test/java/org/tests/model/join/HAccount.java index 2ca8964035..1cd7cf2ce0 100644 --- a/ebean-test/src/test/java/org/tests/model/join/HAccount.java +++ b/ebean-test/src/test/java/org/tests/model/join/HAccount.java @@ -3,8 +3,7 @@ import javax.persistence.*; @Entity -@Inheritance -public abstract class HAccount { +public final class HAccount { @Id String accountNumber; diff --git a/ebean-test/src/test/java/org/tests/o2m/jointable/TestOneToManyJoinTableInheritance.java b/ebean-test/src/test/java/org/tests/o2m/jointable/TestOneToManyJoinTableInheritance.java index 818bf8b85d..97e917c2ba 100644 --- a/ebean-test/src/test/java/org/tests/o2m/jointable/TestOneToManyJoinTableInheritance.java +++ b/ebean-test/src/test/java/org/tests/o2m/jointable/TestOneToManyJoinTableInheritance.java @@ -6,7 +6,6 @@ import io.ebean.test.LoggedSql; import org.junit.jupiter.api.Test; import org.tests.o2m.jointable.inheritance.ClassA; -import org.tests.o2m.jointable.inheritance.ClassB; import java.util.Arrays; import java.util.List; @@ -20,7 +19,7 @@ public class TestOneToManyJoinTableInheritance extends BaseTestCase { private JtMonkey m2 = new JtMonkey("Uim"); private ClassA classA = new ClassA(); - private ClassB classB = new ClassB(); + private ClassA classB = new ClassA(); @Test public void testSave() { @@ -38,8 +37,8 @@ public void testSave() { assertThat(sql).hasSize(11); assertSql(sql.get(0)).contains("insert into class_super "); if (idType() == IdType.IDENTITY) { - assertSql(sql.get(1)).contains("-- bind(ClassA)"); - assertSql(sql.get(2)).contains("-- bind(ClassB)"); + assertSql(sql.get(1)).contains("-- bind("); + assertSql(sql.get(2)).contains("-- bind("); } assertThat(sql.get(3)).contains("insert into monkey "); if (idType() == IdType.IDENTITY) { @@ -51,7 +50,7 @@ public void testSave() { assertSqlBind(sql, 8, 10); ClassA dbA = DB.find(ClassA.class, 1); - ClassB dbB = DB.find(ClassB.class, 2); + ClassA dbB = DB.find(ClassA.class, 2); assertThat(dbA.getMonkeys()).hasSize(2); assertThat(dbB.getMonkeys()).hasSize(1); diff --git a/ebean-test/src/test/java/org/tests/o2m/jointable/inheritance/ClassA.java b/ebean-test/src/test/java/org/tests/o2m/jointable/inheritance/ClassA.java index 14644d2003..cc2b921510 100644 --- a/ebean-test/src/test/java/org/tests/o2m/jointable/inheritance/ClassA.java +++ b/ebean-test/src/test/java/org/tests/o2m/jointable/inheritance/ClassA.java @@ -1,7 +1,9 @@ package org.tests.o2m.jointable.inheritance; import javax.persistence.Entity; +import javax.persistence.Table; @Entity +@Table(name = "class_super") public class ClassA extends ClassSuper { } diff --git a/ebean-test/src/test/java/org/tests/o2m/jointable/inheritance/ClassB.java b/ebean-test/src/test/java/org/tests/o2m/jointable/inheritance/ClassB.java deleted file mode 100644 index 305b33999b..0000000000 --- a/ebean-test/src/test/java/org/tests/o2m/jointable/inheritance/ClassB.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.tests.o2m.jointable.inheritance; - -import javax.persistence.Entity; - -@Entity -public class ClassB extends ClassSuper { -} diff --git a/ebean-test/src/test/java/org/tests/o2m/jointable/inheritance/ClassSuper.java b/ebean-test/src/test/java/org/tests/o2m/jointable/inheritance/ClassSuper.java index 2b62d81bfe..b4b2451940 100644 --- a/ebean-test/src/test/java/org/tests/o2m/jointable/inheritance/ClassSuper.java +++ b/ebean-test/src/test/java/org/tests/o2m/jointable/inheritance/ClassSuper.java @@ -5,8 +5,7 @@ import javax.persistence.*; import java.util.List; -@Inheritance -@Entity +@MappedSuperclass public abstract class ClassSuper { @Id long sid; diff --git a/ebean-test/src/test/java/org/tests/order/OrderReferencedParent.java b/ebean-test/src/test/java/org/tests/order/OrderReferencedParent.java index 19ea3481c4..b33bf37276 100644 --- a/ebean-test/src/test/java/org/tests/order/OrderReferencedParent.java +++ b/ebean-test/src/test/java/org/tests/order/OrderReferencedParent.java @@ -6,14 +6,16 @@ @Entity @MappedSuperclass -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "type") +// Inheritance(strategy = InheritanceType.SINGLE_TABLE) +// DiscriminatorColumn(name = "type") @Index(columnNames = "type") public class OrderReferencedParent { @Id Long id; + String type; + String name; public OrderReferencedParent(final String name) { diff --git a/ebean-test/src/test/java/org/tests/query/TestQueryMultiJoinFetchPath.java b/ebean-test/src/test/java/org/tests/query/TestQueryMultiJoinFetchPath.java index 90868a9dad..d46bc0e615 100644 --- a/ebean-test/src/test/java/org/tests/query/TestQueryMultiJoinFetchPath.java +++ b/ebean-test/src/test/java/org/tests/query/TestQueryMultiJoinFetchPath.java @@ -23,17 +23,17 @@ void test() { HCustomer c3 = new HCustomer("c3", "c3"); DB.save(c3); - HAccount a1 = new BankAccount(); + HAccount a1 = new HAccount(); a1.setAccountNumber("a1"); a1.setOwner(c1); DB.save(a1); - CustomerAccess ca = new CustomerAccess(); + HAccess ca = new HAccess(); ca.setAccessor(c3); ca.setPrincipal(c1); DB.save(ca); - AccountAccess aa = new AccountAccess(); + HAccess aa = new HAccess(); aa.setAccessor(c2); aa.setAccount(a1); DB.save(aa); @@ -59,9 +59,9 @@ void test() { assertThat(accesses).hasSize(2); if (isH2()) { - assertThat(query.getGeneratedSql()).isEqualTo("select t0.dtype, t0.id, t0.accessor_id, t0.principal_id, t2.dtype, t0.access_account_number, t1.cid, t1.name, t2.dtype, t2.account_number from haccess t0 left join hcustomer t1 on t1.cid = t0.accessor_id left join haccount t2 on t2.account_number = t0.access_account_number and t2.dtype = 'B' left join hcustomer t3 on t3.cid = t0.principal_id where t1.status = ? and t3.status = ? and t0.id in (?,?,?,?,?)"); + assertThat(query.getGeneratedSql()).isEqualTo("select t0.id, t0.accessor_id, t0.principal_id, t0.access_account_number, t1.cid, t1.name, t2.account_number from haccess t0 left join hcustomer t1 on t1.cid = t0.accessor_id left join haccount t2 on t2.account_number = t0.access_account_number left join hcustomer t3 on t3.cid = t0.principal_id where t1.status = ? and t3.status = ? and t0.id in (?,?,?,?,?)"); } else { - assertThat(query.getGeneratedSql()).contains("select t0.dtype, t0.id, t0.accessor_id, t0.principal_id, t2.dtype, t0.access_account_number, t1.cid, t1.name, t2.dtype, t2.account_number from haccess t0 left join hcustomer t1 on t1.cid = t0.accessor_id left join haccount t2 on t2.account_number = t0.access_account_number and t2.dtype = 'B' left join hcustomer t3 on t3.cid = t0.principal_id where t1.status = ? and t3.status = ? and t0.id "); + assertThat(query.getGeneratedSql()).contains("select t0.id, t0.accessor_id, t0.principal_id, t0.access_account_number, t1.cid, t1.name, t2.account_number from haccess t0 left join hcustomer t1 on t1.cid = t0.accessor_id left join haccount t2 on t2.account_number = t0.access_account_number left join hcustomer t3 on t3.cid = t0.principal_id where t1.status = ? and t3.status = ? and t0.id "); } } diff --git a/ebean-test/src/test/java/org/tests/query/other/TestFindIdsWithInheritance.java b/ebean-test/src/test/java/org/tests/query/other/TestFindIdsWithInheritance.java deleted file mode 100644 index b387006a18..0000000000 --- a/ebean-test/src/test/java/org/tests/query/other/TestFindIdsWithInheritance.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.tests.query.other; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import org.junit.jupiter.api.Test; -import org.tests.model.basic.Truck; -import org.tests.model.basic.Vehicle; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class TestFindIdsWithInheritance extends BaseTestCase { - - @Test - public void testQuery() { - - Truck truck = new Truck(); - truck.setLicenseNumber("TK123"); - - DB.save(truck); - - List ids = DB.find(Vehicle.class).findIds(); - assertNotNull(ids); - - DB.delete(truck); - } - -} diff --git a/ebean-test/src/test/java/org/tests/query/other/TestQuerySingleAttribute.java b/ebean-test/src/test/java/org/tests/query/other/TestQuerySingleAttribute.java index db02e5edaa..89013716ab 100644 --- a/ebean-test/src/test/java/org/tests/query/other/TestQuerySingleAttribute.java +++ b/ebean-test/src/test/java/org/tests/query/other/TestQuerySingleAttribute.java @@ -353,7 +353,7 @@ void distinctSelectOnInheritedBean() { .select("more"); query.findSingleAttributeList(); - assertThat(sqlOf(query)).contains("select distinct t0.more from rawinherit_parent t0 where t0.type = 'A'"); + assertThat(sqlOf(query)).contains("select distinct t0.more from rawinherit_parent t0"); } @Test @@ -424,7 +424,7 @@ void findSingleSelectOnInheritedBean() { .select("more"); query.findSingleAttributeList(); - assertThat(sqlOf(query)).contains("select t0.more from rawinherit_parent t0 where t0.type = 'A'"); + assertThat(sqlOf(query)).contains("select t0.more from rawinherit_parent t0"); } @Test diff --git a/ebean-test/src/test/java/org/tests/rawsql/inherit/ParentQueryTest.java b/ebean-test/src/test/java/org/tests/rawsql/inherit/ParentQueryTest.java index 30b004badd..ab3d999682 100644 --- a/ebean-test/src/test/java/org/tests/rawsql/inherit/ParentQueryTest.java +++ b/ebean-test/src/test/java/org/tests/rawsql/inherit/ParentQueryTest.java @@ -4,9 +4,7 @@ import io.ebean.DB; import org.junit.jupiter.api.Test; import org.tests.inherit.ChildA; -import org.tests.inherit.ChildB; import org.tests.inherit.Data; -import org.tests.inherit.Parent; import java.util.ArrayList; import java.util.List; @@ -27,7 +25,7 @@ void queryParentCollectionFetch() { a.setData(exampleData); DB.save(a); - ChildB b = new ChildB(1001, "PQT-PB"); + ChildA b = new ChildA("B", 1001, "PQT-PB"); b.setData(exampleData); DB.save(b); @@ -35,7 +33,7 @@ void queryParentCollectionFetch() { c.setData(exampleData); DB.save(c); - List partial = DB.find(Parent.class).where().ge("val", 1001).findList(); + List partial = DB.find(ChildA.class).where().ge("val", 1001).findList(); assertNotNull(partial.get(0).getData()); assertThat(partial.get(0).getMore()).startsWith("PQT-"); assertThat(partial.get(0).getData()).hasSize(3); diff --git a/ebean-test/src/test/java/org/tests/rawsql/inherit/ParentRawSqlTest.java b/ebean-test/src/test/java/org/tests/rawsql/inherit/ParentRawSqlTest.java index cb8662d1e0..73711e4d4d 100644 --- a/ebean-test/src/test/java/org/tests/rawsql/inherit/ParentRawSqlTest.java +++ b/ebean-test/src/test/java/org/tests/rawsql/inherit/ParentRawSqlTest.java @@ -18,7 +18,7 @@ public class ParentRawSqlTest extends BaseTestCase { @BeforeEach public void clearDb() { DB.deleteAll(DB.find(Data.class).findList()); - DB.deleteAll(DB.find(Parent.class).findList()); + DB.deleteAll(DB.find(ChildA.class).findList()); //@rob: this does not work as it does not clear the ManyToMany relations. // DB.find(Data.class).delete(); // DB.find(Parent.class).delete(); @@ -36,7 +36,7 @@ public void RawSqlParentLoad() { a.setData(exampleData); DB.save(a); - ChildB b = new ChildB(1, "PB"); + ChildA b = new ChildA("B", 1, "PB"); b.setData(exampleData); DB.save(b); @@ -48,7 +48,7 @@ public void RawSqlParentLoad() { .parse("select type, id, val from rawinherit_parent where val > 1") .create(); - List partial = DB.find(Parent.class) + List partial = DB.find(ChildA.class) .setRawSql(rawSql) .findList(); @@ -68,7 +68,7 @@ public void RawSqlParentFetch() { a.setData(exampleData); DB.save(a); - ChildB b = new ChildB(1, "PB"); + ChildA b = new ChildA("B", 1, "PB"); b.setData(exampleData); DB.save(b); @@ -108,8 +108,8 @@ private void joinToInheritanceHierarchy_bug416() { List uncles = DB.find(EUncle.class).setRawSql(rawSql).findList(); assertNotNull(uncles.get(0)); - Parent parent = uncles.get(0).getParent(); - assertTrue(parent instanceof ChildB); + ChildA parent = uncles.get(0).getParent(); + assertTrue(parent instanceof ChildA); } private void joinToInheritanceHierarchy_with_queryJoin() { @@ -127,8 +127,8 @@ private void joinToInheritanceHierarchy_with_queryJoin() { .findList(); assertNotNull(uncles.get(0)); - Parent parent = uncles.get(0).getParent(); - assertTrue(parent instanceof ChildB); + ChildA parent = uncles.get(0).getParent(); + assertTrue(parent instanceof ChildA); } private void joinToInheritanceHierarchy_withIgnore() { @@ -146,8 +146,8 @@ private void joinToInheritanceHierarchy_withIgnore() { .findList(); assertNotNull(uncles.get(0)); - Parent parent = uncles.get(0).getParent(); - assertTrue(parent instanceof ChildB); + ChildA parent = uncles.get(0).getParent(); + assertTrue(parent instanceof ChildA); } private void joinToInheritanceHierarchy_withAliasMapping() { @@ -161,8 +161,8 @@ private void joinToInheritanceHierarchy_withAliasMapping() { .findList(); assertNotNull(uncles.get(0)); - Parent parent = uncles.get(0).getParent(); - assertTrue(parent instanceof ChildB); + ChildA parent = uncles.get(0).getParent(); + assertTrue(parent instanceof ChildA); } /** @@ -180,7 +180,7 @@ private void useColumnMappingWithDiscriminator() { .fetchQuery("parent") .findList(); - List partial = new ArrayList<>(); + List partial = new ArrayList<>(); for (ParentAggregate aggregate : aggregates) { partial.add(aggregate.parent); } @@ -204,7 +204,7 @@ private void useColumnMappingIgnore() { .fetchQuery("parent") .findList(); - List partial = new ArrayList<>(); + List partial = new ArrayList<>(); for (ParentAggregate aggregate : aggregates) { partial.add(aggregate.parent); } @@ -230,7 +230,7 @@ private void useExtraColumnMappingIgnore() { .fetchQuery("parent") .findList(); - List partial = new ArrayList<>(); + List partial = new ArrayList<>(); for (ParentAggregate aggregate : aggregates) { partial.add(aggregate.parent); } diff --git a/ebean-test/src/test/java/org/tests/singleTableInheritance/TestInheritQuery.java b/ebean-test/src/test/java/org/tests/singleTableInheritance/TestInheritQuery.java deleted file mode 100644 index 6010d0bfb8..0000000000 --- a/ebean-test/src/test/java/org/tests/singleTableInheritance/TestInheritQuery.java +++ /dev/null @@ -1,168 +0,0 @@ -package org.tests.singleTableInheritance; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import org.junit.jupiter.api.Test; -import org.tests.singleTableInheritance.model.*; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -public class TestInheritQuery extends BaseTestCase { - - @Test - public void test() { - ZoneExternal zone = new ZoneExternal(); - zone.setAttribute("ABC"); - DB.save(zone); - - PalletLocationExternal location = new PalletLocationExternal(); - location.setZone(zone); - location.setAttribute("123"); - DB.save(location); - - // This line should work too: - List locations = DB.find(PalletLocation.class).where().eq("zone", zone) - .findList(); - // List locations = - // DB.find(PalletLocation.class).where().eq("zone.id", - // zone.getId()).findList(); - - assertNotNull(locations); - assertEquals(1, locations.size()); - PalletLocation rereadLoc = locations.get(0); - assertTrue(rereadLoc instanceof PalletLocation); - Zone rereadZone = rereadLoc.getZone(); - assertNotNull(rereadZone); - assertTrue(rereadZone instanceof ZoneExternal); - } - - @SuppressWarnings("unlikely-arg-type") - @Test - public void testDiscriminator_bug417() { - - - DB.deleteAll(DB.find(Warehouse.class).findList()); - DB.deleteAll(DB.find(PalletLocation.class).findList()); - DB.deleteAll(DB.find(Zone.class).findList()); - DB.deleteAll(DB.find(ZoneInternal.class).findList()); - DB.deleteAll(DB.find(ZoneInternal.class).findList()); - - ZoneInternal zoneInt = new ZoneInternal(); - zoneInt.setAttribute("some zone 1"); - DB.save(zoneInt); - - ZoneExternal zoneExt = new ZoneExternal(); - zoneExt.setAttribute("some zone 2"); - DB.save(zoneExt); - - // queries of Zone and subclasses as root node of query - - // query abstract class on attribute (root of heirarchy) - List zones = DB.find(Zone.class).where().startsWith("attribute", "some zone").findList(); - // select t0.type c0, t0.ID c1, t0.attribute c2, t0.attribute c3 from zones t0 where t0.attribute like ? ; --bind(some zone%) - assertEquals(2, zones.size()); - assertTrue(zones.contains(zoneInt)); - assertTrue(zones.contains(zoneExt)); - - // query internal zones only - // discriminator is in WHERE clause where it belongs - List internalZones = DB.find(ZoneInternal.class).where().startsWith("attribute", "some zone").findList(); - // select t0.type c0, t0.ID c1, t0.attribute c2 from zones t0 where t0.type = 'INT' and t0.attribute like ? ; --bind(some zone%) - assertEquals(1, internalZones.size()); - assertTrue(internalZones.contains(zoneInt)); - assertFalse(internalZones.contains(zoneExt)); - assertTrue(internalZones.get(0) instanceof ZoneInternal); - - // query external zones only - List externalZones = DB.find(ZoneExternal.class).where().startsWith("attribute", "some zone").findList(); - // select t0.type c0, t0.ID c1, t0.attribute c2 from zones t0 where t0.type = 'EXT' and t0.attribute like ? ; --bind(some zone%) - assertEquals(1, externalZones.size()); - assertTrue(externalZones.contains(zoneExt)); - assertFalse(externalZones.contains(zoneInt)); - assertTrue(externalZones.get(0) instanceof ZoneExternal); - - // parents with children of Zones and subclasses - - Warehouse wh = new Warehouse(); - wh.setOfficeZone(zoneInt); // many-to-one - wh.getShippingZones().add(zoneExt); // many-to-many - DB.save(wh); - - // JOIN clause, no discriminator - // parent with many-to-one, doesn't put in discriminator, why not, PK sufficient? - // eager join - Warehouse wh2 = DB.find(Warehouse.class, wh.getId()); - assertNotNull(wh2); - assertEquals(wh.getId(), wh2.getId()); - assertEquals(wh.getOfficeZone(), wh2.getOfficeZone()); - assertEquals(wh.getOfficeZone().getAttribute(), wh2.getOfficeZone().getAttribute()); - - // before the fix, next assertion runs this lazy query: - - // select t0.ID c0, t1.type c1, t1.ID c2 from warehouses t0 - // left join WarehousesShippingZones t1z_ on t1z_.warehouseId = t0.ID - // left join zones t1 on t1.ID = t1z_.shippingZoneId - // where t1.type = 'EXT' // this should be in the join clause - // and t0.ID = ? - // order by t0.ID; --bind(1) - - // this works here because we have at least one shipping zone - - assertEquals(1, wh2.getShippingZones().size()); - assertTrue(wh2.getShippingZones().contains(zoneExt)); - - // set optional concrete to null to set stage for failure - wh.setOfficeZone(null); - DB.save(wh); - - // no discriminator here - wh2 = DB.find(Warehouse.class) - .where().eq("id", wh.getId()) - .findOne(); - - assertNotNull(wh2); - // discriminator is used here, should be in join - // assuming this "manual" fetch is equivalent to autofetch (i.e., autofetch should work the same way) - // before Daryl's fix - // select t0.ID c0, t1.type c1, t1.ID c2, t1.attribute c3 from warehouses t0 left join zones t1 on t1.ID = t0.officeZoneId where t1.type = 'INT' and t0.ID = ? - // todo: after Daryl's fix, not sure if this is proper, no discriminator at all, isn't PK/FK sufficient? - // select t0.ID c0, t1.type c1, t1.ID c2, t1.attribute c3 from warehouses t0 left join zones t1 on t1.ID = t0.officeZoneId where t0.ID = ? ; --bind(1) - wh2 = DB.find(Warehouse.class) - .fetch("officeZone") - .where().eq("id", wh.getId()) - .findOne(); - // key assertion #1 - fails due to left join with discriminator in WHERE - assertNotNull(wh2); - - // clear children to set the stage for left join failure - wh.getShippingZones().clear(); - DB.save(wh); - - wh2 = DB.find(Warehouse.class, wh.getId()); - assertNotNull(wh2); - assertEquals(wh.getId(), wh2.getId()); - assertEquals(0, wh.getShippingZones().size()); - - // query with lazy load of abstract children - wh = DB.find(Warehouse.class) - .where().eq("id", wh.getId()) - .findOne(); - assertNotNull(wh); - assertEquals(wh.getId(), wh2.getId()); - assertEquals(0, wh.getShippingZones().size()); - - // query with fetch of abstract children - wh = DB.find(Warehouse.class) - .fetch("shippingZones") - .where().eq("id", wh.getId()) - .findOne(); - // key assertion #2 - fails due to left join with discriminator in WHERE - assertNotNull(wh); - assertEquals(wh.getId(), wh2.getId()); - assertEquals(0, wh.getShippingZones().size()); - - - } -} diff --git a/ebean-test/src/test/java/org/tests/singleTableInheritance/model/PalletLocation.java b/ebean-test/src/test/java/org/tests/singleTableInheritance/model/PalletLocation.java deleted file mode 100644 index 694246b5b6..0000000000 --- a/ebean-test/src/test/java/org/tests/singleTableInheritance/model/PalletLocation.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.tests.singleTableInheritance.model; - -import javax.persistence.*; - -@Entity -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING) -public class PalletLocation { - @Id - @Column(name = "id") - private Integer id; - - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "zone_sid") - private Zone zone; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public Zone getZone() { - return zone; - } - - public void setZone(Zone zone) { - this.zone = zone; - } -} diff --git a/ebean-test/src/test/java/org/tests/singleTableInheritance/model/PalletLocationExternal.java b/ebean-test/src/test/java/org/tests/singleTableInheritance/model/PalletLocationExternal.java deleted file mode 100644 index 553a77852b..0000000000 --- a/ebean-test/src/test/java/org/tests/singleTableInheritance/model/PalletLocationExternal.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.tests.singleTableInheritance.model; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@Entity -@DiscriminatorValue("EXT") -public class PalletLocationExternal extends PalletLocation { - private String attribute; - - public String getAttribute() { - return attribute; - } - - public void setAttribute(String attribute) { - this.attribute = attribute; - } -} diff --git a/ebean-test/src/test/java/org/tests/singleTableInheritance/model/Warehouse.java b/ebean-test/src/test/java/org/tests/singleTableInheritance/model/Warehouse.java deleted file mode 100644 index b79e599505..0000000000 --- a/ebean-test/src/test/java/org/tests/singleTableInheritance/model/Warehouse.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.tests.singleTableInheritance.model; - -import javax.persistence.*; -import java.util.Set; - -@Entity -@Table(name = "warehouses") -public class Warehouse { - @Id - @Column(name = "id") - private Integer id; - - @ManyToOne//(optional = false) //todo: should this be nullable with assertions made? - @JoinColumn(name = "officezoneid") - private ZoneInternal officeZone; - - @ManyToMany(cascade = CascadeType.PERSIST) - @JoinTable(name = "warehousesshippingzones", - joinColumns = {@JoinColumn(name = "warehouseid", referencedColumnName = "id")}, - inverseJoinColumns = {@JoinColumn(name = "shippingzoneid", referencedColumnName = "id")} - ) - private Set shippingZones; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public ZoneInternal getOfficeZone() { - return officeZone; - } - - public void setOfficeZone(ZoneInternal officeZone) { - this.officeZone = officeZone; - } - - public Set getShippingZones() { - return shippingZones; - } - - public void setShippingZones(Set shippingZones) { - this.shippingZones = shippingZones; - } - -} diff --git a/ebean-test/src/test/java/org/tests/singleTableInheritance/model/Zone.java b/ebean-test/src/test/java/org/tests/singleTableInheritance/model/Zone.java deleted file mode 100644 index f0f820ded2..0000000000 --- a/ebean-test/src/test/java/org/tests/singleTableInheritance/model/Zone.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.tests.singleTableInheritance.model; - -import javax.persistence.*; - -@Entity -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING) -@Table(name = "zones") -public class Zone { - @Id - @Column(name = "id") - private Integer id; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - @Override - public int hashCode() { - if (getId() != null) return getId().hashCode(); - else return super.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof Zone) { - return ((Zone) obj).getId().equals(getId()); - } else { - return false; - } - } -} diff --git a/ebean-test/src/test/java/org/tests/singleTableInheritance/model/ZoneExternal.java b/ebean-test/src/test/java/org/tests/singleTableInheritance/model/ZoneExternal.java deleted file mode 100644 index 26599cf733..0000000000 --- a/ebean-test/src/test/java/org/tests/singleTableInheritance/model/ZoneExternal.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.tests.singleTableInheritance.model; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@Entity -@DiscriminatorValue("EXT") -public class ZoneExternal extends Zone { - private String attribute; - - public String getAttribute() { - return attribute; - } - - public void setAttribute(String attribute) { - this.attribute = attribute; - } - - @Override - public String toString() { - return "ZoneExternal " + getId() + " \"" + getAttribute() + "\""; - } -} diff --git a/ebean-test/src/test/java/org/tests/singleTableInheritance/model/ZoneInternal.java b/ebean-test/src/test/java/org/tests/singleTableInheritance/model/ZoneInternal.java deleted file mode 100644 index eb558952b9..0000000000 --- a/ebean-test/src/test/java/org/tests/singleTableInheritance/model/ZoneInternal.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.tests.singleTableInheritance.model; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -@Entity -@DiscriminatorValue("INT") -public class ZoneInternal extends Zone { - - private String attribute; - - public String getAttribute() { - return attribute; - } - - public void setAttribute(String attribute) { - this.attribute = attribute; - } - - @Override - public String toString() { - return "ZoneInternal " + getId() + " \"" + getAttribute() + "\""; - } -} diff --git a/ebean-test/src/test/java/org/tests/test/TestInheritWithMany.java b/ebean-test/src/test/java/org/tests/test/TestInheritWithMany.java deleted file mode 100644 index 02bd9d1d80..0000000000 --- a/ebean-test/src/test/java/org/tests/test/TestInheritWithMany.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.tests.test; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import io.ebean.Database; -import io.ebeaninternal.api.SpiEbeanServer; -import io.ebeaninternal.server.deploy.BeanDescriptor; -import io.ebeaninternal.server.deploy.InheritInfo; -import org.junit.jupiter.api.Test; -import org.tests.model.inheritmany.IMRelated; -import org.tests.model.inheritmany.IMRoot; -import org.tests.model.inheritmany.IMRootOne; -import org.tests.model.inheritmany.IMRootTwo; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - - -public class TestInheritWithMany extends BaseTestCase { - - - @Test - public void test() { - - Database server = DB.getDefault(); - assertNotNull(server); - - SpiEbeanServer spiServer = (SpiEbeanServer) server; - BeanDescriptor beanDescriptor = spiServer.descriptor(IMRoot.class); - InheritInfo inheritInfo = beanDescriptor.inheritInfo(); - assertNotNull(inheritInfo); - - - IMRootOne one = new IMRootOne(); - one.setName("One Name"); - server.save(one); - add(one, "aaa"); - add(one, "bbb"); - - - IMRootTwo two = new IMRootTwo(); - two.setTitle("Two Title"); - server.save(two); - add(two, "ccc"); - add(two, "ddd"); - - - List list = server.find(IMRoot.class).select("id").findList(); - - for (IMRoot imRoot : list) { - // lazy load the related OneToMany which is related to a non-leaf - List related = imRoot.getRelated(); - for (IMRelated imRelated : related) { - imRelated.getName(); - } - } - - } - - private void add(IMRoot owner, String string) { - - IMRelated relate = new IMRelated(); - relate.setName(string); - relate.setOwner(owner); - - Database server = DB.getDefault(); - server.save(relate); - } - - -} diff --git a/ebean-test/src/test/java/org/tests/text/json/TestJsonInheritanceDiscriminator.java b/ebean-test/src/test/java/org/tests/text/json/TestJsonInheritanceDiscriminator.java deleted file mode 100644 index faac7e1271..0000000000 --- a/ebean-test/src/test/java/org/tests/text/json/TestJsonInheritanceDiscriminator.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.tests.text.json; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import io.ebean.text.json.JsonContext; -import org.junit.jupiter.api.Test; -import org.tests.model.basic.Animal; -import org.tests.model.basic.Cat; -import org.tests.model.basic.Dog; - -import java.sql.Date; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class TestJsonInheritanceDiscriminator extends BaseTestCase { - - @Test - public void testNoDiscriminator() { - - Cat cat = new Cat(); - cat.setName("Gemma"); - - DB.save(cat); - - JsonContext json = DB.json(); - String jsonContent = json.toJson(cat); - - Cat cat2 = json.toBean(Cat.class, jsonContent); - - assertEquals(cat.getId(), cat2.getId()); - assertEquals(cat.getName(), cat2.getName()); - assertEquals(cat.getVersion(), cat2.getVersion()); - - String noDiscriminator = "{\"id\":1,\"name\":\"Gemma\",\"version\":1}"; - - Cat cat3 = json.toBean(Cat.class, noDiscriminator); - - assertEquals(1L, cat3.getId().longValue()); - assertEquals("Gemma", cat3.getName()); - assertEquals(1L, cat3.getVersion().longValue()); - - Dog dog = new Dog(); - dog.setRegistrationNumber("ABC123"); - dog.setDateOfBirth(new Date(System.currentTimeMillis())); - - DB.save(dog); - - List animals = DB.find(Animal.class).findList(); - - String listJson = json.toJson(animals); - - List animals2 = json.toList(Animal.class, listJson); - assertEquals(animals.size(), animals2.size()); - - String noDiscList = "[{\"id\":1,\"name\":\"Gemma\",\"version\":1},{\"name\":\"PussCat\",\"version\":1},{\"species\":\"CAT\",\"name\":\"PussCat\",\"version\":1}]"; - List cats = json.toList(Cat.class, noDiscList); - assertEquals(cats.size(), 3); - - } - -} diff --git a/ebean-test/src/test/java/org/tests/text/json/TestTextJsonInheritance.java b/ebean-test/src/test/java/org/tests/text/json/TestTextJsonInheritance.java deleted file mode 100644 index 6f2fc22f1a..0000000000 --- a/ebean-test/src/test/java/org/tests/text/json/TestTextJsonInheritance.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.tests.text.json; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import io.ebean.text.json.JsonContext; -import org.junit.jupiter.api.Test; -import org.tests.model.basic.*; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class TestTextJsonInheritance extends BaseTestCase { - - @Test - public void parseJson_when_inheritanceType_outOfOrderDtype() { - - String fom = "{\"id\":90,\"name\":\"Frank\",\"vehicle\":{\"id\":42,\"licenseNumber\":\"T100\",\"capacity\":99.0,\"dtype\":\"T\"}}"; - - VehicleDriver driver1 = DB.json().toBean(VehicleDriver.class, fom); - assertThat(driver1.getVehicle()).isInstanceOf(Truck.class); - assertThat(driver1.getVehicle().getLicenseNumber()).isEqualTo("T100"); - } - - @Test - public void test() { - - setupData(); - - List list = DB.find(Vehicle.class).setAutoTune(false).findList(); - - assertEquals(2, list.size()); - - JsonContext jsonContext = DB.json(); - String jsonString = jsonContext.toJson(list); - - List rebuiltList = jsonContext.toList(Vehicle.class, jsonString); - - assertEquals(2, rebuiltList.size()); - } - - private void setupData() { - DB.createUpdate(CarAccessory.class, "delete from CarAccessory").execute(); - DB.createUpdate(CarFuse.class, "delete from CarFuse").execute(); - DB.createUpdate(Trip.class, "delete from trip").execute(); - DB.createUpdate(VehicleDriver.class, "delete from vehicleDriver").execute(); - DB.createUpdate(Vehicle.class, "delete from vehicle").execute(); - - Car c = new Car(); - c.setLicenseNumber("C6788"); - c.setDriver("CarDriver"); - DB.save(c); - - Truck t = new Truck(); - t.setLicenseNumber("T1098"); - t.setCapacity(20D); - DB.save(t); - } -}