/** @param session */ public void readMataData(Session session, ObjectNode matadataNode) { for (int retry = 0; ; retry++) { try { Connection conn = null; String shardName = matadataNode.getShardName(); String tableName = matadataNode.getQualifiedObjectName(); String catalog = matadataNode.getCatalog(); String schema = matadataNode.getSchema(); try { JdbcRepository dsRepository = (JdbcRepository) database.getRepository(); DataSource dataSource = dsRepository.getDataSourceByShardName(shardName); conn = dataSource.getConnection(); tableName = database.identifier(tableName); if (catalog != null) { catalog = database.identifier(catalog); } if (schema != null) { schema = database.identifier(schema); } tryReadMetaData(conn, catalog, schema, tableName); return; } catch (Exception e) { throw DbException.convert(e); } finally { JdbcUtils.closeSilently(conn); } } catch (DbException e) { if (retry >= MAX_RETRY) { throw e; } } } }
public ConnectionHolder(Session session) { Database database = session.getDatabase(); JdbcRepository repository = (JdbcRepository) database.getRepository(); this.session = session; this.trace = database.getTrace(Trace.TRANSACTION); this.target = repository.getConnectionProvider(); String mode = database.getSettings().transactionMode; this.holderStrategy = transactionMode(mode); }
protected Connection applyConnection(boolean readOnly, String username, String password) throws SQLException { List<DataSourceMarker> tryList = New.arrayList(); DataSourceMarker selected = dataSource.doRoute(readOnly); while (selected != null) { try { tryList.add(selected); return (username != null) ? database.haGet(selected, username, password) : database.haGet(selected); } catch (SQLException e) { selected = dataSource.doRoute(readOnly, tryList); } } throw new SQLException("No avaliable datasource in shard " + dataSource); }
/** * @param database * @param dataSource * @param connection * @param trace * @throws SQLException */ protected SmartSupport(JdbcRepository database, SmartDataSource dataSource) { this.database = database; this.dataSource = dataSource; this.trace = database.getTrace(); }