Skip to content

Commit 4807c2c

Browse files
Merge pull request #81 from GwangCheonLee/main
cubrid support
2 parents 67f57b2 + 088ba15 commit 4807c2c

File tree

12 files changed

+493
-0
lines changed

12 files changed

+493
-0
lines changed

flyway-database-cubrid/pom.xml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.18.0</version>
27+
</parent>
28+
29+
<artifactId>flyway-database-cubrid</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+
</dependencies>
43+
44+
<build>
45+
<resources>
46+
<resource>
47+
<directory>src/main/resources</directory>
48+
<filtering>true</filtering>
49+
</resource>
50+
</resources>
51+
<plugins>
52+
<plugin>
53+
<artifactId>maven-resources-plugin</artifactId>
54+
</plugin>
55+
<plugin>
56+
<artifactId>maven-jar-plugin</artifactId>
57+
</plugin>
58+
</plugins>
59+
</build>
60+
</project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.flywaydb.community.database;
17+
18+
import java.io.IOException;
19+
import java.nio.charset.StandardCharsets;
20+
import java.util.Objects;
21+
import org.flywaydb.core.api.FlywayException;
22+
import org.flywaydb.core.extensibility.PluginMetadata;
23+
import org.flywaydb.core.internal.util.FileUtils;
24+
25+
public class CubridDatabaseExtension implements PluginMetadata {
26+
27+
public static String readVersion() {
28+
try {
29+
return FileUtils.copyToString(
30+
Objects.requireNonNull(
31+
CubridDatabaseExtension.class.getClassLoader().getResourceAsStream(
32+
"org/flywaydb/community/database/cubrid/version.txt")),
33+
StandardCharsets.UTF_8);
34+
} catch (IOException e) {
35+
throw new FlywayException("Unable to read extension version: " + e.getMessage(), e);
36+
}
37+
}
38+
39+
@Override
40+
public String getDescription() {
41+
return "Community-contributed CUBRID database support extension " + readVersion()
42+
+ " by Redgate";
43+
}
44+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.flywaydb.community.database.cubrid;
17+
18+
import org.flywaydb.core.internal.database.base.Connection;
19+
20+
public class CubridConnection extends Connection<CubridDatabase> {
21+
22+
public CubridConnection(CubridDatabase database, java.sql.Connection connection) {
23+
super(database, connection);
24+
}
25+
26+
@Override
27+
protected String getCurrentSchemaNameOrSearchPath() {
28+
// schema isn't supported
29+
return null;
30+
}
31+
32+
@Override
33+
public CubridSchema getSchema(String name) {
34+
return new CubridSchema(jdbcTemplate, database, name);
35+
}
36+
37+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.flywaydb.community.database.cubrid;
17+
18+
import java.sql.Connection;
19+
import lombok.CustomLog;
20+
import org.flywaydb.core.api.configuration.Configuration;
21+
import org.flywaydb.core.internal.database.base.Database;
22+
import org.flywaydb.core.internal.database.base.Table;
23+
import org.flywaydb.core.internal.jdbc.JdbcConnectionFactory;
24+
import org.flywaydb.core.internal.jdbc.StatementInterceptor;
25+
26+
@CustomLog
27+
public class CubridDatabase extends Database<CubridConnection> {
28+
29+
public CubridDatabase(Configuration configuration,
30+
JdbcConnectionFactory jdbcConnectionFactory,
31+
StatementInterceptor statementInterceptor) {
32+
super(configuration, jdbcConnectionFactory, statementInterceptor);
33+
}
34+
35+
@Override
36+
protected CubridConnection doGetConnection(Connection connection) {
37+
return new CubridConnection(this, connection);
38+
}
39+
40+
@Override
41+
public void ensureSupported(Configuration configuration) {
42+
}
43+
44+
@Override
45+
public boolean supportsDdlTransactions() {
46+
return false;
47+
}
48+
49+
@Override
50+
public String getBooleanTrue() {
51+
return "1";
52+
}
53+
54+
@Override
55+
public String getBooleanFalse() {
56+
return "0";
57+
}
58+
59+
@Override
60+
public boolean catalogIsSchema() {
61+
return false;
62+
}
63+
64+
@Override
65+
public String getRawCreateScript(Table table, boolean baseline) {
66+
return "CREATE TABLE IF NOT EXISTS " + table + " (\n" +
67+
" \"installed_rank\" INT NOT NULL PRIMARY KEY,\n" +
68+
" \"version\" VARCHAR(50),\n" +
69+
" \"description\" VARCHAR(200) NOT NULL,\n" +
70+
" \"type\" VARCHAR(20) NOT NULL,\n" +
71+
" \"script\" VARCHAR(1000) NOT NULL,\n" +
72+
" \"checksum\" INT,\n" +
73+
" \"installed_by\" VARCHAR(100) NOT NULL,\n" +
74+
" \"installed_on\" TIMESTAMP NOT NULL DEFAULT NOW(),\n" +
75+
" \"execution_time\" INT NOT NULL,\n" +
76+
" \"success\" INT NOT NULL\n" +
77+
");\n"
78+
+ (baseline ? getBaselineStatement(table) + ";\n" : "")
79+
+ "CREATE INDEX " + table.getName() + "_s_idx ON " + table + " (\"success\");";
80+
}
81+
82+
@Override
83+
public boolean useSingleConnection() {
84+
return false;
85+
}
86+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.flywaydb.community.database.cubrid;
17+
18+
import java.sql.Connection;
19+
import java.sql.Types;
20+
import org.flywaydb.community.database.CubridDatabaseExtension;
21+
import org.flywaydb.core.api.ResourceProvider;
22+
import org.flywaydb.core.api.configuration.Configuration;
23+
import org.flywaydb.core.internal.database.base.BaseDatabaseType;
24+
import org.flywaydb.core.internal.database.base.CommunityDatabaseType;
25+
import org.flywaydb.core.internal.database.base.Database;
26+
import org.flywaydb.core.internal.jdbc.JdbcConnectionFactory;
27+
import org.flywaydb.core.internal.jdbc.StatementInterceptor;
28+
import org.flywaydb.core.internal.parser.Parser;
29+
import org.flywaydb.core.internal.parser.ParsingContext;
30+
31+
public class CubridDatabaseType extends BaseDatabaseType implements CommunityDatabaseType {
32+
33+
@Override
34+
public String getName() {
35+
return "CUBRID";
36+
}
37+
38+
@Override
39+
public int getNullType() {
40+
return Types.NULL;
41+
}
42+
43+
@Override
44+
public boolean handlesJDBCUrl(String url) {
45+
return url.startsWith("jdbc:cubrid:");
46+
}
47+
48+
@Override
49+
public String getDriverClass(String url, ClassLoader classLoader) {
50+
return "cubrid.jdbc.driver.CUBRIDDriver";
51+
}
52+
53+
@Override
54+
public boolean handlesDatabaseProductNameAndVersion(String databaseProductName,
55+
String databaseProductVersion,
56+
Connection connection) {
57+
return databaseProductName != null && databaseProductName.trim().toLowerCase()
58+
.contains("cubrid");
59+
}
60+
61+
62+
@Override
63+
public Database<CubridConnection> createDatabase(Configuration configuration,
64+
JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) {
65+
return new CubridDatabase(configuration, jdbcConnectionFactory, statementInterceptor);
66+
}
67+
68+
@Override
69+
public Parser createParser(Configuration configuration, ResourceProvider resourceProvider,
70+
ParsingContext parsingContext) {
71+
return new CubridParser(configuration, parsingContext);
72+
}
73+
74+
@Override
75+
public String getPluginVersion(Configuration config) {
76+
return CubridDatabaseExtension.readVersion();
77+
}
78+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2010 - 2025 Red Gate Software Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.flywaydb.community.database.cubrid;
17+
18+
import org.flywaydb.core.api.configuration.Configuration;
19+
import org.flywaydb.core.internal.parser.Parser;
20+
import org.flywaydb.core.internal.parser.ParsingContext;
21+
22+
public class CubridParser extends Parser {
23+
24+
protected CubridParser(Configuration configuration, ParsingContext parsingContext) {
25+
super(configuration, parsingContext, 2);
26+
}
27+
}

0 commit comments

Comments
 (0)