package io.ebeaninternal.server.deploy.meta;
import io.ebeaninternal.server.query.SqlJoinType;
import javax.persistence.CascadeType;
public class DeployBeanPropertyAssocOne<T> extends DeployBeanPropertyAssoc<T> {
private boolean oneToOne;
private boolean oneToOneExported;
private boolean primaryKeyJoin;
private boolean primaryKeyExport;
private DeployBeanEmbedded deployEmbedded;
private String columnPrefix;
public DeployBeanPropertyAssocOne(DeployBeanDescriptor<?> desc, Class<T> targetType) {
super(desc, targetType);
}
public DeployBeanEmbedded getDeployEmbedded() {
if (deployEmbedded == null) {
deployEmbedded = new DeployBeanEmbedded();
}
return deployEmbedded;
}
public boolean isCompound() {
return getDeployEmbedded().getPropertyColumnMap().size() > 1;
}
@Override
public String getDbColumn() {
DeployTableJoinColumn[] columns = tableJoin.columns();
if (columns.length == 1) {
return columns[0].getLocalDbColumn();
}
return super.getDbColumn();
}
public boolean isOneToOne() {
return oneToOne;
}
public void setOneToOne() {
this.oneToOne = true;
}
public boolean isOneToOneExported() {
return oneToOneExported;
}
public void setOneToOneExported() {
this.oneToOneExported = true;
}
@Override
public void setImportedPrimaryKeyColumn(DeployBeanProperty primaryKey) {
this.importedPrimaryKey = true;
String dbColumn = primaryKey.getDbColumn();
if (dbColumn != null) {
tableJoin.setLocalColumn(dbColumn);
}
}
@Override
public void setSqlFormula(String formulaSelect, String formulaJoin) {
super.setSqlFormula(formulaSelect, formulaJoin);
DeployTableJoinColumn[] columns = tableJoin.columns();
if (columns.length == 1) {
columns[0].setLocalSqlFormula(formulaSelect);
}
}
public void setColumnPrefix(String columnPrefix) {
this.columnPrefix = columnPrefix;
}
public String getColumnPrefix() {
return columnPrefix;
}
public void setPrimaryKeyJoin(boolean primaryKeyJoin) {
this.primaryKeyJoin = primaryKeyJoin;
}
public boolean isPrimaryKeyJoin() {
return primaryKeyJoin;
}
public boolean isPrimaryKeyExport() {
return primaryKeyExport;
}
public void setPrimaryKeyExport() {
this.primaryKeyExport = true;
this.oneToOneExported = true;
if (!cascadeInfo.isSave()) {
cascadeInfo.setType(CascadeType.ALL);
}
}
public void setJoinType(boolean outerJoin) {
tableJoin.setType(outerJoin ? SqlJoinType.OUTER : SqlJoinType.INNER);
}
public void setJoinColumns(DeployTableJoinColumn[] columns, boolean reverse) {
tableJoin.setColumns(columns, reverse);
}
}