Skip to content

4.0 renames #651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ To run a simple query, the following can be used:
```java
Driver driver = GraphDatabase.driver("bolt://localhost:7687", AuthTokens.basic("neo4j", "PasSW0rd"));
try (Session session = driver.session()) {
StatementResult rs = session.run("CREATE (n) RETURN n");
Result result = session.run("CREATE (n) RETURN n");
}
driver.close();
```
Expand Down
2 changes: 1 addition & 1 deletion driver/src/main/java/org/neo4j/driver/Bookmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* the database is as up-to-date as the latest transaction referenced by the supplied bookmarks.
*
* Within a session, bookmark propagation is carried out automatically.
* Thus all transactions in a session including explicit and implicit transactions are ensured to be carried out one after another.
* Thus all transactions in a session (both managed and unmanaged) are guaranteed to be carried out one after another.
*
* To opt out of this mechanism for unrelated units of work, applications can use multiple sessions.
*/
Expand Down
2 changes: 1 addition & 1 deletion driver/src/main/java/org/neo4j/driver/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public interface Driver extends AutoCloseable
* This will return the type system supported by the driver.
* The types supported on a particular server a session is connected against might not contain all of the types defined here.
*
* @return type system used by this statement runner for classifying values
* @return type system used by this query runner for classifying values
*/
@Experimental
TypeSystem defaultTypeSystem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,29 @@
import static org.neo4j.driver.Values.value;

/**
* An executable statement, i.e. the statements' text and its parameters.
* The components of a Cypher query, containing the query text and parameter map.
*
* @see Session
* @see Transaction
* @see StatementResult
* @see StatementResult#consume()
* @see Result
* @see Result#consume()
* @see ResultSummary
* @since 1.0
*/
@Immutable
public class Statement
public class Query
{
private final String text;
private final Value parameters;

/**
* Create a new statement.
* @param text the statement text
* @param parameters the statement parameters
* Create a new query.
* @param text the query text
* @param parameters the parameter map
*/
public Statement( String text, Value parameters )
public Query(String text, Value parameters )
{
this.text = validateQuery( text );
this.text = validateQueryText( text );
if( parameters == null )
{
this.parameters = Values.EmptyMap;
Expand All @@ -69,79 +69,79 @@ else if ( parameters instanceof MapValue )
}

/**
* Create a new statement.
* @param text the statement text
* @param parameters the statement parameters
* Create a new query.
* @param text the query text
* @param parameters the parameter map
*/
public Statement( String text, Map<String, Object> parameters )
public Query(String text, Map<String, Object> parameters )
{
this( text, Values.value( parameters ) );
}

/**
* Create a new statement.
* @param text the statement text
* Create a new query.
* @param text the query text
*/
public Statement( String text )
public Query(String text )
{
this( text, Values.EmptyMap );
}

/**
* @return the statement's text
* @return the query text
*/
public String text()
{
return text;
}

/**
* @return the statement's parameters
* @return the parameter map
*/
public Value parameters()
{
return parameters;
}

/**
* @param newText the new statement's text
* @return a new statement with updated text
* @param newText the new query text
* @return a new Query object with updated text
*/
public Statement withText( String newText )
public Query withText(String newText )
{
return new Statement( newText, parameters );
return new Query( newText, parameters );
}

/**
* @param newParameters the new statement's parameters
* @return a new statement with updated parameters
* @param newParameters the new parameter map
* @return a new Query object with updated parameters
*/
public Statement withParameters( Value newParameters )
public Query withParameters(Value newParameters )
{
return new Statement( text, newParameters );
return new Query( text, newParameters );
}

/**
* @param newParameters the new statement's parameters
* @return a new statement with updated parameters
* @param newParameters the new parameter map
* @return a new Query object with updated parameters
*/
public Statement withParameters( Map<String, Object> newParameters )
public Query withParameters(Map<String, Object> newParameters )
{
return new Statement( text, newParameters );
return new Query( text, newParameters );
}

/**
* Create a new statement with new parameters derived by updating this'
* statement's parameters using the given updates.
* Create a new query with new parameters derived by updating this'
* query's parameters using the given updates.
*
* Every update key that points to a null value will be removed from
* the new statement's parameters. All other entries will just replace
* any existing parameter in the new statement.
* the new query's parameters. All other entries will just replace
* any existing parameter in the new query.
*
* @param updates describing how to update the parameters
* @return a new statement with updated parameters
* @return a new query with updated parameters
*/
public Statement withUpdatedParameters( Value updates )
public Query withUpdatedParameters(Value updates )
{
if ( updates == null || updates.isEmpty() )
{
Expand Down Expand Up @@ -179,8 +179,8 @@ public boolean equals( Object o )
return false;
}

Statement statement = (Statement) o;
return text.equals( statement.text ) && parameters.equals( statement.parameters );
Query query = (Query) o;
return text.equals( query.text ) && parameters.equals( query.parameters );

}

Expand All @@ -195,13 +195,13 @@ public int hashCode()
@Override
public String toString()
{
return format( "Statement{text='%s', parameters=%s}", text, parameters );
return format( "Query{text='%s', parameters=%s}", text, parameters );
}

private static String validateQuery( String query )
private static String validateQueryText(String query )
{
checkArgument( query != null, "Cypher query should not be null" );
checkArgument( !query.isEmpty(), "Cypher query should not be an empty string" );
checkArgument( query != null, "Cypher query text should not be null" );
checkArgument( !query.isEmpty(), "Cypher query text should not be an empty string" );
return query;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@
import java.util.Map;

/**
* Common interface for components that can execute Neo4j statements.
* Common interface for components that can execute Neo4j queries.
*
* <h2>Important notes on semantics</h2>
* <p>
* Statements run in the same {@link StatementRunner} are guaranteed
* to execute in order, meaning changes made by one statement will be seen
* by all subsequent statements in the same {@link StatementRunner}.
* queries run in the same {@link QueryRunner} are guaranteed
* to execute in order, meaning changes made by one query will be seen
* by all subsequent queries in the same {@link QueryRunner}.
* <p>
* However, to allow handling very large results, and to improve performance,
* result streams are retrieved lazily from the network.
* This means that when any of {@link #run(Statement)}
* methods return a result, the statement has only started executing - it may not
* This means that when any of {@link #run(Query)}
* methods return a result, the query has only started executing - it may not
* have completed yet. Most of the time, you will not notice this, because the
* driver automatically waits for statements to complete at specific points to
* driver automatically waits for queries to complete at specific points to
* fulfill its contracts.
* <p>
* Specifically, the driver will ensure all outstanding statements are completed
* Specifically, the driver will ensure all outstanding queries are completed
* whenever you:
*
* <ul>
* <li>Read from or discard a result, for instance via
* {@link StatementResult#next()} or {@link StatementResult#consume()} </li>
* {@link Result#next()} or {@link Result#consume()} </li>
* <li>Explicitly commit/rollback a transaction using blocking {@link Transaction#close()} </li>
* <li>Close a session using blocking {@link Session#close()}</li>
* </ul>
Expand All @@ -59,13 +59,13 @@
* @see Transaction
* @since 1.0
*/
public interface StatementRunner
public interface QueryRunner
{
/**
* Run a statement and return a result stream.
* Run a query and return a result stream.
* <p>
* This method takes a set of parameters that will be injected into the
* statement by Neo4j. Using parameters is highly encouraged, it helps avoid
* query by Neo4j. Using parameters is highly encouraged, it helps avoid
* dangerous cypher injection attacks and improves database performance as
* Neo4j can re-use query plans more often.
* <p>
Expand All @@ -77,25 +77,25 @@ public interface StatementRunner
* might be more helpful, it converts your map to a {@link Value} for you.
*
* <h2>Example</h2>
* <pre class="doctest:StatementRunnerDocIT#parameterTest">
* <pre class="doctest:QueryRunnerDocIT#parameterTest">
* {@code
*
* StatementResult cursor = session.run( "MATCH (n) WHERE n.name = {myNameParam} RETURN (n)",
* Result result = session.run( "MATCH (n) WHERE n.name = {myNameParam} RETURN (n)",
* Values.parameters( "myNameParam", "Bob" ) );
* }
* </pre>
*
* @param statementTemplate text of a Neo4j statement
* @param query text of a Neo4j query
* @param parameters input parameters, should be a map Value, see {@link Values#parameters(Object...)}.
* @return a stream of result values and associated metadata
*/
StatementResult run( String statementTemplate, Value parameters );
Result run(String query, Value parameters );

/**
* Run a statement and return a result stream.
* Run a query and return a result stream.
* <p>
* This method takes a set of parameters that will be injected into the
* statement by Neo4j. Using parameters is highly encouraged, it helps avoid
* query by Neo4j. Using parameters is highly encouraged, it helps avoid
* dangerous cypher injection attacks and improves database performance as
* Neo4j can re-use query plans more often.
* <p>
Expand All @@ -104,61 +104,61 @@ public interface StatementRunner
* a list of allowed types.
*
* <h2>Example</h2>
* <pre class="doctest:StatementRunnerDocIT#parameterTest">
* <pre class="doctest:QueryRunnerDocIT#parameterTest">
* {@code
*
* Map<String, Object> parameters = new HashMap<String, Object>();
* parameters.put("myNameParam", "Bob");
*
* StatementResult cursor = session.run( "MATCH (n) WHERE n.name = {myNameParam} RETURN (n)",
* Result result = session.run( "MATCH (n) WHERE n.name = {myNameParam} RETURN (n)",
* parameters );
* }
* </pre>
*
* @param statementTemplate text of a Neo4j statement
* @param statementParameters input data for the statement
* @param query text of a Neo4j query
* @param parameters input data for the query
* @return a stream of result values and associated metadata
*/
StatementResult run( String statementTemplate, Map<String,Object> statementParameters );
Result run(String query, Map<String,Object> parameters );

/**
* Run a statement and return a result stream.
* Run a query and return a result stream.
* <p>
* This method takes a set of parameters that will be injected into the
* statement by Neo4j. Using parameters is highly encouraged, it helps avoid
* query by Neo4j. Using parameters is highly encouraged, it helps avoid
* dangerous cypher injection attacks and improves database performance as
* Neo4j can re-use query plans more often.
* <p>
* This version of run takes a {@link Record} of parameters, which can be useful
* if you want to use the output of one statement as input for another.
* if you want to use the output of one query as input for another.
*
* @param statementTemplate text of a Neo4j statement
* @param statementParameters input data for the statement
* @param query text of a Neo4j query
* @param parameters input data for the query
* @return a stream of result values and associated metadata
*/
StatementResult run( String statementTemplate, Record statementParameters );
Result run(String query, Record parameters );

/**
* Run a statement and return a result stream.
* Run a query and return a result stream.
*
* @param statementTemplate text of a Neo4j statement
* @param query text of a Neo4j query
* @return a stream of result values and associated metadata
*/
StatementResult run( String statementTemplate );
Result run(String query );

/**
* Run a statement and return a result stream.
* Run a query and return a result stream.
* <h2>Example</h2>
* <pre class="doctest:StatementRunnerDocIT#statementObjectTest">
* <pre class="doctest:QueryRunnerDocIT#queryObjectTest">
* {@code
*
* Statement statement = new Statement( "MATCH (n) WHERE n.name=$myNameParam RETURN n.age" );
* StatementResult cursor = session.run( statement.withParameters( Values.parameters( "myNameParam", "Bob" ) ) );
* Query query = new Query( "MATCH (n) WHERE n.name=$myNameParam RETURN n.age" );
* Result result = session.run( query.withParameters( Values.parameters( "myNameParam", "Bob" ) ) );
* }
* </pre>
*
* @param statement a Neo4j statement
* @param query a Neo4j query
* @return a stream of result values and associated metadata
*/
StatementResult run( Statement statement );
Result run(Query query);
}
4 changes: 2 additions & 2 deletions driver/src/main/java/org/neo4j/driver/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
/**
* Container for Cypher result values.
* <p>
* Streams of records are returned from Cypher statement execution, contained
* within a {@link StatementResult}.
* Streams of records are returned from Cypher query execution, contained
* within a {@link Result}.
* <p>
* A record is a form of ordered map and, as such, contained values can be
* accessed by either positional {@link #get(int) index} or textual
Expand Down
2 changes: 1 addition & 1 deletion driver/src/main/java/org/neo4j/driver/Records.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Static utility methods for retaining records
*
* @see StatementResult#list()
* @see Result#list()
* @since 1.0
*/
public abstract class Records
Expand Down
Loading