Author: kwright
Date: Wed Oct 30 05:54:53 2013
New Revision: 1536971
URL: http://svn.apache.org/r1536971
Log:
A better way to do the upgrade
Modified:
manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/authority/AuthorityConnectionManager.java
manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/repository/RepositoryConnectionManager.java
Modified:
manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/authority/AuthorityConnectionManager.java
URL:
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/authority/AuthorityConnectionManager.java?rev=1536971&r1=1536970&r2=1536971&view=diff
==============================================================================
---
manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/authority/AuthorityConnectionManager.java
(original)
+++
manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/authority/AuthorityConnectionManager.java
Wed Oct 30 05:54:53 2013
@@ -141,17 +141,20 @@ public class AuthorityConnectionManager
IResultRow row = set.getRow(i);
String authName = (String)row.getValue(nameField);
String authDescription = (String)row.getValue(descriptionField);
- ArrayList list = new ArrayList();
- list.add(authName);
- IResultSet set2 = dbInterface.performQuery("SELECT 'x' FROM
"+authMgr.getTableName()+" WHERE
"+authMgr.getGroupNameColumn()+"=?",list,null,null);
- if (set2.getRowCount() == 0)
+ // Attempt to create a matching auth group. This will fail if
the group
+ // already exists
+ IAuthorityGroup grp = authMgr.create();
+ grp.setName(authName);
+ grp.setDescription(authDescription);
+ try
{
- // Create an authority group with this name
- Map<String,Object> groupMap = new HashMap<String,Object>();
- groupMap.put(authMgr.getGroupNameColumn(),authName);
- if (authDescription != null)
-
groupMap.put(authMgr.getGroupDescriptionColumn(),authDescription);
-
dbInterface.performInsert(authMgr.getTableName(),groupMap,null);
+ authMgr.save(grp);
+ }
+ catch (ManifoldCFException e)
+ {
+ if (e.getErrorCode() !=
ManifoldCFException.DATABASE_TRANSACTION_ABORT)
+ throw e;
+ // Fall through; the row exists already
}
Map<String,String> map = new HashMap<String,String>();
map.put(groupNameField,authName);
@@ -278,15 +281,21 @@ public class AuthorityConnectionManager
// For importing older than MCF 1.5 import files...
if (conn.getAuthGroup() == null || conn.getAuthGroup().length() == 0)
{
- // Create a matching auth group.
- IAuthorityGroup grp = authMgr.load(name);
- if (grp == null)
+ // Attempt to create a matching auth group. This will fail if the
group
+ // already exists
+ IAuthorityGroup grp = authMgr.create();
+ grp.setName(name);
+ grp.setDescription(description);
+ try
{
- grp = authMgr.create();
- grp.setName(name);
- grp.setDescription(description);
authMgr.save(grp);
}
+ catch (ManifoldCFException e)
+ {
+ if (e.getErrorCode() !=
ManifoldCFException.DATABASE_TRANSACTION_ABORT)
+ throw e;
+ // Fall through; the row exists already
+ }
conn.setAuthGroup(name);
}
Modified:
manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/repository/RepositoryConnectionManager.java
URL:
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/repository/RepositoryConnectionManager.java?rev=1536971&r1=1536970&r2=1536971&view=diff
==============================================================================
---
manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/repository/RepositoryConnectionManager.java
(original)
+++
manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/repository/RepositoryConnectionManager.java
Wed Oct 30 05:54:53 2013
@@ -140,15 +140,19 @@ public class RepositoryConnectionManager
String authName = (String)row.getValue(authorityNameField);
if (authName != null && authName.length() > 0)
{
- ArrayList list = new ArrayList();
- list.add(authName);
- IResultSet set2 = dbInterface.performQuery("SELECT 'x' FROM
"+authMgr.getTableName()+" WHERE
"+authMgr.getGroupNameColumn()+"=?",list,null,null);
- if (set2.getRowCount() == 0)
+ // Attempt to create a matching auth group. This will fail if
the group
+ // already exists
+ IAuthorityGroup grp = authMgr.create();
+ grp.setName(authName);
+ try
{
- // Create an authority group with this name
- Map<String,Object> groupMap = new HashMap<String,Object>();
- groupMap.put(authMgr.getGroupNameColumn(),authName);
-
dbInterface.performInsert(authMgr.getTableName(),groupMap,null);
+ authMgr.save(grp);
+ }
+ catch (ManifoldCFException e)
+ {
+ if (e.getErrorCode() !=
ManifoldCFException.DATABASE_TRANSACTION_ABORT)
+ throw e;
+ // Fall through; the row exists already
}
Map<String,String> map = new HashMap<String,String>();
map.put(groupNameField,authName);