Package org.apache.avalon.excalibur.datasource.ids

Examples of org.apache.avalon.excalibur.datasource.ids.IdGenerator


    public void testMaxShortIds() throws Exception
    {
        getLogger().info( "testMaxShortIds" );

        IdGenerator idGenerator = (IdGenerator)m_idGeneratorSelector.select( "ids-testMaxShortIds" );
        try
        {
            int testCount = 100;
            long max = Short.MAX_VALUE;
            long initial = max - testCount;

            // Initialize the counter in the database.
            initializeNextLongId( "test", initial );

            for( int i = 0; i <= testCount; i++ )
            {
                short id = idGenerator.getNextShortId();
                assertEquals( "The returned id was not what was expected.", i + initial, id );
            }

            // Next one should throw an exception
            try
            {
                short id = idGenerator.getNextShortId();
                fail( "Should not have gotten an id: " + id );
            }
            catch( IdException e )
            {
                // Good.  Got the exception.
View Full Code Here


    public void testMaxIntegerIds() throws Exception
    {
        getLogger().info( "testMaxIntegerIds" );

        IdGenerator idGenerator = (IdGenerator)m_idGeneratorSelector.select( "ids-testMaxIntegerIds" );
        try
        {
            int testCount = 100;
            long max = Integer.MAX_VALUE;
            long initial = max - testCount;

            // Initialize the counter in the database.
            initializeNextLongId( "test", initial );

            for( int i = 0; i <= testCount; i++ )
            {
                int id = idGenerator.getNextIntegerId();
                assertEquals( "The returned id was not what was expected.", i + initial, id );
            }

            // Next one should throw an exception
            try
            {
                int id = idGenerator.getNextIntegerId();
                fail( "Should not have gotten an id: " + id );
            }
            catch( IdException e )
            {
                // Good.  Got the exception.
View Full Code Here

    public void testMaxLongIds() throws Exception
    {
        getLogger().info( "testMaxLongIds" );

        IdGenerator idGenerator = (IdGenerator)m_idGeneratorSelector.select( "ids-testMaxLongIds" );
        try
        {
            int testCount = 100;
            long max = Long.MAX_VALUE;
            long initial = max - testCount;

            // Initialize the counter in the database.
            initializeNextLongId( "test", initial );

            for( int i = 0; i <= testCount; i++ )
            {
                long id = idGenerator.getNextLongId();
                assertEquals( "The returned id was not what was expected.", i + initial, id );
            }

            // Next one should throw an exception
            try
            {
                long id = idGenerator.getNextLongId();
                fail( "Should not have gotten an id: " + id );
            }
            catch( IdException e )
            {
                // Good.  Got the exception.
View Full Code Here

    return getPersistentField(fieldName).getDBName();
  }

  public final IdGenerator getIdGenerator(String fieldName) throws PersistenceException
  {
    IdGenerator generator = null;
    PersistentField oneField = getPersistentField(fieldName);
    String hint = oneField.getAutoIncremented();

    if (hint.equals("identity"))
    {
View Full Code Here

    try
    {
      // ===================================================
      // Obtain unique cache id
      // ===================================================
      IdGenerator myIdGenerator = (IdGenerator) getService(IdGenerator.ROLE, svcConfig.getHint(IdGenerator.ROLE));

      try
      {
        myQueryId = myIdGenerator.getNextIntegerId();
      }
      catch (IdException ie)
      {
        throw new QueryException("Unable to get myQueryId. ");
      }
View Full Code Here

    return myFactory;
  }

  protected void setAutoIncrement(String fieldName) throws PersistenceException
  {
    IdGenerator myIdGenerator = myMetaData.getIdGenerator(fieldName);

    try
    {
      setField(fieldName, myIdGenerator.getNextIntegerId());
    }
    catch (IdException ie)
    {
      log.error("Unable to auto-increment field", ie);
      throw new PersistenceException("$keelFieldNoAutoInc|" + myMetaData.getDescription(fieldName), ie);
View Full Code Here

     *-------------------------------------------------------------*/
    public void testNonExistingTableName() throws Exception
    {
        getLogger().info( "testNonExistingTableName" );

        IdGenerator idGenerator =
            (IdGenerator)m_idGeneratorSelector.select( "ids-testNonExistingTableName" );
        try
        {
            try
            {
                idGenerator.getNextIntegerId();
                fail( "Should not have gotten an id" );
            }
            catch( IdException e )
            {
                // Got the expected error.
View Full Code Here

    public void testSimpleRequestIdsSize1() throws Exception
    {
        getLogger().info( "testSimpleRequestIdsSize1" );

        IdGenerator idGenerator =
            (IdGenerator)m_idGeneratorSelector.select( "ids-testSimpleRequestIdsSize1" );
        try
        {
            int testCount = 100;

            // Initialize the counter in the database.
            initializeNextLongId( "test", 1 );

            for( int i = 1; i <= testCount; i++ )
            {
                int id = idGenerator.getNextIntegerId();
                assertEquals( "The returned id was not what was expected.", i, id );
            }

            assertEquals( "The next_id column in the database did not have the expected value.",
                          testCount + 1, peekNextLongId( "test" ) );
View Full Code Here

    public void testSimpleRequestIdsSize10() throws Exception
    {
        getLogger().info( "testSimpleRequestIdsSize10" );

        IdGenerator idGenerator =
            (IdGenerator)m_idGeneratorSelector.select( "ids-testSimpleRequestIdsSize10" );
        try
        {
            int testCount = 100;

            // Initialize the counter in the database.
            initializeNextLongId( "test", 1 );

            for( int i = 1; i <= testCount; i++ )
            {
                int id = idGenerator.getNextIntegerId();
                assertEquals( "The returned id was not what was expected.", i, id );
            }

            assertEquals( "The next_id column in the database did not have the expected value.",
                          testCount + 1, peekNextLongId( "test" ) );
View Full Code Here

    public void testSimpleRequestIdsSize100() throws Exception
    {
        getLogger().info( "testSimpleRequestIdsSize100" );

        IdGenerator idGenerator =
            (IdGenerator)m_idGeneratorSelector.select( "ids-testSimpleRequestIdsSize100" );
        try
        {
            int testCount = 100;

            // Initialize the counter in the database.
            initializeNextLongId( "test", 1 );

            for( int i = 1; i <= testCount; i++ )
            {
                int id = idGenerator.getNextIntegerId();
                assertEquals( "The returned id was not what was expected.", i, id );
            }

            assertEquals( "The next_id column in the database did not have the expected value.",
                          testCount + 1, peekNextLongId( "test" ) );
View Full Code Here

TOP

Related Classes of org.apache.avalon.excalibur.datasource.ids.IdGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.