// Path: neo4j-jdbc/src/main/java/org/neo4j/jdbc/utils/ExceptionBuilder.java
// public class ExceptionBuilder {
// 
// 	private ExceptionBuilder() {}
// 
// 	/**
// 	 * An <code>UnsupportedOperationException</code> exception builder that  retrueve it's caller to make
// 	 * a not yet implemented exception with method and class name.
// 	 *
// 	 * @return an UnsupportedOperationException
// 	 */
// 	public static UnsupportedOperationException buildUnsupportedOperationException() {
// 		StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
// 		if (stackTraceElements.length > 2) {
// 			StackTraceElement caller = stackTraceElements[2];
// 
// 			StringBuilder sb = new StringBuilder().append("Method ").append(caller.getMethodName()).append(" in class ").append(caller.getClassName())
// 					.append(" is not yet implemented.");
// 
// 			return new UnsupportedOperationException(sb.toString());
// 		} else {
// 			return new UnsupportedOperationException("Not yet implemented.");
// 		}
// 	}
// }
// 
// Path: neo4j-jdbc/src/main/java/org/neo4j/jdbc/utils/PreparedStatementBuilder.java
// public class PreparedStatementBuilder {
// 
// 	private PreparedStatementBuilder() {}
// 
// 	/**
// 	 * This method return a String that is the original raw string with all valid placeholders replaced with neo4j curly brackets notation for parameters.
// 	 * <br>
// 	 * i.e. MATCH n RETURN n WHERE n.name = ? is transformed in MATCH n RETURN n WHERE n.name = {1}
// 	 *
// 	 * @param raw The string to be translated.
// 	 * @return The string with the placeholders replaced.
// 	 */
// 	public static String replacePlaceholders(String raw) {
// 		int index = 1;
// 		String digested = raw;
// 
// 		String regex = "\\?(?=[^\"]*(?:\"[^\"]*\"[^\"]*)*$)";
// 		Matcher matcher = Pattern.compile(regex).matcher(digested);
// 
// 		while (matcher.find()) {
// 			digested = digested.replaceFirst(regex, "{" + index + "}");
// 			index++;
// 		}
// 
// 		return digested;
// 	}
// 
// 	/**
// 	 * Given a string (statement) it counts all valid placeholders
// 	 *
// 	 * @param raw The string of the statement
// 	 * @return The number of all valid placeholders
// 	 */
// 	public static int namedParameterCount(String raw) {
// 		int max = 0;
// 		String regex = "\\{\\s*`?\\s*(\\d+)\\s*`?\\s*\\}(?=[^\"]*(\"[^\"]*\"[^\"]*)*$)";
// 		Matcher matcher = Pattern.compile(regex).matcher(raw);
// 		while (matcher.find()) {
// 			max = Math.max(Integer.parseInt(matcher.group(1)),max);
// 		}
// 		return max;
// 	}
// 
// }


import static java.sql.Types.*;
import org.neo4j.jdbc.utils.ExceptionBuilder;
import org.neo4j.jdbc.utils.PreparedStatementBuilder;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.sql.Date;
import java.sql.ResultSet;
import java.util.*;
/*
 * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it]
 * <p>
 * This file is part of the "LARUS Integration Framework for Neo4j".
 * <p>
 * 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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.
 * <p>
 * Created on 03/02/16
 */
package org.neo4j.jdbc;




/**
 * Don't forget to close some attribute (like currentResultSet and currentUpdateCount) or your implementation.
 *
 * @author AgileLARUS
 * @since 3.0.0
 */
public abstract class Neo4jPreparedStatement extends Neo4jStatement implements PreparedStatement {

	protected String                    statement;
	protected HashMap<String, Object>   parameters;
	protected List<Map<String, Object>> batchParameters;
	private   int                       parametersNumber;
	private static final List<Integer> UNSUPPORTED_TYPES = Collections .unmodifiableList(
			Arrays.asList(
					ARRAY,
					BLOB,
					CLOB,
					DATALINK,
					JAVA_OBJECT,
					NCHAR,
					NCLOB,
					NVARCHAR,
					LONGNVARCHAR,
					REF,
					ROWID,
					SQLXML,
					STRUCT
			)
	);

	/**
	 * Default constructor with connection and statement.
	 *
	 * @param connection   The JDBC connection
	 * @param rawStatement The prepared statement
	 */
	protected Neo4jPreparedStatement(Neo4jConnection connection, String rawStatement) {
		super(connection);
		this.statement = PreparedStatementBuilder.replacePlaceholders(rawStatement);
// Path: neo4j-jdbc/src/main/java/org/neo4j/jdbc/utils/ExceptionBuilder.java
// public class ExceptionBuilder {
// 
// 	private ExceptionBuilder() {}
// 
// 	/**
// 	 * An <code>UnsupportedOperationException</code> exception builder that  retrueve it's caller to make
// 	 * a not yet implemented exception with method and class name.
// 	 *
// 	 * @return an UnsupportedOperationException
// 	 */
// 	public static UnsupportedOperationException buildUnsupportedOperationException() {
// 		StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
// 		if (stackTraceElements.length > 2) {
// 			StackTraceElement caller = stackTraceElements[2];
// 
// 			StringBuilder sb = new StringBuilder().append("Method ").append(caller.getMethodName()).append(" in class ").append(caller.getClassName())
// 					.append(" is not yet implemented.");
// 
// 			return new UnsupportedOperationException(sb.toString());
// 		} else {
// 			return new UnsupportedOperationException("Not yet implemented.");
// 		}
// 	}
// }
// 
// Path: neo4j-jdbc/src/main/java/org/neo4j/jdbc/utils/PreparedStatementBuilder.java
// public class PreparedStatementBuilder {
// 
// 	private PreparedStatementBuilder() {}
// 
// 	/**
// 	 * This method return a String that is the original raw string with all valid placeholders replaced with neo4j curly brackets notation for parameters.
// 	 * <br>
// 	 * i.e. MATCH n RETURN n WHERE n.name = ? is transformed in MATCH n RETURN n WHERE n.name = {1}
// 	 *
// 	 * @param raw The string to be translated.
// 	 * @return The string with the placeholders replaced.
// 	 */
// 	public static String replacePlaceholders(String raw) {
// 		int index = 1;
// 		String digested = raw;
// 
// 		String regex = "\\?(?=[^\"]*(?:\"[^\"]*\"[^\"]*)*$)";
// 		Matcher matcher = Pattern.compile(regex).matcher(digested);
// 
// 		while (matcher.find()) {
// 			digested = digested.replaceFirst(regex, "{" + index + "}");
// 			index++;
// 		}
// 
// 		return digested;
// 	}
// 
// 	/**
// 	 * Given a string (statement) it counts all valid placeholders
// 	 *
// 	 * @param raw The string of the statement
// 	 * @return The number of all valid placeholders
// 	 */
// 	public static int namedParameterCount(String raw) {
// 		int max = 0;
// 		String regex = "\\{\\s*`?\\s*(\\d+)\\s*`?\\s*\\}(?=[^\"]*(\"[^\"]*\"[^\"]*)*$)";
// 		Matcher matcher = Pattern.compile(regex).matcher(raw);
// 		while (matcher.find()) {
// 			max = Math.max(Integer.parseInt(matcher.group(1)),max);
// 		}
// 		return max;
// 	}
// 
// }


// Path: neo4j-jdbc/src/main/java/org/neo4j/jdbc/Neo4jPreparedStatement.java
import static java.sql.Types.*;
import org.neo4j.jdbc.utils.ExceptionBuilder;
import org.neo4j.jdbc.utils.PreparedStatementBuilder;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.sql.Date;
import java.sql.ResultSet;
import java.util.*;

/*
 * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it]
 * <p>
 * This file is part of the "LARUS Integration Framework for Neo4j".
 * <p>
 * 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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.
 * <p>
 * Created on 03/02/16
 */
package org.neo4j.jdbc;




/**
 * Don't forget to close some attribute (like currentResultSet and currentUpdateCount) or your implementation.
 *
 * @author AgileLARUS
 * @since 3.0.0
 */
public abstract class Neo4jPreparedStatement extends Neo4jStatement implements PreparedStatement {

	protected String                    statement;
	protected HashMap<String, Object>   parameters;
	protected List<Map<String, Object>> batchParameters;
	private   int                       parametersNumber;
	private static final List<Integer> UNSUPPORTED_TYPES = Collections .unmodifiableList(
			Arrays.asList(
					ARRAY,
					BLOB,
					CLOB,
					DATALINK,
					JAVA_OBJECT,
					NCHAR,
					NCLOB,
					NVARCHAR,
					LONGNVARCHAR,
					REF,
					ROWID,
					SQLXML,
					STRUCT
			)
	);

	/**
	 * Default constructor with connection and statement.
	 *
	 * @param connection   The JDBC connection
	 * @param rawStatement The prepared statement
	 */
	protected Neo4jPreparedStatement(Neo4jConnection connection, String rawStatement) {
		super(connection);
		this.statement = PreparedStatementBuilder.replacePlaceholders(rawStatement);
		this.parametersNumber = PreparedStatementBuilder.namedParameterCount(statement);