/** * PUBLIC: * Define the source foreign key relationship in the one-to-many mapping. * This method is used for composite source foreign key relationships. * That is, the source object's table has multiple foreign key fields * that are references to * the target object's (typically primary) key fields. * Both the source foreign key field name and the corresponding * target primary key field name must be specified. */ @Override public void addForeignKeyField(DatabaseField sourceForeignKeyField, DatabaseField targetKeyField) { this.getSourceForeignKeyFields().add(sourceForeignKeyField); this.getTargetForeignKeyFields().add(targetKeyField); this.setIsForeignKeyRelationship(true); }
/** * PUBLIC: * Define the source foreign key relationship in the one-to-many mapping. * This method is used for composite source foreign key relationships. * That is, the source object's table has multiple foreign key fields * that are references to * the target object's (typically primary) key fields. * Both the source foreign key field name and the corresponding * target primary key field name must be specified. */ public void addForeignKeyField(DatabaseField sourceForeignKeyField, DatabaseField targetKeyField) { this.getSourceForeignKeyFields().add(sourceForeignKeyField); this.getTargetForeignKeyFields().add(targetKeyField); this.setIsForeignKeyRelationship(true); }
protected void initializeSourceForeignKeysToTargetKeys() throws DescriptorException { // Since we require a custom selection query, these keys are optional. if (getSourceForeignKeyFields().size() != getTargetForeignKeyFields().size()) { throw DescriptorException.sizeMismatchOfForeignKeys(this); } for (int i = 0; i < getTargetForeignKeyFields().size(); i++) { DatabaseField field = getReferenceDescriptor().buildField(getTargetForeignKeyFields().get(i)); getTargetForeignKeyFields().set(i, field); } for (int i = 0; i < getSourceForeignKeyFields().size(); i++) { DatabaseField field = getDescriptor().buildField(getSourceForeignKeyFields().get(i)); getSourceForeignKeyFields().set(i, field); getSourceForeignKeysToTargetKeys().put(field, getTargetForeignKeyFields().get(i)); } }
/** * PUBLIC: * Define the source foreign key relationship in the one-to-many mapping. * This method is used for composite source foreign key relationships. * That is, the source object's table has multiple foreign key fields * that are references to * the target object's (typically primary) key fields. * Both the source foreign key field name and the corresponding * target primary key field name must be specified. */ @Override public void addForeignKeyField(DatabaseField sourceForeignKeyField, DatabaseField targetKeyField) { this.getSourceForeignKeyFields().add(sourceForeignKeyField); this.getTargetForeignKeyFields().add(targetKeyField); this.setIsForeignKeyRelationship(true); }
protected void initializeSourceForeignKeysToTargetKeys() throws DescriptorException { // Since we require a custom selection query, these keys are optional. if (getSourceForeignKeyFields().size() != getTargetForeignKeyFields().size()) { throw DescriptorException.sizeMismatchOfForeignKeys(this); } for (int i = 0; i < getTargetForeignKeyFields().size(); i++) { DatabaseField field = getReferenceDescriptor().buildField(getTargetForeignKeyFields().get(i)); getTargetForeignKeyFields().set(i, field); } for (int i = 0; i < getSourceForeignKeyFields().size(); i++) { DatabaseField field = getDescriptor().buildField(getSourceForeignKeyFields().get(i)); getSourceForeignKeyFields().set(i, field); getSourceForeignKeysToTargetKeys().put(field, getTargetForeignKeyFields().get(i)); } }
protected void initializeSourceForeignKeysToTargetKeys() throws DescriptorException { // Since we require a custom selection query, these keys are optional. if (getSourceForeignKeyFields().size() != getTargetForeignKeyFields().size()) { throw DescriptorException.sizeMismatchOfForeignKeys(this); } for (int i = 0; i < getTargetForeignKeyFields().size(); i++) { DatabaseField field = getReferenceDescriptor().buildField((DatabaseField)getTargetForeignKeyFields().get(i)); getTargetForeignKeyFields().set(i, field); } for (int i = 0; i < getSourceForeignKeyFields().size(); i++) { DatabaseField field = getReferenceDescriptor().buildField((DatabaseField)getSourceForeignKeyFields().get(i)); getSourceForeignKeyFields().set(i, field); getSourceForeignKeysToTargetKeys().put(field, getTargetForeignKeyFields().get(i)); } }
/** * INTERNAL: */ public Vector getForeignKeyRows(AbstractRecord row, AbstractSession session) { Vector subRows = new Vector(); if (getForeignKeyGroupingElement() == null) { if (this.getSourceForeignKeyFields().size() > 0) { Object values = row.getValues(this.getSourceForeignKeyFields().get(0)); if (values != null) { if (values instanceof Vector) { int valuesSize = ((Vector)values).size(); for (int j = 0; j < valuesSize; j++) { AbstractRecord newRecord = this.descriptor.getObjectBuilder().createRecord(session); newRecord.put(this.getSourceForeignKeyFields().get(0), ((Vector)values).get(j)); subRows.add(newRecord); } } else { AbstractRecord newRecord = this.descriptor.getObjectBuilder().createRecord(session); newRecord.put(getSourceForeignKeyFields().get(0), values); subRows.add(newRecord); } } } } else { subRows = (Vector)row.getValues(getForeignKeyGroupingElement()); } return subRows; }
/** * INTERNAL: */ public Vector getForeignKeyRows(AbstractRecord row, AbstractSession session) { Vector subRows = new Vector(); if (getForeignKeyGroupingElement() == null) { if (this.getSourceForeignKeyFields().size() > 0) { Object values = row.getValues(this.getSourceForeignKeyFields().get(0)); if (values != null) { if (values instanceof Vector) { int valuesSize = ((Vector)values).size(); for (int j = 0; j < valuesSize; j++) { AbstractRecord newRecord = this.descriptor.getObjectBuilder().createRecord(session); newRecord.put(this.getSourceForeignKeyFields().get(0), ((Vector)values).get(j)); subRows.add(newRecord); } } else { AbstractRecord newRecord = this.descriptor.getObjectBuilder().createRecord(session); newRecord.put(getSourceForeignKeyFields().get(0), values); subRows.add(newRecord); } } } } else { subRows = (Vector)row.getValues(getForeignKeyGroupingElement()); } return subRows; }
/** * INTERNAL: * Write fields needed for insert into the template for with null values. */ @Override public void writeInsertFieldsIntoRow(AbstractRecord row, AbstractSession session) { if (isForeignKeyRelationship() && !isReadOnly()) { if (getForeignKeyGroupingElement() != null) { row.put(getForeignKeyGroupingElement(), null); } else if (this.getSourceForeignKeyFields().size() > 0) { row.put(getSourceForeignKeyFields().get(0), null); } } else { super.writeInsertFieldsIntoRow(row, session); } }
/** * INTERNAL: * This row is built for shallow insert which happens in case of bidirectional inserts. * The foreign keys must be set to null to avoid constraints. */ public void writeFromObjectIntoRowForShallowInsert(Object object, AbstractRecord row, AbstractSession session) { if (isForeignKeyRelationship() && !isReadOnly()) { if (getForeignKeyGroupingElement() != null) { row.put(getForeignKeyGroupingElement(), null); } else if (this.getSourceForeignKeyFields().size() > 0) { row.put(getSourceForeignKeyFields().get(0), null); } } else { super.writeFromObjectIntoRowForShallowInsert(object, row, session); } }
/** * INTERNAL: * Write fields needed for insert into the template for with null values. */ public void writeInsertFieldsIntoRow(AbstractRecord row, AbstractSession session) { if (isForeignKeyRelationship() && !isReadOnly()) { if (getForeignKeyGroupingElement() != null) { row.put(getForeignKeyGroupingElement(), null); } else if (this.getSourceForeignKeyFields().size() > 0) { row.put(getSourceForeignKeyFields().get(0), null); } } else { super.writeInsertFieldsIntoRow(row, session); } }
/** * INTERNAL: * This row is built for shallow insert which happens in case of bidirectional inserts. * The foreign keys must be set to null to avoid constraints. */ @Override public void writeFromObjectIntoRowForShallowInsert(Object object, AbstractRecord row, AbstractSession session) { if (isForeignKeyRelationship() && !isReadOnly()) { if (getForeignKeyGroupingElement() != null) { row.put(getForeignKeyGroupingElement(), null); } else if (this.getSourceForeignKeyFields().size() > 0) { row.put(getSourceForeignKeyFields().get(0), null); } } else { super.writeFromObjectIntoRowForShallowInsert(object, row, session); } }
/** * INTERNAL: * This row is built for shallow insert which happens in case of bidirectional inserts. * The foreign keys must be set to null to avoid constraints. */ @Override public void writeFromObjectIntoRowForShallowInsert(Object object, AbstractRecord row, AbstractSession session) { if (isForeignKeyRelationship() && !isReadOnly()) { if (getForeignKeyGroupingElement() != null) { row.put(getForeignKeyGroupingElement(), null); } else if (this.getSourceForeignKeyFields().size() > 0) { row.put(getSourceForeignKeyFields().get(0), null); } } else { super.writeFromObjectIntoRowForShallowInsert(object, row, session); } }
/** * INTERNAL: * This row is built for shallow insert which happens in case of bidirectional inserts. * The foreign keys must be set to null to avoid constraints. */ @Override public void writeFromObjectIntoRowForShallowInsertWithChangeRecord(ChangeRecord changeRecord, AbstractRecord row, AbstractSession session) { if (isForeignKeyRelationship() && !isReadOnly()) { if (getForeignKeyGroupingElement() != null) { row.put(getForeignKeyGroupingElement(), null); } else if (this.getSourceForeignKeyFields().size() > 0) { row.put(getSourceForeignKeyFields().get(0), null); } } else { super.writeFromObjectIntoRowForShallowInsertWithChangeRecord(changeRecord, row, session); } }
/** * INTERNAL: * Write fields needed for insert into the template for with null values. */ @Override public void writeInsertFieldsIntoRow(AbstractRecord row, AbstractSession session) { if (isForeignKeyRelationship() && !isReadOnly()) { if (getForeignKeyGroupingElement() != null) { row.put(getForeignKeyGroupingElement(), null); } else if (this.getSourceForeignKeyFields().size() > 0) { row.put(getSourceForeignKeyFields().get(0), null); } } else { super.writeInsertFieldsIntoRow(row, session); } }
/** * INTERNAL: * This row is built for shallow insert which happens in case of bidirectional inserts. * The foreign keys must be set to null to avoid constraints. */ public void writeFromObjectIntoRowForShallowInsertWithChangeRecord(ChangeRecord changeRecord, AbstractRecord row, AbstractSession session) { if (isForeignKeyRelationship() && !isReadOnly()) { if (getForeignKeyGroupingElement() != null) { row.put(getForeignKeyGroupingElement(), null); } else if (this.getSourceForeignKeyFields().size() > 0) { row.put(getSourceForeignKeyFields().get(0), null); } } else { super.writeFromObjectIntoRowForShallowInsertWithChangeRecord(changeRecord, row, session); } }
/** * INTERNAL: * This row is built for shallow insert which happens in case of bidirectional inserts. * The foreign keys must be set to null to avoid constraints. */ @Override public void writeFromObjectIntoRowForShallowInsertWithChangeRecord(ChangeRecord changeRecord, AbstractRecord row, AbstractSession session) { if (isForeignKeyRelationship() && !isReadOnly()) { if (getForeignKeyGroupingElement() != null) { row.put(getForeignKeyGroupingElement(), null); } else if (this.getSourceForeignKeyFields().size() > 0) { row.put(getSourceForeignKeyFields().get(0), null); } } else { super.writeFromObjectIntoRowForShallowInsertWithChangeRecord(changeRecord, row, session); } }
/** * INTERNAL: * This row is built for update after shallow insert which happens in case of bidirectional inserts. * It contains the foreign keys with non null values that were set to null for shallow insert. * If mapping overrides writeFromObjectIntoRowForShallowInsert method it must override this one, too. */ public void writeFromObjectIntoRowForUpdateAfterShallowInsert(Object object, AbstractRecord row, AbstractSession session, DatabaseTable table) { if (isReadOnly() || !isForeignKeyRelationship()) { return; } if (getForeignKeyGroupingElement() != null) { if (!getForeignKeyGroupingElement().getTable().equals(table)) { return; } } else if (this.getSourceForeignKeyFields().size() > 0) { if (!getSourceForeignKeyFields().get(0).getTable().equals(table)) { return; } } writeFromObjectIntoRow(object, row, session, WriteType.UPDATE); }
/** * INTERNAL: * This row is built for update after shallow insert which happens in case of bidirectional inserts. * It contains the foreign keys with non null values that were set to null for shallow insert. * If mapping overrides writeFromObjectIntoRowForShallowInsert method it must override this one, too. */ public void writeFromObjectIntoRowForUpdateAfterShallowInsert(Object object, AbstractRecord row, AbstractSession session, DatabaseTable table) { if (isReadOnly() || !isForeignKeyRelationship()) { return; } if (getForeignKeyGroupingElement() != null) { if (!getForeignKeyGroupingElement().getTable().equals(table)) { return; } } else if (this.getSourceForeignKeyFields().size() > 0) { if (!getSourceForeignKeyFields().get(0).getTable().equals(table)) { return; } } writeFromObjectIntoRow(object, row, session, WriteType.UPDATE); }
/** * Build and return a database row that contains a foreign key for the specified reference * object. This will be stored in the nested row(s). */ protected XMLRecord extractKeyRowFromReferenceObject(Object object, AbstractSession session, XMLRecord parentRecord) { Element newNode = XPathEngine.getInstance().createUnownedElement(parentRecord.getDOM(), getForeignKeyGroupingElement()); XMLRecord result = new DOMRecord(newNode); result.setSession(session); for (int i = 0; i < this.getSourceForeignKeyFields().size(); i++) { DatabaseField fkField = (DatabaseField)getSourceForeignKeyFields().get(i); if (object == null) { result.add(fkField, null); } else { DatabaseField pkField = (DatabaseField)this.getSourceForeignKeysToTargetKeys().get(fkField); Object value = this.getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(object, pkField, session); result.add(fkField, value); } } return result; }