From 1e9ab55e1edfe9f4d0e16478e97c4efac3e45b50 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Mon, 15 Mar 2010 13:59:53 +0000
Subject: [PATCH] bug fixed: couldn't create user/role with '-'

SVN: 15149
---
 .../postgresql/PostgreSQLAdminDAO.java        | 62 +++++++------------
 1 file changed, 23 insertions(+), 39 deletions(-)

diff --git a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/postgresql/PostgreSQLAdminDAO.java b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/postgresql/PostgreSQLAdminDAO.java
index ed075d05739..3e2ad5ba2ce 100644
--- a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/postgresql/PostgreSQLAdminDAO.java
+++ b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/postgresql/PostgreSQLAdminDAO.java
@@ -88,7 +88,7 @@ public class PostgreSQLAdminDAO extends AbstractDatabaseAdminDAO
     {
         try
         {
-            getJdbcTemplate().execute("create user " + owner);
+            getJdbcTemplate().execute("create user \"" + owner + "\"");
             if (operationLog.isInfoEnabled())
             {
                 operationLog.info("Created role '" + owner + "'.");
@@ -113,52 +113,36 @@ public class PostgreSQLAdminDAO extends AbstractDatabaseAdminDAO
     {
         if (StringUtils.isNotBlank(readOnlyGroupOrNull))
         {
-            try
-            {
-                getJdbcTemplate().execute("create role " + readOnlyGroupOrNull);
-                if (operationLog.isInfoEnabled())
-                {
-                    operationLog.info("Created role '" + readOnlyGroupOrNull + "'.");
-                }
-            } catch (DataAccessException ex)
-            {
-                if (DBUtilities.isDuplicateObjectException(ex))
-                {
-                    if (operationLog.isInfoEnabled())
-                    {
-                        operationLog.info("Role '" + readOnlyGroupOrNull + "' already exists.");
-                    }
-                } else
-                {
-                    operationLog.error("Database role '" + readOnlyGroupOrNull
-                            + "' couldn't be created:", ex);
-                    throw ex;
-                }
-            }
+            createRole(readOnlyGroupOrNull);
         }
         if (StringUtils.isNotBlank(readWriteGroupOrNull))
         {
-            try
+            createRole(readWriteGroupOrNull);
+        }
+    }
+
+    private void createRole(String role)
+    {
+        try
+        {
+            getJdbcTemplate().execute("create role \"" + role + "\"");
+            if (operationLog.isInfoEnabled())
+            {
+                operationLog.info("Created role '" + role + "'.");
+            }
+        } catch (DataAccessException ex)
+        {
+            if (DBUtilities.isDuplicateObjectException(ex))
             {
-                getJdbcTemplate().execute("create role " + readWriteGroupOrNull);
                 if (operationLog.isInfoEnabled())
                 {
-                    operationLog.info("Created role '" + readWriteGroupOrNull + "'.");
+                    operationLog.info("Role '" + role + "' already exists.");
                 }
-            } catch (DataAccessException ex)
+            } else
             {
-                if (DBUtilities.isDuplicateObjectException(ex))
-                {
-                    if (operationLog.isInfoEnabled())
-                    {
-                        operationLog.info("Role '" + readWriteGroupOrNull + "' already exists.");
-                    }
-                } else
-                {
-                    operationLog.error("Database role '" + readWriteGroupOrNull
-                            + "' couldn't be created:", ex);
-                    throw ex;
-                }
+                operationLog.error("Database role '" + role
+                        + "' couldn't be created:", ex);
+                throw ex;
             }
         }
     }
-- 
GitLab