org.neo4j.jdbc.http.HttpNeo4jStatement Maven / Gradle / Ivy
Show all versions of neo4j-jdbc-http Show documentation
/*
* Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it]
*
* This file is part of the "LARUS Integration Framework for Neo4j".
*
* The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Created on 15/4/2016
*/
package org.neo4j.jdbc.http;
import org.neo4j.jdbc.Loggable;
import org.neo4j.jdbc.Neo4jStatement;
import org.neo4j.jdbc.http.driver.Neo4jResponse;
import java.sql.BatchUpdateException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class HttpNeo4jStatement extends Neo4jStatement implements Loggable {
public HttpNeo4jStatement(HttpNeo4jConnection httpConnection) {
super(httpConnection);
batchStatements = new ArrayList<>();
}
@Override public ResultSet executeQuery(String cypher) throws SQLException {
this.execute(cypher);
return currentResultSet;
}
@Override public int executeUpdate(String cypher) throws SQLException {
this.execute(cypher);
return currentUpdateCount;
}
@Override public boolean execute(String cypher) throws SQLException {
checkClosed();
// execute the query
Neo4jResponse response = ((HttpNeo4jConnection) getConnection()).executeQuery(cypher, null, Boolean.TRUE);
if (response.hasErrors()) {
throw new SQLException(response.displayErrors());
}
// Parse stats
this.currentUpdateCount = response.getFirstResult().getUpdateCount();
// Parse response data
boolean hasResultSets = response.hasResultSets();
this.currentResultSet = hasResultSets ? new HttpNeo4jResultSet(this,response.getFirstResult()) : null;
return hasResultSets;
}
@Override public int getResultSetConcurrency() throws SQLException {
return ResultSet.CONCUR_READ_ONLY;
}
@Override public int getResultSetType() throws SQLException {
return ResultSet.TYPE_FORWARD_ONLY;
}
@Override public int getResultSetHoldability() throws SQLException {
return ResultSet.CLOSE_CURSORS_AT_COMMIT;
}
/*-------------------*/
/* Batch */
/*-------------------*/
@Override public int[] executeBatch() throws SQLException {
this.checkClosed();
// execute batch queries
List