/** * PUBLIC: * Returns an collection of the values. */ public Collection values() { return getValues(); } }
/** * PUBLIC: * Check if the value is contained in the row. */ public boolean containsValue(Object value) { return getValues().contains(value); }
/** * PUBLIC: * Returns an Enumeration of the values. */ public Enumeration elements() { return getValues().elements(); }
/** * INTERNAL: * replaces the value at index with value */ public void replaceAt(Object value, int index) { getValues().setElementAt(value, index); }
/** * INTERNAL: * Add the field-value pair to the row. Will not check, * will simply add to the end of the row */ public void add(DatabaseField key, Object value) { getFields().addElement(key); getValues().addElement(value); }
/** * INTERNAL: * Remove the field key from the row. */ public Object remove(DatabaseField key) { int index = getFields().indexOf(key); if (index >= 0) { getFields().removeElementAt(index); Object value = getValues().elementAt(index); getValues().removeElementAt(index); return value; } return null; }
/** * 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: */ public String toString() { StringWriter writer = new StringWriter(); writer.write(Helper.getShortClassName(getClass())); writer.write("("); for (int index = 0; index < getFields().size(); index++) { writer.write(Helper.cr()); writer.write("\t"); writer.write(String.valueOf((getFields().elementAt(index)))); writer.write(" => "); writer.write(String.valueOf((getValues().elementAt(index)))); } writer.write(")"); return writer.toString(); }
/** * 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; }
/** * 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: * Add the field-value pair to the row. */ public Object put(DatabaseField key, Object value) { int index = getFields().indexOf(key); if (index >= 0) { Object oldValue = getValues().elementAt(index); replaceAt(value, index); return oldValue; } else { add(key, value); } return null; }
/** * 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); } }
/** * Fetch the locator(s) from the result set and write LOB value to the table */ public void fetchLocatorAndWriteValue(DatabaseCall dbCall, Object resultSet) throws SQLException { Enumeration enumFields = dbCall.getContexts().getFields().elements(); Enumeration enumValues = dbCall.getContexts().getValues().elements(); AbstractSession executionSession = dbCall.getQuery().getSession().getExecutionSession(dbCall.getQuery()); while (enumFields.hasMoreElements()) { DatabaseField field = (DatabaseField)enumFields.nextElement(); Object value = enumValues.nextElement(); //write the value through the locator executionSession.getPlatform().writeLOB(field, value, (ResultSet)resultSet, executionSession); } }
/** * INTERNAL: * The results are *not* in a cursor, build the collection. */ protected Object executeNonCursor() throws DatabaseException { Vector rows = getQueryMechanism().executeSelect(); if (useAbstractRecord ){ Object results = getContainerPolicy().buildContainerFromVector(rows, getSession()); return results; } ContainerPolicy containerPolicy = getContainerPolicy(); Object reportResults = containerPolicy.containerInstance(rows.size()); for (Iterator rowsEnum = rows.iterator(); rowsEnum.hasNext();) { containerPolicy.addInto( ((AbstractRecord)rowsEnum.next()).getValues() , reportResults, getSession()); } return reportResults; }
row.add(sourceKey, value); } else { value = row.getValues().elementAt(index);
if (mapping != null){ value = row.getValues().get(item.getResultIndex()); value = ((AbstractDirectMapping)mapping).getAttributeValue(value, query.getSession()); Vector trimedValues = Helper.copyVector(row.getValues(), item.getResultIndex(), row.size()); AbstractRecord subRow = new DatabaseRecord(trimedFields, trimedValues); value = item.getDescriptor().getObjectBuilder().buildObject(query, subRow, joinManager); value = row.getValues().get(item.getResultIndex());
/** * 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); } }