/** * PUBLIC: * Return the number of field/value pairs in the row. */ public int size() { return getFields().size(); }
/** * PUBLIC: * Returns a set of the keys. */ public Set keySet() { return new HashSet(getFields()); }
/** * PUBLIC: * Returns an Enumeration of the DatabaseField objects. */ public Enumeration keys() { return getFields().elements(); }
/** * INTERNAL: * Check if the field is contained in the row. */ public boolean containsKey(DatabaseField key) { // Optimize check. int index = key.getIndex(); if ((index >= 0) && (index < getFields().size())) { DatabaseField field = (DatabaseField)getFields().elementAt(index); if ((field == key) || field.equals(key)) { return true; } } return getFields().contains(key); }
/** * 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: * Returns the row's field with the same name. */ public DatabaseField getField(DatabaseField key) { // Optimize check. int index = key.getIndex(); if ((index >= 0) && (index < getFields().size())) { DatabaseField field = (DatabaseField)getFields().elementAt(index); if ((field == key) || field.equals(key)) { return field; } } for (index = 0; index < getFields().size(); index++) { DatabaseField field = (DatabaseField)getFields().elementAt(index); if ((field == key) || field.equals(key)) { return field; } } return null; }
/** * 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: * 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; }
/** * 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); } }
/** * 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; }
/** * 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: * 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: * The results are *not* in a cursor, build the collection. */ public Object executeNonCursor() throws DatabaseException, QueryException { ContainerPolicy cp = getContainerPolicy(); Vector rows = getQueryMechanism().executeSelect(); Object result = cp.containerInstance(rows.size()); DatabaseField resultDirectField = null; for (Enumeration stream = rows.elements(); stream.hasMoreElements();) { AbstractRecord row = (AbstractRecord)stream.nextElement(); if (resultDirectField == null) { resultDirectField = (DatabaseField)row.getFields().firstElement(); } Object value = row.get(resultDirectField); if (getValueConverter() != null) { value = getValueConverter().convertDataValueToObjectValue(value, session); } cp.addInto(value, result, getSession()); } return result; } }
int index = row.getFields().indexOf(sourceKey); if (index == -1) {
/** * 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); } }
/** * Build the select statement for selecting the locator */ private SQLSelectStatement buildSelectStatementForLocator(WriteObjectQuery writeQuery, DatabaseCall call, AbstractSession session) { SQLSelectStatement selectStatement = new SQLSelectStatement(); Vector tables = writeQuery.getDescriptor().getTables(); selectStatement.setTables(tables); //rather than get ALL fields from the descriptor, only use the LOB-related fields to build the minimal SELECT statement. selectStatement.setFields(call.getContexts().getFields()); //the where clause setting here is sufficient if the object does not map to multiple tables. selectStatement.setWhereClause(writeQuery.getDescriptor().getObjectBuilder().buildPrimaryKeyExpressionFromObject(writeQuery.getObject(), session)); //need pessimistic locking for the locator select selectStatement.setLockingClause(ForUpdateClause.newInstance(ObjectBuildingQuery.LOCK)); if (tables.size() > 1) { //the primary key expression from the primary table Expression expression = selectStatement.getWhereClause(); //additioanl join from the non-primary tables Expression additionalJoin = (Expression)writeQuery.getDescriptor().getQueryManager().getAdditionalJoinExpression(); if (additionalJoin != null) { expression = expression.and(additionalJoin); } //where clause now contains extra joins across all tables selectStatement.setWhereClause(expression); } //normalize the statement at the end, such as assign alias to all tables, and build sorting statement selectStatement.normalize(session, writeQuery.getDescriptor()); return selectStatement; }