/** * INTERNAL: * Certain types of container policies require an extra update statement after a relationship * is inserted. Return whether this update statement is required. */ @Override public boolean shouldUpdateForeignKeysPostInsert() { return !((DatabaseMapping)keyMapping).isReadOnly(); }
/** * INTERNAL: * Certain types of container policies require an extra update statement after a relationship * is inserted. Return whether this update statement is required * @return */ public boolean shouldUpdateForeignKeysPostInsert(){ return !((DatabaseMapping)keyMapping).isReadOnly(); }
/** * INTERNAL: * Certain types of container policies require an extra update statement after a relationship * is inserted. Return whether this update statement is required. */ @Override public boolean shouldUpdateForeignKeysPostInsert() { return !((DatabaseMapping)keyMapping).isReadOnly(); }
/** * INTERNAL: * Called when the insert query is being initialized to ensure the fields for the key are in the insert query * * @see MappedKeyMapContainerPolicy */ @Override public void addFieldsForMapKey(AbstractRecord joinRow) { if (((DatabaseMapping)keyMapping).isReadOnly()) { return; } keyMapping.addFieldsForMapKey(joinRow); }
/** * INTERNAL: * Called when the insert query is being initialized to ensure the fields for the key are in the insert query * * @see MappedKeyMapContainerPolicy */ public void addFieldsForMapKey(AbstractRecord joinRow){ if (((DatabaseMapping)keyMapping).isReadOnly()){ return; } keyMapping.addFieldsForMapKey(joinRow); }
/** * INTERNAL: * Called when the insert query is being initialized to ensure the fields for the key are in the insert query * * @see MappedKeyMapContainerPolicy */ @Override public void addFieldsForMapKey(AbstractRecord joinRow) { if (((DatabaseMapping)keyMapping).isReadOnly()) { return; } keyMapping.addFieldsForMapKey(joinRow); }
/** * INTERNAL: * Add any non-Foreign-key data from an Object describe by a MapKeyMapping to a database row * This is typically used in write queries to ensure all the data stored in the collection table is included * in the query. */ @Override public Map getKeyMappingDataForWriteQuery(Object object, AbstractSession session) { if (((DatabaseMapping)keyMapping).isReadOnly()) { return null; } Object keyValue = ((Map.Entry)object).getKey(); return keyMapping.extractIdentityFieldsForQuery(keyValue, session); }
/** * INTERNAL: * Return true if read-only is explicitly set to true; * otherwise return whether the transformation has no fields * (no fields = read-only) */ @Override public boolean isReadOnly() { if (super.isReadOnly()) { return true; } else { return getFieldTransformations().isEmpty() && this.fieldToTransformers.isEmpty(); } }
/** * INTERNAL: * Add any non-Foreign-key data from an Object describe by a MapKeyMapping to a database row * This is typically used in write queries to ensure all the data stored in the collection table is included * in the query. * @param object * @param databaseRow * @param session */ public Map getKeyMappingDataForWriteQuery(Object object, AbstractSession session){ if (((DatabaseMapping)keyMapping).isReadOnly()){ return null; } Object keyValue = ((Map.Entry)object).getKey(); return keyMapping.extractIdentityFieldsForQuery(keyValue, session); }
/** * INTERNAL: * Return true if read-only is explicitly set to true; * otherwise return whether the transformation has no fields * (no fields = read-only) */ @Override public boolean isReadOnly() { if (super.isReadOnly()) { return true; } else { return getFieldTransformations().isEmpty() && this.fieldToTransformers.isEmpty(); } }
/** * INTERNAL: * Add any non-Foreign-key data from an Object describe by a MapKeyMapping to a database row * This is typically used in write queries to ensure all the data stored in the collection table is included * in the query. */ @Override public Map getKeyMappingDataForWriteQuery(Object object, AbstractSession session) { if (((DatabaseMapping)keyMapping).isReadOnly()) { return null; } Object keyValue = ((Map.Entry)object).getKey(); return keyMapping.extractIdentityFieldsForQuery(keyValue, session); }
/** * INTERNAL: * Return true if read-only is explicitly set to true; * otherwise return whether the transformation has no fields * (no fields = read-only) */ public boolean isReadOnly() { if (super.isReadOnly()) { return true; } else { return getFieldTransformations().isEmpty() && getFieldToTransformers().isEmpty(); } }
/** * INTERNAL: * Return whether this mapping requires extra queries to update the rows if it is * used as a key in a map. This will typically be true if there are any parts to this mapping * that are not read-only. */ @Override public boolean requiresDataModificationEventsForMapKey(){ if (getReferenceDescriptor() != null){ Iterator<DatabaseMapping> i = getReferenceDescriptor().getMappings().iterator(); while (i.hasNext()){ DatabaseMapping mapping = i.next(); if (!mapping.isReadOnly()){ Iterator<DatabaseField> fields = mapping.getFields().iterator(); while (fields.hasNext()){ DatabaseField field = fields.next(); if (field.isUpdatable()){ return true; } } } } return false; } return true; }
/** * INTERNAL: * Extract the fields for the Map key from the object to use in a query. */ @Override public Map extractIdentityFieldsForQuery(Object object, AbstractSession session){ Map keyFields = new HashMap(); ClassDescriptor descriptor =getReferenceDescriptor(); boolean usePrimaryKeyFields = (descriptor.getPrimaryKeyFields() != null && ! descriptor.getPrimaryKeyFields().isEmpty()) ? true : false; Iterator <DatabaseMapping> i = descriptor.getMappings().iterator(); while (i.hasNext()){ DatabaseMapping mapping = i.next(); if (!mapping.isReadOnly() && (!usePrimaryKeyFields || (usePrimaryKeyFields && mapping.isPrimaryKeyMapping()))){ Iterator<DatabaseField> fields = mapping.getFields().iterator(); while (fields.hasNext()){ DatabaseField field = fields.next(); if (field.isUpdatable()){ Object value = descriptor.getObjectBuilder().extractValueFromObjectForField(object, field, session); keyFields.put(field, value); } } } } return keyFields; }
/** * INTERNAL: * Extract the fields for the Map key from the object to use in a query. */ @Override public Map extractIdentityFieldsForQuery(Object object, AbstractSession session){ Map keyFields = new HashMap(); ClassDescriptor descriptor =getReferenceDescriptor(); boolean usePrimaryKeyFields = (descriptor.getPrimaryKeyFields() != null && ! descriptor.getPrimaryKeyFields().isEmpty()) ? true : false; Iterator <DatabaseMapping> i = descriptor.getMappings().iterator(); while (i.hasNext()){ DatabaseMapping mapping = i.next(); if (!mapping.isReadOnly() && (!usePrimaryKeyFields || (usePrimaryKeyFields && mapping.isPrimaryKeyMapping()))){ Iterator<DatabaseField> fields = mapping.getFields().iterator(); while (fields.hasNext()){ DatabaseField field = fields.next(); if (field.isUpdatable()){ Object value = descriptor.getObjectBuilder().extractValueFromObjectForField(object, field, session); keyFields.put(field, value); } } } } return keyFields; }
/** * INTERNAL: * This method is used to check the key mapping to ensure that it does not write to * a field that is written by another mapping. There are two possibilities: * * 1. The conflicting mapping has already been processed. In that case, we add MultipleWritableMappings * exception to the integrity checker right away * 2. There are no conflicting mappings. In that case, we store the list of fields that this mapping * has processed on the descriptor for the target so they can be checked as the descriptor initializes * @param session */ public void processAdditionalWritableMapKeyFields(AbstractSession session){ if (!((DatabaseMapping)getKeyMapping()).isReadOnly()){ CollectionMapping mapping = (CollectionMapping)valueMapping; Iterator<DatabaseField> i = getIdentityFieldsForMapKey().iterator(); while (i.hasNext()){ DatabaseField field = i.next(); if (mapping.getReferenceDescriptor().getObjectBuilder().getMappingsByField().containsKey(field) || mapping.getReferenceDescriptor().getAdditionalWritableMapKeyFields().contains(field)) { session.getIntegrityChecker().handleError(DescriptorException.multipleWriteMappingsForField(field.toString(), mapping)); } else { mapping.getReferenceDescriptor().getAdditionalWritableMapKeyFields().add(field); } } } }
/** * INTERNAL: * Used when initializing queries for mappings that use a Map * Called when the insert query is being initialized to ensure the fields for the map key are in the insert query */ @Override public void addFieldsForMapKey(AbstractRecord joinRow){ for (DatabaseMapping mapping : getReferenceDescriptor().getMappings()) { if (!mapping.isReadOnly()) { for (DatabaseField field : mapping.getFields()) { if (field.isUpdatable()){ joinRow.put(field, null); } } } } }
/** * INTERNAL: * Used when initializing queries for mappings that use a Map * Called when the insert query is being initialized to ensure the fields for the map key are in the insert query */ @Override public void addFieldsForMapKey(AbstractRecord joinRow){ for (DatabaseMapping mapping : getReferenceDescriptor().getMappings()) { if (!mapping.isReadOnly()) { for (DatabaseField field : mapping.getFields()) { if (field.isUpdatable()){ joinRow.put(field, null); } } } } }
/** * INTERNAL: * Initialize the mappings as a separate step. * This is done as a separate step to ensure that inheritance has been first resolved. */ public void initialize(AbstractSession session) throws DescriptorException { if (hasTenantDiscriminatorFields()) { for (DatabaseField discriminatorField : tenantDiscriminatorFields.keySet()) { DatabaseMapping mapping = getDescriptor().getObjectBuilder().getMappingForField(discriminatorField); if (mapping != null && ! mapping.isReadOnly() && ! mapping.isMultitenantPrimaryKeyMapping()) { throw ValidationException.nonReadOnlyMappedTenantDiscriminatorField(getDescriptor().getJavaClassName(), discriminatorField.getQualifiedName()); } // Add the context property to the session set. session.addMultitenantContextProperty(tenantDiscriminatorFields.get(discriminatorField)); } } }
/** * INTERNAL: * Initialize the mappings as a separate step. * This is done as a separate step to ensure that inheritance has been first resolved. */ public void initialize(AbstractSession session) throws DescriptorException { if (hasTenantDiscriminatorFields()) { for (DatabaseField discriminatorField : tenantDiscriminatorFields.keySet()) { DatabaseMapping mapping = getDescriptor().getObjectBuilder().getMappingForField(discriminatorField); if (mapping != null && ! mapping.isReadOnly() && ! mapping.isMultitenantPrimaryKeyMapping()) { throw ValidationException.nonReadOnlyMappedTenantDiscriminatorField(getDescriptor().getJavaClassName(), discriminatorField.getQualifiedName()); } // Add the context property to the session set. session.addMultitenantContextProperty(tenantDiscriminatorFields.get(discriminatorField)); } } }