/*
* This source file was generated by FireStorm/DAO.
*
* If you purchase a full license for FireStorm/DAO you can customize this header file.
*
* For more information please visit
http://www.codefutures.com/products/firestorm
*/
package com.mycompany.loca.jdbc;
import com.mycompany.loca.dao.*;
import com.mycompany.loca.dto.*;
import com.mycompany.loca.exceptions.*;
import java.sql.Connection;
import java.util.Collection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class ClientDaoImpl extends AbstractDAO implements ClientDao
{
/**
* The factory class for this DAO has two versions of the create() method - one that
takes no arguments and one that takes a Connection argument. If the Connection version
is chosen then the connection will be stored in this attribute and will be used by all
calls to this DAO, otherwise a new Connection will be allocated for each operation.
*/
protected java.sql.Connection userConn;
/**
* All finder methods in this class use this SELECT constant to build their queries
*/
protected final String SQL_SELECT = "SELECT NUMEROCLIENT, NOM, PRENOM, ADRESSE, NATIONALITÉ, PASSEPORT, PERMIS, TELEPHONE, MAIL, NOMAC, PRENOMAC, ADRESSEAC, NATIONALITÉAC, PASSEPORTAC, PERMISAC, TELEPHONEAC, MAILAC FROM " + getTableName() + "";
/**
* Finder methods will pass this value to the JDBC setMaxRows method
*/
protected int maxRows;
/**
* SQL INSERT statement for this table
*/
protected final String SQL_INSERT = "INSERT INTO " + getTableName() + " ( NUMEROCLIENT, NOM, PRENOM, ADRESSE, NATIONALITÉ, PASSEPORT, PERMIS, TELEPHONE, MAIL, NOMAC, PRENOMAC, ADRESSEAC, NATIONALITÉAC, PASSEPORTAC, PERMISAC, TELEPHONEAC, MAILAC ) VALUES ( ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
/**
* SQL UPDATE statement for this table
*/
protected final String SQL_UPDATE = "UPDATE " + getTableName() + " SET NUMEROCLIENT = ?, NOM = ?, PRENOM = ?, ADRESSE = ?, NATIONALITÉ = ?, PASSEPORT = ?, PERMIS = ?, TELEPHONE = ?, MAIL = ?, NOMAC = ?, PRENOMAC = ?, ADRESSEAC = ?, NATIONALITÉAC = ?, PASSEPORTAC = ?, PERMISAC = ?, TELEPHONEAC = ?, MAILAC = ? WHERE NUMEROCLIENT = ?";
/**
* SQL DELETE statement for this table
*/
protected final String SQL_DELETE = "DELETE FROM " + getTableName() + " WHERE NUMEROCLIENT = ?";
/**
* Index of column NUMEROCLIENT
*/
protected static final int COLUMN_NUMEROCLIENT = 1;
/**
* Index of column NOM
*/
protected static final int COLUMN_NOM = 2;
/**
* Index of column PRENOM
*/
protected static final int COLUMN_PRENOM = 3;
/**
* Index of column ADRESSE
*/
protected static final int COLUMN_ADRESSE = 4;
/**
* Index of column NATIONALITÉ
*/
protected static final int COLUMN_NATIONALITÉ = 5;
/**
* Index of column PASSEPORT
*/
protected static final int COLUMN_PASSEPORT = 6;
/**
* Index of column PERMIS
*/
protected static final int COLUMN_PERMIS = 7;
/**
* Index of column TELEPHONE
*/
protected static final int COLUMN_TELEPHONE = 8;
/**
* Index of column MAIL
*/
protected static final int COLUMN_MAIL = 9;
/**
* Index of column NOMAC
*/
protected static final int COLUMN_NOMAC = 10;
/**
* Index of column PRENOMAC
*/
protected static final int COLUMN_PRENOMAC = 11;
/**
* Index of column ADRESSEAC
*/
protected static final int COLUMN_ADRESSEAC = 12;
/**
* Index of column NATIONALITÉAC
*/
protected static final int COLUMN_NATIONALITÉAC = 13;
/**
* Index of column PASSEPORTAC
*/
protected static final int COLUMN_PASSEPORTAC = 14;
/**
* Index of column PERMISAC
*/
protected static final int COLUMN_PERMISAC = 15;
/**
* Index of column TELEPHONEAC
*/
protected static final int COLUMN_TELEPHONEAC = 16;
/**
* Index of column MAILAC
*/
protected static final int COLUMN_MAILAC = 17;
/**
* Number of columns
*/
protected static final int NUMBER_OF_COLUMNS = 17;
/**
* Index of primary-key column NUMEROCLIENT
*/
protected static final int PK_COLUMN_NUMEROCLIENT = 1;
/**
* Inserts a new row in the CLIENT table.
*/
public ClientPk insert(Client dto) throws ClientDaoException
{
long t1 = System.currentTimeMillis();
// declare variables
final boolean isConnSupplied = (userConn != null);
Connection conn = null;
PreparedStatement stmt = null;
@SuppressWarnings("unused")
ResultSet rs = null;
try {
// get the user-specified connection or get a connection from the ResourceManager
conn = isConnSupplied ? userConn : ResourceManager.getConnection();
StringBuffer sql = new StringBuffer();
StringBuffer values = new StringBuffer();
sql.append( "INSERT INTO " + getTableName() + " (" );
int modifiedCount = 0;
if (dto.isNumeroclientModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "NUMEROCLIENT" );
values.append( "?" );
modifiedCount++;
}
if (dto.isNomModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "NOM" );
values.append( "?" );
modifiedCount++;
}
if (dto.isPrenomModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "PRENOM" );
values.append( "?" );
modifiedCount++;
}
if (dto.isAdresseModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "ADRESSE" );
values.append( "?" );
modifiedCount++;
}
if (dto.isNationalitéModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "NATIONALITÉ" );
values.append( "?" );
modifiedCount++;
}
if (dto.isPasseportModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "PASSEPORT" );
values.append( "?" );
modifiedCount++;
}
if (dto.isPermisModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "PERMIS" );
values.append( "?" );
modifiedCount++;
}
if (dto.isTelephoneModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "TELEPHONE" );
values.append( "?" );
modifiedCount++;
}
if (dto.isMailModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "MAIL" );
values.append( "?" );
modifiedCount++;
}
if (dto.isNomacModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "NOMAC" );
values.append( "?" );
modifiedCount++;
}
if (dto.isPrenomacModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "PRENOMAC" );
values.append( "?" );
modifiedCount++;
}
if (dto.isAdresseacModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "ADRESSEAC" );
values.append( "?" );
modifiedCount++;
}
if (dto.isNationalitéacModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "NATIONALITÉAC" );
values.append( "?" );
modifiedCount++;
}
if (dto.isPasseportacModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "PASSEPORTAC" );
values.append( "?" );
modifiedCount++;
}
if (dto.isPermisacModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "PERMISAC" );
values.append( "?" );
modifiedCount++;
}
if (dto.isTelephoneacModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "TELEPHONEAC" );
values.append( "?" );
modifiedCount++;
}
if (dto.isMailacModified()) {
if (modifiedCount>0) {
sql.append( ", " );
values.append( ", " );
}
sql.append( "MAILAC" );
values.append( "?" );
modifiedCount++;
}
if (modifiedCount==0) {
// nothing to insert
throw new IllegalStateException( "Nothing to insert" );
}
sql.append( ") VALUES (" );
sql.append( values );
sql.append( ")" );
stmt = conn.prepareStatement( sql.toString() );
int index = 1;
if (dto.isNumeroclientModified()) {
stmt.setString( index++, dto.getNumeroclient() );
}
if (dto.isNomModified()) {
stmt.setString( index++, dto.getNom() );
}
if (dto.isPrenomModified()) {
stmt.setString( index++, dto.getPrenom() );
}
if (dto.isAdresseModified()) {
stmt.setString( index++, dto.getAdresse() );
}
if (dto.isNationalitéModified()) {
stmt.setString( index++, dto.getNationalité() );
}
if (dto.isPasseportModified()) {
stmt.setString( index++, dto.getPasseport() );
}
if (dto.isPermisModified()) {
stmt.setString( index++, dto.getPermis() );
}
if (dto.isTelephoneModified()) {
stmt.setString( index++, dto.getTelephone() );
}
if (dto.isMailModified()) {
stmt.setString( index++, dto.getMail() );
}
if (dto.isNomacModified()) {
stmt.setString( index++, dto.getNomac() );
}
if (dto.isPrenomacModified()) {
stmt.setString( index++, dto.getPrenomac() );
}
if (dto.isAdresseacModified()) {
stmt.setString( index++, dto.getAdresseac() );
}
if (dto.isNationalitéacModified()) {
stmt.setString( index++, dto.getNationalitéac() );
}
if (dto.isPasseportacModified()) {
stmt.setString( index++, dto.getPasseportac() );
}
if (dto.isPermisacModified()) {
stmt.setString( index++, dto.getPermisac() );
}
if (dto.isTelephoneacModified()) {
stmt.setString( index++, dto.getTelephoneac() );
}
if (dto.isMailacModified()) {
stmt.setString( index++, dto.getMailac() );
}
System.out.println( "Executing " + sql.toString() + " with values: " + dto );
int rows = stmt.executeUpdate();
long t2 = System.currentTimeMillis();
System.out.println( rows + " rows affected (" + (t2-t1) + " ms)" );
reset(dto);
return dto.createPk();
}
catch (Exception _e) {
_e.printStackTrace();
throw new ClientDaoException( "Exception: " + _e.getMessage(), _e );
}
finally {
ResourceManager.close(stmt);
if (!isConnSupplied) {
ResourceManager.close(conn);
}
}
}
/**
* Updates a single row in the CLIENT table.
*/
public void update(ClientPk pk, Client dto) throws ClientDaoException
{
long t1 = System.currentTimeMillis();
// declare variables
final boolean isConnSupplied = (userConn != null);
Connection conn = null;
PreparedStatement stmt = null;
try {
// get the user-specified connection or get a connection from the ResourceManager
conn = isConnSupplied ? userConn : ResourceManager.getConnection();
StringBuffer sql = new StringBuffer();
sql.append( "UPDATE " + getTableName() + " SET " );
boolean modified = false;
if (dto.isNumeroclientModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "NUMEROCLIENT=?" );
modified=true;
}
if (dto.isNomModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "NOM=?" );
modified=true;
}
if (dto.isPrenomModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "PRENOM=?" );
modified=true;
}
if (dto.isAdresseModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "ADRESSE=?" );
modified=true;
}
if (dto.isNationalitéModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "NATIONALITÉ=?" );
modified=true;
}
if (dto.isPasseportModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "PASSEPORT=?" );
modified=true;
}
if (dto.isPermisModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "PERMIS=?" );
modified=true;
}
if (dto.isTelephoneModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "TELEPHONE=?" );
modified=true;
}
if (dto.isMailModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "MAIL=?" );
modified=true;
}
if (dto.isNomacModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "NOMAC=?" );
modified=true;
}
if (dto.isPrenomacModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "PRENOMAC=?" );
modified=true;
}
if (dto.isAdresseacModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "ADRESSEAC=?" );
modified=true;
}
if (dto.isNationalitéacModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "NATIONALITÉAC=?" );
modified=true;
}
if (dto.isPasseportacModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "PASSEPORTAC=?" );
modified=true;
}
if (dto.isPermisacModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "PERMISAC=?" );
modified=true;
}
if (dto.isTelephoneacModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "TELEPHONEAC=?" );
modified=true;
}
if (dto.isMailacModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "MAILAC=?" );
modified=true;
}
if (!modified) {
// nothing to update
return;
}
sql.append( " WHERE NUMEROCLIENT=?" );
System.out.println( "Executing " + sql.toString() + " with values: " + dto );
stmt = conn.prepareStatement( sql.toString() );
int index = 1;
if (dto.isNumeroclientModified()) {
stmt.setString( index++, dto.getNumeroclient() );
}
if (dto.isNomModified()) {
stmt.setString( index++, dto.getNom() );
}
if (dto.isPrenomModified()) {
stmt.setString( index++, dto.getPrenom() );
}
if (dto.isAdresseModified()) {
stmt.setString( index++, dto.getAdresse() );
}
if (dto.isNationalitéModified()) {
stmt.setString( index++, dto.getNationalité() );
}
if (dto.isPasseportModified()) {
stmt.setString( index++, dto.getPasseport() );
}
if (dto.isPermisModified()) {
stmt.setString( index++, dto.getPermis() );
}
if (dto.isTelephoneModified()) {
stmt.setString( index++, dto.getTelephone() );
}
if (dto.isMailModified()) {
stmt.setString( index++, dto.getMail() );
}
if (dto.isNomacModified()) {
stmt.setString( index++, dto.getNomac() );
}
if (dto.isPrenomacModified()) {
stmt.setString( index++, dto.getPrenomac() );
}
if (dto.isAdresseacModified()) {
stmt.setString( index++, dto.getAdresseac() );
}
if (dto.isNationalitéacModified()) {
stmt.setString( index++, dto.getNationalitéac() );
}
if (dto.isPasseportacModified()) {
stmt.setString( index++, dto.getPasseportac() );
}
if (dto.isPermisacModified()) {
stmt.setString( index++, dto.getPermisac() );
}
if (dto.isTelephoneacModified()) {
stmt.setString( index++, dto.getTelephoneac() );
}
if (dto.isMailacModified()) {
stmt.setString( index++, dto.getMailac() );
}
stmt.setString( index++, pk.getNumeroclient() );
int rows = stmt.executeUpdate();
reset(dto);
long t2 = System.currentTimeMillis();
System.out.println( rows + " rows affected (" + (t2-t1) + " ms)" );
}
catch (Exception _e) {
_e.printStackTrace();
throw new ClientDaoException( "Exception: " + _e.getMessage(), _e );
}
finally {
ResourceManager.close(stmt);
if (!isConnSupplied) {
ResourceManager.close(conn);
}
}
}
/**
* Deletes a single row in the CLIENT table.
*/
public void delete(ClientPk pk) throws ClientDaoException
{
long t1 = System.currentTimeMillis();
// declare variables
final boolean isConnSupplied = (userConn != null);
Connection conn = null;
PreparedStatement stmt = null;
try {
// get the user-specified connection or get a connection from the ResourceManager
conn = isConnSupplied ? userConn : ResourceManager.getConnection();
System.out.println( "Executing " + SQL_DELETE + " with PK: " + pk );
stmt = conn.prepareStatement( SQL_DELETE );
stmt.setString( 1, pk.getNumeroclient() );
int rows = stmt.executeUpdate();
long t2 = System.currentTimeMillis();
System.out.println( rows + " rows affected (" + (t2-t1) + " ms)" );
}
catch (Exception _e) {
_e.printStackTrace();
throw new ClientDaoException( "Exception: " + _e.getMessage(), _e );
}
finally {
ResourceManager.close(stmt);
if (!isConnSupplied) {
ResourceManager.close(conn);
}
}
}
/**
* Returns the rows from the CLIENT table that matches the specified primary-key value.
*/
public Client findByPrimaryKey(ClientPk pk) throws ClientDaoException
{
return findByPrimaryKey( pk.getNumeroclient() );
}
/**
* Returns all rows from the CLIENT table that match the criteria 'NUMEROCLIENT = :numeroclient'.
*/
public Client findByPrimaryKey(String numeroclient) throws ClientDaoException
{
Client ret[] = findByDynamicSelect( SQL_SELECT + " WHERE NUMEROCLIENT = ?", new Object[] { numeroclient } );
return ret.length==0 ? null : ret[0];
}
/**
* Returns all rows from the CLIENT table that match the criteria ''.
*/
public Client[] findAll() throws ClientDaoException
{
return findByDynamicSelect( SQL_SELECT + " ORDER BY NUMEROCLIENT", null );
}
/**
* Returns all rows from the CLIENT table that match the criteria 'NUMEROCLIENT = :numeroclient'.
*/
public Client[] findWhereNumeroclientEquals(String numeroclient) throws ClientDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE NUMEROCLIENT = ? ORDER BY NUMEROCLIENT", new Object[] { numeroclient } );
}
/**
* Returns all rows from the CLIENT table that match the criteria 'NOM = :nom'.
*/
public Client[] findWhereNomEquals(String nom) throws ClientDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE NOM = ? ORDER BY NOM", new Object[] { nom } );
}
/**
* Returns all rows from the CLIENT table that match the criteria 'NATIONALITÉ = :nationalité'.
*/
public Client[] findWhereNationalitéEquals(String nationalité) throws ClientDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE NATIONALITÉ = ? ORDER BY NATIONALITÉ", new Object[] { nationalité } );
}
/**
* Returns all rows from the CLIENT table that match the criteria 'PASSEPORT = :passeport'.
*/
public Client[] findWherePasseportEquals(String passeport) throws ClientDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE PASSEPORT = ? ORDER BY PASSEPORT", new Object[] { passeport } );
}
/**
* Returns all rows from the CLIENT table that match the criteria 'PERMIS = :permis'.
*/
public Client[] findWherePermisEquals(String permis) throws ClientDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE PERMIS = ? ORDER BY PERMIS", new Object[] { permis } );
}
/**
* Returns all rows from the CLIENT table that match the criteria 'TELEPHONE = :telephone'.
*/
public Client[] findWhereTelephoneEquals(String telephone) throws ClientDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE TELEPHONE = ? ORDER BY TELEPHONE", new Object[] { telephone } );
}
/**
* Returns all rows from the CLIENT table that match the criteria 'MAIL = :mail'.
*/
public Client[] findWhereMailEquals(String mail) throws ClientDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE MAIL = ? ORDER BY MAIL", new Object[] { mail } );
}
/**
* Method 'ClientDaoImpl'
*
*/
public ClientDaoImpl()
{
}
/**
* Method 'ClientDaoImpl'
*
* @param userConn
*/
public ClientDaoImpl(final java.sql.Connection userConn)
{
this.userConn = userConn;
}
/**
* Sets the value of maxRows
*/
public void setMaxRows(int maxRows)
{
this.maxRows = maxRows;
}
/**
* Gets the value of maxRows
*/
public int getMaxRows()
{
return maxRows;
}
/**
* Method 'getTableName'
*
* @return String
*/
public String getTableName()
{
return "CLIENT";
}
/**
* Fetches a single row from the result set
*/
protected Client fetchSingleResult(ResultSet rs) throws SQLException
{
if (rs.next()) {
Client dto = new Client();
populateDto( dto, rs);
return dto;
} else {
return null;
}
}
/**
* Fetches multiple rows from the result set
*/
@SuppressWarnings("unchecked")
protected Client[] fetchMultiResults(ResultSet rs) throws SQLException
{
Collection resultList = new ArrayList();
while (rs.next()) {
Client dto = new Client();
populateDto( dto, rs);
resultList.add( dto );
}
Client ret[] = new Client[ resultList.size() ];
resultList.toArray( ret );
return ret;
}
/**
* Populates a DTO with data from a ResultSet
*/
protected void populateDto(Client dto, ResultSet rs) throws SQLException
{
dto.setNumeroclient( rs.getString( COLUMN_NUMEROCLIENT ) );
dto.setNom( rs.getString( COLUMN_NOM ) );
dto.setPrenom( rs.getString( COLUMN_PRENOM ) );
dto.setAdresse( rs.getString( COLUMN_ADRESSE ) );
dto.setNationalité( rs.getString( COLUMN_NATIONALITÉ ) );
dto.setPasseport( rs.getString( COLUMN_PASSEPORT ) );
dto.setPermis( rs.getString( COLUMN_PERMIS ) );
dto.setTelephone( rs.getString( COLUMN_TELEPHONE ) );
dto.setMail( rs.getString( COLUMN_MAIL ) );
dto.setNomac( rs.getString( COLUMN_NOMAC ) );
dto.setPrenomac( rs.getString( COLUMN_PRENOMAC ) );
dto.setAdresseac( rs.getString( COLUMN_ADRESSEAC ) );
dto.setNationalitéac( rs.getString( COLUMN_NATIONALITÉAC ) );
dto.setPasseportac( rs.getString( COLUMN_PASSEPORTAC ) );
dto.setPermisac( rs.getString( COLUMN_PERMISAC ) );
dto.setTelephoneac( rs.getString( COLUMN_TELEPHONEAC ) );
dto.setMailac( rs.getString( COLUMN_MAILAC ) );
reset(dto);
}
/**
* Resets the modified attributes in the DTO
*/
protected void reset(Client dto)
{
dto.setNumeroclientModified( false );
dto.setNomModified( false );
dto.setPrenomModified( false );
dto.setAdresseModified( false );
dto.setNationalitéModified( false );
dto.setPasseportModified( false );
dto.setPermisModified( false );
dto.setTelephoneModified( false );
dto.setMailModified( false );
dto.setNomacModified( false );
dto.setPrenomacModified( false );
dto.setAdresseacModified( false );
dto.setNationalitéacModified( false );
dto.setPasseportacModified( false );
dto.setPermisacModified( false );
dto.setTelephoneacModified( false );
dto.setMailacModified( false );
}
/**
* Returns all rows from the CLIENT table that match the specified arbitrary SQL statement
*/
public Client[] findByDynamicSelect(String sql, Object[] sqlParams) throws ClientDaoException
{
// declare variables
final boolean isConnSupplied = (userConn != null);
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
// get the user-specified connection or get a connection from the ResourceManager
conn = isConnSupplied ? userConn : ResourceManager.getConnection();
// construct the SQL statement
final String SQL = sql;
System.out.println( "Executing " + SQL );
// prepare statement
stmt = conn.prepareStatement( SQL );
stmt.setMaxRows( maxRows );
// bind parameters
for (int i=0; sqlParams!=null && i<sqlParams.length; i++ ) {
stmt.setObject( i+1, sqlParams[i] );
}
rs = stmt.executeQuery();
// fetch the results
return fetchMultiResults(rs);
}
catch (Exception _e) {
_e.printStackTrace();
throw new ClientDaoException( "Exception: " + _e.getMessage(), _e );
}
finally {
ResourceManager.close(rs);
ResourceManager.close(stmt);
if (!isConnSupplied) {
ResourceManager.close(conn);
}
}
}
/**
* Returns all rows from the CLIENT table that match the specified arbitrary SQL statement
*/
public Client[] findByDynamicWhere(String sql, Object[] sqlParams) throws ClientDaoException
{
// declare variables
final boolean isConnSupplied = (userConn != null);
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
// get the user-specified connection or get a connection from the ResourceManager
conn = isConnSupplied ? userConn : ResourceManager.getConnection();
// construct the SQL statement
final String SQL = SQL_SELECT + " WHERE " + sql;
System.out.println( "Executing " + SQL );
// prepare statement
stmt = conn.prepareStatement( SQL );
stmt.setMaxRows( maxRows );
// bind parameters
for (int i=0; sqlParams!=null && i<sqlParams.length; i++ ) {
stmt.setObject( i+1, sqlParams[i] );
}
rs = stmt.executeQuery();
// fetch the results
return fetchMultiResults(rs);
}
catch (Exception _e) {
_e.printStackTrace();
throw new ClientDaoException( "Exception: " + _e.getMessage(), _e );
}
finally {
ResourceManager.close(rs);
ResourceManager.close(stmt);
if (!isConnSupplied) {
ResourceManager.close(conn);
}
}
}
@Override
public void insert(ClientPk pk, Client dto) throws ClientDaoException {
// TODO Auto-generated method stub
}
}
Partager