Search in sources :

Example 1 with DataSourceRepository

use of com.wplatform.ddal.shards.DataSourceRepository in project jdbc-shards by wplatform.

the class JdbcWorker method getDataSource.

protected DataSource getDataSource() {
    DataSourceRepository dataSourceRepository = session.getDataSourceRepository();
    DataSource dataSource = dataSourceRepository.getDataSourceByShardName(shardName);
    return dataSource;
}
Also used : DataSourceRepository(com.wplatform.ddal.shards.DataSourceRepository) DataSource(javax.sql.DataSource)

Example 2 with DataSourceRepository

use of com.wplatform.ddal.shards.DataSourceRepository in project jdbc-shards by wplatform.

the class TableMate method readMataData.

/**
     * @param session
     */
public void readMataData(Session session, TableNode matadataNode) {
    for (int retry = 0; ; retry++) {
        try {
            Connection conn = null;
            String tableName = matadataNode.getCompositeObjectName();
            String shardName = matadataNode.getShardName();
            try {
                DataSourceRepository dsRepository = session.getDataSourceRepository();
                DataSource dataSource = dsRepository.getDataSourceByShardName(shardName);
                Optional optional = Optional.build().shardName(shardName).readOnly(false);
                conn = session.applyConnection(dataSource, optional);
                tableName = database.identifier(tableName);
                tryReadMetaData(conn, tableName);
                return;
            } catch (Exception e) {
                throw DbException.convert(e);
            } finally {
                JdbcUtils.closeSilently(conn);
            }
        } catch (DbException e) {
            if (retry >= MAX_RETRY) {
                throw e;
            }
        }
    }
}
Also used : DataSourceRepository(com.wplatform.ddal.shards.DataSourceRepository) Optional(com.wplatform.ddal.excutor.Optional) Connection(java.sql.Connection) SQLException(java.sql.SQLException) DbException(com.wplatform.ddal.message.DbException) DataSource(javax.sql.DataSource) DbException(com.wplatform.ddal.message.DbException)

Aggregations

DataSourceRepository (com.wplatform.ddal.shards.DataSourceRepository)2 DataSource (javax.sql.DataSource)2 Optional (com.wplatform.ddal.excutor.Optional)1 DbException (com.wplatform.ddal.message.DbException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1