Search in sources :

Example 16 with QuotingStrategy

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

the class Oracle8LOBBatchTranslator method createLOBSelectString.

String createLOBSelectString(List<DbAttribute> selectedLOBAttributes, List<DbAttribute> qualifierAttributes) {
    QuotingStrategy strategy = adapter.getQuotingStrategy();
    StringBuilder buf = new StringBuilder();
    buf.append("SELECT ");
    Iterator<DbAttribute> it = selectedLOBAttributes.iterator();
    while (it.hasNext()) {
        buf.append(strategy.quotedName(it.next()));
        if (it.hasNext()) {
            buf.append(", ");
        }
    }
    buf.append(" FROM ").append(strategy.quotedFullyQualifiedName(query.getDbEntity())).append(" WHERE ");
    it = qualifierAttributes.iterator();
    while (it.hasNext()) {
        DbAttribute attribute = it.next();
        appendDbAttribute(buf, attribute);
        buf.append(" = ?");
        if (it.hasNext()) {
            buf.append(" AND ");
        }
    }
    buf.append(" FOR UPDATE");
    return buf.toString();
}
Also used : DbAttribute(org.apache.cayenne.map.DbAttribute) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 17 with QuotingStrategy

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

the class Oracle8LOBInsertBatchTranslator method createSql.

@Override
public String createSql(BatchQueryRow row) {
    List<DbAttribute> dbAttributes = query.getDbAttributes();
    QuotingStrategy strategy = adapter.getQuotingStrategy();
    StringBuilder buffer = new StringBuilder("INSERT INTO ");
    buffer.append(strategy.quotedFullyQualifiedName(query.getDbEntity()));
    buffer.append(" (");
    for (Iterator<DbAttribute> i = dbAttributes.iterator(); i.hasNext(); ) {
        DbAttribute attribute = i.next();
        buffer.append(strategy.quotedName(attribute));
        if (i.hasNext()) {
            buffer.append(", ");
        }
    }
    buffer.append(") VALUES (");
    for (int i = 0; i < dbAttributes.size(); i++) {
        if (i > 0) {
            buffer.append(", ");
        }
        appendUpdatedParameter(buffer, dbAttributes.get(i), row.getValue(i));
    }
    buffer.append(')');
    return buffer.toString();
}
Also used : DbAttribute(org.apache.cayenne.map.DbAttribute) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 18 with QuotingStrategy

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

the class Oracle8LOBUpdateBatchTranslator method createSql.

@Override
public String createSql(BatchQueryRow row) {
    UpdateBatchQuery updateBatch = (UpdateBatchQuery) query;
    List<DbAttribute> idDbAttributes = updateBatch.getQualifierAttributes();
    List<DbAttribute> updatedDbAttributes = updateBatch.getUpdatedAttributes();
    QuotingStrategy strategy = adapter.getQuotingStrategy();
    StringBuilder buffer = new StringBuilder("UPDATE ");
    buffer.append(strategy.quotedFullyQualifiedName(query.getDbEntity()));
    buffer.append(" SET ");
    int len = updatedDbAttributes.size();
    for (int i = 0; i < len; i++) {
        if (i > 0) {
            buffer.append(", ");
        }
        DbAttribute attribute = updatedDbAttributes.get(i);
        buffer.append(strategy.quotedName(attribute));
        buffer.append(" = ");
        appendUpdatedParameter(buffer, attribute, row.getValue(i));
    }
    buffer.append(" WHERE ");
    Iterator<DbAttribute> i = idDbAttributes.iterator();
    while (i.hasNext()) {
        DbAttribute attribute = i.next();
        appendDbAttribute(buffer, attribute);
        buffer.append(" = ?");
        if (i.hasNext()) {
            buffer.append(" AND ");
        }
    }
    return buffer.toString();
}
Also used : UpdateBatchQuery(org.apache.cayenne.query.UpdateBatchQuery) DbAttribute(org.apache.cayenne.map.DbAttribute) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 19 with QuotingStrategy

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

the class PostgresAdapter method createTable.

/**
 * Customizes table creating procedure for PostgreSQL. One difference with
 * generic implementation is that "bytea" type has no explicit length unlike
 * similar binary types in other databases.
 *
 * @since 1.0.2
 */
@Override
public String createTable(DbEntity ent) {
    QuotingStrategy context = getQuotingStrategy();
    StringBuilder buf = new StringBuilder();
    buf.append("CREATE TABLE ").append(context.quotedFullyQualifiedName(ent)).append(" (");
    // columns
    Iterator<DbAttribute> it = ent.getAttributes().iterator();
    boolean first = true;
    while (it.hasNext()) {
        if (first) {
            first = false;
        } else {
            buf.append(", ");
        }
        createAttribute(ent, context, buf, it.next());
    }
    // primary key clause
    Iterator<DbAttribute> pkit = ent.getPrimaryKeys().iterator();
    if (pkit.hasNext()) {
        if (first) {
            first = false;
        } else {
            buf.append(", ");
        }
        buf.append("PRIMARY KEY (");
        boolean firstPk = true;
        while (pkit.hasNext()) {
            if (firstPk) {
                firstPk = false;
            } else {
                buf.append(", ");
            }
            DbAttribute at = pkit.next();
            buf.append(context.quotedName(at));
        }
        buf.append(')');
    }
    buf.append(')');
    return buf.toString();
}
Also used : DbAttribute(org.apache.cayenne.map.DbAttribute) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 20 with QuotingStrategy

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

the class UnitDbAdapter method dropConstraints.

protected void dropConstraints(Connection conn, DataMap map, Collection<String> tablesToDrop) throws Exception {
    Map<String, Collection<String>> constraintsMap = getConstraints(conn, map, tablesToDrop);
    for (Map.Entry<String, Collection<String>> entry : constraintsMap.entrySet()) {
        Collection<String> constraints = entry.getValue();
        if (constraints == null || constraints.isEmpty()) {
            continue;
        }
        Object tableName = entry.getKey();
        DbEntity entity = map.getDbEntity(tableName.toString());
        if (entity == null) {
            continue;
        }
        QuotingStrategy strategy = adapter.getQuotingStrategy();
        for (String constraint : constraints) {
            StringBuilder drop = new StringBuilder();
            drop.append("ALTER TABLE ").append(strategy.quotedFullyQualifiedName(entity)).append(" DROP CONSTRAINT ").append(constraint);
            executeDDL(conn, drop.toString());
        }
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) Collection(java.util.Collection) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy) HashMap(java.util.HashMap) Map(java.util.Map) DataMap(org.apache.cayenne.map.DataMap)

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