Checkpoint: Update @GeneratedValue to handle long, not yet compiled.
My installation is outdated?
This commit is contained in:
@@ -30,7 +30,7 @@ public @interface GeneratedValue
|
|||||||
* initial value is 1. <em>Note:</em> this default differs from the value used by the EJB3
|
* initial value is 1. <em>Note:</em> this default differs from the value used by the EJB3
|
||||||
* persistence framework.
|
* persistence framework.
|
||||||
*/
|
*/
|
||||||
int initialValue () default 1;
|
long initialValue () default 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If there are rows in our corresponding table, this boolean determines whether or not to
|
* If there are rows in our corresponding table, this boolean determines whether or not to
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class IdentityValueGenerator extends ValueGenerator
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override // from ValueGenerator
|
@Override // from ValueGenerator
|
||||||
public int nextGeneratedValue (Connection conn, DatabaseLiaison liaison, Statement stmt)
|
public long nextGeneratedValue (Connection conn, DatabaseLiaison liaison, Statement stmt)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
return liaison.lastInsertedId(conn, stmt, _dm.getTableName(), _fm.getColumnName());
|
return liaison.lastInsertedId(conn, stmt, _dm.getTableName(), _fm.getColumnName());
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class TableValueGenerator extends ValueGenerator
|
|||||||
conn, _valueTable,
|
conn, _valueTable,
|
||||||
Arrays.asList(_pkColumnName, _valueColumnName),
|
Arrays.asList(_pkColumnName, _valueColumnName),
|
||||||
Arrays.asList(new ColumnDefinition("VARCHAR(255)", true, false, null),
|
Arrays.asList(new ColumnDefinition("VARCHAR(255)", true, false, null),
|
||||||
new ColumnDefinition("INTEGER")),
|
new ColumnDefinition("BIGINT")),
|
||||||
Arrays.asList(_pkColumnName));
|
Arrays.asList(_pkColumnName));
|
||||||
|
|
||||||
// and also that there's a row in it for us
|
// and also that there's a row in it for us
|
||||||
@@ -58,11 +58,11 @@ public class TableValueGenerator extends ValueGenerator
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int initialValue = _initialValue;
|
long initialValue = _initialValue;
|
||||||
if (_migrateIfExists) {
|
if (_migrateIfExists) {
|
||||||
Integer max = getFieldMaximum(conn, liaison);
|
Long max = getFieldMaximum(conn, liaison);
|
||||||
if (max != null) {
|
if (max != null) {
|
||||||
initialValue = 1 + max.intValue();
|
initialValue = 1 + max.longValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ public class TableValueGenerator extends ValueGenerator
|
|||||||
liaison.columnSQL(_pkColumnName) + ", " + liaison.columnSQL(_valueColumnName) +
|
liaison.columnSQL(_pkColumnName) + ", " + liaison.columnSQL(_valueColumnName) +
|
||||||
") VALUES (?, ?)");
|
") VALUES (?, ?)");
|
||||||
stmt.setString(1, _pkColumnValue);
|
stmt.setString(1, _pkColumnValue);
|
||||||
stmt.setInt(2, initialValue);
|
stmt.setLong(2, initialValue);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ public class TableValueGenerator extends ValueGenerator
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override // from ValueGenerator
|
@Override // from ValueGenerator
|
||||||
public int nextGeneratedValue (Connection conn, DatabaseLiaison liaison, Statement stmt)
|
public long nextGeneratedValue (Connection conn, DatabaseLiaison liaison, Statement stmt)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
// TODO: Make this lockless!
|
// TODO: Make this lockless!
|
||||||
@@ -111,12 +111,12 @@ public class TableValueGenerator extends ValueGenerator
|
|||||||
", column=" + _valueColumnName + "]");
|
", column=" + _valueColumnName + "]");
|
||||||
}
|
}
|
||||||
// fetch the next available value
|
// fetch the next available value
|
||||||
int val = rs.getInt(1);
|
int val = rs.getLong(1);
|
||||||
|
|
||||||
// claim this value locklessly
|
// claim this value locklessly
|
||||||
writeStatement.setInt(1, val + _allocationSize);
|
writeStatement.setLong(1, val + _allocationSize);
|
||||||
writeStatement.setString(2, _pkColumnValue);
|
writeStatement.setString(2, _pkColumnValue);
|
||||||
writeStatement.setInt(3, val);
|
writeStatement.setLong(3, val);
|
||||||
|
|
||||||
// if we modified a row, we know we and nobody else got this particular value!
|
// if we modified a row, we know we and nobody else got this particular value!
|
||||||
if (writeStatement.executeUpdate() == 1) {
|
if (writeStatement.executeUpdate() == 1) {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public abstract class ValueGenerator
|
|||||||
* @param stmt if post-factum, the statement that was used to perform the insert which resulted
|
* @param stmt if post-factum, the statement that was used to perform the insert which resulted
|
||||||
* in the auto-generation of a value, otherwise null.
|
* in the auto-generation of a value, otherwise null.
|
||||||
*/
|
*/
|
||||||
public abstract int nextGeneratedValue (Connection conn, DatabaseLiaison liaison, Statement stmt)
|
public abstract long nextGeneratedValue (Connection conn, DatabaseLiaison liaison, Statement stmt)
|
||||||
throws SQLException;
|
throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,10 +61,10 @@ public abstract class ValueGenerator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Scans the table associated with this {@link ValueGenerator} and returns either null, if
|
* Scans the table associated with this {@link ValueGenerator} and returns either null, if
|
||||||
* there are no rows, or an {@link Integer} containing the largest numerical value our
|
* there are no rows, or a {@link Long} containing the largest numerical value our
|
||||||
* field attains.
|
* field attains.
|
||||||
*/
|
*/
|
||||||
protected Integer getFieldMaximum (Connection conn, DatabaseLiaison liaison)
|
protected Long getFieldMaximum (Connection conn, DatabaseLiaison liaison)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
String column = _fm.getColumnName();
|
String column = _fm.getColumnName();
|
||||||
@@ -79,9 +79,9 @@ public abstract class ValueGenerator
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cnt = rs.getInt(1);
|
long cnt = rs.getLong(1);
|
||||||
if (cnt > 0) {
|
if (cnt > 0) {
|
||||||
return Integer.valueOf(rs.getInt(2));
|
return Long.valueOf(rs.getLong(2));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ public abstract class ValueGenerator
|
|||||||
return _fm;
|
return _fm;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int _initialValue;
|
protected long _initialValue;
|
||||||
protected int _allocationSize;
|
protected int _allocationSize;
|
||||||
protected boolean _migrateIfExists;
|
protected boolean _migrateIfExists;
|
||||||
|
|
||||||
|
|||||||
@@ -41,18 +41,18 @@ public abstract class BaseLiaison implements DatabaseLiaison
|
|||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public int lastInsertedId (Connection conn, String table, String column) throws SQLException {
|
public int lastInsertedId (Connection conn, String table, String column) throws SQLException {
|
||||||
return lastInsertedId(conn, null, table, column);
|
return (int)lastInsertedId(conn, null, table, column);
|
||||||
}
|
}
|
||||||
|
|
||||||
// from DatabaseLiaison
|
// from DatabaseLiaison
|
||||||
public int lastInsertedId (Connection conn, Statement istmt, String table, String column)
|
public long lastInsertedId (Connection conn, Statement istmt, String table, String column)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
// if this JDBC driver supports getGeneratedKeys, use it!
|
// if this JDBC driver supports getGeneratedKeys, use it!
|
||||||
if (istmt != null && conn.getMetaData().supportsGetGeneratedKeys()) {
|
if (istmt != null && conn.getMetaData().supportsGetGeneratedKeys()) {
|
||||||
ResultSet rs = istmt.getGeneratedKeys();
|
ResultSet rs = istmt.getGeneratedKeys();
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
return rs.getInt(column);
|
return rs.getLong(column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fetchLastInsertedId(conn, table, column);
|
return fetchLastInsertedId(conn, table, column);
|
||||||
@@ -62,7 +62,7 @@ public abstract class BaseLiaison implements DatabaseLiaison
|
|||||||
* Requests the last inserted id for the specified table and column. This is used if a JDBC
|
* Requests the last inserted id for the specified table and column. This is used if a JDBC
|
||||||
* driver does not support {@code getGeneratedKeys} or an attempt to use that failed.
|
* driver does not support {@code getGeneratedKeys} or an attempt to use that failed.
|
||||||
*/
|
*/
|
||||||
protected int fetchLastInsertedId (Connection conn, String table, String column)
|
protected long fetchLastInsertedId (Connection conn, String table, String column)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
throw new SQLException(
|
throw new SQLException(
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public interface DatabaseLiaison
|
|||||||
* @return the requested inserted id.
|
* @return the requested inserted id.
|
||||||
* @throws SQLException if we are unable to obtain the last inserted id.
|
* @throws SQLException if we are unable to obtain the last inserted id.
|
||||||
*/
|
*/
|
||||||
public int lastInsertedId (Connection conn, Statement istmt, String table, String column)
|
public long lastInsertedId (Connection conn, Statement istmt, String table, String column)
|
||||||
throws SQLException;
|
throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class HsqldbLiaison extends BaseLiaison
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int fetchLastInsertedId (Connection conn, String table, String column)
|
protected long fetchLastInsertedId (Connection conn, String table, String column)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
// HSQL does not keep track of per-table-and-column insertion data, so we are pretty much
|
// HSQL does not keep track of per-table-and-column insertion data, so we are pretty much
|
||||||
@@ -85,7 +85,7 @@ public class HsqldbLiaison extends BaseLiaison
|
|||||||
try {
|
try {
|
||||||
stmt = conn.createStatement();
|
stmt = conn.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery("call IDENTITY()");
|
ResultSet rs = stmt.executeQuery("call IDENTITY()");
|
||||||
return rs.next() ? rs.getInt(1) : super.fetchLastInsertedId(conn, table, column);
|
return rs.next() ? rs.getLong(1) : super.fetchLastInsertedId(conn, table, column);
|
||||||
} finally {
|
} finally {
|
||||||
JDBCUtil.close(stmt);
|
JDBCUtil.close(stmt);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class MySQLLiaison extends BaseLiaison
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override // from BaseLiaison
|
@Override // from BaseLiaison
|
||||||
public int lastInsertedId (Connection conn, Statement istmt, String table, String column)
|
public long lastInsertedId (Connection conn, Statement istmt, String table, String column)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
// MySQL uses "GENERATED_KEY" as the column name for the last inserted key, so we have to
|
// MySQL uses "GENERATED_KEY" as the column name for the last inserted key, so we have to
|
||||||
@@ -59,7 +59,7 @@ public class MySQLLiaison extends BaseLiaison
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int fetchLastInsertedId (Connection conn, String table, String column)
|
protected long fetchLastInsertedId (Connection conn, String table, String column)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
// MySQL does not keep track of per-table-and-column insertion data, so we are pretty much
|
// MySQL does not keep track of per-table-and-column insertion data, so we are pretty much
|
||||||
@@ -69,7 +69,7 @@ public class MySQLLiaison extends BaseLiaison
|
|||||||
try {
|
try {
|
||||||
stmt = conn.createStatement();
|
stmt = conn.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery("select LAST_INSERT_ID()");
|
ResultSet rs = stmt.executeQuery("select LAST_INSERT_ID()");
|
||||||
return rs.next() ? rs.getInt(1) : super.fetchLastInsertedId(conn, table, column);
|
return rs.next() ? rs.getLong(1) : super.fetchLastInsertedId(conn, table, column);
|
||||||
} finally {
|
} finally {
|
||||||
JDBCUtil.close(stmt);
|
JDBCUtil.close(stmt);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class PostgreSQLLiaison extends BaseLiaison
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int fetchLastInsertedId (Connection conn, String table, String column)
|
protected long fetchLastInsertedId (Connection conn, String table, String column)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
// PostgreSQL's support for auto-generated ID's comes in the form of appropriately named
|
// PostgreSQL's support for auto-generated ID's comes in the form of appropriately named
|
||||||
@@ -46,14 +46,14 @@ public class PostgreSQLLiaison extends BaseLiaison
|
|||||||
try {
|
try {
|
||||||
ResultSet rs = stmt.executeQuery(
|
ResultSet rs = stmt.executeQuery(
|
||||||
"select currval('\"" + table + "_" + column + "_seq\"')");
|
"select currval('\"" + table + "_" + column + "_seq\"')");
|
||||||
return rs.next() ? rs.getInt(1) : super.fetchLastInsertedId(conn, table, column);
|
return rs.next() ? rs.getLong(1) : super.fetchLastInsertedId(conn, table, column);
|
||||||
} finally {
|
} finally {
|
||||||
JDBCUtil.close(stmt);
|
JDBCUtil.close(stmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// from DatabaseLiaison
|
// from DatabaseLiaison
|
||||||
public void createGenerator (Connection conn, String tableName, String columnName, int initValue)
|
public void createGenerator (Connection conn, String tableName, String columnName, long initValue)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
if (initValue == 1) {
|
if (initValue == 1) {
|
||||||
|
|||||||
@@ -12,23 +12,23 @@ public class GeneratedValueRecord extends PersistentRecord
|
|||||||
{
|
{
|
||||||
// AUTO-GENERATED: FIELDS START
|
// AUTO-GENERATED: FIELDS START
|
||||||
public static final Class<GeneratedValueRecord> _R = GeneratedValueRecord.class;
|
public static final Class<GeneratedValueRecord> _R = GeneratedValueRecord.class;
|
||||||
public static final ColumnExp<Integer> RECORD_ID = colexp(_R, "recordId");
|
public static final ColumnExp<Long> RECORD_ID = colexp(_R, "recordId");
|
||||||
public static final ColumnExp<Integer> VALUE = colexp(_R, "value");
|
public static final ColumnExp<Long> VALUE = colexp(_R, "value");
|
||||||
// AUTO-GENERATED: FIELDS END
|
// AUTO-GENERATED: FIELDS END
|
||||||
|
|
||||||
public static final int SCHEMA_VERSION = 1;
|
public static final int SCHEMA_VERSION = 2;
|
||||||
|
|
||||||
@Id @GeneratedValue
|
@Id @GeneratedValue
|
||||||
public int recordId;
|
public long recordId;
|
||||||
|
|
||||||
public int value;
|
public long value;
|
||||||
|
|
||||||
// AUTO-GENERATED: METHODS START
|
// AUTO-GENERATED: METHODS START
|
||||||
/**
|
/**
|
||||||
* Create and return a primary {@link Key} to identify a {@link GeneratedValueRecord}
|
* Create and return a primary {@link Key} to identify a {@link GeneratedValueRecord}
|
||||||
* with the supplied key values.
|
* with the supplied key values.
|
||||||
*/
|
*/
|
||||||
public static Key<GeneratedValueRecord> getKey (int recordId)
|
public static Key<GeneratedValueRecord> getKey (long recordId)
|
||||||
{
|
{
|
||||||
return newKey(_R, recordId);
|
return newKey(_R, recordId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user