Package com.ibatis.sqlmap.client

Examples of com.ibatis.sqlmap.client.SqlMapClient


            doProcessResult(exchange, result);
        }
    }

    private void doUpdate(Exchange exchange) throws Exception {
        SqlMapClient client = endpoint.getSqlClient();

        Object result;
        Object in = exchange.getIn().getBody();
        if (in != null) {
            // lets handle arrays or collections of objects
            Iterator iter = ObjectHelper.createIterator(in);
            while (iter.hasNext()) {
                Object value = iter.next();
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Updating: " + value + " using statement: " + statement);
                }
                result = client.update(statement, value);
                doProcessResult(exchange, result);
            }
        } else {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Updating using statement: " + statement);
            }
            result = client.update(statement);
            doProcessResult(exchange, result);
        }
    }
View Full Code Here


            doProcessResult(exchange, result);
        }
    }

    private void doDelete(Exchange exchange) throws Exception {
        SqlMapClient client = endpoint.getSqlClient();

        Object result;
        Object in = exchange.getIn().getBody();
        if (in != null) {
            // lets handle arrays or collections of objects
            Iterator iter = ObjectHelper.createIterator(in);
            while (iter.hasNext()) {
                Object value = iter.next();
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Deleting: " + value + " using statement: " + statement);
                }
                result = client.delete(statement, value);
                doProcessResult(exchange, result);
            }
        } else {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Deleting using statement: " + statement);
            }
            result = client.delete(statement);
            doProcessResult(exchange, result);
        }
    }
View Full Code Here

    private String dropPrefix;
   
    public MetadataKey getMetadataKey( Metadata metadata )
        throws ArchivaDatabaseException
    {
        SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();

        try
        {
            sqlMap.startTransaction();

            getLogger().info( "Getting metadata key" );
            MetadataKey newMetadataKey = (MetadataKey) sqlMap.queryForObject( "getMetadataKey", metadata );
           
            if ( newMetadataKey == null )
            {
                getLogger().info( "added new metadata" );
                sqlMap.update( "addMetadataKey", metadata );
               
                newMetadataKey = (MetadataKey) sqlMap.queryForObject( "getMetadataKey", metadata );
               
                if ( newMetadataKey == null )
                {
                    throw new ArchivaDatabaseException( "unable to create new MetadataKeys" );
                }
            }
           
            return newMetadataKey;
           
        }
        catch ( SQLException e )
        {
            getLogger().error( "Error while adding metadata, showing all linked exceptions in SQLException." );

            while ( e != null )
            {
                getLogger().error( e.getMessage(), e );

                e = e.getNextException();
            }

            throw new ArchivaDatabaseException ( "Error while interacting with the database.", e );
        }
        finally
        {
            try
            {
                sqlMap.endTransaction();
            }
            catch ( SQLException e )
            {
                e.printStackTrace();
            }
View Full Code Here


    protected void initializeTable( String tableName )
        throws ArchivaDatabaseException   
    {
        SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();

        try
        {
            sqlMap.startTransaction();

            Connection con = sqlMap.getCurrentConnection();

            DatabaseMetaData databaseMetaData = con.getMetaData();

            ResultSet rs = databaseMetaData.getTables( con.getCatalog(), null, null, null );

            // check if the index database exists in the database
            while ( rs.next() )
            {
                String dbTableName = rs.getString( "TABLE_NAME" );

                // if it does then we are already initialized
                if ( dbTableName.toLowerCase().equals( tableName.toLowerCase() ) )
                {
                    return;
                }
            }
           
            // Create the tables
           
            getLogger().info( "Creating table: " + tableName );
            sqlMap.update( createPrefix + tableName, null );
           
            sqlMap.commitTransaction();
        }
        catch ( SQLException e )
        {
            getLogger().error( "Error while initializing database, showing all linked exceptions in SQLException." );

            while ( e != null )
            {
                getLogger().error( e.getMessage(), e );

                e = e.getNextException();
            }

            throw new ArchivaDatabaseException( "Error while setting up database.", e );
        }
        finally
        {
            try
            {
                sqlMap.endTransaction();
            }
            catch ( SQLException e )
            {
                e.printStackTrace();
            }
View Full Code Here

    }
   
    protected void dropTable( String tableName )
    throws ArchivaDatabaseException   
    {
    SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();

    try
    {
        sqlMap.startTransaction();

        getLogger().info( "Dropping table: " + tableName );
        sqlMap.update( dropPrefix + tableName, null );
       
        sqlMap.commitTransaction();
    }
    catch ( SQLException e )
    {
        getLogger().error( "Error while dropping database, showing all linked exceptions in SQLException." );

        while ( e != null )
        {
            getLogger().error( e.getMessage(), e );

            e = e.getNextException();
        }

        throw new ArchivaDatabaseException( "Error while dropping database.", e );
    }
    finally
    {
        try
        {
            sqlMap.endTransaction();
        }
        catch ( SQLException e )
        {
            e.printStackTrace();
        }
View Full Code Here

   
   
    protected boolean tableExists( String tableName )
    throws ArchivaDatabaseException   
{
    SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();

    try
    {
        sqlMap.startTransaction();

        Connection con = sqlMap.getCurrentConnection();

        DatabaseMetaData databaseMetaData = con.getMetaData();

        ResultSet rs = databaseMetaData.getTables( con.getCatalog(), null, null, null );

        // check if the index database exists in the database
        while ( rs.next() )
        {
            String dbTableName = rs.getString( "TABLE_NAME" );

            // if it does then we are already initialized
            if ( dbTableName.toLowerCase().equals( tableName.toLowerCase() ) )
            {
                return true;
            }
        }
        return false;
    }
    catch ( SQLException e )
    {
        getLogger().error( "Error while check database, showing all linked exceptions in SQLException." );

        while ( e != null )
        {
            getLogger().error( e.getMessage(), e );

            e = e.getNextException();
        }

        throw new ArchivaDatabaseException( "Error while checking database.", e );
    }
    finally
    {
        try
        {
            sqlMap.endTransaction();
        }
        catch ( SQLException e )
        {
            e.printStackTrace();
        }
View Full Code Here

{
    public void create( RepositoryMetadata metadata )
        throws ArchivaDatabaseException
    {
   
        SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();

        try
        {
            sqlMap.startTransaction();

            getLogger().info( "Adding repository metadata" );
            sqlMap.update( "addRepositoryMetadata", metadata );
           
            sqlMap.commitTransaction();
        }
        catch ( SQLException e )
        {
            getLogger().error( "Error while executing statement, showing all linked exceptions in SQLException." );

            while ( e != null )
            {
                getLogger().error( e.getMessage(), e );

                e = e.getNextException();
            }

            throw new ArchivaDatabaseException( "Error while executing statement.", e );
        }
        finally
        {
            try
            {
                sqlMap.endTransaction();
            }
            catch ( SQLException e )
            {
                e.printStackTrace();
            }
View Full Code Here

    public RepositoryMetadata read( String groupId, String artifactId, String version )
        throws ArchivaDatabaseException
    {
       
        SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();

        try
        {
            sqlMap.startTransaction();

            getLogger().info( "Reading repository metadata" );
            RepositoryMetadata repositoryMetadata = (RepositoryMetadata) sqlMap.queryForObject( "getRepositoryMetadata", new MetadataKey( groupId, artifactId, version ) );
           
            return repositoryMetadata;
        }
        catch ( SQLException e )
        {
            getLogger().error( "Error while executing statement, showing all linked exceptions in SQLException." );

            while ( e != null )
            {
                getLogger().error( e.getMessage(), e );

                e = e.getNextException();
            }

            throw new ArchivaDatabaseException( "Error while executing statement.", e );
        }
        finally
        {
            try
            {
                sqlMap.endTransaction();
            }
            catch ( SQLException e )
            {
                e.printStackTrace();
            }
View Full Code Here

     */
    public void update( RepositoryMetadata metadata )
        throws ArchivaDatabaseException
    {
       
        SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();

        try
        {
            sqlMap.startTransaction();

            getLogger().info( "Updating repository metadata" );
            sqlMap.update( "updateRepositoryMetadata", metadata );
           
            sqlMap.commitTransaction();
        }
        catch ( SQLException e )
        {
            getLogger().error( "Error while executing statement, showing all linked exceptions in SQLException." );

            while ( e != null )
            {
                getLogger().error( e.getMessage(), e );

                e = e.getNextException();
            }

            throw new ArchivaDatabaseException( "Error while executing statement.", e );
        }
        finally
        {
            try
            {
                sqlMap.endTransaction();
            }
            catch ( SQLException e )
            {
                e.printStackTrace();
            }
View Full Code Here

    }

    public void delete( String groupId, String artifactId, String version )
        throws ArchivaDatabaseException
    {
        SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();

        try
        {
            sqlMap.startTransaction();

            getLogger().info( "Removing repository metadata" );
            sqlMap.update( "removeRepositoryMetadata", new MetadataKey( groupId, artifactId, version ) );
           
            sqlMap.commitTransaction();
        }
        catch ( SQLException e )
        {
            getLogger().error( "Error while executing statement, showing all linked exceptions in SQLException." );

            while ( e != null )
            {
                getLogger().error( e.getMessage(), e );

                e = e.getNextException();
            }

            throw new ArchivaDatabaseException( "Error while executing statement.", e );
        }
        finally
        {
            try
            {
                sqlMap.endTransaction();
            }
            catch ( SQLException e )
            {
                e.printStackTrace();
            }
View Full Code Here

TOP

Related Classes of com.ibatis.sqlmap.client.SqlMapClient

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.