/** * PUBLIC: * Adds a field-value pair to the row. * @param key String * @param value Object * @return Object - the previous Object with that key, could be null */ public Object put(String key, Object value) { return super.put(key, value); }
/** * PUBLIC: * Adds a field-value pair to the row. * @param key Object, either String or DatabaseField * @param value Object * @return Object - the previous Object with that key, could be null * @throws ValidationException if inappropriate key is used */ public Object put(Object key, Object value) throws ValidationException { return super.put(key, value); }
/** * PUBLIC: * Add the field-value pair to the row. */ public Object put(Object key, Object value) throws ValidationException { if (key instanceof String) { return put((String)key, value); } else if (key instanceof DatabaseField) { return put((DatabaseField)key, value); } else { throw ValidationException.onlyFieldsAreValidKeysForDatabaseRows(); } }
/** * PUBLIC: * Add all of the elements. */ public void putAll(Map map) { Iterator entriesIterator = map.entrySet().iterator(); while (entriesIterator.hasNext()) { Map.Entry entry = (Map.Entry)entriesIterator.next(); put(entry.getKey(), entry.getValue()); } }
/** * PUBLIC: * Add the field-value pair to the row. */ public Object put(String key, Object value) { return put(new DatabaseField(key), value); }
/** * INTERNAL: * Add update fields for template row. * These are any unmapped fields required to write in an update. */ public void addLockFieldsToUpdateRow(AbstractRecord databaseRow, AbstractSession session) { if (isStoredInCache()) { databaseRow.put(getWriteLockField(), null); } }
/** * INTERNAL: * Build and return a database row with all the reference * fields set to nulls. */ protected AbstractRecord buildNullReferenceRow() { AbstractRecord result = new DatabaseRecord(getReferenceFields().size()); for (Enumeration stream = getReferenceFields().elements(); stream.hasMoreElements();) { result.put((DatabaseField)stream.nextElement(), null); } return result; }
/** * INTERNAL: * Merge the provided row into this row. Existing field values in this row will * be replaced with values from the provided row. Fields not in this row will be * added from provided row. Values not in provided row will remain in this row. */ public void mergeFrom(AbstractRecord row){ for (int index = 0; index < row.size(); ++index){ this.put(row.getFields().get(index), row.getValues().get(index)); } }
/** * INTERNAL: * A subclass should implement this method if it wants different behaviour. * Write the foreign key values from the attribute to the row. */ public void writeFromAttributeIntoRow(Object attribute, AbstractRecord row, AbstractSession session) { AbstractRecord targetRow = buildRowFromAggregate(null, attribute, session); for (Enumeration stream = targetRow.keys(); stream.hasMoreElements(); ) { DatabaseField field = (DatabaseField) stream.nextElement(); Object value = targetRow.get(field); row.put(field, value); } }
/** * INTERNAL: * Add abstract class indicator information to the database row. This is * required when building a row for an insert or an update of a concrete child * descriptor. * This is only used to build a template row. */ public void addClassIndicatorFieldToInsertRow(AbstractRecord databaseRow) { if (hasClassExtractor()) { return; } DatabaseField field = getClassIndicatorField(); databaseRow.put(field, null); }
/** * INTERNAL: * Translate argumentValues into a database row. */ public AbstractRecord rowFromArguments(Vector argumentValues) throws QueryException { Vector argumentNames = getArguments(); if (argumentNames.size() != argumentValues.size()) { throw QueryException.argumentSizeMismatchInQueryAndQueryDefinition(this); } AbstractRecord row = new DatabaseRecord(); for (int index = 0; index < argumentNames.size(); index++) { String argumentName = (String)argumentNames.elementAt(index); Object argumentValue = argumentValues.elementAt(index); row.put(new DatabaseField(argumentName), argumentValue); } return row; }
/** * INTERNAL: * Return DatabaseRow containing output fields and values. * Called only if shouldBuildOutputRow method returns true. */ public AbstractRecord buildOutputRow(CallableStatement statement) throws SQLException { AbstractRecord row = new DatabaseRecord(); for (int index = 0; index < parameters.size(); index++) { Object parameter = parameters.elementAt(index); if (parameter instanceof OutputParameterForCallableStatement) { OutputParameterForCallableStatement outParameter = (OutputParameterForCallableStatement)parameter; if (!outParameter.isCursor()) { Object value = statement.getObject(index + 1); DatabaseField field = outParameter.getOutputField(); row.put(field, value); } } } return row; }
/** * INTERNAL: * The translation row may require additional fields than the primary key if the mapping in not on the primary key. */ protected void prepareTranslationRow(AbstractRecord translationRow, Object object, AbstractSession session) { // Make sure that each source key field is in the translation row. for (Enumeration sourceFieldsEnum = getSourceKeyFields().elements(); sourceFieldsEnum.hasMoreElements();) { DatabaseField sourceKey = (DatabaseField)sourceFieldsEnum.nextElement(); if (!translationRow.containsKey(sourceKey)) { Object value = getDescriptor().getObjectBuilder().extractValueFromObjectForField(object, sourceKey, session); translationRow.put(sourceKey, value); } } }
/** * INTERNAL: * The translation row may require additional fields than the primary key if the mapping in not on the primary key. */ protected void prepareTranslationRow(AbstractRecord translationRow, Object object, AbstractSession session) { // Make sure that each source key field is in the translation row. for (Enumeration sourceFieldsEnum = getSourceKeyFields().elements(); sourceFieldsEnum.hasMoreElements();) { DatabaseField sourceKey = (DatabaseField)sourceFieldsEnum.nextElement(); if (!translationRow.containsKey(sourceKey)) { Object value = getDescriptor().getObjectBuilder().extractValueFromObjectForField(object, sourceKey, session); translationRow.put(sourceKey, value); } } }
/** * INTERNAL: * Add abstract class indicator information to the database row. This is * required when building a row for an insert or an update of a concrete child * descriptor. */ public void addClassIndicatorFieldToRow(AbstractRecord databaseRow) { if (hasClassExtractor()) { return; } DatabaseField field = getClassIndicatorField(); Object value = getClassIndicatorValue(); databaseRow.put(field, value); }
/** * INTERNAL: * return the aggregate databaseRow with the primary keys from the source table and targer table */ public AbstractRecord getAggregateRow(ObjectLevelModifyQuery query, Object object) { Vector referenceObjectKeys = getReferenceObjectKeys(query); AbstractRecord aggregateRow = new DatabaseRecord(); Vector keys = getTargetForeignKeyFields(); for (int keyIndex = 0; keyIndex < keys.size(); keyIndex++) { aggregateRow.put(keys.elementAt(keyIndex), referenceObjectKeys.elementAt(keyIndex)); } getReferenceDescriptor(object.getClass(), query.getSession()).getObjectBuilder().buildRow(aggregateRow, object, query.getSession()); return aggregateRow; }
/** * Initialize insert query. This query is used to insert the collection of objects into the * reference table. */ protected void initializeInsertQuery(AbstractSession session) { super.initializeInsertQuery(session); getInsertQuery().getModifyRow().put(getDirectKeyField(), null); }
/** * Build the row from the primary key values. */ public AbstractRecord buildRowFromPrimaryKeyValues(Vector key, AbstractSession session) { AbstractRecord databaseRow = createRecord(key.size()); int keySize = key.size(); for (int index = 0; index < keySize; index++) { DatabaseField field = (DatabaseField)getDescriptor().getPrimaryKeyFields().get(index); Object value = key.elementAt(index); value = session.getPlatform(getDescriptor().getJavaClass()).getConversionManager().convertObject(value, field.getType()); databaseRow.put(field, value); } return databaseRow; }
/** * INTERNAL: * This method updates the modify row with the old lock value. */ public void writeLockValueIntoRow(ObjectLevelModifyQuery query, Object domainObject) { Object lockValue = getWriteLockValue(domainObject, query.getPrimaryKey(), query.getSession()); query.getModifyRow().put(getWriteLockField(), lockValue); if (isStoredInCache()) { query.getSession().getIdentityMapAccessor().updateWriteLockValue(query.getPrimaryKey(), domainObject.getClass(), lockValue); } }
/** * INTERNAL: * This method adds the lock value to the translation row of the * passed in query. depending on the storage flag, the value is * either retrieved from the cache of the object. */ public void addLockValuesToTranslationRow(ObjectLevelModifyQuery query) { Object value; if (isStoredInCache()) { value = query.getSession().getIdentityMapAccessor().getWriteLockValue(query.getPrimaryKey(), query.getObject().getClass()); } else { value = lockValueFromObject(query.getObject()); } if (value == null) { if (query.isDeleteObjectQuery()) { throw OptimisticLockException.noVersionNumberWhenDeleting(query.getObject(), query); } else { throw OptimisticLockException.noVersionNumberWhenUpdating(query.getObject(), query); } } query.getTranslationRow().put(getWriteLockField(), value); }