1 28 29 package com.caucho.db.sql; 30 31 import com.caucho.db.jdbc.GeneratedKeysResultSet; 32 import com.caucho.db.table.Column; 33 import com.caucho.db.table.Table; 34 import com.caucho.log.Log; 35 36 import java.sql.SQLException ; 37 import java.util.logging.Logger ; 38 39 class AutoIncrementExpr extends Expr { 40 private static final Logger log = Log.open(AutoIncrementExpr.class); 41 42 private Table _table; 43 44 AutoIncrementExpr(Table table) 45 { 46 _table = table; 47 } 48 49 52 public Class getType() 53 { 54 return long.class; 55 } 56 57 64 public long evalLong(QueryContext context) 65 throws SQLException 66 { 67 long value = _table.nextAutoIncrement(context); 68 69 GeneratedKeysResultSet keysRS = context.getGeneratedKeysResultSet(); 70 71 if (keysRS != null) { 72 Column column = _table.getAutoIncrementColumn(); 73 74 keysRS.setColumn(1, column); 75 keysRS.setLong(1, value); 76 } 77 78 return value; 79 } 80 81 88 public double evalDouble(QueryContext context) 89 throws SQLException 90 { 91 return evalLong(context); 92 } 93 94 101 public String evalString(QueryContext context) 102 throws SQLException 103 { 104 return String.valueOf(evalLong(context)); 105 } 106 107 public String toString() 108 { 109 return "auto_increment()"; 110 } 111 } 112 | Popular Tags |