return pi;
}
public ProximityInfo findRadiusFromXY(Point point, int radius, ProximityOptions po, int idLicenca) throws Exception
{
ProximityInfo pi = new ProximityInfo();
try
{
String[] tb;
String[] whereClause;
tb = po.getPoiDataSource().split(Pattern.quote("|"));
if (Functions.IsNullOrEmpty(po.getWhereClause()))
po.setWhereClause("");
whereClause = po.getWhereClause().split(Pattern.quote("|"));
// verifica se o n�mero de tabelas � igual ao n�mero de clausulas
// where
if ((tb.length != whereClause.length) || (po.getFieldList().length() == 0))
throw (new Exception("Numero de poiDataSource e diferente do numero de whereClause ou fieldList e esta em branco."));
Boolean validos = validarPoiDataSource(tb, po.getFieldList(), po.getWhereClause(), idLicenca);
if (!validos)
throw (new Exception("poiDatasource ou fieldList invalidos."));
int i = 0;
String strSelect = "";
String fields = po.getFieldList();
String orderBy = "";
fields = fields.replace("|", ",");
Extent ext = new Extent();
double raio = radius * 9.7125097125097125097125097125097e-6;
ext.setXMin(point.getX() - raio);
ext.setXMax(point.getX() + raio);
ext.setYMin(point.getY() + raio);
ext.setYMax(point.getY() - raio);
if (fields.split(Pattern.quote(",")).length > 0)
orderBy = " , " + fields.split(Pattern.quote(","))[0];
if (whereClause[0] != "")
whereClause[0] = "and " + whereClause[0];
strSelect = "select count(1) as total from dados_clientes." + tb[i] + " where x<>0 and ((x>=" + ext.getXMin() + " and x<=" + ext.getXMax() + ") and (y>=" + ext.getYMin() + " and y<="
+ ext.getYMax() + "))" + whereClause[0];
Connection con = dataBase.getConnection("DADOS_WEBSERVICES");
Statement st = con.createStatement();
ResultSet rr = st.executeQuery(strSelect.toUpperCase());
rr.next();
int nrReg = rr.getInt("total");
rr.close();
st.close();
con.close();
if (po.getResultRange().getRecordsPerPage() > 50)
po.getResultRange().setRecordsPerPage(50);
if (po.getResultRange().getRecordsPerPage() < 1)
po.getResultRange().setRecordsPerPage(5);
Pagination pg = Functions.definePage(nrReg, po.getResultRange().getRecordsPerPage(), po.getResultRange().getPageIndex());
strSelect = "select tabela, x, y, 102960 * SQRT(POWER(x - " + point.getX() + ",2) + POWER(y - " + point.getY() + ",2)) as distancia, " + fields + " from dados_clientes." + tb[i]
+ " where x<>0 and ((x>=" + ext.getXMin() + " and x<=" + ext.getXMax() + ") and (y>=" + ext.getYMin() + " and y<=" + ext.getYMax() + "))" + whereClause[0] + " order by distancia "
+ orderBy + " LIMIT " + (pg.getRecordsInitial() - 1) + "," + (pg.getRecordsFinal());
con = dataBase.getConnection("DADOS_WEBSERVICES");
st = con.createStatement();
rr = st.executeQuery(strSelect.toUpperCase());
int columnCount = rr.getMetaData().getColumnCount();
String[][] resultSet = new String[Math.abs((pg.getRecordsInitial() - 1) - pg.getRecordsFinal())][columnCount];
while (rr.next())
{
int w = rr.getRow();
for (int j = 1; j < columnCount + 1; j++)
{
if (j == 4)
resultSet[w - 1][j - 1] = String.valueOf(rr.getObject(j)).substring(0, String.valueOf(rr.getObject(j)).indexOf("."));
else
resultSet[w - 1][j - 1] = String.valueOf(rr.getObject(j));
}
}
pi.setResultSet(resultSet);
pi.setRecordCount(nrReg);
if (po.getResultRange().getRecordsPerPage() != 0)
{
pi.setPageCount(nrReg / po.getResultRange().getRecordsPerPage());
if (pi.getRecordCount() % po.getResultRange().getRecordsPerPage() > 0)
pi.setPageCount(pi.getPageCount() + 1);
}
else
pi.setPageCount(1);
rr.close();
st.close();
con.close();