Make DbMapping.getInsert() return and cache the full insert prepared statement.
This commit is contained in:
parent
b201bf8f35
commit
cf6d9b8330
2 changed files with 34 additions and 31 deletions
|
@ -1030,25 +1030,45 @@ public final class DbMapping implements Updatable {
|
|||
*
|
||||
* @return ...
|
||||
*/
|
||||
public StringBuffer getInsert() {
|
||||
public String getInsert() throws ClassNotFoundException, SQLException {
|
||||
String ins = insertString;
|
||||
|
||||
if (ins != null) {
|
||||
return new StringBuffer(ins);
|
||||
return ins;
|
||||
}
|
||||
|
||||
StringBuffer s = new StringBuffer("INSERT INTO ");
|
||||
StringBuffer b1 = new StringBuffer("INSERT INTO ");
|
||||
b1.append(getTableName());
|
||||
b1.append(" ( ");
|
||||
b1.append(getIDField());
|
||||
|
||||
s.append(getTableName());
|
||||
s.append(" ( ");
|
||||
s.append(getIDField());
|
||||
StringBuffer b2 = new StringBuffer(" ) VALUES ( ?");
|
||||
|
||||
DbColumn[] cols = getColumns();
|
||||
|
||||
for (int i = 0; i < cols.length; i++) {
|
||||
Relation rel = cols[i].getRelation();
|
||||
String name = cols[i].getName();
|
||||
|
||||
if (((rel != null) && (rel.isPrimitive() ||
|
||||
rel.isReference())) ||
|
||||
name.equalsIgnoreCase(getNameField()) ||
|
||||
name.equalsIgnoreCase(getPrototypeField())) {
|
||||
b1.append(", " + cols[i].getName());
|
||||
b2.append(", ?");
|
||||
}
|
||||
}
|
||||
|
||||
b1.append(b2.toString());
|
||||
b1.append(" )");
|
||||
|
||||
// cache rendered string for later calls.
|
||||
insertString = s.toString();
|
||||
ins = insertString = b1.toString();
|
||||
|
||||
return s;
|
||||
return ins;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
|
|
@ -508,34 +508,17 @@ public final class NodeManager {
|
|||
throw new NullPointerException("Error inserting relational node: Connection is null");
|
||||
}
|
||||
|
||||
String insertString = dbm.getInsert();
|
||||
PreparedStatement stmt = con.prepareStatement(insertString);
|
||||
|
||||
// app.logEvent ("inserting relational node: "+node.getID ());
|
||||
DbColumn[] columns = dbm.getColumns();
|
||||
|
||||
StringBuffer b1 = dbm.getInsert();
|
||||
StringBuffer b2 = new StringBuffer(" ) VALUES ( ?");
|
||||
|
||||
String nameField = dbm.getNameField();
|
||||
String prototypeField = dbm.getPrototypeField();
|
||||
|
||||
for (int i = 0; i < columns.length; i++) {
|
||||
Relation rel = columns[i].getRelation();
|
||||
String name = columns[i].getName();
|
||||
|
||||
if (((rel != null) && (rel.isPrimitive() || rel.isReference())) ||
|
||||
name.equalsIgnoreCase(nameField) || name.equalsIgnoreCase(prototypeField)) {
|
||||
b1.append(", " + columns[i].getName());
|
||||
b2.append(", ?");
|
||||
}
|
||||
}
|
||||
|
||||
b1.append(b2.toString());
|
||||
b1.append(" )");
|
||||
|
||||
// Connection con = dbm.getConnection();
|
||||
PreparedStatement stmt = con.prepareStatement(b1.toString());
|
||||
|
||||
if (logSql) {
|
||||
app.logEvent("### insertNode: " + b1.toString());
|
||||
app.logEvent("### insertNode: " + insertString);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
Loading…
Add table
Reference in a new issue