| Method from org.hibernate.type.EntityType Detail: |
public int compare(Object x,
Object y,
EntityMode entityMode) {
return 0; //TODO: entities CAN be compared, by PK, fix this! - > only if/when we can extract the id values....
}
|
public Object deepCopy(Object value,
EntityMode entityMode,
SessionFactoryImplementor factory) {
return value; //special case ... this is the leaf of the containment graph, even though not immutable
}
|
public Object fromXMLNode(Node xml,
Mapping factory) throws HibernateException {
if ( !isEmbeddedInXML ) {
return getIdentifierType(factory).fromXMLNode(xml, factory);
}
else {
return xml;
}
}
|
public final String getAssociatedEntityName() {
return associatedEntityName;
}
The name of the associated entity. |
public String getAssociatedEntityName(SessionFactoryImplementor factory) {
return getAssociatedEntityName();
}
The name of the associated entity. |
public Joinable getAssociatedJoinable(SessionFactoryImplementor factory) throws MappingException {
return ( Joinable ) factory.getEntityPersister( associatedEntityName );
}
Retrieves the Joinable defining the associated entity. |
public int getHashCode(Object x,
EntityMode entityMode,
SessionFactoryImplementor factory) {
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 Object getIdentifier(Object value,
SessionImplementor session) throws HibernateException {
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;
}
}
|
public final String getIdentifierOrUniqueKeyPropertyName(Mapping factory) throws MappingException {
if ( isReferenceToPrimaryKey() ) {
return factory.getIdentifierPropertyName( getAssociatedEntityName() );
}
else {
return uniqueKeyPropertyName;
}
}
The name of the property on the associated entity to which our FK
refers |
public final Type getIdentifierOrUniqueKeyType(Mapping factory) throws MappingException {
if ( isReferenceToPrimaryKey() ) {
return getIdentifierType(factory);
}
else {
Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName );
if ( type.isEntityType() ) {
type = ( ( EntityType ) type).getIdentifierOrUniqueKeyType( factory );
}
return type;
}
}
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). |
Type getIdentifierType(Mapping factory) {
return factory.getIdentifierType( getAssociatedEntityName() );
}
Convenience method to locate the identifier type of the associated entity. |
Type getIdentifierType(SessionImplementor session) {
return getIdentifierType( session.getFactory() );
}
Convenience method to locate the identifier type of the associated entity. |
public String getLHSPropertyName() {
return null;
}
|
public String getName() {
return associatedEntityName;
}
For entity types, the name correlates to the associated entity name. |
public String getOnCondition(String alias,
SessionFactoryImplementor factory,
Map enabledFilters) throws MappingException {
if ( isReferenceToPrimaryKey() ) { //TODO: this is a bit arbitrary, expose a switch to the user?
return "";
}
else {
return getAssociatedJoinable( factory ).filterFragment( alias, enabledFilters );
}
}
|
public String getPropertyName() {
return null;
}
|
public String getRHSUniqueKeyPropertyName() {
return uniqueKeyPropertyName;
}
|
public final Class getReturnedClass() {
if ( returnedClass == null ) {
returnedClass = determineAssociatedEntityClass();
}
return returnedClass;
}
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... |
public Type getSemiResolvedType(SessionFactoryImplementor factory) {
return factory.getEntityPersister( associatedEntityName ).getIdentifierType();
}
|
public boolean isAssociationType() {
return true;
}
An entity type is a type of association type |
public boolean isEmbeddedInXML() {
return isEmbeddedInXML;
}
|
public final boolean isEntityType() {
return true;
}
Explicitly, an entity type is an entity type ;) |
public boolean isEqual(Object x,
Object y,
EntityMode entityMode,
SessionFactoryImplementor factory) {
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() {
return false;
}
|
protected boolean isNotEmbedded(SessionImplementor session) {
return !isEmbeddedInXML && session.getEntityMode()==EntityMode.DOM4J;
}
|
protected boolean isNull(Object owner,
SessionImplementor session) {
return false;
}
|
abstract protected boolean isNullable()
|
abstract public boolean isOneToOne()
|
public boolean isReferenceToPrimaryKey() {
return uniqueKeyPropertyName==null;
}
Does this association foreign key reference the primary key of the other table?
Otherwise, it references a property-ref. |
public final boolean isSame(Object x,
Object y,
EntityMode entityMode) {
return x == y;
}
Two entities are considered the same when their instances are the same. |
public boolean isXMLElement() {
return isEmbeddedInXML;
}
|
public Object loadByUniqueKey(String entityName,
String uniqueKeyPropertyName,
Object key,
SessionImplementor session) throws HibernateException {
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 );
}
Load an instance by a unique key that is not the primary key. |
public Object nullSafeGet(ResultSet rs,
String name,
SessionImplementor session,
Object owner) throws HibernateException, SQLException {
return nullSafeGet( rs, new String[] {name}, session, owner );
}
|
public final Object nullSafeGet(ResultSet rs,
String[] names,
SessionImplementor session,
Object owner) throws HibernateException, SQLException {
return resolve( hydrate(rs, names, session, owner), session, owner );
}
|
public Object replace(Object original,
Object target,
SessionImplementor session,
Object owner,
Map copyCache) throws HibernateException {
if ( original == null ) {
return null;
}
Object cached = copyCache.get(original);
if ( cached != null ) {
return cached;
}
else {
if ( original == target ) {
return target;
}
if ( session.getContextEntityIdentifier( original ) == null &&
ForeignKeys.isTransient( associatedEntityName, original, Boolean.FALSE, session ) ) {
final Object copy = session.getFactory().getEntityPersister( associatedEntityName )
.instantiate( null, session.getEntityMode() );
//TODO: should this be Session.instantiate(Persister, ...)?
copyCache.put( original, copy );
return copy;
}
else {
Object id = getIdentifier( original, session );
if ( id == null ) {
throw new AssertionFailure("non-transient entity has a null id");
}
id = getIdentifierOrUniqueKeyType( session.getFactory() )
.replace(id, null, session, owner, copyCache);
return resolve( id, session, owner );
}
}
}
|
public Object resolve(Object value,
SessionImplementor session,
Object owner) throws HibernateException {
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 );
}
}
}
Resolve an identifier or unique key value |
protected final Object resolveIdentifier(Serializable id,
SessionImplementor session) throws HibernateException {
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;
}
Resolve an identifier via a load. |
public void setToXMLNode(Node node,
Object value,
SessionFactoryImplementor factory) throws HibernateException {
if ( !isEmbeddedInXML ) {
getIdentifierType(factory).setToXMLNode(node, value, factory);
}
else {
Element elt = (Element) value;
replaceNode( node, new ElementWrapper(elt) );
}
}
|
public String toLoggableString(Object value,
SessionFactoryImplementor factory) {
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();
}
Generate a loggable representation of an instance of the value mapped by this type. |
public String toString() {
return getClass().getName() + '(" + getAssociatedEntityName() + ')";
}
Generates a string representation of this type. |