Java 类org.hibernate.type.CollectionType 实例源码
项目:lams
文件:HibernateTraversableResolver.java
private void addAssociationsToTheSetForOneProperty(String name, Type type, String prefix, SessionFactoryImplementor factory) {
if ( type.isCollectionType() ) {
CollectionType collType = (CollectionType) type;
Type assocType = collType.getElementType( factory );
addAssociationsToTheSetForOneProperty(name, assocType, prefix, factory);
}
//ToOne association
else if ( type.isEntityType() || type.isAnyType() ) {
associations.add( prefix + name );
} else if ( type.isComponentType() ) {
CompositeType componentType = (CompositeType) type;
addAssociationsToTheSetForAllProperties(
componentType.getPropertyNames(),
componentType.getSubtypes(),
(prefix.equals( "" ) ? name : prefix + name) + ".",
factory);
}
}
项目:lams
文件:Map.java
public CollectionType getDefaultCollectionType() {
if ( isSorted() ) {
return getMappings().getTypeResolver()
.getTypeFactory()
.sortedMap( getRole(), getReferencedPropertyName(), getComparator() );
}
else if ( hasOrder() ) {
return getMappings().getTypeResolver()
.getTypeFactory()
.orderedMap( getRole(), getReferencedPropertyName() );
}
else {
return getMappings().getTypeResolver()
.getTypeFactory()
.map( getRole(), getReferencedPropertyName() );
}
}
项目:lams
文件:Set.java
public CollectionType getDefaultCollectionType() {
if ( isSorted() ) {
return getMappings().getTypeResolver()
.getTypeFactory()
.sortedSet( getRole(), getReferencedPropertyName(), getComparator() );
}
else if ( hasOrder() ) {
return getMappings().getTypeResolver()
.getTypeFactory()
.orderedSet( getRole(), getReferencedPropertyName() );
}
else {
return getMappings().getTypeResolver()
.getTypeFactory()
.set( getRole(), getReferencedPropertyName() );
}
}
项目:lams
文件:AbstractEmptinessExpression.java
protected QueryableCollection getQueryableCollection(
String entityName,
String propertyName,
SessionFactoryImplementor factory) throws HibernateException {
final PropertyMapping ownerMapping = (PropertyMapping) factory.getEntityPersister( entityName );
final Type type = ownerMapping.toType( propertyName );
if ( !type.isCollectionType() ) {
throw new MappingException(
"Property path [" + entityName + "." + propertyName + "] does not reference a collection"
);
}
final String role = ( (CollectionType) type ).getRole();
try {
return (QueryableCollection) factory.getCollectionPersister( role );
}
catch ( ClassCastException cce ) {
throw new QueryException( "collection role is not queryable: " + role );
}
catch ( Exception e ) {
throw new QueryException( "collection role not found: " + role );
}
}
项目:lams
文件:JoinHelper.java
public JoinDefinedByMetadata createCollectionJoin(
QuerySpace leftHandSide,
String lhsPropertyName,
CollectionQuerySpace rightHandSide,
boolean rightHandSideRequired,
CollectionType joinedPropertyType,
SessionFactoryImplementor sessionFactory) {
return new JoinImpl(
leftHandSide,
lhsPropertyName,
rightHandSide,
joinedPropertyType.getAssociatedJoinable( sessionFactory ).getKeyColumnNames(),
joinedPropertyType,
rightHandSideRequired
);
}
项目:lams
文件:Nullability.java
/**
* check sub elements-nullability. Returns property path that break
* nullability or null if none
*
* @param propertyType type to check
* @param value value to check
*
* @return property path
* @throws HibernateException error while getting subcomponent values
*/
private String checkSubElementsNullability(Type propertyType, Object value) throws HibernateException {
if ( propertyType.isComponentType() ) {
return checkComponentNullability( value, (CompositeType) propertyType );
}
if ( propertyType.isCollectionType() ) {
// persistent collections may have components
final CollectionType collectionType = (CollectionType) propertyType;
final Type collectionElementType = collectionType.getElementType( session.getFactory() );
if ( collectionElementType.isComponentType() ) {
// check for all components values in the collection
final CompositeType componentType = (CompositeType) collectionElementType;
final Iterator itr = CascadingActions.getLoadedElementsIterator( session, collectionType, value );
while ( itr.hasNext() ) {
final Object compositeElement = itr.next();
if ( compositeElement != null ) {
return checkComponentNullability( compositeElement, componentType );
}
}
}
}
return null;
}
项目:lams
文件:WrapVisitor.java
@Override
Object processCollection(Object collection, CollectionType collectionType)
throws HibernateException {
if ( collection != null && ( collection instanceof PersistentCollection ) ) {
final SessionImplementor session = getSession();
PersistentCollection coll = (PersistentCollection) collection;
if ( coll.setCurrentSession( session ) ) {
reattachCollection( coll, collectionType );
}
return null;
}
else {
return processArrayOrNewCollection( collection, collectionType );
}
}
项目: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
文件:EvictVisitor.java
public void evictCollection(Object value, CollectionType type) {
final Object pc;
if ( type.hasHolder() ) {
pc = getSession().getPersistenceContext().removeCollectionHolder(value);
}
else if ( value instanceof PersistentCollection ) {
pc = value;
}
else {
return; //EARLY EXIT!
}
PersistentCollection collection = (PersistentCollection) pc;
if ( collection.unsetSession( getSession() ) ) evictCollection(collection);
}
项目:lams
文件:PathExpressionParser.java
public void end(QueryTranslatorImpl q) throws QueryException {
ignoreInitialJoin = false;
Type propertyType = getPropertyType();
if ( propertyType != null && propertyType.isCollectionType() ) {
collectionRole = ( ( CollectionType ) propertyType ).getRole();
collectionName = q.createNameForCollection( collectionRole );
prepareForIndex( q );
}
else {
columns = currentColumns();
setType();
}
//important!!
continuation = false;
}
项目:cacheonix-core
文件:AbstractEmptinessExpression.java
protected QueryableCollection getQueryableCollection(String entityName, String propertyName, SessionFactoryImplementor factory)
throws HibernateException {
PropertyMapping ownerMapping = ( PropertyMapping ) factory.getEntityPersister( entityName );
Type type = ownerMapping.toType( propertyName );
if ( !type.isCollectionType() ) {
throw new MappingException(
"Property path [" + entityName + "." + propertyName + "] does not reference a collection"
);
}
String role = ( ( CollectionType ) type ).getRole();
try {
return ( QueryableCollection ) factory.getCollectionPersister( role );
}
catch ( ClassCastException cce ) {
throw new QueryException( "collection role is not queryable: " + role );
}
catch ( Exception e ) {
throw new QueryException( "collection role not found: " + role );
}
}
项目:cacheonix-core
文件:WrapVisitor.java
Object processCollection(Object collection, CollectionType collectionType)
throws HibernateException {
if ( collection!=null && (collection instanceof PersistentCollection) ) {
final SessionImplementor session = getSession();
PersistentCollection coll = (PersistentCollection) collection;
if ( coll.setCurrentSession(session) ) {
reattachCollection( coll, collectionType );
}
return null;
}
else {
return processArrayOrNewCollection(collection, collectionType);
}
}
项目: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
文件:EvictVisitor.java
public void evictCollection(Object value, CollectionType type) {
final Object pc;
if ( type.hasHolder( getSession().getEntityMode() ) ) {
pc = getSession().getPersistenceContext().removeCollectionHolder(value);
}
else if ( value instanceof PersistentCollection ) {
pc = value;
}
else {
return; //EARLY EXIT!
}
PersistentCollection collection = (PersistentCollection) pc;
if ( collection.unsetSession( getSession() ) ) evictCollection(collection);
}
项目:cacheonix-core
文件:PathExpressionParser.java
public void end(QueryTranslatorImpl q) throws QueryException {
ignoreInitialJoin = false;
Type propertyType = getPropertyType();
if ( propertyType != null && propertyType.isCollectionType() ) {
collectionRole = ( ( CollectionType ) propertyType ).getRole();
collectionName = q.createNameForCollection( collectionRole );
prepareForIndex( q );
}
else {
columns = currentColumns();
setType();
}
//important!!
continuation = false;
}
项目:open-cyclos
文件:HibernateQueryHandler.java
/**
* Copies the persistent properties from the source to the destination entity
*/
public void copyProperties(final Entity source, final Entity dest) {
if (source == null || dest == null) {
return;
}
final ClassMetadata metaData = getClassMetaData(source);
final Object[] values = metaData.getPropertyValues(source, EntityMode.POJO);
// Skip the collections
final Type[] types = metaData.getPropertyTypes();
for (int i = 0; i < types.length; i++) {
final Type type = types[i];
if (type instanceof CollectionType) {
values[i] = null;
}
}
metaData.setPropertyValues(dest, values, EntityMode.POJO);
}
项目:geomajas-project-server
文件:HibernateEntityMapper.java
@Override
public EntityCollection getChildCollection(String name) throws LayerException {
Type type = metadata.getPropertyType(name);
if (type instanceof CollectionType) {
CollectionType ct = (CollectionType) type;
Collection coll = (Collection) metadata.getPropertyValue(object, name, EntityMode.POJO);
if (coll == null) {
// normally should not happen, hibernate instantiates it automatically
coll = (Collection) ct.instantiate(0);
metadata.setPropertyValue(object, name, coll, EntityMode.POJO);
}
String entityName = ct.getAssociatedEntityName((SessionFactoryImplementor) sessionFactory);
ClassMetadata childMetadata = sessionFactory.getClassMetadata(entityName);
return new HibernateEntityCollection(metadata, childMetadata, object, coll);
} else {
throw new LayerException(ExceptionCode.FEATURE_MODEL_PROBLEM);
}
}
项目:lams
文件:Collection.java
public CollectionType getCollectionType() {
if ( typeName == null ) {
return getDefaultCollectionType();
}
else {
return mappings.getTypeResolver()
.getTypeFactory()
.customCollection( typeName, typeParameters, role, referencedPropertyName );
}
}
项目:lams
文件:CascadingActions.java
@Override
public Iterator getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
// delete does cascade to uninitialized collections
return getAllElementsIterator( session, collectionType, collection );
}
项目:lams
文件:CascadingActions.java
@Override
public Iterator getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
// lock doesn't cascade to uninitialized collections
return getLoadedElementsIterator( session, collectionType, collection );
}
项目:lams
文件:CascadingActions.java
@Override
public Iterator getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
// refresh doesn't cascade to uninitialized collections
return getLoadedElementsIterator( session, collectionType, collection );
}
项目:lams
文件:CascadingActions.java
@Override
public Iterator getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
// evicts don't cascade to uninitialized collections
return getLoadedElementsIterator( session, collectionType, collection );
}
项目:lams
文件:CascadingActions.java
@Override
public Iterator getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
// saves / updates don't cascade to uninitialized collections
return getLoadedElementsIterator( session, collectionType, collection );
}
项目:lams
文件:CascadingActions.java
@Override
public Iterator getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
// merges don't cascade to uninitialized collections
return getLoadedElementsIterator( session, collectionType, collection );
}
项目:lams
文件:CascadingActions.java
@Override
public Iterator getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
// persists don't cascade to uninitialized collections
return getAllElementsIterator( session, collectionType, collection );
}
项目:lams
文件:CascadingActions.java
@Override
public Iterator getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
// persists don't cascade to uninitialized collections
return getLoadedElementsIterator( session, collectionType, collection );
}
项目:lams
文件:CascadingActions.java
@Override
public Iterator getCascadableChildrenIterator(
EventSource session,
CollectionType collectionType,
Object collection) {
// replicate does cascade to uninitialized collections
return getLoadedElementsIterator( session, collectionType, collection );
}
项目:lams
文件:CascadingActions.java
/**
* Iterate just the elements of the collection that are already there. Don't load
* any new elements from the database.
*/
public static Iterator getLoadedElementsIterator(
SessionImplementor session,
CollectionType collectionType,
Object collection) {
if ( collectionIsInitialized( collection ) ) {
// handles arrays and newly instantiated collections
return collectionType.getElementsIterator( collection, session );
}
else {
// does not handle arrays (thats ok, cos they can't be lazy)
// or newly instantiated collections, so we can do the cast
return ((PersistentCollection) collection).queuedAdditionIterator();
}
}
项目:lams
文件:Cascade.java
private void cascadeAssociation(
final Object parent,
final Object child,
final Type type,
final CascadeStyle style,
final Object anything,
final boolean isCascadeDeleteEnabled) {
if ( type.isEntityType() || type.isAnyType() ) {
cascadeToOne( parent, child, type, style, anything, isCascadeDeleteEnabled );
}
else if ( type.isCollectionType() ) {
cascadeCollection( parent, child, style, anything, (CollectionType) type );
}
}
项目:lams
文件:Cascade.java
/**
* Cascade an action to a collection
*/
private void cascadeCollection(
final Object parent,
final Object child,
final CascadeStyle style,
final Object anything,
final CollectionType type) {
final CollectionPersister persister = eventSource.getFactory().getCollectionPersister( type.getRole() );
final Type elemType = persister.getElementType();
final CascadePoint originalCascadePoint = cascadePoint;
if ( cascadePoint == CascadePoint.AFTER_INSERT_BEFORE_DELETE) {
cascadePoint = CascadePoint.AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION;
}
//cascade to current collection elements
if ( elemType.isEntityType() || elemType.isAnyType() || elemType.isComponentType() ) {
cascadeCollectionElements(
parent,
child,
type,
style,
elemType,
anything,
persister.isCascadeDeleteEnabled()
);
}
cascadePoint = originalCascadePoint;
}
项目:lams
文件:OnUpdateVisitor.java
@Override
Object processCollection(Object collection, CollectionType type) throws HibernateException {
if ( collection == CollectionType.UNFETCHED_COLLECTION ) {
return null;
}
EventSource session = getSession();
CollectionPersister persister = session.getFactory().getCollectionPersister( type.getRole() );
final Serializable collectionKey = extractCollectionKeyFromOwner( persister );
if ( collection!=null && (collection instanceof PersistentCollection) ) {
PersistentCollection wrapper = (PersistentCollection) collection;
if ( wrapper.setCurrentSession(session) ) {
//a "detached" collection!
if ( !isOwnerUnchanged( wrapper, persister, collectionKey ) ) {
// if the collection belonged to a different entity,
// clean up the existing state of the collection
removeCollection( persister, collectionKey, session );
}
reattachCollection(wrapper, type);
}
else {
// a collection loaded in the current session
// can not possibly be the collection belonging
// to the entity passed to update()
removeCollection(persister, collectionKey, session);
}
}
else {
// null or brand new collection
// this will also (inefficiently) handle arrays, which have
// no snapshot, so we can't do any better
removeCollection(persister, collectionKey, session);
}
return null;
}
项目:lams
文件:OnLockVisitor.java
@Override
public Object processCollection(Object collection, CollectionType type) throws HibernateException {
if ( collection == null ) {
return null;
}
final SessionImplementor session = getSession();
final CollectionPersister persister = session.getFactory().getCollectionPersister( type.getRole() );
if ( collection instanceof PersistentCollection ) {
final PersistentCollection persistentCollection = (PersistentCollection) collection;
if ( persistentCollection.setCurrentSession( session ) ) {
if ( isOwnerUnchanged( persistentCollection, persister, extractCollectionKeyFromOwner( persister ) ) ) {
// a "detached" collection that originally belonged to the same entity
if ( persistentCollection.isDirty() ) {
throw new HibernateException( "reassociated object has dirty collection" );
}
reattachCollection( persistentCollection, type );
}
else {
// a "detached" collection that belonged to a different entity
throw new HibernateException( "reassociated object has dirty collection reference" );
}
}
else {
// a collection loaded in the current session
// can not possibly be the collection belonging
// to the entity passed to update()
throw new HibernateException( "reassociated object has dirty collection reference" );
}
}
else {
// brand new collection
//TODO: or an array!! we can't lock objects with arrays now??
throw new HibernateException( "reassociated object has dirty collection reference (or an array)" );
}
return null;
}
项目:lams
文件:DefaultRefreshEventListener.java
private void evictCachedCollections(Type[] types, Serializable id, SessionFactoryImplementor factory)
throws HibernateException {
for ( Type type : types ) {
if ( type.isCollectionType() ) {
factory.getCache().evictCollection( ( (CollectionType) type ).getRole(), id );
}
else if ( type.isComponentType() ) {
CompositeType actype = (CompositeType) type;
evictCachedCollections( actype.getSubtypes(), id, factory );
}
}
}
项目:lams
文件:EvictVisitor.java
@Override
Object processCollection(Object collection, CollectionType type)
throws HibernateException {
if (collection!=null) evictCollection(collection, type);
return null;
}
项目:lams
文件:OnReplicateVisitor.java
@Override
public Object processCollection(Object collection, CollectionType type) throws HibernateException {
if ( collection == CollectionType.UNFETCHED_COLLECTION ) {
return null;
}
final EventSource session = getSession();
final CollectionPersister persister = session.getFactory().getCollectionPersister( type.getRole() );
if ( isUpdate ) {
removeCollection( persister, extractCollectionKeyFromOwner( persister ), session );
}
if ( collection != null && collection instanceof PersistentCollection ) {
final PersistentCollection wrapper = (PersistentCollection) collection;
wrapper.setCurrentSession( session );
if ( wrapper.wasInitialized() ) {
session.getPersistenceContext().addNewCollection( persister, wrapper );
}
else {
reattachCollection( wrapper, type );
}
}
else {
// otherwise a null or brand new collection
// this will also (inefficiently) handle arrays, which
// have no snapshot, so we can't do any better
//processArrayOrNewCollection(collection, type);
}
return null;
}
项目:lams
文件:DotNode.java
public void resolveIndex(AST parent) throws SemanticException {
if ( isResolved() ) {
return;
}
Type propertyType = prepareLhs(); // Prepare the left hand side and get the data type.
dereferenceCollection( (CollectionType) propertyType, true, true, null, parent );
}
项目:lams
文件:IdentNode.java
public void resolveIndex(AST parent) throws SemanticException {
// An ident node can represent an index expression if the ident
// represents a naked property ref
// *Note: this makes the assumption (which is currently the case
// in the hql-sql grammar) that the ident is first resolved
// itself (addrExpr -> resolve()). The other option, if that
// changes, is to call resolve from here; but it is
// currently un-needed overhead.
if (!(isResolved() && nakedPropertyRef)) {
throw new UnsupportedOperationException();
}
String propertyName = getOriginalText();
if (!getDataType().isCollectionType()) {
throw new SemanticException("Collection expected; [" + propertyName + "] does not refer to a collection property");
}
// TODO : most of below was taken verbatim from DotNode; should either delegate this logic or super-type it
CollectionType type = (CollectionType) getDataType();
String role = type.getRole();
QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection(role);
String alias = null; // DotNode uses null here...
String columnTableAlias = getFromElement().getTableAlias();
JoinType joinType = JoinType.INNER_JOIN;
boolean fetch = false;
FromElementFactory factory = new FromElementFactory(
getWalker().getCurrentFromClause(),
getFromElement(),
propertyName,
alias,
getFromElement().toColumns(columnTableAlias, propertyName, false),
true
);
FromElement elem = factory.createCollection(queryableCollection, role, joinType, fetch, true);
setFromElement(elem);
getWalker().addQuerySpaces(queryableCollection.getCollectionSpaces()); // Always add the collection's query spaces.
}
项目:lams
文件:AbstractMapComponentNode.java
@Override
public void resolve(
boolean generateJoin,
boolean implicitJoin,
String classAlias,
AST parent) throws SemanticException {
if ( parent != null ) {
throw attemptedDereference();
}
final FromReferenceNode mapReference = getMapReference();
mapReference.resolve( true, true );
FromElement sourceFromElement = null;
if ( isAliasRef( mapReference ) ) {
final QueryableCollection collectionPersister = mapReference.getFromElement().getQueryableCollection();
if ( Map.class.isAssignableFrom( collectionPersister.getCollectionType().getReturnedClass() ) ) {
sourceFromElement = mapReference.getFromElement();
}
}
else {
if ( mapReference.getDataType().isCollectionType() ) {
final CollectionType collectionType = (CollectionType) mapReference.getDataType();
if ( Map.class.isAssignableFrom( collectionType.getReturnedClass() ) ) {
sourceFromElement = mapReference.getFromElement();
}
}
}
if ( sourceFromElement == null ) {
throw nonMap();
}
setFromElement( sourceFromElement );
setDataType( resolveType( sourceFromElement.getQueryableCollection() ) );
this.columns = resolveColumns( sourceFromElement.getQueryableCollection() );
initText( this.columns );
setFirstChild( null );
}
项目:cacheonix-core
文件:Collection.java
public CollectionType getCollectionType() {
if ( typeName == null ) {
return getDefaultCollectionType();
}
else {
return TypeFactory.customCollection( typeName, typeParameters, role, referencedPropertyName, isEmbedded() );
}
}
项目:cacheonix-core
文件:Map.java
public CollectionType getDefaultCollectionType() {
if ( isSorted() ) {
return TypeFactory.sortedMap( getRole(), getReferencedPropertyName(), isEmbedded(), getComparator() );
}
else if ( hasOrder() ) {
return TypeFactory.orderedMap( getRole(), getReferencedPropertyName(), isEmbedded() );
}
else {
return TypeFactory.map( getRole(), getReferencedPropertyName(), isEmbedded() );
}
}