package synapticloop.sample.h2zero.question;
// - - - - thoughtfully generated by synapticloop h2zero - - - -
// with the use of synapticloop templar templating language
// (java-create-question.templar)
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Date;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.HashMap;
import java.util.List;
import java.util.Enumeration;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
import synapticloop.h2zero.base.exception.H2ZeroFinderException;
import synapticloop.h2zero.base.manager.ConnectionManager;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import synapticloop.sample.h2zero.model.util.Constants;
public class UserQuestion {
// the binder is unused in code, but will generate compile problems if this
// class is no longer referenced in the h2zero file. Just a nicety for
// removing dead code
@SuppressWarnings("unused")
private static final String BINDER = Constants.USER_binder;
private static final Logger LOGGER = Logger.getLogger(UserQuestion.class);
private static final String SQL_DO_WE_HAVE_MORE_THAN_TWENTY_USERS = "select count(*) > 20 from user";
private static final String SQL_DOES_USER_NAME_EXIST = "select count(*) > 0 from user";
private static final String SQL_DO_WE_HAVE_USERS_BETWEEN_AGE_EXCLUSIVE = "select count(*) > 0 from user" + " where num_age > ? and num_age < ?";
private static final String SQL_DO_WE_HAVE_USERS_IN_AGES = "select count(*) > 0 from user" + " where num_age in (...)";
private static HashMap doWeHaveUsersInAges_statement_cache = new HashMap();
public static boolean doWeHaveMoreThanTwentyUsers() throws H2ZeroFinderException, SQLException {
Connection connection = null;
try {
connection = ConnectionManager.getConnection();
return(doWeHaveMoreThanTwentyUsers(connection));
} catch (SQLException sqlex) {
throw sqlex;
} finally {
ConnectionManager.closeAll(connection);
}
}
public static boolean doWeHaveMoreThanTwentyUsers(Connection connection) throws H2ZeroFinderException, SQLException {
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
boolean answer = false;
try {
preparedStatement = connection.prepareStatement(SQL_DO_WE_HAVE_MORE_THAN_TWENTY_USERS);
resultSet = preparedStatement.executeQuery();
if(resultSet.next()) {
answer = resultSet.getBoolean(1);
}
} catch (SQLException sqlex) {
throw sqlex;
} finally {
ConnectionManager.closeAll(resultSet, preparedStatement);
}
return(answer);
}
public static boolean doWeHaveMoreThanTwentyUsersSilent() {
try {
return(doWeHaveMoreThanTwentyUsers());
} catch(H2ZeroFinderException h2zfex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("H2ZeroFinderException doWeHaveMoreThanTwentyUsersSilent(): " + h2zfex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
h2zfex.printStackTrace();
}
}
return(false);
} catch(SQLException sqlex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("SQLException doWeHaveMoreThanTwentyUsersSilent(): " + sqlex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
sqlex.printStackTrace();
}
}
return(false);
}
}
public static boolean doWeHaveMoreThanTwentyUsersSilent(Connection connection) {
try {
return(doWeHaveMoreThanTwentyUsers(connection));
} catch(H2ZeroFinderException h2zfex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("H2ZeroFinderException doWeHaveMoreThanTwentyUsersSilent(): " + h2zfex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
h2zfex.printStackTrace();
}
}
return(false);
} catch(SQLException sqlex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("SQLException doWeHaveMoreThanTwentyUsersSilent(): " + sqlex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
sqlex.printStackTrace();
}
}
return(false);
}
}
public static boolean doesUserNameExist() throws H2ZeroFinderException, SQLException {
Connection connection = null;
try {
connection = ConnectionManager.getConnection();
return(doesUserNameExist(connection));
} catch (SQLException sqlex) {
throw sqlex;
} finally {
ConnectionManager.closeAll(connection);
}
}
public static boolean doesUserNameExist(Connection connection) throws H2ZeroFinderException, SQLException {
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
boolean answer = false;
try {
preparedStatement = connection.prepareStatement(SQL_DOES_USER_NAME_EXIST);
resultSet = preparedStatement.executeQuery();
if(resultSet.next()) {
answer = resultSet.getBoolean(1);
}
} catch (SQLException sqlex) {
throw sqlex;
} finally {
ConnectionManager.closeAll(resultSet, preparedStatement);
}
return(answer);
}
public static boolean doesUserNameExistSilent() {
try {
return(doesUserNameExist());
} catch(H2ZeroFinderException h2zfex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("H2ZeroFinderException doesUserNameExistSilent(): " + h2zfex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
h2zfex.printStackTrace();
}
}
return(false);
} catch(SQLException sqlex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("SQLException doesUserNameExistSilent(): " + sqlex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
sqlex.printStackTrace();
}
}
return(false);
}
}
public static boolean doesUserNameExistSilent(Connection connection) {
try {
return(doesUserNameExist(connection));
} catch(H2ZeroFinderException h2zfex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("H2ZeroFinderException doesUserNameExistSilent(): " + h2zfex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
h2zfex.printStackTrace();
}
}
return(false);
} catch(SQLException sqlex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("SQLException doesUserNameExistSilent(): " + sqlex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
sqlex.printStackTrace();
}
}
return(false);
}
}
public static boolean doWeHaveUsersBetweenAgeExclusive(Integer numAgeFrom, Integer numAgeTo) throws H2ZeroFinderException, SQLException {
Connection connection = null;
try {
connection = ConnectionManager.getConnection();
return(doWeHaveUsersBetweenAgeExclusive(connection, numAgeFrom, numAgeTo));
} catch (SQLException sqlex) {
throw sqlex;
} finally {
ConnectionManager.closeAll(connection);
}
}
public static boolean doWeHaveUsersBetweenAgeExclusive(Connection connection, Integer numAgeFrom, Integer numAgeTo) throws H2ZeroFinderException, SQLException {
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
boolean answer = false;
try {
preparedStatement = connection.prepareStatement(SQL_DO_WE_HAVE_USERS_BETWEEN_AGE_EXCLUSIVE);
ConnectionManager.setInt(preparedStatement, 1, numAgeFrom);
ConnectionManager.setInt(preparedStatement, 2, numAgeTo);
resultSet = preparedStatement.executeQuery();
if(resultSet.next()) {
answer = resultSet.getBoolean(1);
}
} catch (SQLException sqlex) {
throw sqlex;
} finally {
ConnectionManager.closeAll(resultSet, preparedStatement);
}
return(answer);
}
public static boolean doWeHaveUsersBetweenAgeExclusiveSilent(Integer numAgeFrom, Integer numAgeTo) {
try {
return(doWeHaveUsersBetweenAgeExclusive(numAgeFrom, numAgeTo));
} catch(H2ZeroFinderException h2zfex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("H2ZeroFinderException doWeHaveUsersBetweenAgeExclusiveSilent(" + numAgeFrom + ", " + numAgeTo + "): " + h2zfex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
h2zfex.printStackTrace();
}
}
return(false);
} catch(SQLException sqlex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("SQLException doWeHaveUsersBetweenAgeExclusiveSilent(" + numAgeFrom + ", " + numAgeTo + "): " + sqlex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
sqlex.printStackTrace();
}
}
return(false);
}
}
public static boolean doWeHaveUsersBetweenAgeExclusiveSilent(Connection connection, Integer numAgeFrom, Integer numAgeTo) {
try {
return(doWeHaveUsersBetweenAgeExclusive(connection, numAgeFrom, numAgeTo));
} catch(H2ZeroFinderException h2zfex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("H2ZeroFinderException doWeHaveUsersBetweenAgeExclusiveSilent(" + numAgeFrom + ", " + numAgeTo + "): " + h2zfex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
h2zfex.printStackTrace();
}
}
return(false);
} catch(SQLException sqlex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("SQLException doWeHaveUsersBetweenAgeExclusiveSilent(" + numAgeFrom + ", " + numAgeTo + "): " + sqlex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
sqlex.printStackTrace();
}
}
return(false);
}
}
public static boolean doWeHaveUsersInAges(List numAgeList) throws H2ZeroFinderException, SQLException {
Connection connection = null;
try {
connection = ConnectionManager.getConnection();
return(doWeHaveUsersInAges(connection, numAgeList));
} catch (SQLException sqlex) {
throw sqlex;
} finally {
ConnectionManager.closeAll(connection);
}
}
public static boolean doWeHaveUsersInAges(Connection connection, List numAgeList) throws H2ZeroFinderException, SQLException {
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
boolean answer = false;
try {
if(doWeHaveUsersInAges_statement_cache.containsKey(numAgeList.size() + ":" )) {
preparedStatement = connection.prepareStatement(doWeHaveUsersInAges_statement_cache.get(numAgeList.size() + ":" ));
} else {
String preparedStatementTemp = SQL_DO_WE_HAVE_USERS_IN_AGES;
StringBuilder stringBuilder = null;
stringBuilder = new StringBuilder();
for(int i = 0; i < numAgeList.size(); i++) {
if(i > 0) {
stringBuilder.append(", ");
}
stringBuilder.append("?");
}
preparedStatementTemp = SQL_DO_WE_HAVE_USERS_IN_AGES.replaceFirst("\\.\\.\\.", stringBuilder.toString());
doWeHaveUsersInAges_statement_cache.put(numAgeList.size() + ":" , preparedStatementTemp);
preparedStatement = connection.prepareStatement(preparedStatementTemp);
}
int i = 1;
for (Integer numAgeIn : numAgeList) {
ConnectionManager.setInt(preparedStatement, i, numAgeIn);
i++;
}
resultSet = preparedStatement.executeQuery();
if(resultSet.next()) {
answer = resultSet.getBoolean(1);
}
} catch (SQLException sqlex) {
throw sqlex;
} finally {
ConnectionManager.closeAll(resultSet, preparedStatement);
}
return(answer);
}
public static boolean doWeHaveUsersInAgesSilent(List numAgeList) {
try {
return(doWeHaveUsersInAges(numAgeList));
} catch(H2ZeroFinderException h2zfex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("H2ZeroFinderException doWeHaveUsersInAgesSilent(" + numAgeList + "): " + h2zfex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
h2zfex.printStackTrace();
}
}
return(false);
} catch(SQLException sqlex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("SQLException doWeHaveUsersInAgesSilent(" + numAgeList + "): " + sqlex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
sqlex.printStackTrace();
}
}
return(false);
}
}
public static boolean doWeHaveUsersInAgesSilent(Connection connection, List numAgeList) {
try {
return(doWeHaveUsersInAges(connection, numAgeList));
} catch(H2ZeroFinderException h2zfex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("H2ZeroFinderException doWeHaveUsersInAgesSilent(" + numAgeList + "): " + h2zfex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
h2zfex.printStackTrace();
}
}
return(false);
} catch(SQLException sqlex) {
if(LOGGER.isEnabledFor(Level.WARN)) {
LOGGER.warn("SQLException doWeHaveUsersInAgesSilent(" + numAgeList + "): " + sqlex.getMessage());
if(LOGGER.isEnabledFor(Level.DEBUG)) {
sqlex.printStackTrace();
}
}
return(false);
}
}
}