All Downloads are FREE. Search and download functionalities are using the official Maven repository.

liquibase.database.core.Db2zDatabase Maven / Gradle / Ivy

There is a newer version: 4.30.0
Show newest version
package liquibase.database.core;

import liquibase.database.DatabaseConnection;
import liquibase.exception.DatabaseException;
import liquibase.structure.DatabaseObject;
import liquibase.structure.core.Column;
import liquibase.structure.core.Index;
import liquibase.util.StringUtil;

public class Db2zDatabase extends AbstractDb2Database {
	
	// See https://www.ibm.com/support/knowledgecenter/en/SSEPEK_11.0.0/sqlref/src/tpc/db2z_limits.html#db2z_limits__limdt, 
	// may not apply to older versions, caveat emptor 
	private static final int MAX_DB2Z_TIMESTAMP_FRACTIONAL_DIGITS = 12;
	
    public Db2zDatabase() {
        super.setCurrentDateTimeFunction("CURRENT TIMESTAMP");
        super.sequenceNextValueFunction = "NEXT VALUE FOR %s";
        super.sequenceCurrentValueFunction = "PREVIOUS VALUE FOR %s";
        super.unquotedObjectsAreUppercased=true;
    }

    @Override
    public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException {
        return conn.getDatabaseProductName().startsWith("DB2") && StringUtil.startsWith(conn.getDatabaseProductVersion(), "DSN");
    }

    @Override
    public String getShortName() {
        return "db2z";
    }

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

    @Override
    public String correctObjectName(final String objectName, final Class objectType) {
        return objectName;
    }

    @Override
    public boolean isSystemObject(DatabaseObject example) {
        boolean isSystemIndex = example instanceof Index && example.getName() != null && example.getName().contains("_#_");
        boolean isSystemColumn = example instanceof Column && StringUtil.startsWith(example.getName(), "DB2_GENERATED");
        return isSystemIndex || isSystemColumn || super.isSystemObject(example);
    }

    @Override
    protected String getDefaultDatabaseProductName() {
        return "DB2/z";
    }

    @Override
    public int getMaxFractionalDigitsForTimestamp() {
    	return MAX_DB2Z_TIMESTAMP_FRACTIONAL_DIGITS;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy