Java 类org.hibernate.type.EntityType 实例源码
项目:lams
文件:EntityJoinWalker.java
private void findKeyManyToOneTargetIndices(
ArrayList<Integer> keyManyToOneTargetIndices,
OuterJoinableAssociation joinWithCompositeId,
CompositeType componentType) {
for ( Type subType : componentType.getSubtypes() ) {
if ( subType.isEntityType() ) {
Integer index = locateKeyManyToOneTargetIndex( joinWithCompositeId, (EntityType) subType );
if ( index != null ) {
keyManyToOneTargetIndices.add( index );
}
}
else if ( subType.isComponentType() ) {
findKeyManyToOneTargetIndices(
keyManyToOneTargetIndices,
joinWithCompositeId,
(CompositeType) subType
);
}
}
}
项目:lams
文件:EntityJoinWalker.java
private Integer locateKeyManyToOneTargetIndex(OuterJoinableAssociation joinWithCompositeId, EntityType keyManyToOneType) {
// the lhs (if one) is a likely candidate
if ( joinWithCompositeId.getLhsAlias() != null ) {
final OuterJoinableAssociation lhs = associationsByAlias.get( joinWithCompositeId.getLhsAlias() );
if ( keyManyToOneType.getAssociatedEntityName( factory ).equals( lhs.getJoinableType().getAssociatedEntityName( factory ) ) ) {
return positionsByAlias.get( lhs.getRhsAlias() );
}
}
// otherwise, seek out OuterJoinableAssociation which are RHS of given OuterJoinableAssociation
// (joinWithCompositeId)
for ( OuterJoinableAssociation oja : associationsByAlias.values() ) {
if ( oja.getLhsAlias() != null && oja.getLhsAlias().equals( joinWithCompositeId.getRhsAlias() ) ) {
if ( keyManyToOneType.equals( oja.getJoinableType() ) ) {
return positionsByAlias.get( oja.getLhsAlias() );
}
}
}
return null;
}
项目:lams
文件:JoinWalker.java
/**
* Does the mapping, and Hibernate default semantics, specify that
* this association should be fetched by outer joining
*/
protected boolean isJoinedFetchEnabledInMapping(FetchMode config, AssociationType type)
throws MappingException {
if ( !type.isEntityType() && !type.isCollectionType() ) {
return false;
}
else {
if (config==FetchMode.JOIN) return true;
if (config==FetchMode.SELECT) return false;
if ( type.isEntityType() ) {
//TODO: look at the owning property and check that it
// isn't lazy (by instrumentation)
EntityType entityType =(EntityType) type;
EntityPersister persister = getFactory().getEntityPersister( entityType.getAssociatedEntityName() );
return !persister.hasProxy();
}
else {
return false;
}
}
}
项目:lams
文件:ResultSetProcessingContextImpl.java
private void registerNonExists(EntityFetch fetch) {
final EntityType fetchedType = fetch.getFetchedType();
if ( ! fetchedType.isOneToOne() ) {
return;
}
final EntityReferenceProcessingState fetchOwnerState = getOwnerProcessingState( fetch );
if ( fetchOwnerState == null ) {
throw new IllegalStateException( "Could not locate fetch owner state" );
}
final EntityKey ownerEntityKey = fetchOwnerState.getEntityKey();
if ( ownerEntityKey == null ) {
throw new IllegalStateException( "Could not locate fetch owner EntityKey" );
}
session.getPersistenceContext().addNullProperty(
ownerEntityKey,
fetchedType.getPropertyName()
);
}
项目:lams
文件:EntityReferenceInitializerImpl.java
private void handleMissingIdentifier(ResultSetProcessingContext context) {
if ( EntityFetch.class.isInstance( entityReference ) ) {
final EntityFetch fetch = (EntityFetch) entityReference;
final EntityType fetchedType = fetch.getFetchedType();
if ( ! fetchedType.isOneToOne() ) {
return;
}
final EntityReferenceProcessingState fetchOwnerState = context.getOwnerProcessingState( fetch );
if ( fetchOwnerState == null ) {
throw new IllegalStateException( "Could not locate fetch owner state" );
}
final EntityKey ownerEntityKey = fetchOwnerState.getEntityKey();
if ( ownerEntityKey != null ) {
context.getSession().getPersistenceContext().addNullProperty(
ownerEntityKey,
fetchedType.getPropertyName()
);
}
}
}
项目:lams
文件:AliasResolutionContextImpl.java
private EntityReferenceAliases createCollectionElementAliases(
CollectionPersister collectionPersister,
String tableAlias,
String elementQuerySpaceUid) {
if ( !collectionPersister.getElementType().isEntityType() ) {
return null;
}
else {
final EntityType entityElementType = (EntityType) collectionPersister.getElementType();
return generateEntityReferenceAliases(
elementQuerySpaceUid,
tableAlias,
(EntityPersister) entityElementType.getAssociatedJoinable( sessionFactory() )
);
}
}
项目:lams
文件:JoinHelper.java
public JoinDefinedByMetadata createEntityJoin(
QuerySpace leftHandSide,
String lhsPropertyName,
EntityQuerySpace rightHandSide,
boolean rightHandSideRequired,
EntityType joinedPropertyType,
SessionFactoryImplementor sessionFactory) {
return new JoinImpl(
leftHandSide,
lhsPropertyName,
rightHandSide,
determineRhsColumnNames( joinedPropertyType, sessionFactory ),
joinedPropertyType,
rightHandSideRequired
);
}
项目:lams
文件:AbstractExpandingFetchSource.java
@Override
public BidirectionalEntityReference buildBidirectionalEntityReference(
AssociationAttributeDefinition attributeDefinition,
FetchStrategy fetchStrategy,
EntityReference targetEntityReference) {
final EntityType fetchedType = (EntityType) attributeDefinition.getType();
final EntityPersister fetchedPersister = attributeDefinition.toEntityDefinition().getEntityPersister();
if ( fetchedPersister == null ) {
throw new WalkingException(
String.format(
"Unable to locate EntityPersister [%s] for bidirectional entity reference [%s]",
fetchedType.getAssociatedEntityName(),
attributeDefinition.getName()
)
);
}
final BidirectionalEntityReference bidirectionalEntityReference =
new BidirectionalEntityReferenceImpl( this, attributeDefinition, targetEntityReference );
addBidirectionalEntityReference( bidirectionalEntityReference );
return bidirectionalEntityReference;
}
项目:lams
文件:AbstractEntityPersister.java
private EntityLoader createUniqueKeyLoader(
Type uniqueKeyType,
String[] columns,
LoadQueryInfluencers loadQueryInfluencers) {
if ( uniqueKeyType.isEntityType() ) {
String className = ( ( EntityType ) uniqueKeyType ).getAssociatedEntityName();
uniqueKeyType = getFactory().getEntityPersister( className ).getIdentifierType();
}
return new EntityLoader(
this,
columns,
uniqueKeyType,
1,
LockMode.NONE,
getFactory(),
loadQueryInfluencers
);
}
项目:lams
文件:AbstractPropertyMapping.java
protected void initIdentifierPropertyPaths(
final String path,
final EntityType etype,
final String[] columns,
final String[] columnReaders,
final String[] columnReaderTemplates,
final Mapping factory) throws MappingException {
Type idtype = etype.getIdentifierOrUniqueKeyType( factory );
String idPropName = etype.getIdentifierOrUniqueKeyPropertyName(factory);
boolean hasNonIdentifierPropertyNamedId = hasNonIdentifierPropertyNamedId( etype, factory );
if ( etype.isReferenceToPrimaryKey() ) {
if ( !hasNonIdentifierPropertyNamedId ) {
String idpath1 = extendPath(path, EntityPersister.ENTITY_ID);
addPropertyPath(idpath1, idtype, columns, columnReaders, columnReaderTemplates, null);
initPropertyPaths(idpath1, idtype, columns, columnReaders, columnReaderTemplates, null, factory);
}
}
if (idPropName!=null) {
String idpath2 = extendPath(path, idPropName);
addPropertyPath(idpath2, idtype, columns, columnReaders, columnReaderTemplates, null);
initPropertyPaths(idpath2, idtype, columns, columnReaders, columnReaderTemplates, null, factory);
}
}
项目:lams
文件:Cascade.java
/**
* Cascade an action to a to-one association or any type
*/
private void cascadeToOne(
final Object parent,
final Object child,
final Type type,
final CascadeStyle style,
final Object anything,
final boolean isCascadeDeleteEnabled) {
final String entityName = type.isEntityType()
? ( (EntityType) type ).getAssociatedEntityName()
: null;
if ( style.reallyDoCascade( action ) ) {
//not really necessary, but good for consistency...
eventSource.getPersistenceContext().addChildParent( child, parent );
try {
action.cascade( eventSource, child, entityName, anything, isCascadeDeleteEnabled );
}
finally {
eventSource.getPersistenceContext().removeChildParent( child );
}
}
}
项目:lams
文件:IteratorImpl.java
public void remove() {
if (!single) {
throw new UnsupportedOperationException("Not a single column hibernate query result set");
}
if (currentResult==null) {
throw new IllegalStateException("Called Iterator.remove() before next()");
}
if ( !( types[0] instanceof EntityType ) ) {
throw new UnsupportedOperationException("Not an entity");
}
session.delete(
( (EntityType) types[0] ).getAssociatedEntityName(),
currentResult,
false,
null
);
}
项目:lams
文件:AbstractVisitor.java
/**
* Visit a property value. Dispatch to the
* correct handler for the property type.
* @param value
* @param type
* @throws HibernateException
*/
final Object processValue(Object value, Type type) throws HibernateException {
if ( type.isCollectionType() ) {
//even process null collections
return processCollection( value, (CollectionType) type );
}
else if ( type.isEntityType() ) {
return processEntity( value, (EntityType) type );
}
else if ( type.isComponentType() ) {
return processComponent( value, (CompositeType) type );
}
else {
return null;
}
}
项目:lams
文件:DotNode.java
/**
* Is the given property name a reference to the primary key of the associated
* entity construed by the given entity type?
* <p/>
* For example, consider a fragment like order.customer.id
* (where order is a from-element alias). Here, we'd have:
* propertyName = "id" AND
* owningType = ManyToOneType(Customer)
* and are being asked to determine whether "customer.id" is a reference
* to customer's PK...
*
* @param propertyName The name of the property to check.
* @param owningType The type represeting the entity "owning" the property
*
* @return True if propertyName references the entity's (owningType->associatedEntity)
* primary key; false otherwise.
*/
private boolean isReferenceToPrimaryKey(String propertyName, EntityType owningType) {
EntityPersister persister = getSessionFactoryHelper()
.getFactory()
.getEntityPersister( owningType.getAssociatedEntityName() );
if ( persister.getEntityMetamodel().hasNonIdentifierPropertyNamedId() ) {
// only the identifier property field name can be a reference to the associated entity's PK...
return propertyName.equals( persister.getIdentifierPropertyName() ) && owningType.isReferenceToPrimaryKey();
}
// here, we have two possibilities:
// 1) the property-name matches the explicitly identifier property name
// 2) the property-name matches the implicit 'id' property name
// the referenced node text is the special 'id'
if ( EntityPersister.ENTITY_ID.equals( propertyName ) ) {
return owningType.isReferenceToPrimaryKey();
}
String keyPropertyName = getSessionFactoryHelper().getIdentifierOrUniqueKeyPropertyName( owningType );
return keyPropertyName != null && keyPropertyName.equals( propertyName ) && owningType.isReferenceToPrimaryKey();
}
项目:lams
文件:FromElementFactory.java
FromElement addFromElement() throws SemanticException {
final FromClause parentFromClause = fromClause.getParentFromClause();
if ( parentFromClause != null ) {
// Look up class name using the first identifier in the path.
final String pathAlias = PathHelper.getAlias( path );
final FromElement parentFromElement = parentFromClause.getFromElement( pathAlias );
if ( parentFromElement != null ) {
return createFromElementInSubselect( path, pathAlias, parentFromElement, classAlias );
}
}
final EntityPersister entityPersister = fromClause.getSessionFactoryHelper().requireClassPersister( path );
final FromElement elem = createAndAddFromElement(
path,
classAlias,
entityPersister,
(EntityType) ( (Queryable) entityPersister ).getType(),
null
);
// Add to the query spaces.
fromClause.getWalker().addQuerySpaces( entityPersister.getQuerySpaces() );
return elem;
}
项目:lams
文件:FromElementFactory.java
private FromElement createJoin(
String entityClass,
String tableAlias,
JoinSequence joinSequence,
EntityType type,
boolean manyToMany) throws SemanticException {
// origin, path, implied, columns, classAlias,
EntityPersister entityPersister = fromClause.getSessionFactoryHelper().requireClassPersister( entityClass );
FromElement destination = createAndAddFromElement(
entityClass,
classAlias,
entityPersister,
type,
tableAlias
);
return initializeJoin( path, destination, joinSequence, getColumns(), origin, manyToMany );
}
项目:lams
文件:MapEntryNode.java
private void determineKeySelectExpressions(QueryableCollection collectionPersister, List selections) {
AliasGenerator aliasGenerator = new LocalAliasGenerator( 0 );
appendSelectExpressions( collectionPersister.getIndexColumnNames(), selections, aliasGenerator );
Type keyType = collectionPersister.getIndexType();
if ( keyType.isAssociationType() ) {
EntityType entityType = (EntityType) keyType;
Queryable keyEntityPersister = (Queryable) sfi().getEntityPersister(
entityType.getAssociatedEntityName( sfi() )
);
SelectFragment fragment = keyEntityPersister.propertySelectFragmentFragment(
collectionTableAlias(),
null,
false
);
appendSelectExpressions( fragment, selections, aliasGenerator );
}
}
项目:lams
文件:MapEntryNode.java
private void determineValueSelectExpressions(QueryableCollection collectionPersister, List selections) {
AliasGenerator aliasGenerator = new LocalAliasGenerator( 1 );
appendSelectExpressions( collectionPersister.getElementColumnNames(), selections, aliasGenerator );
Type valueType = collectionPersister.getElementType();
if ( valueType.isAssociationType() ) {
EntityType valueEntityType = (EntityType) valueType;
Queryable valueEntityPersister = (Queryable) sfi().getEntityPersister(
valueEntityType.getAssociatedEntityName( sfi() )
);
SelectFragment fragment = valueEntityPersister.propertySelectFragmentFragment(
elementTableAlias(),
null,
false
);
appendSelectExpressions( fragment, selections, aliasGenerator );
}
}
项目:lams
文件:WhereParser.java
private String getElementName(PathExpressionParser.CollectionElement element, QueryTranslatorImpl q) throws QueryException {
String name;
if ( element.isOneToMany ) {
name = element.alias;
}
else {
Type type = element.elementType;
if ( type.isEntityType() ) { //ie. a many-to-many
String entityName = ( ( EntityType ) type ).getAssociatedEntityName();
name = pathExpressionParser.continueFromManyToMany( entityName, element.elementColumns, q );
}
else {
throw new QueryException( "illegally dereferenced collection element" );
}
}
return name;
}
项目:cacheonix-core
文件:JoinWalker.java
/**
* Does the mapping, and Hibernate default semantics, specify that
* this association should be fetched by outer joining
*/
protected boolean isJoinedFetchEnabledInMapping(FetchMode config, AssociationType type)
throws MappingException {
if ( !type.isEntityType() && !type.isCollectionType() ) {
return false;
}
else {
if (config==FetchMode.JOIN) return true;
if (config==FetchMode.SELECT) return false;
if ( type.isEntityType() ) {
//TODO: look at the owning property and check that it
// isn't lazy (by instrumentation)
EntityType entityType =(EntityType) type;
EntityPersister persister = getFactory().getEntityPersister( entityType.getAssociatedEntityName() );
return !persister.hasProxy();
}
else {
return false;
}
}
}
项目:cacheonix-core
文件:AbstractPropertyMapping.java
protected void initIdentifierPropertyPaths(
final String path,
final EntityType etype,
final String[] columns,
final Mapping factory) throws MappingException {
Type idtype = etype.getIdentifierOrUniqueKeyType( factory );
String idPropName = etype.getIdentifierOrUniqueKeyPropertyName(factory);
boolean hasNonIdentifierPropertyNamedId = hasNonIdentifierPropertyNamedId( etype, factory );
if ( etype.isReferenceToPrimaryKey() ) {
if ( !hasNonIdentifierPropertyNamedId ) {
String idpath1 = extendPath(path, EntityPersister.ENTITY_ID);
addPropertyPath(idpath1, idtype, columns, null);
initPropertyPaths(idpath1, idtype, columns, null, factory);
}
}
if (idPropName!=null) {
String idpath2 = extendPath(path, idPropName);
addPropertyPath(idpath2, idtype, columns, null);
initPropertyPaths(idpath2, idtype, columns, null, factory);
}
}
项目:cacheonix-core
文件:AbstractVisitor.java
/**
* Visit a property value. Dispatch to the
* correct handler for the property type.
* @param value
* @param type
* @throws HibernateException
*/
final Object processValue(Object value, Type type) throws HibernateException {
if ( type.isCollectionType() ) {
//even process null collections
return processCollection( value, (CollectionType) type );
}
else if ( type.isEntityType() ) {
return processEntity( value, (EntityType) type );
}
else if ( type.isComponentType() ) {
return processComponent( value, (AbstractComponentType) type );
}
else {
return null;
}
}
项目:cacheonix-core
文件:IteratorImpl.java
public void remove() {
if (!single) {
throw new UnsupportedOperationException("Not a single column hibernate query result set");
}
if (currentResult==null) {
throw new IllegalStateException("Called Iterator.remove() before next()");
}
if ( !( types[0] instanceof EntityType ) ) {
throw new UnsupportedOperationException("Not an entity");
}
session.delete(
( (EntityType) types[0] ).getAssociatedEntityName(),
currentResult,
false,
null
);
}
项目:cacheonix-core
文件:DotNode.java
/**
* Is the given property name a reference to the primary key of the associated
* entity construed by the given entity type?
* <p/>
* For example, consider a fragment like order.customer.id
* (where order is a from-element alias). Here, we'd have:
* propertyName = "id" AND
* owningType = ManyToOneType(Customer)
* and are being asked to determine whether "customer.id" is a reference
* to customer's PK...
*
* @param propertyName The name of the property to check.
* @param owningType The type represeting the entity "owning" the property
* @return True if propertyName references the entity's (owningType->associatedEntity)
* primary key; false otherwise.
*/
private boolean isReferenceToPrimaryKey(String propertyName, EntityType owningType) {
EntityPersister persister = getSessionFactoryHelper()
.getFactory()
.getEntityPersister( owningType.getAssociatedEntityName() );
if ( persister.getEntityMetamodel().hasNonIdentifierPropertyNamedId() ) {
// only the identifier property field name can be a reference to the associated entity's PK...
return propertyName.equals( persister.getIdentifierPropertyName() ) && owningType.isReferenceToPrimaryKey();
}
else {
// here, we have two possibilities:
// 1) the property-name matches the explicitly identifier property name
// 2) the property-name matches the implicit 'id' property name
if ( EntityPersister.ENTITY_ID.equals( propertyName ) ) {
// the referenced node text is the special 'id'
return owningType.isReferenceToPrimaryKey();
}
else {
String keyPropertyName = getSessionFactoryHelper().getIdentifierOrUniqueKeyPropertyName( owningType );
return keyPropertyName != null && keyPropertyName.equals( propertyName ) && owningType.isReferenceToPrimaryKey();
}
}
}
项目:cacheonix-core
文件:FromElementFactory.java
FromElement addFromElement() throws SemanticException {
FromClause parentFromClause = fromClause.getParentFromClause();
if ( parentFromClause != null ) {
// Look up class name using the first identifier in the path.
String pathAlias = PathHelper.getAlias( path );
FromElement parentFromElement = parentFromClause.getFromElement( pathAlias );
if ( parentFromElement != null ) {
return createFromElementInSubselect( path, pathAlias, parentFromElement, classAlias );
}
}
EntityPersister entityPersister = fromClause.getSessionFactoryHelper().requireClassPersister( path );
FromElement elem = createAndAddFromElement( path,
classAlias,
entityPersister,
( EntityType ) ( ( Queryable ) entityPersister ).getType(),
null );
// Add to the query spaces.
fromClause.getWalker().addQuerySpaces( entityPersister.getQuerySpaces() );
return elem;
}
项目:cacheonix-core
文件:FromElement.java
private void doInitialize(FromClause fromClause, String tableAlias, String className, String classAlias,
EntityPersister persister, EntityType type) {
if ( initialized ) {
throw new IllegalStateException( "Already initialized!!" );
}
this.fromClause = fromClause;
this.tableAlias = tableAlias;
this.className = className;
this.classAlias = classAlias;
this.elementType = new FromElementType( this, persister, type );
// Register the FromElement with the FROM clause, now that we have the names and aliases.
fromClause.registerFromElement( this );
if ( log.isDebugEnabled() ) {
log.debug( fromClause + " : " + className + " ("
+ ( classAlias == null ? "no alias" : classAlias ) + ") -> " + tableAlias );
}
}
项目:cacheonix-core
文件:WhereParser.java
private String getElementName(PathExpressionParser.CollectionElement element, QueryTranslatorImpl q) throws QueryException {
String name;
if ( element.isOneToMany ) {
name = element.alias;
}
else {
Type type = element.elementType;
if ( type.isEntityType() ) { //ie. a many-to-many
String entityName = ( ( EntityType ) type ).getAssociatedEntityName();
name = pathExpressionParser.continueFromManyToMany( entityName, element.elementColumns, q );
}
else {
throw new QueryException( "illegally dereferenced collection element" );
}
}
return name;
}
项目:haloDao-Hibernate3
文件:HaloDao.java
/**
* 取自锐道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;
}
项目:breeze.server.java
文件:RelationshipFixer.java
/**
* Set an association value based on the value of the foreign key. This updates the property of the entity.
* @param propName Name of the navigation/association property of the entity, e.g. "Customer". May be null if the property is the entity's identifier.
* @param propType Type of the property
* @param entityInfo Breeze EntityInfo
* @param meta Metadata for the entity class
*/
private void fixupRelationship(String propName, EntityType propType, EntityInfo entityInfo, ClassMetadata meta)
{
Object entity = entityInfo.entity;
if (removeMode) {
meta.setPropertyValue(entity, propName, null);
return;
}
Object relatedEntity = getPropertyValue(meta, entity, propName);
if (relatedEntity != null) {
// entities are already connected - still need to add to dependency graph
EntityInfo relatedEntityInfo = saveWorkState.findEntityInfo(relatedEntity);
maybeAddToGraph(entityInfo, relatedEntityInfo, propType);
return;
}
relatedEntity = getRelatedEntity(propName, propType, entityInfo, meta);
if (relatedEntity != null) {
meta.setPropertyValue(entity, propName, relatedEntity);
}
}
项目:breeze.server.java
文件:RelationshipFixer.java
/**
* Get a related entity based on the value of the foreign key. Attempts to find the related entity in the
* saveMap; if its not found there, it is loaded via the Session (which should create a proxy, not actually load
* the entity from the database).
* Related entities are Promoted in the saveOrder according to their state.
* @param propName Name of the navigation/association property of the entity, e.g. "Customer". May be null if the property is the entity's identifier.
* @param propType Type of the property
* @param entityInfo Breeze EntityInfo
* @param meta Metadata for the entity class
* @return
*/
private Object getRelatedEntity(String propName, EntityType propType, EntityInfo entityInfo, ClassMetadata meta) {
Object relatedEntity = null;
String foreignKeyName = findForeignKey(propName, meta);
Object id = getForeignKeyValue(entityInfo, meta, foreignKeyName);
if (id != null) {
Class returnEntityClass = propType.getReturnedClass();
EntityInfo relatedEntityInfo = saveWorkState.findEntityInfoById(returnEntityClass, id);
if (relatedEntityInfo == null) {
EntityState state = entityInfo.entityState;
// if (state == EntityState.Added || state == EntityState.Modified || (state == EntityState.Deleted
// && propType.getForeignKeyDirection() != ForeignKeyDirection.FOREIGN_KEY_TO_PARENT)) {
if (state != EntityState.Deleted || propType.getForeignKeyDirection() != ForeignKeyDirection.FOREIGN_KEY_TO_PARENT) {
String relatedEntityName = propType.getName();
relatedEntity = session.load(relatedEntityName, (Serializable) id, LockOptions.NONE);
}
} else {
maybeAddToGraph(entityInfo, relatedEntityInfo, propType);
relatedEntity = relatedEntityInfo.entity;
}
}
return relatedEntity;
}
项目:screensaver
文件:FromElementFactory.java
FromElement addFromElement() throws SemanticException {
FromClause parentFromClause = fromClause.getParentFromClause();
if ( parentFromClause != null ) {
// Look up class name using the first identifier in the path.
String pathAlias = PathHelper.getAlias( path );
FromElement parentFromElement = parentFromClause.getFromElement( pathAlias );
if ( parentFromElement != null ) {
return createFromElementInSubselect( path, pathAlias, parentFromElement, classAlias );
}
}
EntityPersister entityPersister = fromClause.getSessionFactoryHelper().requireClassPersister( path );
FromElement elem = createAndAddFromElement( path,
classAlias,
entityPersister,
( EntityType ) ( ( Queryable ) entityPersister ).getType(),
null );
// Add to the query spaces.
fromClause.getWalker().addQuerySpaces( entityPersister.getQuerySpaces() );
return elem;
}
项目:lams
文件:OneToMany.java
private EntityType getEntityType() {
return mappings.getTypeResolver().getTypeFactory().manyToOne(
getReferencedEntityName(),
true,
null,
false,
false,
isIgnoreNotFound(),
false
);
}
项目:lams
文件:ManyToOne.java
public void createPropertyRefConstraints(Map persistentClasses) {
if (referencedPropertyName!=null) {
PersistentClass pc = (PersistentClass) persistentClasses.get(getReferencedEntityName() );
Property property = pc.getReferencedProperty( getReferencedPropertyName() );
if (property==null) {
throw new MappingException(
"Could not find property " +
getReferencedPropertyName() +
" on " +
getReferencedEntityName()
);
}
else {
if ( !hasFormula() && !"none".equals( getForeignKeyName() ) ) {
java.util.List refColumns = new ArrayList();
Iterator iter = property.getColumnIterator();
while ( iter.hasNext() ) {
Column col = (Column) iter.next();
refColumns.add( col );
}
ForeignKey fk = getTable().createForeignKey(
getForeignKeyName(),
getConstraintColumns(),
( (EntityType) getType() ).getAssociatedEntityName(),
refColumns
);
fk.setCascadeDeleteEnabled(isCascadeDeleteEnabled() );
}
}
}
}
项目:lams
文件:SQLQueryReturnProcessor.java
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 );
}
}
项目:lams
文件:OuterJoinableAssociation.java
private boolean isOneToOne() {
if ( joinableType.isEntityType() ) {
EntityType etype = (EntityType) joinableType;
return etype.isOneToOne() /*&& etype.isReferenceToPrimaryKey()*/;
}
else {
return false;
}
}
项目:lams
文件:QuerySpaceHelper.java
public ExpandingEntityQuerySpace makeEntityQuerySpace(
ExpandingQuerySpace lhsQuerySpace,
AssociationAttributeDefinition attribute,
String querySpaceUid,
FetchStrategy fetchStrategy) {
final EntityType fetchedType = (EntityType) attribute.getType();
final EntityPersister fetchedPersister = attribute.toEntityDefinition().getEntityPersister();
if ( fetchedPersister == null ) {
throw new WalkingException(
String.format(
"Unable to locate EntityPersister [%s] for fetch [%s]",
fetchedType.getAssociatedEntityName(),
attribute.getName()
)
);
}
// TODO: Queryable.isMultiTable() may be more broad than it needs to be...
final boolean isMultiTable = Queryable.class.cast( fetchedPersister ).isMultiTable();
final boolean required = lhsQuerySpace.canJoinsBeRequired() && !isMultiTable && !attribute.isNullable();
return makeEntityQuerySpace(
lhsQuerySpace,
fetchedPersister,
attribute.getName(),
(EntityType) attribute.getType(),
querySpaceUid,
required,
shouldIncludeJoin( fetchStrategy )
);
}
项目:lams
文件:QuerySpaceHelper.java
public ExpandingEntityQuerySpace makeEntityQuerySpace(
ExpandingQuerySpace lhsQuerySpace,
EntityPersister fetchedPersister,
String attributeName,
EntityType attributeType,
String querySpaceUid,
boolean required,
boolean shouldIncludeJoin) {
final ExpandingEntityQuerySpace rhs = lhsQuerySpace.getExpandingQuerySpaces().makeEntityQuerySpace(
querySpaceUid,
fetchedPersister,
required
);
if ( shouldIncludeJoin ) {
final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createEntityJoin(
lhsQuerySpace,
attributeName,
rhs,
required,
attributeType,
fetchedPersister.getFactory()
);
lhsQuerySpace.addJoin( join );
}
return rhs;
}
项目:lams
文件:AbstractPropertyMapping.java
private boolean hasNonIdentifierPropertyNamedId(final EntityType entityType, final Mapping factory) {
// TODO : would be great to have a Mapping#hasNonIdentifierPropertyNamedId method
// I don't believe that Mapping#getReferencedPropertyType accounts for the identifier property; so
// if it returns for a property named 'id', then we should have a non-id field named id
try {
return factory.getReferencedPropertyType( entityType.getAssociatedEntityName(), EntityPersister.ENTITY_ID ) != null;
}
catch( MappingException e ) {
return false;
}
}
项目:lams
文件:AbstractEntityTuplizer.java
@Override
public void setIdentifier(Object entity, Serializable id, EntityMode entityMode, SessionImplementor session) {
final Object[] extractedValues = mappedIdentifierType.getPropertyValues( id, entityMode );
final Object[] injectionValues = new Object[ extractedValues.length ];
final PersistenceContext persistenceContext = session.getPersistenceContext();
for ( int i = 0; i < virtualIdComponent.getSubtypes().length; i++ ) {
final Type virtualPropertyType = virtualIdComponent.getSubtypes()[i];
final Type idClassPropertyType = mappedIdentifierType.getSubtypes()[i];
if ( virtualPropertyType.isEntityType() && ! idClassPropertyType.isEntityType() ) {
if ( session == null ) {
throw new AssertionError(
"Deprecated version of getIdentifier (no session) was used but session was required"
);
}
final String associatedEntityName = ( (EntityType) virtualPropertyType ).getAssociatedEntityName();
final EntityKey entityKey = session.generateEntityKey(
(Serializable) extractedValues[i],
session.getFactory().getEntityPersister( associatedEntityName )
);
// it is conceivable there is a proxy, so check that first
Object association = persistenceContext.getProxy( entityKey );
if ( association == null ) {
// otherwise look for an initialized version
association = persistenceContext.getEntity( entityKey );
}
injectionValues[i] = association;
}
else {
injectionValues[i] = extractedValues[i];
}
}
virtualIdComponent.setPropertyValues( entity, injectionValues, entityMode );
}
项目:lams
文件:CascadingActions.java
@Override
public void noCascade(
EventSource session,
Object child,
Object parent,
EntityPersister persister,
int propertyIndex) {
if ( child == null ) {
return;
}
Type type = persister.getPropertyTypes()[propertyIndex];
if ( type.isEntityType() ) {
String childEntityName = ((EntityType) type).getAssociatedEntityName( session.getFactory() );
if ( !isInManagedState( child, session )
&& !(child instanceof HibernateProxy) //a proxy cannot be transient and it breaks ForeignKeys.isTransient
&& ForeignKeys.isTransient( childEntityName, child, null, session ) ) {
String parentEntiytName = persister.getEntityName();
String propertyName = persister.getPropertyNames()[propertyIndex];
throw new TransientPropertyValueException(
"object references an unsaved transient instance - save the transient instance before flushing",
childEntityName,
parentEntiytName,
propertyName
);
}
}
}