package art.servers.transactionsserver.test.persistence;
|
|
|
import art.library.model.devices.user.User;
|
import art.library.persistence.PersistenceDatabase;
|
import art.library.persistence.PersistenceDatabaseParameters;
|
import java.lang.annotation.Annotation;
|
import java.sql.ResultSet;
|
import java.util.logging.Level;
|
import java.util.logging.Logger;
|
|
public class PersistanceTestGIS
|
{
|
static PersistenceDatabase persistence = null;
|
|
public static void main(String[] args) throws Exception
|
{
|
try
|
{
|
// String DIJKSTRA_QUERY
|
// = "SELECT "
|
// + "seq, "
|
// + "b.osm_id as osm_id, "
|
// + "id1 AS node, "
|
// + "b.source AS source, "
|
// + "b.target AS target, "
|
// + "id2 AS edge, "
|
// + "b.cost, "
|
// + "ST_AsGeoJSON(geom_way) as nodosRuta, "
|
// + "b.km as distance, "
|
// + "b.clazz as TipoVia, "
|
// + "b.kmh as vel_teo "
|
// + "FROM pgr_dijkstra( "
|
// + "'SELECT id AS id, "
|
// + "source::integer, "
|
// + "target::integer AS target, "
|
// + "cost::double precision AS cost, "
|
// + "reverse_cost::double precision "
|
// // + "FROM " + PGR + "', ?, ?, false, true) a "
|
// + "FROM " + PGR + "', ?, ?, true, true) a "
|
// + "LEFT JOIN " + PGR + " b ON (a.id2 = b.id) order by seq asc";
|
|
|
|
PersistenceDatabaseParameters p = new PersistenceDatabaseParameters();
|
p.type = "postgresql";
|
p.driver = "org.postgresql.Driver";
|
p.connectionString = "jdbc:postgresql://172.16.11.199:5432/gis_mataro";
|
p.user = "postgres";
|
p.password = "p0stgr3s";
|
p.connections = 1;
|
p.pendingFolder = "database/pending/timeless";
|
p.pendingDays = 7;
|
p.pendingTimer = 60;
|
persistence = new PersistenceDatabase(p);
|
|
String name = (String) getAnnotation(User.class, "Table", "name");
|
ResultSet rs = persistence.executeQuery("select * from mataro_2po_vertex limit 1");
|
while (rs.next())
|
{
|
System.out.println(rs.getString(1));
|
}
|
|
//List<User> users = (List<User>) (List<?>) persistence.getObject(User.class.getName(), "rol = rol GROUP BY rol");
|
|
} catch (Exception e)
|
{
|
Logger.getLogger(PersistanceTestUsers.class.getName()).log(Level.INFO, "", e);
|
}
|
}
|
|
public static Object getAnnotation(Class clase, String annotationName, String attributeName) throws Exception
|
{
|
Annotation[] annotations = clase.getDeclaredAnnotations();
|
|
for (Annotation annotation : annotations)
|
{
|
if (annotation.annotationType().getSimpleName().equals(annotationName))
|
{
|
Object result = annotation.annotationType().getMethod(attributeName).invoke(annotation);
|
return result;
|
}
|
}
|
|
throw new Exception();
|
}
|
|
}
|