You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by li...@apache.org on 2023/07/13 11:25:46 UTC
[calcite] branch main updated: [CALCITE-5841] Improve singleton implementation for `ChinookAvaticaServer` in calcite-plus
This is an automated email from the ASF dual-hosted git repository.
libenchao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new 91ca42fbcc [CALCITE-5841] Improve singleton implementation for `ChinookAvaticaServer` in calcite-plus
91ca42fbcc is described below
commit 91ca42fbccafe044fb122427848a62e4c30a3eea
Author: Ran Tao <ch...@gmail.com>
AuthorDate: Thu Jul 13 00:01:13 2023 +0800
[CALCITE-5841] Improve singleton implementation for `ChinookAvaticaServer` in calcite-plus
Close apache/calcite#3313
---
.../calcite/chinook/ChinookAvaticaServer.java | 33 +++++++++++++---------
1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/plus/src/main/java/org/apache/calcite/chinook/ChinookAvaticaServer.java b/plus/src/main/java/org/apache/calcite/chinook/ChinookAvaticaServer.java
index 306008a2e4..4bcb00540d 100644
--- a/plus/src/main/java/org/apache/calcite/chinook/ChinookAvaticaServer.java
+++ b/plus/src/main/java/org/apache/calcite/chinook/ChinookAvaticaServer.java
@@ -62,16 +62,18 @@ public class ChinookAvaticaServer {
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;
@@ -86,16 +88,19 @@ public class ChinookAvaticaServer {
* 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;