1 21 package oracle.toplink.essentials.internal.expressions; 23 24 import java.io.*; 25 import java.util.*; 26 import oracle.toplink.essentials.exceptions.*; 27 import oracle.toplink.essentials.internal.helper.*; 28 import oracle.toplink.essentials.queryframework.*; 29 import oracle.toplink.essentials.internal.sessions.AbstractSession; 30 31 39 public class SQLInsertStatement extends SQLModifyStatement { 40 41 44 protected SQLCall buildCallWithoutReturning(AbstractSession session) { 45 SQLCall call = new SQLCall(); 46 call.returnNothing(); 47 48 Writer writer = new CharArrayWriter(200); 49 try { 50 writer.write("INSERT "); 51 writer.write("INTO "); 52 writer.write(getTable().getQualifiedName()); 53 writer.write(" ("); 54 55 Vector fieldsForTable = new Vector(); 56 for (Enumeration fieldsEnum = getModifyRow().keys(); fieldsEnum.hasMoreElements();) { 57 DatabaseField field = (DatabaseField)fieldsEnum.nextElement(); 58 if (field.getTable().equals(getTable()) || (!field.hasTableName())) { 59 fieldsForTable.addElement(field); 60 } 61 } 62 63 if (fieldsForTable.isEmpty()) { 64 throw QueryException.objectToInsertIsEmpty(getTable()); 65 } 66 67 for (int i = 0; i < fieldsForTable.size(); i++) { 68 writer.write(((DatabaseField)fieldsForTable.elementAt(i)).getName()); 69 if ((i + 1) < fieldsForTable.size()) { 70 writer.write(", "); 71 } 72 } 73 writer.write(") VALUES ("); 74 75 for (int i = 0; i < fieldsForTable.size(); i++) { 76 DatabaseField field = (DatabaseField)fieldsForTable.elementAt(i); 77 call.appendModify(writer, field); 78 if ((i + 1) < fieldsForTable.size()) { 79 writer.write(", "); 80 } 81 } 82 writer.write(")"); 83 84 call.setSQLString(writer.toString()); 85 } catch (IOException exception) { 86 throw ValidationException.fileError(exception); 87 } 88 return call; 89 } 90 } 91 | Popular Tags |