Skip to content

Commit

Permalink
fix #379
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Sep 18, 2017
1 parent 88f95e8 commit 6db844d
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public final class MasterSlaveConnection extends AbstractConnectionAdapter {

private final MasterSlaveDataSource masterSlaveDataSource;

private SQLType cachedSQLType;

/**
* Get database connections via SQL type.
*
Expand All @@ -56,6 +58,7 @@ public final class MasterSlaveConnection extends AbstractConnectionAdapter {
* @throws SQLException SQL exception
*/
public Collection<Connection> getConnections(final SQLType sqlType) throws SQLException {
cachedSQLType = sqlType;
Map<String, DataSource> dataSources = SQLType.DDL == sqlType ? masterSlaveDataSource.getAllDataSources() : masterSlaveDataSource.getDataSource(sqlType).toMap();
Collection<Connection> result = new LinkedList<>();
for (Entry<String, DataSource> each : dataSources.entrySet()) {
Expand All @@ -74,7 +77,7 @@ public Collection<Connection> getConnections(final SQLType sqlType) throws SQLEx

@Override
public DatabaseMetaData getMetaData() throws SQLException {
return masterSlaveDataSource.getDataSource(SQLType.DML).getDataSource().getConnection().getMetaData();
return getConnections(null == cachedSQLType ? SQLType.DML : cachedSQLType).iterator().next().getMetaData();
}

@Override
Expand Down

0 comments on commit 6db844d

Please sign in to comment.