Package org.hibernate.persister.entity

Examples of org.hibernate.persister.entity.Loadable


  public static String getMainSidePropertyName(OgmCollectionPersister collectionPersister) {
    if ( !collectionPersister.isInverse() ) {
      return collectionPersister.getUnqualifiedRole();
    }

    Loadable mainSidePersister = (Loadable) collectionPersister.getElementPersister();

    for ( int i = 0; i < mainSidePersister.getPropertyNames().length; i++ ) {
      String candidateProperty = mainSidePersister.getPropertyNames()[i];
      Type type = mainSidePersister.getPropertyType( candidateProperty );

      // candidate is to-one association
      if ( type.isEntityType() ) {
        if ( Arrays.equals( collectionPersister.getKeyColumnNames(), mainSidePersister.getPropertyColumnNames( i ) ) ) {
          return candidateProperty;
        }
      }
      // candidate is to-many association
      else if ( type.isCollectionType() ) {
View Full Code Here


   * Otherwise use the table name
   */
  //TODO we could cache such knowledge in a service if that turns out to be costly
  private String buildCollectionRole(OgmCollectionPersister collectionPersister) {
    String otherSidePropertyName = null;
    Loadable elementPersister = (Loadable) collectionPersister.getElementPersister();
    Type[] propertyTypes = elementPersister.getPropertyTypes();

    for ( int index = 0 ; index <  propertyTypes.length ; index++ ) {
      Type type = propertyTypes[index];
      //we try and restrict type search as much as possible
      if ( type.isAssociationType() ) {
        boolean matching = false;
        //if the main side collection is a one-to-many, the reverse side should be a to-one is not a collection
        if ( collectionPersister.isOneToMany() && ! type.isCollectionType() ) {
          matching = isToOneMatching( elementPersister, index, type );
        }
        //if the main side collection is not a one-to-many, the reverse side should be a collection
        else if ( ! collectionPersister.isOneToMany() && type.isCollectionType() ) {
          matching = isCollectionMatching( (CollectionType) type, collectionPersister.getTableName() );
        }
        if ( matching ) {
          otherSidePropertyName = elementPersister.getPropertyNames()[index];
          break;
        }
      }
    }
    return processOtherSidePropertyName( otherSidePropertyName );
View Full Code Here

  public Type getIdentifierType(Criteria subcriteria) {
    return ( ( Loadable ) getPropertyMapping( getEntityName( subcriteria ) ) ).getIdentifierType();
  }

  public TypedValue getTypedIdentifierValue(Criteria subcriteria, Object value) {
    final Loadable loadable = ( Loadable ) getPropertyMapping( getEntityName( subcriteria ) );
    return new TypedValue(
        loadable.getIdentifierType(),
            value,
            EntityMode.POJO
    );
  }
View Full Code Here

  throws SQLException, HibernateException {

    final Serializable id = key.getIdentifier();

    // Get the persister for the _subclass_
    final Loadable persister = (Loadable) getFactory().getEntityPersister( instanceEntityName );

    if ( log.isTraceEnabled() ) {
      log.trace(
          "Initializing object from ResultSet: " +
          MessageHelper.infoString( persister, id, getFactory() )
        );
    }
   
    boolean eagerPropertyFetch = isEagerPropertyFetchEnabled(i);

    // add temp entry so that the next step is circular-reference
    // safe - only needed because some types don't take proper
    // advantage of two-phase-load (esp. components)
    TwoPhaseLoad.addUninitializedEntity(
        key,
        object,
        persister,
        lockMode,
        !eagerPropertyFetch,
        session
      );

    //This is not very nice (and quite slow):
    final String[][] cols = persister == rootPersister ?
        getEntityAliases()[i].getSuffixedPropertyAliases() :
        getEntityAliases()[i].getSuffixedPropertyAliases(persister);

    final Object[] values = persister.hydrate(
        rs,
        id,
        object,
        rootPersister,
        cols,
        eagerPropertyFetch,
        session
      );

    final Object rowId = persister.hasRowId() ? rs.getObject(rowIdAlias) : null;

    final AssociationType[] ownerAssociationTypes = getOwnerAssociationTypes();
    if ( ownerAssociationTypes != null && ownerAssociationTypes[i] != null ) {
      String ukName = ownerAssociationTypes[i].getRHSUniqueKeyPropertyName();
      if (ukName!=null) {
        final int index = ( (UniqueKeyLoadable) persister ).getPropertyIndex(ukName);
        final Type type = persister.getPropertyTypes()[index];
 
        // polymorphism not really handled completely correctly,
        // perhaps...well, actually its ok, assuming that the
        // entity name used in the lookup is the same as the
        // the one used here, which it will be
View Full Code Here

  public Type getIdentifierType(Criteria subcriteria) {
    return ( ( Loadable ) getPropertyMapping( getEntityName( subcriteria ) ) ).getIdentifierType();
  }

  public TypedValue getTypedIdentifierValue(Criteria subcriteria, Object value) {
    final Loadable loadable = ( Loadable ) getPropertyMapping( getEntityName( subcriteria ) );
    return new TypedValue(
        loadable.getIdentifierType(),
            value,
            EntityMode.POJO
    );
  }
View Full Code Here

  throws SQLException, HibernateException {

    final Serializable id = key.getIdentifier();

    // Get the persister for the _subclass_
    final Loadable persister = (Loadable) getFactory().getEntityPersister( instanceEntityName );

    if ( log.isTraceEnabled() ) {
      log.trace(
          "Initializing object from ResultSet: " +
          MessageHelper.infoString( persister, id, getFactory() )
        );
    }
   
    boolean eagerPropertyFetch = isEagerPropertyFetchEnabled(i);

    // add temp entry so that the next step is circular-reference
    // safe - only needed because some types don't take proper
    // advantage of two-phase-load (esp. components)
    TwoPhaseLoad.addUninitializedEntity(
        key,
        object,
        persister,
        lockMode,
        !eagerPropertyFetch,
        session
      );

    //This is not very nice (and quite slow):
    final String[][] cols = persister == rootPersister ?
        getEntityAliases()[i].getSuffixedPropertyAliases() :
        getEntityAliases()[i].getSuffixedPropertyAliases(persister);

    final Object[] values = persister.hydrate(
        rs,
        id,
        object,
        rootPersister,
        cols,
        eagerPropertyFetch,
        session
      );

    final Object rowId = persister.hasRowId() ? rs.getObject(rowIdAlias) : null;

    final AssociationType[] ownerAssociationTypes = getOwnerAssociationTypes();
    if ( ownerAssociationTypes != null && ownerAssociationTypes[i] != null ) {
      String ukName = ownerAssociationTypes[i].getRHSUniqueKeyPropertyName();
      if (ukName!=null) {
        final int index = ( (UniqueKeyLoadable) persister ).getPropertyIndex(ukName);
        final Type type = persister.getPropertyTypes()[index];
 
        // polymorphism not really handled completely correctly,
        // perhaps...well, actually its ok, assuming that the
        // entity name used in the lookup is the same as the
        // the one used here, which it will be
View Full Code Here

  throws SQLException, HibernateException {

    final Serializable id = key.getIdentifier();

    // Get the persister for the _subclass_
    final Loadable persister = (Loadable) getFactory().getEntityPersister( instanceEntityName );

    if ( LOG.isTraceEnabled() )
      LOG.tracev( "Initializing object from ResultSet: {0}", MessageHelper.infoString( persister, id, getFactory() ) );

    boolean eagerPropertyFetch = isEagerPropertyFetchEnabled(i);

    // add temp entry so that the next step is circular-reference
    // safe - only needed because some types don't take proper
    // advantage of two-phase-load (esp. components)
    TwoPhaseLoad.addUninitializedEntity(
        key,
        object,
        persister,
        lockMode,
        !eagerPropertyFetch,
        session
      );

    //This is not very nice (and quite slow):
    final String[][] cols = persister == rootPersister ?
        getEntityAliases()[i].getSuffixedPropertyAliases() :
        getEntityAliases()[i].getSuffixedPropertyAliases(persister);

    final Object[] values = persister.hydrate(
        rs,
        id,
        object,
        rootPersister,
        cols,
        eagerPropertyFetch,
        session
      );

    final Object rowId = persister.hasRowId() ? rs.getObject(rowIdAlias) : null;

    final AssociationType[] ownerAssociationTypes = getOwnerAssociationTypes();
    if ( ownerAssociationTypes != null && ownerAssociationTypes[i] != null ) {
      String ukName = ownerAssociationTypes[i].getRHSUniqueKeyPropertyName();
      if (ukName!=null) {
        final int index = ( (UniqueKeyLoadable) persister ).getPropertyIndex(ukName);
        final Type type = persister.getPropertyTypes()[index];

        // polymorphism not really handled completely correctly,
        // perhaps...well, actually its ok, assuming that the
        // entity name used in the lookup is the same as the
        // the one used here, which it will be

        EntityUniqueKey euk = new EntityUniqueKey(
            rootPersister.getEntityName(), //polymorphism comment above
            ukName,
            type.semiResolve( values[index], session, object ),
            type,
            persister.getEntityMode(),
            session.getFactory()
        );
        session.getPersistenceContext().addEntity( euk, object );
      }
    }
View Full Code Here

  public Type getIdentifierType(Criteria criteria) {
    return ( ( Loadable ) getPropertyMapping( getEntityName( criteria ) ) ).getIdentifierType();
  }
  @Override
  public TypedValue getTypedIdentifierValue(Criteria criteria, Object value) {
    final Loadable loadable = ( Loadable ) getPropertyMapping( getEntityName( criteria ) );
    return new TypedValue( loadable.getIdentifierType(), value );
  }
View Full Code Here

  throws SQLException, HibernateException {

    final Serializable id = key.getIdentifier();

    // Get the persister for the _subclass_
    final Loadable persister = (Loadable) getFactory().getEntityPersister( instanceEntityName );

    if ( LOG.isTraceEnabled() )
      LOG.tracev( "Initializing object from ResultSet: {0}", MessageHelper.infoString( persister, id, getFactory() ) );

    boolean eagerPropertyFetch = isEagerPropertyFetchEnabled(i);

    // add temp entry so that the next step is circular-reference
    // safe - only needed because some types don't take proper
    // advantage of two-phase-load (esp. components)
    TwoPhaseLoad.addUninitializedEntity(
        key,
        object,
        persister,
        lockMode,
        !eagerPropertyFetch,
        session
      );

    //This is not very nice (and quite slow):
    final String[][] cols = persister == rootPersister ?
        getEntityAliases()[i].getSuffixedPropertyAliases() :
        getEntityAliases()[i].getSuffixedPropertyAliases(persister);

    final Object[] values = persister.hydrate(
        rs,
        id,
        object,
        rootPersister,
        cols,
        eagerPropertyFetch,
        session
      );

    final Object rowId = persister.hasRowId() ? rs.getObject(rowIdAlias) : null;

    final AssociationType[] ownerAssociationTypes = getOwnerAssociationTypes();
    if ( ownerAssociationTypes != null && ownerAssociationTypes[i] != null ) {
      String ukName = ownerAssociationTypes[i].getRHSUniqueKeyPropertyName();
      if (ukName!=null) {
        final int index = ( (UniqueKeyLoadable) persister ).getPropertyIndex(ukName);
        final Type type = persister.getPropertyTypes()[index];

        // polymorphism not really handled completely correctly,
        // perhaps...well, actually its ok, assuming that the
        // entity name used in the lookup is the same as the
        // the one used here, which it will be

        EntityUniqueKey euk = new EntityUniqueKey(
            rootPersister.getEntityName(), //polymorphism comment above
            ukName,
            type.semiResolve( values[index], session, object ),
            type,
            persister.getEntityMode(),
            session.getFactory()
        );
        session.getPersistenceContext().addEntity( euk, object );
      }
    }
View Full Code Here

      EntityKey entityKey,
      LockMode lockModeToAcquire) {
    final Serializable id = entityKey.getIdentifier();

    // Get the persister for the _subclass_
    final Loadable concreteEntityPersister = (Loadable) context.getSession().getFactory().getEntityPersister( concreteEntityTypeName );

    if ( log.isTraceEnabled() ) {
      log.tracev(
          "Initializing object from ResultSet: {0}",
          MessageHelper.infoString(
              concreteEntityPersister,
              id,
              context.getSession().getFactory()
          )
      );
    }

    // add temp entry so that the next step is circular-reference
    // safe - only needed because some types don't take proper
    // advantage of two-phase-load (esp. components)
    TwoPhaseLoad.addUninitializedEntity(
        entityKey,
        entityInstance,
        concreteEntityPersister,
        lockModeToAcquire,
        !context.getLoadPlan().areLazyAttributesForceFetched(),
        context.getSession()
    );

    final EntityPersister rootEntityPersister = context.getSession().getFactory().getEntityPersister(
        concreteEntityPersister.getRootEntityName()
    );
    final Object[] values;
    try {
      values = concreteEntityPersister.hydrate(
          resultSet,
          id,
          entityInstance,
          (Loadable) entityReference.getEntityPersister(),
          concreteEntityPersister == rootEntityPersister
              ? entityReferenceAliases.getColumnAliases().getSuffixedPropertyAliases()
              : entityReferenceAliases.getColumnAliases().getSuffixedPropertyAliases( concreteEntityPersister ),
          context.getLoadPlan().areLazyAttributesForceFetched(),
          context.getSession()
      );

      context.getProcessingState( entityReference ).registerHydratedState( values );
    }
    catch (SQLException e) {
      throw context.getSession().getFactory().getJdbcServices().getSqlExceptionHelper().convert(
          e,
          "Could not read entity state from ResultSet : " + entityKey
      );
    }

    final Object rowId;
    try {
      rowId = concreteEntityPersister.hasRowId()
          ? resultSet.getObject( entityReferenceAliases.getColumnAliases().getRowIdAlias() )
          : null;
    }
    catch (SQLException e) {
      throw context.getSession().getFactory().getJdbcServices().getSqlExceptionHelper().convert(
          e,
          "Could not read entity row-id from ResultSet : " + entityKey
      );
    }

    final EntityType entityType = EntityFetch.class.isInstance( entityReference )
        ? ( (EntityFetch) entityReference ).getFetchedType()
        : entityReference.getEntityPersister().getEntityMetamodel().getEntityType();

    if ( entityType != null ) {
      String ukName = entityType.getRHSUniqueKeyPropertyName();
      if ( ukName != null ) {
        final int index = ( (UniqueKeyLoadable) concreteEntityPersister ).getPropertyIndex( ukName );
        final Type type = concreteEntityPersister.getPropertyTypes()[index];

        // polymorphism not really handled completely correctly,
        // perhaps...well, actually its ok, assuming that the
        // entity name used in the lookup is the same as the
        // the one used here, which it will be

        EntityUniqueKey euk = new EntityUniqueKey(
            entityReference.getEntityPersister().getEntityName(),
            ukName,
            type.semiResolve( values[index], context.getSession(), entityInstance ),
            type,
            concreteEntityPersister.getEntityMode(),
            context.getSession().getFactory()
        );
        context.getSession().getPersistenceContext().addEntity( euk, entityInstance );
      }
    }
View Full Code Here

TOP

Related Classes of org.hibernate.persister.entity.Loadable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.