Search in sources :

Example 1 with SetAllowNullToDb

use of org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb in project cayenne by apache.

the class FirebirdMergerTokenFactory method createSetAllowNullToDb.

@Override
public MergerToken createSetAllowNullToDb(DbEntity entity, DbAttribute column) {
    return new SetAllowNullToDb(entity, column) {

        public List<String> createSql(DbAdapter adapter) {
            QuotingStrategy context = adapter.getQuotingStrategy();
            String entityName = context.quotedFullyQualifiedName(getEntity());
            String columnName = context.quotedName(getColumn());
            // but this might be achived by modyfication system tables
            return Collections.singletonList(String.format("UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = NULL " + " WHERE RDB$FIELD_NAME = '%s' AND RDB$RELATION_NAME = '%s'", columnName, entityName));
        }
    };
}
Also used : DbAdapter(org.apache.cayenne.dba.DbAdapter) SetAllowNullToDb(org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 2 with SetAllowNullToDb

use of org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb in project cayenne by apache.

the class IngresMergerTokenFactory method createSetAllowNullToDb.

@Override
public MergerToken createSetAllowNullToDb(DbEntity entity, DbAttribute column) {
    return new SetAllowNullToDb(entity, column) {

        @Override
        public List<String> createSql(DbAdapter adapter) {
            StringBuilder sqlBuffer = new StringBuilder();
            QuotingStrategy context = adapter.getQuotingStrategy();
            sqlBuffer.append("ALTER TABLE ");
            sqlBuffer.append(context.quotedFullyQualifiedName(getEntity()));
            sqlBuffer.append(" ALTER COLUMN ");
            sqlBuffer.append(context.quotedName(getColumn()));
            sqlBuffer.append(" ");
            sqlBuffer.append(adapter.externalTypesForJdbcType(getColumn().getType())[0]);
            if (adapter.typeSupportsLength(getColumn().getType()) && getColumn().getMaxLength() > 0) {
                sqlBuffer.append("(");
                sqlBuffer.append(getColumn().getMaxLength());
                sqlBuffer.append(")");
            }
            sqlBuffer.append(" WITH NULL");
            return Collections.singletonList(sqlBuffer.toString());
        }
    };
}
Also used : DbAdapter(org.apache.cayenne.dba.DbAdapter) SetAllowNullToDb(org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 3 with SetAllowNullToDb

use of org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb in project cayenne by apache.

the class MySQLMergerTokenFactory method createSetAllowNullToDb.

@Override
public MergerToken createSetAllowNullToDb(final DbEntity entity, final DbAttribute column) {
    return new SetAllowNullToDb(entity, column) {

        @Override
        public List<String> createSql(DbAdapter adapter) {
            StringBuffer sqlBuffer = new StringBuffer();
            QuotingStrategy context = adapter.getQuotingStrategy();
            sqlBuffer.append("ALTER TABLE ");
            sqlBuffer.append(context.quotedFullyQualifiedName(getEntity()));
            sqlBuffer.append(" CHANGE ");
            sqlBuffer.append(context.quotedName(getColumn()));
            sqlBuffer.append(" ");
            adapter.createTableAppendColumn(sqlBuffer, column);
            return Collections.singletonList(sqlBuffer.toString());
        }
    };
}
Also used : DbAdapter(org.apache.cayenne.dba.DbAdapter) SetAllowNullToDb(org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Aggregations

DbAdapter (org.apache.cayenne.dba.DbAdapter)3 QuotingStrategy (org.apache.cayenne.dba.QuotingStrategy)3 SetAllowNullToDb (org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb)3