1 2 12 package com.versant.core.jdbc.sql; 13 14 import com.versant.core.jdbc.JdbcKeyGenerator; 15 import com.versant.core.jdbc.JdbcKeyGeneratorFactory; 16 import com.versant.core.jdbc.JdbcMetaDataBuilder; 17 import com.versant.core.jdbc.metadata.JdbcTable; 18 19 import java.sql.Connection ; 20 import java.sql.SQLException ; 21 import java.sql.Statement ; 22 import java.util.HashSet ; 23 24 import com.versant.core.common.BindingSupportImpl; 25 26 30 public class AutoIncJdbcKeyGenerator implements JdbcKeyGenerator { 31 32 protected SqlDriver sqlDriver; 33 34 37 public static class Factory implements JdbcKeyGeneratorFactory { 38 39 43 public Object createArgsBean() { 44 return null; 45 } 46 47 51 public JdbcKeyGenerator createJdbcKeyGenerator(String className, 52 JdbcTable classTable, Object args) { 53 return new AutoIncJdbcKeyGenerator(className, classTable); 54 } 55 } 56 57 public AutoIncJdbcKeyGenerator(String className, JdbcTable classTable) { 58 if (classTable.pk.length > 1) { 59 throw BindingSupportImpl.getInstance().illegalArgument("Cannot use AUTOINC key generator on a table with multiple " + 60 "primary key columns: " + classTable.name + " (" + 61 className + ")"); 62 } 63 sqlDriver = classTable.sqlDriver; 64 } 65 66 74 public void addKeyGenTables(HashSet set, JdbcMetaDataBuilder mdb) { 75 } 77 78 83 public boolean isPostInsertGenerator() { 84 return true; 85 } 86 87 93 public String getPostInsertSQLSuffix(JdbcTable classTable) { 94 return sqlDriver.getAutoIncPostInsertSQLSuffix(classTable); 95 } 96 97 111 public void generatePrimaryKeyPost(String className, 112 JdbcTable classTable, Object [] data, 113 Connection con, Statement stat) throws SQLException { 114 data[0] = sqlDriver.getAutoIncColumnValue(classTable, con, stat); 115 } 116 117 137 public void generatePrimaryKeyPre(String className, 138 JdbcTable classTable, int newObjectCount, Object [] data, 139 Connection con) throws SQLException { 140 throw BindingSupportImpl.getInstance().internal("generatePrimaryKeyPre called for " + 141 "post insert key generator"); 142 } 143 144 157 public void init(String className, JdbcTable classTable, 158 Connection con) throws SQLException { 159 } 161 162 168 public boolean isRequiresOwnConnection() { 169 return false; 170 } 171 172 } 173 174 | Popular Tags |