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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Oct 2 15:26:30 CEST 2011


Author: alfonx
Date: 2011-10-02 15:26:29 +0200 (Sun, 02 Oct 2011)
New Revision: 1745

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


Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/postgres/PGUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/postgres/PGUtil.java	2011-09-30 13:45:06 UTC (rev 1744)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/postgres/PGUtil.java	2011-10-02 13:26:29 UTC (rev 1745)
@@ -455,7 +455,7 @@
 		String sqlTableSpace = tablespace == null ? "" : " TABLESPACE " + tablespace;
 
 		String sqlUsing = type == null ? "" : " USING " + type;
-		
+
 		final String queryString = "CREATE " + (unique ? "UNIQUE " : "") + "INDEX " + idxName + " ON " + tableName
 				+ sqlUsing + " (" + columns + ") " + sqlFillFactor + sqlTableSpace;
 		try {
@@ -558,4 +558,33 @@
 		return count;
 	}
 
+	/**
+	 * Existiert ein relationsname als View?
+	 * 
+	 * @param viewName
+	 *            Darf eine Schemaangabe mit . Trenner enthalten.
+	 * @throws SQLException
+	 */
+	public static boolean existsView(Connection c, String viewName) throws SQLException {
+
+		String schema = "public";
+
+		if (viewName.contains(".")) {
+			final String[] split = viewName.split("\\.");
+			schema = split[0];
+			viewName = split[1];
+		}
+
+		final String checkView = "SELECT * FROM information_schema.VIEWS where table_schema = '" + schema
+				+ "' and table_name = '" + viewName + "' LIMIT 1";
+		ResultSet rs = c.createStatement().executeQuery(checkView);
+
+		return rs.next();
+	}
+
+	public static void dropViewIfExists(Connection c, String viewName) throws SQLException {
+		final String dropView = "DROP VIEW IF EXISTS " + viewName;
+		c.createStatement().executeUpdate(dropView);
+	}
+
 }



More information about the Schmitzm-commits mailing list