/** * PUBLIC: * Returns the Object associated with the given key * (null if the key does not map to an Object.) * @param key DatabaseField * @return Object - the value associated with the key */ public Object getValues(DatabaseField key) { return super.get(key); }
/** * INTERNAL: * Write fields needed for insert into the template for with null values. */ public void writeInsertFieldsIntoRow(AbstractRecord databaseRow, AbstractSession session) { if (isReadOnly()) { return; } AbstractRecord targetRow = buildTemplateInsertRow(session); for (Enumeration keyEnum = targetRow.keys(); keyEnum.hasMoreElements();) { DatabaseField field = (DatabaseField)keyEnum.nextElement(); Object value = targetRow.get(field); //CR-3286097 - Should use add not put, to avoid linear search. databaseRow.add(field, value); } }
/** * PUBLIC: * Clears the contents of the database row, both fields and values. */ public void clear() { super.clear(); }
/** * 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: * Clone the row and its values. */ public Object clone() { try { AbstractRecord clone = (AbstractRecord)super.clone(); clone.setFields((Vector)getFields().clone()); clone.setValues((Vector)getValues().clone()); return clone; } catch (CloneNotSupportedException exception) { } return null; }
/** * 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; }
DatabaseField referenceKey = (DatabaseField)getReferenceKeyFields().elementAt(index); DatabaseField sourceKey = (DatabaseField)getSourceKeyFields().elementAt(index); Object sourceKeyValue = writeQuery.getTranslationRow().get(sourceKey); writeQuery.getTranslationRow().put(referenceKey, sourceKeyValue); AbstractRecord thisRow = (AbstractRecord)writeQuery.getTranslationRow().clone(); Object value = object; if (getValueConverter() != null){ thisRow.add(getDirectField(), null); }else{ thisRow.add(getDirectField(), value); if (count != null){ for (int counter = count.intValue(); counter > 0; --counter){ thisRow = (AbstractRecord)writeQuery.getTranslationRow().clone(); thisRow.add(getDirectField(), value); Integer count = (Integer)changeRecord.getAddObjectMap().get(object); for (int counter = count.intValue(); counter > 0; --counter){ AbstractRecord thisRow = (AbstractRecord)writeQuery.getTranslationRow().clone(); Object value = object; if (getValueConverter() != null){ thisRow.add(getDirectField(), null); }else{ thisRow.add(getDirectField(), value);
row = (AbstractRecord)row.clone(); int i = 0; for (Enumeration sourceKeys = getSourceKeyFields().elements(); int index = row.getFields().indexOf(sourceKey); if (index == -1) { value = joinManager.getBaseQuery().getTranslationRow().get(sourceKey); row.add(sourceKey, value); } else { value = row.getValues().elementAt(index); row.add((DatabaseField)getTargetForeignKeyFields().elementAt(i), value);
protected void updateObjectAndRowWithReturnRow(Collection returnFields, boolean isFirstCallForInsert) { WriteObjectQuery writeQuery = getWriteObjectQuery(); AbstractRecord outputRow = (AbstractRecord)writeQuery.getProperties().get("output"); if ((outputRow == null) || outputRow.isEmpty()) { return; for (Iterator iterator = returnFields.iterator(); iterator.hasNext();) { DatabaseField field = (DatabaseField)iterator.next(); if (outputRow.containsKey(field)) { row.put(field, outputRow.get(field)); if (row.isEmpty()) { return; for (int i = 0; i < primaryKeyFields.size(); i++) { DatabaseField field = (DatabaseField)primaryKeyFields.get(i); if (row.containsKey(field)) { pkToModify.put(field, row.get(field)); if (!pkToModify.isEmpty()) { primaryKeys = getDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(object, getSession()); writeQuery.setPrimaryKey(primaryKeys); getModifyRow().putAll(pkToModify); getDescriptor().getObjectBuilder().addPrimaryKeyForNonDefaultTable(getModifyRow());
DatabaseField referenceKey = (DatabaseField)getReferenceKeyFields().elementAt(index); DatabaseField sourceKey = (DatabaseField)getSourceKeyFields().elementAt(index); Object sourceKeyValue = query.getTranslationRow().get(sourceKey); databaseRow.put(referenceKey, sourceKeyValue); object = getValueConverter().convertObjectValueToDataValue(object, query.getSession()); databaseRow.put(getDirectField(), object); event[0] = Insert; event[1] = getInsertQuery(); event[2] = databaseRow.clone(); query.getSession().getCommitManager().addDataModificationEvent(this, event); } else {
/** * 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); } }
DatabaseField primaryKeyField = (DatabaseField)primaryKeyFieldEnum.next(); DatabaseField secondaryKeyField = (DatabaseField)secondaryKeyFieldEnum.next(); Object primaryValue = databaseRow.get(primaryKeyField); if ((primaryValue == null) && (!databaseRow.containsKey(primaryKeyField))) { if (object != null) { DatabaseMapping mapping = getMappingForField(secondaryKeyField); databaseRow.put(primaryKeyField, databaseRow.get(secondaryKeyField)); } else { databaseRow.put(secondaryKeyField, primaryValue);
/** * INTERNAL: * Used by cursored stream. * Return the first field in the row. */ public Object buildObject(AbstractRecord row) { Object value = row.get(row.getFields().firstElement()); if (getValueConverter() != null) { value = getValueConverter().convertDataValueToObjectValue(value, session); } return value; }
/** * INTERNAL: * get reference object keys */ public Vector getReferenceObjectKeys(ObjectLevelModifyQuery query) throws DatabaseException, OptimisticLockException { Vector referenceObjectKeys = new Vector(getSourceKeyFields().size()); //For CR#2587-S.M. For nested aggregate collections the source keys can easily be read from the original query. AbstractRecord translationRow = query.getTranslationRow(); for (Enumeration sourcekeys = getSourceKeyFields().elements(); sourcekeys.hasMoreElements();) { DatabaseField sourceKey = (DatabaseField)sourcekeys.nextElement(); // CR#2587. Try first to get the source key from the original query. If that fails try to get it from the object. Object referenceKey = null; if ((translationRow != null) && (translationRow.containsKey(sourceKey))) { referenceKey = translationRow.get(sourceKey); } else { referenceKey = getDescriptor().getObjectBuilder().extractValueFromObjectForField(query.getObject(), sourceKey, query.getSession()); } referenceObjectKeys.addElement(referenceKey); } return referenceObjectKeys; }
referenceValue = getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(referenceObject, targetKey, session); databaseRow.add(sourceKey, referenceValue); fieldsEnum.hasMoreElements();) { DatabaseField sourceKey = (DatabaseField)fieldsEnum.nextElement(); Object referenceValue = referenceRow.get(sourceKey); databaseRow.add(sourceKey, referenceValue);
if (parameterType == MODIFY) { DatabaseField field = (DatabaseField)parameter; Object value = modifyRow.get(field); if (value == null) { value = modifyRow.getField(field); Object value = modifyRow.get(field); value = session.getPlatform().getCustomModifyValueForCall(this, value, field, true); if (value == null) { value = modifyRow.getField(field); } else { field = (DatabaseField)parameter; value = translationRow.get(field); if (value == null) {// Backward compatibility double check. value = modifyRow.get(field); value = translationRow.getField(field);
/** * Perform a cache lookup for the query. * If the translation row contains all the primary key fields, * then a cache check will be performed. * If the object is found in the cache, return it; * otherwise return null. */ public Object checkCacheForObject(AbstractRecord translationRow, AbstractSession session) { // Null check added for CR#4295 - TW if ((translationRow == null) || (translationRow.isEmpty())) { return null; } List keyFields = getDescriptor().getPrimaryKeyFields(); Vector primaryKey = new Vector(keyFields.size()); for (int index = 0; index < keyFields.size(); index++) { Object value = translationRow.get((DatabaseField)keyFields.get(index)); if (value == null) { return null; } else { primaryKey.add(value); } } return session.getIdentityMapAccessorInstance().getFromIdentityMapWithDeferredLock(primaryKey, getReadObjectQuery().getReferenceClass(), false, getDescriptor()); }