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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Jan 14 22:08:10 CET 2012


Author: alfonx
Date: 2012-01-14 22:08:09 +0100 (Sat, 14 Jan 2012)
New Revision: 1820

Modified:
   trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/PGUtil.java
   trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/SqlQueryStat.java
Log:
SqlQueryStat kann laufende SQl-Statements abbrechen...

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-14 20:45:15 UTC (rev 1819)
+++ trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/PGUtil.java	2012-01-14 21:08:09 UTC (rev 1820)
@@ -968,4 +968,14 @@
 		return cols;
 	}
 
+	/**
+	 * Killt eine SQL-Abfrage mit gegebenenr ProvessID (pid)
+	 * @throws SQLException 
+	 */
+	public static boolean pg_terminate_backend(Connection dbc, Long procId) throws SQLException {
+		String sql = "SELECT pg_terminate_backend("+procId+");";
+		int colsRs = dbc.createStatement().executeUpdate(sql);
+		return colsRs > 0;
+	}
+
 }

Modified: trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/SqlQueryStat.java
===================================================================
--- trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/SqlQueryStat.java	2012-01-14 20:45:15 UTC (rev 1819)
+++ trunk/schmitzm-db/src/main/java/de/schmitzm/postgres/SqlQueryStat.java	2012-01-14 21:08:09 UTC (rev 1820)
@@ -1,14 +1,13 @@
 package de.schmitzm.postgres;
 
+import java.sql.Connection;
 import java.sql.SQLException;
 
 import org.apache.log4j.Logger;
 import org.postgresql.util.PGInterval;
 
 /**
- * Beschreibt eine laufende SQL Aktion.
- * 
- * TODO schmitzm-pg
+ * Beschreibt eine laufende SQL Query.
  */
 public class SqlQueryStat {
 
@@ -28,7 +27,7 @@
 		}
 		runningFor = runningFor_;
 	}
-	
+
 	public SqlQueryStat(String query, PGInterval interval, boolean waiting, Long procId) {
 		this.query = query;
 		this.waiting = waiting;
@@ -51,7 +50,7 @@
 	public Long getProcId() {
 		return procId;
 	}
-	
+
 	/**
 	 * Process-ID
 	 */
@@ -59,5 +58,14 @@
 
 	private final PGInterval runningFor;
 	private final String query;
-	
+
+	/**
+	 * Bricht diese SQL Query ab. http://stackoverflow.com/questions/5108876/kill-a-postgresql-session-connection
+	 * 
+	 * @throws SQLException
+	 */
+	public boolean kill(Connection dbc) throws SQLException {
+		return PGUtil.pg_terminate_backend(dbc, procId);
+	}
+
 }



More information about the Schmitzm-commits mailing list