Skip to content

Commit 6391e82

Browse files
authored
Merge pull request #68 from timeplus-io/timeplus-support
Timeplus Support
2 parents cca1ebf + 4cb9411 commit 6391e82

File tree

13 files changed

+854
-0
lines changed

13 files changed

+854
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,5 @@ buildNumber.properties
137137
*_LOCAL_*.txt
138138
*_REMOTE_*.txt
139139

140+
.DS_Store
141+
*.cfg

flyway-database-timeplus/pom.xml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (C) Red Gate Software Ltd 2010-2024
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<project xmlns="http://maven.apache.org/POM/4.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<parent>
24+
<groupId>org.flywaydb</groupId>
25+
<artifactId>flyway-community-db-support</artifactId>
26+
<version>10.16.3</version>
27+
</parent>
28+
29+
<artifactId>flyway-database-timeplus</artifactId>
30+
<name>${project.artifactId}</name>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>${project.groupId}</groupId>
35+
<artifactId>flyway-core</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.projectlombok</groupId>
39+
<artifactId>lombok</artifactId>
40+
<scope>provided</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>com.timeplus</groupId>
44+
<artifactId>timeplus-native-jdbc</artifactId>
45+
<version>2.0.7</version>
46+
<optional>true</optional>
47+
</dependency>
48+
</dependencies>
49+
50+
<build>
51+
<resources>
52+
<resource>
53+
<directory>src/main/resources</directory>
54+
<filtering>true</filtering>
55+
</resource>
56+
</resources>
57+
<plugins>
58+
<plugin>
59+
<artifactId>maven-resources-plugin</artifactId>
60+
</plugin>
61+
<plugin>
62+
<artifactId>maven-jar-plugin</artifactId>
63+
</plugin>
64+
</plugins>
65+
</build>
66+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*-
2+
* ========================LICENSE_START=================================
3+
* flyway-database-timeplus
4+
* ========================================================================
5+
* Copyright (C) 2010 - 2024 Red Gate Software Ltd
6+
* ========================================================================
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =========================LICENSE_END==================================
19+
*/
20+
/*
21+
* Copyright (C) Red Gate Software Ltd 2010-2024
22+
*
23+
* Licensed under the Apache License, Version 2.0 (the "License");
24+
* you may not use this file except in compliance with the License.
25+
* You may obtain a copy of the License at
26+
*
27+
* http://www.apache.org/licenses/LICENSE-2.0
28+
*
29+
* Unless required by applicable law or agreed to in writing, software
30+
* distributed under the License is distributed on an "AS IS" BASIS,
31+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32+
* See the License for the specific language governing permissions and
33+
* limitations under the License.
34+
*/
35+
package org.flywaydb.community.database;
36+
37+
import org.flywaydb.core.api.FlywayException;
38+
import org.flywaydb.core.extensibility.PluginMetadata;
39+
import org.flywaydb.core.internal.util.FileUtils;
40+
41+
import java.io.IOException;
42+
import java.nio.charset.StandardCharsets;
43+
44+
public class TimeplusDatabaseExtension implements PluginMetadata {
45+
public String getDescription() {
46+
return "Community-contributed Timeplus database support extension " + readVersion();
47+
}
48+
49+
public static String readVersion() {
50+
try {
51+
return FileUtils.copyToString(
52+
TimeplusDatabaseExtension.class.getClassLoader().getResourceAsStream("org/flywaydb/community/database/timeplus/version.txt"),
53+
StandardCharsets.UTF_8);
54+
} catch (IOException e) {
55+
throw new FlywayException("Unable to read extension version: " + e.getMessage(), e);
56+
}
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*-
2+
* ========================LICENSE_START=================================
3+
* flyway-database-timeplus
4+
* ========================================================================
5+
* Copyright (C) 2010 - 2024 Red Gate Software Ltd
6+
* ========================================================================
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =========================LICENSE_END==================================
19+
*/
20+
/*
21+
* Copyright (C) Red Gate Software Ltd 2010-2024
22+
*
23+
* Licensed under the Apache License, Version 2.0 (the "License");
24+
* you may not use this file except in compliance with the License.
25+
* You may obtain a copy of the License at
26+
*
27+
* http://www.apache.org/licenses/LICENSE-2.0
28+
*
29+
* Unless required by applicable law or agreed to in writing, software
30+
* distributed under the License is distributed on an "AS IS" BASIS,
31+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32+
* See the License for the specific language governing permissions and
33+
* limitations under the License.
34+
*/
35+
package org.flywaydb.community.database.timeplus;
36+
37+
import lombok.Getter;
38+
import org.flywaydb.core.extensibility.ConfigurationExtension;
39+
40+
import java.util.Map;
41+
42+
@Getter
43+
public class TimeplusConfigurationExtension implements ConfigurationExtension {
44+
private static final String CLUSTER_NAME = "flyway.timeplus.clusterName";
45+
private static final String ZOOKEEPER_PATH = "flyway.timeplus.zookeeperPath";
46+
47+
private static final String ZOOKEEPER_PATH_DEFAULT_VALUE = "/timeplus/tables/{shard}/{database}/{table}";
48+
49+
private String clusterName;
50+
private String zookeeperPath = ZOOKEEPER_PATH_DEFAULT_VALUE;
51+
52+
@Override
53+
public String getNamespace() {
54+
return "timeplus";
55+
}
56+
57+
@Override
58+
public void extractParametersFromConfiguration(Map<String, String> configuration) {
59+
String clusterName = configuration.remove(CLUSTER_NAME);
60+
if (clusterName != null) {
61+
this.clusterName = clusterName;
62+
}
63+
64+
String zookeeperPath = configuration.remove(ZOOKEEPER_PATH);
65+
if (zookeeperPath != null) {
66+
this.zookeeperPath = zookeeperPath;
67+
}
68+
}
69+
70+
@Override
71+
public String getConfigurationParameterFromEnvironmentVariable(String environmentVariable) {
72+
if ("FLYWAY_TIMEPLUS_CLUSTER_NAME".equals(environmentVariable)) {
73+
return CLUSTER_NAME;
74+
}
75+
if ("FLYWAY_TIMEPLUS_ZOOKEEPER_PATH".equals(environmentVariable)) {
76+
return ZOOKEEPER_PATH;
77+
}
78+
return null;
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*-
2+
* ========================LICENSE_START=================================
3+
* flyway-database-timeplus
4+
* ========================================================================
5+
* Copyright (C) 2010 - 2024 Red Gate Software Ltd
6+
* ========================================================================
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =========================LICENSE_END==================================
19+
*/
20+
/*
21+
* Copyright (C) Red Gate Software Ltd 2010-2024
22+
*
23+
* Licensed under the Apache License, Version 2.0 (the "License");
24+
* you may not use this file except in compliance with the License.
25+
* You may obtain a copy of the License at
26+
*
27+
* http://www.apache.org/licenses/LICENSE-2.0
28+
*
29+
* Unless required by applicable law or agreed to in writing, software
30+
* distributed under the License is distributed on an "AS IS" BASIS,
31+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32+
* See the License for the specific language governing permissions and
33+
* limitations under the License.
34+
*/
35+
package org.flywaydb.community.database.timeplus;
36+
37+
import org.flywaydb.core.internal.database.base.Connection;
38+
39+
import java.sql.SQLException;
40+
import java.util.Optional;
41+
42+
public class TimeplusConnection extends Connection<TimeplusDatabase> {
43+
private static final String DEFAULT_CATALOG_TERM = "database";
44+
45+
TimeplusConnection(TimeplusDatabase database, java.sql.Connection connection) {
46+
super(database, connection);
47+
}
48+
49+
@Override
50+
protected String getCurrentSchemaNameOrSearchPath() throws SQLException {
51+
var jdbcConnection = getJdbcTemplate().getConnection();
52+
var currentSchema = useCatalog(jdbcConnection) ?
53+
jdbcConnection.getCatalog() : jdbcConnection.getSchema();
54+
55+
return Optional.ofNullable(currentSchema).map(database::unQuote).orElse(null);
56+
}
57+
58+
@Override
59+
public void doChangeCurrentSchemaOrSearchPathTo(String schema) throws SQLException {
60+
// databaseTerm is catalog since driver version 0.5.0
61+
// https://github.com/Timeplus/timeplus-java/issues/1273 & https://github.com/dbeaver/dbeaver/issues/19383
62+
// For compatibility with old libraries, ((TimeplusConnection) getJdbcConnection()).useCatalog() should be checked
63+
var jdbcConnection = getJdbcTemplate().getConnection();
64+
65+
if (useCatalog(jdbcConnection)) {
66+
jdbcConnection.setCatalog(schema);
67+
} else {
68+
jdbcConnection.setSchema(schema);
69+
}
70+
}
71+
72+
protected boolean useCatalog(java.sql.Connection jdbcConnection) throws SQLException {
73+
return DEFAULT_CATALOG_TERM.equals(jdbcConnection.getMetaData().getCatalogTerm());
74+
}
75+
76+
@Override
77+
public TimeplusSchema getSchema(String name) {
78+
return new TimeplusSchema(jdbcTemplate, database, name);
79+
}
80+
}

0 commit comments

Comments
 (0)