forked from flyway/flyway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from luissemantic/kinetica_support
Kinetica support
- Loading branch information
Showing
9 changed files
with
476 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...db-support/src/main/java/org/flywaydb/community/database/kinetica/KineticaConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (C) Red Gate Software Ltd 2010-2022 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.flywaydb.community.database.kinetica; | ||
|
||
import org.flywaydb.community.database.ignite.thin.IgniteThinDatabase; | ||
import org.flywaydb.community.database.ignite.thin.IgniteThinSchema; | ||
import org.flywaydb.core.internal.database.base.Connection; | ||
import org.flywaydb.core.internal.database.base.Schema; | ||
|
||
import java.sql.SQLException; | ||
|
||
public class KineticaConnection extends Connection<KineticaDatabase> { | ||
|
||
KineticaConnection(KineticaDatabase database, java.sql.Connection connection) { | ||
super(database, connection); | ||
} | ||
|
||
@Override | ||
public void doRestoreOriginalState() throws SQLException {} | ||
|
||
@Override | ||
public void doChangeCurrentSchemaOrSearchPathTo(String schema) throws SQLException { | ||
getJdbcConnection().setSchema(schema); | ||
} | ||
|
||
@Override | ||
public Schema getSchema(String name) { | ||
return new KineticaSchema(jdbcTemplate, database, name); | ||
} | ||
|
||
@Override | ||
protected String getCurrentSchemaNameOrSearchPath() throws SQLException { | ||
return getJdbcConnection().getSchema(); | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
...y-db-support/src/main/java/org/flywaydb/community/database/kinetica/KineticaDatabase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright (C) Red Gate Software Ltd 2010-2022 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.flywaydb.community.database.kinetica; | ||
|
||
import org.flywaydb.core.api.configuration.Configuration; | ||
import org.flywaydb.core.internal.database.base.Database; | ||
import org.flywaydb.core.internal.database.base.Table; | ||
import org.flywaydb.core.internal.jdbc.JdbcConnectionFactory; | ||
import org.flywaydb.core.internal.jdbc.StatementInterceptor; | ||
|
||
import java.sql.Connection; | ||
|
||
|
||
public class KineticaDatabase extends Database { | ||
|
||
public KineticaDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) { | ||
super(configuration, jdbcConnectionFactory, statementInterceptor); | ||
} | ||
|
||
@Override | ||
protected KineticaConnection doGetConnection(Connection connection) { | ||
return new KineticaConnection(this, connection); | ||
} | ||
|
||
@Override | ||
public final void ensureSupported() { | ||
notifyDatabaseIsNotFormallySupported(); | ||
} | ||
|
||
@Override | ||
public String getRawCreateScript(Table table, boolean baseline) { | ||
return "CREATE REPLICATED TABLE " + table + " (\n" + | ||
" \"installed_rank\" INT NOT NULL,\n" + | ||
" \"version\" VARCHAR(50),\n" + | ||
" \"description\" VARCHAR(200) NOT NULL,\n" + | ||
" \"type\" VARCHAR(20) NOT NULL,\n" + | ||
" \"script\" VARCHAR(1000) NOT NULL,\n" + | ||
" \"checksum\" INT,\n" + | ||
" \"installed_by\" VARCHAR(100) NOT NULL,\n" + | ||
" \"installed_on\" TIMESTAMP NOT NULL,\n" + | ||
" \"execution_time\" INT NOT NULL,\n" + | ||
" \"success\" tinyint NOT NULL,\n" + | ||
" PRIMARY KEY (\"installed_rank\")\n" + | ||
") ;\n" + | ||
(baseline ? getBaselineStatement(table) + ";\n" : "") + | ||
"ALTER TABLE ADD INDEX public." + table + " (\"success\");"; | ||
} | ||
|
||
@Override | ||
public String getSelectStatement(Table table) { | ||
return "SELECT " + quote("installed_rank") | ||
+ "," + quote("version") | ||
+ "," + quote("description") | ||
+ "," + quote("type") | ||
+ "," + quote("script") | ||
+ "," + quote("checksum") | ||
+ "," + quote("installed_on") | ||
+ "," + quote("installed_by") | ||
+ "," + quote("execution_time") | ||
+ "," + quote("success") | ||
+ " FROM " + table | ||
// Ignore special table created marker | ||
+ " WHERE " + quote("type") + " != 'TABLE'" | ||
+ " AND " + quote("installed_rank") + " > ?" | ||
+ " ORDER BY " + quote("installed_rank"); | ||
} | ||
|
||
@Override | ||
public String getInsertStatement(Table table) { | ||
java.util.Date t = new java.util.Date (); | ||
|
||
return "INSERT INTO " + table | ||
+ " (" + quote("installed_rank") | ||
+ ", " + quote("version") | ||
+ ", " + quote("description") | ||
+ ", " + quote("type") | ||
+ ", " + quote("script") | ||
+ ", " + quote("checksum") | ||
+ ", " + quote("installed_by") | ||
+ ", " + quote("installed_on") | ||
+ ", " + quote("execution_time") | ||
+ ", " + quote("success") | ||
+ ")" | ||
+ " VALUES (?, ?, ?, ?, ?, ?, ?," +t.getTime()+", ?,?)"; | ||
} | ||
|
||
@Override | ||
public boolean supportsDdlTransactions() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean supportsChangingCurrentSchema() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getBooleanTrue() { | ||
return "1"; | ||
} | ||
|
||
@Override | ||
public String getBooleanFalse() { | ||
return "0"; | ||
} | ||
|
||
@Override | ||
public boolean catalogIsSchema() { | ||
return false; | ||
} | ||
|
||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...-support/src/main/java/org/flywaydb/community/database/kinetica/KineticaDatabaseType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (C) Red Gate Software Ltd 2010-2022 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.flywaydb.community.database.kinetica; | ||
|
||
import org.flywaydb.core.api.ResourceProvider; | ||
import org.flywaydb.core.api.configuration.Configuration; | ||
import org.flywaydb.core.internal.database.base.BaseDatabaseType; | ||
import org.flywaydb.core.internal.jdbc.ExecutionTemplate; | ||
import org.flywaydb.core.internal.jdbc.JdbcConnectionFactory; | ||
import org.flywaydb.core.internal.jdbc.StatementInterceptor; | ||
import org.flywaydb.core.internal.jdbc.TransactionalExecutionTemplate; | ||
import org.flywaydb.core.internal.parser.Parser; | ||
import org.flywaydb.core.internal.parser.ParsingContext; | ||
import java.sql.Connection; | ||
import java.sql.Types; | ||
|
||
|
||
public class KineticaDatabaseType extends BaseDatabaseType { | ||
|
||
@Override | ||
public String getName() { | ||
return "kinetica"; | ||
} | ||
|
||
@Override | ||
public int getNullType() { | ||
return Types.VARCHAR; | ||
} | ||
|
||
@Override | ||
public boolean handlesJDBCUrl(String url) { | ||
return url.startsWith("jdbc:kinetica:"); | ||
} | ||
|
||
@Override | ||
public KineticaDatabase createDatabase(Configuration configuration, boolean printInfo, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) { | ||
return createDatabase(configuration, jdbcConnectionFactory, statementInterceptor); | ||
} | ||
|
||
@Override | ||
public KineticaDatabase createDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) { | ||
return new KineticaDatabase(configuration,jdbcConnectionFactory,statementInterceptor); | ||
} | ||
|
||
@Override | ||
public String getDriverClass(String url, ClassLoader classLoader) { | ||
return "com.kinetica.jdbc.Driver"; | ||
} | ||
|
||
@Override | ||
public boolean handlesDatabaseProductNameAndVersion(String databaseProductName, String databaseProductVersion, Connection connection) { | ||
return databaseProductName.startsWith("Kinetica"); | ||
} | ||
|
||
@Override | ||
public Parser createParser(Configuration configuration, ResourceProvider resourceProvider, ParsingContext parsingContext) { | ||
return new KineticaParser(configuration, parsingContext); | ||
} | ||
|
||
@Override | ||
public ExecutionTemplate createTransactionalExecutionTemplate(Connection connection, boolean rollbackOnException) { | ||
final KineticaExecutionTemplate kineticaExecutionTemplate = new KineticaExecutionTemplate(); | ||
return kineticaExecutionTemplate; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...ort/src/main/java/org/flywaydb/community/database/kinetica/KineticaExecutionTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (C) Red Gate Software Ltd 2010-2022 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.flywaydb.community.database.kinetica; | ||
|
||
import org.flywaydb.core.api.FlywayException; | ||
import org.flywaydb.core.internal.exception.FlywaySqlException; | ||
import org.flywaydb.core.internal.jdbc.ExecutionTemplate; | ||
import java.sql.SQLException; | ||
import java.util.concurrent.Callable; | ||
|
||
public class KineticaExecutionTemplate implements ExecutionTemplate { | ||
|
||
/** | ||
* Executes this callback. | ||
* This method is an override to remove all transactional (commits, rollbacks,etc) that are not supported in Kinetica. | ||
* | ||
* @param callback The callback to execute. | ||
* @return The result of the NON transaction KINETICA code. | ||
*/ | ||
@Override | ||
public <T> T execute(Callable<T> callback) { | ||
|
||
try { | ||
T result = callback.call(); | ||
return result; | ||
} catch (Exception e) { | ||
RuntimeException rethrow; | ||
if (e instanceof SQLException) { | ||
rethrow = new FlywaySqlException("Unable to execute SQL statement", (SQLException) e); | ||
} else if (e instanceof RuntimeException) { | ||
rethrow = (RuntimeException) e; | ||
} else { | ||
rethrow = new FlywayException(e); | ||
} | ||
|
||
throw rethrow; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ity-db-support/src/main/java/org/flywaydb/community/database/kinetica/KineticaParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (C) Red Gate Software Ltd 2010-2022 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.flywaydb.community.database.kinetica; | ||
|
||
import org.flywaydb.core.api.configuration.Configuration; | ||
import org.flywaydb.core.internal.parser.Parser; | ||
import org.flywaydb.core.internal.parser.ParsingContext; | ||
|
||
public class KineticaParser extends Parser { | ||
|
||
public KineticaParser(Configuration configuration, ParsingContext parsingContext) { | ||
super(configuration, parsingContext, 2); | ||
} | ||
|
||
} |
Oops, something went wrong.