Examples of OgmEntityPersister


Examples of org.hibernate.ogm.persister.OgmEntityPersister

  throws HibernateException {

    final Serializable id = key.getIdentifier();

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

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

    //FIXME figure out what that means and what value should be set
    //boolean eagerPropertyFetch = isEagerPropertyFetchEnabled(i);
    boolean eagerPropertyFetch = true;

    // 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
    );

    //TODO what to do with that in OGM
//    //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(
        resultset,
        id,
        object,
        rootPersister,
        //cols,
        eagerPropertyFetch,
        session
      );

    if ( persister.hasRowId() ) {
      throw new HibernateException( "Hibernate OGM does nto support row id");
    }
    final Object rowId = 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

Examples of org.hibernate.ogm.persister.OgmEntityPersister

      if (collectionPersister != null) {
        EntityKey entityKey;
        // we are explicitly looking to update the non owning side
        if ( inverse ) {
          //look for the other side of the collection, build the key of the other side's entity
          OgmEntityPersister elementPersister = (OgmEntityPersister) collectionPersister.getElementPersister();
          entityKey = EntityKeyBuilder.fromPersister(
              elementPersister,
              (Serializable) key,
              session
          );
          collectionMetadataKey.setCollectionRole( buildCollectionRole(collectionPersister) );
        }
        else {
          //we are on the right side, use the association property
          collectionMetadataKey.setCollectionRole( getUnqualifiedRole( collectionPersister ) );
          entityKey = EntityKeyBuilder.fromPersister(
              (OgmEntityPersister) collectionPersister.getOwnerEntityPersister(),
              (Serializable) key,
              session
          );
        }
        collectionMetadataKey.setOwnerEntityKey( entityKey );
        //TODO add information on the collection type, set, map, bag, list etc

        AssociationKind type = collectionPersister.getElementType().isEntityType() ? AssociationKind.ASSOCIATION : AssociationKind.EMBEDDED;
        collectionMetadataKey.setAssociationKind( type );
        collectionMetadataKey.setRowKeyColumnNames( collectionPersister.getRowKeyColumnNames() );
      }
      // We have a to-one on the main side
      else if ( propertyType != null ) {
        collectionMetadataKey.setAssociationKind( propertyType.isEntityType() ? AssociationKind.ASSOCIATION : AssociationKind.EMBEDDED );
        if ( propertyType instanceof EntityType ) {
          EntityType entityType = (EntityType) propertyType;
          OgmEntityPersister associatedPersister = (OgmEntityPersister) entityType.getAssociatedJoinable( session.getFactory() );
          EntityKey entityKey = new EntityKey(
              associatedPersister.getTableName(),
              associatedPersister.getIdentifierColumnNames(),
              columnValues
          );
          collectionMetadataKey.setOwnerEntityKey( entityKey );
          collectionMetadataKey.setRowKeyColumnNames( rowKeyColumnNames );
          collectionMetadataKey.setCollectionRole( getCollectionRoleFromToOne( associatedPersister ) );
View Full Code Here

Examples of org.hibernate.ogm.persister.OgmEntityPersister

      // If that's a OneToOne check the associated property name and see if it matches where we come from
      // we need to do that as OneToOne don't define columns
      OneToOneType oneToOneType = (OneToOneType) type;
      String associatedProperty = oneToOneType.getRHSUniqueKeyPropertyName();
      if ( associatedProperty != null ) {
        OgmEntityPersister mainSidePersister = (OgmEntityPersister) oneToOneType.getAssociatedJoinable( session.getFactory() );
        try {
          int propertyIndex = mainSidePersister.getPropertyIndex( associatedProperty );
          return mainSidePersister.getPropertyTypes()[propertyIndex] == propertyType;
        }
        catch ( HibernateException e ) {
          //not the right property
          //probably should not happen
        }
View Full Code Here

Examples of org.hibernate.ogm.persister.OgmEntityPersister

  public Object convertToPropertyType(String entityType, List<String> propertyPath, String value) {
    if ( propertyPath.size() > 1 ) {
      throw new UnsupportedOperationException( "Queries on embedded/associated entities are not supported yet." );
    }

    OgmEntityPersister persister = getPersister( entityType );

    Type propertyType = persister.getPropertyType( propertyPath.get( propertyPath.size() - 1 ) );

    if ( propertyType instanceof AbstractStandardBasicType ) {
      return ( (AbstractStandardBasicType<?>) propertyType ).fromString( value );
    }
    else {
View Full Code Here

Examples of org.hibernate.ogm.persister.OgmEntityPersister

      return value;
    }
  }

  public String getColumnName(String entityType, String propertyName) {
    OgmEntityPersister persister = getPersister( entityType );

    String columnName = propertyName;

    if ( columnName.equals( persister.getIdentifierPropertyName() ) ) {
      columnName = MongoDBDialect.ID_FIELDNAME;
    }
    else {
      String[] columnNames = persister.getPropertyColumnNames( columnName );
      columnName = columnNames[0];
    }

    return columnName;
  }
View Full Code Here

Examples of org.hibernate.ogm.persister.OgmEntityPersister

      Serializable id,
      Object optionalObject,
      SessionImplementor session,
      LockOptions lockOptions,
      OgmLoadingContext ogmLoadingContext) {
    final OgmEntityPersister currentPersister = entityPersisters[0];
    if ( log.isDebugEnabled() ) {
      if ( id != null ) {
        log.debug(
            "loading entity: " +
            MessageHelper.infoString( currentPersister, id, currentPersister.getIdentifierType(), session.getFactory() )
          );
      }
      else {
        log.debug(
            "loading entities from list of tuples: " +
            MessageHelper.infoString( currentPersister, id, currentPersister.getIdentifierType(), session.getFactory() )
        );
      }
    }
    QueryParameters qp = new QueryParameters();
    qp.setPositionalParameterTypes( new Type[] { currentPersister.getIdentifierType() } );
    qp.setPositionalParameterValues( new Object[] { id } );
    qp.setOptionalObject( optionalObject );
    qp.setOptionalEntityName( currentPersister.getEntityName() );
    qp.setOptionalId( id );
    qp.setLockOptions( lockOptions );

    List<Object> result = doQueryAndInitializeNonLazyCollections(
        session,
View Full Code Here

Examples of org.hibernate.ogm.persister.OgmEntityPersister

    if (keys.length == 0) {
      //do nothing, this is a collection
    }
    else {
      if (optionalId == null) {
        final OgmEntityPersister currentPersister = entityPersisters[0];
        Tuple tuple =  ogmLoadingContext.getResultSet().getTuple();
        GridType gridIdentifierType = currentPersister.getGridIdentifierType();
        optionalId = (Serializable) gridIdentifierType.nullSafeGet( tuple, currentPersister.getIdentifierColumnNames(), session, null );
      }
      final org.hibernate.engine.spi.EntityKey key = session.generateEntityKey( optionalId,  entityPersisters[0] );
      keys[0] = key;
    }
  }
View Full Code Here

Examples of org.hibernate.ogm.persister.OgmEntityPersister

    }

    //TODO this if won't work when we will support collections inside the entity tuple but that will do for now
    final TupleAsMapResultSet resultset = new TupleAsMapResultSet();
    if ( getEntityPersisters().length > 0 ) {
      OgmEntityPersister persister = getEntityPersisters()[0];
      final EntityKey key = EntityKeyBuilder.fromPersister( persister, id, session );
      Tuple entry = gridDialect.getTuple( key, persister.getTupleContext() );
      if ( entry != null ) {
        resultset.addTuple( entry );
      }
    }
    else {
      //collection persister
      if ( getCollectionPersisters().length != 1 ) {
        throw new AssertionFailure( "Found an unexpected number of collection persisters: " + getCollectionPersisters().length );
      }
      final OgmCollectionPersister persister = (OgmCollectionPersister) getCollectionPersisters()[0];
      AssociationPersister associationPersister = new AssociationPersister(
          persister.getOwnerEntityPersister().getMappedClass()
        )
        .gridDialect( gridDialect )
        .key( id )
        .keyGridType( persister.getKeyGridType() )
        .collectionPersister( persister )
        .associationKeyMetadata( persister.getAssociationKeyMetadata() )
        .session( session );
      Association assoc = associationPersister.getAssociationOrNull();
      if ( assoc != null ) {
        for ( RowKey rowKey : assoc.getKeys() ) {
          resultset.addTuple( assoc.get( rowKey ) );
View Full Code Here

Examples of org.hibernate.ogm.persister.OgmEntityPersister

  throws HibernateException {

    final Serializable id = key.getIdentifier();

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

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

    //FIXME figure out what that means and what value should be set
    //boolean eagerPropertyFetch = isEagerPropertyFetchEnabled(i);
    boolean eagerPropertyFetch = true;

    // 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
    );

    //TODO what to do with that in OGM
//    //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(
        resultset,
        id,
        object,
        rootPersister,
        //cols,
        eagerPropertyFetch,
        session
      );

    if ( persister.hasRowId() ) {
      throw new HibernateException( "Hibernate OGM does nto support row id");
    }
    final Object rowId = 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

Examples of org.hibernate.ogm.persister.impl.OgmEntityPersister

      Neo4jQueryResolverDelegate resolverDelegate) {
    return SingleEntityQueryBuilder.getInstance( new Neo4jPredicateFactory( propertyHelper, resolverDelegate ), propertyHelper );
  }

  private EntityKeyMetadata getKeyMetaData(Class<?> entityType) {
    OgmEntityPersister persister = (OgmEntityPersister) ( sessionFactory ).getEntityPersister( entityType.getName() );
    return new EntityKeyMetadata( persister.getTableName(), persister.getRootTableIdentifierColumnNames() );
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.