com.ait.tooling.server.sql.GSQL Maven / Gradle / Ivy
/*
* Copyright (c) 2017 Ahome' Innovation Technologies. All rights reserved. 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.ait.tooling.server.sql;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Objects;
import javax.sql.DataSource;
import com.ait.tooling.common.api.java.util.StringOps;
import com.ait.tooling.server.core.json.JSONArray;
import com.ait.tooling.server.core.json.JSONObject;
import groovy.sql.GroovyResultSet;
import groovy.sql.GroovyRowResult;
import groovy.sql.InOutParameter;
import groovy.sql.InParameter;
import groovy.sql.OutParameter;
import groovy.sql.ResultSetOutParameter;
import groovy.sql.Sql;
public class GSQL extends Sql
{
private static IGSQLRowObjectMapper s_default_row_object_mapper;
private List m_setobj_list;
private List m_precon_list;
public static final InParameter GSQLINPARAMETER(final int type, final Object value)
{
return in(type, value);
}
public static final OutParameter GSQLOUTPARAMETER(final int type)
{
return out(type);
}
public static final InOutParameter GSQLINOUTPARAMETER(final int type, final Object value)
{
return inout(in(type, value));
}
public static final InOutParameter GSQLINOUTPARAMETER(final InParameter in)
{
return inout(in);
}
public static final ResultSetOutParameter GSQLRESULTSETOUTPARAMETER(final int type)
{
return new ResultSetOutParameter()
{
@Override
public final int getType()
{
return type;
}
};
}
public static final void setDefaultRowObjectMapper(final IGSQLRowObjectMapper mapper)
{
s_default_row_object_mapper = mapper;
}
public GSQL(final DataSource ds)
{
super(Objects.requireNonNull(ds, "DataSource was null"));
}
public void setStatementSetObjectHandlers(final List list)
{
m_setobj_list = list;
}
public void setPreProcessConnectionHandlers(final List list)
{
m_precon_list = list;
}
@Override
protected void setObject(final PreparedStatement statement, final int i, final Object value) throws SQLException
{
if ((null == m_setobj_list) || (m_setobj_list.isEmpty()))
{
super.setObject(statement, i, value);
}
else
{
boolean done = false;
for (IGSQLStatementSetObjectHandler handler : m_setobj_list)
{
if (handler.setObject(statement, i, value))
{
done = true;
break;
}
}
if (false == done)
{
super.setObject(statement, i, value);
}
}
}
@Override
protected void closeResources(final Connection connection, final Statement statement, final ResultSet results)
{
super.closeResources(connection, statement, results);
}
@Override
protected void closeResources(final Connection connection, final Statement statement)
{
super.closeResources(connection, statement);
}
@Override
protected void closeResources(final Connection connection)
{
super.closeResources(connection);
}
@Override
protected Connection createConnection() throws SQLException
{
if ((null == m_precon_list) || (m_precon_list.isEmpty()))
{
final Connection connection = super.createConnection();
return connection;
}
Connection connection = super.createConnection();
for (IGSQLPreProcessConnectionHandler handler : m_precon_list)
{
handler.preProcessConnection(connection);
}
return connection;
}
@Override
protected AbstractQueryCommand createQueryCommand(final String sql)
{
return super.createQueryCommand(sql);
}
@Override
protected AbstractQueryCommand createPreparedQueryCommand(String sql, List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy