View Javadoc
1 /* 2 * Created on 2003-6-16 9:41:11 by joel guo 3 * 4 * vTradEx Information Technology Inc. 5 */ 6 package com.cyclops.dbdigger.idbroker; 7 import java.sql.Connection; 8 import java.text.MessageFormat; 9 10 import com.cyclops.dbdigger.DBDiggerException; 11 import com.cyclops.dbdigger.schema.Table; 12 import com.workingdogs.town.ConnDefinition; 13 import com.workingdogs.town.QueryDataSet; 14 import com.workingdogs.town.Record; 15 /*** Add description <font color="red">HERE</font>! 16 * 17 * @author <a href="mailto:joeblack.guo@vtradex.com">joel guo</a> 18 * @since 2003-6-16 9:41:11 19 */ 20 public class OracleKeyPrefetcher implements KeyPrefetcher { 21 private static final String SEQUENCE_SUFFIX = "_SEQ"; 22 private static final String SQL_FORMAT = 23 "SELECT {1}.nextval AS id FROM dual"; 24 private static final String ID = "id"; 25 /*** Override method prefectch() of super class 26 * @see com.cyclops.dbdigger.idbroker.KeyPrefetcher#prefectch(com.cyclops.dbdigger.schema.Table, java.sql.Connection) 27 */ 28 public PrimaryKey prefectch(Table table, Connection dbcon) 29 throws DBDiggerException { 30 String sql = 31 MessageFormat.format( 32 SQL_FORMAT, 33 new Object[] {getSequenceName(table)}); 34 ConnDefinition cd = ConnDefinition.getInstance(dbcon); 35 try { 36 QueryDataSet qds = new QueryDataSet(cd, sql); 37 Record r = qds.fetchRecords(1).getRecord(0); 38 return new NumberKey(r.getValue(ID).asBigDecimal()); 39 } catch (Throwable e) { 40 throw new DBDiggerException( 41 "Error when prefetch id from table " + table, 42 e); 43 } 44 } 45 /*** Get name of the sequence 46 * @param table Table object 47 * @return Sequace name 48 */ 49 protected String getSequenceName(Table table) { 50 return table.getName() + SEQUENCE_SUFFIX; 51 } 52 }

This page was automatically generated by Maven