Alejandro Acuña
2024-10-07 e68f1da78bc96da5410d19e0486446917d263fc6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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();
    }
 
}