Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kinetica support #1

Merged
merged 4 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions flyway-community-db-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
<version>${version.junit}</version>
</dependency>
<!-- JDBC drivers -->
<!-- https://mvnrepository.com/artifact/com.kinetica/kinetica-jdbc -->
<dependency>
<groupId>com.kinetica</groupId>
<artifactId>kinetica-jdbc</artifactId>
<version>7.1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-core</artifactId>
Expand Down
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();
}
}
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;
}


}
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;
}
}
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;
}
}
}
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);
}

}
Loading