Package com.ibatis.sqlmap.client

Examples of com.ibatis.sqlmap.client.SqlMapClient


    }

    public void create( Artifact artifact )
        throws ArchivaDatabaseException
    {
        SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();

        try
        {
            sqlMap.startTransaction();

            getLogger().info( "Adding artifact." );
            sqlMap.update( "addArtifact", artifact );

            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


    }

    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

    // System.exit (0);
  }// end of main

  public static void readIbatisXml() {
    String resource = "ibatis.config.xml";
    SqlMapClient client = null;

    try {
      if (client == null) {
        Reader reader = Resources.getResourceAsReader(resource);
        client = SqlMapClientBuilder.buildSqlMapClient(reader);
View Full Code Here

  protected SqlMapClient getSqlMapClient() throws Exception {
    String dataSourceId = config.getFeedConfigLocation();
    if (sqlMapClients.containsKey(dataSourceId)) {
      return sqlMapClients.get(dataSourceId);
    } else {
      SqlMapClient client = SqlMapClientBuilder.buildSqlMapClient(
          config.getAdapterConfiguration()
              .getAdapterConfigAsReader());
      sqlMapClients.put(dataSourceId, client);
      return client;
    }
View Full Code Here

    }
  }

  @SuppressWarnings("unchecked")
  public Feed getFeed() throws Exception {
    SqlMapClient client = getSqlMapClient();
    String queryId = config.getFeedId() + "-get-feed";
    List<Map<String, Object>> rows = client.queryForList(queryId);
    Feed feed = createFeed();
    ServerConfiguration serverConfig = config.getServerConfiguration();
    if (serverConfig.getFeedNamespacePrefix() != null && serverConfig.getFeedNamespacePrefix().length() > 0) {
      feed.declareNS(serverConfig.getFeedNamespace(), serverConfig.getFeedNamespacePrefix());
    }
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  public Entry getEntry(Object entryId) throws Exception {
    String queryId = config.getFeedId() + "-get-entry";
    SqlMapClient client = getSqlMapClient();
    Map<String, Object> row = (Map<String, Object>)
        client.queryForObject(queryId, entryId);
    if (row == null) {
      // didn't find the entry.
      return null;
    }
    return createEntryFromRow(null,row);
View Full Code Here

    }
    return createEntryFromRow(null,row);
  }

  public Entry createEntry(Entry entry) throws Exception {
    SqlMapClient client = getSqlMapClient();
    String queryId = config.getFeedId() + "-insert-entry";
    Object newEntryId = client.insert(queryId, collectColumns(entry));
    return getEntry(newEntryId);
  }
View Full Code Here

    Object newEntryId = client.insert(queryId, collectColumns(entry));
    return getEntry(newEntryId);
  }

  public Entry updateEntry(Object entryId, Entry entry) throws Exception {
    SqlMapClient client = getSqlMapClient();
    String queryId = config.getFeedId() + "-update-entry";
    return client.update(queryId, collectColumns(entry)) > 0
        ? getEntry(entryId) : null;
  }
View Full Code Here

        ? getEntry(entryId) : null;
  }

  public boolean deleteEntry(Object entryId) throws Exception {
    String queryId = config.getFeedId() + "-delete-entry";
    SqlMapClient client = getSqlMapClient();
    return client.delete(queryId, entryId) > 0;
  }
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.