/** * PUBLIC: * Returns the number of field-value pairs in the database row. * @return int */ public int size() { return super.size(); }
/** * PUBLIC: * Return if the row is empty. */ public boolean isEmpty() { return size() == 0; }
/** * Update the change set with all of the field values in the row. * This handle writable and read-only mappings, direct and nested aggregates. * It is used from ReturningPolicy and VersionLockingPolicy. */ public void updateChangeSet(ClassDescriptor desc, ObjectChangeSet objectChangeSet, AbstractRecord row, Object object) { HashSet handledMappings = new HashSet(row.size()); for (int i = 0; i < row.size(); i++) { DatabaseField field = (DatabaseField)row.getFields().elementAt(i); Object value = row.getValues().elementAt(i); updateChangeSet(desc, objectChangeSet, field, object, handledMappings); } }
/** * PUBLIC: * Returns a set of the keys. */ public Set entrySet() { int size = this.size(); Map tempMap = new HashMap(size); for (int i = 0; i < size; i++) { tempMap.put(this.getFields().elementAt(i), this.getValues().elementAt(i)); } return tempMap.entrySet(); }
/** * 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: * Assign returned row to object */ public void assignReturnRow(Object object, AbstractSession writeSession, AbstractRecord row) throws DatabaseException { writeSession.log(SessionLog.FINEST, SessionLog.QUERY, "assign_return_row", row); // Require a query context to read into an object. ReadObjectQuery query = new ReadObjectQuery(); query.setSession(writeSession); // To avoid processing the same mapping twice, // maintain Collection of mappings already used. HashSet handledMappings = new HashSet(row.size()); for (int index = 0; index < row.size(); index++) { DatabaseField field = (DatabaseField)row.getFields().elementAt(index); assignReturnValueForField(object, query, row, field, handledMappings); } }
/** * INTERNAL: */ public AbstractRecord trimRowForJoin(AbstractRecord row, Object value, AbstractSession executionSession) { // CR #... the field for many objects may be in the row, // so build the subpartion of the row through the computed values in the query, // this also helps the field indexing match. int fieldStartIndex; if(value instanceof Integer) { fieldStartIndex = ((Integer)value).intValue(); } else { // must be Map of classes to Integers Map map = (Map)value; Class cls; if (getDescriptor().hasInheritance() && getDescriptor().getInheritancePolicy().shouldReadSubclasses()) { cls = getDescriptor().getInheritancePolicy().classFromRow(row, executionSession); } else { cls = getDescriptor().getJavaClass(); } fieldStartIndex = ((Integer)map.get(cls)).intValue(); } Vector trimedFields = Helper.copyVector(row.getFields(), fieldStartIndex, row.size()); Vector trimedValues = Helper.copyVector(row.getValues(), fieldStartIndex, row.size()); return new DatabaseRecord(trimedFields, trimedValues); } }
if (item.getDescriptor().getAllFields().size() + item.getResultIndex() > row.size()) { throw QueryException.reportQueryResultSizeMismatch(item.getDescriptor().getAllFields().size() + item.getResultIndex(), row.size()); Vector trimedFields = Helper.copyVector(row.getFields(), item.getResultIndex(), row.size()); Vector trimedValues = Helper.copyVector(row.getValues(), item.getResultIndex(), row.size()); AbstractRecord subRow = new DatabaseRecord(trimedFields, trimedValues); value = item.getDescriptor().getObjectBuilder().buildObject(query, subRow, joinManager);
/** * 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; }