LocationInqDAOImpl.java
package com.mycim.server.reticle.dao.impl;
import com.mycim.framework.jdbc.JdbcTemplate;
import com.mycim.framework.jdbc.mapper.RowMapper;
import com.mycim.server.reticle.dao.LocationInqDAO;
import com.mycim.valueobject.consts.DataBaseNames;
import com.mycim.valueobject.ems.Location;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* location查询实现类
* @author can.yang
*/
@Repository
public class LocationInqDAOImpl implements LocationInqDAO {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public Location getLocationById(String locationId) {
StringBuilder sql = new StringBuilder("SELECT ");
sql.append(" LOCATION_RRN, LOCATION_ID, LOCATION_ID_MAIN, LOCATION_R, LOCATION_C, LOCATION_P,LOCATION_TYPE FROM ");
sql.append(DataBaseNames.LOCATION);
sql.append(" WHERE LOCATION_ID = ? ");
List arge = new ArrayList();
arge.add(locationId);
return jdbcTemplate.queryForObjectWithNull(sql.toString(), arge.toArray(), new RowMapper<Location>() {
@Override
public Location mapRow(ResultSet rs, int rowNum) throws SQLException {
Location location = new Location();
location.setInstanceRrn(rs.getLong("LOCATION_RRN"));
location.setLocationIdMain(rs.getString("LOCATION_ID_MAIN"));
location.setLocationR(rs.getString("LOCATION_R"));
location.setLocationC(rs.getString("LOCATION_C"));
location.setLocationP(rs.getLong("LOCATION_P"));
location.setLocationId(rs.getString("LOCATION_ID"));
location.setLocationType(rs.getString("LOCATION_TYPE"));
return location;
};
});
}
@Override
public Location getLocationByRrn(Long locationRrn) {
StringBuilder sql = new StringBuilder("SELECT ");
sql.append(" LOCATION_RRN, LOCATION_ID, LOCATION_ID_MAIN, LOCATION_R, LOCATION_C, LOCATION_P,LOCATION_TYPE FROM ");
sql.append(DataBaseNames.LOCATION);
sql.append(" WHERE LOCATION_RRN = ? ");
List arge = new ArrayList();
arge.add(locationRrn);
return jdbcTemplate.queryForObjectWithNull(sql.toString(), arge.toArray(), new RowMapper<Location>() {
@Override
public Location mapRow(ResultSet rs, int rowNum) throws SQLException {
Location location = new Location();
location.setInstanceRrn(rs.getLong("LOCATION_RRN"));
location.setLocationIdMain(rs.getString("LOCATION_ID_MAIN"));
location.setLocationR(rs.getString("LOCATION_R"));
location.setLocationC(rs.getString("LOCATION_C"));
location.setLocationP(rs.getLong("LOCATION_P"));
location.setLocationId(rs.getString("LOCATION_ID"));
location.setLocationType(rs.getString("LOCATION_TYPE"));
return location;
};
});
}
}