[Schmitzm-commits] r1631 - trunk/schmitzm-core/src/main/java/de/schmitzm/geotools/postgres

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Jul 18 13:49:11 CEST 2011


Author: alfonx
Date: 2011-07-18 13:49:10 +0200 (Mon, 18 Jul 2011)
New Revision: 1631

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/geotools/postgres/PGUtil.java
Log:


Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/geotools/postgres/PGUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/geotools/postgres/PGUtil.java	2011-07-18 11:43:16 UTC (rev 1630)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/geotools/postgres/PGUtil.java	2011-07-18 11:49:10 UTC (rev 1631)
@@ -77,11 +77,23 @@
 		throw new RuntimeException("DB Type mapping for " + binding
 				+ " not yet implemented.");
 	}
+	
+	/**
+	 * Legt ein Schema an, wenn es vorher nicht existierte. 
+	 * @return <code>true</code> wenn das Schema neu angelegt wurde.
+	 */
+	public static boolean createSchemaIfNotExists(Connection c, String schemaname) throws SQLException {
+		if (!existsSchema(c, schemaname)) {
+			c.createStatement().executeQuery("create schema "+schemaname);
+			return true;
+		}
+		return false;
+	}
 
 	/**
 	 * Liefert <code>true</code> wenn ein Schema mit dem Namen in der PG Datenbank existiert.
 	 */
-	static boolean existsSchema(Connection c, String schemaname) throws SQLException {
+	public static boolean existsSchema(Connection c, String schemaname) throws SQLException {
 		ResultSet rs = c.createStatement().executeQuery("select 1 from pg_catalog.pg_namespace where nspname = '"+schemaname+"'");
 		return rs.next();
 	}



More information about the Schmitzm-commits mailing list