use of com.runwaysdk.dataaccess.ValueObject in project geoprism-registry by terraframe.
the class ChangeRequestService method findPageNumber.
// An attempt to do this without selectable sqls
// private int findPageNumber(String crOid, ChangeRequestQuery query, int pageSize)
// {
// QueryFactory qf = new QueryFactory();
// ValueQuery vq = new ValueQuery(qf);
//
// vq.FROM(query);
//
// vq.SELECT(query.getOid());
// vq.SELECT(query.getCreateDate());
//
// Selectable createDate = query.getCreateDate();
//
// vq.SELECT(vq.RANK("rn").OVER(null, new OrderBy(createDate, SortOrder.DESC)));
//
// vq.WHERE(query.getOid().EQ(crOid));
//
// ValueObject vo = vq.getIterator().getAll().get(0);
//
// long rowNum = Long.parseLong(vo.getValue("rn"));
//
// int pageNum = (int) ( (rowNum / pageSize) + 1 );
//
// return pageNum;
// }
private int findPageNumber(String crOid, ChangeRequestQuery query, int pageSize) {
QueryFactory qf = new QueryFactory();
ValueQuery innerVq = new ValueQuery(qf);
String sub1Sql = query.getSQL();
innerVq.FROM("(" + sub1Sql + ")", "sub1");
String createDateAlias = query.getCreateDate().getColumnAlias();
Matcher m = Pattern.compile("change_request_\\d+\\.create_date AS (create_date_\\d+),").matcher(sub1Sql);
if (m.find()) {
createDateAlias = m.group(1);
}
innerVq.SELECT(innerVq.aSQLCharacter("oid", "oid"));
// The rank function is forcing a group by, which we don't want to do. It also doesn't use our alias.
// SelectableSQLDate createDate = innerVq.aSQLDate(query.getCreateDate().getColumnAlias(), query.getCreateDate().getColumnAlias());
// AggregateFunction rank = innerVq.RANK("rn").OVER(null, new OrderBy(createDate, SortOrder.DESC));
Selectable rank = innerVq.aSQLInteger("rn", "(ROW_NUMBER() OVER (ORDER BY " + createDateAlias + " DESC))");
innerVq.SELECT(rank);
ValueQuery outerVq = new ValueQuery(qf);
outerVq.FROM("(" + innerVq.getSQL() + ")", "sub2");
Selectable oidSel = outerVq.aSQLCharacter("oid", "oid");
outerVq.SELECT(oidSel);
outerVq.SELECT(outerVq.aSQLInteger("rn", "rn"));
outerVq.WHERE(oidSel.EQ(crOid));
List<ValueObject> voList = outerVq.getIterator().getAll();
if (voList.size() > 0) {
ValueObject vo = voList.get(0);
long rowNum = Long.parseLong(vo.getValue("rn"));
int pageNum = (int) ((rowNum / pageSize) + 1);
return pageNum;
} else {
return 1;
}
}
use of com.runwaysdk.dataaccess.ValueObject in project geoprism-registry by terraframe.
the class VectorTileBuilder method writeVectorTiles.
protected byte[] writeVectorTiles(String layerName, Envelope envelope, ValueQuery query) throws IOException {
OIterator<ValueObject> iterator = query.getIterator();
try {
List<Geometry> geometries = new LinkedList<Geometry>();
while (iterator.hasNext()) {
ValueObject object = iterator.next();
AttributeGeometryIF attributeIF = (AttributeGeometryIF) object.getAttributeIF(GeoserverFacade.GEOM_COLUMN);
Geometry geometry = attributeIF.getGeometry();
geometry.setUserData(this.getUserData(object));
geometries.add(geometry);
}
GeometryFactory geomFactory = new GeometryFactory();
IGeometryFilter acceptAllGeomFilter = geometry -> true;
MvtLayerParams layerParams = new MvtLayerParams();
TileGeomResult tileGeom = JtsAdapter.createTileGeom(geometries, envelope, geomFactory, layerParams, acceptAllGeomFilter);
final VectorTile.Tile.Builder tileBuilder = VectorTile.Tile.newBuilder();
// Create MVT layer
final MvtLayerProps layerProps = new MvtLayerProps();
final IUserDataConverter ignoreUserData = new UserDataConverter();
// MVT tile geometry to MVT features
final List<VectorTile.Tile.Feature> features = JtsAdapter.toFeatures(tileGeom.mvtGeoms, layerProps, ignoreUserData);
final VectorTile.Tile.Layer.Builder layerBuilder = MvtLayerBuild.newLayerBuilder(layerName, layerParams);
layerBuilder.addAllFeatures(features);
MvtLayerBuild.writeProps(layerBuilder, layerProps);
// Build MVT layer
final VectorTile.Tile.Layer layer = layerBuilder.build();
// Add built layer to MVT
tileBuilder.addLayers(layer);
// / Build MVT
Tile mvt = tileBuilder.build();
return mvt.toByteArray();
} finally {
iterator.close();
}
}
Aggregations