提交 a7e2deb9 编写于 作者: S Serge Rider

Value binder model

上级 63bebd94
......@@ -83,7 +83,7 @@ public class GISGeometryValueHandler extends JDBCAbstractValueHandler {
}
}
protected void bindGeometryParameter(JDBCSession session, JDBCPreparedStatement statement, int paramIndex, Geometry value) throws SQLException, DBCException {
protected void bindGeometryParameter(@NotNull JDBCSession session, @NotNull JDBCPreparedStatement statement, int paramIndex, @NotNull Geometry value) throws SQLException, DBCException {
bindBytes(statement, paramIndex, convertGeometryToBinaryFormat(session, value));
}
......@@ -141,11 +141,11 @@ public class GISGeometryValueHandler extends JDBCAbstractValueHandler {
return super.getValueDisplayString(column, value, format);
}
protected byte[] fetchBytes(JDBCResultSet resultSet, int index) throws SQLException {
protected byte[] fetchBytes(@NotNull JDBCResultSet resultSet, int index) throws SQLException {
return resultSet.getBytes(index);
}
protected void bindBytes(JDBCPreparedStatement dbStat, int index, byte[] bytes) throws SQLException {
protected void bindBytes(@NotNull JDBCPreparedStatement dbStat, int index, @NotNull byte[] bytes) throws SQLException {
dbStat.setBytes(index, bytes);
}
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* 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.
*/
package org.jkiss.dbeaver.model.data;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.struct.DBSAttributeBase;
/**
* Provides possibility to override default SQL query binding
*/
public interface DBDValueBinder extends DBDValueHandler
{
String makeQueryBind(DBSAttributeBase attribute) throws DBCException;
}
......@@ -148,7 +148,7 @@ public abstract class ExecuteBatchImpl implements DBSDataManipulator.ExecuteBatc
}
}
if (statement == null || !reuse) {
statement = prepareStatement(session, rowValues);
statement = prepareStatement(session, handlers, rowValues);
statistics.setQueryText(statement.getQueryString());
statistics.addStatementsCount();
}
......@@ -324,7 +324,7 @@ public abstract class ExecuteBatchImpl implements DBSDataManipulator.ExecuteBatc
}
@NotNull
protected abstract DBCStatement prepareStatement(@NotNull DBCSession session, Object[] attributeValues) throws DBCException;
protected abstract DBCStatement prepareStatement(@NotNull DBCSession session, DBDValueHandler[] handlers, Object[] attributeValues) throws DBCException;
protected abstract void bindStatement(@NotNull DBDValueHandler[] handlers, @NotNull DBCStatement statement, Object[] attributeValues) throws DBCException;
......
......@@ -325,7 +325,7 @@ public abstract class JDBCTable<DATASOURCE extends DBPDataSource, CONTAINER exte
@NotNull
@Override
protected DBCStatement prepareStatement(@NotNull DBCSession session, Object[] attributeValues) throws DBCException {
protected DBCStatement prepareStatement(@NotNull DBCSession session, DBDValueHandler[] handlers, Object[] attributeValues) throws DBCException {
// Make query
StringBuilder query = new StringBuilder(200);
query
......@@ -358,7 +358,13 @@ public abstract class JDBCTable<DATASOURCE extends DBPDataSource, CONTAINER exte
}
if (hasKey) query.append(","); //$NON-NLS-1$
hasKey = true;
query.append("?"); //$NON-NLS-1$
DBDValueHandler valueHandler = handlers[i];
if (valueHandler instanceof DBDValueBinder) {
query.append(((DBDValueBinder) valueHandler) .makeQueryBind(attribute));
} else {
query.append("?"); //$NON-NLS-1$
}
}
query.append(")"); //$NON-NLS-1$
......@@ -408,7 +414,7 @@ public abstract class JDBCTable<DATASOURCE extends DBPDataSource, CONTAINER exte
return new ExecuteBatchImpl(attributes, keysReceiver, false) {
@NotNull
@Override
protected DBCStatement prepareStatement(@NotNull DBCSession session, Object[] attributeValues) throws DBCException {
protected DBCStatement prepareStatement(@NotNull DBCSession session, DBDValueHandler[] handlers, Object[] attributeValues) throws DBCException {
String tableAlias = null;
SQLDialect dialect = ((SQLDataSource) session.getDataSource()).getSQLDialect();
if (dialect.supportsAliasInUpdate()) {
......@@ -423,13 +429,20 @@ public abstract class JDBCTable<DATASOURCE extends DBPDataSource, CONTAINER exte
query.append("\nSET "); //$NON-NLS-1$ //$NON-NLS-2$
boolean hasKey = false;
for (DBSAttributeBase attribute : updateAttributes) {
for (int i = 0; i < updateAttributes.length; i++) {
DBSAttributeBase attribute = updateAttributes[i];
if (hasKey) query.append(","); //$NON-NLS-1$
hasKey = true;
if (tableAlias != null) {
query.append(tableAlias).append(dialect.getStructSeparator());
}
query.append(getAttributeName(attribute)).append("=?"); //$NON-NLS-1$
query.append(getAttributeName(attribute)).append("="); //$NON-NLS-1$
DBDValueHandler valueHandler = handlers[i];
if (valueHandler instanceof DBDValueBinder) {
query.append(((DBDValueBinder) valueHandler) .makeQueryBind(attribute));
} else {
query.append("?"); //$NON-NLS-1$
}
}
if (keyAttributes.length > 0) {
query.append("\nWHERE "); //$NON-NLS-1$
......@@ -477,7 +490,7 @@ public abstract class JDBCTable<DATASOURCE extends DBPDataSource, CONTAINER exte
return new ExecuteBatchImpl(keyAttributes, null, false) {
@NotNull
@Override
protected DBCStatement prepareStatement(@NotNull DBCSession session, Object[] attributeValues) throws DBCException {
protected DBCStatement prepareStatement(@NotNull DBCSession session, DBDValueHandler[] handlers, Object[] attributeValues) throws DBCException {
String tableAlias = null;
SQLDialect dialect = ((SQLDataSource) session.getDataSource()).getSQLDialect();
if (dialect.supportsAliasInUpdate()) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册