[Schmitzm-commits] r1836 - trunk/schmitzm-db/src/main/java/de/schmitzm/postgres

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Jan 23 23:24:06 CET 2012


Author: alfonx
Date: 2012-01-23 23:24:05 +0100 (Mon, 23 Jan 2012)
New Revision: 1836

Added:
   trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/PGPostGisMetadata.java
Modified:
   trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/PGUtil.java
Log:


Added: trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/PGPostGisMetadata.java
===================================================================
--- trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/PGPostGisMetadata.java	2012-01-23 20:47:50 UTC (rev 1835)
+++ trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/PGPostGisMetadata.java	2012-01-23 22:24:05 UTC (rev 1836)
@@ -0,0 +1,69 @@
+package de.schmitzm.postgres;
+
+public class PGPostGisMetadata {
+
+	public PGPostGisMetadata(String schema, String tablename, String geomcol, Integer numDim, Integer srid, String type) {
+		this.schema = schema;
+		this.tablename = tablename;
+		this.geomcol = geomcol;
+		this.numDim = numDim;
+		this.type = type;
+		this.srid = srid;
+	}
+
+	private String schema;
+	private String tablename;
+	private Integer numDim;
+	private String type;
+	private Integer srid;
+	private String geomcol;
+
+	public String getSchema() {
+		return schema;
+	}
+
+	public void setSchema(String schema) {
+		this.schema = schema;
+	}
+
+	public String getTablename() {
+		return tablename;
+	}
+
+	public void setTablename(String tablename) {
+		this.tablename = tablename;
+	}
+
+	public Integer getNumDim() {
+		return numDim;
+	}
+
+	public void setNumDim(Integer numDim) {
+		this.numDim = numDim;
+	}
+
+	public String getType() {
+		return type;
+	}
+
+	public void setType(String type) {
+		this.type = type;
+	}
+
+	public Integer getSrid() {
+		return srid;
+	}
+
+	public void setSrid(Integer srid) {
+		this.srid = srid;
+	}
+
+	public String getGeomcol() {
+		return geomcol;
+	}
+
+	public void setGeomcol(String geomcol) {
+		this.geomcol = geomcol;
+	}
+
+}


Property changes on: trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/PGPostGisMetadata.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/PGUtil.java
===================================================================
--- trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/PGUtil.java	2012-01-23 20:47:50 UTC (rev 1835)
+++ trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/PGUtil.java	2012-01-23 22:24:05 UTC (rev 1836)
@@ -134,29 +134,32 @@
 		return columns;
 	}
 
-	/**
-	 * Querys the <code>geometry_columns</code> table. It is part of every POSTGIS installation and must/should describe
-	 * the geometry columns and tables.
-	 * 
-	 * @deprecated
-	 */
-	static public String[] create(Statement s) {
-		String[] columns = new String[0];
+	public static PGPostGisMetadata getPostGisMetadata(Connection c, String tablename, String geoCol)
+			throws SQLException {
+
+		String schema = "public";
+		if (tablename.contains(".")) {
+			final String[] split = tablename.split("\\.");
+			schema = split[0];
+			tablename = split[1];
+		}
+
+		String sql = "SELECT coord_dimension, srid, type FROM geometry_columns where f_table_catalog='' and f_table_name='"
+				+ tablename + "' and f_geometry_column=" + geoCol;
+		ResultSet rs = null;
+		Statement s = c.createStatement();
 		try {
-			ResultSet rs = s.executeQuery("SELECT f_table_name FROM geometry_columns;");
-			try {
-
-				while (rs.next()) {
-					columns = LangUtil.extendArray(columns, rs.getString(1));
-				}
-			} finally {
+			rs = s.executeQuery(sql);
+			if (rs.next()) {
+				PGPostGisMetadata metadata = new PGPostGisMetadata(schema, tablename, geoCol, rs.getInt(1),
+						rs.getInt(2), rs.getString(3));
+				return metadata;
+			} else
+				return null;
+		} finally {
+			if (rs != null)
 				rs.close();
-			}
-		} catch (SQLException e) {
-			log.error(e, e);
 		}
-
-		return columns;
 	}
 
 	/**
@@ -193,6 +196,7 @@
 				+ ",'"
 				+ type.toUpperCase()
 				+ "' );";
+
 	}
 
 	/**



More information about the Schmitzm-commits mailing list