[Schmitzm-commits] r1815 - in trunk: . schmitzm-db-pg schmitzm-db-pg/.settings schmitzm-db-pg/src schmitzm-db-pg/src/main schmitzm-db-pg/src/main/java schmitzm-db-pg/src/main/java/postgres

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Jan 14 21:35:27 CET 2012


Author: alfonx
Date: 2012-01-14 21:35:25 +0100 (Sat, 14 Jan 2012)
New Revision: 1815

Added:
   trunk/schmitzm-db-pg/
   trunk/schmitzm-db-pg/.classpath
   trunk/schmitzm-db-pg/.project
   trunk/schmitzm-db-pg/.settings/
   trunk/schmitzm-db-pg/.settings/org.eclipse.core.resources.prefs
   trunk/schmitzm-db-pg/.settings/org.eclipse.jdt.core.prefs
   trunk/schmitzm-db-pg/.settings/org.eclipse.m2e.core.prefs
   trunk/schmitzm-db-pg/.settings/org.jboss.ide.eclipse.as.core.prefs
   trunk/schmitzm-db-pg/pom.xml
   trunk/schmitzm-db-pg/src/
   trunk/schmitzm-db-pg/src/main/
   trunk/schmitzm-db-pg/src/main/java/
   trunk/schmitzm-db-pg/src/main/java/postgres/
   trunk/schmitzm-db-pg/src/main/java/postgres/SqlQueryStat.java
   trunk/schmitzm-db-pg/src/main/java/sql/
Modified:
   trunk/schmitzm-db-pg/src/main/java/postgres/PGUtil.java
Log:
Neues Modul schmitz-db mit Datenbankmethoden

Added: trunk/schmitzm-db-pg/.classpath
===================================================================
--- trunk/schmitzm-db-pg/.classpath	2012-01-09 15:27:04 UTC (rev 1814)
+++ trunk/schmitzm-db-pg/.classpath	2012-01-14 20:35:25 UTC (rev 1815)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="lib" path="/home/stefan/.m2/repository/postgresql/postgresql/9.1-901.jdbc4/postgresql-9.1-901.jdbc4.jar">
+		<attributes>
+			<attribute name="maven.groupId" value="postgresql"/>
+			<attribute name="maven.artifactId" value="postgresql"/>
+			<attribute name="maven.version" value="9.1-901.jdbc4"/>
+			<attribute name="maven.scope" value="compile"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>


Property changes on: trunk/schmitzm-db-pg/.classpath
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/schmitzm-db-pg/.project
===================================================================
--- trunk/schmitzm-db-pg/.project	2012-01-09 15:27:04 UTC (rev 1814)
+++ trunk/schmitzm-db-pg/.project	2012-01-14 20:35:25 UTC (rev 1815)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>schmitzm-db</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+	</natures>
+</projectDescription>


Property changes on: trunk/schmitzm-db-pg/.project
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/schmitzm-db-pg/.settings/org.eclipse.core.resources.prefs
===================================================================
--- trunk/schmitzm-db-pg/.settings/org.eclipse.core.resources.prefs	2012-01-09 15:27:04 UTC (rev 1814)
+++ trunk/schmitzm-db-pg/.settings/org.eclipse.core.resources.prefs	2012-01-14 20:35:25 UTC (rev 1815)
@@ -0,0 +1,3 @@
+#Sat Jan 14 21:27:48 CET 2012
+eclipse.preferences.version=1
+encoding/<project>=UTF-8


Property changes on: trunk/schmitzm-db-pg/.settings/org.eclipse.core.resources.prefs
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/schmitzm-db-pg/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/schmitzm-db-pg/.settings/org.eclipse.jdt.core.prefs	2012-01-09 15:27:04 UTC (rev 1814)
+++ trunk/schmitzm-db-pg/.settings/org.eclipse.jdt.core.prefs	2012-01-14 20:35:25 UTC (rev 1815)
@@ -0,0 +1,6 @@
+#Sat Jan 14 21:27:48 CET 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6


Property changes on: trunk/schmitzm-db-pg/.settings/org.eclipse.jdt.core.prefs
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/schmitzm-db-pg/.settings/org.eclipse.m2e.core.prefs
===================================================================
--- trunk/schmitzm-db-pg/.settings/org.eclipse.m2e.core.prefs	2012-01-09 15:27:04 UTC (rev 1814)
+++ trunk/schmitzm-db-pg/.settings/org.eclipse.m2e.core.prefs	2012-01-14 20:35:25 UTC (rev 1815)
@@ -0,0 +1,5 @@
+#Sat Jan 14 21:27:47 CET 2012
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1


Property changes on: trunk/schmitzm-db-pg/.settings/org.eclipse.m2e.core.prefs
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/schmitzm-db-pg/.settings/org.jboss.ide.eclipse.as.core.prefs
===================================================================
--- trunk/schmitzm-db-pg/.settings/org.jboss.ide.eclipse.as.core.prefs	2012-01-09 15:27:04 UTC (rev 1814)
+++ trunk/schmitzm-db-pg/.settings/org.jboss.ide.eclipse.as.core.prefs	2012-01-14 20:35:25 UTC (rev 1815)
@@ -0,0 +1,3 @@
+#Sat Jan 14 21:32:04 CET 2012
+eclipse.preferences.version=1
+org.jboss.ide.eclipse.as.core.singledeployable.deployableList=


Property changes on: trunk/schmitzm-db-pg/.settings/org.jboss.ide.eclipse.as.core.prefs
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/schmitzm-db-pg/pom.xml
===================================================================
--- trunk/schmitzm-db-pg/pom.xml	2012-01-09 15:27:04 UTC (rev 1814)
+++ trunk/schmitzm-db-pg/pom.xml	2012-01-14 20:35:25 UTC (rev 1815)
@@ -0,0 +1,46 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+
+	<groupId>de.schmitzm</groupId>
+	<artifactId>schmitzm-db</artifactId>
+	<version>2.7-SNAPSHOT</version>
+	<packaging>jar</packaging>
+
+	<parent>
+		<groupId>de.schmitzm</groupId>
+		<artifactId>schmitzm-parent</artifactId>
+		<version>2.7-SNAPSHOT</version>
+		<relativePath>../schmitzm-parent/pom.xml</relativePath>
+	</parent>
+
+	<name>schmitzm-db</name>
+
+	<dependencies>
+
+		<dependency>
+			<groupId>de.schmitzm</groupId>
+			<artifactId>schmitzm-core</artifactId>
+			<version>${project.version}</version>
+			<type>test-jar</type>
+			<scope>test</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>de.schmitzm</groupId>
+			<artifactId>schmitzm-core</artifactId>
+			<version>${project.version}</version>
+			<type>jar</type>
+			<scope>compile</scope>
+		</dependency>
+		
+		<dependency>
+			<groupId>postgresql</groupId>
+			<artifactId>postgresql</artifactId>
+			<version>9.0-801.jdbc4</version>
+		</dependency>
+	</dependencies>
+
+	<build>
+	</build>
+</project>


Property changes on: trunk/schmitzm-db-pg/pom.xml
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/schmitzm-db-pg/src/main/java/postgres (from rev 1814, trunk/schmitzm-core/src/main/java/de/schmitzm/postgres)

Modified: trunk/schmitzm-db-pg/src/main/java/postgres/PGUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/postgres/PGUtil.java	2012-01-09 15:27:04 UTC (rev 1814)
+++ trunk/schmitzm-db-pg/src/main/java/postgres/PGUtil.java	2012-01-14 20:35:25 UTC (rev 1815)
@@ -515,8 +515,10 @@
 		if (fillFactor != null)
 			sqlFillFactor = " WITH (FILLFACTOR=" + (int) (fillFactor * 100) + ") ";
 
-		String sqlTableSpace = (tablespace == null || tablespace.equalsIgnoreCase("null")) ? "" : " TABLESPACE "
+		String sqlTableSpace = (tablespace == null || tablespace.equalsIgnoreCase("null") || !existsTablespace(c, tableName)) ? "" : " TABLESPACE "
 				+ tablespace;
+		
+		
 
 		String sqlUsing = type == null ? "" : " USING " + type;
 
@@ -549,6 +551,32 @@
 	}
 
 	/**
+	 * Liefert <code>true</code> wenn ein tablespace mit dem Namen existiert.
+	 * @throws SQLException 
+	 */
+	private static boolean existsTablespace(Connection c, String spaceName) throws SQLException {
+		
+		// SELECT count(1) FROM pg_tablespace where spcname = 'spcname';
+		String stmtSql = "SELECT COUNT(*) FROM pg_tablespace where spcname = '"+spaceName+"'";
+
+		PreparedStatement stmt = c.prepareStatement(stmtSql);
+		stmt.execute();
+
+		ResultSet result = stmt.getResultSet();
+		try {
+			int count = 0;
+			if (result.next())
+				count = result.getInt(1);
+
+			return count > 0;
+		} finally {
+			result.close();
+			stmt.close();
+		}
+
+	}
+
+	/**
 	 * Fügt einen Benutzer zu einer Rolle hinzu. Wenn der benutzer bereits in der Rolle enthalten ist, wird keine
 	 * Exception geschmisssen.
 	 * 
@@ -704,7 +732,7 @@
 			where += " and age (now(),query_start) >= interval '" + minSecondsRunning + " second' ";
 		}
 
-		final String sql = "select current_query, age (now(),query_start) as qage, waiting from pg_stat_activity "
+		final String sql = "select current_query, age (now(),query_start) as qage, waiting, procpid from pg_stat_activity "
 				+ where + " order by qage desc";
 		ResultSet rs = c.createStatement().executeQuery(sql);
 
@@ -713,6 +741,7 @@
 				String q = rs.getString(1);
 				String since = rs.getString(2);
 				String waiting = rs.getString(3);
+				String waiting = rs.getString(3);
 
 				result.add(new String[] { q, since, waiting });
 			}
@@ -938,4 +967,5 @@
 		}
 		return cols;
 	}
+
 }

Added: trunk/schmitzm-db-pg/src/main/java/postgres/SqlQueryStat.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/postgres/SqlQueryStat.java	2012-01-09 15:27:04 UTC (rev 1814)
+++ trunk/schmitzm-db-pg/src/main/java/postgres/SqlQueryStat.java	2012-01-14 20:35:25 UTC (rev 1815)
@@ -0,0 +1,59 @@
+package de.schmitzm.postgres;
+
+import java.sql.SQLException;
+
+import org.apache.log4j.Logger;
+import org.postgresql.util.PGInterval;
+
+/**
+ * Beschreibt eine laufende SQL Aktion.
+ * 
+ * TODO schmitzm-pg
+ */
+public class SqlQueryStat {
+
+	final static Logger log = Logger.getLogger(SqlQueryStat.class);
+	private final boolean waiting;
+
+	public SqlQueryStat(String query, String interval, boolean waiting, Long procId) {
+		this.query = query;
+		this.waiting = waiting;
+		this.procId = procId;
+		PGInterval runningFor_;
+		try {
+			runningFor_ = new PGInterval(interval);
+		} catch (SQLException e) {
+			log.error(e);
+			runningFor_ = new PGInterval();
+		}
+		runningFor = runningFor_;
+	}
+
+	public PGInterval getRunningFor() {
+		return runningFor;
+	}
+
+	public String getQuery() {
+		return query;
+	}
+
+	public boolean isWaiting() {
+		return waiting;
+	}
+
+	public Long getProcId() {
+		return procId;
+	}
+
+	public void setProcId(Long procId) {
+		this.procId = procId;
+	}
+
+	private final PGInterval runningFor;
+	private final String query;
+	
+	/**
+	 * Process-ID
+	 */
+	private final Long procId;
+}


Property changes on: trunk/schmitzm-db-pg/src/main/java/postgres/SqlQueryStat.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/schmitzm-db-pg/src/main/java/sql (from rev 1814, trunk/schmitzm-core/src/main/java/de/schmitzm/sql)



More information about the Schmitzm-commits mailing list