roaddefectquery.java

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

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

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;


import mcaps.apps.prrm.roaddefect.dao.jdbc.query.ContactByIdQuery;
import mcaps.apps.prrm.roaddefect.dao.util.RoadDefectField;
import mcaps.apps.prrm.roaddefect.model.Contact;
import mcaps.apps.prrm.roaddefect.model.Road;
import mcaps.apps.prrm.roaddefect.model.RoadDefect;
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 road defect.
 * 
 * @author jov
 * @date Sep 23, 2005
 * @version 1.0.1.0
 */
public class RoadDefectQuery extends SQLQuery {

	private ContactByIdQuery contactByIdQuery;
	private RoadQuery roadQuery;

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

	/**
	 * The constructor that accepts datasource and additional 
	 * parameters like sort field index and sort order 
	 * and provides table name to initialize the super
	 * class constructor.
	 * @param ds the datasource object
	 * @param sortColumnIdx the index of the field in which used as sort column
	 * @param order the sort order
	 */
	public RoadDefectQuery(DataSource ds, int sortColumnIdx, SortOrder order) {
		super(ds, TableNameConstants.ROADDEFECT_TABLENAME, sortColumnIdx, order);
	}

	/**
	 * The constructor that accepts datasource and additional 
	 * parameters like sort field index array and sort order array
	 * and provides table name to initialize the super
	 * class constructor.
	 * @param ds the datasource object
	 * @param sortFieldIdxArray the array off sort field index
	 * @param orderArray the array of the sort order for the sort fields
	 */
	public RoadDefectQuery(DataSource ds, int[] sortColumnIdxArray, SortOrder[] sortOrderArray) {
		super(ds, TableNameConstants.ROADDEFECT_TABLENAME, sortColumnIdxArray, sortOrderArray);
	}

	/**
	 * 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 RoadDefectQuery(DataSource ds, String whereClause, int[] paramTypes){
		super(ds, TableNameConstants.ROADDEFECT_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 RoadDefectQuery(DataSource ds, String whereClause, 
													int[] paramTypes, int sortColIdx,
													SortOrder order) {
		super(ds, TableNameConstants.ROADDEFECT_TABLENAME, whereClause, paramTypes, sortColIdx, order);
	}

	/**
	 * The constructor that accepts datasource and additional 
	 * parameters like where clause and param types of the where
	 * clause parameters, sort field index array, sort order
	 * array 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 sortFieldIdxArray the array of sort field index
	 * @param orderArray the array of sort order
	 */
	public RoadDefectQuery(DataSource ds, String whereClause, 
													int[] paramTypes, int[] sortColumnIdxArray, 
													SortOrder[] sortOrderArray) {
		super(ds, TableNameConstants.ROADDEFECT_TABLENAME, whereClause, paramTypes, sortColumnIdxArray, sortOrderArray);
	}


	/**
	 * Sets the contactByIdQuery.
	 * @param contactByIdQuery The contactByIdQuery to set.
	 */
	public void setContactByIdQuery (ContactByIdQuery contactByIdQuery) {
		this.contactByIdQuery = contactByIdQuery;
	}
	
	/**
	 * Sets the roadQuery.
	 * @param roadQuery The roadQuery to set.
	 */
	public void setRoadQuery (RoadQuery roadQuery) {
		this.roadQuery = roadQuery;
	}

	/* (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;
		RoadDefect roadDefect = new RoadDefect();
		roadDefect.setContact(new Contact());

		roadDefect.setId(new Integer(rs.getInt(RoadDefectField.FIELDS[i++])));
		roadDefect.setDefectType(rs.getString(RoadDefectField.FIELDS[i++]));
		roadDefect.setDefectDetail(rs.getString(RoadDefectField.FIELDS[i++]));
		roadDefect.setLocation(rs.getString(RoadDefectField.FIELDS[i++]));
		roadDefect.setSeverity(rs.getString(RoadDefectField.FIELDS[i++]));
		roadDefect.setStatus(rs.getString(RoadDefectField.FIELDS[i++]));
		Object[] roadParamTypes = new Object[] {new Integer(rs.getInt(RoadDefectField.FIELDS[i++])) };
		List roadList = roadQuery.execute(roadParamTypes);
		if (roadList.size() > 0){
			Road road = (Road)roadList.get(0);
			if (road != null){
				roadDefect.setRoad(road);
			}
		}
		Object[] contactParamTypes = new Object[] { new Integer(rs.getInt(RoadDefectField.FIELDS[i++])) };
		List contactList = contactByIdQuery.execute(contactParamTypes);
		if (contactList.size() > 0){
			Contact contact = (Contact)contactList.get(0);
			if (contact != null){
			roadDefect.setContact(contact);
			}
		}
		roadDefect.setClosedDate(rs.getTimestamp(RoadDefectField.FIELDS[i++]));
		roadDefect.setCreationTime(rs.getTimestamp(RoadDefectField.FIELDS[i++]));
		roadDefect.setLastModifiedTime(rs.getTimestamp(RoadDefectField.FIELDS[i++]));
		return roadDefect;
	}
	
	/* (non-Javadoc)
	 * @see mcapss.prrm.base.dao.jdbc.SQLQuery#getSelectFieldsName()
	 */
	protected String[] getSelectFieldsName(){
		return RoadDefectField.FIELDS;		
	}

	


}

⌨️ 快捷键说明

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