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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jul 21 16:00:46 CEST 2011


Author: alfonx
Date: 2011-07-21 16:00:45 +0200 (Thu, 21 Jul 2011)
New Revision: 1640

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/geotools/postgres/PGUtil.java
Log:
Rollenanagement f?\195?\188r Publicationen und Seminare auch in GUI 

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-21 12:39:13 UTC (rev 1639)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/geotools/postgres/PGUtil.java	2011-07-21 14:00:45 UTC (rev 1640)
@@ -143,7 +143,7 @@
 	 */
 	public static boolean createSchemaIfNotExists(Connection c, String schemaname) throws SQLException {
 		if (!existsSchema(c, schemaname)) {
-			c.createStatement().execute("create schema " + schemaname);
+			c.createStatement().execute("create schema " + schemaname.toLowerCase());
 			return true;
 		}
 		return false;
@@ -154,7 +154,7 @@
 	 */
 	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 + "'");
+				"select 1 from pg_catalog.pg_namespace where nspname = '" + schemaname.toLowerCase() + "'");
 		return rs.next();
 	}
 
@@ -170,7 +170,7 @@
 				.createStatement()
 				.executeQuery(
 						"select rolname from pg_user join pg_auth_members on (pg_user.usesysid=pg_auth_members.member) join pg_roles on (pg_roles.oid=pg_auth_members.roleid) where pg_user.usename='"
-								+ username + "'");
+								+ username.toLowerCase() + "'");
 		while (rs.next()) {
 			roles.add(rs.getString(1));
 		}
@@ -188,7 +188,7 @@
 	public static List<String> listTablesInSchema(Connection c, String schemaname) throws SQLException {
 		List<String> tables = new ArrayList<String>();
 
-		String sql = "select tablename from pg_tables where schemaname = '" + schemaname + "'";
+		String sql = "select tablename from pg_tables where schemaname = '" + schemaname.toLowerCase() + "'";
 		ResultSet rs = c.createStatement().executeQuery(sql);
 		while (rs.next()) {
 			tables.add(rs.getString(1));
@@ -207,4 +207,20 @@
 		}
 		return false;
 	}
+
+	public static boolean existsRole(Connection c, String rolename) throws SQLException {
+		ResultSet rs = c.createStatement().executeQuery(
+				"select count(1) from pg_roles where rolname = '" + rolename.toLowerCase() + "'");
+		if (rs.next())
+			return rs.getInt(1) > 0;
+		return false;
+	}
+
+	public static void removeAllPrivilegesFrom(Connection c, String rolename, String tablename) throws SQLException {
+		c.createStatement().executeUpdate("revoke all on TABLE " + tablename.toLowerCase() + " from " + rolename.toLowerCase() + " cascade");
+	}
+
+	public static void dropRoleIfExists(Connection c, String rolename) throws SQLException {
+		c.createStatement().executeUpdate("drop role if exists " + rolename.toLowerCase());
+	}
 }



More information about the Schmitzm-commits mailing list