private static boolean emptyNode(EntityKey entityKey) { for ( Object value : entityKey.getColumnValues() ) { if ( value != null ) { return false; } } return true; }
private static boolean emptyNode(EntityKey entityKey) { for ( Object value : entityKey.getColumnValues() ) { if ( value != null ) { return false; } } return true; }
protected Map<String, Object> multiGetParams(EntityKey[] keys) { // We assume only one metadata type int numberOfColumnNames = keys[0].getColumnNames().length; int numberOfParams = keys.length * numberOfColumnNames; int counter = 0; Map<String, Object> params = new HashMap<>( numberOfParams ); for ( int row = 0; row < keys.length; row++ ) { for ( int col = 0; col < keys[row].getColumnValues().length; col++ ) { params.put( String.valueOf( counter++ ), keys[row].getColumnValues()[col] ); } } return params; }
private void saveToOneAssociations(List<Statement> statements, EntityKey key, final Map<String, EntityKey> toOneAssociations, TupleContext tupleContext) { for ( Map.Entry<String, EntityKey> entry : toOneAssociations.entrySet() ) { Statement statement = getEntityQueries( key.getMetadata(), tupleContext ).getUpdateOneToOneAssociationStatement( entry.getKey(), key.getColumnValues(), entry.getValue().getColumnValues() ); statements.add( statement ); } }
private void updateTuple(EntityKey key, List<Statement> statements, Map<String, Object> properties, TupleContext tupleContext) { if ( !properties.isEmpty() ) { Statement statement = getEntityQueries( key.getMetadata(), tupleContext ).getUpdateEntityPropertiesStatement( key.getColumnValues(), properties ); statements.add( statement ); } }
SerializableEntityKey(EntityKey key) { columnNames = key.getColumnNames(); columnValues = key.getColumnValues(); table = key.getTable(); }
protected Object[] createRelationshipForEmbeddedQueryValues(AssociationKey associationKey, EntityKey embeddedKey) { String collectionRole = associationKey.getMetadata().getCollectionRole(); Object[] columnValues = associationKey.getEntityKey().getColumnValues(); if ( isCollectionOfPrimitives( collectionRole, embeddedKey.getColumnNames() ) ) { return ArrayHelper.concat( columnValues, embeddedKey.getColumnValues()[0] ); } else { return ArrayHelper.concat( columnValues, embeddedKey.getColumnValues() ); } }
private ClosableIterator<NodeWithEmbeddedNodes> singlePropertyIdFindEntities(HttpNeo4jClient executionEngine, EntityKey[] keys, Long txId) { Object[] paramsValues = new Object[keys.length]; for ( int i = 0; i < keys.length; i++ ) { paramsValues[i] = keys[i].getColumnValues()[0]; } Map<String, Object> params = Collections.singletonMap( "0", (Object) paramsValues ); Statements statements = new Statements(); statements.addStatement( multiGetQuery, params, Statement.AS_GRAPH ); List<StatementResult> results = executeQuery( executionEngine, txId, statements ); return closableIterator( results, keys ); }
/** * Removes the relationship(s) representing the given association. If the association refers to an embedded entity * (collection), the referenced entities are removed as well. * * @param executionEngine the {@link GraphDatabaseService} used to run the query * @param associationKey represents the association */ public void removeAssociation(GraphDatabaseService executionEngine, AssociationKey associationKey) { executionEngine.execute( removeAssociationQuery, params( associationKey.getEntityKey().getColumnValues() ) ); }
/** * Removes the relationship(s) representing the given association. If the association refers to an embedded entity * (collection), the referenced entities are removed as well. * * @param executionEngine the {@link GraphDatabaseService} used to run the query * @param associationKey represents the association */ @Override public void removeAssociation(GraphDatabaseService executionEngine, AssociationKey associationKey) { executionEngine.execute( removeAssociationQuery, params( associationKey.getEntityKey().getColumnValues() ) ); }
public Relationship findRelationship(HttpNeo4jClient dataBase, Long txId, AssociationKey associationKey, RowKey rowKey) { Object[] relationshipValues = relationshipValues( associationKey, rowKey ); Object[] queryValues = ArrayHelper.concat( associationKey.getEntityKey().getColumnValues(), relationshipValues ); Graph result = executeQuery( dataBase, txId, findRelationshipQuery, params( queryValues ) ); if ( result != null ) { if ( result.getRelationships().size() > 0 ) { return result.getRelationships().get( 0 ); } } return null; }
public void removeAssociationRow(HttpNeo4jClient database, Long txId, AssociationKey associationKey, RowKey rowKey) { Object[] relationshipValues = relationshipValues( associationKey, rowKey ); Object[] queryValues = ArrayHelper.concat( associationKey.getEntityKey().getColumnValues(), relationshipValues ); executeQuery( database, txId, removeAssociationRowQuery, params( queryValues ) ); }
private Relationship findOrCreateRelationshipWithEntityNode(AssociationKey associationKey, AssociationContext associationContext, AssociationOperation action) { Tuple associationRow = action.getValue(); EntityKey ownerKey = associationKey.getEntityKey(); AssociatedEntityKeyMetadata associatedEntityKeyMetadata = associationContext.getAssociationTypeContext().getAssociatedEntityKeyMetadata(); EntityKey targetKey = getEntityKey( associationRow, associatedEntityKeyMetadata ); Object[] relationshipProperties = relationshipProperties( associationKey, associationRow ); Transaction txId = transaction( associationContext ); return getAssociationQueries( associationKey.getMetadata() ) .createRelationship( txId, ownerKey.getColumnValues(), targetKey.getColumnValues(), relationshipProperties ); }
/** * Remove an association row * * @param executionEngine the {@link GraphDatabaseService} used to run the query * @param associationKey represents the association * @param rowKey represents a row in an association */ public void removeAssociationRow(GraphDatabaseService executionEngine, AssociationKey associationKey, RowKey rowKey) { Object[] relationshipValues = relationshipValues( associationKey, rowKey ); Object[] queryValues = ArrayHelper.concat( associationKey.getEntityKey().getColumnValues(), relationshipValues ); executionEngine.execute( removeAssociationRowQuery, params( queryValues ) ); }
private Relationship findOrCreateRelationshipWithEntityNode(AssociationKey associationKey, Tuple associationRow, AssociatedEntityKeyMetadata associatedEntityKeyMetadata, TupleTypeContext tupleTypeContext) { EntityKey targetEntityKey = getEntityKey( associationRow, associatedEntityKeyMetadata ); Node targetNode = getEntityQueries( targetEntityKey.getMetadata(), (TupleTypeContext) null ).findEntity( dataBase, targetEntityKey.getColumnValues() ); return createRelationshipWithTargetNode( associationKey, associationRow, tupleTypeContext, targetNode ); }
public Relationship findRelationship(Transaction tx, AssociationKey associationKey, RowKey rowKey) { Object[] relationshipValues = relationshipValues( associationKey, rowKey ); Object[] queryValues = ArrayHelper.concat( associationKey.getEntityKey().getColumnValues(), relationshipValues ); StatementResult result = tx.run( findRelationshipQuery, params( queryValues ) ); return relationship( result ); }
@Override public void removeTuple(EntityKey key, TupleContext tupleContext) { Long txId = transactionId( tupleContext.getTransactionContext() ); getEntityQueries( key.getMetadata(), tupleContext.getTupleTypeContext() ).removeEntity( client, txId, key.getColumnValues() ); }
@Override public void removeTuple(EntityKey key, TupleContext tupleContext) { final String cacheName = cacheName( key ); log.debugf( "removeTuple for key '%s' on cache '%s'", key, cacheName ); ProtoStreamMappingAdapter mapper = provider.getDataMapperForCache( cacheName ); ProtostreamId idBuffer = mapper.createIdPayload( key.getColumnNames(), key.getColumnValues() ); mapper.withinCacheEncodingContext( c -> c.remove( idBuffer ) ); }
private Relationship createRelationshipWithTargetNode(AssociationKey associationKey, Tuple associationRow, TupleTypeContext tupleTypeContext, Node targetNode) { EntityKey entityKey = associationKey.getEntityKey(); Node ownerNode = getEntityQueries( entityKey.getMetadata(), tupleTypeContext ).findEntity( dataBase, entityKey.getColumnValues() ); Relationship relationship = ownerNode.createRelationshipTo( targetNode, withName( associationKey.getMetadata().getCollectionRole() ) ); applyProperties( associationKey, associationRow, relationship ); return relationship; }
@Override public Association getAssociation(AssociationKey associationKey, AssociationContext associationContext) { EntityKey entityKey = associationKey.getEntityKey(); Long transactionId = transactionId( associationContext.getTransactionContext() ); NodeWithEmbeddedNodes node = getEntityQueries( entityKey.getMetadata(), associationContext.getTupleTypeContext() ).findEntity( client, transactionId, entityKey.getColumnValues() ); if ( node == null ) { return null; } Map<RowKey, Tuple> tuples = createAssociationMap( associationKey, associationContext, entityKey, associationContext.getTransactionContext() ); return new Association( new RemoteNeo4jAssociationSnapshot( tuples ) ); }