Methods Summary |
---|
public int | compare(java.lang.Object x, java.lang.Object y, org.hibernate.EntityMode entityMode){@inheritDoc}
return 0; //TODO: entities CAN be compared, by PK, fix this! -> only if/when we can extract the id values....
|
public java.lang.Object | deepCopy(java.lang.Object value, org.hibernate.EntityMode entityMode, org.hibernate.engine.SessionFactoryImplementor factory){@inheritDoc}
return value; //special case ... this is the leaf of the containment graph, even though not immutable
|
private java.lang.Class | determineAssociatedEntityClass()
try {
return ReflectHelper.classForName( getAssociatedEntityName() );
}
catch ( ClassNotFoundException cnfe ) {
return java.util.Map.class;
}
|
public java.lang.Object | fromXMLNode(org.dom4j.Node xml, org.hibernate.engine.Mapping factory){@inheritDoc}
if ( !isEmbeddedInXML ) {
return getIdentifierType(factory).fromXMLNode(xml, factory);
}
else {
return xml;
}
|
public final java.lang.String | getAssociatedEntityName()The name of the associated entity.
return associatedEntityName;
|
public java.lang.String | getAssociatedEntityName(org.hibernate.engine.SessionFactoryImplementor factory)The name of the associated entity.
return getAssociatedEntityName();
|
public org.hibernate.persister.entity.Joinable | getAssociatedJoinable(org.hibernate.engine.SessionFactoryImplementor factory)Retrieves the {@link Joinable} defining the associated entity.
return ( Joinable ) factory.getEntityPersister( associatedEntityName );
|
public int | getHashCode(java.lang.Object x, org.hibernate.EntityMode entityMode, org.hibernate.engine.SessionFactoryImplementor factory){@inheritDoc}
EntityPersister persister = factory.getEntityPersister(associatedEntityName);
if ( !persister.canExtractIdOutOfEntity() ) {
return super.getHashCode(x, entityMode);
}
final Serializable id;
if (x instanceof HibernateProxy) {
id = ( (HibernateProxy) x ).getHibernateLazyInitializer().getIdentifier();
}
else {
id = persister.getIdentifier(x, entityMode);
}
return persister.getIdentifierType().getHashCode(id, entityMode, factory);
|
protected final java.lang.Object | getIdentifier(java.lang.Object value, org.hibernate.engine.SessionImplementor session)
if ( isNotEmbedded(session) ) {
return value;
}
if ( isReferenceToPrimaryKey() ) {
return ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session ); //tolerates nulls
}
else if ( value == null ) {
return null;
}
else {
EntityPersister entityPersister = session.getFactory().getEntityPersister( getAssociatedEntityName() );
Object propertyValue = entityPersister.getPropertyValue( value, uniqueKeyPropertyName, session.getEntityMode() );
// We now have the value of the property-ref we reference. However,
// we need to dig a little deeper, as that property might also be
// an entity type, in which case we need to resolve its identitifier
Type type = entityPersister.getPropertyType( uniqueKeyPropertyName );
if ( type.isEntityType() ) {
propertyValue = ( ( EntityType ) type ).getIdentifier( propertyValue, session );
}
return propertyValue;
}
|
private static java.io.Serializable | getIdentifier(java.lang.Object object, org.hibernate.persister.entity.EntityPersister persister, org.hibernate.EntityMode entityMode)Get the identifier value of an instance or proxy.
Intended only for loggin purposes!!!
if (object instanceof HibernateProxy) {
HibernateProxy proxy = (HibernateProxy) object;
LazyInitializer li = proxy.getHibernateLazyInitializer();
return li.getIdentifier();
}
else {
return persister.getIdentifier( object, entityMode );
}
|
public final java.lang.String | getIdentifierOrUniqueKeyPropertyName(org.hibernate.engine.Mapping factory)The name of the property on the associated entity to which our FK
refers
if ( isReferenceToPrimaryKey() ) {
return factory.getIdentifierPropertyName( getAssociatedEntityName() );
}
else {
return uniqueKeyPropertyName;
}
|
public final Type | getIdentifierOrUniqueKeyType(org.hibernate.engine.Mapping factory)Determine the type of either (1) the identifier if we reference the
associated entity's PK or (2) the unique key to which we refer (i.e.
the property-ref).
if ( isReferenceToPrimaryKey() ) {
return getIdentifierType(factory);
}
else {
Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName );
if ( type.isEntityType() ) {
type = ( ( EntityType ) type).getIdentifierOrUniqueKeyType( factory );
}
return type;
}
|
Type | getIdentifierType(org.hibernate.engine.Mapping factory)Convenience method to locate the identifier type of the associated entity.
return factory.getIdentifierType( getAssociatedEntityName() );
|
Type | getIdentifierType(org.hibernate.engine.SessionImplementor session)Convenience method to locate the identifier type of the associated entity.
return getIdentifierType( session.getFactory() );
|
public java.lang.String | getLHSPropertyName()
return null;
|
public java.lang.String | getName()For entity types, the name correlates to the associated entity name.
return associatedEntityName;
|
public java.lang.String | getOnCondition(java.lang.String alias, org.hibernate.engine.SessionFactoryImplementor factory, java.util.Map enabledFilters)
if ( isReferenceToPrimaryKey() ) { //TODO: this is a bit arbitrary, expose a switch to the user?
return "";
}
else {
return getAssociatedJoinable( factory ).filterFragment( alias, enabledFilters );
}
|
public java.lang.String | getPropertyName()
return null;
|
public java.lang.String | getRHSUniqueKeyPropertyName()
return uniqueKeyPropertyName;
|
public final java.lang.Class | getReturnedClass()This returns the wrong class for an entity with a proxy, or for a named
entity. Theoretically it should return the proxy class, but it doesn't.
The problem here is that we do not necessarily have a ref to the associated
entity persister (nor to the session factory, to look it up) which is really
needed to "do the right thing" here...
if ( returnedClass == null ) {
returnedClass = determineAssociatedEntityClass();
}
return returnedClass;
|
public Type | getSemiResolvedType(org.hibernate.engine.SessionFactoryImplementor factory)
return factory.getEntityPersister( associatedEntityName ).getIdentifierType();
|
public boolean | isAssociationType()An entity type is a type of association type
return true;
|
public boolean | isEmbeddedInXML(){@inheritDoc}
return isEmbeddedInXML;
|
public final boolean | isEntityType()Explicitly, an entity type is an entity type ;)
return true;
|
public boolean | isEqual(java.lang.Object x, java.lang.Object y, org.hibernate.EntityMode entityMode, org.hibernate.engine.SessionFactoryImplementor factory){@inheritDoc}
EntityPersister persister = factory.getEntityPersister(associatedEntityName);
if ( !persister.canExtractIdOutOfEntity() ) {
return super.isEqual(x, y, entityMode);
}
Serializable xid;
if (x instanceof HibernateProxy) {
xid = ( (HibernateProxy) x ).getHibernateLazyInitializer()
.getIdentifier();
}
else {
xid = persister.getIdentifier(x, entityMode);
}
Serializable yid;
if (y instanceof HibernateProxy) {
yid = ( (HibernateProxy) y ).getHibernateLazyInitializer()
.getIdentifier();
}
else {
yid = persister.getIdentifier(y, entityMode);
}
return persister.getIdentifierType()
.isEqual(xid, yid, entityMode, factory);
|
public boolean | isMutable(){@inheritDoc}
return false;
|
protected boolean | isNotEmbedded(org.hibernate.engine.SessionImplementor session)
return !isEmbeddedInXML && session.getEntityMode()==EntityMode.DOM4J;
|
protected boolean | isNull(java.lang.Object owner, org.hibernate.engine.SessionImplementor session)
return false;
|
protected abstract boolean | isNullable()
|
public abstract boolean | isOneToOne()
|
public boolean | isReferenceToPrimaryKey()Does this association foreign key reference the primary key of the other table?
Otherwise, it references a property-ref.
return uniqueKeyPropertyName==null;
|
public final boolean | isSame(java.lang.Object x, java.lang.Object y, org.hibernate.EntityMode entityMode)Two entities are considered the same when their instances are the same.
return x == y;
|
public boolean | isXMLElement(){@inheritDoc}
return isEmbeddedInXML;
|
public java.lang.Object | loadByUniqueKey(java.lang.String entityName, java.lang.String uniqueKeyPropertyName, java.lang.Object key, org.hibernate.engine.SessionImplementor session)Load an instance by a unique key that is not the primary key.
final SessionFactoryImplementor factory = session.getFactory();
UniqueKeyLoadable persister = ( UniqueKeyLoadable ) factory.getEntityPersister( entityName );
//TODO: implement caching?! proxies?!
EntityUniqueKey euk = new EntityUniqueKey(
entityName,
uniqueKeyPropertyName,
key,
getIdentifierOrUniqueKeyType( factory ),
session.getEntityMode(),
session.getFactory()
);
final PersistenceContext persistenceContext = session.getPersistenceContext();
Object result = persistenceContext.getEntity( euk );
if ( result == null ) {
result = persister.loadByUniqueKey( uniqueKeyPropertyName, key, session );
}
return result == null ? null : persistenceContext.proxyFor( result );
|
public java.lang.Object | nullSafeGet(java.sql.ResultSet rs, java.lang.String name, org.hibernate.engine.SessionImplementor session, java.lang.Object owner){@inheritDoc}
return nullSafeGet( rs, new String[] {name}, session, owner );
|
public final java.lang.Object | nullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, org.hibernate.engine.SessionImplementor session, java.lang.Object owner){@inheritDoc}
return resolve( hydrate(rs, names, session, owner), session, owner );
|
public java.lang.Object | replace(java.lang.Object original, java.lang.Object target, org.hibernate.engine.SessionImplementor session, java.lang.Object owner, java.util.Map copyCache){@inheritDoc}
if ( original == null ) {
return null;
}
Object cached = copyCache.get(original);
if ( cached != null ) {
return cached;
}
else {
if ( original == target ) {
return target;
}
Object id = getIdentifier( original, session );
if ( id == null ) {
throw new AssertionFailure("cannot copy a reference to an object with a null id");
}
id = getIdentifierOrUniqueKeyType( session.getFactory() )
.replace(id, null, session, owner, copyCache);
return resolve( id, session, owner );
}
|
public java.lang.Object | resolve(java.lang.Object value, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)Resolve an identifier or unique key value
if ( isNotEmbedded( session ) ) {
return value;
}
if ( value == null ) {
return null;
}
else {
if ( isNull( owner, session ) ) {
return null; //EARLY EXIT!
}
if ( isReferenceToPrimaryKey() ) {
return resolveIdentifier( (Serializable) value, session );
}
else {
return loadByUniqueKey( getAssociatedEntityName(), uniqueKeyPropertyName, value, session );
}
}
|
protected final java.lang.Object | resolveIdentifier(java.io.Serializable id, org.hibernate.engine.SessionImplementor session)Resolve an identifier via a load.
boolean isProxyUnwrapEnabled = unwrapProxy &&
session.getFactory()
.getEntityPersister( getAssociatedEntityName() )
.isInstrumented( session.getEntityMode() );
Object proxyOrEntity = session.internalLoad(
getAssociatedEntityName(),
id,
eager,
isNullable() && !isProxyUnwrapEnabled
);
if ( proxyOrEntity instanceof HibernateProxy ) {
( ( HibernateProxy ) proxyOrEntity ).getHibernateLazyInitializer()
.setUnwrap( isProxyUnwrapEnabled );
}
return proxyOrEntity;
|
public void | setToXMLNode(org.dom4j.Node node, java.lang.Object value, org.hibernate.engine.SessionFactoryImplementor factory){@inheritDoc}
if ( !isEmbeddedInXML ) {
getIdentifierType(factory).setToXMLNode(node, value, factory);
}
else {
Element elt = (Element) value;
replaceNode( node, new ElementWrapper(elt) );
}
|
public java.lang.String | toLoggableString(java.lang.Object value, org.hibernate.engine.SessionFactoryImplementor factory)Generate a loggable representation of an instance of the value mapped by this type.
if ( value == null ) {
return "null";
}
EntityPersister persister = factory.getEntityPersister( associatedEntityName );
StringBuffer result = new StringBuffer().append( associatedEntityName );
if ( persister.hasIdentifierProperty() ) {
final EntityMode entityMode = persister.guessEntityMode( value );
final Serializable id;
if ( entityMode == null ) {
if ( isEmbeddedInXML ) {
throw new ClassCastException( value.getClass().getName() );
}
id = ( Serializable ) value;
}
else {
id = getIdentifier( value, persister, entityMode );
}
result.append( '#" )
.append( persister.getIdentifierType().toLoggableString( id, factory ) );
}
return result.toString();
|
public java.lang.String | toString()Generates a string representation of this type.
return getClass().getName() + '(" + getAssociatedEntityName() + ')";
|