package io.ebeaninternal.server.deploy;
import io.ebean.bean.EntityBean;
import io.ebean.bean.PersistenceContext;
import io.ebean.core.type.DataReader;
import io.ebeaninternal.server.query.SqlJoinType;
import java.sql.SQLException;
abstract class AssocOneHelp {
final BeanPropertyAssocOne<?> property;
private final BeanDescriptor<?> target;
private final String path;
AssocOneHelp(BeanPropertyAssocOne<?> property) {
this(property, null);
}
AssocOneHelp(BeanPropertyAssocOne<?> property, String embeddedPrefix) {
this.property = property;
this.target = property.targetDescriptor;
this.path = (embeddedPrefix == null) ? property.name : embeddedPrefix + "." + property.name;
}
void loadIgnore(DbReadContext ctx) {
property.targetIdBinder.loadIgnore(ctx);
}
Object read(DataReader reader) throws SQLException {
return property.read(reader);
}
Object readSet(DataReader reader, EntityBean bean) throws SQLException {
Object val = read(reader);
if (bean != null) {
property.setValue(bean, val);
}
return val;
}
Object read(DbReadContext ctx) throws SQLException {
Object id = property.targetIdBinder.read(ctx);
if (id == null) {
return null;
}
PersistenceContext pc = ctx.getPersistenceContext();
Object existing = target.contextGet(pc, id);
if (existing != null) {
return existing;
}
boolean disableLazyLoading = ctx.isDisableLazyLoading();
Object ref = target.contextRef(pc, ctx.isReadOnly(), disableLazyLoading, id);
if (!disableLazyLoading) {
ctx.register(path, ((EntityBean) ref)._ebean_getIntercept());
}
return ref;
}
Object readSet(DbReadContext ctx, EntityBean bean) throws SQLException {
Object val = read(ctx);
if (bean != null) {
property.setValue(bean, val);
ctx.propagateState(val);
}
return val;
}
abstract void appendSelect(DbSqlContext ctx, boolean subQuery);
void appendFrom(DbSqlContext ctx, SqlJoinType joinType) {
}
}