return ri;
}
public CityLocationInfo findCity(City city, AddressOptions ao, int idLicenca) throws Exception {
CityLocationInfo cityLocationInfo = new CityLocationInfo();
CityLocation[] location;
try {
int iCount = 0;
Pagination pg;
// Se for diferente de 0,1,2 ou 3, seta o valor padr�o de 2 -
// anywhere
if ((ao.getSearchType() != AddressOptions.Exact) && (ao.getSearchType() != AddressOptions.BeginsWith)
&& (ao.getSearchType() != AddressOptions.Anywhere) && (ao.getSearchType() != AddressOptions.EndsWith))
ao.setSearchType(AddressOptions.Anywhere);
String country;
if (!Functions.IsNullOrEmpty(city.getCountry()))
country = city.getCountry();
else
country = "BRASIL";
// transformar valores null em "" para n�o dar null pointer
// exception
if (city.getName() == null)
city.setName("");
if (city.getState() == null)
city.setState("");
Connection con = dataBase.getConnection(Functions.getDataBase(idLicenca, country).getSource());
CallableStatement cst = null;
cst = con.prepareCall("{call CP_WS_TB_CIDADES_SELECT_FONETICO(?,?,?,?,?)}");
cst.setString(1, city.getName());
cst.setString(2, city.getState());
cst.setInt(3, (ao.isUsePhonetic()) ? 1 : 0);
cst.setInt(4, ao.getSearchType());
cst.setInt(5, 0);
cst.execute();
ResultSet rs1 = cst.getResultSet();
CachedRowSetImpl crs = new CachedRowSetImpl();
crs.populate(rs1);
int TotalRecords = crs.size();
if (TotalRecords > 0) {
pg = Functions.definePage(TotalRecords, ao.getResultRange().getRecordsPerPage(), ao.getResultRange().getPageIndex());
if (pg.getRecordsInitial() <= TotalRecords) {
location = new CityLocation[(pg.getRecordsFinal() - pg.getRecordsInitial()) + 1];
for (int intI = pg.getRecordsInitial(); intI <= pg.getRecordsFinal(); intI++) {
if (rs1.absolute(intI)) {
// definir city
location[iCount] = new CityLocation();
location[iCount].setCity(new City());
location[iCount].getCity().setName(rs1.getString("MUNICY"));
location[iCount].getCity().setState(rs1.getString("UF"));
// definir point
location[iCount].setPoint(new Point());
location[iCount].getPoint().setX(Double.parseDouble(rs1.getString("X")));
location[iCount].getPoint().setY(Double.parseDouble(rs1.getString("Y")));
// definir carAccess
location[iCount].setCarAccess(true);
// atribuir CEP
location[iCount].setZipRangeStart(rs1.getString("CEP_INI"));
location[iCount].setZipRangeEnd(rs1.getString("CEP_FIM"));
location[iCount].setCapital(rs1.getBoolean("CAPITAL"));
location[iCount].setAddressesAvailable(true);
iCount++;
}
}
} else {
location = new CityLocation[0];
}
cityLocationInfo.setRecordCount((int) pg.getRecordCount());
cityLocationInfo.setPageCount(pg.getPageCount());
cityLocationInfo.setCityLocation(location);
} else {
location = new CityLocation[0];
cityLocationInfo.setCityLocation(location);
}
con.close();
rs1.close();
crs.close();