/** * INTERNAL: Returns the first field from each of the owned tables, used for fine-grained * pessimistic locking. */ protected Vector getForUpdateOfFields() { Vector allFields = getFields(); int expected = getTableAliases().size(); Vector firstFields = new Vector(expected); DatabaseTable lastTable = null; DatabaseField field = null; int i = 0; // The following loop takes O(n*m) time. n=# of fields. m=#tables. // However, in the m=1 case this will take one pass only. // Also assuming that fields are generally sorted by table, this will // take O(n) time. // An even faster way may be to go getDescriptor().getAdditionalPrimaryKeyFields. while ((i < allFields.size()) && (firstFields.size() < expected)) { field = (DatabaseField) allFields.elementAt(i++); if ((lastTable == null) || !field.getTable().equals(lastTable)) { lastTable = field.getTable(); int j = 0; while (j < firstFields.size()) { if (lastTable.equals(((DatabaseField) firstFields.elementAt(j)).getTable())) { break; } j++; } if (j == firstFields.size()) { firstFields.addElement(field); } } } return firstFields; }
/** INTERNAL: */ protected Vector<DatabaseField> getVectorOfFieldsToGenerate(int operation, DatabaseTable table) { if (this.main[operation][ALL] == null) { return null; } if (this.tableToFieldsForGenerationMap == null) { // the method is called for the first time tableToFieldsForGenerationMap = new HashMap[NUM_OPERATIONS]; } if (this.tableToFieldsForGenerationMap[operation] == null) { // the method is called for the first time for this operation this.tableToFieldsForGenerationMap[operation] = new HashMap(); } Vector<DatabaseField> fieldsForGeneration = this.tableToFieldsForGenerationMap[operation].get(table); if (fieldsForGeneration == null) { // the method is called for the first time for this operation and this table fieldsForGeneration = new NonSynchronizedVector(); Iterator it = this.main[operation][ALL].iterator(); while (it.hasNext()) { DatabaseField field = (DatabaseField) it.next(); if (field.getTable().equals(table)) { fieldsForGeneration.add(field); } } this.tableToFieldsForGenerationMap[operation].put(table, fieldsForGeneration); } return fieldsForGeneration; }
protected static void writeUniqueFieldName( Writer writer, DatabaseField field, DatasourcePlatform platform) throws IOException { // EMPLOYEE_EMP_ID writer.write(field.getTable().getNameDelimited(platform)); writer.write("_"); writer.write(field.getNameDelimited(platform)); }
/** INTERNAL: */ protected void fieldIsNotFromDescriptor(DatabaseField field) { if (field.getTable().equals(getDescriptor().getDefaultTable())) { if (this.fieldsNotFromDescriptor_DefaultTable == null) { this.fieldsNotFromDescriptor_DefaultTable = new HashMap(); } this.fieldsNotFromDescriptor_DefaultTable.put(field, field); } else { if (this.fieldsNotFromDescriptor_OtherTables == null) { this.fieldsNotFromDescriptor_OtherTables = new HashMap(); } this.fieldsNotFromDescriptor_OtherTables.put(field, field); } }
/** Append the string containing the SQL insert string for the given table. */ protected SQLCall buildCallWithoutReturning(AbstractSession session) { SQLCall call = new SQLCall(); call.returnNothing(); Writer writer = new CharArrayWriter(200); try { writer.write("INSERT "); if (getHintString() != null) { writer.write(getHintString()); writer.write(" "); } writer.write("INTO "); writer.write(getTable().getQualifiedNameDelimited(session.getPlatform())); writer.write(" ("); Vector fieldsForTable = new Vector(); for (Enumeration fieldsEnum = getModifyRow().keys(); fieldsEnum.hasMoreElements(); ) { DatabaseField field = (DatabaseField) fieldsEnum.nextElement(); if (field.getTable().equals(getTable()) || (!field.hasTableName())) { fieldsForTable.addElement(field); } } if (fieldsForTable.isEmpty()) { throw QueryException.objectToInsertIsEmpty(getTable()); } for (int i = 0; i < fieldsForTable.size(); i++) { writer.write( ((DatabaseField) fieldsForTable.elementAt(i)).getNameDelimited(session.getPlatform())); if ((i + 1) < fieldsForTable.size()) { writer.write(", "); } } writer.write(") VALUES ("); for (int i = 0; i < fieldsForTable.size(); i++) { DatabaseField field = (DatabaseField) fieldsForTable.elementAt(i); call.appendModify(writer, field); if ((i + 1) < fieldsForTable.size()) { writer.write(", "); } } writer.write(")"); call.setSQLString(writer.toString()); } catch (IOException exception) { throw ValidationException.fileError(exception); } return call; }