/** * 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(); }
/** * 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()); } }
/** * 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; }
/** * 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"); } }
/** * 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()); } }
public MTable build() { intersectionTable = createTable(); MTable existingTable = ctx.addTable(intersectionTable); if (existingTable != null) { throw new IllegalStateException("Property " + manyProp.getFullBeanName() + " has duplicate ManyToMany intersection table " + intersectionTable.getName() + ". Please use @JoinTable to define unique table to use"); } buildFkConstraints(); if (manyProp.getTargetDescriptor().isDraftable()) { ctx.createDraft(intersectionTable, false); } return intersectionTable; }
/** * 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; }
private void logSummary() { String draft = (beanDescriptor.isDraftable() && !publish) ? " draft[true]" : ""; String name = beanDescriptor.getName(); switch (type) { case INSERT: transaction.logSummary("Inserted [" + name + "] [" + idValue + "]" + draft); break; case UPDATE: transaction.logSummary("Updated [" + name + "] [" + idValue + "]" + draft); break; case DELETE: transaction.logSummary("Deleted [" + name + "] [" + idValue + "]" + draft); break; case DELETE_SOFT: transaction.logSummary("SoftDelete [" + name + "] [" + idValue + "]" + draft); break; default: break; } }
DeleteMeta(boolean emptyStringAsNull, BeanDescriptor<?> desc, BindableId id, Bindable version, Bindable tenantId) { this.emptyStringAsNull = emptyStringAsNull; this.tableName = desc.getBaseTable(); this.id = id; this.version = version; this.tenantId = tenantId; String tableName = desc.getBaseTable(); this.sqlNone = genSql(ConcurrencyMode.NONE, tableName); this.sqlVersion = genSql(ConcurrencyMode.VERSION, tableName); if (desc.isDraftable()) { String draftTableName = desc.getDraftTable(); this.sqlDraftNone = genSql(ConcurrencyMode.NONE, draftTableName); this.sqlDraftVersion = genSql(ConcurrencyMode.VERSION, draftTableName); } else { this.sqlDraftNone = sqlNone; this.sqlDraftVersion = sqlVersion; } }
/** * 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(); }
/** * Return true if the bean type is a Draftable. */ public boolean isDraftable() { return beanDescriptor.isDraftable(); }
/** * Transfer the values from the draftBean to the liveBean. * <p> * This will recursive transfer values to all @DraftableElement properties. * </p> */ @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.getIdProperty(); if (idProperty != null) { idProperty.publish(draft, live); } BeanProperty[] props = desc.propertiesNonMany(); for (BeanProperty prop : props) { prop.publish(draft, live); } BeanPropertyAssocMany<?>[] many = desc.propertiesMany(); for (BeanPropertyAssocMany<?> aMany : many) { if (aMany.getTargetDescriptor().isDraftable()) { aMany.publishMany(draft, live); } } return liveBean; }
this.sqlDraftWithId = desc.isDraftable() ? genSql(false, draftTableName, true) : sqlWithId; this.sqlDraftNullId = desc.isDraftable() ? genSql(true, draftTableName, true) : sqlNullId;
/** * 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"); } }
public MTable build() { intersectionTable = createTable(); MTable existingTable = ctx.addTable(intersectionTable); if (existingTable != null) { throw new IllegalStateException("Property " + manyProp.getFullBeanName() + " has duplicate ManyToMany intersection table " + intersectionTable.getName() + ". Please use @JoinTable to define unique table to use"); } buildFkConstraints(); if (manyProp.getTargetDescriptor().isDraftable()) { ctx.createDraft(intersectionTable, false); } return intersectionTable; }
private void logSummary() { String draft = (beanDescriptor.isDraftable() && !publish) ? " draft[true]" : ""; String name = beanDescriptor.getName(); switch (type) { case INSERT: transaction.logSummary("Inserted [" + name + "] [" + idValue + "]" + draft); break; case UPDATE: transaction.logSummary("Updated [" + name + "] [" + idValue + "]" + draft); break; case DELETE: transaction.logSummary("Deleted [" + name + "] [" + idValue + "]" + draft); break; case DELETE_SOFT: transaction.logSummary("SoftDelete [" + name + "] [" + idValue + "]" + draft); break; default: break; } }
DeleteMeta(boolean emptyStringAsNull, BeanDescriptor<?> desc, BindableId id, Bindable version, Bindable tenantId) { this.emptyStringAsNull = emptyStringAsNull; this.tableName = desc.getBaseTable(); this.id = id; this.version = version; this.tenantId = tenantId; String tableName = desc.getBaseTable(); this.sqlNone = genSql(ConcurrencyMode.NONE, tableName); this.sqlVersion = genSql(ConcurrencyMode.VERSION, tableName); if (desc.isDraftable()) { String draftTableName = desc.getDraftTable(); this.sqlDraftNone = genSql(ConcurrencyMode.NONE, draftTableName); this.sqlDraftVersion = genSql(ConcurrencyMode.VERSION, draftTableName); } else { this.sqlDraftNone = sqlNone; this.sqlDraftVersion = sqlVersion; } }
/** * Transfer the values from the draftBean to the liveBean. * <p> * This will recursive transfer values to all @DraftableElement properties. * </p> */ @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.getIdProperty(); if (idProperty != null) { idProperty.publish(draft, live); } BeanProperty[] props = desc.propertiesNonMany(); for (BeanProperty prop : props) { prop.publish(draft, live); } BeanPropertyAssocMany<?>[] many = desc.propertiesMany(); for (BeanPropertyAssocMany<?> aMany : many) { if (aMany.getTargetDescriptor().isDraftable()) { aMany.publishMany(draft, live); } } return liveBean; }
this.sqlDraftWithId = desc.isDraftable() ? genSql(false, draftTableName, true) : sqlWithId; this.sqlDraftNullId = desc.isDraftable() ? genSql(true, draftTableName, true) : sqlNullId;