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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Sep 30 14:29:10 CEST 2011


Author: alfonx
Date: 2011-09-30 14:29:10 +0200 (Fri, 30 Sep 2011)
New Revision: 1743

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

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-29 21:41:36 UTC (rev 1742)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/postgres/PGUtil.java	2011-09-30 12:29:10 UTC (rev 1743)
@@ -87,16 +87,16 @@
 		c.createStatement().executeUpdate(sql);
 	}
 
-    /**
-     * Erstellt eine neue Rolle, wenn diese noch nicht existiert.
-     */
-    public static void createRoleIfNotExists(Connection c, String rolename) throws SQLException {
-        if ( existsRole(c, rolename) )
-          return;
-        createRole(c, rolename);
-    }
+	/**
+	 * Erstellt eine neue Rolle, wenn diese noch nicht existiert.
+	 */
+	public static void createRoleIfNotExists(Connection c, String rolename) throws SQLException {
+		if (existsRole(c, rolename))
+			return;
+		createRole(c, rolename);
+	}
 
-    /**
+	/**
 	 * Querys the <code>geometry_columns</code> table is part of every POSTGIS installation and must/should describe the
 	 * geometry columns and tables.
 	 */
@@ -342,7 +342,7 @@
 	 */
 	public static void addIndex(Connection c, final String tableName, final String columns, String idxPostfix,
 			final boolean unique) throws SQLException {
-		addIndex(c, tableName, columns, idxPostfix, unique, null, null, false, 0.9);
+		addIndex(c, tableName, columns, idxPostfix, unique, null, null, false, null);
 	}
 
 	/**
@@ -358,8 +358,8 @@
 			tableName = tableName.substring(tableName.indexOf(".") + 1, tableName.length());
 
 		List<String> idxes = new ArrayList<String>();
-		
-		//	, array_to_string(array_agg(a.attname), ', ') as column_names 
+
+		// , array_to_string(array_agg(a.attname), ', ') as column_names
 		String sql = "select t.relname as table_name, i.relname as index_name from pg_class t, pg_class i, pg_index ix, pg_attribute a where t.oid = ix.indrelid and i.oid = ix.indexrelid and a.attrelid = t.oid and a.attnum = ANY(ix.indkey) and t.relkind = 'r' and t.relname like '"
 				+ tableName + "' group by t.relname, i.relname order by t.relname, i.relname";
 
@@ -397,7 +397,7 @@
 	 */
 	public static void addIndex(Connection c, final String tableName, final String columns, String idxPostfix,
 			final boolean unique, String tablespace, String type, boolean forceRecreationIfExistsAlready,
-			double fillFactor) throws SQLException {
+			Double fillFactor) throws SQLException {
 		String idxNameWithDot = tableName + "_" + idxPostfix;
 		final String idxName = idxNameWithDot.replace(".", "_");
 
@@ -445,12 +445,19 @@
 
 		Statement s = c.createStatement();
 
-		if (fillFactor <= 0. || fillFactor > 1.)
+		if (fillFactor != null && fillFactor <= 0. || fillFactor > 1.)
 			throw new IllegalArgumentException("fillFactor muss großer 0 und kleinergleich 1 sein.");
 
+		String sqlFillFactor = "";
+		if (fillFactor != null)
+			sqlFillFactor = " WITH (FILLFACTOR=" + (int) (fillFactor * 100) + ") ";
+
+		String sqlTableSpace = tablespace == null ? "" : " TABLESPACE " + tablespace;
+
+		String sqlUsing = type == null ? "" : " USING " + type;
+		
 		final String queryString = "CREATE " + (unique ? "UNIQUE " : "") + "INDEX " + idxName + " ON " + tableName
-				+ (type == null ? "" : " USING " + type) + " (" + columns + ") " + "WITH (FILLFACTOR="
-				+ (int) (fillFactor * 100) + ")" + (tablespace == null ? "" : " TABLESPACE " + tablespace);
+				+ sqlUsing + " (" + columns + ") " + sqlFillFactor + sqlTableSpace;
 		try {
 			s.execute(queryString);
 			c.commit();



More information about the Schmitzm-commits mailing list