use of org.apache.cayenne.query.UpdateBatchQuery in project cayenne by apache.
the class QuotedIdentifiersIT method testPrefetchQuote.
@Test
public void testPrefetchQuote() {
DbEntity entity = context.getEntityResolver().getObjEntity(QuoteAdress.class).getDbEntity();
List<DbAttribute> idAttributes = Collections.singletonList(entity.getAttribute("City"));
List<DbAttribute> updatedAttributes = Collections.singletonList(entity.getAttribute("City"));
UpdateBatchQuery updateQuery = new UpdateBatchQuery(entity, idAttributes, updatedAttributes, Collections.emptySet(), 1);
List objects3 = context.performQuery(updateQuery);
assertEquals(0, objects3.size());
List<Quote_Person> objects4 = ObjectSelect.query(Quote_Person.class).select(context);
assertEquals(2, objects4.size());
List<Quote_Person> objects5 = ObjectSelect.query(Quote_Person.class, Quote_Person.SALARY.eq(100)).select(context);
assertEquals(1, objects5.size());
List<Quote_Person> objects6 = ObjectSelect.query(Quote_Person.class, Quote_Person.GROUP.eq("107324")).select(context);
assertEquals(1, objects6.size());
List<QuoteAdress> objects7 = ObjectSelect.query(QuoteAdress.class, QuoteAdress.GROUP.eq("324")).select(context);
assertEquals(1, objects7.size());
ObjectIdQuery queryObjectId = new ObjectIdQuery(ObjectId.of("QuoteAdress", QuoteAdress.GROUP.getName(), "324"));
List objects8 = context.performQuery(queryObjectId);
assertEquals(1, objects8.size());
ObjectIdQuery queryObjectId2 = new ObjectIdQuery(ObjectId.of("Quote_Person", "GROUP", "1111"));
List objects9 = context.performQuery(queryObjectId2);
assertEquals(1, objects9.size());
Quote_Person quote_Person2 = ObjectSelect.query(Quote_Person.class, Quote_Person.NAME.eq("Name")).selectOne(context);
RelationshipQuery relationshipQuery = new RelationshipQuery(quote_Person2.getObjectId(), "address_Rel");
List objects10 = context.performQuery(relationshipQuery);
assertEquals(1, objects10.size());
}
use of org.apache.cayenne.query.UpdateBatchQuery in project cayenne by apache.
the class UpdateBatchTranslator method createBindings.
@Override
protected DbAttributeBinding[] createBindings() {
UpdateBatchQuery updateBatch = (UpdateBatchQuery) query;
List<DbAttribute> updatedDbAttributes = updateBatch.getUpdatedAttributes();
List<DbAttribute> qualifierAttributes = updateBatch.getQualifierAttributes();
int ul = updatedDbAttributes.size();
int ql = qualifierAttributes.size();
DbAttributeBinding[] bindings = new DbAttributeBinding[ul + ql];
for (int i = 0; i < ul; i++) {
bindings[i] = new DbAttributeBinding(updatedDbAttributes.get(i));
}
for (int i = 0; i < ql; i++) {
bindings[ul + i] = new DbAttributeBinding(qualifierAttributes.get(i));
}
return bindings;
}
use of org.apache.cayenne.query.UpdateBatchQuery in project cayenne by apache.
the class UpdateBatchTranslator method createSql.
@Override
protected String createSql() {
UpdateBatchQuery updateBatch = (UpdateBatchQuery) query;
QuotingStrategy strategy = adapter.getQuotingStrategy();
List<DbAttribute> qualifierAttributes = updateBatch.getQualifierAttributes();
List<DbAttribute> updatedDbAttributes = updateBatch.getUpdatedAttributes();
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(" = ?");
}
buffer.append(" WHERE ");
Iterator<DbAttribute> i = qualifierAttributes.iterator();
while (i.hasNext()) {
DbAttribute attribute = i.next();
appendDbAttribute(buffer, attribute);
buffer.append(updateBatch.isNull(attribute) ? " IS NULL" : " = ?");
if (i.hasNext()) {
buffer.append(" AND ");
}
}
return buffer.toString();
}
use of org.apache.cayenne.query.UpdateBatchQuery in project cayenne by apache.
the class UpdateBatchTranslator method updateBindings.
@Override
public DbAttributeBinding[] updateBindings(BatchQueryRow row) {
UpdateBatchQuery updateBatch = context.getQuery();
int i = 0;
int j = 0;
for (; i < updateBatch.getUpdatedAttributes().size(); i++) {
Object value = row.getValue(i);
ExtendedType<?> extendedType = value == null ? context.getAdapter().getExtendedTypes().getDefaultType() : context.getAdapter().getExtendedTypes().getRegisteredType(value.getClass());
bindings[j].include(++j, value, extendedType);
}
for (DbAttribute attribute : updateBatch.getQualifierAttributes()) {
if (updateBatch.isNull(attribute)) {
i++;
continue;
}
Object value = row.getValue(i);
ExtendedType<?> extendedType = context.getAdapter().getExtendedTypes().getRegisteredType(value.getClass());
bindings[j].include(++j, value, extendedType);
i++;
}
return bindings;
}
use of org.apache.cayenne.query.UpdateBatchQuery 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();
}
Aggregations