|
6 | 6 | import java.util.Properties;
|
7 | 7 | import java.util.function.Supplier;
|
8 | 8 |
|
| 9 | +import org.apache.calcite.avatica.ConnectStringParser; |
9 | 10 | import org.apache.calcite.avatica.DriverVersion;
|
10 | 11 | import org.apache.calcite.jdbc.CalciteConnection;
|
11 | 12 | import org.apache.calcite.jdbc.CalcitePrepare;
|
@@ -69,28 +70,32 @@ public Connection connect(String url, Properties props) throws SQLException {
|
69 | 70 | CalciteConnection calciteConnection = (CalciteConnection) connection;
|
70 | 71 | SchemaPlus rootSchema = calciteConnection.getRootSchema();
|
71 | 72 |
|
72 |
| - String remaining = url.substring(getConnectStringPrefix().length()).trim(); |
73 |
| - String[] catalogs = remaining.split(","); |
74 |
| - |
75 | 73 | // built-in schemas
|
76 | 74 | rootSchema.add("DEFAULT", new AbstractSchema());
|
77 | 75 |
|
78 | 76 | calciteConnection.setSchema("DEFAULT");
|
79 | 77 |
|
80 | 78 | WrappedSchemaPlus wrappedRootSchema = new WrappedSchemaPlus(rootSchema);
|
| 79 | + |
| 80 | + // Load properties from url and from getConnection() |
| 81 | + Properties properties = new Properties(); |
| 82 | + properties.putAll(props); // via getConnection() |
| 83 | + properties.putAll(ConnectStringParser.parse(url.substring(getConnectStringPrefix().length()))); |
| 84 | + String[] catalogs = properties.getProperty("catalogs", "").split(","); |
| 85 | + |
81 | 86 | if (catalogs.length == 0 || catalogs[0].length() == 0) {
|
82 | 87 | // load all catalogs (typical usage)
|
83 | 88 | for (Catalog catalog : CatalogService.catalogs()) {
|
84 |
| - catalog.register(wrappedRootSchema, props); |
| 89 | + catalog.register(wrappedRootSchema, properties); |
85 | 90 | }
|
86 | 91 | } else {
|
87 |
| - // load specific catalogs when loaded as `jdbc:hoptimator://foo,bar` |
| 92 | + // load specific catalogs when loaded as `jdbc:hoptimator://catalogs=foo,bar` |
88 | 93 | for (String catalog : catalogs) {
|
89 | 94 | CatalogService.catalog(catalog).register(wrappedRootSchema, props);
|
90 | 95 | }
|
91 | 96 | }
|
92 | 97 |
|
93 |
| - return new HoptimatorConnection(calciteConnection, props); |
| 98 | + return new HoptimatorConnection(calciteConnection, properties); |
94 | 99 | } catch (Exception e) {
|
95 | 100 | throw new SQLException("Problem loading " + url, e);
|
96 | 101 | }
|
|
0 commit comments