/** * INTERNAL: * Maintain for backward compatibility. * This is 'public' so StoredProcedureGenerator * does not have to use the custom query expressions. */ public Map getTargetForeignKeyToSourceKeys() { return getTargetForeignKeysToSourceKeys(); }
/** * INTERNAL: * Maintain for backward compatibility. * This is 'public' so StoredProcedureGenerator * does not have to use the custom query expressions. */ public Map getTargetForeignKeyToSourceKeys() { return getTargetForeignKeysToSourceKeys(); }
/** * INTERNAL: * Maintain for backward compatibility. * This is 'public' so StoredProcedureGenerator * does not have to use the custom query expressions. */ public Map getTargetForeignKeyToSourceKeys() { return getTargetForeignKeysToSourceKeys(); }
/** * INTERNAL: */ protected void prepareOneToManySelectionQuery(OneToManyMapping sourceMapping, AbstractSession session) { // Clone the mapping because in reality that is what we have, that // is, a 1-M mapping to each class of the hierarchy. OneToManyMapping oneToMany = (OneToManyMapping) sourceMapping.clone(); // Update the foreign key fields on the mapping. Basically, take the // table name off and let the descriptor figure it out. Vector<DatabaseField> targetForeignKeyFields = new Vector<DatabaseField>(); for (DatabaseField fkField : oneToMany.getTargetForeignKeysToSourceKeys().keySet()) { targetForeignKeyFields.add(new DatabaseField(fkField.getName())); } // Update our foreign key fields and clear the key maps. oneToMany.setTargetForeignKeyFields(targetForeignKeyFields); oneToMany.getTargetForeignKeysToSourceKeys().clear(); oneToMany.getSourceKeysToTargetForeignKeys().clear(); addSelectionQuery(oneToMany, sourceMapping, session); }
/** * Extract the key field values from the specified row. * Used for batch reading. Keep the fields in the same order * as in the targetForeignKeysToSourceKeys hashtable. */ protected Vector extractPrimaryKeyFromRow(AbstractRecord row, AbstractSession session) { Vector key = new Vector(this.getTargetForeignKeysToSourceKeys().size()); for (Iterator stream = getTargetForeignKeysToSourceKeys().values().iterator(); stream.hasNext();) { DatabaseField field = (DatabaseField)stream.next(); Object value = row.get(field); // Must ensure the classification to get a cache hit. try { value = session.getDatasourcePlatform().convertObject(value, getDescriptor().getObjectBuilder().getFieldClassification(field)); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, getDescriptor(), e); } key.addElement(value); } return key; }
/** * The selection criteria are created with target foreign keys and source "primary" keys. * These criteria are then used to read the target records from the table. * These criteria are also used as the default "delete all" criteria. * * CR#3922 - This method is almost the same as buildSelectionCriteria() the difference * is that TargetForeignKeysToSourceKeys contains more information after login then SourceKeyFields * contains before login. */ protected Expression buildDefaultSelectionCriteriaAndAddFieldsToQuery() { Expression selectionCriteria = null; Expression builder = new ExpressionBuilder(); for (Iterator keys = getTargetForeignKeysToSourceKeys().keySet().iterator(); keys.hasNext();) { DatabaseField targetForeignKey = (DatabaseField)keys.next(); DatabaseField sourceKey = getTargetForeignKeysToSourceKeys().get(targetForeignKey); Expression partialSelectionCriteria = builder.getField(targetForeignKey).equal(builder.getParameter(sourceKey)); selectionCriteria = partialSelectionCriteria.and(selectionCriteria); } getContainerPolicy().addAdditionalFieldsToQuery(getSelectionQuery(), builder); return selectionCriteria; }
/** * The selection criteria are created with target foreign keys and source "primary" keys. * These criteria are then used to read the target records from the table. * These criteria are also used as the default "delete all" criteria. * * CR#3922 - This method is almost the same as buildSelectionCriteria() the difference * is that TargetForeignKeysToSourceKeys contains more information after login then SourceKeyFields * contains before login. */ protected Expression buildDefaultSelectionCriteriaAndAddFieldsToQuery() { Expression selectionCriteria = null; Expression builder = new ExpressionBuilder(); for (Iterator keys = getTargetForeignKeysToSourceKeys().keySet().iterator(); keys.hasNext();) { DatabaseField targetForeignKey = (DatabaseField)keys.next(); DatabaseField sourceKey = getTargetForeignKeysToSourceKeys().get(targetForeignKey); Expression partialSelectionCriteria = builder.getField(targetForeignKey).equal(builder.getParameter(sourceKey)); selectionCriteria = partialSelectionCriteria.and(selectionCriteria); } getContainerPolicy().addAdditionalFieldsToQuery(getSelectionQuery(), builder); return selectionCriteria; }
/** * The selection criteria are created with target foreign keys and source "primary" keys. * These criteria are then used to read the target records from the table. * These criteria are also used as the default "delete all" criteria. * * CR#3922 - This method is almost the same as buildSelectionCriteria() the difference * is that TargetForeignKeysToSourceKeys contains more information after login then SourceKeyFields * contains before login. */ protected Expression buildDefaultSelectionCriteriaAndAddFieldsToQuery() { Expression selectionCriteria = null; Expression builder = new ExpressionBuilder(); for (Iterator keys = getTargetForeignKeysToSourceKeys().keySet().iterator(); keys.hasNext();) { DatabaseField targetForeignKey = (DatabaseField)keys.next(); DatabaseField sourceKey = getTargetForeignKeysToSourceKeys().get(targetForeignKey); Expression partialSelectionCriteria = builder.getField(targetForeignKey).equal(builder.getParameter(sourceKey)); selectionCriteria = partialSelectionCriteria.and(selectionCriteria); } getContainerPolicy().addAdditionalFieldsToQuery(getSelectionQuery(), builder); return selectionCriteria; }
/** * Extract the foreign key value from the reference object. * Used for batch reading. Keep the fields in the same order * as in the targetForeignKeysToSourceKeys hashtable. */ protected Vector extractForeignKeyFromReferenceObject(Object object, AbstractSession session) { Vector foreignKey = new Vector(this.getTargetForeignKeysToSourceKeys().size()); for (Iterator stream = getTargetForeignKeysToSourceKeys().entrySet().iterator(); stream.hasNext();) { Map.Entry entry = (Map.Entry)stream.next(); DatabaseField targetField = (DatabaseField)entry.getKey(); DatabaseField sourceField = (DatabaseField)entry.getValue(); if (object == null) { foreignKey.addElement(null); } else { Object value = getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(object, targetField, session); //CR:somenewsgroupbug need to ensure source and target types match. try { value = session.getDatasourcePlatform().convertObject(value, getDescriptor().getObjectBuilder().getFieldClassification(sourceField)); } catch (ConversionException e) { throw ConversionException.couldNotBeConverted(this, getDescriptor(), e); } foreignKey.addElement(value); } } return foreignKey; }
/** * INTERNAL: * Clone the appropriate attributes. */ public Object clone() { OneToManyMapping clone = (OneToManyMapping)super.clone(); clone.setTargetForeignKeysToSourceKeys(new HashMap(getTargetForeignKeysToSourceKeys())); clone.addTargetQuery = (DataModifyQuery) this.addTargetQuery.clone(); clone.removeTargetQuery = (DataModifyQuery) this.removeTargetQuery.clone(); clone.removeAllTargetsQuery = (DataModifyQuery) this.removeAllTargetsQuery.clone(); return clone; }
/** * INTERNAL: * Clone the appropriate attributes. */ @Override public Object clone() { OneToManyMapping clone = (OneToManyMapping)super.clone(); clone.setTargetForeignKeysToSourceKeys(new HashMap(getTargetForeignKeysToSourceKeys())); if (addTargetQuery != null){ clone.addTargetQuery = (DataModifyQuery) this.addTargetQuery.clone(); } clone.removeTargetQuery = (DataModifyQuery) this.removeTargetQuery.clone(); clone.removeAllTargetsQuery = (DataModifyQuery) this.removeAllTargetsQuery.clone(); return clone; }
/** * INTERNAL: * Clone the appropriate attributes. */ @Override public Object clone() { OneToManyMapping clone = (OneToManyMapping)super.clone(); clone.setTargetForeignKeysToSourceKeys(new HashMap(getTargetForeignKeysToSourceKeys())); if (addTargetQuery != null){ clone.addTargetQuery = (DataModifyQuery) this.addTargetQuery.clone(); } clone.removeTargetQuery = (DataModifyQuery) this.removeTargetQuery.clone(); clone.removeAllTargetsQuery = (DataModifyQuery) this.removeAllTargetsQuery.clone(); return clone; }
DatabaseField targetForeignKey = targetForeignKeys.next(); DatabaseField sourcePrimaryKey = sourceKeys.next(); getTargetForeignKeysToSourceKeys().put(targetForeignKey, sourcePrimaryKey); getSourceKeysToTargetForeignKeys().put(sourcePrimaryKey, targetForeignKey);
DatabaseField targetForeignKey = targetForeignKeys.next(); DatabaseField sourcePrimaryKey = sourceKeys.next(); getTargetForeignKeysToSourceKeys().put(targetForeignKey, sourcePrimaryKey); getSourceKeysToTargetForeignKeys().put(sourcePrimaryKey, targetForeignKey);
DatabaseField targetForeignKey = targetForeignKeys.next(); DatabaseField sourcePrimaryKey = sourceKeys.next(); getTargetForeignKeysToSourceKeys().put(targetForeignKey, sourcePrimaryKey); getSourceKeysToTargetForeignKeys().put(sourcePrimaryKey, targetForeignKey);
private void addForeignKeyFieldToSourceTargetTable(OneToManyMapping mapping) { addForeignMappingFkConstraint(mapping.getTargetForeignKeysToSourceKeys()); if(mapping.getListOrderField() != null) { getTableDefFromDBTable(mapping.getListOrderField().getTable()).addField(getFieldDefFromDBField(mapping.getListOrderField(), false)); } }
protected void addForeignKeyFieldToSourceTargetTable(OneToManyMapping mapping) { if (mapping.getDescriptor().hasTablePerClassPolicy()) { return; } addForeignMappingFkConstraint(mapping.getTargetForeignKeysToSourceKeys(), mapping.isCascadeOnDeleteSetOnDatabase()); if (mapping.getListOrderField() != null) { FieldDefinition fieldDef = getFieldDefFromDBField(mapping.getListOrderField()); TableDefinition table = getTableDefFromDBTable(mapping.getListOrderField().getTable()); if (!table.getFields().contains(fieldDef)) { table.addField(fieldDef); } } }
protected void addForeignKeyFieldToSourceTargetTable(OneToManyMapping mapping) { if (mapping.getDescriptor().hasTablePerClassPolicy()) { return; } addForeignMappingFkConstraint(mapping.getTargetForeignKeysToSourceKeys(), mapping.isCascadeOnDeleteSetOnDatabase()); if (mapping.getListOrderField() != null) { FieldDefinition fieldDef = getFieldDefFromDBField(mapping.getListOrderField()); TableDefinition table = getTableDefFromDBTable(mapping.getListOrderField().getTable()); if (!table.getFields().contains(fieldDef)) { table.addField(fieldDef); } } }