From 3dedb868eaeddf2f011a7a00ec59a9838798889c Mon Sep 17 00:00:00 2001 From: zell Date: Thu, 18 Oct 2007 01:50:11 +0000 Subject: [PATCH] I made a mistake originally allowing IDENTITY value generators some partial configuration (e.g. start value and increment value). This only ever worked on PostgreSQL, and so would cause completely different behaviour under MySQL. That's obviously a bad idea. So, IdentityValueGenerator's init() was meant only to be called upon table creation, but in r2234 I began calling it in all of a table's generators after every auto-migration. Needless to say this was bloody stupid, and caused MemberRecord's primary key generator to reset in production just now. My fix is not to revert r2234, however, but to explicitly state init()'s expected behaviour: it should certainly not reset a generator if it already exists, but only ensure that it's operational -- creating it only if necessary. We now never reset an IDENTITY generator, ever. The whole point of them is, after all, that they're auto-created by the database. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2242 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/jdbc/DatabaseLiaison.java | 8 -------- src/java/com/samskivert/jdbc/MySQLLiaison.java | 8 -------- .../com/samskivert/jdbc/depot/IdentityValueGenerator.java | 3 +-- src/java/com/samskivert/jdbc/depot/ValueGenerator.java | 2 +- 4 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/java/com/samskivert/jdbc/DatabaseLiaison.java b/src/java/com/samskivert/jdbc/DatabaseLiaison.java index 0ff7c683..01cf2c48 100644 --- a/src/java/com/samskivert/jdbc/DatabaseLiaison.java +++ b/src/java/com/samskivert/jdbc/DatabaseLiaison.java @@ -57,14 +57,6 @@ public interface DatabaseLiaison */ public boolean isTransientException (SQLException sqe); - /** - * This method initializes the column value auto-generator described in {@link - * #lastInsertedId}. - */ - public void initializeGenerator ( - Connection conn, String table, String column, int first, int step) - throws SQLException; - /** * This method deletes the column value auto-generator described in {@link * #lastInsertedId}. diff --git a/src/java/com/samskivert/jdbc/MySQLLiaison.java b/src/java/com/samskivert/jdbc/MySQLLiaison.java index 55ae62ab..cea0d95c 100644 --- a/src/java/com/samskivert/jdbc/MySQLLiaison.java +++ b/src/java/com/samskivert/jdbc/MySQLLiaison.java @@ -51,14 +51,6 @@ public class MySQLLiaison extends BaseLiaison msg.indexOf("Broken pipe") != -1)); } - // from DatabaseLiaison - public void initializeGenerator ( - Connection conn, String table, String column, int first, int step) - throws SQLException - { - // AUTO_INCREMENT does not allow this kind of control - } - public void deleteGenerator (Connection conn, String tableName, String columnName) throws SQLException { diff --git a/src/java/com/samskivert/jdbc/depot/IdentityValueGenerator.java b/src/java/com/samskivert/jdbc/depot/IdentityValueGenerator.java index b53cbbc4..7b85b2c4 100644 --- a/src/java/com/samskivert/jdbc/depot/IdentityValueGenerator.java +++ b/src/java/com/samskivert/jdbc/depot/IdentityValueGenerator.java @@ -46,8 +46,7 @@ public class IdentityValueGenerator extends ValueGenerator public void init (Connection conn, DatabaseLiaison liaison) throws SQLException { - liaison.initializeGenerator( - conn, _dm.getTableName(), _fm.getColumnName(), _initialValue, _allocationSize); + // identity value generators are auto-created by the database } @Override // from ValueGenerator diff --git a/src/java/com/samskivert/jdbc/depot/ValueGenerator.java b/src/java/com/samskivert/jdbc/depot/ValueGenerator.java index 7d683040..0c9c2408 100644 --- a/src/java/com/samskivert/jdbc/depot/ValueGenerator.java +++ b/src/java/com/samskivert/jdbc/depot/ValueGenerator.java @@ -53,7 +53,7 @@ public abstract class ValueGenerator public abstract boolean isPostFactum (); /** - * Prepares the generator for operation. + * Ensures the generator is prepared for operation, creating it (only) if necessary. */ public abstract void init (Connection conn, DatabaseLiaison liaison) throws SQLException;