com.querydsl.sql.teradata.SetQueryBandClause Maven / Gradle / Ivy
/*
* Copyright 2015, The Querydsl Team (http://www.querydsl.com/team)
*
* 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 com.querydsl.sql.teradata;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.inject.Provider;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.querydsl.sql.Configuration;
import com.querydsl.sql.SQLBindings;
import com.querydsl.sql.SQLTemplates;
import com.querydsl.sql.dml.AbstractSQLClause;
/**
* {@code SetQueryBandClause} provides support for Teradata specific set query_band executions.
*
* @author tiwe
*
*/
public class SetQueryBandClause extends AbstractSQLClause {
private boolean forSession = true;
private final Map values = Maps.newLinkedHashMap();
private transient String queryString;
private transient String parameter;
public SetQueryBandClause(Connection connection, SQLTemplates templates) {
this(connection, new Configuration(templates));
}
public SetQueryBandClause(Connection connection, Configuration configuration) {
super(configuration, connection);
}
public SetQueryBandClause(Provider connection, Configuration configuration) {
super(configuration, connection);
}
public SetQueryBandClause forSession() {
queryString = null;
forSession = true;
return this;
}
public SetQueryBandClause forTransaction() {
queryString = null;
forSession = false;
return this;
}
public SetQueryBandClause set(String key, String value) {
queryString = null;
values.put(key, value);
return this;
}
public SetQueryBandClause set(Map values) {
queryString = null;
this.values.putAll(values);
return this;
}
@Override
public void clear() {
values.clear();
}
@Override
public long execute() {
PreparedStatement stmt = null;
try {
stmt = connection().prepareStatement(toString());
if (parameter != null) {
stmt.setString(1, parameter);
}
return 1;
} catch (SQLException e) {
List