contactquery.java

来自「Java的框架」· Java 代码 · 共 97 行

JAVA
97
字号
package mcaps.apps.prrm.roaddefect.dao.jdbc.query;

import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

import mcaps.apps.prrm.roaddefect.dao.util.ContactField;
import mcaps.apps.prrm.roaddefect.model.Contact;
import mcap.core.base.dao.jdbc.SQLQuery;
import mcap.core.base.dao.util.SortOrder;
import mcaps.apps.prrm.util.TableNameConstants;

/**
 * The class that extends the SQLQuery class to customize
 * the query for contact table.
 * 
 * @author jov
 * @date Sept 25, 2005
 * @version 1.0.1.0
 */
public class ContactQuery extends SQLQuery {

	/**
	 * The default constructor that accepts datasource and 
	 * provides the contact table name to initialize the super
	 * class constructor.
	 * @param ds the datasource object
	 */
	public ContactQuery(DataSource ds) {
		super(ds,TableNameConstants.CONTACT_TABLENAME);
	}

	/**
	 * The constructor that accepts datasource and additional 
	 * parameters like where clause and param types of the where
	 * clause parameters and provides table name to initialize the super
	 * class constructor.
	 * @param ds the datasource object
	 * @param whereClause where clause to refine the query
	 * @param paramTypes the array of parameter types
	 */
	public ContactQuery(DataSource ds, String whereClause, 
																			int[] paramTypes) {
		super(ds,TableNameConstants.CONTACT_TABLENAME,whereClause,paramTypes);
	}

	/**
	 * The constructor that accepts datasource and additional 
	 * parameters like where clause, param types of the where
	 * clause parameters, sort column index, sort order and provides 
	 * table name to initialize the super class constructor.
	 * @param ds the datasource object
	 * @param whereClause where clause to refine the query
	 * @param paramTypes the array of parameter types
	 * @param sortFieldIdx the sort field index
	 * @param order the sort order
	 */
	public ContactQuery(DataSource ds, String whereClause, 
											int[] paramTypes,int sortFieldIdx, 
											SortOrder order) {
		super(ds, TableNameConstants.CONTACT_TABLENAME, whereClause, 
				paramTypes, sortFieldIdx, order);
	}

	
	/* (non-Javadoc)
	 * @see org.springframework.jdbc.object.MappingSqlQuery#mapRow(java.sql.ResultSet, int)
	 */
	protected Object mapRow(ResultSet rs, int rowNum) throws SQLException {
		int i = 0;
		Contact contact = new Contact();
		contact.setId(new Integer(rs.getInt(ContactField.FIELDS[i++])));
		contact.setFirstName(rs.getString(ContactField.FIELDS[i++]));
		contact.setLastName(rs.getString(ContactField.FIELDS[i++]));
		contact.setBlock(rs.getString(ContactField.FIELDS[i++]));
		contact.setFloor(rs.getInt(ContactField.FIELDS[i++]));
		contact.setUnit(rs.getInt(ContactField.FIELDS[i++]));
		contact.setRoadName(rs.getString(ContactField.FIELDS[i++]));
		contact.setPostcode(rs.getString(ContactField.FIELDS[i++]));
		contact.setCountry(rs.getString(ContactField.FIELDS[i++]));
		contact.setTelephone(rs.getString(ContactField.FIELDS[i++]));
		contact.setEmail(rs.getString(ContactField.FIELDS[i++]));
		contact.setLastModifiedTime(rs.getTimestamp(ContactField.FIELDS[i++]));
		return contact;
	}
	
	/* (non-Javadoc)
	 * @see mcapss.prrm.base.dao.jdbc.SQLQuery#getSelectFieldsName()
	 */
	protected String[] getSelectFieldsName(){
		return ContactField.FIELDS;		
	}


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?