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();
}
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();
}
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();
}
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();
}
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());
}
}
}
Aggregations