⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractjdbcclinic.java

📁 spring,z几 塞积极 决撒 积极上经济歼击机就 将计就计经济年毫毫毫毫毫毫毫毫毫毫毫毫毫毫
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	/**
	 * Abstract base class for all <code>Owner</code> Query Objects.
	 */
	protected abstract class OwnersQuery extends MappingSqlQuery {

		/**
		 * Create a new instance of OwnersQuery.
		 * @param ds the DataSource to use for the query
		 * @param sql SQL string to use for the query
		 */
		protected OwnersQuery(DataSource ds, String sql) {
			super(ds, sql);
		}

		protected Object mapRow(ResultSet rs, int rownum) throws SQLException {
			Owner owner = new Owner();
			owner.setId(new Integer(rs.getInt("id")));
			owner.setFirstName(rs.getString("first_name"));
			owner.setLastName(rs.getString("last_name"));
			owner.setAddress(rs.getString("address"));
			owner.setCity(rs.getString("city"));
			owner.setTelephone(rs.getString("telephone"));
			return owner;
		}
	}


	/**
	 * <code>Owner</code>s by last name Query Object.
	 */
	protected class OwnersByNameQuery extends OwnersQuery {

		/**
		 * Create a new instance of OwnersByNameQuery.
		 * @param ds the DataSource to use for the query
		 */
		protected OwnersByNameQuery(DataSource ds) {
			super(ds, "SELECT id,first_name,last_name,address,city,telephone FROM owners WHERE last_name like ?");
			declareParameter(new SqlParameter(Types.VARCHAR));
			compile();
		}
	}


	/**
	 * <code>Owner</code> by id Query Object.
	 */
	protected class OwnerQuery extends OwnersQuery {

		/**
		 * Create a new instance of OwnerQuery.
		 * @param ds the DataSource to use for the query
		 */
		protected OwnerQuery(DataSource ds) {
			super(ds, "SELECT id,first_name,last_name,address,city,telephone FROM owners WHERE id=?");
			declareParameter(new SqlParameter(Types.INTEGER));
			compile();
		}
	}


	/**
	 * <code>Owner</code> Insert Object.
	 */
	protected class OwnerInsert extends SqlUpdate {

		/**
		 * Create a new instance of OwnerInsert.
		 * @param ds the DataSource to use for the insert
		 */
		protected OwnerInsert(DataSource ds) {
			super(ds, "INSERT INTO owners VALUES(?,?,?,?,?,?)");
			declareParameter(new SqlParameter(Types.INTEGER));
			declareParameter(new SqlParameter(Types.VARCHAR));
			declareParameter(new SqlParameter(Types.VARCHAR));
			declareParameter(new SqlParameter(Types.VARCHAR));
			declareParameter(new SqlParameter(Types.VARCHAR));
			declareParameter(new SqlParameter(Types.VARCHAR));
			compile();
		}

		protected void insert(Owner owner) {
			Object[] objs = new Object[] {
				null, owner.getFirstName(), owner.getLastName(),
				owner.getAddress(), owner.getCity(), owner.getTelephone()};
			super.update(objs);
			retrieveIdentity(owner);
		}
	}


	/**
	 * <code>Owner</code> Update Object.
	 */
	protected class OwnerUpdate extends SqlUpdate {

		/**
		 * Create a new instance of OwnerUpdate.
		 * @param ds the DataSource to use for the update
		 */
		protected OwnerUpdate(DataSource ds) {
			super(ds, "UPDATE owners SET first_name=?,last_name=?,address=?,city=?,telephone=? WHERE id=?");
			declareParameter(new SqlParameter(Types.VARCHAR));
			declareParameter(new SqlParameter(Types.VARCHAR));
			declareParameter(new SqlParameter(Types.VARCHAR));
			declareParameter(new SqlParameter(Types.VARCHAR));
			declareParameter(new SqlParameter(Types.VARCHAR));
			declareParameter(new SqlParameter(Types.INTEGER));
			compile();
		}

		/**
		 * Method to update an <code>Owner</code>'s data.
		 * @param owner to update
		 * @return the number of rows affected by the update
		 */
		protected int update(Owner owner) {
			return this.update(new Object[] {
				owner.getFirstName(), owner.getLastName(), owner.getAddress(),
				owner.getCity(), owner.getTelephone(), owner.getId()});
		}
	}


	/**
	 * Abstract base class for all <code>Pet</code> Query Objects.
	 */
	protected abstract class PetsQuery extends MappingSqlQuery {

		/**
		 * Create a new instance of PetsQuery.
		 * @param ds the DataSource to use for the query
		 * @param sql SQL string to use for the query
		 */
		protected PetsQuery(DataSource ds, String sql) {
			super(ds, sql);
		}

		protected Object mapRow(ResultSet rs, int rownum) throws SQLException {
			JdbcPet pet = new JdbcPet();
			pet.setId(new Integer(rs.getInt("id")));
			pet.setName(rs.getString("name"));
			pet.setBirthDate(rs.getDate("birth_date"));
			pet.setTypeId(rs.getInt("type_id"));
			pet.setOwnerId(rs.getInt("owner_id"));
			return pet;
		}
	}


	/**
	 * <code>Pet</code>s by <code>Owner</code> Query Object.
	 */
	protected class PetsByOwnerQuery extends PetsQuery {

		/**
		 * Create a new instance of PetsByOwnerQuery.
		 * @param ds the DataSource to use for the query
		 */
		protected PetsByOwnerQuery(DataSource ds) {
			super(ds, "SELECT id,name,birth_date,type_id,owner_id FROM pets WHERE owner_id=?");
			declareParameter(new SqlParameter(Types.INTEGER));
			compile();
		}
	}


	/**
	 * <code>Pet</code> by id Query Object.
	 */
    protected class PetQuery extends PetsQuery {

		/**
		 * Create a new instance of PetQuery.
		 * @param ds the DataSource to use for the query
		 */
		protected PetQuery(DataSource ds) {
			super(ds, "SELECT id,name,birth_date,type_id,owner_id FROM pets WHERE id=?");
			declareParameter(new SqlParameter(Types.INTEGER));
			compile();
		}
	}


	/**
	 * <code>Pet</code> Insert Object.
	 */
	protected class PetInsert extends SqlUpdate {

		/**
		 * Create a new instance of PetInsert.
		 * @param ds the DataSource to use for the insert
		 */
		protected PetInsert(DataSource ds) {
			super(ds, "INSERT INTO pets VALUES(?,?,?,?,?)");
			declareParameter(new SqlParameter(Types.INTEGER));
			declareParameter(new SqlParameter(Types.VARCHAR));
			declareParameter(new SqlParameter(Types.DATE));
			declareParameter(new SqlParameter(Types.INTEGER));
			declareParameter(new SqlParameter(Types.INTEGER));
			compile();
		}

		/**
		 * Method to insert a new <code>Pet</code>.
		 * @param pet to insert
		 */
		protected void insert(Pet pet) {
			Object[] objs = new Object[] {
				null, pet.getName(), new java.sql.Date(pet.getBirthDate().getTime()),
				pet.getType().getId(), pet.getOwner().getId()};
			super.update(objs);
			retrieveIdentity(pet);
		}
	}


	/**
	 * <code>Pet</code> Update Object.
	 */
	protected class PetUpdate extends SqlUpdate {

		/**
		 * Create a new instance of PetUpdate.
		 * @param ds the DataSource to use for the update
		 */
		protected PetUpdate(DataSource ds) {
			super(ds, "UPDATE pets SET name=?,birth_date=?,type_id=?,owner_id=? WHERE id=?");
			declareParameter(new SqlParameter(Types.VARCHAR));
			declareParameter(new SqlParameter(Types.DATE));
			declareParameter(new SqlParameter(Types.INTEGER));
			declareParameter(new SqlParameter(Types.INTEGER));
			declareParameter(new SqlParameter(Types.INTEGER));
			compile();
		}

		/**
		 * Method to update an <code>Pet</code>'s data.
		 * @param pet to update
		 * @return the number of rows affected by the update
		 */
		protected int update(Pet pet) {
			return this.update(new Object[] {
				pet.getName(), new java.sql.Date(pet.getBirthDate().getTime()),
				pet.getType().getId(), pet.getOwner().getId(), pet.getId()});
		}
	}


	/**
	 * All <code>Pet</code> types Query Object.
	 */
	protected class PetTypesQuery extends MappingSqlQuery {

		/**
		 * Create a new instance of PetTypesQuery.
		 * @param ds the DataSource to use for the query
		 */
		protected PetTypesQuery(DataSource ds) {
			super(ds, "SELECT id,name FROM types ORDER BY name");
			compile();
		}

		protected Object mapRow(ResultSet rs, int rownum) throws SQLException {
			PetType type = new PetType();
			type.setId(new Integer(rs.getInt("id")));
			type.setName(rs.getString("name"));
			return type;
		}
	}


	/**
	 * <code>Visit</code>s by <code>Pet</code> Query Object.
	 */
	protected class VisitsQuery extends MappingSqlQuery {

		/**
		 * Create a new instance of VisitsQuery.
		 * @param ds the DataSource to use for the query
		 */
		protected VisitsQuery(DataSource ds) {
			super(ds, "SELECT id,visit_date,description FROM visits WHERE pet_id=?");
			declareParameter(new SqlParameter(Types.INTEGER));
			compile();
		}

		protected Object mapRow(ResultSet rs, int rownum) throws SQLException {
			Visit visit = new Visit();
			visit.setId(new Integer(rs.getInt("id")));
			visit.setDate(rs.getDate("visit_date"));
			visit.setDescription(rs.getString("description"));
			return visit;
		}
	}


	/**
	 * <code>Visit</code> Insert Object.
	 */
	protected class VisitInsert extends SqlUpdate {

		/**
		 * Create a new instance of VisitInsert.
		 * @param ds the DataSource to use for the insert
		 */
		protected VisitInsert(DataSource ds) {
			super(ds, "INSERT INTO visits VALUES(?,?,?,?)");
			declareParameter(new SqlParameter(Types.INTEGER));
			declareParameter(new SqlParameter(Types.INTEGER));
			declareParameter(new SqlParameter(Types.DATE));
			declareParameter(new SqlParameter(Types.VARCHAR));
			compile();
		}

		/**
		 * Method to insert a new <code>Visit</code>.
		 * @param visit to insert
		 */
		protected void insert(Visit visit) {
			super.update(new Object[] {
				null, visit.getPet().getId(), new java.sql.Date(visit.getDate().getTime()),
				visit.getDescription()});
			retrieveIdentity(visit);
		}
	}

}

⌨️ 快捷键说明

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