public boolean isIncludeCascadeSave() { // Note ManyToMany always included as we always 'save' // the relationship via insert/delete of intersection table // REMOVALS means including PrivateOwned relationships return cascadeInfo.isSave() || hasJoinTable() || ModifyListenMode.REMOVALS == modifyListenMode; }
@Override public void addSelectExported(DbSqlContext ctx, String tableAlias) { String alias = hasJoinTable() ? "int_" : tableAlias; if (alias == null) { alias = "t0"; } for (ExportedProperty exportedProperty : exportedProperties) { ctx.appendColumn(alias, exportedProperty.getForeignDbColumn()); } }
if (hasJoinTable()) { sb.append(query.isAsDraft() ? intersectionDraftTable : intersectionPublishTable); } else { sb.append(targetDescriptor.getBaseTable(query.getTemporalMode())); if (softDelete && hasJoinTable()) { sb.append(" x join "); sb.append(targetDescriptor.getBaseTable(query.getTemporalMode())); String alias = hasJoinTable() ? "x2" : "x"; sb.append(" and ").append(targetDescriptor.getSoftDeletePredicate(alias));
/** * Find the matching foreignDbColumn for a given local property. */ private ExportedProperty findMatch(boolean embedded, BeanProperty prop) { if (hasJoinTable()) { // look for column going to intersection return findMatch(embedded, prop, prop.getDbColumn(), intersectionJoin); } else { return findMatch(embedded, prop, prop.getDbColumn(), tableJoin); } }
@Override public void visitMany(BeanPropertyAssocMany<?> p) { if (p.hasJoinTable() && p.getMappedBy() == null) { // only create on other 'owning' side // build the create table and fkey constraints // putting the DDL into ctx for later output as we are // in the middle of rendering the create table DDL MTable intersectionTable = new ModelBuildIntersectionTable(ctx, p).build(); if (p.isO2mJoinTable()) { intersectionTable.clearForeignKeyIndexes(); Collection<MColumn> cols = intersectionTable.allColumns(); if (cols.size() == 2) { // always the second column that we put the unique constraint on MColumn col = new ArrayList<>(cols).get(1); col.setUnique(determineUniqueConstraintName(col.getName())); } } } else if (p.isElementCollection()) { ModelBuildElementTable.build(ctx, p); } }
EntityBean detail = (EntityBean) detailBean; EntityBeanIntercept ebi = detail._ebean_getIntercept(); if (many.hasJoinTable()) { skipSavingThisBean = targetDescriptor.isReference(ebi); } else {
BeanPropertyAssocManySqlHelp(BeanPropertyAssocMany<T> many, ExportedProperty[] exportedProperties) { this.many = many; this.exportedProperties = exportedProperties; this.hasJoinTable = many.hasJoinTable(); this.descriptor = many.getBeanDescriptor(); this.exportedPropertyBindProto = deriveExportedPropertyBindProto(); String delStmt; if (hasJoinTable) { delStmt = "delete from " + many.inverseJoin.getTable() + " where "; } else { delStmt = "delete from " + many.targetTable() + " where "; } deleteByParentIdSql = delStmt + deriveWhereParentIdSql(false, ""); deleteByParentIdInSql = delStmt + deriveWhereParentIdSql(true, ""); if (many.isElementCollection()) { elementCollectionInsertSql = elementCollectionInsert(); } else { elementCollectionInsertSql = null; } }
private void initialiseAssocMany() { if (!isTransient) { this.help = BeanCollectionHelpFactory.create(this); if (hasJoinTable() || elementCollection) { importedId = createImportedId(this, targetDescriptor, tableJoin); } else { // find the property in the many that matches // back to the master (Order in the OrderDetail bean) childMasterProperty = initChildMasterProperty(); if (childMasterProperty != null) { childMasterProperty.setRelationshipProperty(this); } } if (mapKey != null) { mapKeyProperty = initMapKeyProperty(); } exportedProperties = createExported(); this.sqlHelp = new BeanPropertyAssocManySqlHelp<>(this, exportedProperties); if (exportedProperties.length > 0) { embeddedExportedProperties = exportedProperties[0].isEmbedded(); if (fetchOrderBy != null) { lazyFetchOrderBy = sqlHelp.lazyFetchOrderBy(fetchOrderBy); } } } }
@Override void save() { if (many.hasJoinTable()) { // check if we can save the m2m intersection in this direction // we only allow one direction based on first traversed basis boolean saveIntersectionFromThisDirection = isSaveIntersection(); if (cascade) { saveAssocManyDetails(false); } // for ManyToMany save the 'relationship' via inserts/deletes // into/from the intersection table if (saveIntersectionFromThisDirection) { // only allowed on one direction of a m2m based on beanName saveAssocManyIntersection(request.isDeleteMissingChildren()); } else { resetModifyState(); } } else { if (isModifyListenMode()) { // delete any removed beans via private owned. Needs to occur before // a 'deleteMissingChildren' statement occurs removeAssocManyPrivateOwned(); } if (cascade) { // potentially deletes 'missing children' for 'stateless update' saveAssocManyDetails(request.isDeleteMissingChildren()); } } }
public boolean isIncludeCascadeSave() { // Note ManyToMany always included as we always 'save' // the relationship via insert/delete of intersection table // REMOVALS means including PrivateOwned relationships return cascadeInfo.isSave() || hasJoinTable() || ModifyListenMode.REMOVALS == modifyListenMode; }
@Override public void addSelectExported(DbSqlContext ctx, String tableAlias) { String alias = hasJoinTable() ? "int_" : tableAlias; if (alias == null) { alias = "t0"; } for (ExportedProperty exportedProperty : exportedProperties) { ctx.appendColumn(alias, exportedProperty.getForeignDbColumn()); } }
if (many.hasJoinTable()) { if (deleteMode.isHard()) {
if (hasJoinTable()) { sb.append(query.isAsDraft() ? intersectionDraftTable : intersectionPublishTable); } else { sb.append(targetDescriptor.getBaseTable(query.getTemporalMode())); if (softDelete && hasJoinTable()) { sb.append(" x join "); sb.append(targetDescriptor.getBaseTable(query.getTemporalMode())); String alias = hasJoinTable() ? "x2" : "x"; sb.append(" and ").append(targetDescriptor.getSoftDeletePredicate(alias));
/** * Find the matching foreignDbColumn for a given local property. */ private ExportedProperty findMatch(boolean embedded, BeanProperty prop) { if (hasJoinTable()) { // look for column going to intersection return findMatch(embedded, prop, prop.getDbColumn(), intersectionJoin); } else { return findMatch(embedded, prop, prop.getDbColumn(), tableJoin); } }
@Override public void visitMany(BeanPropertyAssocMany<?> p) { if (p.hasJoinTable() && p.getMappedBy() == null) { // only create on other 'owning' side // build the create table and fkey constraints // putting the DDL into ctx for later output as we are // in the middle of rendering the create table DDL MTable intersectionTable = new ModelBuildIntersectionTable(ctx, p).build(); if (p.isO2mJoinTable()) { intersectionTable.clearForeignKeyIndexes(); Collection<MColumn> cols = intersectionTable.allColumns(); if (cols.size() == 2) { // always the second column that we put the unique constraint on MColumn col = new ArrayList<>(cols).get(1); col.setUnique(determineUniqueConstraintName(col.getName())); } } } else if (p.isElementCollection()) { ModelBuildElementTable.build(ctx, p); } }
EntityBean detail = (EntityBean) detailBean; EntityBeanIntercept ebi = detail._ebean_getIntercept(); if (many.hasJoinTable()) { skipSavingThisBean = targetDescriptor.isReference(ebi); } else {
BeanPropertyAssocManySqlHelp(BeanPropertyAssocMany<T> many, ExportedProperty[] exportedProperties) { this.many = many; this.exportedProperties = exportedProperties; this.hasJoinTable = many.hasJoinTable(); this.descriptor = many.getBeanDescriptor(); this.exportedPropertyBindProto = deriveExportedPropertyBindProto(); String delStmt; if (hasJoinTable) { delStmt = "delete from " + many.inverseJoin.getTable() + " where "; } else { delStmt = "delete from " + many.targetTable() + " where "; } deleteByParentIdSql = delStmt + deriveWhereParentIdSql(false, ""); deleteByParentIdInSql = delStmt + deriveWhereParentIdSql(true, ""); if (many.isElementCollection()) { elementCollectionInsertSql = elementCollectionInsert(); } else { elementCollectionInsertSql = null; } }
private void initialiseAssocMany() { if (!isTransient) { this.help = BeanCollectionHelpFactory.create(this); if (hasJoinTable() || elementCollection) { importedId = createImportedId(this, targetDescriptor, tableJoin); } else { // find the property in the many that matches // back to the master (Order in the OrderDetail bean) childMasterProperty = initChildMasterProperty(); if (childMasterProperty != null) { childMasterProperty.setRelationshipProperty(this); } } if (mapKey != null) { mapKeyProperty = initMapKeyProperty(); } exportedProperties = createExported(); this.sqlHelp = new BeanPropertyAssocManySqlHelp<>(this, exportedProperties); if (exportedProperties.length > 0) { embeddedExportedProperties = exportedProperties[0].isEmbedded(); if (fetchOrderBy != null) { lazyFetchOrderBy = sqlHelp.lazyFetchOrderBy(fetchOrderBy); } } } }
@Override void save() { if (many.hasJoinTable()) { // check if we can save the m2m intersection in this direction // we only allow one direction based on first traversed basis boolean saveIntersectionFromThisDirection = isSaveIntersection(); if (cascade) { saveAssocManyDetails(false); } // for ManyToMany save the 'relationship' via inserts/deletes // into/from the intersection table if (saveIntersectionFromThisDirection) { // only allowed on one direction of a m2m based on beanName saveAssocManyIntersection(request.isDeleteMissingChildren()); } else { resetModifyState(); } } else { if (isModifyListenMode()) { // delete any removed beans via private owned. Needs to occur before // a 'deleteMissingChildren' statement occurs removeAssocManyPrivateOwned(); } if (cascade) { // potentially deletes 'missing children' for 'stateless update' saveAssocManyDetails(request.isDeleteMissingChildren()); } } }
if (many.hasJoinTable()) { if (deleteMode.isHard()) {