Package org.hibernate.ogm.datastore.spi

Examples of org.hibernate.ogm.datastore.spi.Tuple


    return IdSourceKey.forTable( generatorKeyMetadata, segmentName );
  }

  private Object nullSafeSet(GridType type, Object value, String columnName, SessionImplementor session) {
    Tuple tuple = new Tuple();
    type.nullSafeSet( tuple, value, new String[] { columnName }, session );
    return tuple.get( columnName );
  }
View Full Code Here


  @Override
  public Object readKey(ResultSet rs, String[] aliases, SessionImplementor session)
      throws HibernateException, SQLException {
    final TupleAsMapResultSet resultset = rs.unwrap( TupleAsMapResultSet.class );
    final Tuple keyTuple = resultset.getTuple();
    return keyGridType.nullSafeGet( keyTuple, aliases, session, null );
  }
View Full Code Here

  // At the moment we only support the case where one entity type is returned
  private List<Object> listOfEntities(SessionImplementor session, Type[] resultTypes, ClosableIterator<Tuple> tuples) {
    List<Object> results = new ArrayList<Object>();
    Class<?> returnedClass = resultTypes[0].getReturnedClass();
    while ( tuples.hasNext() ) {
      Tuple tuple = tuples.next();
      OgmLoader loader = createLoader( session, returnedClass );
      results.add( entity( session, tuple, loader ) );
    }
    return results;
  }
View Full Code Here

  }

  private List<Object> listOfArrays(SessionImplementor session, Iterator<Tuple> tuples) {
    List<Object> results = new ArrayList<Object>();
    while ( tuples.hasNext() ) {
      Tuple tuple = tuples.next();
      Object[] entry = null;
      if ( !customQuery.getCustomQueryReturns().isEmpty() ) {
        entry = new Object[customQuery.getCustomQueryReturns().size()];
        int i = 0;
        for ( Return queryReturn : customQuery.getCustomQueryReturns() ) {
          ScalarReturn scalarReturn = (ScalarReturn) queryReturn;
          Type type = scalarReturn.getType();

          if ( type != null ) {
            GridType gridType = typeTranslator.getType( type );
            entry[i++] = gridType.nullSafeGet( tuple, scalarReturn.getColumnAlias(), session, null );
          }
          else {
            entry[i++] = tuple.get( scalarReturn.getColumnAlias() );
          }
        }
      }
      else {
        // TODO OGM-564 As a temporary work-around, retrieving the names from the actual result in case there
        // are no query returns defined (no result mapping has been given for a native query). Actually we
        // should drive this based on the selected columns as otherwise the order might not be correct and/or
        // null values will not show up
        entry = new Object[tuple.getColumnNames().size()];
        int i = 0;
        for ( String column : tuple.getColumnNames() ) {
          entry[i++] = tuple.get( column );
        }
      }

      if ( entry.length == 1 ) {
        results.add( entry[0] );
View Full Code Here

  @Override
  public Object readElement(ResultSet rs, Object owner, String[] aliases, SessionImplementor session)
      throws HibernateException, SQLException {
    final TupleAsMapResultSet resultset = rs.unwrap( TupleAsMapResultSet.class );
    final Tuple keyTuple = resultset.getTuple();
    return elementGridType.nullSafeGet( keyTuple, aliases, session, owner );
  }
View Full Code Here

  @Override
  public Object readIdentifier(ResultSet rs, String alias, SessionImplementor session)
      throws HibernateException, SQLException {
    final TupleAsMapResultSet resultset = rs.unwrap( TupleAsMapResultSet.class );
    final Tuple keyTuple = resultset.getTuple();
    return identifierGridType.nullSafeGet( keyTuple, alias, session, null );
  }
View Full Code Here

  @Override
  public Object readIndex(ResultSet rs, String[] aliases, SessionImplementor session)
      throws HibernateException, SQLException {
    final TupleAsMapResultSet resultset = rs.unwrap( TupleAsMapResultSet.class );
    final Tuple keyTuple = resultset.getTuple();
    return indexGridType.nullSafeGet( keyTuple, aliases, session, null );
  }
View Full Code Here

    while ( entries.hasNext() ) {
      Object entry = entries.next();
      if ( collection.needsUpdating( entry, i, elementType ) ) {
        // find the matching element
        RowKey assocEntryKey = getTupleKeyForUpdate( key, collection, session, i, entry, associationPersister );
        Tuple assocEntryTuple = associationPersister.getAssociation().get( assocEntryKey );
        if ( assocEntryTuple == null ) {
          throw new AssertionFailure( "Updating a collection tuple that is not present: " + "table {" + getTableName() + "} collectionKey {" + key + "} entry {" + entry + "}" );
        }
        // update the matching element
        // FIXME update the associated entity key data
View Full Code Here

  }

  private RowKeyAndTuple createAndPutTupleforInsert(Serializable key, PersistentCollection collection,
      AssociationPersister associationPersister, SessionImplementor session, int i, Object entry) {
    RowKeyBuilder rowKeyBuilder = initializeRowKeyBuilder();
    Tuple tuple = new Tuple();
    if ( hasIdentifier ) {
      final Object identifier = collection.getIdentifier( entry, i );
      String[] names = { getIdentifierColumnName() };
      identifierGridType.nullSafeSet( tuple, identifier, names, session );
    }
    getKeyGridType().nullSafeSet( tuple, key, getKeyColumnNames(), session );
    // No need to write to where as we don't do where clauses in OGM :)
    if ( hasIndex ) {
      Object index = collection.getIndex( entry, i, this );
      indexGridType.nullSafeSet( tuple, incrementIndexByBase( index ), getIndexColumnNames(), session );
    }
    else {
      // use element as tuple key
      final Object element = collection.getElement( entry );
      getElementGridType().nullSafeSet( tuple, element, getElementColumnNames(), session );

    }

    RowKeyAndTuple result = new RowKeyAndTuple();
    EntityKey entityKey = associationPersister.createTargetKey( rowKeyBuilder.getColumnNames(), tuple );
    result.key = rowKeyBuilder.values( tuple ).entityKey( entityKey ).build();

    Tuple assocEntryTuple = associationPersister.createAndPutAssociationTuple( result.key );
    for ( String column : tuple.getColumnNames() ) {
      assocEntryTuple.put( column, tuple.get( column ) );
    }
    result.tuple = assocEntryTuple;
    return result;
  }
View Full Code Here

    return builder;
  }

  private RowKey getTupleKeyForUpdate(Serializable key, PersistentCollection collection, SessionImplementor session, int i, Object entry, AssociationPersister associationPersister) {
    RowKeyBuilder rowKeyBuilder = initializeRowKeyBuilder();
    Tuple tuple = new Tuple();
    if ( hasIdentifier ) {
      final Object identifier = collection.getIdentifier( entry, i );
      String[] names = { getIdentifierColumnName() };
      identifierGridType.nullSafeSet( tuple, identifier, names, session );
    }
View Full Code Here

TOP

Related Classes of org.hibernate.ogm.datastore.spi.Tuple

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.