Search in sources :

Example 1 with ClobType

use of liquibase.datatype.core.ClobType in project liquibase by liquibase.

the class AbstractIntegrationTest method testInsertLongClob.

@Test
public void testInsertLongClob() {
    assumeNotNull(this.getDatabase());
    DatabaseChangeLog longClobChangelog = new DatabaseChangeLog();
    ChangeSet longClobInsert = new ChangeSet(longClobChangelog);
    ColumnConfig clobColumn = new ColumnConfig();
    clobColumn.setName("clobColumn");
    clobColumn.setType(LoadDataChange.LOAD_DATA_TYPE.CLOB.name());
    // Oracle database only allows string values of up to 4000 characters
    // so we test that the CLOB insertion is actually done as a CLOB in the JDBC statement
    StringBuilder longClobString = new StringBuilder(4001);
    for (int i = 0; i < 4001; i++) {
        longClobString.append('a');
    }
    clobColumn.setValue(longClobString.toString());
    CreateTableStatement clobTableCreator = new CreateTableStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), "tableWithClob");
    clobTableCreator.addColumn("clobColumn", new ClobType());
    InsertExecutablePreparedStatement insertStatement = new InsertExecutablePreparedStatement(database, database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), "tableWithClob", Arrays.asList(clobColumn), longClobInsert, Scope.getCurrentScope().getResourceAccessor());
    try {
        database.execute(new SqlStatement[] { clobTableCreator, insertStatement }, new ArrayList<>());
    } catch (LiquibaseException ex) {
        ex.printStackTrace();
        fail("Long clob insertion failed!");
    }
}
Also used : ClobType(liquibase.datatype.core.ClobType) ColumnConfig(liquibase.change.ColumnConfig) CreateTableStatement(liquibase.statement.core.CreateTableStatement) LiquibaseException(liquibase.exception.LiquibaseException) ChangeSet(liquibase.changelog.ChangeSet) InsertExecutablePreparedStatement(liquibase.statement.InsertExecutablePreparedStatement) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) Test(org.junit.Test)

Example 2 with ClobType

use of liquibase.datatype.core.ClobType in project liquibase by liquibase.

the class ClobTypeTest method mssqlEscapedNTextToNVarcharNoConvertTest.

@Test
public void mssqlEscapedNTextToNVarcharNoConvertTest() throws Exception {
    Scope.child(GlobalConfiguration.CONVERT_DATA_TYPES.getKey(), false, () -> {
        ClobType ct = new ClobType();
        ct.finishInitialization("[NText]");
        DatabaseDataType dbType = ct.toDatabaseDataType(new MSSQLDatabase());
        assertEquals("nvarchar (max)", dbType.getType());
    });
}
Also used : ClobType(liquibase.datatype.core.ClobType) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Test(org.junit.Test)

Example 3 with ClobType

use of liquibase.datatype.core.ClobType in project liquibase by liquibase.

the class ClobTypeTest method mssqlEscapedTextToVarcharTest.

@Test
public void mssqlEscapedTextToVarcharTest() throws Exception {
    Scope.child(GlobalConfiguration.CONVERT_DATA_TYPES.getKey(), true, () -> {
        ClobType ct = new ClobType();
        ct.finishInitialization("[Text]");
        DatabaseDataType dbType = ct.toDatabaseDataType(new MSSQLDatabase());
        assertEquals("varchar (max)", dbType.getType());
    });
}
Also used : ClobType(liquibase.datatype.core.ClobType) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Test(org.junit.Test)

Example 4 with ClobType

use of liquibase.datatype.core.ClobType in project liquibase by liquibase.

the class ClobTypeTest method mssqlEscapedTextToVarcharNoConvertTest.

@Test
public void mssqlEscapedTextToVarcharNoConvertTest() throws Exception {
    Scope.child(GlobalConfiguration.CONVERT_DATA_TYPES.getKey(), false, () -> {
        ClobType ct = new ClobType();
        ct.finishInitialization("[Text]");
        DatabaseDataType dbType = ct.toDatabaseDataType(new MSSQLDatabase());
        assertEquals("varchar (max)", dbType.getType());
    });
}
Also used : ClobType(liquibase.datatype.core.ClobType) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Test(org.junit.Test)

Example 5 with ClobType

use of liquibase.datatype.core.ClobType in project liquibase by liquibase.

the class ClobTypeTest method mssqlTextToVarcharTest.

@Test
public void mssqlTextToVarcharTest() throws Exception {
    Scope.child(GlobalConfiguration.CONVERT_DATA_TYPES.getKey(), true, () -> {
        ClobType ct = new ClobType();
        ct.finishInitialization("Text");
        DatabaseDataType dbType = ct.toDatabaseDataType(new MSSQLDatabase());
        assertEquals("varchar (max)", dbType.getType());
    });
}
Also used : ClobType(liquibase.datatype.core.ClobType) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Test(org.junit.Test)

Aggregations

ClobType (liquibase.datatype.core.ClobType)7 Test (org.junit.Test)7 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)6 ColumnConfig (liquibase.change.ColumnConfig)1 ChangeSet (liquibase.changelog.ChangeSet)1 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)1 LiquibaseException (liquibase.exception.LiquibaseException)1 InsertExecutablePreparedStatement (liquibase.statement.InsertExecutablePreparedStatement)1 CreateTableStatement (liquibase.statement.core.CreateTableStatement)1