From 43fa85fe71f33d53779cbe2f7bcc8efcf6251841 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Tue, 29 Aug 2023 00:16:38 +1200 Subject: [PATCH] [15x] Remove Draftable support --- .../src/main/java/io/ebean/Database.java | 98 -------- .../main/java/io/ebean/ExpressionList.java | 5 - ebean-api/src/main/java/io/ebean/Query.java | 5 - .../java/io/ebeaninternal/api/SpiQuery.java | 10 - .../server/core/DefaultBeanLoader.java | 7 +- .../server/core/DefaultServer.java | 48 ---- .../server/core/InternalConfiguration.java | 3 +- .../server/core/PersistRequestBean.java | 74 +----- .../ebeaninternal/server/core/Persister.java | 10 - .../server/deploy/BeanDescriptor.java | 128 +--------- .../deploy/BeanDescriptorDraftHelp.java | 99 -------- .../deploy/BeanDescriptorInitContext.java | 12 +- .../server/deploy/BeanDescriptorManager.java | 31 +-- .../server/deploy/BeanProperty.java | 67 +----- .../server/deploy/BeanPropertyAssocMany.java | 86 +------ .../server/deploy/DbReadContext.java | 5 - .../server/deploy/DbSqlContext.java | 5 - .../server/deploy/IntersectionBuilder.java | 23 +- .../server/deploy/IntersectionTable.java | 14 +- .../deploy/meta/DeployBeanDescriptor.java | 33 +-- .../deploy/meta/DeployBeanProperty.java | 39 --- .../meta/DeployBeanPropertyAssocMany.java | 15 -- .../deploy/meta/DeployBeanPropertyLists.java | 15 -- .../server/deploy/parse/AnnotationClass.java | 4 +- .../server/deploy/parse/AnnotationFields.java | 11 +- .../expression/DefaultExpressionList.java | 5 - .../server/expression/JunctionExpression.java | 5 - .../server/loadcontext/DLoadContext.java | 6 - .../server/persist/DefaultPersister.java | 222 +----------------- .../ebeaninternal/server/persist/Flags.java | 33 +-- .../persist/MergeNodeAssocManyToMany.java | 4 +- .../server/persist/SaveManyBeans.java | 8 +- .../server/persist/dml/DeleteMeta.java | 16 +- .../server/persist/dml/InsertHandler.java | 4 +- .../server/persist/dml/InsertMeta.java | 41 +--- .../server/persist/dmlbind/Bindable.java | 5 - .../persist/dmlbind/BindableAssocOne.java | 5 - .../dmlbind/BindableDiscriminator.java | 5 - .../persist/dmlbind/BindableEmbedded.java | 6 - .../dmlbind/BindableEncryptedProperty.java | 5 - .../persist/dmlbind/BindableIdEmbedded.java | 5 - .../persist/dmlbind/BindableIdEmpty.java | 5 - .../persist/dmlbind/BindableIdScalar.java | 5 - .../server/persist/dmlbind/BindableList.java | 18 -- .../persist/dmlbind/BindableProperty.java | 5 - .../dmlbind/BindablePropertyVersion.java | 5 - .../dmlbind/BindableUnidirectional.java | 5 - .../io/ebeaninternal/server/query/CQuery.java | 5 - .../server/query/CQueryBuilder.java | 11 +- .../server/query/CQueryDraftSupport.java | 28 --- .../server/query/CQueryEngine.java | 10 +- .../server/query/DefaultDbSqlContext.java | 13 +- .../server/query/DefaultFetchGroupQuery.java | 5 - .../ebeaninternal/server/query/STreeType.java | 5 - .../server/query/SqlBeanLoad.java | 2 +- .../server/query/SqlTreeBuilder.java | 3 +- .../server/query/SqlTreeLoadBean.java | 3 - .../server/querydefn/DefaultOrmQuery.java | 12 - .../server/querydefn/OrmQueryPlanKeyTest.java | 2 - .../platform/DbTriggerBasedHistoryDdl.java | 6 +- .../platform/HanaHistoryDdl.java | 6 +- .../dbmigration/model/CurrentModel.java | 2 - .../dbmigration/model/MColumn.java | 19 +- .../dbmigration/model/MTable.java | 83 +------ .../dbmigration/model/ModelContainer.java | 11 - .../model/build/ModelBuildContext.java | 53 ----- .../build/ModelBuildIntersectionTable.java | 5 - .../build/ModelBuildPropertyVisitor.java | 14 -- .../java/io/ebean/typequery/TQRootBean.java | 8 - .../config/PlatformNoGeneratedKeysTest.java | 2 +- .../xtest/internal/api/TDSpiEbeanServer.java | 40 ---- .../ebean/xtest/internal/api/TDSpiServer.java | 40 ---- .../internal/server/persist/FlagsTest.java | 22 +- .../tests/defaultvalues/DefaultsModel.java | 11 - .../org/tests/defaultvalues/TestDefaults.java | 8 +- .../java/org/tests/draftable/DocLinkTest.java | 118 ++++------ .../tests/draftable/LinkQueryPublishTest.java | 4 +- .../org/tests/draftable/OrganisationTest.java | 19 +- .../tests/insert/TestInsertCheckUnique.java | 19 +- .../tests/insert/TestInsertDuplicateKey.java | 6 +- .../org/tests/model/draftable/Document.java | 15 +- .../TestTransactionTryResources.java | 2 - 82 files changed, 166 insertions(+), 1711 deletions(-) delete mode 100644 ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorDraftHelp.java delete mode 100644 ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryDraftSupport.java diff --git a/ebean-api/src/main/java/io/ebean/Database.java b/ebean-api/src/main/java/io/ebean/Database.java index 809992f9ab..5f84af1671 100644 --- a/ebean-api/src/main/java/io/ebean/Database.java +++ b/ebean-api/src/main/java/io/ebean/Database.java @@ -1326,104 +1326,6 @@ public interface Database { */ DocumentStore docStore(); - /** - * Publish a single bean given its type and id returning the resulting live bean. - *

- * The values are published from the draft to the live bean. - * - * @param the type of the entity bean - * @param beanType the type of the entity bean - * @param id the id of the entity bean - * @param transaction the transaction the publish process should use (can be null) - */ - @Nullable - T publish(Class beanType, Object id, Transaction transaction); - - /** - * Publish a single bean given its type and id returning the resulting live bean. - * This will use the current transaction or create one if required. - *

- * The values are published from the draft to the live bean. - * - * @param the type of the entity bean - * @param beanType the type of the entity bean - * @param id the id of the entity bean - */ - @Nullable - T publish(Class beanType, Object id); - - /** - * Publish the beans that match the query returning the resulting published beans. - *

- * The values are published from the draft beans to the live beans. - * - * @param the type of the entity bean - * @param query the query used to select the draft beans to publish - * @param transaction the transaction the publish process should use (can be null) - */ - List publish(Query query, Transaction transaction); - - /** - * Publish the beans that match the query returning the resulting published beans. - * This will use the current transaction or create one if required. - *

- * The values are published from the draft beans to the live beans. - * - * @param the type of the entity bean - * @param query the query used to select the draft beans to publish - */ - List publish(Query query); - - /** - * Restore the draft bean back to the live state. - *

- * The values from the live beans are set back to the draft bean and the - * @DraftDirty and @DraftReset properties are reset. - * - * @param the type of the entity bean - * @param beanType the type of the entity bean - * @param id the id of the entity bean to restore - * @param transaction the transaction the restore process should use (can be null) - */ - @Nullable - T draftRestore(Class beanType, Object id, Transaction transaction); - - /** - * Restore the draft bean back to the live state. - *

- * The values from the live beans are set back to the draft bean and the - * @DraftDirty and @DraftReset properties are reset. - * - * @param the type of the entity bean - * @param beanType the type of the entity bean - * @param id the id of the entity bean to restore - */ - @Nullable - T draftRestore(Class beanType, Object id); - - /** - * Restore the draft beans matching the query back to the live state. - *

- * The values from the live beans are set back to the draft bean and the - * @DraftDirty and @DraftReset properties are reset. - * - * @param the type of the entity bean - * @param query the query used to select the draft beans to restore - * @param transaction the transaction the restore process should use (can be null) - */ - List draftRestore(Query query, Transaction transaction); - - /** - * Restore the draft beans matching the query back to the live state. - *

- * The values from the live beans are set back to the draft bean and the - * @DraftDirty and @DraftReset properties are reset. - * - * @param the type of the entity bean - * @param query the query used to select the draft beans to restore - */ - List draftRestore(Query query); - /** * Returns the set of properties/paths that are unknown (do not map to known properties or paths). *

diff --git a/ebean-api/src/main/java/io/ebean/ExpressionList.java b/ebean-api/src/main/java/io/ebean/ExpressionList.java index 9660d3e3e8..d5d4003ccb 100644 --- a/ebean-api/src/main/java/io/ebean/ExpressionList.java +++ b/ebean-api/src/main/java/io/ebean/ExpressionList.java @@ -106,11 +106,6 @@ default OrderBy order() { */ Query asOf(Timestamp asOf); - /** - * Execute the query against the draft set of tables. - */ - Query asDraft(); - /** * Convert the query to a DTO bean query. *

diff --git a/ebean-api/src/main/java/io/ebean/Query.java b/ebean-api/src/main/java/io/ebean/Query.java index 3cde03c15a..49f2b96003 100644 --- a/ebean-api/src/main/java/io/ebean/Query.java +++ b/ebean-api/src/main/java/io/ebean/Query.java @@ -250,11 +250,6 @@ enum LockWait { */ Query asOf(Timestamp asOf); - /** - * Execute the query against the draft set of tables. - */ - Query asDraft(); - /** * Convert the query to a DTO bean query. *

diff --git a/ebean-core/src/main/java/io/ebeaninternal/api/SpiQuery.java b/ebean-core/src/main/java/io/ebeaninternal/api/SpiQuery.java index 77fc16e43a..b8b0a37a2b 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/api/SpiQuery.java +++ b/ebean-core/src/main/java/io/ebeaninternal/api/SpiQuery.java @@ -168,11 +168,6 @@ enum TemporalMode { */ SOFT_DELETED(false), - /** - * Query runs against draft tables. - */ - DRAFT(false), - /** * Query runs against current data (normal). */ @@ -375,11 +370,6 @@ public static TemporalMode of(SpiQuery query) { */ boolean isAsOfQuery(); - /** - * Return true if this is a 'As Draft' query. - */ - boolean isAsDraft(); - /** * Return true if this query includes soft deleted rows. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultBeanLoader.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultBeanLoader.java index 563a68274f..e3f747682b 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultBeanLoader.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultBeanLoader.java @@ -178,12 +178,11 @@ private void refreshBeanInternal(EntityBean bean, SpiQuery.Mode mode, int embedd desc.contextPut(pc, id, bean); ebi.setPersistenceContext(pc); } - boolean draft = desc.isDraftInstance(bean); if (embeddedOwnerIndex == -1) { if (desc.lazyLoadMany(ebi)) { return; } - if (!draft && Mode.LAZYLOAD_BEAN == mode && desc.isBeanCaching()) { + if (Mode.LAZYLOAD_BEAN == mode && desc.isBeanCaching()) { // lazy loading and the bean cache is active if (desc.cacheBeanLoad(bean, ebi, id, pc)) { return; @@ -192,9 +191,7 @@ private void refreshBeanInternal(EntityBean bean, SpiQuery.Mode mode, int embedd } SpiQuery query = server.createQuery(desc.type()); query.setLazyLoadProperty(ebi.lazyLoadProperty()); - if (draft) { - query.asDraft(); - } else if (mode == SpiQuery.Mode.LAZYLOAD_BEAN && desc.isSoftDelete()) { + if (mode == SpiQuery.Mode.LAZYLOAD_BEAN && desc.isSoftDelete()) { query.setIncludeSoftDeletes(); } if (embeddedOwnerIndex > -1) { 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 80e8cf9037..20a1006ed3 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 @@ -1636,54 +1636,6 @@ public void insertAll(@Nullable Collection beans, @Nullable Transaction trans }, transaction); } - @Override - public List publish(Query query, @Nullable Transaction transaction) { - return executeInTrans((txn) -> persister.publish(query, txn), transaction); - } - - @Nullable - @Override - public T publish(Class beanType, Object id) { - return publish(beanType, id, null); - } - - @Override - public List publish(Query query) { - return publish(query, null); - } - - @Nullable - @Override - public T publish(Class beanType, Object id, @Nullable Transaction transaction) { - Query query = find(beanType).setId(id); - List liveBeans = publish(query, transaction); - return (liveBeans.size() == 1) ? liveBeans.get(0) : null; - } - - @Override - public List draftRestore(Query query, @Nullable Transaction transaction) { - return executeInTrans((txn) -> persister.draftRestore(query, txn), transaction); - } - - @Nullable - @Override - public T draftRestore(Class beanType, Object id, @Nullable Transaction transaction) { - Query query = find(beanType).setId(id); - List beans = draftRestore(query, transaction); - return (beans.size() == 1) ? beans.get(0) : null; - } - - @Nullable - @Override - public T draftRestore(Class beanType, Object id) { - return draftRestore(beanType, id, null); - } - - @Override - public List draftRestore(Query query) { - return draftRestore(query, null); - } - private EntityBean checkEntityBean(Object bean) { return (EntityBean) Objects.requireNonNull(bean); } 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 7c2d5d9bc9..578586b0c3 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 @@ -120,11 +120,10 @@ public final class InternalConfiguration { this.dtoBeanManager = new DtoBeanManager(typeManager); this.beanDescriptorManager = new BeanDescriptorManager(this); Map asOfTableMapping = beanDescriptorManager.deploy(); - Map draftTableMap = beanDescriptorManager.draftTableMap(); beanDescriptorManager.scheduleBackgroundTrim(); this.dataTimeZone = initDataTimeZone(); this.binder = getBinder(typeManager, databasePlatform, dataTimeZone); - this.cQueryEngine = new CQueryEngine(config, databasePlatform, binder, asOfTableMapping, draftTableMap); + this.cQueryEngine = new CQueryEngine(config, databasePlatform, binder, asOfTableMapping); } public boolean isJacksonCorePresent() { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/PersistRequestBean.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/PersistRequestBean.java index 32da95dab1..b622b679ca 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/PersistRequestBean.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/PersistRequestBean.java @@ -44,7 +44,6 @@ public final class PersistRequestBean extends PersistRequest implements BeanP */ private final Object parentBean; private final boolean dirty; - private final boolean publish; private int flags; private boolean saveRecurse; private DocStoreMode docStoreMode; @@ -153,10 +152,6 @@ public PersistRequestBean(SpiEbeanServer server, T bean, Object parentBean, Bean } } this.concurrencyMode = beanDescriptor.concurrencyMode(intercept); - this.publish = Flags.isPublish(flags); - if (isMarkDraftDirty(publish)) { - beanDescriptor.setDraftDirty(entityBean, true); - } this.dirty = intercept.isDirty(); } @@ -201,13 +196,6 @@ public boolean isCascade() { return Flags.isRecurse(flags); } - /** - * Return true if the draftDirty property should be set to true for this request. - */ - private boolean isMarkDraftDirty(boolean publish) { - return !publish && type != Type.DELETE && beanDescriptor.isDraftable(); - } - /** * Set the transaction from prior persist request. * Only used when hard deleting draft & associated live beans. @@ -417,7 +405,7 @@ public Map updatedValues() { * Set the cache notify status. */ private void setNotifyCache() { - this.notifyCache = beanDescriptor.isCacheNotify(type, publish); + this.notifyCache = beanDescriptor.isCacheNotify(type); } /** @@ -642,28 +630,6 @@ public T createReference() { return beanDescriptor.createRef(beanId(), null); } - /** - * Return true if the bean type is a Draftable. - */ - public boolean isDraftable() { - return beanDescriptor.isDraftable(); - } - - /** - * Return true if this request is a hard delete of a draftable bean. - * If this is true Ebean is expected to auto-publish and delete the associated live bean. - */ - public boolean isHardDeleteDraft() { - if (type == Type.DELETE && beanDescriptor.isDraftable() && !beanDescriptor.isDraftableElement()) { - // deleting a top level draftable bean - if (beanDescriptor.isLiveInstance(entityBean)) { - throw new PersistenceException("Explicit Delete is not allowed on a 'live' bean - only draft beans"); - } - return true; - } - return false; - } - /** * Return true if this was a hard/permanent delete request (and should cascade as such). */ @@ -671,16 +637,6 @@ public boolean isHardDeleteCascade() { return (type == Type.DELETE && beanDescriptor.isSoftDelete()); } - /** - * Checks for @Draftable entity beans with @Draft property that the bean is a 'draft'. - * Save or Update is not allowed to execute using 'live' beans - must use publish(). - */ - public void checkDraft() { - if (beanDescriptor.isDraftable() && beanDescriptor.isLiveInstance(entityBean)) { - throw new PersistenceException("Save or update is not allowed on a 'live' bean - only draft beans"); - } - } - /** * Return the parent bean for cascading save with unidirectional relationship. */ @@ -928,20 +884,19 @@ private void controllerPost() { } private void logSummaryMessage() { - String draft = (beanDescriptor.isDraftable() && !publish) ? " draft[true]" : ""; String name = beanDescriptor.name(); switch (type) { case INSERT: - transaction.logSummary("Inserted [{0}] [{1}]{2}", name, (idValue == null ? "" : idValue), draft); + transaction.logSummary("Inserted [{0}] [{1}]", name, (idValue == null ? "" : idValue)); break; case UPDATE: - transaction.logSummary("Updated [{0}] [{1}]{2}", name, idValue , draft); + transaction.logSummary("Updated [{0}] [{1}]", name, idValue); break; case DELETE: - transaction.logSummary("Deleted [{0}] [{1}]{2}", name, idValue , draft); + transaction.logSummary("Deleted [{0}] [{1}]", name, idValue); break; case DELETE_SOFT: - transaction.logSummary("SoftDelete [{0}] [{1}]{2}", name, idValue , draft); + transaction.logSummary("SoftDelete [{0}] [{1}]", name, idValue); break; default: break; @@ -979,9 +934,6 @@ public void deferredRelationship(EntityBean assocBean, ImportedId importedId, En private void postInsert() { // mark all properties as loaded after an insert to support immediate update beanDescriptor.setAllLoaded(entityBean); - if (!publish) { - beanDescriptor.setDraft(entityBean); - } if (transaction.isAutoPersistUpdates() && idValue != null) { // with getGeneratedKeys off we will not have a idValue beanDescriptor.contextPut(transaction.persistenceContext(), idValue, entityBean); @@ -1129,13 +1081,6 @@ public int flags() { return flags; } - /** - * Return true if this request is a 'publish' action. - */ - public boolean isPublish() { - return publish; - } - /** * Return the key for an update persist request. */ @@ -1152,17 +1097,14 @@ public String updatePlanHash() { key.append('v'); } } - if (publish) { - key.append('p'); - } return key.toString(); } /** - * Return the table to update depending if the request is a 'publish' one or normal. + * Return the table to update. */ public String updateTable() { - return publish ? beanDescriptor.baseTable() : beanDescriptor.draftTable(); + return beanDescriptor.baseTable(); } /** @@ -1374,7 +1316,7 @@ public EntityBean importedOrphanForRemoval() { * Return the SQL used to fetch the last inserted id value. */ public String selectLastInsertedId() { - return beanDescriptor.selectLastInsertedId(publish); + return beanDescriptor.selectLastInsertedId(); } /** diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/Persister.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/Persister.java index 46927f1122..24ffc24166 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/Persister.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/Persister.java @@ -83,16 +83,6 @@ public interface Persister { */ int executeCallable(CallableSql callable, Transaction t); - /** - * Publish the draft beans matching the given query. - */ - List publish(Query query, Transaction transaction); - - /** - * Restore the draft beans back to the matching live beans. - */ - List draftRestore(Query query, Transaction transaction); - /** * Visit the metrics. */ 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 5b56011d49..ade52548eb 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 @@ -42,7 +42,6 @@ import io.ebeaninternal.server.querydefn.DefaultOrmQuery; import io.ebeaninternal.server.querydefn.OrmQueryDetail; import io.ebeaninternal.server.querydefn.OrmQueryProperties; -import io.ebeaninternal.server.rawsql.SpiRawSql; import io.ebeaninternal.util.SortByClause; import io.ebeaninternal.util.SortByClauseParser; import io.ebeanservice.docstore.api.DocStoreBeanAdapter; @@ -103,7 +102,6 @@ public enum EntityType { * getGeneratedKeys is not supported. */ private final String selectLastInsertedId; - private final String selectLastInsertedIdDraft; private final boolean autoTunable; private final ConcurrencyMode concurrencyMode; private final IndexDefinition[] indexDefinitions; @@ -115,17 +113,12 @@ public enum EntityType { private final TableJoin primaryKeyJoin; private final BeanProperty softDeleteProperty; private final boolean softDelete; - private final String draftTable; private final PartitionMeta partitionMeta; private final TablespaceMeta tablespaceMeta; private final String storageEngine; private final String dbComment; - private final boolean draftable; - private final boolean draftableElement; private final BeanProperty unmappedJson; private final BeanProperty tenant; - private final BeanProperty draft; - private final BeanProperty draftDirty; private final LinkedHashMap propMap; /** * Map of DB column to property path (for nativeSql mapping). @@ -218,7 +211,6 @@ public enum EntityType { private final String baseTableAlias; private final boolean cacheSharableBeans; private final String docStoreQueueId; - private final BeanDescriptorDraftHelp draftHelp; private final BeanDescriptorCacheHelp cacheHelp; private final BeanDescriptorJsonHelp jsonHelp; private DocStoreBeanAdapter docStoreAdapter; @@ -253,13 +245,9 @@ public BeanDescriptor(BeanDescriptorMap owner, DeployBeanDescriptor deploy) { this.idGeneratedValue = deploy.isIdGeneratedValue(); this.idGenerator = deploy.getIdGenerator(); this.selectLastInsertedId = deploy.getSelectLastInsertedId(); - this.selectLastInsertedIdDraft = deploy.getSelectLastInsertedIdDraft(); this.concurrencyMode = deploy.getConcurrencyMode(); this.indexDefinitions = deploy.getIndexDefinitions(); - this.draftable = deploy.isDraftable(); - this.draftableElement = deploy.isDraftableElement(); this.historySupport = deploy.isHistorySupport(); - this.draftTable = deploy.getDraftTable(); this.baseTable = InternString.intern(deploy.getBaseTable()); this.baseTableAsOf = deploy.getBaseTableAsOf(); this.primaryKeyJoin = deploy.getPrimaryKeyJoin(); @@ -281,8 +269,6 @@ public BeanDescriptor(BeanDescriptorMap owner, DeployBeanDescriptor deploy) { this.versionProperty = listHelper.getVersionProperty(); this.unmappedJson = listHelper.getUnmappedJson(); this.tenant = listHelper.getTenant(); - this.draft = listHelper.getDraft(); - this.draftDirty = listHelper.getDraftDirty(); this.propMap = listHelper.getPropertyMap(); this.propertiesTransient = listHelper.getTransients(); this.propertiesNonTransient = listHelper.getNonTransients(); @@ -311,7 +297,6 @@ public BeanDescriptor(BeanDescriptorMap owner, DeployBeanDescriptor deploy) { this.cacheSharableBeans = noRelationships && deploy.getCacheOptions().isReadOnly(); this.cacheHelp = new BeanDescriptorCacheHelp<>(this, owner.cacheManager(), deploy.getCacheOptions(), cacheSharableBeans, propertiesOneImported); this.jsonHelp = initJsonHelp(); - this.draftHelp = new BeanDescriptorDraftHelp<>(this); this.docStoreAdapter = owner.createDocStoreBeanAdapter(this, deploy); this.docStoreQueueId = docStoreAdapter.queueId(); // Check if there are no cascade save associated beans ( subject to change @@ -473,9 +458,6 @@ public BeanProperty propertyByIndex(int pos) { * as they are used to get the imported and exported properties. */ void initialiseId(BeanDescriptorInitContext initContext) { - if (draftable) { - initContext.addDraft(baseTable, draftTable); - } if (historySupport) { // add mapping (used to swap out baseTable for asOf queries) initContext.addHistory(baseTable, baseTableAsOf); @@ -494,10 +476,6 @@ void initialiseId(BeanDescriptorInitContext initContext) { * Initialise the exported and imported parts for associated properties. */ public void initialiseOther(BeanDescriptorInitContext initContext) { - for (BeanPropertyAssocMany many : propertiesManyToMany) { - // register associated draft table for M2M intersection - many.registerDraftIntersectionTable(initContext); - } if (historySupport) { // history support on this bean so check all associated intersection tables // and if they are not excluded register the associated 'with history' table @@ -1044,24 +1022,6 @@ public void docStoreDeleteById(Object idValue, DocStoreUpdateContext txn) throws docStoreAdapter.deleteById(idValue, txn); } - public T publish(T draftBean, T liveBean) { - return draftHelp.publish(draftBean, liveBean); - } - - /** - * Reset properties on the draft bean based on @DraftDirty and @DraftReset. - */ - public boolean draftReset(T draftBean) { - return draftHelp.draftReset(draftBean); - } - - /** - * Return the draft dirty boolean property or null if there is not one assigned to this bean type. - */ - BeanProperty draftDirty() { - return draftDirty; - } - /** * Prepare the query for multi-tenancy check for document store only use. */ @@ -1114,11 +1074,7 @@ public boolean isManyPropCaching() { /** * Return true if the persist request needs to notify the cache. */ - public boolean isCacheNotify(PersistRequest.Type type, boolean publish) { - if (draftable && !publish) { - // no caching when editing draft beans - return false; - } + public boolean isCacheNotify(PersistRequest.Type type) { return cacheHelp.isCacheNotify(type); } @@ -2622,8 +2578,6 @@ public boolean isBaseTable() { @Override public String baseTable(SpiQuery.TemporalMode mode) { switch (mode) { - case DRAFT: - return draftTable; case VERSIONS: return baseTableVersionsBetween; case AS_OF: @@ -2633,13 +2587,6 @@ public String baseTable(SpiQuery.TemporalMode mode) { } } - /** - * Return the associated draft table. - */ - public String draftTable() { - return draftTable; - } - @Override public boolean isSoftDelete() { return softDelete; @@ -2671,20 +2618,6 @@ public void markAsDeleted(EntityBean bean) { } } - /** - * Return true if this entity type is draftable. - */ - public boolean isDraftable() { - return draftable; - } - - /** - * Return true if this entity type is a draftable element (child). - */ - public boolean isDraftableElement() { - return draftableElement; - } - @Override public Map pathMap(String prefix) { return pathMaps.computeIfAbsent(prefix, s -> { @@ -2750,28 +2683,6 @@ public void setTenantId(EntityBean entityBean, Object tenantId) { } } - /** - * Set the draft to true for this entity bean instance. - * This bean is being loaded via asDraft() query. - */ - @Override - public void setDraft(EntityBean entityBean) { - if (draft != null) { - draft.setValue(entityBean, true); - } - } - - /** - * Return true if the bean is considered a 'draft' instance (not 'live'). - */ - public boolean isDraftInstance(EntityBean entityBean) { - if (draft != null) { - return Boolean.TRUE == draft.getValue(entityBean); - } - // no draft property - so return false - return false; - } - @Override public boolean isToManyDirty(EntityBean bean) { final EntityBeanIntercept ebi = bean._ebean_getIntercept(); @@ -2786,39 +2697,6 @@ public boolean isToManyDirty(EntityBean bean) { return false; } - /** - * Return true if the bean is draftable and considered a 'live' instance. - */ - public boolean isLiveInstance(EntityBean entityBean) { - if (draft != null) { - return Boolean.FALSE == draft.getValue(entityBean); - } - // no draft property - so return false - return false; - } - - /** - * If there is a @DraftDirty property set it's value on the bean. - */ - public void setDraftDirty(EntityBean entityBean, boolean value) { - if (draftDirty != null) { - // check to see if the dirty property has already - // been set and if so do not set the value - if (!entityBean._ebean_getIntercept().isChangedProperty(draftDirty.propertyIndex())) { - draftDirty.setValueIntercept(entityBean, value); - } - } - } - - /** - * Optimise the draft query fetching any draftable element relationships. - */ - public void draftQueryOptimise(Query query) { - // use per query PersistenceContext to ensure fresh beans loaded - query.setPersistenceContextScope(PersistenceContextScope.QUERY); - draftHelp.draftQueryOptimise(query); - } - /** * Return true if this entity bean has history support. */ @@ -2864,8 +2742,8 @@ public IdentityMode identityMode() { * This is only used with Identity columns and getGeneratedKeys is not * supported. */ - public String selectLastInsertedId(boolean publish) { - return publish ? selectLastInsertedId : selectLastInsertedIdDraft; + public String selectLastInsertedId() { + return selectLastInsertedId; } /** diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorDraftHelp.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorDraftHelp.java deleted file mode 100644 index f11a921c73..0000000000 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorDraftHelp.java +++ /dev/null @@ -1,99 +0,0 @@ -package io.ebeaninternal.server.deploy; - -import io.ebean.Query; -import io.ebean.bean.EntityBean; - -import java.util.ArrayList; -import java.util.List; - -/** - * Helper for BeanDescriptor that manages draft entity beans. - * - * @param The entity bean type - */ -final class BeanDescriptorDraftHelp { - - private final BeanDescriptor desc; - private final BeanProperty draftDirty; - private final BeanProperty[] resetProperties; - - BeanDescriptorDraftHelp(BeanDescriptor desc) { - this.desc = desc; - this.draftDirty = desc.draftDirty(); - this.resetProperties = resetProperties(); - } - - /** - * Return the properties that are reset on draft beans after publish. - */ - private BeanProperty[] resetProperties() { - List list = new ArrayList<>(); - for (BeanProperty prop : desc.propertiesNonMany()) { - if (prop.isDraftReset()) { - list.add(prop); - } - } - return list.toArray(new BeanProperty[0]); - } - - /** - * Set the value of all the 'reset properties' to null on the draft bean. - */ - boolean draftReset(T draftBean) { - EntityBean draftEntityBean = (EntityBean) draftBean; - if (draftDirty != null) { - // set @DraftDirty property to false - draftDirty.setValueIntercept(draftEntityBean, false); - } - // set to null on all @DraftReset properties - for (BeanProperty resetProperty : resetProperties) { - resetProperty.setValueIntercept(draftEntityBean, null); - } - // return true if the bean is dirty (and should be persisted) - return draftEntityBean._ebean_getIntercept().isDirty(); - } - - /** - * Transfer the values from the draftBean to the liveBean. - *

- * This will recursive transfer values to all @DraftableElement properties. - *

- */ - @SuppressWarnings("unchecked") - public T publish(T draftBean, T liveBean) { - if (liveBean == null) { - liveBean = (T) desc.createEntityBean(); - } - EntityBean draft = (EntityBean) draftBean; - EntityBean live = (EntityBean) liveBean; - BeanProperty idProperty = desc.idProperty(); - if (idProperty != null) { - idProperty.publish(draft, live); - } - for (BeanProperty prop : desc.propertiesNonMany()) { - prop.publish(draft, live); - } - for (BeanPropertyAssocMany many : desc.propertiesMany()) { - if (many.targetDescriptor().isDraftable()) { - many.publishMany(draft, live); - } - } - return liveBean; - } - - /** - * Fetch draftable element relationships. - */ - void draftQueryOptimise(Query query) { - for (BeanPropertyAssocOne anOne : desc.propertiesOne()) { - if (anOne.targetDescriptor().isDraftableElement()) { - query.fetch(anOne.name()); - } - } - for (BeanPropertyAssocMany aMany : desc.propertiesMany()) { - if (aMany.targetDescriptor().isDraftableElement()) { - query.fetch(aMany.name()); - } - } - } -} diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorInitContext.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorInitContext.java index 9ce8615696..c8484470b6 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorInitContext.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorInitContext.java @@ -5,20 +5,14 @@ class BeanDescriptorInitContext { private final Map withHistoryTables; - private final Map draftTables; private final String asOfViewSuffix; private String embeddedPrefix; - BeanDescriptorInitContext(Map withHistoryTables, Map draftTables, String asOfViewSuffix) { + BeanDescriptorInitContext(Map withHistoryTables, String asOfViewSuffix) { this.withHistoryTables = withHistoryTables; - this.draftTables = draftTables; this.asOfViewSuffix = asOfViewSuffix; } - void addDraft(String baseTable, String draftTable) { - draftTables.put(baseTable, draftTable); - } - void addHistory(String baseTable, String baseTableAsOf) { withHistoryTables.put(baseTable, baseTableAsOf); } @@ -27,10 +21,6 @@ void addHistoryIntersection(String intersectionTableName) { withHistoryTables.put(intersectionTableName, intersectionTableName + asOfViewSuffix); } - void addDraftIntersection(String intersectionPublishTable, String intersectionDraftTable) { - draftTables.put(intersectionPublishTable, intersectionDraftTable); - } - public void setEmbeddedPrefix(String embeddedPrefix) { this.embeddedPrefix = embeddedPrefix; } 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 2173a8d26b..e647aee934 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 @@ -106,10 +106,6 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy * Map of base tables to 'with history views' used to support 'as of' queries. */ private final Map asOfTableMap = new HashMap<>(); - /** - * Map of base tables to 'draft' tables. - */ - private final Map draftTableMap = new HashMap<>(); // temporary collections used during startup and then cleared private Map, DeployBeanInfo> deployInfoMap = new HashMap<>(); @@ -269,13 +265,6 @@ public IdBinder createIdBinder(BeanProperty idProperty) { return idBinderFactory.createIdBinder(idProperty); } - /** - * Return the map of base tables to draft tables. - */ - public Map draftTableMap() { - return draftTableMap; - } - /** * Deploy returning the asOfTableMap (which is required by the SQL builders). */ @@ -417,7 +406,7 @@ private void initialiseAll() { // now that all the BeanDescriptors are in their map // we can initialise them which sorts out circular // dependencies for OneToMany and ManyToOne etc - BeanDescriptorInitContext initContext = new BeanDescriptorInitContext(asOfTableMap, draftTableMap, asOfViewSuffix); + BeanDescriptorInitContext initContext = new BeanDescriptorInitContext(asOfTableMap, asOfViewSuffix); // PASS 1: // initialise the ID properties of all the beans @@ -959,13 +948,6 @@ private void checkMappedByOneToMany(DeployBeanInfo info, DeployBeanPropertyAs // skip mapping check return; } - DeployBeanDescriptor targetDesc = targetDescriptor(prop); - if (targetDesc.isDraftableElement()) { - // automatically turning on orphan removal and CascadeType.ALL - prop.setModifyListenMode(BeanCollection.ModifyListenMode.REMOVALS); - prop.getCascadeInfo().setSaveDelete(true, true); - } - if (prop.hasOrderColumn()) { makeOrderColumn(prop); } @@ -991,6 +973,7 @@ private void checkMappedByOneToMany(DeployBeanInfo info, DeployBeanPropertyAs String mappedBy = prop.getMappedBy(); // get the mappedBy property + DeployBeanDescriptor targetDesc = targetDescriptor(prop); DeployBeanPropertyAssocOne mappedAssocOne = mappedManyToOne(prop, targetDesc, mappedBy); DeployTableJoin tableJoin = prop.getTableJoin(); if (!tableJoin.hasJoinColumns()) { @@ -1032,9 +1015,6 @@ private void checkMappedByManyToMany(DeployBeanPropertyAssocMany prop) { // get the bean descriptor that holds the mappedBy property String mappedBy = prop.getMappedBy(); if (mappedBy == null) { - if (targetDescriptor(prop).isDraftable()) { - prop.setIntersectionDraftTable(); - } return; } @@ -1059,10 +1039,6 @@ private void checkMappedByManyToMany(DeployBeanPropertyAssocMany prop) { DeployTableJoin inverseJoin = new DeployTableJoin(); mappedIntJoin.copyTo(inverseJoin, false, intTableName); prop.setInverseJoin(inverseJoin); - - if (targetDesc.isDraftable()) { - prop.setIntersectionDraftTable(); - } } private DeployBeanPropertyAssocMany mappedManyToMany(DeployBeanPropertyAssocMany prop, String mappedBy, DeployBeanDescriptor targetDesc) { @@ -1179,8 +1155,7 @@ private void setIdGeneration(DeployBeanDescriptor desc) { if (identityMode.isIdentity()) { // used when getGeneratedKeys is not supported (SQL Server 2000, SAP Hana) String selectLastInsertedId = dbIdentity.getSelectLastInsertedId(desc.getBaseTable()); - String selectLastInsertedIdDraft = (!desc.isDraftable()) ? selectLastInsertedId : dbIdentity.getSelectLastInsertedId(desc.getDraftTable()); - desc.setSelectLastInsertedId(selectLastInsertedId, selectLastInsertedIdDraft); + desc.setSelectLastInsertedId(selectLastInsertedId); return; } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java index a439e73794..2d1e74edff 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java @@ -171,10 +171,6 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty { final boolean jsonDeserialize; private final boolean unmappedJson; private final boolean tenantId; - private final boolean draft; - private final boolean draftOnly; - private final boolean draftDirty; - private final boolean draftReset; private final boolean softDelete; private final String softDeleteDbSet; private final String softDeleteDbPredicate; @@ -201,10 +197,6 @@ public BeanProperty(BeanDescriptor descriptor, DeployBeanProperty deploy) { this.excludedFromHistory = deploy.isExcludedFromHistory(); this.unmappedJson = deploy.isUnmappedJson(); this.tenantId = deploy.isTenantId(); - this.draft = deploy.isDraft(); - this.draftDirty = deploy.isDraftDirty(); - this.draftOnly = deploy.isDraftOnly(); - this.draftReset = deploy.isDraftReset(); this.secondaryTable = deploy.isSecondaryTable(); if (secondaryTable) { this.secondaryTableJoin = new TableJoin(deploy.getSecondaryTableJoin()); @@ -296,10 +288,6 @@ protected BeanProperty(BeanProperty source, BeanPropertyOverride override) { this.aggregation = null; this.excludedFromHistory = source.excludedFromHistory; this.tenantId = source.tenantId; - this.draft = source.draft; - this.draftDirty = source.draftDirty; - this.draftOnly = source.draftOnly; - this.draftReset = source.draftReset; this.softDelete = source.softDelete; this.softDeleteDbSet = source.softDeleteDbSet; this.softDeleteDbPredicate = source.softDeleteDbPredicate; @@ -483,7 +471,7 @@ public void appendSelect(DbSqlContext ctx, boolean subQuery) { ctx.appendFormulaSelect(aggregation); } else if (formula) { ctx.appendFormulaSelect(sqlFormulaSelect); - } else if (!isTransient && !ignoreDraftOnlyProperty(ctx.isDraftQuery())) { + } else if (!isTransient) { if (secondaryTableJoin != null) { ctx.pushTableAlias(ctx.relativePrefix(secondaryTableJoinPrefix)); } @@ -590,17 +578,6 @@ public boolean isLocal() { return local; } - /** - * Copy/set the property value from the draft bean to the live bean. - */ - public void publish(EntityBean draftBean, EntityBean liveBean) { - if (!version && !draftOnly) { - // set property value from draft to live - Object value = getValueIntercept(draftBean); - setValueIntercept(liveBean, value); - } - } - /** * Return the DB literal expression to set the deleted state to true. */ @@ -1090,16 +1067,8 @@ public boolean isTransient() { /** * Return true if this property is loadable from a resultSet. */ - public boolean isLoadProperty(boolean draftQuery) { - return !ignoreDraftOnlyProperty(draftQuery) && (!isTransient || formula); - } - - /** - * Return true if this is a draftOnly property on a non-asDraft query and as such this - * property should not be included in a sql query. - */ - private boolean ignoreDraftOnlyProperty(boolean draftQuery) { - return draftOnly && !draftQuery; + public boolean isLoadProperty() { + return !isTransient || formula; } /** @@ -1248,36 +1217,6 @@ public boolean isTenantId() { return tenantId; } - /** - * Return true if this property only exists on the draft table. - */ - public boolean isDraftOnly() { - return draftOnly; - } - - /** - * Return true if this property is a boolean flag on a draftable bean - * indicating if the instance is a draft or live bean. - */ - public boolean isDraft() { - return draft; - } - - /** - * Return true if this property is a boolean flag only on the draft table - * indicating that when the draft is different from the published row. - */ - public boolean isDraftDirty() { - return draftDirty; - } - - /** - * Return true if this property is reset/cleared on publish (on the draft bean). - */ - boolean isDraftReset() { - return draftReset; - } - /** * Return true if this property is the soft delete property. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java index c9899888c5..f349ea253f 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java @@ -41,8 +41,6 @@ public class BeanPropertyAssocMany extends BeanPropertyAssoc implements ST * Join for manyToMany intersection table. */ private final TableJoin intersectionJoin; - private final String intersectionPublishTable; - private final String intersectionDraftTable; private final boolean orphanRemoval; private IntersectionTable intersectionTable; /** @@ -102,13 +100,6 @@ public BeanPropertyAssocMany(BeanDescriptor descriptor, DeployBeanPropertyAss this.mapKey = deploy.getMapKey(); this.fetchOrderBy = deploy.getFetchOrderBy(); this.intersectionJoin = deploy.createIntersectionTableJoin(); - if (intersectionJoin != null) { - this.intersectionPublishTable = intersectionJoin.getTable(); - this.intersectionDraftTable = deploy.getIntersectionDraftTable(); - } else { - this.intersectionPublishTable = null; - this.intersectionDraftTable = null; - } this.inverseJoin = deploy.createInverseTableJoin(); this.modifyListenMode = deploy.getModifyListenMode(); this.jsonHelp = descriptor.isJacksonCorePresent() ? new BeanPropertyAssocManyJsonHelp(this) : null; @@ -375,7 +366,7 @@ public void setEbeanServer(SpiEbeanServer server) { } private IntersectionTable initIntersectionTable() { - IntersectionBuilder row = new IntersectionBuilder(intersectionPublishTable, intersectionDraftTable); + IntersectionBuilder row = new IntersectionBuilder(intersectionJoin.getTable()); for (ExportedProperty exportedProperty : exportedProperties) { row.addColumn(exportedProperty.getForeignDbColumn()); } @@ -434,7 +425,7 @@ public String assocIsEmpty(SpiExpressionRequest request, String path) { StringBuilder sb = new StringBuilder(50).append("from "); // use from to stop parsing on table name SpiQuery query = request.queryRequest().query(); if (hasJoinTable()) { - sb.append(query.isAsDraft() ? intersectionDraftTable : intersectionPublishTable); + sb.append(intersectionJoin.getTable()); } else { sb.append(targetDescriptor.baseTable(query.temporalMode())); } @@ -764,37 +755,21 @@ public IntersectionRow buildManyDeleteChildren(EntityBean parentBean, Set draftVal = (BeanCollection) getValueIntercept(draft); - BeanCollection liveVal = (BeanCollection) getValueIntercept(live); - - // Organise the existing live beans into map keyed by id - Map liveBeansAsMap = liveBeansAsMap(liveVal); - - // publish from each draft to live bean creating new live beans as required - draftVal.size(); - Collection actualDetails = draftVal.actualDetails(); - for (T bean : actualDetails) { - Object id = targetDescriptor.id(bean); - T liveBean = liveBeansAsMap.remove(id); - - if (isManyToMany()) { - if (liveBean == null) { - // add new relationship (Map not allowed here) - liveVal.addBean(targetDescriptor.createReference(id, null)); - } - } else { - // recursively publish the OneToMany child bean - T newLive = targetDescriptor.publish(bean, liveBean); - if (liveBean == null) { - // Map not allowed here - liveVal.addBean(newLive); - } - } - } - // anything remaining should be deleted (so remove from modify aware collection) - Collection values = liveBeansAsMap.values(); - for (T value : values) { - liveVal.removeBean(value); - } - } - - @SuppressWarnings("unchecked") - private Map liveBeansAsMap(BeanCollection liveVal) { - liveVal.size(); - Collection liveBeans = liveVal.actualDetails(); - Map liveMap = new LinkedHashMap<>(); - for (Object liveBean : liveBeans) { - Object id = targetDescriptor.id(liveBean); - liveMap.put(id, (T) liveBean); - } - return liveMap; - } - public boolean isIncludeCascadeSave() { // Note ManyToMany always included as we always 'save' // the relationship via insert/delete of intersection table diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbReadContext.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbReadContext.java index 434f52ba47..e244d109f2 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbReadContext.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbReadContext.java @@ -79,11 +79,6 @@ public interface DbReadContext { */ SpiQuery.Mode queryMode(); - /** - * Return true if the underlying query is a 'asDraft' query. - */ - boolean isDraftQuery(); - /** * Return true if this request disables lazy loading. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbSqlContext.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbSqlContext.java index be515b634a..03c8623eb0 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbSqlContext.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbSqlContext.java @@ -124,11 +124,6 @@ public interface DbSqlContext { */ int asOfTableCount(); - /** - * Return true if the query is a 'asDraft' query. - */ - boolean isDraftQuery(); - /** * Start group by clause. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/IntersectionBuilder.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/IntersectionBuilder.java index e2ceec06e6..fa91c9fb5b 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/IntersectionBuilder.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/IntersectionBuilder.java @@ -8,13 +8,11 @@ */ public final class IntersectionBuilder { - private final String publishTable; - private final String draftTable; + private final String table; private final List columns = new ArrayList<>(); - IntersectionBuilder(String publishTable, String draftTable) { - this.publishTable = publishTable; - this.draftTable = draftTable; + IntersectionBuilder(String table) { + this.table = table; } public void addColumn(String column) { @@ -22,18 +20,9 @@ public void addColumn(String column) { } public IntersectionTable build() { - String insertSql = insertSql(publishTable); - String deleteSql = deleteSql(publishTable); - String draftInsertSql; - String draftDeleteSql; - if (publishTable.equals(draftTable)) { - draftInsertSql = insertSql; - draftDeleteSql = deleteSql; - } else { - draftInsertSql = insertSql(draftTable); - draftDeleteSql = deleteSql(draftTable); - } - return new IntersectionTable(insertSql, deleteSql, draftInsertSql, draftDeleteSql); + String insertSql = insertSql(table); + String deleteSql = deleteSql(table); + return new IntersectionTable(insertSql, deleteSql); } private String insertSql(String tableName) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/IntersectionTable.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/IntersectionTable.java index 1a3553ed48..efa8b9f559 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/IntersectionTable.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/IntersectionTable.java @@ -7,28 +7,24 @@ public final class IntersectionTable { private final String insertSql; private final String deleteSql; - private final String draftInsertSql; - private final String draftDeleteSql; - IntersectionTable(String insertSql, String deleteSql, String draftInsertSql, String draftDeleteSql) { + IntersectionTable(String insertSql, String deleteSql) { this.insertSql = insertSql; this.deleteSql = deleteSql; - this.draftInsertSql = draftInsertSql; - this.draftDeleteSql = draftDeleteSql; } /** * Return a SqlUpdate for inserting into the intersection table. */ - public SqlUpdate insert(Database server, boolean draft) { - return server.sqlUpdate(draft ? draftInsertSql : insertSql); + public SqlUpdate insert(Database server) { + return server.sqlUpdate(insertSql); } /** * Return a SqlUpdate for deleting from the intersection table. */ - public SqlUpdate delete(Database server, boolean draft) { - return server.sqlUpdate(draft ? draftDeleteSql : deleteSql); + public SqlUpdate delete(Database server) { + return server.sqlUpdate(deleteSql); } } 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 1e0e537831..45361f9e94 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 @@ -63,7 +63,6 @@ public int compare(DeployBeanProperty o1, DeployBeanProperty o2) { * Used with Identity columns but no getGeneratedKeys support. */ private String selectLastInsertedId; - private String selectLastInsertedIdDraft; /** * The concurrency mode for beans of this type. */ @@ -76,11 +75,8 @@ public int compare(DeployBeanProperty o1, DeployBeanProperty o2) { private String baseTable; private String baseTableAsOf; private String baseTableVersionsBetween; - private String draftTable; private String[] dependentTables; private boolean historySupport; - private boolean draftable; - private boolean draftableElement; private TableName baseTableFull; private String[] properties; /** @@ -217,23 +213,6 @@ public TablespaceMeta getTablespaceMeta() { return tablespaceMeta; } - public void setDraftable() { - draftable = true; - } - - public boolean isDraftable() { - return draftable; - } - - public void setDraftableElement() { - draftable = true; - draftableElement = true; - } - - public boolean isDraftableElement() { - return draftableElement; - } - /** * Read the top level doc store deployment information. */ @@ -560,10 +539,6 @@ public void addPostConstructListener(BeanPostConstructListener postConstructList postConstructListeners.add(postConstructListener); } - public String getDraftTable() { - return draftTable; - } - /** * For view based entity return the dependant tables. */ @@ -617,7 +592,6 @@ public void setBaseTable(TableName baseTableFull, String asOfSuffix, String vers this.baseTable = baseTableFull == null ? null : baseTableFull.getQualifiedName(); this.baseTableAsOf = baseTable + asOfSuffix; this.baseTableVersionsBetween = baseTable + versionsBetweenSuffix; - this.draftTable = (draftable) ? baseTable + "_draft" : baseTable; } public void sortProperties() { @@ -691,16 +665,11 @@ public String getSelectLastInsertedId() { return selectLastInsertedId; } - public String getSelectLastInsertedIdDraft() { - return selectLastInsertedIdDraft; - } - /** * Set the SQL used to return the last inserted Id. */ - public void setSelectLastInsertedId(String selectLastInsertedId, String selectLastInsertedIdDraft) { + public void setSelectLastInsertedId(String selectLastInsertedId) { this.selectLastInsertedId = selectLastInsertedId; - this.selectLastInsertedIdDraft = selectLastInsertedIdDraft; } /** diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanProperty.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanProperty.java index 4f927043c5..9f517a7984 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanProperty.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanProperty.java @@ -159,10 +159,6 @@ public class DeployBeanProperty { private int sortOrder; private boolean excludedFromHistory; private boolean tenantId; - private boolean draft; - private boolean draftOnly; - private boolean draftDirty; - private boolean draftReset; private boolean softDelete; private boolean unmappedJson; private String dbComment; @@ -901,41 +897,6 @@ public void setExcludedFromHistory() { this.excludedFromHistory = true; } - public void setDraft() { - this.draft = true; - this.isTransient = true; - } - - public boolean isDraft() { - return draft; - } - - public void setDraftOnly() { - this.draftOnly = true; - } - - public boolean isDraftOnly() { - return draftOnly; - } - - public void setDraftDirty() { - this.draftOnly = true; - this.draftDirty = true; - this.nullable = false; - } - - public boolean isDraftDirty() { - return draftDirty; - } - - public void setDraftReset() { - this.draftReset = true; - } - - public boolean isDraftReset() { - return draftReset; - } - /** * Primitive boolean check so see if not null default false should be applied. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanPropertyAssocMany.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanPropertyAssocMany.java index c201308e2d..3adc0ece2f 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanPropertyAssocMany.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanPropertyAssocMany.java @@ -38,7 +38,6 @@ public class DeployBeanPropertyAssocMany extends DeployBeanPropertyAssoc { private DeployTableJoin inverseJoin; private String fetchOrderBy; private String mapKey; - private String intersectionDraftTable; private DeployOrderColumn orderColumn; /** * Effectively the dynamically created target descriptor (that doesn't have a mapped type/class per say). @@ -191,20 +190,6 @@ public void setFetchOrderBy(String orderBy) { } } - /** - * Return a draft table for intersection between 2 @Draftable entities. - */ - public String getIntersectionDraftTable() { - return (intersectionDraftTable != null) ? intersectionDraftTable : intersectionJoin.getTable(); - } - - /** - * ManyToMany between 2 @Draftable entities to also need draft intersection table. - */ - public void setIntersectionDraftTable() { - this.intersectionDraftTable = intersectionJoin.getTable() + "_draft"; - } - public void setOrderColumn(DeployOrderColumn orderColumn) { this.orderColumn = orderColumn; } 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 e33dd310cd..2f21c6788c 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 @@ -22,8 +22,6 @@ public final class DeployBeanPropertyLists { private BeanProperty versionProperty; private BeanProperty unmappedJson; - private BeanProperty draft; - private BeanProperty draftDirty; private BeanProperty tenant; private final BeanDescriptor desc; private final LinkedHashMap propertyMap; @@ -173,9 +171,6 @@ public BeanProperty getOrderColumn() { private void allocateToList(BeanProperty prop) { if (prop.isTransient()) { transients.add(prop); - if (prop.isDraft()) { - draft = prop; - } if (prop.isUnmappedJson()) { unmappedJson = prop; } @@ -226,8 +221,6 @@ private void allocateToList(BeanProperty prop) { } else { CoreLog.internal.log(WARNING, "Multiple @Version properties - property " + prop.fullName() + " not treated as a version property"); } - } else if (prop.isDraftDirty()) { - draftDirty = prop; } if (!prop.isAggregation()) { baseScalar.add(prop); @@ -324,18 +317,10 @@ public BeanPropertyAssocMany[] getManyToMany() { return getMany2Many(); } - public BeanProperty getDraftDirty() { - return draftDirty; - } - public BeanProperty getUnmappedJson() { return unmappedJson; } - public BeanProperty getDraft() { - return draft; - } - public BeanProperty getSoftDeleteProperty() { for (BeanProperty prop : nonManys) { if (prop.isSoftDelete()) { 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 488ede75cd..1364f0c89c 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 @@ -156,11 +156,11 @@ private void read(Class cls) { } Draftable draftable = typeGet(cls, Draftable.class); if (draftable != null) { - descriptor.setDraftable(); + //TODO: Not Supported } DraftableElement draftableElement = typeGet(cls, DraftableElement.class); if (draftableElement != null) { - descriptor.setDraftableElement(); + //TODO: Not Supported } ReadAudit readAudit = typeGet(cls, ReadAudit.class); if (readAudit != null) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationFields.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationFields.java index 60ef0ddf7b..d3f9c6a7dc 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationFields.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationFields.java @@ -205,16 +205,7 @@ private void initTenantId(DeployBeanProperty prop) { prop.setTenantId(); } if (has(prop, Draft.class)) { - prop.setDraft(); - } - if (has(prop, DraftOnly.class)) { - prop.setDraftOnly(); - } - if (has(prop, DraftDirty.class)) { - prop.setDraftDirty(); - } - if (has(prop, DraftReset.class)) { - prop.setDraftReset(); + // TODO: Not Supported } if (has(prop, SoftDelete.class)) { prop.setSoftDelete(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/expression/DefaultExpressionList.java b/ebean-core/src/main/java/io/ebeaninternal/server/expression/DefaultExpressionList.java index 5b8c644ab8..9d31c2aafe 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/expression/DefaultExpressionList.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/expression/DefaultExpressionList.java @@ -257,11 +257,6 @@ public Query asOf(Timestamp asOf) { return query.asOf(asOf); } - @Override - public Query asDraft() { - return query.asDraft(); - } - @Override public DtoQuery asDto(Class dtoClass) { return query.asDto(dtoClass); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/expression/JunctionExpression.java b/ebean-core/src/main/java/io/ebeaninternal/server/expression/JunctionExpression.java index f5b3d5ac82..fc88a030ba 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/expression/JunctionExpression.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/expression/JunctionExpression.java @@ -347,11 +347,6 @@ public Query asOf(Timestamp asOf) { return exprList.asOf(asOf); } - @Override - public Query asDraft() { - return exprList.asDraft(); - } - @Override public DtoQuery asDto(Class dtoClass) { return exprList.asDto(dtoClass); 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 39bb42b8ba..a74281a5aa 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 @@ -25,7 +25,6 @@ public final class DLoadContext implements LoadContext { private final Map beanMap = new HashMap<>(); private final Map manyMap = new HashMap<>(); private final DLoadBeanContext rootBeanContext; - private final boolean asDraft; private final Timestamp asOf; private final Boolean readOnly; private final CacheMode useBeanCache; @@ -59,7 +58,6 @@ public DLoadContext(BeanDescriptor rootDescriptor, PersistenceContext persist this.origin = initOrigin(); this.defaultBatchSize = 100; this.useBeanCache = CacheMode.OFF; - this.asDraft = false; this.asOf = null; this.readOnly = false; this.disableLazyLoading = false; @@ -86,7 +84,6 @@ public DLoadContext(OrmQueryRequest request, SpiQuerySecondary secondaryQueri SpiQuery query = request.query(); this.useDocStore = query.isUseDocStore(); this.asOf = query.getAsOf(); - this.asDraft = query.isAsDraft(); this.includeSoftDeletes = query.isIncludeSoftDeletes() && query.mode() == SpiQuery.Mode.NORMAL; this.readOnly = query.isReadOnly(); this.disableLazyLoading = query.isDisableLazyLoading(); @@ -322,9 +319,6 @@ void propagateQueryState(SpiQuery query, boolean docStoreMapped) { } query.setDisableLazyLoading(disableLazyLoading); query.asOf(asOf); - if (asDraft) { - query.asDraft(); - } if (includeSoftDeletes) { query.setIncludeSoftDeletes(); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/DefaultPersister.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/DefaultPersister.java index f2c9805dcd..8254781c19 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/DefaultPersister.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/DefaultPersister.java @@ -143,204 +143,6 @@ public int executeSqlUpdateNow(SpiSqlUpdate updSql, Transaction t) { return executeOrQueue(new PersistRequestUpdateSql(server, updSql, (SpiTransaction) t, persistExecute, true)); } - /** - * Restore draft beans to match live beans given the query. - */ - @Override - public List draftRestore(Query query, Transaction transaction) { - Class beanType = query.getBeanType(); - BeanDescriptor desc = server.descriptor(beanType); - DraftHandler draftHandler = new DraftHandler<>(desc, transaction); - - query.usingTransaction(transaction); - List liveBeans = draftHandler.fetchSourceBeans((SpiQuery) query, false); - PUB.log(DEBUG, "draftRestore [{0}] count[{1}]", desc.name(), liveBeans.size()); - if (liveBeans.isEmpty()) { - return Collections.emptyList(); - } - - draftHandler.fetchDestinationBeans(liveBeans, true); - BeanManager mgr = beanDescriptorManager.beanManager(beanType); - - for (T liveBean : liveBeans) { - T draftBean = draftHandler.publishToDestinationBean(liveBean); - // reset @DraftDirty and @DraftReset properties - draftHandler.resetDraft(draftBean); - - PUB.log(TRACE, "draftRestore bean [{0}] id[{1}]", desc.name(), draftHandler.getId()); - update(createRequest(draftBean, transaction, null, mgr, Type.UPDATE, Flags.RECURSE)); - } - - PUB.log(DEBUG, "draftRestore - complete for [{0}]", desc.name()); - return draftHandler.getDrafts(); - } - - /** - * Helper method to return the list of Id values for the list of beans. - */ - private List getBeanIds(BeanDescriptor desc, List beans) { - List idList = new ArrayList<>(beans.size()); - for (T liveBean : beans) { - idList.add(desc.id(liveBean)); - } - return idList; - } - - /** - * Publish from draft to live given the query. - */ - @Override - public List publish(Query query, Transaction transaction) { - Class beanType = query.getBeanType(); - BeanDescriptor desc = server.descriptor(beanType); - DraftHandler draftHandler = new DraftHandler<>(desc, transaction); - - query.usingTransaction(transaction); - List draftBeans = draftHandler.fetchSourceBeans((SpiQuery) query, true); - PUB.log(DEBUG, "publish [{0}] count[{1}]", desc.name(), draftBeans.size()); - if (draftBeans.isEmpty()) { - return Collections.emptyList(); - } - - draftHandler.fetchDestinationBeans(draftBeans, false); - BeanManager mgr = beanDescriptorManager.beanManager(beanType); - - List livePublish = new ArrayList<>(draftBeans.size()); - for (T draftBean : draftBeans) { - T liveBean = draftHandler.publishToDestinationBean(draftBean); - livePublish.add(liveBean); - - // reset @DraftDirty and @DraftReset properties - draftHandler.resetDraft(draftBean); - - Type persistType = draftHandler.isInsert() ? Type.INSERT : Type.UPDATE; - PUB.log(TRACE, "publish bean [{0}] id[{1}] type[{2}]", desc.name(), draftHandler.getId(), persistType); - - PersistRequestBean request = createRequest(liveBean, transaction, null, mgr, persistType, Flags.PUBLISH_RECURSE); - if (persistType == Type.INSERT) { - insert(request); - } else { - update(request); - } - request.resetDepth(); - } - - draftHandler.updateDrafts(transaction, mgr); - PUB.log(DEBUG, "publish - complete for [{0}]", desc.name()); - return livePublish; - } - - /** - * Helper to handle draft beans (properties reset etc). - */ - class DraftHandler { - - final BeanDescriptor desc; - final Transaction transaction; - final List draftUpdates = new ArrayList<>(); - - /** - * Id value of the last published bean. - */ - Object id; - - /** - * True if the last published bean is new/insert. - */ - boolean insert; - - /** - * The destination beans to publish/restore to mapped by id. - */ - Map destBeans; - - DraftHandler(BeanDescriptor desc, Transaction transaction) { - this.desc = desc; - this.transaction = transaction; - } - - /** - * Return the list of draft beans with changes (to be persisted). - */ - List getDrafts() { - return draftUpdates; - } - - /** - * Set the draft dirty state to false and reset any dirtyReset properties. - */ - void resetDraft(T draftBean) { - if (desc.draftReset(draftBean)) { - // draft bean is dirty so collect it for persisting later - draftUpdates.add(draftBean); - } - } - - /** - * Save all the draft beans (with various properties reset etc). - */ - void updateDrafts(Transaction transaction, BeanManager mgr) { - if (!draftUpdates.isEmpty()) { - // update the dirty status on the drafts that have been published - PUB.log(DEBUG, "publish - update dirty status on [{0}] drafts", draftUpdates.size()); - for (T draftUpdate : draftUpdates) { - update(createRequest(draftUpdate, transaction, null, mgr, Type.UPDATE, Flags.ZERO)); - } - } - } - - /** - * Fetch the source beans based on the query. - */ - List fetchSourceBeans(SpiQuery query, boolean asDraft) { - desc.draftQueryOptimise(query); - if (asDraft) { - query.asDraft(); - } - return server.findList(query); - } - - /** - * Fetch the destination beans that will be published to. - */ - void fetchDestinationBeans(List sourceBeans, boolean asDraft) { - List ids = getBeanIds(desc, sourceBeans); - SpiQuery destQuery = server.createQuery(desc.type()); - destQuery.usingTransaction(transaction); - destQuery.where().idIn(ids); - if (asDraft) { - destQuery.asDraft(); - } - desc.draftQueryOptimise(destQuery); - this.destBeans = server.findMap(destQuery); - } - - /** - * Publish/restore the values from the sourceBean to the matching destination bean. - */ - T publishToDestinationBean(T sourceBean) { - id = desc.id(sourceBean); - T destBean = destBeans.get(id); - insert = (destBean == null); - // apply changes from liveBean to draftBean - return desc.publish(sourceBean, destBean); - } - - /** - * Return true if the last publish resulted in an new bean to insert. - */ - boolean isInsert() { - return insert; - } - - /** - * Return the Id value of the last published/restored bean. - */ - Object getId() { - return id; - } - } - /** * Recursively delete the bean. This calls back to the EbeanServer. */ @@ -380,7 +182,6 @@ public int merge(BeanDescriptor desc, EntityBean bean, MergeOptions options, @Override public void update(EntityBean entityBean, Transaction t) { PersistRequestBean req = createRequest(entityBean, t, PersistRequest.Type.UPDATE); - req.checkDraft(); try { req.initTransIfRequiredWithBatchCascade(); if (req.isReference()) { @@ -526,15 +327,8 @@ private void update(PersistRequestBean request) { public int delete(EntityBean bean, Transaction t, boolean permanent) { Type deleteType = permanent ? Type.DELETE_PERMANENT : Type.DELETE; PersistRequestBean originalRequest = createDeleteRequest(bean, t, deleteType); - if (originalRequest.isHardDeleteDraft()) { - // a hard delete of a draftable bean so first we need to delete the associated 'live' bean - // due to FK constraint and then after that execute the original delete of the draft bean - return deleteRequest(createDeleteRequest(originalRequest.createReference(), t, Type.DELETE_PERMANENT, Flags.PUBLISH), originalRequest); - - } else { - // normal delete or soft delete - return deleteRequest(originalRequest); - } + // normal delete or soft delete + return deleteRequest(originalRequest); } /** @@ -988,8 +782,8 @@ private SaveManyBase saveManyRequest(boolean insertedParent, BeanPropertyAssocMa } } - void deleteManyIntersection(EntityBean bean, BeanPropertyAssocMany many, SpiTransaction t, boolean publish, boolean queue) { - SpiSqlUpdate sqlDelete = deleteAllIntersection(bean, many, publish); + void deleteManyIntersection(EntityBean bean, BeanPropertyAssocMany many, SpiTransaction t, boolean queue) { + SpiSqlUpdate sqlDelete = deleteAllIntersection(bean, many); if (queue) { addToFlushQueue(sqlDelete, t, BatchControl.DELETE_QUEUE); } else { @@ -997,8 +791,8 @@ void deleteManyIntersection(EntityBean bean, BeanPropertyAssocMany many, SpiT } } - private SpiSqlUpdate deleteAllIntersection(EntityBean bean, BeanPropertyAssocMany many, boolean publish) { - IntersectionRow intRow = many.buildManyToManyDeleteChildren(bean, publish); + private SpiSqlUpdate deleteAllIntersection(EntityBean bean, BeanPropertyAssocMany many) { + IntersectionRow intRow = many.buildManyToManyDeleteChildren(bean); return intRow.createDeleteChildren(server); } @@ -1047,7 +841,7 @@ private void deleteAssocMany(PersistRequestBean request) { if (many.hasJoinTable()) { if (deleteMode.isHard()) { // delete associated rows from intersection table (but not during soft delete) - deleteManyIntersection(parentBean, many, t, request.isPublish(), false); + deleteManyIntersection(parentBean, many, t, false); } } else { if (ModifyListenMode.REMOVALS == many.modifyListenMode()) { @@ -1239,7 +1033,7 @@ private PersistRequestBean createRequestRecurse(T bean, Transaction t, Ob BeanDescriptor desc = mgr.getBeanDescriptor(); EntityBean entityBean = (EntityBean) bean; PersistRequest.Type type; - if (Flags.isPublishMergeOrNormal(flags)) { + if (Flags.isMergeOrNormal(flags)) { // just use bean state to determine insert or update type = entityBean._ebean_getIntercept().isUpdate() ? Type.UPDATE : Type.INSERT; } else { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/Flags.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/Flags.java index 6c200911e9..0c17d6f640 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/Flags.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/Flags.java @@ -17,11 +17,6 @@ public final class Flags { */ public static final int RECURSE = 0x00000002; - /** - * Indicates Publish mode. - */ - public static final int PUBLISH = 0x00000004; - /** * Indicates Merge mode. */ @@ -37,9 +32,9 @@ public final class Flags { */ public static final int ZERO = 0; - public static final int PUBLISH_RECURSE = PUBLISH + RECURSE; +// public static final int PUBLISH_RECURSE = PUBLISH + RECURSE; - private static final int PUBLISH_MERGE_NORMAL = PUBLISH + MERGE + NORMAL; + private static final int MERGE_NORMAL = MERGE + NORMAL; private static final int INSERT_NORMAL = INSERT + NORMAL; @@ -57,25 +52,18 @@ public static boolean isRecurse(int state) { return isSet(state, RECURSE); } - /** - * Return true if part of a Publish. - */ - public static boolean isPublish(int state) { - return isSet(state, PUBLISH); - } - /** * Return true if part of a Merge. */ public static boolean isMerge(int state) { - return isSet(state, PUBLISH); + return isSet(state, MERGE); } /** * Return true if part of a Merge or Publish or Normal (bean state matches persist). */ - public static boolean isPublishMergeOrNormal(int state) { - return (state & PUBLISH_MERGE_NORMAL) != 0; + public static boolean isMergeOrNormal(int state) { + return (state & MERGE_NORMAL) != 0; } public static boolean isUpdateForce(int state) { @@ -130,17 +118,6 @@ public static int unsetRecurse(int state) { return unset(state, RECURSE); } - /** - * Set Publish flag. - */ - public static int setPublish(int state) { - return set(state, PUBLISH); - } - - public static int unsetPublish(int state) { - return unset(state, PUBLISH); - } - /** * Set Merge flag. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/MergeNodeAssocManyToMany.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/MergeNodeAssocManyToMany.java index cd476ae61b..517280d5d2 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/MergeNodeAssocManyToMany.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/MergeNodeAssocManyToMany.java @@ -54,7 +54,7 @@ public void merge(MergeRequest request) { if (!deletions.isEmpty()) { transaction.flush(); - SqlUpdate delete = intersectionTable.delete(server, false); + SqlUpdate delete = intersectionTable.delete(server); for (EntityBean deletion : deletions) { many.intersectionBind(delete, parentBean, deletion); delete.addBatch(); @@ -64,7 +64,7 @@ public void merge(MergeRequest request) { if (!additions.isEmpty()) { transaction.flush(); - SqlUpdate insert = intersectionTable.insert(server, false); + SqlUpdate insert = intersectionTable.insert(server); for (EntityBean addition : additions) { many.intersectionBind(insert, parentBean, addition); insert.addBatch(); 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 00805a892f..2f061f72ed 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 @@ -23,7 +23,6 @@ final class SaveManyBeans extends SaveManyBase { private final boolean cascade; - private final boolean publish; private final BeanDescriptor targetDescriptor; private final boolean isMap; private final boolean saveRecurseSkippable; @@ -38,7 +37,6 @@ final class SaveManyBeans extends SaveManyBase { SaveManyBeans(DefaultPersister persister, boolean insertedParent, BeanPropertyAssocMany many, EntityBean parentBean, PersistRequestBean request) { super(persister, insertedParent, many, parentBean, request); this.cascade = many.cascadeInfo().isSave(); - this.publish = request.isPublish(); this.targetDescriptor = many.targetDescriptor(); this.isMap = many.manyType().isMap(); this.saveRecurseSkippable = many.isSaveRecurseSkippable(); @@ -258,7 +256,7 @@ private void saveAssocManyIntersection(boolean queue) { if (vanillaCollection || forcedUpdate) { // delete all intersection rows and then treat all // beans in the collection as additions - persister.deleteManyIntersection(parentBean, many, transaction, publish, queue); + persister.deleteManyIntersection(parentBean, many, transaction, queue); } Collection deletions = null; @@ -296,7 +294,7 @@ private void saveAssocManyIntersection(boolean queue) { EntityBean otherDelete = (EntityBean) other; // the object from the 'other' side of the ManyToMany // build a intersection row for 'delete' - IntersectionRow intRow = many.buildManyToManyMapBean(parentBean, otherDelete, publish); + IntersectionRow intRow = many.buildManyToManyMapBean(parentBean, otherDelete); SpiSqlUpdate sqlDelete = intRow.createDelete(server, DeleteMode.HARD); persister.executeOrQueue(sqlDelete, transaction, queue, BatchControl.DELETE_QUEUE); } @@ -316,7 +314,7 @@ private void saveAssocManyIntersection(boolean queue) { throw new PersistenceException("ManyToMany bean does not have an Id value? " + otherBean); } else { // build a intersection row for 'insert' - IntersectionRow intRow = many.buildManyToManyMapBean(parentBean, otherBean, publish); + IntersectionRow intRow = many.buildManyToManyMapBean(parentBean, otherBean); SpiSqlUpdate sqlInsert = intRow.createInsert(server); persister.executeOrQueue(sqlInsert, transaction, queue, BatchControl.INSERT_QUEUE); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/DeleteMeta.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/DeleteMeta.java index e5dd59f853..bc832b8b35 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/DeleteMeta.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/DeleteMeta.java @@ -17,23 +17,12 @@ final class DeleteMeta extends BaseMeta { private final String sqlVersion; private final String sqlNone; - private final String sqlDraftVersion; - private final String sqlDraftNone; DeleteMeta(BeanDescriptor desc, BindableId id, Bindable version, Bindable tenantId) { super(id, version, tenantId); - String tableName = desc.baseTable(); this.sqlNone = genSql(ConcurrencyMode.NONE, tableName); this.sqlVersion = genSql(ConcurrencyMode.VERSION, tableName); - if (desc.isDraftable()) { - String draftTableName = desc.draftTable(); - this.sqlDraftNone = genSql(ConcurrencyMode.NONE, draftTableName); - this.sqlDraftVersion = genSql(ConcurrencyMode.VERSION, draftTableName); - } else { - this.sqlDraftNone = sqlNone; - this.sqlDraftVersion = sqlVersion; - } } /** @@ -59,13 +48,12 @@ String getSql(PersistRequestBean request) { throw new IllegalStateException("Can not deleteById on " + request.fullName() + " as no @Id property"); } - boolean publish = request.isPublish(); switch (request.concurrencyMode()) { case NONE: - return publish ? sqlNone : sqlDraftNone; + return sqlNone; case VERSION: - return publish ? sqlVersion : sqlDraftVersion; + return sqlVersion; default: throw new RuntimeException("Invalid mode " + request.concurrencyMode()); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/InsertHandler.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/InsertHandler.java index 121ee7f879..bd916b4b9a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/InsertHandler.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/InsertHandler.java @@ -69,7 +69,7 @@ public void bind() throws SQLException { SpiTransaction t = persistRequest.transaction(); // get the appropriate sql - sql = meta.getSql(withId, persistRequest.isPublish()); + sql = meta.getSql(withId); PreparedStatement pstmt; if (persistRequest.isBatched()) { pstmt = pstmtBatch(t, sql, persistRequest, useGeneratedKeys); @@ -77,7 +77,7 @@ public void bind() throws SQLException { pstmt = pstmt(t, sql, useGeneratedKeys); } dataBind = bind(pstmt); - meta.bind(this, bean, withId, persistRequest.isPublish()); + meta.bind(this, bean, withId); if (persistRequest.isBatched()) { batchedPstmt.registerInputStreams(dataBind.getInputStreams()); } 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 a4d9cd1f73..14c1c5531a 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 @@ -21,12 +21,9 @@ final class InsertMeta { private final String sqlNullId; private final String sqlWithId; - private final String sqlDraftNullId; - private final String sqlDraftWithId; private final BindableId id; private final Bindable discriminator; private final BindableList all; - private final BindableList allExcludeDraftOnly; private final boolean supportsGetGeneratedKeys; private final boolean concatenatedKey; /** @@ -42,13 +39,10 @@ final class InsertMeta { this.discriminator = discriminator(desc); this.id = id; this.all = all; - this.allExcludeDraftOnly = all.excludeDraftOnly(); this.shadowFKey = shadowFKey; String tableName = desc.baseTable(); - String draftTableName = desc.draftTable(); - this.sqlWithId = genSql(false, tableName, false); - this.sqlDraftWithId = desc.isDraftable() ? genSql(false, draftTableName, true) : sqlWithId; + this.sqlWithId = genSql(false, tableName); // only available for single Id property if (id.isConcatenated()) { @@ -56,7 +50,6 @@ final class InsertMeta { this.concatenatedKey = true; this.identityDbColumns = null; this.sqlNullId = null; - this.sqlDraftNullId = null; this.supportsGetGeneratedKeys = false; this.supportsSelectLastInsertedId = false; @@ -72,8 +65,7 @@ final class InsertMeta { this.supportsGetGeneratedKeys = dbPlatform.dbIdentity().isSupportsGetGeneratedKeys(); this.supportsSelectLastInsertedId = desc.supportsSelectLastInsertedId(); } - this.sqlNullId = genSql(true, tableName, false); - this.sqlDraftNullId = desc.isDraftable() ? genSql(true, draftTableName, true) : sqlNullId; + this.sqlNullId = genSql(true, tableName); } } @@ -119,7 +111,7 @@ boolean deriveConcatenatedId(PersistRequestBean persist) { /** * Bind the request based on whether the id value(s) are null. */ - public void bind(DmlHandler request, EntityBean bean, boolean withId, boolean publish) throws SQLException { + public void bind(DmlHandler request, EntityBean bean, boolean withId) throws SQLException { if (withId) { id.dmlBind(request, bean); } @@ -129,29 +121,25 @@ public void bind(DmlHandler request, EntityBean bean, boolean withId, boolean pu if (discriminator != null) { discriminator.dmlBind(request, bean); } - if (publish) { - allExcludeDraftOnly.dmlBind(request, bean); - } else { - all.dmlBind(request, bean); - } + all.dmlBind(request, bean); } /** * get the sql based whether the id value(s) are null. */ - public String getSql(boolean withId, boolean publish) { + public String getSql(boolean withId) { if (withId) { - return publish ? sqlWithId : sqlDraftWithId; + return sqlWithId; } else { - return publish ? sqlNullId : sqlDraftNullId; + return sqlNullId; } } - private String genSql(boolean nullId, String table, boolean draftTable) { + private String genSql(boolean nullId, String table) { GenerateDmlRequest request = new GenerateDmlRequest(); request.setInsertSetMode(); request.append("insert into ").append(table); - if (nullId && noColumnsForInsert(draftTable)) { + if (nullId && noColumnsForInsert()) { return request.append(defaultValues()).toString(); } request.append(" ("); @@ -164,11 +152,8 @@ private String genSql(boolean nullId, String table, boolean draftTable) { if (discriminator != null) { discriminator.dmlAppend(request); } - if (draftTable) { - all.dmlAppend(request); - } else { - allExcludeDraftOnly.dmlAppend(request); - } + all.dmlAppend(request); + request.append(") values ("); request.append(request.insertBindBuffer()); request.append(")"); @@ -191,10 +176,10 @@ private String defaultValues() { /** * Return true if the insert actually contains no columns. */ - private boolean noColumnsForInsert(boolean draftTable) { + private boolean noColumnsForInsert() { return shadowFKey == null && discriminator == null - && (draftTable ? all.isEmpty() : allExcludeDraftOnly.isEmpty()); + && all.isEmpty(); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/Bindable.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/Bindable.java index be8dbb73b4..8f35860caa 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/Bindable.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/Bindable.java @@ -38,9 +38,4 @@ public interface Bindable { * when binding a update or delete where clause with ALL concurrency mode. */ void dmlBind(BindableRequest request, EntityBean bean) throws SQLException; - - /** - * Return true if the underlying property is 'draft only'. - */ - boolean isDraftOnly(); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableAssocOne.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableAssocOne.java index bdceb84297..c92fa4a2f0 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableAssocOne.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableAssocOne.java @@ -23,11 +23,6 @@ class BindableAssocOne implements Bindable { this.importedId = assocOne.importedId(); } - @Override - public final boolean isDraftOnly() { - return assocOne.isDraftOnly(); - } - @Override public final void addToUpdate(PersistRequestBean request, List list) { if (request.isAddToUpdate(assocOne)) { 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 index 4c72c73c18..eaa50c4059 100644 --- 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 @@ -24,11 +24,6 @@ public BindableDiscriminator(InheritInfo inheritInfo) { this.sqlType = inheritInfo.getDiscriminatorType(); } - @Override - public boolean isDraftOnly() { - return false; - } - @Override public void addToUpdate(PersistRequestBean request, List list) { throw new PersistenceException("Never called (only for inserts)"); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableEmbedded.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableEmbedded.java index a0fcb5fa7e..17204b59c0 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableEmbedded.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableEmbedded.java @@ -6,7 +6,6 @@ import io.ebeaninternal.server.persist.dml.GenerateDmlRequest; import java.sql.SQLException; -import java.util.Arrays; import java.util.List; /** @@ -23,11 +22,6 @@ final class BindableEmbedded implements Bindable { this.items = bindList.toArray(new Bindable[0]); } - @Override - public boolean isDraftOnly() { - return embProp.isDraftOnly(); - } - @Override public void dmlAppend(GenerateDmlRequest request) { for (Bindable item : items) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableEncryptedProperty.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableEncryptedProperty.java index 40fb71c3fc..35d046fb81 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableEncryptedProperty.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableEncryptedProperty.java @@ -23,11 +23,6 @@ final class BindableEncryptedProperty implements Bindable { this.bindEncryptDataFirst = bindEncryptDataFirst; } - @Override - public boolean isDraftOnly() { - return prop.isDraftOnly(); - } - @Override public void addToUpdate(PersistRequestBean request, List list) { if (request.isAddToUpdate(prop)) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableIdEmbedded.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableIdEmbedded.java index 06e6ee1a89..3ebd7cea2f 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableIdEmbedded.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableIdEmbedded.java @@ -28,11 +28,6 @@ final class BindableIdEmbedded implements BindableId { this.matches = matches; } - @Override - public boolean isDraftOnly() { - return false; - } - @Override public boolean isEmpty() { return false; diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableIdEmpty.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableIdEmpty.java index fa9c73b0b7..bf13b2da83 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableIdEmpty.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableIdEmpty.java @@ -13,11 +13,6 @@ public boolean isEmpty() { return true; } - @Override - public boolean isDraftOnly() { - return false; - } - @Override public void addToUpdate(PersistRequestBean request, List list) { // nothing diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableIdScalar.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableIdScalar.java index 58934a710e..d76c4e516e 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableIdScalar.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableIdScalar.java @@ -35,11 +35,6 @@ public String getIdentityColumn() { return uidProp.dbColumn(); } - @Override - public boolean isDraftOnly() { - return false; - } - /** * Does nothing for BindableId. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableList.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableList.java index 85894ee53d..9a40ebf6ec 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableList.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableList.java @@ -20,28 +20,10 @@ public BindableList(List list) { items = list.toArray(new Bindable[0]); } - /** - * Return a bindable list that excludes @DraftOnly properties. - */ - public BindableList excludeDraftOnly() { - List copy = new ArrayList<>(items.length); - for (Bindable b : items) { - if (!b.isDraftOnly()) { - copy.add(b); - } - } - return new BindableList(copy); - } - public boolean isEmpty() { return items.length == 0; } - @Override - public boolean isDraftOnly() { - return false; - } - public void addAll(List list) { Collections.addAll(list, items); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableProperty.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableProperty.java index 137ad992a9..abdfee66f0 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableProperty.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableProperty.java @@ -19,11 +19,6 @@ class BindableProperty implements Bindable { this.prop = prop; } - @Override - public final boolean isDraftOnly() { - return prop.isDraftOnly(); - } - @Override public void addToUpdate(PersistRequestBean request, List list) { if (request.isAddToUpdate(prop)) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindablePropertyVersion.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindablePropertyVersion.java index 2b96f1c22f..146ae387a8 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindablePropertyVersion.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindablePropertyVersion.java @@ -24,11 +24,6 @@ public String toString() { return prop.toString(); } - @Override - public boolean isDraftOnly() { - return prop.isDraftOnly(); - } - @Override public void addToUpdate(PersistRequestBean request, List list) { if (request.isAddToUpdate(prop)) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableUnidirectional.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableUnidirectional.java index 5f5c7490e1..367df85965 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableUnidirectional.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dmlbind/BindableUnidirectional.java @@ -29,11 +29,6 @@ public BindableUnidirectional(BeanDescriptor desc, BeanPropertyAssocOne un this.importedId = unidirectional.importedId(); } - @Override - public boolean isDraftOnly() { - return false; - } - @Override public void addToUpdate(PersistRequestBean request, List list) { throw new PersistenceException("Never called (for insert only)"); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQuery.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQuery.java index ff54e818d3..9e86b86a26 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQuery.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQuery.java @@ -211,11 +211,6 @@ public boolean isLoadContextBean() { return loadContextBean; } - @Override - public boolean isDraftQuery() { - return query.isAsDraft(); - } - @Override public boolean isDisableLazyLoading() { return disableLazyLoading; diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryBuilder.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryBuilder.java index cbbf8bb2ca..609cb4e020 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryBuilder.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryBuilder.java @@ -48,17 +48,15 @@ final class CQueryBuilder { private final Binder binder; private final boolean selectCountWithAlias; private final CQueryHistorySupport historySupport; - private final CQueryDraftSupport draftSupport; private final DatabasePlatform dbPlatform; private final boolean selectCountWithColumnAlias; /** * Create the SqlGenSelect. */ - CQueryBuilder(DatabasePlatform dbPlatform, Binder binder, CQueryHistorySupport historySupport, CQueryDraftSupport draftSupport) { + CQueryBuilder(DatabasePlatform dbPlatform, Binder binder, CQueryHistorySupport historySupport) { this.dbPlatform = dbPlatform; this.binder = binder; - this.draftSupport = draftSupport; this.historySupport = historySupport; this.columnAliasPrefix = dbPlatform.columnAliasPrefix(); this.sqlLimiter = dbPlatform.sqlLimiter(); @@ -221,13 +219,6 @@ CQueryHistorySupport historySupport(SpiQuery query) { return query.temporalMode().isHistory() ? historySupport : null; } - /** - * Return the draft support (or null) for a 'asDraft' query. - */ - CQueryDraftSupport draftSupport(SpiQuery query) { - return query.temporalMode() == SpiQuery.TemporalMode.DRAFT ? draftSupport : null; - } - /** * Build the row count query. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryDraftSupport.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryDraftSupport.java deleted file mode 100644 index c02b25ba6a..0000000000 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryDraftSupport.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.ebeaninternal.server.query; - -import java.util.Map; - -/** - * Support 'asDraft' queries. - */ -final class CQueryDraftSupport { - - /** - * The mapping of base tables to their matching 'draft' table. - */ - private final Map tableMap; - - CQueryDraftSupport(Map tableMap) { - this.tableMap = tableMap; - } - - /** - * Return the draft table associated to the base table. - *

- * This returns null for entities that are not draftable and in that case - * the usual base table is used. - */ - String draftTable(String table) { - return tableMap.get(table); - } -} diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryEngine.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryEngine.java index 405b141bd5..878025fb46 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryEngine.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryEngine.java @@ -38,13 +38,13 @@ public final class CQueryEngine { private final CQueryHistorySupport historySupport; private final DatabasePlatform dbPlatform; - public CQueryEngine(DatabaseConfig config, DatabasePlatform dbPlatform, Binder binder, Map asOfTableMapping, Map draftTableMap) { + public CQueryEngine(DatabaseConfig config, DatabasePlatform dbPlatform, Binder binder, Map asOfTableMapping) { this.dbPlatform = dbPlatform; this.defaultFetchSizeFindEach = config.getJdbcFetchSizeFindEach(); this.defaultFetchSizeFindList = config.getJdbcFetchSizeFindList(); this.forwardOnlyHintOnFindIterate = dbPlatform.forwardOnlyHintOnFindIterate(); this.historySupport = new CQueryHistorySupport(dbPlatform.historySupport(), asOfTableMapping, config.getAsOfSysPeriod()); - this.queryBuilder = new CQueryBuilder(dbPlatform, binder, historySupport, new CQueryDraftSupport(draftTableMap)); + this.queryBuilder = new CQueryBuilder(dbPlatform, binder, historySupport); } public int forwardOnlyFetchSize() { @@ -414,9 +414,6 @@ private void logFindBeanSummary(CQuery q) { if (query.isAutoTuned()) { msg.append("tuned[true] "); } - if (query.isAsDraft()) { - msg.append(" draft[true] "); - } if (originKey != null) { msg.append("origin[").append(originKey).append("] "); } @@ -458,9 +455,6 @@ private void logFindManySummary(CQuery q) { if (query.isAutoTuned()) { msg.append("tuned[true] "); } - if (query.isAsDraft()) { - msg.append(" draft[true] "); - } if (originKey != null) { msg.append("origin[").append(originKey).append("] "); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultDbSqlContext.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultDbSqlContext.java index 9488ad1189..2f18f0f805 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultDbSqlContext.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultDbSqlContext.java @@ -35,16 +35,14 @@ final class DefaultDbSqlContext implements DbSqlContext { private String currentPrefix; private List encryptedProps; private List extraJoins; - private final CQueryDraftSupport draftSupport; private final CQueryHistorySupport historySupport; private final boolean historyQuery; DefaultDbSqlContext(SqlTreeAlias alias, String columnAliasPrefix, CQueryHistorySupport historySupport, - CQueryDraftSupport draftSupport, String fromForUpdate) { + String fromForUpdate) { this.alias = alias; this.columnAliasPrefix = columnAliasPrefix; this.useColumnAlias = columnAliasPrefix != null; - this.draftSupport = draftSupport; this.historySupport = historySupport; this.historyQuery = (historySupport != null); this.fromForUpdate = fromForUpdate; @@ -124,9 +122,7 @@ public void addJoin(String type, String table, TableJoinColumn[] cols, String a1 tableJoins.add(joinKey); sb.append(' ').append(type); boolean addAsOfOnClause = false; - if (draftSupport != null) { - appendTable(table, draftSupport.draftTable(table)); - } else if (!historyQuery) { + if (!historyQuery) { sb.append(' ').append(table).append(' '); } else { // check if there is an associated history table and if so @@ -185,11 +181,6 @@ public int asOfTableCount() { return asOfTableCount; } - @Override - public boolean isDraftQuery() { - return draftSupport != null; - } - @Override public String tableAlias(String prefix) { return alias.tableAlias(prefix); 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 53327fda20..a6c7b54162 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 @@ -150,11 +150,6 @@ public Query asOf(Timestamp asOf) { throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup"); } - @Override - public Query asDraft() { - throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup"); - } - @Override public DtoQuery asDto(Class dtoClass) { 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 449b659261..83383744f9 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 @@ -89,11 +89,6 @@ public interface STreeType { */ Object contextPutIfAbsent(PersistenceContext persistenceContext, Object id, EntityBean localBean); - /** - * Set draft status on the entity bean. - */ - void setDraft(EntityBean localBean); - /** * Invoke any post load listeners. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlBeanLoad.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlBeanLoad.java index 27b6d6fbfb..793c1a1d7d 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlBeanLoad.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlBeanLoad.java @@ -46,7 +46,7 @@ public DbReadContext ctx() { } public Object load(BeanProperty prop) { - if (!rawSql && !prop.isLoadProperty(ctx.isDraftQuery())) { + if (!rawSql && !prop.isLoadProperty()) { return null; } if ((bean == null) 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 8a2465293d..0a56724332 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 @@ -101,9 +101,8 @@ public final class SqlTreeBuilder { this.distinctNoLobs = builder.isPlatformDistinctNoLobs(); String fromForUpdate = builder.fromForUpdate(query); CQueryHistorySupport historySupport = builder.historySupport(query); - CQueryDraftSupport draftSupport = builder.draftSupport(query); String colAlias = subQuery ? null : columnAliasPrefix; - this.ctx = new DefaultDbSqlContext(alias, colAlias, historySupport, draftSupport, fromForUpdate); + this.ctx = new DefaultDbSqlContext(alias, colAlias, historySupport, fromForUpdate); this.common = new SqlTreeCommon(temporalMode, disableLazyLoad, readOnly, includeJoin); } 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 3575d8bbbb..5621373eae 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 @@ -259,9 +259,6 @@ private void postLoad() { if (readIdNormal) { createListProxies(); } - if (temporalMode == SpiQuery.TemporalMode.DRAFT) { - localDesc.setDraft(localBean); - } localDesc.postLoad(localBean); EntityBeanIntercept ebi = localBean._ebean_getIntercept(); 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 9d2955a42a..c82dde777d 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 @@ -336,13 +336,6 @@ public final Query asOf(Timestamp asOfDateTime) { return this; } - @Override - public final Query asDraft() { - this.temporalMode = TemporalMode.DRAFT; - this.useBeanCache = CacheMode.OFF; - return this; - } - @Override public final Query setIncludeSoftDeletes() { this.temporalMode = TemporalMode.SOFT_DELETED; @@ -942,11 +935,6 @@ public final boolean isAsOfQuery() { return asOf != null; } - @Override - public final boolean isAsDraft() { - return TemporalMode.DRAFT == temporalMode; - } - @Override public final boolean isIncludeSoftDeletes() { return TemporalMode.SOFT_DELETED == temporalMode; diff --git a/ebean-core/src/test/java/io/ebeaninternal/server/querydefn/OrmQueryPlanKeyTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/querydefn/OrmQueryPlanKeyTest.java index 6e181573bf..306697f10a 100644 --- a/ebean-core/src/test/java/io/ebeaninternal/server/querydefn/OrmQueryPlanKeyTest.java +++ b/ebean-core/src/test/java/io/ebeaninternal/server/querydefn/OrmQueryPlanKeyTest.java @@ -205,8 +205,6 @@ public void equals_when_idBothGiven() { public void equals_when_diffTemporalMode() { CQueryPlanKey key1 = planKey(query()); - CQueryPlanKey key2 = planKey(query().asDraft()); - assertDifferent(key1, key2); CQueryPlanKey key3 = planKey(query().asOf(new Timestamp(System.currentTimeMillis()))); assertDifferent(key1, key3); diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DbTriggerBasedHistoryDdl.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DbTriggerBasedHistoryDdl.java index 03c2c5d3c1..0a4399f70d 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DbTriggerBasedHistoryDdl.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/DbTriggerBasedHistoryDdl.java @@ -140,10 +140,8 @@ protected void createHistoryTable(DdlBuffer apply, MTable table) { protected void createHistoryTableAs(DdlBuffer apply, MTable table) { apply.append(platformDdl.getCreateTableCommandPrefix()).append(" ").append(historyTableName(table.getName())).append("(").newLine(); for (MColumn column : table.allColumns()) { - if (!column.isDraftOnly()) { - writeColumnDefinition(apply, column.getName(), column.getType()); - apply.append(",").newLine(); - } + writeColumnDefinition(apply, column.getName(), column.getType()); + apply.append(",").newLine(); } // TODO: We must apply also pending dropped columns. Let's do that in a later step if (table.hasDroppedColumns()) { diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/HanaHistoryDdl.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/HanaHistoryDdl.java index 742f23c45d..f50d8606b9 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/HanaHistoryDdl.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/HanaHistoryDdl.java @@ -34,11 +34,9 @@ public void createWithHistory(DdlWrite writer, MTable table) { // create history table Collection cols = table.allColumns(); for (MColumn column : cols) { - if (!column.isDraftOnly()) { - writeColumnDefinition(apply, column.getName(), column.getType(), column.getDefaultValue(), column.isNotnull(), + writeColumnDefinition(apply, column.getName(), column.getType(), column.getDefaultValue(), column.isNotnull(), column.isIdentity() ? platformDdl.identitySuffix : null); - apply.append(",").newLine(); - } + apply.append(",").newLine(); } writeColumnDefinition(apply, systemPeriodStart, "TIMESTAMP", null, false, null); apply.append(",").newLine(); diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/CurrentModel.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/CurrentModel.java index faac168ea2..2200a89fc7 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/CurrentModel.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/CurrentModel.java @@ -93,8 +93,6 @@ public ModelContainer read() { ModelBuildBeanVisitor visitor = new ModelBuildBeanVisitor(context); VisitAllUsing visit = new VisitAllUsing(visitor, server); visit.visitAllBeans(); - // adjust the foreign keys on the 'draft' tables - context.adjustDraftReferences(); } return model; } diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MColumn.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MColumn.java index 712690e0b1..0d350b7c8c 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MColumn.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MColumn.java @@ -47,8 +47,6 @@ public class MColumn { */ private AlterColumn alterColumn; - private boolean draftOnly; - private List dbMigrationInfos; public MColumn(Column column) { @@ -91,7 +89,6 @@ public MColumn(String name, String type, boolean notnull) { */ public MColumn copyForDraft() { MColumn copy = new MColumn(name, type); - copy.draftOnly = draftOnly; copy.checkConstraint = checkConstraint; copy.checkConstraintName = checkConstraintName; copy.defaultValue = defaultValue; @@ -241,25 +238,11 @@ public void setComment(String comment) { this.comment = comment; } - /** - * Set the draftOnly status for this column. - */ - public void setDraftOnly(boolean draftOnly) { - this.draftOnly = draftOnly; - } - - /** - * Return the draftOnly status for this column. - */ - public boolean isDraftOnly() { - return draftOnly; - } - /** * Return true if this column should be included in History DB triggers etc. */ public boolean isIncludeInHistory() { - return !draftOnly && !historyExclude; + return !historyExclude; } public void clearForeignKey() { diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java index 83b41a4fcd..c15ef961aa 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java @@ -29,12 +29,10 @@ public class MTable { private static final System.Logger logger = AppLog.getLogger(MTable.class); private String name; - private MTable draftTable; /** * Marked true for draft tables. These need to have their FK references adjusted * after all the draft tables have been identified. */ - private boolean draft; private PartitionMeta partitionMeta; private TablespaceMeta tablespaceMeta; private String pkName; @@ -107,25 +105,6 @@ private MTable(String name, TablespaceMeta tablespaceMeta, String storageEngine) this.storageEngine = storageEngine; } - /** - * Create a copy of this table structure as a 'draft' table. - *

- * Note that both tables contain @DraftOnly MColumns and these are filtered out - * later when creating the CreateTable object. - */ - public MTable createDraftTable() { - draftTable = new MTable(name + "_draft", this.tablespaceMeta, this.storageEngine); - draftTable.draft = true; - draftTable.whenCreatedColumn = whenCreatedColumn; - // compoundKeys - // compoundUniqueConstraints - draftTable.identityMode = identityMode; - for (MColumn col : allColumns()) { - draftTable.addColumn(col.copyForDraft()); - } - return draftTable; - } - /** * Construct for migration. */ @@ -142,7 +121,6 @@ public MTable(CreateTable createTable) { this.tablespaceMeta = null; } this.withHistory = Boolean.TRUE.equals(createTable.isWithHistory()); - this.draft = Boolean.TRUE.equals(createTable.isDraft()); this.identityMode = fromCreateTable(createTable); List cols = createTable.getColumn(); for (Column column : cols) { @@ -220,14 +198,9 @@ public CreateTable createTable() { if (withHistory) { createTable.setWithHistory(Boolean.TRUE); } - if (draft) { - createTable.setDraft(Boolean.TRUE); - } + for (MColumn column : allColumns()) { - // filter out draftOnly columns from the base table - if (draft || !column.isDraftOnly()) { - createTable.getColumn().add(column.createColumn()); - } + createTable.getColumn().add(column.createColumn()); } for (MCompoundForeignKey compoundKey : compoundKeys) { createTable.getForeignKey().add(compoundKey.createForeignKey()); @@ -282,10 +255,7 @@ private void compareColumns(ModelDiff modelDiff, MTable newTable) { for (MColumn newColumn : newColumnMap.values()) { MColumn localColumn = getColumn(newColumn.getName()); if (localColumn == null) { - // can ignore if draftOnly column and non-draft table - if (!newColumn.isDraftOnly() || draft) { - diffNewColumn(newColumn, newTable); - } + diffNewColumn(newColumn, newTable); } else { localColumn.compare(modelDiff, this, newColumn); } @@ -296,10 +266,6 @@ private void compareColumns(ModelDiff modelDiff, MTable newTable) { MColumn newColumn = newColumnMap.get(existingColumn.getName()); if (newColumn == null) { diffDropColumn(modelDiff, existingColumn); - } else if (newColumn.isDraftOnly() && !draft) { - // effectively a drop column (draft only column on a non-draft table) - logger.log(TRACE, "... drop column {0} from table {1} as now draftOnly", newColumn.getName(), name); - diffDropColumn(modelDiff, existingColumn); } } @@ -425,13 +391,6 @@ public String getSchema() { return pos == -1 ? null : name.substring(0, pos); } - /** - * Return true if this table is a 'Draft' table. - */ - public boolean isDraft() { - return draft; - } - /** * Return true if this table is partitioned. */ @@ -685,42 +644,6 @@ private boolean hasDuplicateForeignKeys() { return false; } - /** - * Adjust the references (FK) if it should relate to a draft table. - */ - public void adjustReferences(ModelContainer modelContainer) { - Collection cols = allColumns(); - for (MColumn col : cols) { - String references = col.getReferences(); - if (references != null) { - String baseTable = extractBaseTable(references); - MTable refBaseTable = modelContainer.getTable(baseTable); - if (refBaseTable.draftTable != null) { - // change references to another associated 'draft' table - String newReferences = deriveReferences(references, refBaseTable.draftTable.getName()); - col.setReferences(newReferences); - } - } - } - } - - /** - * Return the base table name from references (table.column). - */ - private String extractBaseTable(String references) { - int lastDot = references.lastIndexOf('.'); - return references.substring(0, lastDot); - } - - /** - * Return the new references using the given draftTableName. - * (The referenced column is the same as before). - */ - private String deriveReferences(String references, String draftTableName) { - int lastDot = references.lastIndexOf('.'); - return draftTableName + "." + references.substring(lastDot + 1); - } - /** * This method adds information which columns are nullable or not to the compound indices. */ diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java index afd52d1866..8d28de50b2 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/ModelContainer.java @@ -58,17 +58,6 @@ public List getPartitionedTables() { return partitionedTables; } - /** - * Adjust the FK references on all the draft tables. - */ - public void adjustDraftReferences() { - for (MTable table : this.tables.values()) { - if (table.isDraft()) { - table.adjustReferences(this); - } - } - } - /** * Return the map of all the tables. */ diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildContext.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildContext.java index 20730e3724..0f69c077c5 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildContext.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildContext.java @@ -59,14 +59,6 @@ private DbConstraintNaming.MaxLength maxLength() { return new DefaultConstraintMaxLength(databasePlatform.maxConstraintNameLength()); } - /** - * Adjust the foreign key references on any draft tables (that reference other draft tables). - * This is called as a 'second pass' after all the draft tables have been identified. - */ - public void adjustDraftReferences() { - model.adjustDraftReferences(); - } - public String normaliseTable(String baseTable) { return constraintNaming.normaliseTable(baseTable); } @@ -170,51 +162,6 @@ private DbPlatformType getDbType(BeanProperty p) { return dbTypeMap.get(dbType); } - /** - * Create the draft table for a given table. - */ - public void createDraft(MTable table, boolean draftable) { - - MTable draftTable = table.createDraftTable(); - draftTable.setPkName(primaryKeyName(draftTable.getName())); - - if (draftable) { - // Add a FK from @Draftable live table back to it's draft table) - List pkCols = table.primaryKeyColumns(); - if (pkCols.size() == 1) { - // only doing this for single column PK at this stage - MColumn pk = pkCols.get(0); - pk.setReferences(draftTable.getName() + "." + pk.getName()); - pk.setForeignKeyName(foreignKeyConstraintName(table.getName(), pk.getName(), 0)); - } - } - - int fkCount = 0; - int ixCount = 0; - int uqCount = 0; - Collection cols = draftTable.allColumns(); - for (MColumn col : cols) { - if (col.getForeignKeyName() != null) { - // Note that we adjust the 'references' table later in a second pass - // after we know all the tables that are 'draftable' - //col.setReferences(refTable + "." + refColumn); - col.setForeignKeyName(foreignKeyConstraintName(draftTable.getName(), col.getName(), ++fkCount)); - - String[] indexCols = {col.getName()}; - col.setForeignKeyIndex(foreignKeyIndexName(draftTable.getName(), indexCols, ++ixCount)); - } - // adjust the unique constraint names - if (col.getUnique() != null) { - col.setUnique(uniqueConstraintName(draftTable.getName(), col.getName(), ++uqCount)); - } - if (col.getUniqueOneToOne() != null) { - col.setUniqueOneToOne(uniqueConstraintName(draftTable.getName(), col.getName(), ++uqCount)); - } - } - - addTable(draftTable); - } - /** * Return a builder to add foreign keys. */ diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildIntersectionTable.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildIntersectionTable.java index 763016278c..d5246d68a2 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildIntersectionTable.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildIntersectionTable.java @@ -38,11 +38,6 @@ public MTable build() { } buildFkConstraints(); - - if (manyProp.targetDescriptor().isDraftable()) { - ctx.createDraft(intersectionTable, false); - } - return intersectionTable; } 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 4f62384c64..dda9fb8d8b 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 @@ -114,22 +114,9 @@ public void visitEnd() { } } - addDraftTable(); table.updateCompoundIndices(); } - /** - * Create a 'draft' table that is mostly the same as the base table. - * It has @DraftOnly columns and adjusted primary and foreign keys. - */ - private void addDraftTable() { - if (beanDescriptor.isDraftable() || beanDescriptor.isDraftableElement()) { - // create a 'Draft' table which looks very similar (change PK, FK etc) - ctx.createDraft(table, !beanDescriptor.isDraftableElement()); - } - } - - @Override public void visitMany(BeanPropertyAssocMany p) { if (p.createJoinTable()) { @@ -251,7 +238,6 @@ public void visitScalar(BeanProperty p, boolean allowNonNull) { MColumn col = table.addColumnScalar(p.dbColumn(), ctx.getColumnDefn(p, false)); //MColumn col = new MColumn(p.dbColumn(), ctx.getColumnDefn(p, false)); col.setComment(p.dbComment()); - col.setDraftOnly(p.isDraftOnly()); col.setHistoryExclude(p.isExcludedFromHistory()); if (p.isId() || p.isImportedPrimaryKey()) { col.setPrimaryKey(true); 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 7e9996bc07..a073abcca0 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java @@ -523,14 +523,6 @@ public R asOf(Timestamp asOf) { return root; } - /** - * Execute the query against the draft set of tables. - */ - public R asDraft() { - query.asDraft(); - return root; - } - /** * Execute the query including soft deleted rows. */ diff --git a/ebean-test/src/test/java/io/ebean/xtest/config/PlatformNoGeneratedKeysTest.java b/ebean-test/src/test/java/io/ebean/xtest/config/PlatformNoGeneratedKeysTest.java index 2d29618ec1..66678594d6 100644 --- a/ebean-test/src/test/java/io/ebean/xtest/config/PlatformNoGeneratedKeysTest.java +++ b/ebean-test/src/test/java/io/ebean/xtest/config/PlatformNoGeneratedKeysTest.java @@ -78,7 +78,7 @@ public void insertNoBatch_expect_selectIdentity() { assertThat(d0.getId()).isNotNull(); - server.publish(BasicDraftableBean.class, d0.getId()); + //server.publish(BasicDraftableBean.class, d0.getId()); BasicDraftableBean one = server.find(BasicDraftableBean.class, d0.getId()); diff --git a/ebean-test/src/test/java/io/ebean/xtest/internal/api/TDSpiEbeanServer.java b/ebean-test/src/test/java/io/ebean/xtest/internal/api/TDSpiEbeanServer.java index af11aa1b43..e5039d9b81 100644 --- a/ebean-test/src/test/java/io/ebean/xtest/internal/api/TDSpiEbeanServer.java +++ b/ebean-test/src/test/java/io/ebean/xtest/internal/api/TDSpiEbeanServer.java @@ -476,46 +476,6 @@ public CallableSql createCallableSql(String callableSql) { public void register(TransactionCallback transactionCallback) throws PersistenceException { } - @Override - public T publish(Class beanType, Object id) { - return null; - } - - @Override - public List publish(Query query) { - return null; - } - - @Override - public T publish(Class beanType, Object id, Transaction transaction) { - return null; - } - - @Override - public List publish(Query query, Transaction transaction) { - return null; - } - - @Override - public T draftRestore(Class beanType, Object id, Transaction transaction) { - return null; - } - - @Override - public List draftRestore(Query query, Transaction transaction) { - return null; - } - - @Override - public T draftRestore(Class beanType, Object id) { - return null; - } - - @Override - public List draftRestore(Query query) { - return null; - } - @Override public Transaction createTransaction() { return null; diff --git a/ebean-test/src/test/java/io/ebean/xtest/internal/api/TDSpiServer.java b/ebean-test/src/test/java/io/ebean/xtest/internal/api/TDSpiServer.java index 6783426af1..b0cab546d0 100644 --- a/ebean-test/src/test/java/io/ebean/xtest/internal/api/TDSpiServer.java +++ b/ebean-test/src/test/java/io/ebean/xtest/internal/api/TDSpiServer.java @@ -508,46 +508,6 @@ public DocumentStore docStore() { return null; } - @Override - public T publish(Class beanType, Object id, Transaction transaction) { - return null; - } - - @Override - public T publish(Class beanType, Object id) { - return null; - } - - @Override - public List publish(Query query, Transaction transaction) { - return null; - } - - @Override - public List publish(Query query) { - return null; - } - - @Override - public T draftRestore(Class beanType, Object id, Transaction transaction) { - return null; - } - - @Override - public T draftRestore(Class beanType, Object id) { - return null; - } - - @Override - public List draftRestore(Query query, Transaction transaction) { - return null; - } - - @Override - public List draftRestore(Query query) { - return null; - } - @Override public Set validateQuery(Query query) { return null; diff --git a/ebean-test/src/test/java/io/ebean/xtest/internal/server/persist/FlagsTest.java b/ebean-test/src/test/java/io/ebean/xtest/internal/server/persist/FlagsTest.java index dfabbaada2..78fea8460d 100644 --- a/ebean-test/src/test/java/io/ebean/xtest/internal/server/persist/FlagsTest.java +++ b/ebean-test/src/test/java/io/ebean/xtest/internal/server/persist/FlagsTest.java @@ -14,19 +14,11 @@ public void test() { int state = 0; - state = Flags.setPublish(state); - assertThat(Flags.isSet(state, Flags.PUBLISH)).isTrue(); - state = Flags.setMerge(state); state = Flags.setInsert(state); - assertThat(Flags.isSet(state, Flags.PUBLISH)).isTrue(); assertThat(Flags.isSet(state, Flags.MERGE)).isTrue(); assertThat(Flags.isSet(state, Flags.INSERT)).isTrue(); - state = Flags.unsetPublish(state); - assertThat(Flags.isSet(state, Flags.PUBLISH)).isFalse(); - assertThat(Flags.isSet(state, Flags.MERGE)).isTrue(); - assertThat(Flags.isSet(state, Flags.INSERT)).isTrue(); } @Test @@ -72,15 +64,11 @@ public void updateNormal() { @Test public void isPublishOrMerge() { - assertThat(Flags.isPublishMergeOrNormal(0)).isFalse(); - assertThat(Flags.isPublishMergeOrNormal(Flags.INSERT)).isFalse(); - assertThat(Flags.isPublishMergeOrNormal(Flags.RECURSE)).isFalse(); - - assertThat(Flags.isPublishMergeOrNormal(Flags.PUBLISH)).isTrue(); - assertThat(Flags.isPublishMergeOrNormal(Flags.MERGE)).isTrue(); - assertThat(Flags.isPublishMergeOrNormal(Flags.NORMAL)).isTrue(); + assertThat(Flags.isMergeOrNormal(0)).isFalse(); + assertThat(Flags.isMergeOrNormal(Flags.INSERT)).isFalse(); + assertThat(Flags.isMergeOrNormal(Flags.RECURSE)).isFalse(); - int mergePublish = Flags.setMerge(Flags.setPublish(0)); - assertThat(Flags.isPublishMergeOrNormal(mergePublish)).isTrue(); + assertThat(Flags.isMergeOrNormal(Flags.MERGE)).isTrue(); + assertThat(Flags.isMergeOrNormal(Flags.NORMAL)).isTrue(); } } diff --git a/ebean-test/src/test/java/org/tests/defaultvalues/DefaultsModel.java b/ebean-test/src/test/java/org/tests/defaultvalues/DefaultsModel.java index 5140be70ce..cb6d781c85 100644 --- a/ebean-test/src/test/java/org/tests/defaultvalues/DefaultsModel.java +++ b/ebean-test/src/test/java/org/tests/defaultvalues/DefaultsModel.java @@ -10,14 +10,11 @@ import java.util.List; @Entity -@Draftable public class DefaultsModel { @Id Integer id; - @Draft - boolean draft; @OneToMany(cascade = CascadeType.ALL) List relatedModels; @@ -37,12 +34,4 @@ public List getRelatedModels() { public void setRelatedModels(final List relatedModels) { this.relatedModels = relatedModels; } - - public boolean isDraft() { - return draft; - } - - public void setDraft(final boolean draft) { - this.draft = draft; - } } diff --git a/ebean-test/src/test/java/org/tests/defaultvalues/TestDefaults.java b/ebean-test/src/test/java/org/tests/defaultvalues/TestDefaults.java index d0efdec30f..0f861d0c52 100644 --- a/ebean-test/src/test/java/org/tests/defaultvalues/TestDefaults.java +++ b/ebean-test/src/test/java/org/tests/defaultvalues/TestDefaults.java @@ -27,13 +27,13 @@ public void testInsertDefaultValues() { assertThat(current).isNotEmpty(); if (isMySql() || isMariaDB() || isOracle()) { - assertThat(current.get(0)).contains("insert into defaults_model_draft values (default);"); + assertThat(current.get(0)).contains("insert into defaults_model values (default);"); } else if (isDb2()) { - assertThat(current.get(0)).contains("insert into defaults_model_draft (id) values (default)"); + assertThat(current.get(0)).contains("insert into defaults_model (id) values (default)"); } else if (isSqlServer()) { - assertThat(current.get(0)).contains("insert into defaults_model_draft (id) values (?)"); + assertThat(current.get(0)).contains("insert into defaults_model (id) values (?)"); } else { - assertThat(current.get(0)).contains("insert into defaults_model_draft default values;"); + assertThat(current.get(0)).contains("insert into defaults_model default values;"); } } diff --git a/ebean-test/src/test/java/org/tests/draftable/DocLinkTest.java b/ebean-test/src/test/java/org/tests/draftable/DocLinkTest.java index def5d23742..1a8b0e98eb 100644 --- a/ebean-test/src/test/java/org/tests/draftable/DocLinkTest.java +++ b/ebean-test/src/test/java/org/tests/draftable/DocLinkTest.java @@ -24,7 +24,7 @@ public void testLazyLoadOnDraftProperty() { Link link1 = new Link("something"); link1.save(); - DB.getDefault().publish(Link.class, link1.getId()); + //DB.getDefault().publish(Link.class, link1.getId()); Link link = DB.find(Link.class) .setId(link1.getId()) @@ -50,7 +50,7 @@ public void testUpdate_whenNotPublished() { assertThat(link1.isDraft()).isFalse(); link1.save(); - assertThat(link1.isDraft()).isTrue(); + //assertThat(link1.isDraft()).isTrue(); // perform stateless update Link linkUpdate = new Link(); @@ -73,7 +73,7 @@ public void testDelete_whenNotPublished() { assertThat(link1.isDraft()).isFalse(); link1.save(); - assertThat(link1.isDraft()).isTrue(); + //assertThat(link1.isDraft()).isTrue(); link1.setComment("some change"); link1.save(); @@ -86,74 +86,36 @@ public void testDeletePermanent_whenPublished2() { Link link1 = new Link("Ld2"); link1.save(); - DB.getDefault().publish(Link.class, link1.getId()); + //DB.getDefault().publish(Link.class, link1.getId()); - Link link = DB.find(Link.class).setId(link1.getId()).asDraft().findOne(); + Link link = DB.find(Link.class).setId(link1.getId()).findOne(); //.asDraft() DB.deletePermanent(link); } - @Test - public void testDeleteLivePermanent_throwsException() { - - Link link1 = new Link("Ld2"); - link1.save(); - - Link live = DB.getDefault().publish(Link.class, link1.getId()); - - try { - DB.deletePermanent(live); - fail("never get here"); - - } catch (PersistenceException e) { - // assert nice message when trying to delete live bean - assertThat(e.getMessage()).contains("Explicit Delete is not allowed on a 'live' bean - only draft beans"); - } - } - @Test public void testDelete_whenPublished() { Link link1 = new Link("Ld2"); link1.save(); Database server = DB.getDefault(); - server.publish(Link.class, link1.getId()); + //server.publish(Link.class, link1.getId()); - link1 = DB.find(Link.class).setId(link1.getId()).asDraft().findOne(); - assertThat(link1.isDraft()).isTrue(); + link1 = DB.find(Link.class).setId(link1.getId()).findOne(); //.asDraft() + // assertThat(link1.isDraft()).isTrue(); // this is a soft delete (no automatic publish here, only updates draft) link1.delete(); Link live = DB.find(Link.class).setId(link1.getId()).findOne(); - assertThat(live).isNotNull(); - assertThat(live.isDraft()).isFalse(); - assertThat(live.isDeleted()).isFalse(); // soft delete state not published yet - - // this is a permanent delete (effectively has automatic publish) - server.deletePermanent(link1); - - live = DB.find(Link.class).setId(link1.getId()).findOne(); assertThat(live).isNull(); - } - - @Test - public void testUpdateLive_throwsException() { - - Link link1 = new Link("forUpdateLive"); - link1.save(); - - Link live = DB.getDefault().publish(Link.class, link1.getId()); - - live.setComment("foo"); - // Expect a nice - try { - live.save(); - fail("Never get here"); - - } catch (PersistenceException e) { - // we want to assert the message is nice and meaningful (and not a optimistic locking exception etc) - assertThat(e.getMessage()).contains("Save or update is not allowed on a 'live' bean - only draft beans"); - } +// //assertThat(live.isDraft()).isFalse(); +// assertThat(live.isDeleted()).isFalse(); // soft delete state not published yet +// +// // this is a permanent delete (effectively has automatic publish) +// server.deletePermanent(link1); +// +// live = DB.find(Link.class).setId(link1.getId()).findOne(); +// assertThat(live).isNull(); } @Test @@ -166,19 +128,19 @@ public void testDirtyState() { link1.setWhenPublish(when); link1.save(); - Link draft1 = DB.find(Link.class).setId(link1.getId()).asDraft().findOne(); - assertThat(draft1.isDirty()).isTrue(); + Link draft1 = DB.find(Link.class).setId(link1.getId()).findOne(); // .asDraft() + //assertThat(draft1.isDirty()).isTrue(); Database server = DB.getDefault(); - Link linkLive = server.publish(Link.class, link1.getId(), null); + Link linkLive = draft1;//server.publish(Link.class, link1.getId(), null); assertThat(linkLive.getComment()).isEqualTo(comment); assertThat(linkLive.getWhenPublish()).isEqualToIgnoringMillis(when); - Link draft1b = DB.find(Link.class).setId(link1.getId()).asDraft().findOne(); - assertThat(draft1b.isDirty()).isFalse(); - assertThat(draft1b.getComment()).isNull(); - assertThat(draft1b.getWhenPublish()).isNull(); +// Link draft1b = DB.find(Link.class).setId(link1.getId()).findOne(); // .asDraft() +// assertThat(draft1b.isDirty()).isFalse(); +// assertThat(draft1b.getComment()).isNull(); +// assertThat(draft1b.getWhenPublish()).isNull(); } @Test @@ -194,9 +156,9 @@ public void testSave() { link3.save(); Database server = DB.getDefault(); - server.publish(Link.class, link1.getId(), null); - server.publish(Link.class, link2.getId(), null); - server.publish(Link.class, link3.getId(), null); +// server.publish(Link.class, link1.getId(), null); +// server.publish(Link.class, link2.getId(), null); +// server.publish(Link.class, link3.getId(), null); Doc doc1 = new Doc("DocOne"); doc1.getLinks().add(link1); @@ -205,12 +167,12 @@ public void testSave() { Doc draftDoc1 = server.find(Doc.class) .setId(doc1.getId()) - .asDraft() + //.asDraft() .findOne(); assertThat(draftDoc1.getLinks()).hasSize(2); - Doc liveDoc1 = server.publish(Doc.class, doc1.getId(), null); + Doc liveDoc1 = doc1; // server.publish(Doc.class, doc1.getId(), null); assertThat(liveDoc1.getLinks()).hasSize(2); assertThat(liveDoc1.getLinks()).extracting("id").contains(link1.getId(), link2.getId()); @@ -223,7 +185,7 @@ public void testSave() { draftDoc1.save(); // publish with insert and delete of Links M2M relationship - Doc liveDoc2 = server.publish(Doc.class, doc1.getId(), null); + Doc liveDoc2 = draftDoc1;// server.publish(Doc.class, doc1.getId(), null); assertThat(liveDoc2.getLinks()).hasSize(2); assertThat(liveDoc2.getLinks()).extracting("id").contains(remaining.getId(), link3.getId()); @@ -241,25 +203,25 @@ public void testDraftRestore() { Database server = DB.getDefault(); - Link live = server.publish(Link.class, link1.getId(), null); + Link live = link1;//server.publish(Link.class, link1.getId(), null); assertThat(live.isDraft()).isFalse(); Link draftLink = DB.find(Link.class) .setId(link1.getId()) - .asDraft() + //.asDraft() .findOne(); draftLink.setLocation("secondLocation"); draftLink.save(); - server.draftRestore(Link.class, link1.getId(), null); + // server.draftRestore(Link.class, link1.getId(), null); draftLink = DB.find(Link.class) .setId(link1.getId()) - .asDraft() + //.asDraft() .findOne(); - assertThat(draftLink.getLocation()).isEqualTo("firstLocation"); + assertThat(draftLink.getLocation()).isEqualTo("secondLocation");//"firstLocation"); } @Test @@ -272,11 +234,11 @@ public void testDraftRestoreViaQuery() { Database server = DB.getDefault(); - server.publish(Link.class, link1.getId(), null); + //server.publish(Link.class, link1.getId(), null); Link draftLink = DB.find(Link.class) .setId(link1.getId()) - .asDraft() + //.asDraft() .findOne(); draftLink.setLocation("secondLocation"); @@ -284,11 +246,11 @@ public void testDraftRestoreViaQuery() { draftLink.save(); Query query = server.find(Link.class).where().eq("id", link1.getId()).query(); - List links = server.draftRestore(query); + List links = query.findList();//server.draftRestore(query); assertThat(links).hasSize(1); - assertThat(links.get(0).getLocation()).isEqualTo("firstLocation"); - assertThat(links.get(0).isDirty()).isEqualTo(false); - assertThat(links.get(0).getComment()).isNull(); + assertThat(links.get(0).getLocation()).isEqualTo("secondLocation");//"firstLocation"); + //assertThat(links.get(0).isDirty()).isEqualTo(false); + // assertThat(links.get(0).getComment()).isNull(); } } diff --git a/ebean-test/src/test/java/org/tests/draftable/LinkQueryPublishTest.java b/ebean-test/src/test/java/org/tests/draftable/LinkQueryPublishTest.java index 13540041c9..51c5b8780f 100644 --- a/ebean-test/src/test/java/org/tests/draftable/LinkQueryPublishTest.java +++ b/ebean-test/src/test/java/org/tests/draftable/LinkQueryPublishTest.java @@ -34,7 +34,7 @@ public void testPublishViaQuery() { ids.add(link3.getId()); PagedList pagedList = - server.find(Link.class).asDraft() + server.find(Link.class)//.asDraft() .where().idIn(ids) .setMaxRows(10) .findPagedList(); @@ -48,7 +48,7 @@ public void testPublishViaQuery() { .order().asc("id"); - List pubList = server.publish(pubQuery); + List pubList = pubQuery.findList(); // server.publish(pubQuery); assertThat(pubList).hasSize(3); assertThat(pubList).extracting("id").contains(link1.getId(), link2.getId(), link3.getId()); diff --git a/ebean-test/src/test/java/org/tests/draftable/OrganisationTest.java b/ebean-test/src/test/java/org/tests/draftable/OrganisationTest.java index f3ad2cb009..589b5065dd 100644 --- a/ebean-test/src/test/java/org/tests/draftable/OrganisationTest.java +++ b/ebean-test/src/test/java/org/tests/draftable/OrganisationTest.java @@ -37,25 +37,18 @@ public void testSave() { Database server = DB.getDefault(); Document draftDoc = server.find(Document.class) - .asDraft() + //.asDraft() .setId(doc.getId()) .findOne(); assertNotNull(draftDoc); - Document liveDoc = server.find(Document.class) - .setId(doc.getId()) - .findOne(); - assertNull(liveDoc); - - - server.publish(Document.class, doc.getId(), null); + //server.publish(Document.class, doc.getId(), null); doc.setTitle("Mod1"); doc.save(); - server.publish(Document.class, doc.getId(), null); - + //server.publish(Document.class, doc.getId(), null); } @@ -77,9 +70,9 @@ public void testSaveWithCascade() { Database server = DB.getDefault(); - server.publish(Document.class, doc.getId(), null); + //server.publish(Document.class, doc.getId(), null); - Document fetchDoc = DB.find(Document.class).setId(doc.getId()).asDraft().findOne(); + Document fetchDoc = DB.find(Document.class).setId(doc.getId()).findOne(); //.asDraft() List media = fetchDoc.getMedia(); assertThat(media.size()).isEqualTo(2); @@ -97,7 +90,7 @@ public void testSaveWithCascade() { // publish will perform an insert, update and delete on child DocumentMedia // during the publish below with media1 being deleted - Document liveBean = server.publish(Document.class, doc.getId(), null); + Document liveBean = doc;//server.publish(Document.class, doc.getId(), null); assertThat(liveBean.getBody()).isEqualTo("Body2"); assertThat(liveBean.getMedia().size()).isEqualTo(2); assertThat(liveBean.getMedia()).extracting("name").contains("media2", "media3"); diff --git a/ebean-test/src/test/java/org/tests/insert/TestInsertCheckUnique.java b/ebean-test/src/test/java/org/tests/insert/TestInsertCheckUnique.java index c7cf31b77c..71ac140edb 100644 --- a/ebean-test/src/test/java/org/tests/insert/TestInsertCheckUnique.java +++ b/ebean-test/src/test/java/org/tests/insert/TestInsertCheckUnique.java @@ -16,8 +16,10 @@ public class TestInsertCheckUnique extends BaseTestCase { @BeforeEach public void clearDb() { - DB.find(Document.class).asDraft().where().contains("title", "UniqueKey").delete(); - DB.find(Document.class).asDraft().where().isNull("title").delete(); + DB.find(Document.class)//.asDraft() + .where().contains("title", "UniqueKey").delete(); + DB.find(Document.class)//.asDraft() + .where().isNull("title").delete(); } @Test @@ -35,10 +37,6 @@ public void insert_duplicateKey() { doc2.setTitle("AUniqueKey_duplicateCheck"); doc2.setBody("clashes with doc1"); - assertThat(DB.checkUniqueness(doc2)).isEmpty(); - - DB.getDefault().publish(doc1.getClass(), doc1.getId()); - assertThat(DB.checkUniqueness(doc2).toString()).contains("title"); } } @@ -59,12 +57,11 @@ public void insert_duplicateNull() { assertThat(DB.checkUniqueness(doc2)).isEmpty(); - DB.getDefault().publish(doc1.getClass(), doc1.getId()); - - assertThat(DB.checkUniqueness(doc2)).isEmpty(); + //DB.getDefault().publish(doc1.getClass(), doc1.getId()); + //assertThat(DB.checkUniqueness(doc2)).isEmpty(); doc2.save(); - DB.getDefault().publish(doc2.getClass(), doc2.getId()); + //DB.getDefault().publish(doc2.getClass(), doc2.getId()); } } @@ -77,7 +74,7 @@ public void example() { doc1.setBody("one"); doc1.save(); - DB.getDefault().publish(doc1.getClass(), doc1.getId()); + //DB.getDefault().publish(doc1.getClass(), doc1.getId()); Document doc2 = new Document(); doc2.setTitle("One flew over the cuckoo's nest"); diff --git a/ebean-test/src/test/java/org/tests/insert/TestInsertDuplicateKey.java b/ebean-test/src/test/java/org/tests/insert/TestInsertDuplicateKey.java index b894d4de6a..cd74533e0d 100644 --- a/ebean-test/src/test/java/org/tests/insert/TestInsertDuplicateKey.java +++ b/ebean-test/src/test/java/org/tests/insert/TestInsertDuplicateKey.java @@ -21,7 +21,9 @@ public class TestInsertDuplicateKey extends BaseTestCase { @BeforeEach public void clearDb() { - server().find(Document.class).asDraft().where().contains("title", "UniqueKey").delete(); + server().find(Document.class) + //.asDraft() + .where().contains("title", "UniqueKey").delete(); } @Test @@ -64,7 +66,7 @@ public void insertBatch_duplicateKey_catchAndContinue() { List found = DB.getDefault() .find(Document.class) - .asDraft() + //.asDraft() .where().startsWith("body", "insertTheBatch_duplicateKey_catchAndContinue") .findList(); diff --git a/ebean-test/src/test/java/org/tests/model/draftable/Document.java b/ebean-test/src/test/java/org/tests/model/draftable/Document.java index 2652b22377..a6115c23e6 100644 --- a/ebean-test/src/test/java/org/tests/model/draftable/Document.java +++ b/ebean-test/src/test/java/org/tests/model/draftable/Document.java @@ -5,10 +5,7 @@ import io.ebean.annotation.DraftOnly; import io.ebean.annotation.Draftable; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; +import javax.persistence.*; import javax.validation.constraints.Size; import java.sql.Timestamp; import java.util.List; @@ -35,12 +32,8 @@ public class Document extends BaseDomain { @ManyToOne Organisation organisation; - /** - * Relationship to draftable elements. - */ - //@PrivateOwned - @OneToMany(mappedBy = "document")//, cascade = CascadeType.ALL) - List media; + @OneToMany(mappedBy = "document", cascade = CascadeType.ALL) + List media; public String getTitle() { return title; @@ -96,7 +89,7 @@ public static class DocumentFinder extends Finder { } public Document asDraft(Long id) { - return query().asDraft().setId(id).findOne(); + return query().setId(id).findOne(); //.asDraft() } } } diff --git a/ebean-test/src/test/java/org/tests/transaction/TestTransactionTryResources.java b/ebean-test/src/test/java/org/tests/transaction/TestTransactionTryResources.java index dce5451ec2..493321dcb4 100644 --- a/ebean-test/src/test/java/org/tests/transaction/TestTransactionTryResources.java +++ b/ebean-test/src/test/java/org/tests/transaction/TestTransactionTryResources.java @@ -34,7 +34,6 @@ public void tryWithResources_simple() { Document document = Document.find.asDraft(doc.getId()); assertThat(document).isNotNull(); - assertThat(document.isDraft()).isTrue(); // cleanup DB.delete(document); @@ -69,7 +68,6 @@ public void tryWithResources_catch() { List docs = Document.find.query() .where().startsWith("body", "tryWithResources_catch") - .asDraft() .findList(); assertThat(docs).hasSize(1);