本文整理汇总了Java中org.hibernate.type.EntityType.getAssociatedEntityName方法的典型用法代码示例。如果您正苦于以下问题:Java EntityType.getAssociatedEntityName方法的具体用法?Java EntityType.getAssociatedEntityName怎么用?Java EntityType.getAssociatedEntityName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.type.EntityType
的用法示例。
在下文中一共展示了EntityType.getAssociatedEntityName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHibernateType
import org.hibernate.type.EntityType; //导入方法依赖的package包/类
/**
* 取自锐道hibernateUtil类 获取类型 包含关联的
*
* @param property
* @param classMetadata
* @param sessionFactory
* @return Type
*/
private Type getHibernateType(String property, ClassMetadata classMetadata, SessionFactory sessionFactory) {
String[] tokens = StringUtils.split(property, '.');
if (tokens.length == 1)
return classMetadata.getPropertyType(property);
if (tokens.length > 1) {
Type type = null;
ClassMetadata meta = classMetadata;
for (String token : tokens) {
type = meta.getPropertyType(token);
if ((type instanceof EntityType)) {
EntityType entityType = (EntityType) type;
String entityName = entityType.getAssociatedEntityName();
meta = sessionFactory.getClassMetadata(entityName);
}
}
return type;
}
return null;
}
示例2: processJoinReturn
import org.hibernate.type.EntityType; //导入方法依赖的package包/类
private void processJoinReturn(NativeSQLQueryJoinReturn fetchReturn) {
String alias = fetchReturn.getAlias();
// if ( alias2Persister.containsKey( alias ) || collectionAliases.contains( alias ) ) {
if ( alias2Persister.containsKey( alias ) || alias2CollectionPersister.containsKey( alias ) ) {
// already been processed...
return;
}
String ownerAlias = fetchReturn.getOwnerAlias();
// Make sure the owner alias is known...
if ( !alias2Return.containsKey( ownerAlias ) ) {
throw new HibernateException( "Owner alias [" + ownerAlias + "] is unknown for alias [" + alias + "]" );
}
// If this return's alias has not been processed yet, do so b4 further processing of this return
if ( !alias2Persister.containsKey( ownerAlias ) ) {
NativeSQLQueryNonScalarReturn ownerReturn = ( NativeSQLQueryNonScalarReturn ) alias2Return.get(ownerAlias);
processReturn( ownerReturn );
}
SQLLoadable ownerPersister = ( SQLLoadable ) alias2Persister.get( ownerAlias );
Type returnType = ownerPersister.getPropertyType( fetchReturn.getOwnerProperty() );
if ( returnType.isCollectionType() ) {
String role = ownerPersister.getEntityName() + '.' + fetchReturn.getOwnerProperty();
addCollection( role, alias, fetchReturn.getPropertyResultsMap() );
// collectionOwnerAliases.add( ownerAlias );
}
else if ( returnType.isEntityType() ) {
EntityType eType = ( EntityType ) returnType;
String returnEntityName = eType.getAssociatedEntityName();
SQLLoadable persister = getSQLLoadable( returnEntityName );
addPersister( alias, fetchReturn.getPropertyResultsMap(), persister );
}
}
示例3: nullifyTransientReferences
import org.hibernate.type.EntityType; //导入方法依赖的package包/类
/**
* Return null if the argument is an "unsaved" entity (ie. one with no existing database row), or the
* input argument otherwise. This is how Hibernate avoids foreign key constraint violations.
*
* @param value An entity attribute value
* @param type An entity attribute type
*
* @return {@code null} if the argument is an unsaved entity; otherwise return the argument.
*/
private Object nullifyTransientReferences(final Object value, final Type type) {
if ( value == null ) {
return null;
}
else if ( type.isEntityType() ) {
final EntityType entityType = (EntityType) type;
if ( entityType.isOneToOne() ) {
return value;
}
else {
final String entityName = entityType.getAssociatedEntityName();
return isNullifiable( entityName, value ) ? null : value;
}
}
else if ( type.isAnyType() ) {
return isNullifiable( null, value ) ? null : value;
}
else if ( type.isComponentType() ) {
final CompositeType actype = (CompositeType) type;
final Object[] subvalues = actype.getPropertyValues( value, session );
final Type[] subtypes = actype.getSubtypes();
boolean substitute = false;
for ( int i = 0; i < subvalues.length; i++ ) {
final Object replacement = nullifyTransientReferences( subvalues[i], subtypes[i] );
if ( replacement != subvalues[i] ) {
substitute = true;
subvalues[i] = replacement;
}
}
if ( substitute ) {
// todo : need to account for entity mode on the CompositeType interface :(
actype.setPropertyValues( value, subvalues, EntityMode.POJO );
}
return value;
}
else {
return value;
}
}
示例4: nullifyTransientReferences
import org.hibernate.type.EntityType; //导入方法依赖的package包/类
/**
* Return null if the argument is an "unsaved" entity (ie.
* one with no existing database row), or the input argument
* otherwise. This is how Hibernate avoids foreign key constraint
* violations.
*/
private Object nullifyTransientReferences(final Object value, final Type type)
throws HibernateException {
if ( value == null ) {
return null;
}
else if ( type.isEntityType() ) {
EntityType entityType = (EntityType) type;
if ( entityType.isOneToOne() ) {
return value;
}
else {
String entityName = entityType.getAssociatedEntityName();
return isNullifiable(entityName, value) ? null : value;
}
}
else if ( type.isAnyType() ) {
return isNullifiable(null, value) ? null : value;
}
else if ( type.isComponentType() ) {
AbstractComponentType actype = (AbstractComponentType) type;
Object[] subvalues = actype.getPropertyValues(value, session);
Type[] subtypes = actype.getSubtypes();
boolean substitute = false;
for ( int i = 0; i < subvalues.length; i++ ) {
Object replacement = nullifyTransientReferences( subvalues[i], subtypes[i] );
if ( replacement != subvalues[i] ) {
substitute = true;
subvalues[i] = replacement;
}
}
if (substitute) actype.setPropertyValues( value, subvalues, session.getEntityMode() );
return value;
}
else {
return value;
}
}
示例5: dereferenceEntity
import org.hibernate.type.EntityType; //导入方法依赖的package包/类
private void dereferenceEntity(String propertyName, EntityType propertyType, QueryTranslatorImpl q)
throws QueryException {
//NOTE: we avoid joining to the next table if the named property is just the foreign key value
//if its "id"
boolean isIdShortcut = EntityPersister.ENTITY_ID.equals( propertyName ) &&
propertyType.isReferenceToPrimaryKey();
//or its the id property name
final String idPropertyName;
try {
idPropertyName = propertyType.getIdentifierOrUniqueKeyPropertyName( q.getFactory() );
}
catch ( MappingException me ) {
throw new QueryException( me );
}
boolean isNamedIdPropertyShortcut = idPropertyName != null
&& idPropertyName.equals( propertyName )
&& propertyType.isReferenceToPrimaryKey();
if ( isIdShortcut || isNamedIdPropertyShortcut ) {
// special shortcut for id properties, skip the join!
// this must only occur at the _end_ of a path expression
if ( componentPath.length() > 0 ) componentPath.append( '.' );
componentPath.append( propertyName );
}
else {
String entityClass = propertyType.getAssociatedEntityName();
String name = q.createNameFor( entityClass );
q.addType( name, entityClass );
addJoin( name, propertyType );
if ( propertyType.isOneToOne() ) oneToOneOwnerName = currentName;
ownerAssociationType = propertyType;
currentName = name;
currentProperty = propertyName;
q.addPathAliasAndJoin( path.substring( 0, path.toString().lastIndexOf( '.' ) ), name, joinSequence.copy() );
componentPath.setLength( 0 );
currentPropertyMapping = q.getEntityPersister( entityClass );
}
}
示例6: dereferenceEntity
import org.hibernate.type.EntityType; //导入方法依赖的package包/类
private void dereferenceEntity(String propertyName, EntityType propertyType, QueryTranslatorImpl q)
throws QueryException {
//NOTE: we avoid joining to the next table if the named property is just the foreign key value
//if its "id"
boolean isIdShortcut = EntityPersister.ENTITY_ID.equals( propertyName ) &&
propertyType.isReferenceToPrimaryKey();
//or its the id property name
final String idPropertyName;
try {
idPropertyName = propertyType.getIdentifierOrUniqueKeyPropertyName( q.getFactory() );
}
catch ( MappingException me ) {
throw new QueryException( me );
}
boolean isNamedIdPropertyShortcut = idPropertyName != null
&& idPropertyName.equals( propertyName )
&& propertyType.isReferenceToPrimaryKey();
if ( isIdShortcut || isNamedIdPropertyShortcut ) {
// special shortcut for id properties, skip the join!
// this must only occur at the _end_ of a path expression
if ( componentPath.length() > 0 ) componentPath.append( '.' );
componentPath.append( propertyName );
}
else {
String entityClass = propertyType.getAssociatedEntityName();
String name = q.createNameFor( entityClass );
q.addType( name, entityClass );
addJoin( name, propertyType );
if ( propertyType.isOneToOne() ) oneToOneOwnerName = currentName;
ownerAssociationType = propertyType;
currentName = name;
currentProperty = propertyName;
q.addPathAliasAndJoin( path.substring( 0, path.toString().lastIndexOf( '.' ) ), name, joinSequence.copy() );
componentPath.setLength( 0 );
currentPropertyMapping = q.getEntityPersister( entityClass );
}
}
示例7: dereferenceEntityJoin
import org.hibernate.type.EntityType; //导入方法依赖的package包/类
private void dereferenceEntityJoin(String classAlias, EntityType propertyType, boolean impliedJoin, AST parent)
throws SemanticException {
dereferenceType = DEREF_ENTITY;
if ( log.isDebugEnabled() ) {
log.debug( "dereferenceEntityJoin() : generating join for " + propertyName + " in "
+ getFromElement().getClassName() + " "
+ ( ( classAlias == null ) ? "{no alias}" : "(" + classAlias + ")" )
+ " parent = " + ASTUtil.getDebugString( parent )
);
}
// Create a new FROM node for the referenced class.
String associatedEntityName = propertyType.getAssociatedEntityName();
String tableAlias = getAliasGenerator().createName( associatedEntityName );
String[] joinColumns = getColumns();
String joinPath = getPath();
if ( impliedJoin && getWalker().isInFrom() ) {
joinType = getWalker().getImpliedJoinType();
}
FromClause currentFromClause = getWalker().getCurrentFromClause();
FromElement elem = currentFromClause.findJoinByPath( joinPath );
///////////////////////////////////////////////////////////////////////////////
//
// This is the piece which recognizes the condition where an implicit join path
// resolved earlier in a correlated subquery is now being referenced in the
// outer query. For 3.0final, we just let this generate a second join (which
// is exactly how the old parser handles this). Eventually we need to add this
// logic back in and complete the logic in FromClause.promoteJoin; however,
// FromClause.promoteJoin has its own difficulties (see the comments in
// FromClause.promoteJoin).
//
// if ( elem == null ) {
// // see if this joinPath has been used in a "child" FromClause, and if so
// // promote that element to the outer query
// FromClause currentNodeOwner = getFromElement().getFromClause();
// FromClause currentJoinOwner = currentNodeOwner.locateChildFromClauseWithJoinByPath( joinPath );
// if ( currentJoinOwner != null && currentNodeOwner != currentJoinOwner ) {
// elem = currentJoinOwner.findJoinByPathLocal( joinPath );
// if ( elem != null ) {
// currentFromClause.promoteJoin( elem );
// // EARLY EXIT!!!
// return;
// }
// }
// }
//
///////////////////////////////////////////////////////////////////////////////
if ( elem == null ) {
// If this is an implied join in a from element, then use the impled join type which is part of the
// tree parser's state (set by the gramamar actions).
JoinSequence joinSequence = getSessionFactoryHelper()
.createJoinSequence( impliedJoin, propertyType, tableAlias, joinType, joinColumns );
FromElementFactory factory = new FromElementFactory(
currentFromClause,
getLhs().getFromElement(),
joinPath,
classAlias,
joinColumns,
impliedJoin
);
elem = factory.createEntityJoin(
associatedEntityName,
tableAlias,
joinSequence,
fetch,
getWalker().isInFrom(),
propertyType
);
}
else {
currentFromClause.addDuplicateAlias(classAlias, elem);
}
setImpliedJoin( elem );
getWalker().addQuerySpaces( elem.getEntityPersister().getQuerySpaces() );
setFromElement( elem ); // This 'dot' expression now refers to the resulting from element.
}