下面列出了怎么用org.hibernate.persister.entity.UnionSubclassEntityPersister的API类实例代码及写法,或者点击链接到github查看源代码。
public static EntityPersister createClassPersister(
PersistentClass model,
CacheConcurrencyStrategy cache,
SessionFactoryImplementor factory,
Mapping cfg)
throws HibernateException {
Class persisterClass = model.getEntityPersisterClass();
if (persisterClass==null || persisterClass==SingleTableEntityPersister.class) {
return new SingleTableEntityPersister(model, cache, factory, cfg);
}
else if (persisterClass==JoinedSubclassEntityPersister.class) {
return new JoinedSubclassEntityPersister(model, cache, factory, cfg);
}
else if (persisterClass==UnionSubclassEntityPersister.class) {
return new UnionSubclassEntityPersister(model, cache, factory, cfg);
}
else {
return create(persisterClass, model, cache, factory, cfg);
}
}
public void bindUnionSubclass(HibernatePersistentEntity subClass, UnionSubclass unionSubclass,
InFlightMetadataCollector mappings, String sessionFactoryBeanName) throws MappingException {
bindClass(subClass, unionSubclass, mappings);
Mapping subMapping = getMapping(subClass.getJavaClass());
if ( unionSubclass.getEntityPersisterClass() == null ) {
unionSubclass.getRootClass().setEntityPersisterClass(
UnionSubclassEntityPersister.class );
}
String schema = subMapping != null && subMapping.getTable().getSchema() != null ?
subMapping.getTable().getSchema() : null;
String catalog = subMapping != null && subMapping.getTable().getCatalog() != null ?
subMapping.getTable().getCatalog() : null;
Table denormalizedSuperTable = unionSubclass.getSuperclass().getTable();
Table mytable = mappings.addDenormalizedTable(
schema,
catalog,
getTableName(subClass, sessionFactoryBeanName),
unionSubclass.isAbstract() != null && unionSubclass.isAbstract(),
null,
denormalizedSuperTable
);
unionSubclass.setTable( mytable );
unionSubclass.setClassName(subClass.getName());
LOG.info(
"Mapping union-subclass: " + unionSubclass.getEntityName() +
" -> " + unionSubclass.getTable().getName()
);
createClassProperties(subClass, unionSubclass, mappings, sessionFactoryBeanName);
}
public static void bindUnionSubclass(Element node, UnionSubclass unionSubclass,
Mappings mappings, java.util.Map inheritedMetas) throws MappingException {
bindClass( node, unionSubclass, mappings, inheritedMetas );
inheritedMetas = getMetas( node, inheritedMetas, true ); // get meta's from <subclass>
if ( unionSubclass.getEntityPersisterClass() == null ) {
unionSubclass.getRootClass().setEntityPersisterClass(
UnionSubclassEntityPersister.class );
}
Attribute schemaNode = node.attribute( "schema" );
String schema = schemaNode == null ?
mappings.getSchemaName() : schemaNode.getValue();
Attribute catalogNode = node.attribute( "catalog" );
String catalog = catalogNode == null ?
mappings.getCatalogName() : catalogNode.getValue();
Table denormalizedSuperTable = unionSubclass.getSuperclass().getTable();
Table mytable = mappings.addDenormalizedTable(
schema,
catalog,
getClassTableName(unionSubclass, node, schema, catalog, denormalizedSuperTable, mappings ),
unionSubclass.isAbstract() != null && unionSubclass.isAbstract().booleanValue(),
getSubselect( node ),
denormalizedSuperTable
);
unionSubclass.setTable( mytable );
log.info(
"Mapping union-subclass: " + unionSubclass.getEntityName() +
" -> " + unionSubclass.getTable().getName()
);
createClassProperties( node, unionSubclass, mappings, inheritedMetas );
}
public Class<? extends EntityPersister> unionSubclassEntityPersister() {
return UnionSubclassEntityPersister.class;
}
public AssignmentSpecification(AST eq, Queryable persister) {
if ( eq.getType() != HqlSqlTokenTypes.EQ ) {
throw new QueryException( "assignment in set-clause not associated with equals" );
}
this.eq = eq;
this.factory = persister.getFactory();
// Needed to bump this up to DotNode, because that is the only thing which currently
// knows about the property-ref path in the correct format; it is either this, or
// recurse over the DotNodes constructing the property path just like DotNode does
// internally
final DotNode lhs = (DotNode) eq.getFirstChild();
final SqlNode rhs = (SqlNode) lhs.getNextSibling();
validateLhs( lhs );
final String propertyPath = lhs.getPropertyPath();
Set<String> temp = new HashSet<String>();
// yuck!
if ( persister instanceof UnionSubclassEntityPersister ) {
final String[] tables = persister.getConstraintOrderedTableNameClosure();
Collections.addAll( temp, tables );
}
else {
temp.add(
persister.getSubclassTableName( persister.getSubclassPropertyTableNumber( propertyPath ) )
);
}
this.tableNames = Collections.unmodifiableSet( temp );
if ( rhs == null ) {
hqlParameters = new ParameterSpecification[0];
}
else if ( isParam( rhs ) ) {
hqlParameters = new ParameterSpecification[] {( (ParameterNode) rhs ).getHqlParameterSpecification()};
}
else {
List parameterList = ASTUtil.collectChildren(
rhs,
new ASTUtil.IncludePredicate() {
public boolean include(AST node) {
return isParam( node );
}
}
);
hqlParameters = new ParameterSpecification[parameterList.size()];
Iterator itr = parameterList.iterator();
int i = 0;
while ( itr.hasNext() ) {
hqlParameters[i++] = ( (ParameterNode) itr.next() ).getHqlParameterSpecification();
}
}
}