package io.ebeaninternal.server.persist.dmlbind;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.deploy.BeanProperty;
import io.ebeaninternal.server.deploy.BeanPropertyAssocOne;
class MatchedImportedFactory {
static MatchedImportedProperty[] build(BeanProperty[] props, BeanDescriptor<?> desc) {
MatchedImportedProperty[] matches = new MatchedImportedProperty[props.length];
for (int i = 0; i < props.length; i++) {
matches[i] = findMatch(props[i], desc);
if (matches[i] == null) {
return null;
}
}
return matches;
}
private static MatchedImportedProperty findMatch(BeanProperty prop, BeanDescriptor<?> desc) {
String dbColumn = prop.getDbColumn();
BeanPropertyAssocOne<?>[] assocOnes = desc.propertiesOne();
for (BeanPropertyAssocOne<?> assocOne1 : assocOnes) {
if (assocOne1.isImportedPrimaryKey()) {
BeanProperty foreignMatch = assocOne1.getImportedId().findMatchImport(dbColumn);
if (foreignMatch != null) {
return new MatchedImportedEmbedded(prop, assocOne1, foreignMatch);
}
}
}
BeanProperty[] scalar = desc.propertiesBaseScalar();
for (BeanProperty beanProperty : scalar) {
if (dbColumn.equals(beanProperty.getDbColumn())) {
return new MatchedImportedScalar(prop, beanProperty);
}
}
return null;
}
}