org.ibatis.persist.impl.path.RootImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbatis Show documentation
Show all versions of jbatis Show documentation
The jBATIS persistence framework will help you to significantly reduce the amount of Java code that you normally need to access a relational database. iBATIS simply maps JavaBeans to SQL statements using a very simple XML descriptor.
The newest version!
package org.ibatis.persist.impl.path;
import org.ibatis.persist.criteria.Path;
import org.ibatis.persist.criteria.Root;
import org.ibatis.persist.impl.CriteriaBuilderImpl;
import org.ibatis.persist.impl.PathSource;
import org.ibatis.persist.impl.QueryStructure;
import org.ibatis.persist.impl.RenderingContext;
import org.ibatis.persist.impl.util.GetterInterceptor;
import org.ibatis.persist.meta.Attribute;
import org.ibatis.persist.meta.EntityType;
@SuppressWarnings("unchecked")
public class RootImpl extends AbstractFromImpl implements Root, PathSource {
private final EntityType entityType;
String alias;
public RootImpl(CriteriaBuilderImpl criteriaBuilder, EntityType entityType, QueryStructure queryStructure) {
super( criteriaBuilder, queryStructure);
this.entityType = entityType;
}
public EntityType getEntityType() {
return entityType;
}
public EntityType getModel() {
return getEntityType();
}
@Override
protected RuntimeException illegalJoin() {
return new IllegalArgumentException( "UPDATE/DELETE criteria queries cannot define joins" );
}
public void renderFrom(RenderingContext rc) {
if (getAlias() != null) {
rc.append(getModel().getTableName()).append(" as ").append(getAlias());
} else {
rc.append(getModel().getTableName());
}
}
@Override
public String getPathAlias() {
return getAlias();
}
X $ = null;
@Override
public synchronized X $() {
if ($ == null) {
$ = GetterInterceptor.create(getEntityType().getJavaType());
}
return $;
}
@Override
public Path get(Y attribute) {
String attributeName = GetterInterceptor.take();
return getAttr(attributeName);
}
public Path getAttr(String attributeName) {
Attribute attr = getModel().locateAttribute(attributeName);
Path path = new AttributePathImpl(criteriaBuilder(), attr.getType(), this, (Attribute) attr);
return path;
}
@Override
public String getAlias() {
return alias;
}
@Override
public Root alias(String name) {
alias = name;
return this;
}
@Override
public void prepareAlias(RenderingContext rc) {
if ( getAlias() == null ) {
alias( rc.generateAlias() );
}
}
@Override
public String toString() {
return "[" + entityType.getName() + (getAlias() != null ? " as " + getAlias() : "") + "]";
}
}