}
/** <p>Creates a method for cloning one row from the given table.</p>
*/
protected JavaMethod getInsertRowMethod(JavaSource pSource, TableInfo pTableInfo) {
Table table = pTableInfo.getTable();
JavaMethod jm = pSource.newJavaMethod(getInsertRowMethodName(pTableInfo),
Object[].class, JavaSource.PRIVATE);
jm.addThrows(SQLException.class);
DirectAccessible connection = jm.addParam(Connection.class, "pConn");
DirectAccessible map = jm.addParam(Map.class, "pMap");
DirectAccessible values = jm.addParam(Object[].class, "pValue");
logFinestEntering(jm, values);
LocalJavaField baseKey = null;
if (table.getPrimaryKey() != null) {
baseKey = getCacheDataClassInstance(jm, pTableInfo,
table.getPrimaryKey(), values);
jm.addIf(map, ".containsKey(", baseKey, ")");
logFinestExiting(jm, JavaSource.getQuoted("null (Already cloned)"));
jm.addLine("return null;");
jm.addEndIf();
}
for (Iterator iter = pTableInfo.getColumnUpdaters(); iter.hasNext(); ) {
((ColumnUpdater) iter.next()).update(jm, pTableInfo, connection, map, values);
}
jm.addLine(jm.getName(), "(", connection, ", ", values, ");");
if (baseKey != null) {
LocalJavaField clonedKey = getCacheDataClassInstance(jm, pTableInfo,
table.getPrimaryKey(),
values);
jm.addLine(map, ".put(", baseKey, ", ", clonedKey, ");");
}
// Clone objects referencing this object
LocalJavaField referencedValues = null;
for (Iterator referencingIter = tablesByOrder.iterator(); referencingIter.hasNext(); ) {
TableInfo prevTableInfo = (TableInfo) referencingIter.next();
Table prevTable = prevTableInfo.getTable();
for (Iterator fkIter = prevTable.getForeignKeys(); fkIter.hasNext(); ) {
ForeignKey fk = (ForeignKey) fkIter.next();
if (fk.getReferencedTable().equals(table)) {
if (referencedValues == null) {
referencedValues = jm.newJavaField(Object[].class);
referencedValues.addLine(baseKey, ".getValues()");