Skip to content

Commit

Permalink
[CALCITE-5841] Improve singleton implementation for `ChinookAvaticaSe…
Browse files Browse the repository at this point in the history
…rver` in calcite-plus

Close apache#3313
  • Loading branch information
chucheng92 authored and libenchao committed Jul 29, 2023
1 parent 11126c5 commit e3310c2
Showing 1 changed file with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,18 @@ public static class CalciteChinookMetaFactory implements Meta.Factory {
private static final CalciteConnectionProvider CONNECTION_PROVIDER =
new CalciteConnectionProvider();

private static JdbcMeta instance = null;
private static volatile JdbcMeta instance = null;

private static JdbcMeta getInstance() {
if (instance == null) {
try {
instance =
new JdbcMeta(CalciteConnectionProvider.DRIVER_URL,
CONNECTION_PROVIDER.provideConnectionInfo());
} catch (SQLException | IOException e) {
throw new RuntimeException(e);
synchronized (CalciteChinookMetaFactory.class) {
try {
instance =
new JdbcMeta(CalciteConnectionProvider.DRIVER_URL,
CONNECTION_PROVIDER.provideConnectionInfo());
} catch (SQLException | IOException e) {
throw new RuntimeException(e);
}
}
}
return instance;
Expand All @@ -86,16 +88,19 @@ private static JdbcMeta getInstance() {
* Factory for Chinook Calcite database wrapped in meta for Avatica.
*/
public static class RawChinookMetaFactory implements Meta.Factory {
private static JdbcMeta instance = null;
private static volatile JdbcMeta instance = null;

private static JdbcMeta getInstance() {
if (instance == null) {
try {
instance =
new JdbcMeta(ChinookHsqldb.URI,
ChinookHsqldb.USER, ChinookHsqldb.PASSWORD);
} catch (SQLException e) {
throw new RuntimeException(e);
synchronized (RawChinookMetaFactory.class) {
if (instance == null) {
try {
instance =
new JdbcMeta(ChinookHsqldb.URI, ChinookHsqldb.USER, ChinookHsqldb.PASSWORD);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
}
return instance;
Expand Down

0 comments on commit e3310c2

Please sign in to comment.