Class AbstractIdGenerator

    • Field Detail

      • adapter

        protected Adapter adapter
        The adapter that knows the correct sql syntax
      • databaseName

        protected String databaseName
        The internal name of the Database that this Generator is connected to.
    • Constructor Detail

      • AbstractIdGenerator

        public AbstractIdGenerator​(Adapter adapter,
                                   String databaseName)
        Creates an IdGenerator which will work with the specified database.
        Parameters:
        adapter - the adapter that knows the correct sql syntax.
        databaseName - The name of the databaseName to find the correct schema.
    • Method Detail

      • getIdAsInt

        public int getIdAsInt​(Connection connection,
                              Object keyInfo)
                       throws TorqueException
        Returns the last ID used by this connection.
        Specified by:
        getIdAsInt in interface IdGenerator
        Parameters:
        connection - The database connection to read the new id, not null.
        keyInfo - the name of the table for which the id is retrieved.
        Returns:
        An int with the new id.
        Throws:
        TorqueException - if a database error occurs.
      • getIdAsLong

        public long getIdAsLong​(Connection connection,
                                Object keyInfo)
                         throws TorqueException
        Returns the last ID used by this connection.
        Specified by:
        getIdAsLong in interface IdGenerator
        Parameters:
        connection - The database connection to read the new id, not null.
        keyInfo - the name of the table for which the id is retrieved.
        Returns:
        A long with the new id.
        Throws:
        TorqueException - if a database error occurs.
      • getIdAsBigDecimal

        public BigDecimal getIdAsBigDecimal​(Connection connection,
                                            Object keyInfo)
                                     throws TorqueException
        Returns the last ID used by this connection.
        Specified by:
        getIdAsBigDecimal in interface IdGenerator
        Parameters:
        connection - The database connection to read the new id, not null.
        keyInfo - the name of the table for which the id is retrieved.
        Returns:
        A BigDecimal with the new id.
        Throws:
        TorqueException - if a database error occurs.
      • getIdAsString

        public String getIdAsString​(Connection connection,
                                    Object keyInfo)
                             throws TorqueException
        Returns the last ID used by this connection.
        Specified by:
        getIdAsString in interface IdGenerator
        Parameters:
        connection - The database connection to read the new id, not null.
        keyInfo - the name of the table for which the id is retrieved.
        Returns:
        A String with the new id.
        Throws:
        TorqueException - if a database error occurs.
      • isPriorToInsert

        public abstract boolean isPriorToInsert()
        A flag to determine the timing of the id generation
        Specified by:
        isPriorToInsert in interface IdGenerator
        Returns:
        a boolean value
      • isPostInsert

        public abstract boolean isPostInsert()
        A flag to determine the timing of the id generation
        Specified by:
        isPostInsert in interface IdGenerator
        Returns:
        a boolean value
      • isConnectionRequired

        public abstract boolean isConnectionRequired()
        A flag to determine whether a Connection is required to generate an id.
        Specified by:
        isConnectionRequired in interface IdGenerator
        Returns:
        a boolean value
      • isGetGeneratedKeysSupported

        public abstract boolean isGetGeneratedKeysSupported()
        A flag to determine whether Statement#getGeneratedKeys() should be used.
        Specified by:
        isGetGeneratedKeysSupported in interface IdGenerator
        Returns:
        a boolean value
      • getId

        protected <T> T getId​(Connection connection,
                              Object keyInfo,
                              RecordMapper<T> mapper)
                       throws TorqueException
        Returns the last ID used by this connection.
        Type Parameters:
        T - the id object class
        Parameters:
        connection - A Connection.
        keyInfo - an Object that contains additional info.
        mapper - The RecordMapper that maps from a ResultSet to the appropriate java object.
        Returns:
        The generated id.
        Throws:
        TorqueException - if a database error occurs.
      • getIdSql

        public String getIdSql​(Object keyInfo)
                        throws TorqueException
        Returns the SQL to retrieve the next id.
        Parameters:
        keyInfo - an Object that contains additional info.
        Returns:
        the SQL to retrieve the next id.
        Throws:
        TorqueException - if a database error occurs.