Search in sources :

Example 6 with QuotingStrategy

use of org.apache.cayenne.dba.QuotingStrategy in project cayenne by apache.

the class FirebirdMergerTokenFactory method createSetNotNullToDb.

@Override
public MergerToken createSetNotNullToDb(DbEntity entity, DbAttribute column) {
    return new SetNotNullToDb(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 of system tables
            return Collections.singletonList(String.format("UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = 1 " + "WHERE RDB$FIELD_NAME = '%s' AND RDB$RELATION_NAME = '%s'", columnName, entityName));
        }
    };
}
Also used : DbAdapter(org.apache.cayenne.dba.DbAdapter) SetNotNullToDb(org.apache.cayenne.dbsync.merge.token.db.SetNotNullToDb) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 7 with QuotingStrategy

use of org.apache.cayenne.dba.QuotingStrategy in project cayenne by apache.

the class MySQLMergerTokenFactory method createSetNotNullToDb.

@Override
public MergerToken createSetNotNullToDb(final DbEntity entity, final DbAttribute column) {
    return new SetNotNullToDb(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) SetNotNullToDb(org.apache.cayenne.dbsync.merge.token.db.SetNotNullToDb) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 8 with QuotingStrategy

use of org.apache.cayenne.dba.QuotingStrategy in project cayenne by apache.

the class SybaseMergerTokenFactory method createStringQuery.

private static StringBuffer createStringQuery(DbAdapter adapter, DbEntity entity, DbAttribute column) {
    StringBuffer sqlBuffer = new StringBuffer();
    QuotingStrategy context = adapter.getQuotingStrategy();
    sqlBuffer.append("ALTER TABLE ");
    sqlBuffer.append(context.quotedFullyQualifiedName(entity));
    sqlBuffer.append(" MODIFY ");
    adapter.createTableAppendColumn(sqlBuffer, column);
    return sqlBuffer;
}
Also used : QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 9 with QuotingStrategy

use of org.apache.cayenne.dba.QuotingStrategy in project cayenne by apache.

the class SetGeneratedFlagToDb method createSql.

@SuppressWarnings("unchecked")
@Override
public List<String> createSql(DbAdapter adapter) {
    if (!adapter.supportsGeneratedKeys()) {
        return (List<String>) Collections.EMPTY_LIST;
    }
    QuotingStrategy context = adapter.getQuotingStrategy();
    StringBuffer builder = new StringBuffer();
    builder.append("ALTER TABLE ").append(context.quotedFullyQualifiedName(getEntity()));
    appendAlterColumnClause(adapter, builder);
    if (isGenerated) {
        appendAutoIncrement(adapter, builder);
    } else {
        appendDropAutoIncrement(adapter, builder);
    }
    return Collections.singletonList(builder.toString());
}
Also used : List(java.util.List) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 10 with QuotingStrategy

use of org.apache.cayenne.dba.QuotingStrategy in project cayenne by apache.

the class SetGeneratedFlagToDb method appendAlterColumnClause.

protected void appendAlterColumnClause(DbAdapter adapter, StringBuffer builder) {
    QuotingStrategy context = adapter.getQuotingStrategy();
    builder.append(" ALTER COLUMN ").append(context.quotedName(getColumn())).append(" ");
}
Also used : QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Aggregations

QuotingStrategy (org.apache.cayenne.dba.QuotingStrategy)42 DbAdapter (org.apache.cayenne.dba.DbAdapter)11 DbAttribute (org.apache.cayenne.map.DbAttribute)11 DbEntity (org.apache.cayenne.map.DbEntity)5 DbJoin (org.apache.cayenne.map.DbJoin)5 DbRelationship (org.apache.cayenne.map.DbRelationship)5 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)4 SetAllowNullToDb (org.apache.cayenne.dbsync.merge.token.db.SetAllowNullToDb)3 SetNotNullToDb (org.apache.cayenne.dbsync.merge.token.db.SetNotNullToDb)3 EJBQLException (org.apache.cayenne.ejbql.EJBQLException)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 DropColumnToDb (org.apache.cayenne.dbsync.merge.token.db.DropColumnToDb)2 EJBQLPath (org.apache.cayenne.ejbql.parser.EJBQLPath)2 DataMap (org.apache.cayenne.map.DataMap)2 ObjRelationship (org.apache.cayenne.map.ObjRelationship)2 UpdateBatchQuery (org.apache.cayenne.query.UpdateBatchQuery)2 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)2