new EntityKey( (Integer) typeToValueMap.get(TypeId.PLAYER), (Integer) typeToValueMap.get(TypeId.PLATFORM)),
@Override public EntityKey readObject(ObjectInput input) throws IOException, ClassNotFoundException { VersionChecker.readAndCheckVersion( input, VERSION, EntityKey.class ); String tableName = input.readUTF(); String[] columnNames = (String[]) input.readObject(); Object[] values = (Object[]) input.readObject(); return new EntityKey( new DefaultEntityKeyMetadata( tableName, columnNames ), values ); }
@Override public EntityKey readObject(ObjectInput input) throws IOException, ClassNotFoundException { VersionChecker.readAndCheckVersion( input, VERSION, EntityKey.class ); String tableName = input.readUTF(); String[] columnNames = (String[]) input.readObject(); Object[] values = (Object[]) input.readObject(); return new EntityKey( new DefaultEntityKeyMetadata( tableName, columnNames ), values ); }
public static EntityKey fromData( EntityKeyMetadata entityKeyMetadata, GridType identifierGridType, final Serializable id, SharedSessionContractImplementor session) { Object[] values = LogicalPhysicalConverterHelper.getColumnsValuesFromObjectValue( id, identifierGridType, entityKeyMetadata.getColumnNames(), session ); return new EntityKey( entityKeyMetadata, values ); }
private EntityKey key(BoardGame boardGame) { Object[] values = { boardGame.getId() }; return new EntityKey( METADATA, values ); }
/** * Returns the key of the entity targeted by the represented association, retrieved from the given tuple. * * @param tuple the tuple from which to retrieve the referenced entity key * @return the key of the entity targeted by the represented association */ protected EntityKey getEntityKey(Tuple tuple, AssociatedEntityKeyMetadata associatedEntityKeyMetadata) { Object[] columnValues = new Object[ associatedEntityKeyMetadata.getAssociationKeyColumns().length]; int i = 0; for ( String associationKeyColumn : associatedEntityKeyMetadata.getAssociationKeyColumns() ) { columnValues[i] = tuple.get( associationKeyColumn ); i++; } return new EntityKey( associatedEntityKeyMetadata.getEntityKeyMetadata(), columnValues ); }
private EntityKey key(BoardGame boardGame) { Object[] values = { boardGame.getName(), boardGame.getPublisher() }; return new EntityKey( METADATA, values ); }
public AssociationKey getAssociationKey() { if ( associationKey == null ) { final Object[] columnValues = getKeyColumnValues(); EntityKey ownerEntityKey; if ( key != null ) { ownerEntityKey = EntityKeyBuilder.fromPersister( (OgmEntityPersister) getHostingEntityPersister(), (Serializable) key, session ); } else { ownerEntityKey = new EntityKey( ( (OgmEntityPersister) getHostingEntityPersister() ).getEntityKeyMetadata(), columnValues ); } associationKey = new AssociationKey( associationKeyMetadata, columnValues, ownerEntityKey ); } return associationKey; }
/** * Returns the entity key on the other side of association row represented by the given row key. * <p> * <b>Note:</b> May only be invoked if the row key actually contains all the columns making up that entity key. * Specifically, it may <b>not</b> be invoked if the association has index columns (maps, ordered collections), as * the entity key columns will not be part of the row key in this case. */ private EntityKey getEntityKey(AssociationKey associationKey, RowKey rowKey) { String[] associationKeyColumns = associationKey.getMetadata().getAssociatedEntityKeyMetadata().getAssociationKeyColumns(); Object[] columnValues = new Object[associationKeyColumns.length]; int i = 0; for ( String associationKeyColumn : associationKeyColumns ) { columnValues[i] = rowKey.getColumnValue( associationKeyColumn ); i++; } EntityKeyMetadata entityKeyMetadata = associationKey.getMetadata().getAssociatedEntityKeyMetadata().getEntityKeyMetadata(); return new EntityKey( entityKeyMetadata, columnValues ); }
/** * Returns the entity key on the other side of association row represented by the given row key. * <p> * <b>Note:</b> May only be invoked if the row key actually contains all the columns making up that entity key. * Specifically, it may <b>not</b> be invoked if the association has index columns (maps, ordered collections), as * the entity key columns will not be part of the row key in this case. */ private EntityKey getEntityKey(AssociationKey associationKey, RowKey rowKey) { String[] associationKeyColumns = associationKey.getMetadata().getAssociatedEntityKeyMetadata().getAssociationKeyColumns(); Object[] columnValues = new Object[associationKeyColumns.length]; int i = 0; for ( String associationKeyColumn : associationKeyColumns ) { columnValues[i] = rowKey.getColumnValue( associationKeyColumn ); i++; } EntityKeyMetadata entityKeyMetadata = associationKey.getMetadata().getAssociatedEntityKeyMetadata().getEntityKeyMetadata(); return new EntityKey( entityKeyMetadata, columnValues ); }
private EntityKey key(BoardGame boardGame) { Object[] values = { boardGame.getId().getName(), boardGame.getId().getPublisher() }; return new EntityKey( METADATA, values ); }
private void removeNavigationalInformationFromInverseSide(int propertyIndex, AssociationKeyMetadata associationKeyMetadata, Object[] oldColumnValue) { // If the association involves entities deleted by a previous operation of the current batch, // it does not make sense trying to update association itself EntityKey entityKey = new EntityKey( associationKeyMetadata.getEntityKeyMetadata(), oldColumnValue ); if ( gridDialect instanceof BatchOperationsDelegator && ( (BatchOperationsDelegator) gridDialect ).isMarkedForRemoval( entityKey ) ) { return; } AssociationPersister associationPersister = createInverseAssociationPersister( propertyIndex, associationKeyMetadata, oldColumnValue ); Association association = associationPersister.getAssociationOrNull(); // The association might be empty if the navigation information have already been removed. // This typically happens when the entity owning the inverse association has already been deleted prior to // deleting the entity owning the association and a {@code @NotFound(action = NotFoundAction.IGNORE)} is // involved. if ( association != null && !association.isEmpty() ) { RowKey rowKey = getInverseRowKey( associationKeyMetadata, oldColumnValue ); association.remove( rowKey ); associationPersister.flushToDatastore(); } }
keys[i] = new EntityKey( entityKeyMetadata, values );
entityKeys.add( new EntityKey( entityKeyMetadata, columnValues ) );
@Test public void testLoadingFromTuple() throws Exception { final Session session = openSession(); Transaction transaction = session.beginTransaction(); Feeling feeling = new Feeling(); feeling.setName( "Moody" ); session.persist( feeling ); transaction.commit(); session.clear(); transaction = session.beginTransaction(); EntityKey key = new EntityKey( new DefaultEntityKeyMetadata( "Feeling", new String[] { "UUID" } ), new Object[] { feeling.getUUID() } ); Map<String, Object> entityTuple = extractEntityTuple( session, key ); final Tuple tuple = new Tuple( new MapTupleSnapshot( entityTuple ), SnapshotType.UPDATE ); EntityPersister persister = ( (SessionFactoryImplementor) session.getSessionFactory() ) .getMetamodel().entityPersister( Feeling.class ); OgmLoader loader = new OgmLoader( new OgmEntityPersister[] { (OgmEntityPersister) persister }, 1 ); OgmLoadingContext ogmLoadingContext = new OgmLoadingContext(); List<Tuple> tuples = new ArrayList<Tuple>(); tuples.add( tuple ); ogmLoadingContext.setTuples( tuples ); List<Object> entities = loader.loadEntitiesFromTuples( (SessionImplementor) session, LockOptions.NONE, ogmLoadingContext ); assertThat( entities.size() ).isEqualTo( 1 ); assertThat( ( (Feeling) entities.get( 0 ) ).getName() ).isEqualTo( "Moody" ); transaction.commit(); session.close(); }
private EntityKey getPrinterEntityKey(UUID id) { GridType uuidType = ( (SessionFactoryImplementor) sessionFactory ).getServiceRegistry(). getService( TypeTranslator.class ). getType( StandardBasicTypes.UUID_BINARY ); Tuple dummy = new Tuple(); uuidType.nullSafeSet( dummy, id, new String[] { "id" }, null ); return new EntityKey( new DefaultEntityKeyMetadata( "Printer", new String[] { "id" } ), new Object[]{ dummy.get( "id" ) } ); }