AMashenkov commented on a change in pull request #284:
URL: https://github.com/apache/ignite-3/pull/284#discussion_r704237414



##########
File path: 
modules/client/src/main/java/org/apache/ignite/internal/jdbc/JdbcPreparedStatement.java
##########
@@ -0,0 +1,538 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.ignite.internal.jdbc;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.ParameterMetaData;
+import java.sql.PreparedStatement;
+import java.sql.Ref;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLXML;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Objects;
+import org.apache.ignite.client.proto.query.SqlStateCode;
+import org.apache.ignite.client.proto.query.event.JdbcQuery;
+
+/**
+ * Jdbc prepared statement implementation.
+ */
+public class JdbcPreparedStatement extends JdbcStatement implements 
PreparedStatement {
+    /** SQL query. */
+    private final String sql;
+
+    /** Query arguments. */
+    protected ArrayList<Object> args;
+
+    /**
+     * Creates new prepared statement.
+     *
+     * @param conn Connection.
+     * @param sql SQL query.
+     * @param resHoldability Result set holdability.
+     * @param schema Schema name.
+     */
+    JdbcPreparedStatement(JdbcConnection conn, String sql, int resHoldability, 
String schema) {
+        super(conn, resHoldability, schema);
+
+        this.sql = sql;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ResultSet executeQuery() throws SQLException {
+        executeWithArguments();
+
+        ResultSet rs = getResultSet();
+
+        if (rs == null)
+            throw new SQLException("The query isn't SELECT query: " + sql, 
SqlStateCode.PARSING_EXCEPTION);
+
+        return rs;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int executeUpdate() throws SQLException {
+        executeWithArguments();
+
+        int res = getUpdateCount();
+
+        if (res == -1)
+            throw new SQLException("The query is not DML statement: " + sql, 
SqlStateCode.PARSING_EXCEPTION);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean execute() throws SQLException {
+        executeWithArguments();
+
+        return resSets.get(0).isQuery();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void addBatch() throws SQLException {
+        ensureNotClosed();
+
+        batchSize++;
+
+        if (batch == null) {
+            batch = new ArrayList<>();
+
+            batch.add(new JdbcQuery(sql, args.toArray(new Object[0])));

Review comment:
       Is it necessary to pass `sql` to JdbcQuery? 
   Why we pass `null` for the next queries in the batch?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to