private StatementResult runStatement(@Name("kernelTransaction") String statement, Session session, Map<String, Object> finalParams, boolean read) { if (read) return session.readTransaction((Transaction tx) -> tx.run(statement, finalParams)); else return session.writeTransaction((Transaction tx) -> tx.run(statement, finalParams)); }
StatementResult executeCypher(String query, Map<String, Object> params) { if (logCypher) { System.out.format("\n:: CYPHER ::\n%s\n", query); System.out.format(":: DATA ::\n%s\n", params); } StatementResult statementResult = neo4jTransaction.run(query, params); return statementResult; } }
private StatementResult runAll(Transaction tx, List<Statement> statements) { StatementResult result = null; for ( Statement statement : statements ) { result = tx.run( statement ); validate( result ); } return result; }
private void runAll(Transaction tx, List<Statement> statements) { for ( Statement statement : statements ) { StatementResult result = tx.run( statement ); validate( result ); } }
private void runAll(Transaction tx, List<Statement> statements) { List<StatementResult> results = new ArrayList<>(); for ( Statement statement : statements ) { StatementResult result = tx.run( statement ); validate( result ); results.add( result ); } }
private StatementResult createNode(Transaction tx, String label, ObjectMap properties) { // Gathering properties of the node to create a cypher string with them List<String> props = new ArrayList<>(); for (String key : properties.keySet()) { props.add(key + ":\"" + properties.getString(key) + "\""); } String propsJoined = "{" + String.join(",", props) + "}"; // Creating the desired node return tx.run("CREATE (n:" + label + " " + propsJoined + ") RETURN ID(n) AS ID, LABELS(n) AS LABELS"); }
private StatementResult getNode(Transaction tx, String label, ObjectMap properties) { // Gathering properties of the node to create a cypher string with them List<String> props = new ArrayList<>(); for (String key : properties.keySet()) { props.add(key + ":\"" + properties.getString(key) + "\""); } String propsJoined = "{" + String.join(",", props) + "}"; // Getting the desired node return tx.run("MATCH (n:" + label + " " + propsJoined + ") RETURN ID(n) AS ID, LABELS(n) AS LABELS"); }
public ClosableIterator<NodeWithEmbeddedNodes> findEntitiesWithEmbedded(Transaction tx) { StatementResult results = tx.run( getFindEntitiesQuery() ); return closableIterator( results ); }
private ClosableIterator<NodeWithEmbeddedNodes> singlePropertyIdFindEntities(EntityKey[] keys, Transaction tx) { 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 ); Statement statement = new Statement( multiGetQuery, params ); StatementResult statementResult = tx.run( statement ); return closableIterator( statementResult, keys ); }
public Relationship createRelationship(Transaction tx, Object[] ownerKeyValues, Object[] targetKeyValues, Object[] relationshipProperties) { Object[] concat = ArrayHelper.concat( Arrays.asList( ownerKeyValues, targetKeyValues, relationshipProperties ) ); Map<String, Object> params = params( concat ); StatementResult statementResult = tx.run( createRelationshipQuery, params ); return relationship( statementResult ); }
private ClosableIterator<NodeWithEmbeddedNodes> multiPropertiesIdFindEntities(EntityKey[] keys, Transaction tx) { String query = getMultiGetQueryCacheQuery( keys ); Map<String, Object> params = multiGetParams( keys ); StatementResult results = tx.run( query, params ); return closableIterator( results ); }
public void removeToOneAssociation(Transaction tx, Object[] columnValues, String associationRole) { Map<String, Object> params = params( ArrayHelper.concat( columnValues, associationRole ) ); tx.run( getRemoveToOneAssociation(), params ); }
public Relationship createRelationshipForEmbeddedAssociation(Transaction tx, AssociationKey associationKey, EntityKey embeddedKey, Object[] relationshipProperties) { String query = initCreateEmbeddedAssociationQuery( associationKey, embeddedKey ); Object[] queryValues = createRelationshipForEmbeddedQueryValues( associationKey, embeddedKey, relationshipProperties ); StatementResult statementResult = tx.run( query, params( queryValues ) ); return relationship( statementResult ); }
private StatementResult executeRequest(Statement request) { try { Map<String, Object> parameterMap = this.parameterConversion.convertParameters(request.getParameters()); String cypher = cypherModification.apply(request.getStatement()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Request: {} with params {}", cypher, parameterMap); } BoltTransaction tx = (BoltTransaction) transactionManager.getCurrentTransaction(); return tx.nativeBoltTransaction().run(cypher, parameterMap); } catch (ClientException | DatabaseException | TransientException ce) { throw new CypherException(ce.code(), ce.getMessage(), ce); } } }
private StatementResult executeRequest(Statement request) { try { Map<String, Object> parameterMap = parameterConversion.convertParameters(request.getParameters()); String cypher = cypherModification.apply(request.getStatement()); if(LOGGER.isDebugEnabled()) { LOGGER.debug("Request: {} with params {}", cypher, parameterMap); } BoltTransaction tx = (BoltTransaction) transactionManager.getCurrentTransaction(); return tx.nativeBoltTransaction().run(cypher, parameterMap); } catch (ClientException | DatabaseException | TransientException ce) { throw new CypherException(ce.code(), ce.getMessage(), ce); } } }
public void removeAssociationRow(Transaction tx, AssociationKey associationKey, RowKey rowKey) { Object[] relationshipValues = relationshipValues( associationKey, rowKey ); Object[] queryValues = ArrayHelper.concat( associationKey.getEntityKey().getColumnValues(), relationshipValues ); tx.run( removeAssociationRowQuery, params( queryValues ) ); } }
public Node findAssociatedEntity(Transaction tx, Object[] keyValues, String associationrole) { Map<String, Object> params = params( keyValues ); String query = getFindAssociatedEntityQuery( associationrole ); if ( query != null ) { StatementResult statementResult = tx.run( query, params ); if ( statementResult.hasNext() ) { return statementResult.single().get( 0 ).asNode(); } } return null; }
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 ); }
public static ServerVersion version( Driver driver ) { try ( Session session = driver.session() ) { String versionString = session.readTransaction( tx -> tx.run( "RETURN 1" ).consume().server().version() ); return version( versionString ); } }
@Override public int executeBackendUpdateQuery(BackendQuery<String> query, QueryParameters queryParameters, TupleContext tupleContext) { Map<String, Object> parameters = getParameters( queryParameters ); String nativeQuery = buildNativeQuery( query, queryParameters ); Statement statement = new Statement( nativeQuery, parameters ); Transaction transaction = transaction( tupleContext ); StatementResult statementResult = transaction.run( statement ); validateNativeQuery( statementResult ); ResultSummary summary = statementResult.consume(); return updatesCount( summary ); }