Search in sources :

Example 31 with QuotingStrategy

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

the class SybaseMergerTokenFactory method createDropColumnToDb.

/**
 * @since 3.0
 */
@Override
public MergerToken createDropColumnToDb(DbEntity entity, DbAttribute column) {
    return new DropColumnToDb(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(" DROP ");
            sqlBuffer.append(context.quotedName(getColumn()));
            return Collections.singletonList(sqlBuffer.toString());
        }
    };
}
Also used : DropColumnToDb(org.apache.cayenne.dbsync.merge.token.db.DropColumnToDb) DbAdapter(org.apache.cayenne.dba.DbAdapter) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 32 with QuotingStrategy

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

the class SybaseMergerTokenFactory method createAddColumnToDb.

/**
 * @since 3.0
 */
@Override
public MergerToken createAddColumnToDb(DbEntity entity, final DbAttribute column) {
    return new AddColumnToDb(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(" ADD ");
            boolean magnatory = column.isMandatory();
            column.setMandatory(false);
            adapter.createTableAppendColumn(sqlBuffer, column);
            if (magnatory) {
                column.setMandatory(magnatory);
            }
            return Collections.singletonList(sqlBuffer.toString());
        }
    };
}
Also used : AddColumnToDb(org.apache.cayenne.dbsync.merge.token.db.AddColumnToDb) DbAdapter(org.apache.cayenne.dba.DbAdapter) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 33 with QuotingStrategy

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

the class AddColumnToDb method createSql.

@Override
public List<String> createSql(DbAdapter adapter) {
    StringBuffer sqlBuffer = new StringBuffer();
    QuotingStrategy context = adapter.getQuotingStrategy();
    appendPrefix(sqlBuffer, context);
    sqlBuffer.append(JdbcAdapter.getType(adapter, getColumn()));
    sqlBuffer.append(JdbcAdapter.sizeAndPrecision(adapter, getColumn()));
    return Collections.singletonList(sqlBuffer.toString());
}
Also used : QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 34 with QuotingStrategy

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

the class DropColumnToDb method createSql.

@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(" DROP COLUMN ");
    sqlBuffer.append(context.quotedName(getColumn()));
    return Collections.singletonList(sqlBuffer.toString());
}
Also used : QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 35 with QuotingStrategy

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

the class SetAllowNullToDb method createSql.

@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(" DROP NOT NULL");
    return Collections.singletonList(sqlBuffer.toString());
}
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