cst.execute();
ResultSet rs1 = cst.getResultSet();
CachedRowSetImpl crs = new CachedRowSetImpl();
crs.populate(rs1);
int TotalRecords = crs.size();
AddressLocation[] al;
if (TotalRecords > 0) {
pg = Functions.definePage(TotalRecords, ao.getResultRange().getRecordsPerPage(), ao.getResultRange().getPageIndex());
if (country.toLowerCase().equals("brasil")) {
Statement stEstado = con.createStatement();
crs.next();
String sql = " select FNCCAMELCASE(estado) estado from TB_CIDADES where geocode = '" + crs.getString("TABELA") + "' ";
ResultSet rrEstado = stEstado.executeQuery(sql.toUpperCase());
CachedRowSetImpl crsEstado = new CachedRowSetImpl();
crsEstado.populate(rrEstado);
if (crsEstado.size() != 0) {
crsEstado.next();
state = crsEstado.getString("ESTADO");
}
if (pg.getRecordsInitial() <= TotalRecords) {
al = new AddressLocation[(pg.getRecordsFinal() - pg.getRecordsInitial()) + 1];
for (int intI = pg.getRecordsInitial(); intI <= pg.getRecordsFinal(); intI++) {
if (rs1.absolute(intI)) {
al[iCount] = new AddressLocation();
al[iCount].setZipL(rs1.getString("CEPL"));
al[iCount].setZipR(rs1.getString("CEPR"));
al[iCount].setCarAccess(rs1.getBoolean("ROTAPE"));
// classe address
al[iCount].getAddress().setStreet(rs1.getString("LOGRAC"));
al[iCount].getAddress().setDistrict(rs1.getString("BAIRRO"));
al[iCount].getAddress().getCity().setName(rs1.getString("MUNICIPIO"));
al[iCount].getAddress().getCity().setCountry(country);
// al[iCount].getAddress().setZone(rs1.getString("REGIAO"));
if (!country.toLowerCase().equals("brasil"))
al[iCount].getAddress().getCity().setState(state);
else
al[iCount].getAddress().getCity().setState(rs1.getString("TABELA").substring(0, 2).toUpperCase());
if (!al[iCount].getZipL().equals(""))
al[iCount].getAddress().setZip(al[iCount].getZipL());
if (!al[iCount].getZipR().equals(""))
al[iCount].getAddress().setZip(al[iCount].getZipR());
al[iCount].getAddress().setHouseNumber(rs1.getString("MEDIA"));
try {
al[iCount].setPoint(Functions.getGeocodeSQL(rs1.getInt("L_F_ADD"), rs1.getInt("L_T_ADD"), rs1.getInt("R_F_ADD"),
rs1.getInt("R_T_ADD"), al[iCount].getAddress().getHouseNumber(), rs1.getString("COORDS")));
} catch (Exception ex) {
al[iCount].getPoint().setX(0.0);
al[iCount].getPoint().setY(0.0);
}
iCount++;
}
}
ai.setRecordCount((int) pg.getRecordCount());
ai.setPageCount(pg.getPageCount());
} else {
al = new AddressLocation[0];
// throw (new
// Exception("Endere�o n�o encontrado em nossa base de dados!"));
}
ai.setAddressLocation(al);
}
} else {
if (address.getStreet() == "" && (!Functions.IsNullOrEmpty(address.getZip()))) {
String cmd = " select CEP, CORREIO_ENDERECO AS ENDERECO, CORREIO_MUNICIPIO AS CIDADE, CORREIO_UF AS ESTADO, "
+ " COALESCE(X,0) as X, COALESCE(Y,0) as Y, COALESCE(CORREIO_BAIRRO_INI,'') AS BAIRRO " + " FROM TB_CEP_BRASIL "
+ " WHERE CEP = REPLACE('" + address.getZip() + "','-','') " + " AND X IS NOT NULL".toUpperCase();
con = dataBase.getConnection(dataB);
Statement st = con.createStatement();
ResultSet rr = st.executeQuery(cmd);
crs = new CachedRowSetImpl();
crs.populate(rr);
if (crs.size() == 0) {
crs.next();