public IntersectionRow buildManyDeleteChildren(EntityBean parentBean, List<Object> excludeDetailIds) { IntersectionRow row = new IntersectionRow(tableJoin.getTable(), targetDescriptor); if (excludeDetailIds != null && !excludeDetailIds.isEmpty()) { row.setExcludeIds(excludeDetailIds, getTargetDescriptor()); } buildExport(row, parentBean); return row; }
void deleteAssocManyIntersection(EntityBean bean, BeanPropertyAssocMany<?> many, Transaction t, boolean publish) { // delete all intersection rows for this bean IntersectionRow intRow = many.buildManyToManyDeleteChildren(bean, publish); SqlUpdate sqlDelete = intRow.createDeleteChildren(server); executeSqlUpdate(sqlDelete, t); }
@Override public void buildImport(IntersectionRow row, EntityBean other) { Object value = getIdValue(other); if (value == null) { String msg = "Foreign Key value null?"; throw new PersistenceException(msg); } row.put(localDbColumn, value); }
SqlUpdate sqlInsert = intRow.createInsert(server); persister.executeSqlUpdate(sqlInsert, transaction); SqlUpdate sqlDelete = intRow.createDelete(server, DeleteMode.HARD); persister.executeSqlUpdate(sqlDelete, transaction);
public SqlUpdate createDeleteChildren(SpiEbeanServer server) { BindParams bindParams = new BindParams(); StringBuilder sb = new StringBuilder(); sb.append("delete from ").append(tableName).append(" where "); setBindParams(bindParams, sb); return new DefaultSqlUpdate(server, sb.toString(), bindParams); }
public IntersectionRow buildManyToManyDeleteChildren(EntityBean parentBean, boolean publish) { String tableName = publish ? intersectionPublishTable : intersectionDraftTable; IntersectionRow row = new IntersectionRow(tableName); buildExport(row, parentBean); return row; }
/** * Delete the 'many' detail beans for a given parent bean. * <p> * For stateless updates this deletes details beans that are no longer in * the many - the excludeDetailIds holds the detail beans that are in the * collection (and should not be deleted). * </p> */ void deleteManyDetails(SpiTransaction t, BeanDescriptor<?> desc, EntityBean parentBean, BeanPropertyAssocMany<?> many, List<Object> excludeDetailIds, DeleteMode deleteMode) { if (many.getCascadeInfo().isDelete()) { // cascade delete the beans in the collection BeanDescriptor<?> targetDesc = many.getTargetDescriptor(); if (deleteMode.isHard() || targetDesc.isSoftDelete()) { if (targetDesc.isDeleteByStatement()) { // Just delete all the children with one statement IntersectionRow intRow = many.buildManyDeleteChildren(parentBean, excludeDetailIds); SqlUpdate sqlDelete = intRow.createDelete(server, deleteMode); executeSqlUpdate(sqlDelete, t); } else { // Delete recurse using the Id values of the children Object parentId = desc.getId(parentBean); List<Object> idsByParentId = many.findIdsByParentId(parentId, null, t, excludeDetailIds, deleteMode.isHard()); if (!idsByParentId.isEmpty()) { deleteChildrenById(t, targetDesc, idsByParentId, deleteMode); } } } } }
SpiSqlUpdate sqlInsert = intRow.createInsert(server); persister.executeOrQueue(sqlInsert, transaction, queue); SpiSqlUpdate sqlDelete = intRow.createDelete(server, DeleteMode.HARD); persister.executeOrQueue(sqlDelete, transaction, queue);
public SqlUpdate createDelete(SpiEbeanServer server, DeleteMode deleteMode) { BindParams bindParams = new BindParams(); StringBuilder sb = new StringBuilder(); if (deleteMode.isHard()) { sb.append("delete from ").append(tableName); } else { sb.append("update ").append(tableName).append(" set "); sb.append(targetDescriptor.getSoftDeleteDbSet()); } sb.append(" where "); int count = setBindParams(bindParams, sb); if (excludeIds != null) { IdInExpression idIn = new IdInExpression(excludeIds); DefaultExpressionRequest er = new DefaultExpressionRequest(excludeDescriptor); idIn.addSqlNoAlias(er); idIn.addBindValues(er); sb.append(" and not ( "); sb.append(er.getSql()); sb.append(" ) "); List<Object> bindValues = er.getBindValues(); for (Object bindValue : bindValues) { bindParams.setParameter(++count, bindValue); } } return new DefaultSqlUpdate(server, sb.toString(), bindParams); }
public IntersectionRow buildManyToManyMapBean(EntityBean parent, EntityBean other, boolean publish) { String tableName = publish ? intersectionPublishTable : intersectionDraftTable; IntersectionRow row = new IntersectionRow(tableName); buildExport(row, parent); buildImport(row, other); return row; }
/** * Delete the 'many' detail beans for a given parent bean. * <p> * For stateless updates this deletes details beans that are no longer in * the many - the excludeDetailIds holds the detail beans that are in the * collection (and should not be deleted). * </p> */ void deleteManyDetails(SpiTransaction t, BeanDescriptor<?> desc, EntityBean parentBean, BeanPropertyAssocMany<?> many, List<Object> excludeDetailIds, DeleteMode deleteMode) { if (many.getCascadeInfo().isDelete()) { // cascade delete the beans in the collection BeanDescriptor<?> targetDesc = many.getTargetDescriptor(); if (deleteMode.isHard() || targetDesc.isSoftDelete()) { if (targetDesc.isDeleteByStatement()) { // Just delete all the children with one statement IntersectionRow intRow = many.buildManyDeleteChildren(parentBean, excludeDetailIds); SqlUpdate sqlDelete = intRow.createDelete(server, deleteMode); executeSqlUpdate(sqlDelete, t); } else { // Delete recurse using the Id values of the children Object parentId = desc.getId(parentBean); List<Object> idsByParentId = many.findIdsByParentId(parentId, null, t, excludeDetailIds, deleteMode.isHard()); if (!idsByParentId.isEmpty()) { deleteChildrenById(t, targetDesc, idsByParentId, deleteMode); } } } } }
public IntersectionRow buildManyDeleteChildren(EntityBean parentBean, List<Object> excludeDetailIds) { IntersectionRow row = new IntersectionRow(tableJoin.getTable(), targetDescriptor); if (excludeDetailIds != null && !excludeDetailIds.isEmpty()) { row.setExcludeIds(excludeDetailIds, getTargetDescriptor()); } buildExport(row, parentBean); return row; }
@Override public void buildImport(IntersectionRow row, EntityBean other) { EntityBean embeddedId = (EntityBean) foreignAssocOne.getValue(other); if (embeddedId == null) { throw new PersistenceException("Foreign Key value null?"); } for (ImportedIdSimple anImported : imported) { Object scalarValue = anImported.foreignProperty.getValue(embeddedId); row.put(anImported.localDbColumn, scalarValue); } }
public SpiSqlUpdate createDeleteChildren(SpiEbeanServer server) { BindParams bindParams = new BindParams(); StringBuilder sb = new StringBuilder(); sb.append("delete from ").append(tableName).append(" where "); setBindParams(bindParams, sb); return new DefaultSqlUpdate(server, sb.toString(), bindParams); }
public IntersectionRow buildManyToManyDeleteChildren(EntityBean parentBean, boolean publish) { String tableName = publish ? intersectionPublishTable : intersectionDraftTable; IntersectionRow row = new IntersectionRow(tableName); buildExport(row, parentBean); return row; }
private SpiSqlUpdate deleteAllIntersection(EntityBean bean, BeanPropertyAssocMany<?> many, boolean publish) { IntersectionRow intRow = many.buildManyToManyDeleteChildren(bean, publish); return intRow.createDeleteChildren(server); }
private void buildExport(IntersectionRow row, EntityBean parentBean) { if (embeddedExportedProperties) { BeanProperty idProp = descriptor.getIdProperty(); parentBean = (EntityBean) idProp.getValue(parentBean); } for (ExportedProperty exportedProperty : exportedProperties) { Object val = exportedProperty.getValue(parentBean); String fkColumn = exportedProperty.getForeignDbColumn(); row.put(fkColumn, val); } }
public SpiSqlUpdate createDelete(SpiEbeanServer server, DeleteMode deleteMode) { BindParams bindParams = new BindParams(); StringBuilder sb = new StringBuilder(); if (deleteMode.isHard()) { sb.append("delete from ").append(tableName); } else { sb.append("update ").append(tableName).append(" set "); sb.append(targetDescriptor.getSoftDeleteDbSet()); } sb.append(" where "); int count = setBindParams(bindParams, sb); if (excludeIds != null) { IdInExpression idIn = new IdInExpression(excludeIds); DefaultExpressionRequest er = new DefaultExpressionRequest(excludeDescriptor); idIn.addSqlNoAlias(er); idIn.addBindValues(er); sb.append(" and not ( "); sb.append(er.getSql()); sb.append(" ) "); List<Object> bindValues = er.getBindValues(); for (Object bindValue : bindValues) { bindParams.setParameter(++count, bindValue); } } return new DefaultSqlUpdate(server, sb.toString(), bindParams); }
public IntersectionRow buildManyToManyMapBean(EntityBean parent, EntityBean other, boolean publish) { String tableName = publish ? intersectionPublishTable : intersectionDraftTable; IntersectionRow row = new IntersectionRow(tableName); buildExport(row, parent); buildImport(row, other); return row; }
@Override public void buildImport(IntersectionRow row, EntityBean other) { Object value = getIdValue(other); if (value == null) { String msg = "Foreign Key value null?"; throw new PersistenceException(msg); } row.put(localDbColumn, value); }