// if it's a geometry column, just return the metadata
if (assertStreamingGeometryColumn(entity, false))
{
GeometryStreamMetadata gsm = (GeometryStreamMetadata) getGeometryData(entity, GeomStreamComponent.TILE_DESCRIPTORS, null);
AttributeColumnData result = new AttributeColumnData();
result.id = entity.id;
result.metadata = entity.publicMetadata;
result.metadataTileDescriptors = gsm.metadataTileDescriptors;
result.geometryTileDescriptors = gsm.geometryTileDescriptors;
return result;
}
String query = entity.privateMetadata.get(PrivateMetadata.SQLQUERY);
String dataType = entity.publicMetadata.get(PublicMetadata.DATATYPE);
ConnectionInfo connInfo = getColumnConnectionInfo(entity);
List<String> keys = new ArrayList<String>();
List<Double> numericData = null;
List<String> stringData = null;
List<Object> thirdColumn = null; // hack for dimension slider format
List<PGGeom> geometricData = null;
// use config min,max or param min,max to filter the data
double minValue = Double.NaN;
double maxValue = Double.NaN;
// server min,max values take priority over user-specified params
if (entity.publicMetadata.containsKey(PublicMetadata.MIN))
{
try {
minValue = Double.parseDouble(entity.publicMetadata.get(PublicMetadata.MIN));
} catch (Exception e) { }
}
else
{
minValue = minParam;
}
if (entity.publicMetadata.containsKey(PublicMetadata.MAX))
{
try {
maxValue = Double.parseDouble(entity.publicMetadata.get(PublicMetadata.MAX));
} catch (Exception e) { }
}
else
{
maxValue = maxParam;
}
if (Double.isNaN(minValue))
minValue = Double.NEGATIVE_INFINITY;
if (Double.isNaN(maxValue))
maxValue = Double.POSITIVE_INFINITY;
try
{
Connection conn = connInfo.getStaticReadOnlyConnection();
// use default sqlParams if not specified by query params
if (sqlParams == null || sqlParams.length == 0)
{
String sqlParamsString = entity.privateMetadata.get(PrivateMetadata.SQLPARAMS);
sqlParams = CSVParser.defaultParser.parseCSVRow(sqlParamsString, true);
}
SQLResult result = SQLUtils.getResultFromQuery(conn, query, sqlParams, false);
// if dataType is defined in the config file, use that value.
// otherwise, derive it from the sql result.
if (Strings.isEmpty(dataType))
{
dataType = DataType.fromSQLType(result.columnTypes[1]);
entity.publicMetadata.put(PublicMetadata.DATATYPE, dataType); // fill in missing metadata for the client
}
if (dataType.equalsIgnoreCase(DataType.NUMBER)) // special case: "number" => Double
{
numericData = new LinkedList<Double>();
}
else if (dataType.equalsIgnoreCase(DataType.GEOMETRY))
{
geometricData = new LinkedList<PGGeom>();
}
else
{
stringData = new LinkedList<String>();
}
// hack for dimension slider format
if (result.columnTypes.length == 3)
thirdColumn = new LinkedList<Object>();
Object keyObj, dataObj;
double value;
for (int i = 0; i < result.rows.length; i++)
{
keyObj = result.rows[i][0];
if (keyObj == null)
continue;
dataObj = result.rows[i][1];
if (dataObj == null)
continue;
if (numericData != null)
{
try
{
if (dataObj instanceof String)
dataObj = Double.parseDouble((String)dataObj);
value = ((Number)dataObj).doubleValue();
}
catch (Exception e)
{
continue;
}
// filter the data based on the min,max values
if (minValue <= value && value <= maxValue)
numericData.add(value);
else
continue;
}
else if (geometricData != null)
{
// The dataObj must be cast to PGgeometry before an individual Geometry can be extracted.
if (!(dataObj instanceof PGgeometry))
continue;
Geometry geom = ((PGgeometry) dataObj).getGeometry();
int numPoints = geom.numPoints();
// Create PGGeom Bean here and fill it up!
PGGeom bean = new PGGeom();
bean.type = geom.getType();
bean.xyCoords = new double[numPoints * 2];
for (int j = 0; j < numPoints; j++)
{
Point pt = geom.getPoint(j);
bean.xyCoords[j * 2] = pt.x;
bean.xyCoords[j * 2 + 1] = pt.y;
}
geometricData.add(bean);
}
else
{
stringData.add(dataObj.toString());
}
// if we got here, it means a data value was added, so add the corresponding key
keys.add(keyObj.toString());
// hack for dimension slider format
if (thirdColumn != null)
thirdColumn.add(result.rows[i][2]);
}
}
catch (SQLException e)
{
System.err.println(query);
e.printStackTrace();
throw new RemoteException(String.format("Unable to retrieve data for column %s", columnId));
}
catch (NullPointerException e)
{
e.printStackTrace();
throw new RemoteException("Unexpected error", e);
}
AttributeColumnData result = new AttributeColumnData();
result.id = entity.id;
result.metadata = entity.publicMetadata;
result.keys = keys.toArray(new String[keys.size()]);
if (numericData != null)
result.data = numericData.toArray();