/[schmitzm]/trunk/src/skrueger/db/PGUtil.java
ViewVC logotype

Diff of /trunk/src/skrueger/db/PGUtil.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1194 by alfonx, Tue Sep 14 12:45:05 2010 UTC revision 1195 by alfonx, Tue Nov 2 10:33:32 2010 UTC
# Line 1  Line 1 
1  package skrueger.db;  package skrueger.db;
2    
3    import java.sql.ResultSet;
4    import java.sql.SQLException;
5    import java.sql.Statement;
6    
7    import org.apache.log4j.Logger;
8    import org.opengis.referencing.crs.CoordinateReferenceSystem;
9    
10    import schmitzm.lang.LangUtil;
11    
12  /**  /**
13   * Hilfsmethoden für PostgreSQL   * Hilfsmethoden für PostgreSQL
14   */   */
15  public class PGUtil {  public class PGUtil {
16                    static final Logger log = Logger.getLogger(PGUtil.class);
17  // TODO isGeoColumn();  
18            /**
19             * Querys the <code>geometry_columns</code> table is part of every postgis
20             * installation and must/should describe the geometry columns and tables.
21             */
22            static public String[] getColumnsDescribedInGeometryColumnsTable(Statement s) {
23                    String[] columns = new String[0];
24                    try {
25                            ResultSet askGeoe = s
26                                            .executeQuery("SELECT f_table_name FROM geometry_columns;");
27                            while (askGeoe.next()) {
28                                    columns = LangUtil.extendArray(columns, askGeoe.getString(1));
29                            }
30                    } catch (SQLException e) {
31                            log.error(e, e);
32                    }
33    
34                    return columns;
35    
36            }
37    
38            public static int getSridForCRS(CoordinateReferenceSystem crs) {
39                    String full = crs.toWKT().toUpperCase(); // ...
40                    // AUTHORITY["EPSG","900913"]]
41                    String s1 = "AUTHORITY[\"EPSG\",\"";
42                    int p1 = full.indexOf(s1);
43                    if (p1 >= 0) {
44                            String s = full.substring(p1 + s1.length());
45                            int p2 = s.indexOf("\"]");
46                            if (p2 > 0) {
47                                    s = s.substring(0, p2);
48                                    return Integer.parseInt(s);
49                            }
50                    }
51                    return -1;
52            }
53    
54            public static void createOrUpdateGeometrsColumnsEntry(String tableName,
55                            String geoColumnName, CoordinateReferenceSystem crs) {
56                    createOrUpdateGeometrsColumnsEntry(tableName, geoColumnName,
57                                    getSridForCRS(crs));
58            }
59    
60            /**
61             * Creates or Updates
62             *
63             * @param tableName
64             * @param geoColumnName
65             * @param srid
66             */
67            public static void createOrUpdateGeometrsColumnsEntry(String tableName,
68                            String geoColumnName, int srid) {
69    
70                    String createGeometryEntrySQL = "INSERT INTO geometry_columns (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, \"type\") VALUES ( '', 'public', '"
71                                    + tableName
72                                    + "', '"
73                                    + geoColumnName
74                                    + "', 2, "
75                                    + srid
76                                    + ",'MULTIPOLYGON' ) LIMIT 1;";
77            }
78    
79            // TODO isGeoColumn();
80    
81          /**          /**
82           * @param binding           * @param binding
83           *            Eine "einfache" Javaklasse, die in PG abgebildet werden soll.           *            Eine "einfache" Javaklasse, die in PG abgebildet werden soll.
84           * @return einen PG-spezifischen Datentypenamen für einen Javatyp zurück, z.b. "double precision" für <code>Double.class</code>           * @return einen PG-spezifischen Datentypenamen für einen Javatyp zurück,
85             *         z.b. "double precision" für <code>Double.class</code>
86           */           */
87          public static String getColTypeName(Class<?> binding) {          public static String getColTypeName(Class<?> binding) {
88    

Legend:
Removed from v.1194  
changed lines
  Added in v.1195

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26