public boolean isPrimaryKeyMapping(DatabaseMapping mapping) { return getPrimaryKeyMappings().contains(mapping); }
public boolean isPrimaryKeyMapping(DatabaseMapping mapping) { return getPrimaryKeyMappings().contains(mapping); }
public boolean isPrimaryKeyMapping(DatabaseMapping mapping) { return getPrimaryKeyMappings().contains(mapping); }
/** * Return primary key classifications. * These are used to ensure a consistent type for the pk values. */ public List<Class> getPrimaryKeyClassifications() { if (primaryKeyClassifications == null) { List primaryKeyFields = this.descriptor.getPrimaryKeyFields(); List<Class> classifications = new ArrayList(primaryKeyFields.size()); for (int index = 0; index < primaryKeyFields.size(); index++) { DatabaseMapping mapping = 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; }
public static List<SortableKey> getPrimaryKey(PersistenceContext context, String entityName) { ClassDescriptor descriptor = context.getDescriptor(entityName); List<DatabaseMapping> pkMappings = descriptor.getObjectBuilder().getPrimaryKeyMappings(); List<SortableKey> pkIndices = new ArrayList<SortableKey>(); int index = 0; for (DatabaseMapping mapping : pkMappings) { if (!mapping.isMultitenantPrimaryKeyMapping()) { pkIndices.add(new SortableKey(mapping, index)); index++; } } Collections.sort(pkIndices); return pkIndices; }
public static List<SortableKey> getPrimaryKey(PersistenceContext context, String entityName) { ClassDescriptor descriptor = context.getDescriptor(entityName); List<DatabaseMapping> pkMappings = descriptor.getObjectBuilder().getPrimaryKeyMappings(); List<SortableKey> pkIndices = new ArrayList<SortableKey>(); int index = 0; for (DatabaseMapping mapping : pkMappings) { if (!mapping.isMultitenantPrimaryKeyMapping()) { pkIndices.add(new SortableKey(mapping, index)); index++; } } Collections.sort(pkIndices); return pkIndices; }
/** * Extract primary key attribute values from the domainObject. */ public AbstractRecord extractPrimaryKeyRowFromObject(Object domainObject, AbstractSession session) { AbstractRecord databaseRow = createRecord(getPrimaryKeyMappings().size(), session); // PERF: use index not enumeration. for (int index = 0; index < getPrimaryKeyMappings().size(); index++) { getPrimaryKeyMappings().get(index).writeFromObjectIntoRow(domainObject, databaseRow, session, WriteType.UNDEFINED); } // PERF: optimize simple primary key case, no need to remap. if (this.descriptor.hasSimplePrimaryKey()) { return databaseRow; } AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); List primaryKeyFields = this.descriptor.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 = 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; }
/** * Build the row representation of an object. The row built is used only for translations * for the expressions in the expression framework. */ public AbstractRecord buildRowForTranslation(Object object, AbstractSession session) { AbstractRecord databaseRow = createRecord(session); List<DatabaseMapping> primaryKeyMappings = getPrimaryKeyMappings(); int size = primaryKeyMappings.size(); for (int index = 0; index < size; index++) { DatabaseMapping mapping = primaryKeyMappings.get(index); if (mapping != null) { mapping.writeFromObjectIntoRow(object, databaseRow, session, WriteType.UNDEFINED); } } // 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. if (this.descriptor.hasMultipleTables()) { addPrimaryKeyForNonDefaultTable(databaseRow, object, session); } return databaseRow; }
/** * Build the row representation of an object. The row built is used only for translations * for the expressions in the expression framework. */ public AbstractRecord buildRowForTranslation(Object object, AbstractSession session) { AbstractRecord databaseRow = createRecord(session); List<DatabaseMapping> primaryKeyMappings = getPrimaryKeyMappings(); int size = primaryKeyMappings.size(); for (int index = 0; index < size; index++) { DatabaseMapping mapping = primaryKeyMappings.get(index); if (mapping != null) { mapping.writeFromObjectIntoRow(object, databaseRow, session, WriteType.UNDEFINED); } } // 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. if (this.descriptor.hasMultipleTables()) { addPrimaryKeyForNonDefaultTable(databaseRow, object, session); } return databaseRow; }
/** * Build the row representation of an object. The row built is used only for translations * for the expressions in the expression framework. */ public AbstractRecord buildRowForTranslation(Object object, AbstractSession session) { AbstractRecord databaseRow = createRecord(session); List<DatabaseMapping> primaryKeyMappings = getPrimaryKeyMappings(); int size = primaryKeyMappings.size(); for (int index = 0; index < size; index++) { DatabaseMapping mapping = primaryKeyMappings.get(index); 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. if (this.descriptor.hasMultipleTables()) { addPrimaryKeyForNonDefaultTable(databaseRow, object, session); } return databaseRow; }
protected Object constructObjectForId(String entityType, Object id){ FetchGroup fetchGroup = new FetchGroup(); ClassDescriptor descriptor = context.getDescriptor(entityType); List<DatabaseMapping> pkMappings = descriptor.getObjectBuilder().getPrimaryKeyMappings(); for (DatabaseMapping mapping: pkMappings){ fetchGroup.addAttribute(mapping.getAttributeName()); } Map<String, Object> properties = new HashMap<String, Object>(); properties.put(QueryHints.FETCH_GROUP, fetchGroup); properties.put(QueryHints.CACHE_USAGE, CacheUsage.CheckCacheOnly); Object entity = context.find(null, entityType, id, properties); if (entity == null){ return IdHelper.buildObjectShell(context, entityType, id); } return entity; }
/** * Returns a clone of itself. */ public Object clone() { ObjectBuilder objectBuilder = null; try { objectBuilder = (ObjectBuilder)super.clone(); } catch (CloneNotSupportedException exception) { throw new InternalError(exception.toString()); } // Only the shallow copy is created. The entries never change in these data structures objectBuilder.setMappingsByAttribute(new HashMap(getMappingsByAttribute())); objectBuilder.setMappingsByField(new HashMap(getMappingsByField())); objectBuilder.setFieldsMap(new HashMap(getFieldsMap())); objectBuilder.setReadOnlyMappingsByField(new HashMap(getReadOnlyMappingsByField())); objectBuilder.setPrimaryKeyMappings(new ArrayList(getPrimaryKeyMappings())); if (nonPrimaryKeyMappings != null) { objectBuilder.setNonPrimaryKeyMappings(new ArrayList(getNonPrimaryKeyMappings())); } objectBuilder.cloningMappings = new ArrayList(this.cloningMappings); objectBuilder.eagerMappings = new ArrayList(this.eagerMappings); objectBuilder.relationshipMappings = new ArrayList(this.relationshipMappings); return objectBuilder; }
/** * Returns a clone of itself. */ public Object clone() { ObjectBuilder objectBuilder = null; try { objectBuilder = (ObjectBuilder)super.clone(); } catch (CloneNotSupportedException exception) { throw new InternalError(exception.toString()); } // Only the shallow copy is created. The entries never change in these data structures objectBuilder.setMappingsByAttribute(new HashMap(getMappingsByAttribute())); objectBuilder.setMappingsByField(new HashMap(getMappingsByField())); objectBuilder.setFieldsMap(new HashMap(getFieldsMap())); objectBuilder.setReadOnlyMappingsByField(new HashMap(getReadOnlyMappingsByField())); objectBuilder.setPrimaryKeyMappings(new ArrayList(getPrimaryKeyMappings())); objectBuilder.setNonPrimaryKeyMappings(new ArrayList(getNonPrimaryKeyMappings())); objectBuilder.cloningMappings = new ArrayList(this.cloningMappings); objectBuilder.eagerMappings = new ArrayList(this.eagerMappings); objectBuilder.relationshipMappings = new ArrayList(this.relationshipMappings); return objectBuilder; }
protected Object constructObjectForId(String entityType, Object id){ FetchGroup fetchGroup = new FetchGroup(); ClassDescriptor descriptor = context.getDescriptor(entityType); List<DatabaseMapping> pkMappings = descriptor.getObjectBuilder().getPrimaryKeyMappings(); for (DatabaseMapping mapping: pkMappings){ fetchGroup.addAttribute(mapping.getAttributeName()); } Map<String, Object> properties = new HashMap<String, Object>(); properties.put(QueryHints.FETCH_GROUP, fetchGroup); properties.put(QueryHints.CACHE_USAGE, CacheUsage.CheckCacheOnly); Object entity = context.find(null, entityType, id, properties); if (entity == null){ return IdHelper.buildObjectShell(context, entityType, id); } return entity; }
/** * 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(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression boolean isValid = expression.extractPrimaryKeyValues(true, this.descriptor, primaryKeyRow, translationRow); if (!isValid) { return null; } // Check that the sizes match up if (primaryKeyRow.size() != this.descriptor.getPrimaryKeyFields().size()) { return null; } return primaryKeyRow; }
/** * 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(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression. boolean isValid = expression.extractPrimaryKeyValues(requiresExactMatch, this.descriptor, primaryKeyRow, translationRow); if (requiresExactMatch && (!isValid)) { return null; } // Check that the sizes match. if (primaryKeyRow.size() != this.descriptor.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) { if (translationRow != null && translationRow.hasSopObject()) { return translationRow; } AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression boolean isValid = expression.extractPrimaryKeyValues(true, this.descriptor, primaryKeyRow, translationRow); if (!isValid) { return null; } // Check that the sizes match up if (primaryKeyRow.size() != this.descriptor.getPrimaryKeyFields().size()) { return null; } return primaryKeyRow; }
/** * Return the row with primary keys and their values from the given expression. */ public Object extractPrimaryKeyFromExpression(boolean requiresExactMatch, Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression. boolean isValid = expression.extractPrimaryKeyValues(requiresExactMatch, this.descriptor, primaryKeyRow, translationRow); if (requiresExactMatch && (!isValid)) { return null; } // Check that the sizes match. if (primaryKeyRow.size() != this.descriptor.getPrimaryKeyFields().size()) { return null; } Object primaryKey = extractPrimaryKeyFromRow(primaryKeyRow, session); if ((primaryKey == null) && isValid) { return InvalidObject.instance; } return primaryKey; }
/** * Return the row with primary keys and their values from the given expression. */ public AbstractRecord extractPrimaryKeyRowFromExpression(Expression expression, AbstractRecord translationRow, AbstractSession session) { if (translationRow != null && translationRow.hasSopObject()) { return translationRow; } AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression boolean isValid = expression.extractPrimaryKeyValues(true, this.descriptor, primaryKeyRow, translationRow); if (!isValid) { return null; } // Check that the sizes match up if (primaryKeyRow.size() != this.descriptor.getPrimaryKeyFields().size()) { return null; } return primaryKeyRow; }
/** * Return the row with primary keys and their values from the given expression. */ public Object extractPrimaryKeyFromExpression(boolean requiresExactMatch, Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size(), session); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression. boolean isValid = expression.extractPrimaryKeyValues(requiresExactMatch, this.descriptor, primaryKeyRow, translationRow); if (requiresExactMatch && (!isValid)) { return null; } // Check that the sizes match. if (primaryKeyRow.size() != this.descriptor.getPrimaryKeyFields().size()) { return null; } Object primaryKey = extractPrimaryKeyFromRow(primaryKeyRow, session); if ((primaryKey == null) && isValid) { return InvalidObject.instance; } return primaryKey; }