public boolean isPrimaryKeyMapping(DatabaseMapping mapping) { return getPrimaryKeyMappings().contains(mapping); }
/** * INTERNAL: * Build just the primary key mappings into the object. */ public void buildPrimaryKeyAttributesIntoObject(Object original, AbstractRecord databaseRow, ObjectBuildingQuery query) throws DatabaseException, QueryException { AbstractSession executionSession = query.getSession().getExecutionSession(query); // PERF: Avoid synchronized enumerator as is concurrency bottleneck. Vector mappings = getPrimaryKeyMappings(); int mappingsSize = mappings.size(); for (int i = 0; i < mappingsSize; i++) { DatabaseMapping mapping = (DatabaseMapping)mappings.get(i); mapping.buildShallowOriginalFromRow(databaseRow, original, query, executionSession); } }
/** * Build the row representation of an object. The row built is used only for translations * for the expressions in the expresion framework. */ public AbstractRecord buildRowForTranslation(Object object, AbstractSession session) { AbstractRecord databaseRow = createRecord(); for (Iterator mappings = getPrimaryKeyMappings().iterator(); mappings.hasNext();) { DatabaseMapping mapping = (DatabaseMapping)mappings.next(); if (mapping != null) { mapping.writeFromObjectIntoRow(object, databaseRow, session); } } // If this descriptor has multiple tables then we need to append the primary keys for // the non default tables, this is require for m-m, dc defined in the Builder that prefixes the wrong table name. // Ideally the mappings should take part in building the translation row so they can add required values. addPrimaryKeyForNonDefaultTable(databaseRow, object, session); return databaseRow; }
/** * Return primary key classifications. * These are used to ensure a consistent type for the pk values. */ public Vector<Class> getPrimaryKeyClassifications() { if (primaryKeyClassifications == null) { List primaryKeyFields = getDescriptor().getPrimaryKeyFields(); Vector<Class> classifications = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(primaryKeyFields.size()); for (int index = 0; index < primaryKeyFields.size(); index++) { DatabaseMapping mapping = (DatabaseMapping)getPrimaryKeyMappings().get(index); DatabaseField field = (DatabaseField)primaryKeyFields.get(index); if (mapping != null) { classifications.add(Helper.getObjectClass(mapping.getFieldClassification(field))); } else { classifications.add(null); } primaryKeyClassifications = classifications; } } return primaryKeyClassifications; }
/** * Extract primary key attribute values from the domainObject. */ public AbstractRecord extractPrimaryKeyRowFromObject(Object domainObject, AbstractSession session) { AbstractRecord databaseRow = createRecord(getPrimaryKeyMappings().size()); // PERF: use index not enumeration. for (int index = 0; index < getPrimaryKeyMappings().size(); index++) { ((DatabaseMapping)getPrimaryKeyMappings().get(index)).writeFromObjectIntoRow(domainObject, databaseRow, session); } // PERF: optimize simple primary key case, no need to remap. if (getDescriptor().hasSimplePrimaryKey()) { return databaseRow; } AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size()); List primaryKeyFields = getDescriptor().getPrimaryKeyFields(); for (int index = 0; index < primaryKeyFields.size(); index++) { // Ensure that the type extracted from the object is the same type as in the descriptor, // the main reason for this is that 1-1 can optimize on vh by getting from the row as the row-type. Class classification = (Class)getPrimaryKeyClassifications().get(index); DatabaseField field = (DatabaseField)primaryKeyFields.get(index); Object value = databaseRow.get(field); primaryKeyRow.put(field, session.getPlatform(domainObject.getClass()).convertObject(value, classification)); } return primaryKeyRow; }
/** * Returns clone of itself */ public Object clone() { Object object = null; try { object = super.clone(); } catch (Exception exception) { ; } // Only the shallow copy is created. The entries never change in these data structures ((ObjectBuilder)object).setMappingsByAttribute(new HashMap(getMappingsByAttribute())); ((ObjectBuilder)object).setMappingsByField(new HashMap(getMappingsByField())); ((ObjectBuilder)object).setReadOnlyMappingsByField(new HashMap(getReadOnlyMappingsByField())); ((ObjectBuilder)object).setPrimaryKeyMappings((Vector)getPrimaryKeyMappings().clone()); ((ObjectBuilder)object).setNonPrimaryKeyMappings((Vector)getNonPrimaryKeyMappings().clone()); return object; }
for (int index = 0; index < getPrimaryKeyMappings().size(); index++) { AbstractDirectMapping mapping = (AbstractDirectMapping)getPrimaryKeyMappings().get(index); Object keyValue = mapping.valueFromObject(domainObject, (DatabaseField)primaryKeyFields.get(index), session); primaryKeyValues.add(keyValue); AbstractRecord databaseRow = createRecord(getPrimaryKeyMappings().size()); for (int index = 0; index < getPrimaryKeyMappings().size(); index++) { DatabaseMapping mapping = (DatabaseMapping)getPrimaryKeyMappings().get(index);
Vector pkMappings = getPrimaryKeyMappings(); int mappingsSize = pkMappings.size(); for (int i = 0; i < mappingsSize; i++) {
this.getPrimaryKeyMappings().clear(); this.getNonPrimaryKeyMappings().clear(); getPrimaryKeyMappings().addElement(mapping); if (mapping != null) { mapping.setIsPrimaryKeyMapping(true); for (int index = 0; index < getPrimaryKeyMappings().size(); index++) { DatabaseMapping mapping = (DatabaseMapping)getPrimaryKeyMappings().get(index);
ClassDescriptor descriptor = this.getDescriptor(); pkAttributes = new KeyElementAccessor[descriptor.getObjectBuilder().getPrimaryKeyMappings().size()]; } catch (NoSuchMethodException exs) { if (descriptor.getObjectBuilder().getPrimaryKeyMappings().size() == 1) {
/** * Return the row with primary keys and their values from the given expression. */ public Vector extractPrimaryKeyFromExpression(boolean requiresExactMatch, Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size()); //put the curent session onthe expression builder for use later store current session incase //it is required at a later stage AbstractSession oldSession = expression.getBuilder().getSession(); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression. boolean isValid = expression.extractPrimaryKeyValues(requiresExactMatch, getDescriptor(), primaryKeyRow, translationRow); if (requiresExactMatch && (!isValid)) { return null; } // Check that the sizes match. if (primaryKeyRow.size() != getDescriptor().getPrimaryKeyFields().size()) { return null; } return extractPrimaryKeyFromRow(primaryKeyRow, session); }
/** * Return the row with primary keys and their values from the given expression. */ public AbstractRecord extractPrimaryKeyRowFromExpression(Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size()); //put the curent session onthe expression builder for use later store current session incase //it is required at a later stage AbstractSession oldSession = expression.getBuilder().getSession(); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression boolean isValid = expression.extractPrimaryKeyValues(true, getDescriptor(), primaryKeyRow, translationRow); expression.getBuilder().setSession(session.getRootSession(null)); if (!isValid) { return null; } // Check that the sizes match up if (primaryKeyRow.size() != getDescriptor().getPrimaryKeyFields().size()) { return null; } return primaryKeyRow; }
for (Enumeration keyMappingsEnum = getPrimaryKeyMappings().elements(); keyMappingsEnum.hasMoreElements();) { if (((DatabaseMapping)keyMappingsEnum.nextElement()).isOneToOneMapping()) { for (Enumeration keyMappingsEnum = getPrimaryKeyMappings().elements(); keyMappingsEnum.hasMoreElements();) { DatabaseMapping mapping = (DatabaseMapping)keyMappingsEnum.nextElement();
Iterator pkMappingIter = builder.getPrimaryKeyMappings().iterator();
for (int index = getObjectBuilder().getPrimaryKeyMappings().size() - 1; index >= 0; index--) { DatabaseMapping mapping = (DatabaseMapping) getObjectBuilder().getPrimaryKeyMappings().get(index); if ((mapping != null) && mapping.isDirectToFieldMapping()) { getMappings().remove(mapping);