use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class DefaultValueTransformerFactoryIT method testCreateEncryptor.
@Test
public void testCreateEncryptor() {
DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING");
ValueEncryptor t1 = f.createEncryptor(t1_ct);
assertNotNull(t1);
assertTrue(t1 instanceof DefaultValueEncryptor);
assertSame(Utf8StringConverter.INSTANCE, ((DefaultValueEncryptor) t1).getPreConverter());
assertSame(Base64StringConverter.INSTANCE, ((DefaultValueEncryptor) t1).getPostConverter());
DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES");
ValueEncryptor t2 = f.createEncryptor(t2_cb);
assertNotNull(t2);
assertTrue(t2 instanceof DefaultValueEncryptor);
assertSame(BytesToBytesConverter.INSTANCE, ((DefaultValueEncryptor) t2).getPreConverter());
assertSame(BytesToBytesConverter.INSTANCE, ((DefaultValueEncryptor) t2).getPostConverter());
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class DbRelationshipMerger method createTokensForMissingOriginal.
/**
* @param imported DbRelationship that is in db but not in model
* @return generated tokens
*/
@Override
Collection<MergerToken> createTokensForMissingOriginal(DbRelationship imported) {
DbEntity originalDbEntity = getOriginalSourceDbEntity(imported);
DbEntity targetEntity = getOriginalTargetDbEntity(imported);
if (targetEntity != null) {
imported.setTargetEntityName(targetEntity);
}
imported.setSourceEntity(originalDbEntity);
// manipulate the joins to match the DbAttributes in the model
for (DbJoin join : imported.getJoins()) {
DbAttribute sourceAttr = findDbAttribute(originalDbEntity, join.getSourceName());
if (sourceAttr != null) {
join.setSourceName(sourceAttr.getName());
}
DbAttribute targetAttr = findDbAttribute(targetEntity, join.getTargetName());
if (targetAttr != null) {
join.setTargetName(targetAttr.getName());
}
}
// Add all relationships. Tokens will decide whether or not to execute
MergerToken token = getTokenFactory().createDropRelationshipToDb(originalDbEntity, imported);
return Collections.singleton(token);
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class EntityMergeSupport method addMissingAttributes.
private boolean addMissingAttributes(ObjEntity entity) {
boolean changed = false;
for (DbAttribute da : getAttributesToAdd(entity)) {
addMissingAttribute(entity, da);
changed = true;
}
return changed;
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class EntityMergeSupport method isSameAttributes.
/**
* @param collection1 first collection to compare
* @param collection2 second collection to compare
* @return true if collections have same size and attributes in them have same names
*/
private boolean isSameAttributes(Collection<DbAttribute> collection1, Collection<DbAttribute> collection2) {
if (collection1.size() != collection2.size()) {
return false;
}
if (collection1.isEmpty()) {
return true;
}
Iterator<DbAttribute> iterator1 = collection1.iterator();
Iterator<DbAttribute> iterator2 = collection2.iterator();
for (int i = 0; i < collection1.size(); i++) {
DbAttribute attr1 = iterator1.next();
DbAttribute attr2 = iterator2.next();
// attribute can be null, see DbJoin.getSource() and DbJoin.getTarget()
if (attr1 == null) {
if (attr2 != null) {
return false;
}
continue;
}
if (attr2 == null) {
return false;
}
// name is unlikely to be null, but we don't want NPE anyway
if (attr1.getName() == null) {
if (attr2.getName() != null) {
return false;
}
continue;
}
if (!attr1.getName().equals(attr2.getName())) {
return false;
}
}
return true;
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class SetPrimaryKeyToModel method execute.
@Override
public void execute(MergerContext mergerContext) {
DbEntity e = getEntity();
for (DbAttribute attr : e.getAttributes()) {
boolean wasPrimaryKey = attr.isPrimaryKey();
boolean willBePrimaryKey = primaryKeyNewAttributeNames.contains(attr.getName().toUpperCase());
if (wasPrimaryKey != willBePrimaryKey) {
attr.setPrimaryKey(willBePrimaryKey);
e.dbAttributeChanged(new AttributeEvent(this, attr, e));
mergerContext.getDelegate().dbAttributeModified(attr);
}
}
}
Aggregations