use of org.apache.cayenne.DataRow in project cayenne by apache.
the class ReturnTypesMappingIT method testLONGNVARCHAR.
@Test
public void testLONGNVARCHAR() throws Exception {
String columnName = "LONGNVARCHAR_COLUMN";
ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 500; i++) {
buffer.append("ی متوازن، نیازی ندارد که ب large string for tests!!!!\n");
}
String longnvarcharValue = buffer.toString();
test.setLongnvarcharColumn(longnvarcharValue);
context.commitChanges();
DataRow testRead = (DataRow) context.performQuery(MappedSelect.query("SelectReturnTypesMap1")).get(0);
Object columnValue = testRead.get(columnName);
assertNotNull(columnValue);
assertEquals(String.class, columnValue.getClass());
assertEquals(longnvarcharValue, columnValue);
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class ReturnTypesMappingIT method testNCHAR.
@Test
public void testNCHAR() throws Exception {
String columnName = "NCHAR_COLUMN";
ReturnTypesMap1 test = context.newObject(ReturnTypesMap1.class);
String charValue = "درختهای جستجوی متوازن، نیازی ندارد که به صورت!";
test.setNcharColumn(charValue);
context.commitChanges();
DataRow testRead = (DataRow) context.performQuery(MappedSelect.query("SelectReturnTypesMap1")).get(0);
Object columnValue = testRead.get(columnName);
assertNotNull(columnValue);
assertEquals(String.class, columnValue.getClass());
assertEquals(charValue, columnValue);
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class DeletedDiffProcessor method nodeRemoved.
@Override
public void nodeRemoved(Object nodeId) {
ObjectId id = (ObjectId) nodeId;
final MutableObjectChange objectChangeSet = changeSet.getOrCreate(id, ObjectChangeType.DELETE);
// TODO: rewrite with SelectById query after Cayenne upgrade
ObjectIdQuery query = new ObjectIdQuery(id, true, ObjectIdQuery.CACHE);
QueryResponse result = channel.onQuery(null, query);
@SuppressWarnings("unchecked") List<DataRow> rows = result.firstList();
if (rows.isEmpty()) {
LOGGER.warn("No DB snapshot for object to be deleted, no changes will be recorded. ID: " + id);
return;
}
final DataRow row = rows.get(0);
ClassDescriptor descriptor = channel.getEntityResolver().getClassDescriptor(id.getEntityName());
final CommitLogEntity entity = entityFactory.getEntity(id);
descriptor.visitProperties(new PropertyVisitor() {
@Override
public boolean visitAttribute(AttributeProperty property) {
if (!entity.isIncluded(property.getName())) {
return true;
}
Object value;
if (entity.isConfidential(property.getName())) {
value = Confidential.getInstance();
} else {
String key = property.getAttribute().getDbAttributeName();
value = row.get(key);
}
if (value != null) {
objectChangeSet.attributeChanged(property.getName(), value, null);
}
return true;
}
@Override
public boolean visitToOne(ToOneProperty property) {
if (!entity.isIncluded(property.getName())) {
return true;
}
// TODO: is there such a thing as "confidential" relationship that we need to hide?
DbRelationship dbRelationship = property.getRelationship().getDbRelationships().get(0);
ObjectId value = row.createTargetObjectId(property.getTargetDescriptor().getEntity().getName(), dbRelationship);
if (value != null) {
objectChangeSet.toOneRelationshipDisconnected(property.getName(), value);
}
return true;
}
@Override
public boolean visitToMany(ToManyProperty property) {
return true;
}
});
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class FrontBasePkGenerator method longPkFromDatabase.
/**
* @since 3.0
*/
@Override
protected long longPkFromDatabase(DataNode node, DbEntity entity) throws Exception {
String template = "SELECT #result('UNIQUE' 'long') FROM " + entity.getName();
final long[] pkHolder = new long[1];
SQLTemplate query = new SQLTemplate(entity, template);
OperationObserver observer = new DoNothingOperationObserver() {
@Override
public void nextRows(Query query, List<?> dataRows) {
if (dataRows.size() != 1) {
throw new CayenneRuntimeException("Error fetching PK. Expected one row, got %d", dataRows.size());
}
DataRow row = (DataRow) dataRows.get(0);
Number pk = (Number) row.get("UNIQUE");
pkHolder[0] = pk.longValue();
}
};
node.performQueries(Collections.singleton((Query) query), observer);
return pkHolder[0];
}
use of org.apache.cayenne.DataRow in project cayenne by apache.
the class ObjectResolver method objectsFromDataRows.
/**
* Converts rows to objects.
* <p>
* Synchronization note. This method requires EXTERNAL synchronization on
* ObjectStore and DataRowStore.
* </p>
*/
List<Persistent> objectsFromDataRows(List<? extends DataRow> rows) {
if (rows == null || rows.size() == 0) {
return new ArrayList<>(1);
}
List<Persistent> results = new ArrayList<>(rows.size());
for (DataRow row : rows) {
// nulls are possible here since 3.0 for some varieties of EJBQL,
// simple example of this: "select p.toGallery+ from Painting p" where toGallery is null.
results.add(objectFromDataRow(row));
}
// now deal with snapshots
cache.snapshotsUpdatedForObjects(results, rows, refreshObjects);
return results;
}
Aggregations