Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/id In directory sc8-pr-cvs1:/tmp/cvs-serv14211/src/net/sf/hibernate/id Modified Files: Assigned.java HexGenerator.java HiLoGenerator.java HiLoHexGenerator.java IdentifierGenerationException.java IdentifierGenerator.java LongGenerator.java NativeGenerator.java PersistentIdentifierGenerator.java SequenceGenerator.java SequenceHiLoGenerator.java UUIDGenerator.java UUIDHexGenerator.java UUIDStringGenerator.java Log Message: reformatted code with beautiful, shiny, happy TABS! improved an exception Index: Assigned.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/id/Assigned.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Assigned.java 1 Jan 2003 13:54:39 -0000 1.1.1.1 --- Assigned.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 8,12 **** import net.sf.hibernate.engine.SessionImplementor; ! /** * <b>assigned</b><br> * <br> --- 8,12 ---- import net.sf.hibernate.engine.SessionImplementor; ! /** * <b>assigned</b><br> * <br> *************** *** 17,21 **** public static final Assigned INSTANCE = new Assigned(); ! public Serializable generate(SessionImplementor session, Object obj) throws HibernateException { if (obj instanceof PersistentCollection) throw new IdentifierGenerationException( --- 17,21 ---- public static final Assigned INSTANCE = new Assigned(); ! public Serializable generate(SessionImplementor session, Object obj) throws HibernateException { if (obj instanceof PersistentCollection) throw new IdentifierGenerationException( *************** *** 24,31 **** final Serializable id = session.getPersister(obj).getIdentifier(obj); if (id==null) throw new IdentifierGenerationException( ! "ids for this class must be manually assigned before calling save(): " + obj.getClass().getName() ); return id; } ! } --- 24,34 ---- final Serializable id = session.getPersister(obj).getIdentifier(obj); if (id==null) throw new IdentifierGenerationException( ! "ids for this class must be manually assigned before calling save(): " + obj.getClass().getName() ); return id; } ! } + + + Index: HexGenerator.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/id/HexGenerator.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** HexGenerator.java 1 Jan 2003 13:54:39 -0000 1.1.1.1 --- HexGenerator.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 6,22 **** import net.sf.hibernate.engine.SessionImplementor; ! /** * <b>vm.hex</b><br> * <br> ! * An <tt>IdentifierGenerator</tt> that returns a string of hexadecimal digits of ! * length 16, constructed from the system time and a counter value. Not safe * for use in a cluster! */ public class HexGenerator extends LongGenerator { ! public Serializable generate(SessionImplementor session, Object obj) { return Long.toHexString( ( (Long) super.generate(session, obj) ).longValue() ); } ! public static void main( String[] args ) throws Exception { IdentifierGenerator gen = new HexGenerator(); --- 6,22 ---- import net.sf.hibernate.engine.SessionImplementor; ! /** * <b>vm.hex</b><br> * <br> ! * An <tt>IdentifierGenerator</tt> that returns a string of hexadecimal digits of ! * length 16, constructed from the system time and a counter value. Not safe * for use in a cluster! */ public class HexGenerator extends LongGenerator { ! public Serializable generate(SessionImplementor session, Object obj) { return Long.toHexString( ( (Long) super.generate(session, obj) ).longValue() ); } ! public static void main( String[] args ) throws Exception { IdentifierGenerator gen = new HexGenerator(); *************** *** 25,28 **** } } ! } --- 25,31 ---- } } ! } + + + Index: HiLoGenerator.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/id/HiLoGenerator.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** HiLoGenerator.java 1 Jan 2003 13:54:39 -0000 1.1.1.1 --- HiLoGenerator.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 19,23 **** * <b>hilo.long</b><br> * <br> ! * An <tt>IdentifierGenerator</tt> that returns a <tt>Long</tt>, constructed using * a hi/lo algorithm. The hi value MUST be fetched in a seperate transaction * to the <tt>Session</tt> transaction so the generator must be able to obtain --- 19,23 ---- * <b>hilo.long</b><br> * <br> ! * An <tt>IdentifierGenerator</tt> that returns a <tt>Long</tt>, constructed using * a hi/lo algorithm. The hi value MUST be fetched in a seperate transaction * to the <tt>Session</tt> transaction so the generator must be able to obtain *************** *** 29,171 **** * <br> * Two mapping parameters are supported: tablename, columnname. ! * * @see SequenceHiLoGenerator */ public class HiLoGenerator implements PersistentIdentifierGenerator { ! ! private long hi; ! private short lo = Short.MAX_VALUE; ! private final String tableName; ! private final String columnName; ! private final String query; ! private final String update; ! ! private ConnectionProvider connections; ! ! private static final Log log = LogFactory.getLog(HiLoGenerator.class); ! ! public HiLoGenerator(String tableName, String columnName) { ! this.tableName = tableName; ! this.columnName = columnName; ! query = "select " + columnName + " from " + tableName; ! update = "update " + tableName + " set " + columnName + " = ? where " + columnName + " = ?"; ! } ! ! public HiLoGenerator() { ! this("hibernate_unique_key", "next_hi"); ! } ! ! public HiLoGenerator(String driverclass, String url, String username, String password) throws HibernateException { ! this(); ! connections = getConnectionProvider(driverclass, url, username, password); ! } ! ! public HiLoGenerator(String driverclass, String url, String username, String password, String tablename, String columnname) throws HibernateException { ! this(tablename, columnname); ! connections = getConnectionProvider(driverclass, url, username, password); ! } ! ! protected ConnectionProvider getConnectionProvider(String driverclass, String url, String username, String password) throws HibernateException { ! Properties props = new Properties(); ! props.put(Environment.DRIVER, driverclass); ! props.put(Environment.URL, url); ! props.put(Environment.USER, username); ! props.put(Environment.PASS, password); return ConnectionProviderFactory.newConnectionProvider(props); ! } ! ! public synchronized Serializable generate(SessionImplementor session, Object obj) throws SQLException { ! if (lo == Short.MAX_VALUE) { ! int rows; ! int hiInt; ! // This has to be done using a different connection to the ! // containing transaction because the new hi value must ! // remain valid even if the containing transaction rolls ! // back ! Connection conn; ! if (connections==null) { ! conn = session.getFactory().openConnection(); ! } ! else { ! conn = connections.getConnection(); ! } ! ! try { ! ! do { ! // The loop ensures atomicity of the ! // select + update even for no transaction ! // or read committed isolation level ! PreparedStatement qps = conn.prepareStatement(query); ! try { ! ResultSet rs = qps.executeQuery(); ! rs.next(); ! hiInt = rs.getInt(columnName); ! rs.close(); ! } ! catch (SQLException sqle) { ! log.error("could not read a hi value - may need to populate the table: " + tableName, sqle); ! throw sqle; ! } ! finally { ! qps.close(); ! } ! ! PreparedStatement ups = conn.prepareStatement(update); ! try { ! ups.setInt( 1, hiInt + 1 ); ! ups.setInt( 2, hiInt ); ! rows = ups.executeUpdate(); ! } ! catch (SQLException sqle) { ! log.error("could not update hi value in: " + tableName, sqle); ! throw sqle; ! } ! finally { ! ups.close(); ! } ! } ! while (rows==0); ! ! conn.commit(); ! ! lo = 0; ! hi = hiInt; ! ! } ! finally { ! ! if (connections==null) { ! session.getFactory().closeConnection(conn); ! } ! else { ! connections.closeConnection(conn); ! } ! ! } ! log.debug("New hi value: " + hi); ! } ! ! return new Long( ( hi << 16 ) + lo++ ); ! ! } ! ! ! public String[] sqlCreateStrings(Dialect dialect) throws HibernateException { ! return new String[] { ! "create table " + tableName + " ( " + columnName + " " + dialect.getTypeName(Types.INTEGER) + " )", ! "insert into " + tableName + " values ( 0 )" ! }; ! } - public String sqlDropString(Dialect dialect) { - return "drop table " + tableName; - } - public Object generatorKey() { - return tableName; - } - } --- 29,174 ---- * <br> * Two mapping parameters are supported: tablename, columnname. ! * * @see SequenceHiLoGenerator */ public class HiLoGenerator implements PersistentIdentifierGenerator { ! ! private long hi; ! private short lo = Short.MAX_VALUE; ! private final String tableName; ! private final String columnName; ! private final String query; ! private final String update; ! ! private ConnectionProvider connections; ! ! private static final Log log = LogFactory.getLog(HiLoGenerator.class); ! ! public HiLoGenerator(String tableName, String columnName) { ! this.tableName = tableName; ! this.columnName = columnName; ! query = "select " + columnName + " from " + tableName; ! update = "update " + tableName + " set " + columnName + " = ? where " + columnName + " = ?"; ! } ! ! public HiLoGenerator() { ! this("hibernate_unique_key", "next_hi"); ! } ! ! public HiLoGenerator(String driverclass, String url, String username, String password) throws HibernateException { ! this(); ! connections = getConnectionProvider(driverclass, url, username, password); ! } ! ! public HiLoGenerator(String driverclass, String url, String username, String password, String tablename, String columnname) throws HibernateException { ! this(tablename, columnname); ! connections = getConnectionProvider(driverclass, url, username, password); ! } ! ! protected ConnectionProvider getConnectionProvider(String driverclass, String url, String username, String password) throws HibernateException { ! Properties props = new Properties(); ! props.put(Environment.DRIVER, driverclass); ! props.put(Environment.URL, url); ! props.put(Environment.USER, username); ! props.put(Environment.PASS, password); return ConnectionProviderFactory.newConnectionProvider(props); ! } ! ! public synchronized Serializable generate(SessionImplementor session, Object obj) throws SQLException { ! if (lo == Short.MAX_VALUE) { ! int rows; ! int hiInt; ! // This has to be done using a different connection to the ! // containing transaction because the new hi value must ! // remain valid even if the containing transaction rolls ! // back ! Connection conn; ! if (connections==null) { ! conn = session.getFactory().openConnection(); ! } ! else { ! conn = connections.getConnection(); ! } ! ! try { ! ! do { ! // The loop ensures atomicity of the ! // select + update even for no transaction ! // or read committed isolation level ! PreparedStatement qps = conn.prepareStatement(query); ! try { ! ResultSet rs = qps.executeQuery(); ! rs.next(); ! hiInt = rs.getInt(columnName); ! rs.close(); ! } ! catch (SQLException sqle) { ! log.error("could not read a hi value - may need to populate the table: " + tableName, sqle); ! throw sqle; ! } ! finally { ! qps.close(); ! } ! ! PreparedStatement ups = conn.prepareStatement(update); ! try { ! ups.setInt( 1, hiInt + 1 ); ! ups.setInt( 2, hiInt ); ! rows = ups.executeUpdate(); ! } ! catch (SQLException sqle) { ! log.error("could not update hi value in: " + tableName, sqle); ! throw sqle; ! } ! finally { ! ups.close(); ! } ! } ! while (rows==0); ! ! conn.commit(); ! ! lo = 0; ! hi = hiInt; ! ! } ! finally { ! ! if (connections==null) { ! session.getFactory().closeConnection(conn); ! } ! else { ! connections.closeConnection(conn); ! } ! ! } ! log.debug("New hi value: " + hi); ! } ! ! return new Long( ( hi << 16 ) + lo++ ); ! ! } ! ! ! public String[] sqlCreateStrings(Dialect dialect) throws HibernateException { ! return new String[] { ! "create table " + tableName + " ( " + columnName + " " + dialect.getTypeName(Types.INTEGER) + " )", ! "insert into " + tableName + " values ( 0 )" ! }; ! } ! ! public String sqlDropString(Dialect dialect) { ! return "drop table " + tableName; ! } ! ! public Object generatorKey() { ! return tableName; ! } ! ! } Index: HiLoHexGenerator.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/id/HiLoHexGenerator.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** HiLoHexGenerator.java 1 Jan 2003 13:54:40 -0000 1.1.1.1 --- HiLoHexGenerator.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 8,15 **** import net.sf.hibernate.engine.SessionImplementor; ! /** * <b>hilo.hex</b><br> * <br> ! * Returns a string of hex digits of length 16. Otherwise identical to * <tt>HiLoGenerator</tt>.<br> * <br> --- 8,15 ---- import net.sf.hibernate.engine.SessionImplementor; ! /** * <b>hilo.hex</b><br> * <br> ! * Returns a string of hex digits of length 16. Otherwise identical to * <tt>HiLoGenerator</tt>.<br> * <br> *************** *** 19,27 **** public class HiLoHexGenerator extends HiLoGenerator { ! public Serializable generate(SessionImplementor session, Object obj) throws SQLException { return Long.toHexString( ( (Long) super.generate(session, obj) ).longValue() ); } ! public HiLoHexGenerator(String driverclass, String url, String username, String password) throws HibernateException { super(driverclass, url, username, password); --- 19,27 ---- public class HiLoHexGenerator extends HiLoGenerator { ! public Serializable generate(SessionImplementor session, Object obj) throws SQLException { return Long.toHexString( ( (Long) super.generate(session, obj) ).longValue() ); } ! public HiLoHexGenerator(String driverclass, String url, String username, String password) throws HibernateException { super(driverclass, url, username, password); *************** *** 31,35 **** super(driverclass, url, username, password, tableName, columnName); } ! public HiLoHexGenerator(String tableName, String columnName) { super(tableName, columnName); --- 31,35 ---- super(driverclass, url, username, password, tableName, columnName); } ! public HiLoHexGenerator(String tableName, String columnName) { super(tableName, columnName); *************** *** 39,44 **** super(); } - } --- 39,47 ---- super(); } + + + } + Index: IdentifierGenerationException.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/id/IdentifierGenerationException.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** IdentifierGenerationException.java 1 Jan 2003 13:54:40 -0000 1.1.1.1 --- IdentifierGenerationException.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 5,16 **** /** ! * Thrown by <tt>IdentifierGenerator</tt> implementation class when * ID generation fails. ! * * @see IdentifierGenerator */ public class IdentifierGenerationException extends HibernateException { ! public IdentifierGenerationException(String msg) { super(msg); --- 5,16 ---- /** ! * Thrown by <tt>IdentifierGenerator</tt> implementation class when * ID generation fails. ! * * @see IdentifierGenerator */ public class IdentifierGenerationException extends HibernateException { ! public IdentifierGenerationException(String msg) { super(msg); *************** *** 22,23 **** --- 22,26 ---- } + + + Index: IdentifierGenerator.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/id/IdentifierGenerator.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** IdentifierGenerator.java 1 Jan 2003 13:54:40 -0000 1.1.1.1 --- IdentifierGenerator.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 9,13 **** import java.sql.SQLException; ! /** * The general contract between a class that generates unique * IDs and the <tt>Session</tt>. It is not intended that this --- 9,13 ---- import java.sql.SQLException; ! /** * The general contract between a class that generates unique * IDs and the <tt>Session</tt>. It is not intended that this *************** *** 21,25 **** * <br> * Implementors MUST be threadsafe ! * * @see PersistentIdentifierGenerator */ --- 21,25 ---- * <br> * Implementors MUST be threadsafe ! * * @see PersistentIdentifierGenerator */ *************** *** 27,31 **** /** * Generate a new identifier. ! * @param session * @param object the entity or toplevel collection for which the id is being generated * @return Serializable a new identifier --- 27,31 ---- /** * Generate a new identifier. ! * @param session * @param object the entity or toplevel collection for which the id is being generated * @return Serializable a new identifier *************** *** 35,36 **** --- 35,39 ---- public Serializable generate(SessionImplementor session, Object object) throws SQLException, HibernateException; } + + + Index: LongGenerator.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/id/LongGenerator.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** LongGenerator.java 1 Jan 2003 13:54:41 -0000 1.1.1.1 --- LongGenerator.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 6,19 **** import net.sf.hibernate.engine.SessionImplementor; ! /** * <b>vm.long</b><br> * <br> ! * An <tt>IdentifierGenerator</tt> that returns a <tt>Long</tt>, constructed from the * system time and a counter value. Not safe for use in a cluster! */ public class LongGenerator implements IdentifierGenerator { ! private static short counter = (short) 0; ! protected short getCount() { synchronized(LongGenerator.class) { --- 6,19 ---- import net.sf.hibernate.engine.SessionImplementor; ! /** * <b>vm.long</b><br> * <br> ! * An <tt>IdentifierGenerator</tt> that returns a <tt>Long</tt>, constructed from the * system time and a counter value. Not safe for use in a cluster! */ public class LongGenerator implements IdentifierGenerator { ! private static short counter = (short) 0; ! protected short getCount() { synchronized(LongGenerator.class) { *************** *** 22,30 **** } } ! public Serializable generate(SessionImplementor cache, Object obj) { return new Long( ( System.currentTimeMillis() << 16 ) + getCount() ); } ! public static void main( String[] args ) throws Exception { IdentifierGenerator gen = new LongGenerator(); --- 22,30 ---- } } ! public Serializable generate(SessionImplementor cache, Object obj) { return new Long( ( System.currentTimeMillis() << 16 ) + getCount() ); } ! public static void main( String[] args ) throws Exception { IdentifierGenerator gen = new LongGenerator(); *************** *** 34,37 **** } } ! } --- 34,40 ---- } } ! } + + + Index: NativeGenerator.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/id/NativeGenerator.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** NativeGenerator.java 1 Jan 2003 13:54:41 -0000 1.1.1.1 --- NativeGenerator.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 12,19 **** * <b>native</b><br> * <br> ! * Indicates to the <tt>Session</tt> that identity (ie. identity/autoincrement ! * column) key generation should be used, if supported. Otherwise a sequence is * used. ! * * @see SequenceGenerator */ --- 12,19 ---- * <b>native</b><br> * <br> ! * Indicates to the <tt>Session</tt> that identity (ie. identity/autoincrement ! * column) key generation should be used, if supported. Otherwise a sequence is * used. ! * * @see SequenceGenerator */ *************** *** 28,55 **** seqgen = new SequenceGenerator(sequenceName); } ! ! public Serializable generate(SessionImplementor s, Object obj) throws SQLException, HibernateException { ! if ( s.getFactory().getDialect().supportsIdentityColumns() ) { ! return null; ! } ! else { ! return seqgen.generate(s, obj); ! } ! } ! public Object generatorKey() { return "native:" + (String) seqgen.generatorKey(); } ! public String[] sqlCreateStrings(Dialect dialect) ! throws HibernateException { return dialect.supportsIdentityColumns() ? ! new String[0] : ! seqgen.sqlCreateStrings(dialect); } ! public String sqlDropString(Dialect dialect) throws HibernateException { return dialect.supportsIdentityColumns() ? null : seqgen.sqlDropString(dialect); } ! } --- 28,58 ---- seqgen = new SequenceGenerator(sequenceName); } ! ! public Serializable generate(SessionImplementor s, Object obj) throws SQLException, HibernateException { ! if ( s.getFactory().getDialect().supportsIdentityColumns() ) { ! return null; ! } ! else { ! return seqgen.generate(s, obj); ! } ! } ! public Object generatorKey() { return "native:" + (String) seqgen.generatorKey(); } ! public String[] sqlCreateStrings(Dialect dialect) ! throws HibernateException { return dialect.supportsIdentityColumns() ? ! new String[0] : ! seqgen.sqlCreateStrings(dialect); } ! public String sqlDropString(Dialect dialect) throws HibernateException { return dialect.supportsIdentityColumns() ? null : seqgen.sqlDropString(dialect); } ! } + + + Index: PersistentIdentifierGenerator.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/id/PersistentIdentifierGenerator.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** PersistentIdentifierGenerator.java 1 Jan 2003 13:54:41 -0000 1.1.1.1 --- PersistentIdentifierGenerator.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 7,16 **** /** * An <tt>IdentifierGenerator</tt> that requires creation of database objects. ! * * @see IdentifierGenerator */ public interface PersistentIdentifierGenerator extends IdentifierGenerator { ! /** * The SQL required to create the underlying database objects. --- 7,16 ---- /** * An <tt>IdentifierGenerator</tt> that requires creation of database objects. ! * * @see IdentifierGenerator */ public interface PersistentIdentifierGenerator extends IdentifierGenerator { ! /** * The SQL required to create the underlying database objects. *************** *** 35,38 **** */ public Object generatorKey(); ! } --- 35,41 ---- */ public Object generatorKey(); ! } + + + Index: SequenceGenerator.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/id/SequenceGenerator.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** SequenceGenerator.java 1 Jan 2003 13:54:42 -0000 1.1.1.1 --- SequenceGenerator.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 13,17 **** import net.sf.hibernate.dialect.Dialect; ! /** * <b>sequence</b><br> * <br> --- 13,17 ---- import net.sf.hibernate.dialect.Dialect; ! /** * <b>sequence</b><br> * <br> *************** *** 20,24 **** * <br> * One mapping parameter is supported: sequencename. ! * * @see SequenceHiLoGenerator * @see HiLoGenerator --- 20,24 ---- * <br> * One mapping parameter is supported: sequencename. ! * * @see SequenceHiLoGenerator * @see HiLoGenerator *************** *** 26,34 **** public class SequenceGenerator implements PersistentIdentifierGenerator { ! private final String sequenceName; private static final Log log = LogFactory.getLog(SequenceGenerator.class); ! public SequenceGenerator(String sequenceName) { this.sequenceName = sequenceName; --- 26,34 ---- public class SequenceGenerator implements PersistentIdentifierGenerator { ! private final String sequenceName; private static final Log log = LogFactory.getLog(SequenceGenerator.class); ! public SequenceGenerator(String sequenceName) { this.sequenceName = sequenceName; *************** *** 40,44 **** public Serializable generate(SessionImplementor session, Object obj) throws SQLException, HibernateException { ! String sql = session.getFactory().getDialect().getSequenceNextValString(sequenceName); PreparedStatement st = session.getBatcher().prepareStatement(sql); --- 40,44 ---- public Serializable generate(SessionImplementor session, Object obj) throws SQLException, HibernateException { ! String sql = session.getFactory().getDialect().getSequenceNextValString(sequenceName); PreparedStatement st = session.getBatcher().prepareStatement(sql); *************** *** 71,82 **** }; } ! public String sqlDropString(Dialect dialect) throws HibernateException { return dialect.getDropSequenceString(sequenceName); } ! public Object generatorKey() { return sequenceName; } ! } --- 71,85 ---- }; } ! public String sqlDropString(Dialect dialect) throws HibernateException { return dialect.getDropSequenceString(sequenceName); } ! public Object generatorKey() { return sequenceName; } ! } + + + Index: SequenceHiLoGenerator.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/id/SequenceHiLoGenerator.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** SequenceHiLoGenerator.java 1 Jan 2003 13:54:42 -0000 1.1.1.1 --- SequenceHiLoGenerator.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 15,26 **** * <br> * An <tt>IdentifierGenerator</tt> that combines a hi/lo algorithm with an underlying ! * oracle-style sequence that generates hi values. The user may specify a * maximum lo value to determine how often new hi values are fetched.<br> * <br> ! * If sequences are not available, <tt>HiLoGenerator</tt> might be an * alternative.<br> * <br> * One mapping parameter is supported: sequencename. ! * * @see HiLoGenerator */ --- 15,26 ---- * <br> * An <tt>IdentifierGenerator</tt> that combines a hi/lo algorithm with an underlying ! * oracle-style sequence that generates hi values. The user may specify a * maximum lo value to determine how often new hi values are fetched.<br> * <br> ! * If sequences are not available, <tt>HiLoGenerator</tt> might be an * alternative.<br> * <br> * One mapping parameter is supported: sequencename. ! * * @see HiLoGenerator */ *************** *** 44,48 **** this("hibernate_sequence"); } ! public synchronized Serializable generate(SessionImplementor session, Object obj) throws SQLException, HibernateException { if ( lo==maxLoValue ) { --- 44,48 ---- this("hibernate_sequence"); } ! public synchronized Serializable generate(SessionImplementor session, Object obj) throws SQLException, HibernateException { if ( lo==maxLoValue ) { *************** *** 54,57 **** return new Long( hi + lo++ ); } ! } --- 54,60 ---- return new Long( hi + lo++ ); } ! } + + + Index: UUIDGenerator.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/id/UUIDGenerator.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** UUIDGenerator.java 1 Jan 2003 13:54:42 -0000 1.1.1.1 --- UUIDGenerator.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 5,12 **** import net.sf.hibernate.util.BytesHelper; ! /** * The base class for ID generators that use a UUID algorithm. This * class implements the algorithm, subclasses define the ID format. ! * * @see UUIDHexGenerator * @see UUIDStringGenerator --- 5,12 ---- import net.sf.hibernate.util.BytesHelper; ! /** * The base class for ID generators that use a UUID algorithm. This * class implements the algorithm, subclasses define the ID format. ! * * @see UUIDHexGenerator * @see UUIDStringGenerator *************** *** 14,18 **** public abstract class UUIDGenerator implements IdentifierGenerator { ! private static final int ip; static { --- 14,18 ---- public abstract class UUIDGenerator implements IdentifierGenerator { ! private static final int ip; static { *************** *** 28,36 **** private static short counter = (short) 0; private static final int jvm = (int) ( System.currentTimeMillis() >>> 8 ); ! public UUIDGenerator() { } ! ! /** * Unique across JVMs on this machine (unless they load this class * in the same quater second - very unlikely) --- 28,36 ---- private static short counter = (short) 0; private static final int jvm = (int) ( System.currentTimeMillis() >>> 8 ); ! public UUIDGenerator() { } ! ! /** * Unique across JVMs on this machine (unless they load this class * in the same quater second - very unlikely) *************** *** 39,44 **** return jvm; } ! ! /** * Unique in a millisecond for this JVM instance (unless there * are > Short.MAX_VALUE instances created in a millisecond) --- 39,44 ---- return jvm; } ! ! /** * Unique in a millisecond for this JVM instance (unless there * are > Short.MAX_VALUE instances created in a millisecond) *************** *** 50,55 **** } } ! ! /** * Unique in a local network */ --- 50,55 ---- } } ! ! /** * Unique in a local network */ *************** *** 57,62 **** return ip; } ! ! /** * Unique down to millisecond */ --- 57,62 ---- return ip; } ! ! /** * Unique down to millisecond */ *************** *** 67,71 **** return (int) System.currentTimeMillis(); } - } \ No newline at end of file --- 67,73 ---- return (int) System.currentTimeMillis(); } + + + } Index: UUIDHexGenerator.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/id/UUIDHexGenerator.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** UUIDHexGenerator.java 1 Jan 2003 13:54:42 -0000 1.1.1.1 --- UUIDHexGenerator.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 6,10 **** import net.sf.hibernate.engine.SessionImplementor; ! /** * <b>uuid.hex</b><br> * <br> --- 6,10 ---- import net.sf.hibernate.engine.SessionImplementor; ! /** * <b>uuid.hex</b><br> * <br> *************** *** 13,17 **** * Optionally, the string may be generated with seperators * between each component of the UUID. ! * * @see UUIDStringGenerator */ --- 13,17 ---- * Optionally, the string may be generated with seperators * between each component of the UUID. ! * * @see UUIDStringGenerator */ *************** *** 20,34 **** private final String sep; ! public UUIDHexGenerator() { super(); sep = ""; } ! public UUIDHexGenerator(String sep) { super(); this.sep=sep; } ! protected String format(int intval) { String formatted = Integer.toHexString(intval); --- 20,34 ---- private final String sep; ! public UUIDHexGenerator() { super(); sep = ""; } ! public UUIDHexGenerator(String sep) { super(); this.sep=sep; } ! protected String format(int intval) { String formatted = Integer.toHexString(intval); *************** *** 37,41 **** return buf.toString(); } ! protected String format(short shortval) { String formatted = Integer.toHexString(shortval); --- 37,41 ---- return buf.toString(); } ! protected String format(short shortval) { String formatted = Integer.toHexString(shortval); *************** *** 44,58 **** return buf.toString(); } ! public Serializable generate(SessionImplementor cache, Object obj) { return new StringBuffer(36) ! .append( format( getIP() ) ).append(sep) ! .append( format( getJVM() ) ).append(sep) ! .append( format( getHiTime() ) ).append(sep) ! .append( format( getLoTime() ) ).append(sep) ! .append( format( getCount() ) ) ! .toString(); } ! public static void main( String[] args ) throws Exception { IdentifierGenerator gen = new UUIDHexGenerator("/"); --- 44,58 ---- return buf.toString(); } ! public Serializable generate(SessionImplementor cache, Object obj) { return new StringBuffer(36) ! .append( format( getIP() ) ).append(sep) ! .append( format( getJVM() ) ).append(sep) ! .append( format( getHiTime() ) ).append(sep) ! .append( format( getLoTime() ) ).append(sep) ! .append( format( getCount() ) ) ! .toString(); } ! public static void main( String[] args ) throws Exception { IdentifierGenerator gen = new UUIDHexGenerator("/"); *************** *** 65,69 **** } } - } --- 65,72 ---- } } + + + } + Index: UUIDStringGenerator.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/id/UUIDStringGenerator.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** UUIDStringGenerator.java 1 Jan 2003 13:54:44 -0000 1.1.1.1 --- UUIDStringGenerator.java 4 Jan 2003 11:15:28 -0000 1.2 *************** *** 7,21 **** import net.sf.hibernate.util.*; ! /** * <b>uuid.string</b><br> * <br> * A <tt>UUIDGenerator</tt> that returns a string of length 16, ! * This string will NOT consist of only alphanumeric * characters. Use this only if you don't mind unreadable * identifiers.<br> * <br> ! * This implementation is known to be incompatible with * Postgres. ! * * @see UUIDHexGenerator */ --- 7,21 ---- import net.sf.hibernate.util.*; ! /** * <b>uuid.string</b><br> * <br> * A <tt>UUIDGenerator</tt> that returns a string of length 16, ! * This string will NOT consist of only alphanumeric * characters. Use this only if you don't mind unreadable * identifiers.<br> * <br> ! * This implementation is known to be incompatible with * Postgres. ! * * @see UUIDHexGenerator */ *************** *** 24,48 **** private String sep; ! public UUIDStringGenerator() { super(); sep=""; } ! public UUIDStringGenerator(String sep) { super(); this.sep=sep; } ! public Serializable generate(SessionImplementor cache, Object obj) { return new StringBuffer(20) ! .append( toString( getIP() ) ).append(sep) ! .append( toString( getJVM() ) ).append(sep) ! .append( toString( getHiTime() ) ).append(sep) ! .append( toString( getLoTime() ) ).append(sep) ! .append( toString( getCount() ) ) ! .toString(); } ! public static void main( String[] args ) throws Exception { IdentifierGenerator gen = new UUIDStringGenerator();//("/"); --- 24,48 ---- private String sep; ! public UUIDStringGenerator() { super(); sep=""; } ! public UUIDStringGenerator(String sep) { super(); this.sep=sep; } ! public Serializable generate(SessionImplementor cache, Object obj) { return new StringBuffer(20) ! .append( toString( getIP() ) ).append(sep) ! .append( toString( getJVM() ) ).append(sep) ! .append( toString( getHiTime() ) ).append(sep) ! .append( toString( getLoTime() ) ).append(sep) ! .append( toString( getCount() ) ) ! .toString(); } ! public static void main( String[] args ) throws Exception { IdentifierGenerator gen = new UUIDStringGenerator();//("/"); *************** *** 56,63 **** return new String ( BytesHelper.toBytes(value) ); } ! private static String toString(short value) { return new String ( BytesHelper.toBytes(value) ); } ! } --- 56,66 ---- return new String ( BytesHelper.toBytes(value) ); } ! private static String toString(short value) { return new String ( BytesHelper.toBytes(value) ); } ! } + + + |