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

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Wed Oct 9 10:05:42 CEST 2013


Author: alfonx
Date: 2013-10-09 10:05:42 +0200 (Wed, 09 Oct 2013)
New Revision: 2396

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


Modified: trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/PGUtil.java
===================================================================
--- trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/PGUtil.java	2013-10-08 21:16:59 UTC (rev 2395)
+++ trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/PGUtil.java	2013-10-09 08:05:42 UTC (rev 2396)
@@ -137,37 +137,6 @@
 		createRole(c, rolename, inhRoles);
 	}
 
-	//
-	// /**
-	// * Querys the <code>geometry_columns</code> table. It is part of every
-	// POSTGIS installation and must/should describe
-	// * the geometry columns and tables.
-	// *
-	// * @return Liste von String[], wobei jeder String[] ein Paar aus Schema
-	// und Tabelle
-	// *
-	// */
-	// static public List<String[]>
-	// getTabelsDescribedInGeometryColumnsTable(Statement s) {
-	// String[] columns = new String[0];
-	// try {
-	// ResultSet rs =
-	// s.executeQuery("SELECT distinct f_table_name FROM geometry_columns;");
-	// try {
-	//
-	// while (rs.next()) {
-	// columns = LangUtil.extendArray(columns, rs.getString(1));
-	// }
-	// } finally {
-	// rs.close();
-	// }
-	// } catch (SQLException e) {
-	// log.error(e, e);
-	// }
-	//
-	// return columns;
-	// }
-
 	/**
 	 * Liefert ein {@link PGPostGisMetadata} Objekt für die angefragte Geometry-Spalte in der angegebenen Tabelle.
 	 * 
@@ -526,22 +495,6 @@
 	 * @throws SQLException
 	 */
 	public static void createOrReplaceTriggerFunction(Connection c, String name, String plCommands) throws SQLException {
-		// System.err.println(plCommands);
-
-		// String sql = "CREATE OR REPLACE FUNCTION " + name + "()" +
-		// " RETURNS trigger AS $" + name
-		// + "$\nBEGIN\n?\nRETURN NEW;" + "\nEND;\n$" + name +
-		// "$ LANGUAGE 'plpgsql'";
-		// PreparedStatement ps = c.prepareStatement(sql);
-		// ps.setString(0, plCommands);
-		// ps.executeUpdate();
-
-		// String sql = "CREATE OR REPLACE FUNCTION " + name + "()" +
-		// " RETURNS trigger AS $" + name + "$\nBEGIN\n "
-		// + plCommands + " \nRETURN NEW;" + "\nEND;\n$" + name +
-		// "$ LANGUAGE 'plpgsql'";
-		// c.createStatement().executeUpdate(sql);
-
 		createOrReplaceFunction(c, name, null, "TRIGGER", null, plCommands + "\nRETURN NEW");
 	}
 
@@ -561,16 +514,7 @@
 	 */
 	public static void createOrReplaceFunction(Connection c, String name, String parameters, String returns,
 			String declare, String plCommands) throws SQLException {
-		// System.err.println(plCommands);
 
-		// String sql = "CREATE OR REPLACE FUNCTION " + name + "()" +
-		// " RETURNS trigger AS $" + name
-		// + "$\nBEGIN\n?\nRETURN NEW;" + "\nEND;\n$" + name +
-		// "$ LANGUAGE 'plpgsql'";
-		// PreparedStatement ps = c.prepareStatement(sql);
-		// ps.setString(0, plCommands);
-		// ps.executeUpdate();
-
 		parameters = LangUtil.removeWhitespacesToEmpty(parameters);
 		declare = LangUtil.removeWhitespacesToEmpty(declare);
 
@@ -865,13 +809,12 @@
 			return "query";
 		return "current_query";
 	}
-	
+
 	private static String getColumnNameProcPidInPgStatActivity(Connection c) throws SQLException {
 		if (getVersion(c).compareTo(PgVersion._9_3) > 0)
 			return "pid";
 		return "procpid";
 	}
-	
 
 	/**
 	 * Liefert die Anzahl der offenen Sessions zur Datenbank.
@@ -895,7 +838,7 @@
 			stmtSql += " AND usename = ?";
 		if (queryLike != null) {
 
-			stmtSql += " AND "+getColumnNameQueryInPgStatActivity(c)+" like '" + queryLike + "'";
+			stmtSql += " AND " + getColumnNameQueryInPgStatActivity(c) + " like '" + queryLike + "'";
 		}
 
 		PreparedStatement stmt = c.prepareStatement(stmtSql);
@@ -1008,9 +951,10 @@
 	 */
 	static public Long getBlockingPid(Connection c, Long blockedPid) throws SQLException {
 		final String sql = "SELECT kl.pid as blocking_pid FROM pg_catalog.pg_locks bl "
-				+ "JOIN pg_catalog.pg_stat_activity a on bl.pid = a."+getColumnNameProcPidInPgStatActivity(c)+" "
+				+ "JOIN pg_catalog.pg_stat_activity a on bl.pid = a." + getColumnNameProcPidInPgStatActivity(c) + " "
 				+ "JOIN pg_catalog.pg_locks kl "
-				+ "JOIN pg_catalog.pg_stat_activity ka on kl.pid = ka."+getColumnNameProcPidInPgStatActivity(c)+" on bl.transactionid = kl.transactionid and bl.pid != kl.pid "
+				+ "JOIN pg_catalog.pg_stat_activity ka on kl.pid = ka." + getColumnNameProcPidInPgStatActivity(c)
+				+ " on bl.transactionid = kl.transactionid and bl.pid != kl.pid "
 				+ "WHERE not bl.granted AND bl.pid = " + blockedPid;
 		ResultSet rs = c.createStatement().executeQuery(sql);
 		try {
@@ -1043,9 +987,9 @@
 		String where = "WHERE TRUE ";
 
 		if (filter == 1)
-			where += "AND "+getColumnNameQueryInPgStatActivity(c)+" != '<IDLE>' ";
+			where += "AND " + getColumnNameQueryInPgStatActivity(c) + " != '<IDLE>' ";
 		else if (filter == 2)
-			where += "AND "+getColumnNameQueryInPgStatActivity(c)+" not like '<IDLE>%' ";
+			where += "AND " + getColumnNameQueryInPgStatActivity(c) + " not like '<IDLE>%' ";
 
 		if (datName != null)
 			where += " AND datname like '" + datName + "'";
@@ -1058,7 +1002,8 @@
 		}
 
 		final String sql = "SELECT " + getColumnNameQueryInPgStatActivity(c)
-				+ ", age (now(),query_start) as qage, waiting, " + getColumnNameProcPidInPgStatActivity(c)+", client_addr, usename, application_name from pg_stat_activity "
+				+ ", age (now(),query_start) as qage, waiting, " + getColumnNameProcPidInPgStatActivity(c)
+				+ ", client_addr, usename, application_name from pg_stat_activity "
 				+ where + " ORDER BY qage desc";
 		ResultSet rs = c.createStatement().executeQuery(sql);
 
@@ -1229,14 +1174,6 @@
 
 	/**
 	 * Creates a new Column.
-	 * 
-	 * @param dbc
-	 * @param tableName
-	 * @param columnName
-	 * @param colTypeName
-	 * @param comment
-	 * @return
-	 * @throws SQLException
 	 */
 	public static boolean addColumn(Connection dbc, String tableName, String columnName, String colTypeName,
 			String comment) throws SQLException {
@@ -1283,8 +1220,6 @@
 
 		ArrayList<String> cols = new ArrayList<String>();
 
-		// String tableName = PropertyUtils.getDbTableName(i);
-
 		String sql = "SELECT column_name FROM information_schema.COLUMNS WHERE TABLE_NAME = '" + tableName
 				+ "' and TABLE_SCHEMA = '" + schema + "';";
 



More information about the Schmitzm-commits mailing list