use of org.apache.cayenne.util.EqualsBuilder in project cayenne by apache.
the class ClientServerChannelIT method testPerformQueryValuePropagation.
@Test
public void testPerformQueryValuePropagation() throws Exception {
byte[] bytes = new byte[] { 1, 2, 3 };
tMtTable3.insert(1, bytes, "abc", 4);
Query query = new SelectQuery("MtTable3");
QueryResponse response = clientServerChannel.onQuery(null, query);
assertNotNull(response);
List<?> results = response.firstList();
assertNotNull(results);
assertEquals(1, results.size());
Object result = results.get(0);
assertTrue("Result is of wrong type: " + result, result instanceof ClientMtTable3);
ClientMtTable3 clientObject = (ClientMtTable3) result;
assertEquals("abc", clientObject.getCharColumn());
assertEquals(new Integer(4), clientObject.getIntColumn());
assertTrue(new EqualsBuilder().append(clientObject.getBinaryColumn(), bytes).isEquals());
}
use of org.apache.cayenne.util.EqualsBuilder in project cayenne by apache.
the class RelationshipLoader method load.
@Override
public void load(DatabaseMetaData metaData, DbLoadDataStore map) throws SQLException {
if (config.isSkipRelationshipsLoading()) {
return;
}
for (Map.Entry<String, Set<ExportedKey>> entry : map.getExportedKeysEntrySet()) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Process keys for: " + entry.getKey());
}
Set<ExportedKey> exportedKeys = entry.getValue();
ExportedKey key = exportedKeys.iterator().next();
if (key == null) {
throw new IllegalStateException();
}
ExportedKey.KeyData PK = key.getPk();
ExportedKey.KeyData FK = key.getFk();
DbEntity pkEntity = map.getDbEntity(PK.getTable());
DbEntity fkEntity = map.getDbEntity(FK.getTable());
if (pkEntity == null || fkEntity == null) {
// Check for existence of this entities were made in creation of ExportedKey
throw new IllegalStateException();
}
if (!new EqualsBuilder().append(pkEntity.getCatalog(), PK.getCatalog()).append(pkEntity.getSchema(), PK.getSchema()).append(fkEntity.getCatalog(), FK.getCatalog()).append(fkEntity.getSchema(), PK.getSchema()).isEquals()) {
LOGGER.info("Skip relation: '" + key + "' because it related to objects from other catalog/schema");
LOGGER.info(" relation primary key: '" + PK.getCatalog() + "." + PK.getSchema() + "'");
LOGGER.info(" primary key entity: '" + pkEntity.getCatalog() + "." + pkEntity.getSchema() + "'");
LOGGER.info(" relation foreign key: '" + FK.getCatalog() + "." + FK.getSchema() + "'");
LOGGER.info(" foreign key entity: '" + fkEntity.getCatalog() + "." + fkEntity.getSchema() + "'");
continue;
}
// forwardRelationship is a reference from table with primary key
// it is what exactly we load from db
DbRelationship forwardRelationship = new DbRelationship();
forwardRelationship.setSourceEntity(pkEntity);
forwardRelationship.setTargetEntityName(fkEntity);
// TODO: dirty and non-transparent... using DbRelationshipDetected for the benefit of the merge package.
// This info is available from joins....
DbRelationshipDetected reverseRelationship = new DbRelationshipDetected();
reverseRelationship.setFkName(FK.getName());
reverseRelationship.setSourceEntity(fkEntity);
reverseRelationship.setTargetEntityName(pkEntity);
reverseRelationship.setToMany(false);
createAndAppendJoins(exportedKeys, pkEntity, fkEntity, forwardRelationship, reverseRelationship);
boolean toDependentPK = isToDependentPK(forwardRelationship);
boolean toMany = isToMany(toDependentPK, fkEntity, forwardRelationship);
forwardRelationship.setToDependentPK(toDependentPK);
forwardRelationship.setToMany(toMany);
// set relationship names only after their joins are ready ...
// generator logic is based on relationship state...
setRelationshipName(pkEntity, forwardRelationship);
setRelationshipName(fkEntity, reverseRelationship);
checkAndAddRelationship(pkEntity, forwardRelationship);
checkAndAddRelationship(fkEntity, reverseRelationship);
}
}
Aggregations