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

support sinodb #3713

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) Red Gate Software Ltd 2010-2023
*
* 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.core.internal.database.sinodb;

import org.flywaydb.core.internal.database.base.Connection;
import org.flywaydb.core.internal.database.base.Schema;

import java.sql.SQLException;

/**
* SinoDB connection.
*/
public class SinoDBConnection extends Connection<SinoDBDatabase> {
InformixConnection(InformixDatabase database, java.sql.Connection connection) {
super(database, connection);
}

@Override
protected String getCurrentSchemaNameOrSearchPath() throws SQLException {
return getJdbcConnection().getMetaData().getUserName();
}

@Override
public Schema getSchema(String name) {
return new InformixSchema(jdbcTemplate, database, name);
}

@Override
public void changeCurrentSchemaTo(Schema schema) {
// Informix doesn't support schemas
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright (C) Red Gate Software Ltd 2010-2023
*
* 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.core.internal.database.sinodb;

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;
import java.sql.SQLException;

/**
* SinoDB database.
*/
public class SinoDBDatabase extends Database<SinoDBConnection> {

public SinoDBDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) {
super(configuration, jdbcConnectionFactory, statementInterceptor);
}

@Override
protected SinoDBConnection doGetConnection(Connection connection) {
return new SinoDBConnection(this, connection);
}







@Override
public final void ensureSupported() {
ensureDatabaseIsRecentEnough("12.10");
recommendFlywayUpgradeIfNecessary("12.10");
}

@Override
public String getRawCreateScript(Table table, boolean baseline) {
String tablespace = configuration.getTablespace() == null
? ""
: " IN \"" + configuration.getTablespace() + "\"";

return "CREATE 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 LVARCHAR(1000) NOT NULL,\n" +
" checksum INT,\n" +
" installed_by VARCHAR(100) NOT NULL,\n" +
" installed_on DATETIME YEAR TO FRACTION(3) DEFAULT CURRENT YEAR TO FRACTION(3) NOT NULL,\n" +
" execution_time INT NOT NULL,\n" +
" success SMALLINT NOT NULL\n" +
")" + tablespace + ";\n" +
(baseline ? getBaselineStatement(table) + ";\n" : "") +
"ALTER TABLE " + table + " ADD CONSTRAINT CHECK (success in (0,1)) CONSTRAINT " + table.getName() + "_s;\n" +
"ALTER TABLE " + table + " ADD CONSTRAINT PRIMARY KEY (installed_rank) CONSTRAINT " + table.getName() + "_pk;\n" +
"CREATE INDEX " + table.getName() + "_s_idx ON " + table + " (success);";
}

@Override
protected String doGetCurrentUser() throws SQLException {
return getJdbcMetaData().getUserName();
}

@Override
public boolean supportsDdlTransactions() {
return true;
}

@Override
public String getBooleanTrue() {
return "1";
}

@Override
public String getBooleanFalse() {
return "0";
}

@Override
public String getOpenQuote() {
return "";
}

@Override
public String getCloseQuote() {
return "";
}

@Override
public boolean catalogIsSchema() {
return false;
}

@Override
public boolean useSingleConnection() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (C) Red Gate Software Ltd 2010-2023
*
* 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.core.internal.database.sinodb;

import org.flywaydb.core.api.ResourceProvider;
import org.flywaydb.core.api.configuration.Configuration;
import org.flywaydb.core.internal.database.base.Database;
import org.flywaydb.core.internal.database.base.BaseDatabaseType;
import org.flywaydb.core.internal.jdbc.JdbcConnectionFactory;
import org.flywaydb.core.internal.jdbc.StatementInterceptor;
import org.flywaydb.core.internal.parser.Parser;
import org.flywaydb.core.internal.parser.ParsingContext;

import java.sql.Connection;
import java.sql.Types;

public class SinoDBDatabaseType extends BaseDatabaseType {
@Override
public String getName() {
return "SinoDB";
}

@Override
public int getNullType() {
return Types.VARCHAR;
}

@Override
public boolean handlesJDBCUrl(String url) {
return url.startsWith("jdbc:informix-sqli:");
}

@Override
public String getDriverClass(String url, ClassLoader classLoader) {
return "com.sinodbms.jdbc.IfxDriver";
}

@Override
public boolean handlesDatabaseProductNameAndVersion(String databaseProductName, String databaseProductVersion, Connection connection) {
return databaseProductName.startsWith("SinoDB");
}

@Override
public Database createDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) {
return new SinoDBDatabase(configuration, jdbcConnectionFactory, statementInterceptor);
}

@Override
public Parser createParser(Configuration configuration, ResourceProvider resourceProvider, ParsingContext parsingContext) {
return new SinoDBParser(configuration, parsingContext);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) Red Gate Software Ltd 2010-2023
*
* 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.core.internal.database.sinodb;

import com.googlecode.flyway.core.dbsupport.DbSupport;
import com.googlecode.flyway.core.dbsupport.Function;
import com.googlecode.flyway.core.dbsupport.JdbcTemplate;
import com.googlecode.flyway.core.dbsupport.Schema;
import com.googlecode.flyway.core.util.StringUtils;
import java.sql.SQLException;

public class SinoDBFunction extends Function {
public SinoDBFunction(JdbcTemplate jdbcTemplate, DbSupport dbSupport, Schema schema, String name, String... args) {
super(jdbcTemplate, dbSupport, schema, name, args);
}

protected void doDrop() throws SQLException {
this.jdbcTemplate.execute("DROP FUNCTION " + this.dbSupport.quote(new String[]{this.schema.getName(), this.name}) + "(" + StringUtils.arrayToCommaDelimitedString(this.args) + ")", new Object[0]);
}

public String toString() {
return super.toString() + "(" + StringUtils.arrayToCommaDelimitedString(this.args) + ")";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) Red Gate Software Ltd 2010-2023
*
* 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.core.internal.database.sinodb;
import org.flywaydb.core.internal.database.sinodb.DbSupport;
import org.flywaydb.core.internal.jdbc.JdbcTemplate;
import org.flywaydb.core.internal.database.base.Schema;
import org.flywaydb.core.internal.database.base.Type;
import java.sql.SQLException;

public class SinoDBRowType extends Type {
public SinoDBRowType(JdbcTemplate jdbcTemplate, DbSupport dbSupport, Schema schema, String name) {
super(jdbcTemplate, dbSupport, schema, name);
}

protected void doDrop() throws SQLException {
this.jdbcTemplate.execute("DROP ROW TYPE " + this.dbSupport.quote(new String[]{this.schema.getName(), this.name}) + " RESTRICT", new Object[0]);
}
}
Loading