/** * INTERNAL: * Return all the source relation key fields associated with the mapping. */ public Vector<DatabaseField> getSourceRelationKeyFields() { return this.mechanism.getSourceRelationKeyFields(); }
/** * INTERNAL: * Return all the source relation key fields associated with the mapping. */ public Vector<DatabaseField> getSourceRelationKeyFields() { return this.mechanism.getSourceRelationKeyFields(); }
/** * INTERNAL: * Return all the source relation key fields associated with the mapping. */ public Vector<DatabaseField> getSourceRelationKeyFields() { return this.mechanism.getSourceRelationKeyFields(); }
/** * PUBLIC: * Return the source relation key field names associated with the mapping. * These are in-order with the sourceKeyFieldNames. */ public Vector getSourceRelationKeyFieldNames() { Vector fieldNames = new Vector(getSourceRelationKeyFields().size()); for (Enumeration fieldsEnum = getSourceRelationKeyFields().elements(); fieldsEnum.hasMoreElements();) { fieldNames.addElement(((DatabaseField)fieldsEnum.nextElement()).getQualifiedName()); } return fieldNames; }
/** * PUBLIC: * Return the source relation key field names associated with the mapping. * These are in-order with the sourceKeyFieldNames. */ public Vector getSourceRelationKeyFieldNames() { Vector fieldNames = new Vector(getSourceRelationKeyFields().size()); for (Enumeration fieldsEnum = getSourceRelationKeyFields().elements(); fieldsEnum.hasMoreElements();) { fieldNames.addElement(((DatabaseField)fieldsEnum.nextElement()).getQualifiedName()); } return fieldNames; }
/** * PUBLIC: * Return the source relation key field names associated with the mapping. * These are in-order with the sourceKeyFieldNames. */ public Vector getSourceRelationKeyFieldNames() { Vector fieldNames = new Vector(getSourceRelationKeyFields().size()); for (Enumeration fieldsEnum = getSourceRelationKeyFields().elements(); fieldsEnum.hasMoreElements();) { fieldNames.addElement(((DatabaseField)fieldsEnum.nextElement()).getQualifiedName()); } return fieldNames; }
/** * PUBLIC: * Set the source key field in the relation table. * This is the name of the foreign key in the relation table to the source's primary key field. * This method is used if the source primary key is a singleton only. */ public void setSourceRelationKeyFieldName(String sourceRelationKeyFieldName) { getSourceRelationKeyFields().addElement(new DatabaseField(sourceRelationKeyFieldName)); }
/** * PUBLIC: * Set the source key field in the relation table. * This is the name of the foreign key in the relation table to the source's primary key field. * This method is used if the source primary key is a singleton only. */ public void setSourceRelationKeyFieldName(String sourceRelationKeyFieldName) { getSourceRelationKeyFields().addElement(new DatabaseField(sourceRelationKeyFieldName)); }
/** * PUBLIC: * Set the source key field in the relation table. * This is the name of the foreign key in the relation table to the source's primary key field. * This method is used if the source primary key is a singleton only. */ public void setSourceRelationKeyFieldName(String sourceRelationKeyFieldName) { getSourceRelationKeyFields().addElement(new DatabaseField(sourceRelationKeyFieldName)); }
/** * PUBLIC: * Add the fields in the intermediate table that corresponds to the primary * key in the source table. This method is used if the keys are composite. */ public void addSourceRelationKeyField(DatabaseField sourceRelationKeyField, DatabaseField sourcePrimaryKeyField) { getSourceRelationKeyFields().addElement(sourceRelationKeyField); getSourceKeyFields().addElement(sourcePrimaryKeyField); }
/** * PUBLIC: * Add the fields in the intermediate table that corresponds to the primary * key in the source table. This method is used if the keys are composite. */ public void addSourceRelationKeyField(DatabaseField sourceRelationKeyField, DatabaseField sourcePrimaryKeyField) { getSourceRelationKeyFields().addElement(sourceRelationKeyField); getSourceKeyFields().addElement(sourcePrimaryKeyField); }
/** * PUBLIC: * Add the fields in the intermediate table that corresponds to the primary * key in the source table. This method is used if the keys are composite. */ public void addSourceRelationKeyField(DatabaseField sourceRelationKeyField, DatabaseField sourcePrimaryKeyField) { getSourceRelationKeyFields().addElement(sourceRelationKeyField); getSourceKeyFields().addElement(sourcePrimaryKeyField); }
/** * INTERNAL: * All the source relation key field names are converted to DatabaseField and stored. */ protected void initializeSourceRelationKeys(AbstractSession session, ForeignReferenceMapping mapping) throws DescriptorException { if (getSourceRelationKeyFields().size() == 0) { throw DescriptorException.noSourceRelationKeysSpecified(mapping); } for (Enumeration entry = getSourceRelationKeyFields().elements(); entry.hasMoreElements();) { DatabaseField field = (DatabaseField)entry.nextElement(); if (field.hasTableName() && (!(field.getTableName().equals(getRelationTable().getName())))) { throw DescriptorException.relationKeyFieldNotProperlySpecified(field, mapping); } field.setTable(getRelationTable()); } }
/** * INTERNAL: * Allow the mapping the do any further batch preparation. */ protected void postPrepareNestedBatchQuery(ReadQuery batchQuery, ReadAllQuery query) { // Force a distinct to filter out m-1 duplicates. if (!query.isDistinctComputed()) { ((ObjectLevelReadQuery)batchQuery).useDistinct(); } if(this.mechanism != null) { ReadAllQuery mappingBatchQuery = (ReadAllQuery)batchQuery; mappingBatchQuery.setShouldIncludeData(true); for (Enumeration relationFieldsEnum = this.mechanism.getSourceRelationKeyFields().elements(); relationFieldsEnum.hasMoreElements();) { mappingBatchQuery.getAdditionalFields().add(mappingBatchQuery.getExpressionBuilder().getTable(this.mechanism.getRelationTable()).getField((DatabaseField)relationFieldsEnum.nextElement())); } } }
/** * INTERNAL: * Extract the source primary key value from the relation row. * Used for batch reading, most following same order and fields as in the mapping. */ protected Object extractKeyFromTargetRow(AbstractRecord row, AbstractSession session) { int size = getSourceRelationKeyFields().size(); Object[] key = new Object[size]; ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager(); for (int index = 0; index < size; index++) { DatabaseField relationField = this.sourceRelationKeyFields.get(index); DatabaseField sourceField = this.sourceKeyFields.get(index); Object value = row.get(relationField); // Must ensure the classification gets a cache hit. value = conversionManager.convertObject(value, sourceField.getType()); key[index] = value; } return new CacheId(key); }
/** * INTERNAL: * Extract the source primary key value from the relation row. * Used for batch reading, most following same order and fields as in the mapping. */ protected Object extractKeyFromTargetRow(AbstractRecord row, AbstractSession session) { int size = getSourceRelationKeyFields().size(); Object[] key = new Object[size]; ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager(); for (int index = 0; index < size; index++) { DatabaseField relationField = this.sourceRelationKeyFields.get(index); DatabaseField sourceField = this.sourceKeyFields.get(index); Object value = row.get(relationField); // Must ensure the classification gets a cache hit. value = conversionManager.convertObject(value, sourceField.getType()); key[index] = value; } return new CacheId(key); }
/** * INTERNAL: * All the source relation key field names are converted to DatabaseField and stored. */ protected void initializeSourceRelationKeys(ForeignReferenceMapping mapping) throws DescriptorException { if (getSourceRelationKeyFields().size() == 0) { throw DescriptorException.noSourceRelationKeysSpecified(mapping); } for (Enumeration entry = getSourceRelationKeyFields().elements(); entry.hasMoreElements();) { DatabaseField field = (DatabaseField)entry.nextElement(); // Update the fields table first if the mapping is from a table per tenant entity. ClassDescriptor sourceDescriptor = mapping.getDescriptor(); if (sourceDescriptor.hasTablePerMultitenantPolicy()) { field.setTable(((TablePerMultitenantPolicy) sourceDescriptor.getMultitenantPolicy()).getTable(field.getTable())); } if (field.hasTableName() && (!(field.getTableName().equals(getRelationTable().getName())))) { throw DescriptorException.relationKeyFieldNotProperlySpecified(field, mapping); } field.setTable(getRelationTable()); } }
/** * INTERNAL: * The mapping clones itself to create deep copy. */ public Object clone() { RelationTableMechanism clone; try { clone = (RelationTableMechanism)super.clone(); } catch (CloneNotSupportedException e) { throw new InternalError(); } clone.setTargetKeyFields(cloneFields(getTargetKeyFields())); clone.setSourceKeyFields(cloneFields(getSourceKeyFields())); clone.setTargetRelationKeyFields(cloneFields(getTargetRelationKeyFields())); clone.setSourceRelationKeyFields(cloneFields(getSourceRelationKeyFields())); clone.setInsertQuery((DataModifyQuery) insertQuery.clone()); clone.setDeleteQuery((DataModifyQuery) deleteQuery.clone()); if(lockRelationTableQuery != null) { clone.lockRelationTableQuery = (DirectReadQuery)lockRelationTableQuery.clone(); } return clone; }
/** * INTERNAL: * The mapping clones itself to create deep copy. */ public Object clone() { RelationTableMechanism clone; try { clone = (RelationTableMechanism)super.clone(); } catch (CloneNotSupportedException e) { throw new InternalError(); } clone.setTargetKeyFields(cloneFields(getTargetKeyFields())); clone.setSourceKeyFields(cloneFields(getSourceKeyFields())); clone.setTargetRelationKeyFields(cloneFields(getTargetRelationKeyFields())); clone.setSourceRelationKeyFields(cloneFields(getSourceRelationKeyFields())); clone.setInsertQuery((DataModifyQuery) insertQuery.clone()); clone.setDeleteQuery((DataModifyQuery) deleteQuery.clone()); if(lockRelationTableQuery != null) { clone.lockRelationTableQuery = (DirectReadQuery)lockRelationTableQuery.clone(); } return clone; }
/** * Build relation table definitions for all many-to-many relationships in a EclipseLink descriptor. */ private void buildRelationTableDefinition(RelationTableMechanism relationTableMechanism, DatabaseField listOrderField, ContainerPolicy cp) { //first create relation table TableDefinition tblDef = getTableDefFromDBTable(relationTableMechanism.getRelationTable()); //add source foreign key fields into the relation table Vector srcFkFields = relationTableMechanism.getSourceRelationKeyFields(); Vector srcKeyFields = relationTableMechanism.getSourceKeyFields(); buildRelationTableFields(tblDef, srcFkFields, srcKeyFields); //add target foreign key fields into the relation table Vector targFkFields = relationTableMechanism.getTargetRelationKeyFields(); Vector targKeyFields = relationTableMechanism.getTargetKeyFields(); buildRelationTableFields(tblDef, targFkFields, targKeyFields); if (cp != null){ addFieldsForMappedKeyMapContainerPolicy(cp, tblDef); } if(listOrderField != null) { tblDef.addField(getFieldDefFromDBField(listOrderField, false)); } }