Author: kwright
Date: Mon Jun 24 14:09:56 2013
New Revision: 1496062
URL: http://svn.apache.org/r1496062
Log:
Add mapping prerequisites
Added:
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingPrereqManager.java
(with props)
Modified:
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/IMappingConnection.java
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingConnection.java
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingConnectionManager.java
Modified:
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/IMappingConnection.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/IMappingConnection.java?rev=1496062&r1=1496061&r2=1496062&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/IMappingConnection.java
(original)
+++
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/interfaces/IMappingConnection.java
Mon Jun 24 14:09:56 2013
@@ -80,4 +80,9 @@ public interface IMappingConnection
*/
public int getMaxConnections();
+ /** Get the prerequisite mappers.
+ *@return the set of mapping connections (by name) that must be run prior to
this one.
+ */
+ public Set<String> getPrerequisites();
+
}
Modified:
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingConnection.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingConnection.java?rev=1496062&r1=1496061&r2=1496062&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingConnection.java
(original)
+++
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingConnection.java
Mon Jun 24 14:09:56 2013
@@ -37,6 +37,8 @@ public class MappingConnection implement
protected ConfigParams configParams = new ConfigParams();
protected int maxCount = 100;
+ protected Set<String> prerequisites = new HashSet<String>();
+
/** Constructor.
*/
public MappingConnection()
@@ -55,6 +57,10 @@ public class MappingConnection implement
rval.className = className;
rval.maxCount = maxCount;
rval.configParams = configParams.duplicate();
+ for (String s : prerequisites)
+ {
+ rval.prerequisites.add(s);
+ }
return rval;
}
@@ -146,4 +152,12 @@ public class MappingConnection implement
return maxCount;
}
+ /** Get the prerequisite mappers.
+ *@return the set of mapping connections (by name) that must be run prior to
this one.
+ */
+ public Set<String> getPrerequisites()
+ {
+ return prerequisites;
+ }
+
}
Modified:
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingConnectionManager.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingConnectionManager.java?rev=1496062&r1=1496061&r2=1496062&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingConnectionManager.java
(original)
+++
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingConnectionManager.java
Mon Jun 24 14:09:56 2013
@@ -27,11 +27,11 @@ import org.apache.manifoldcf.authorities
/** Implementation of the authority connection manager functionality.
*
* <br><br>
- * <b>authconnectors</b>
+ * <b>mapconnections</b>
* <table border="1" cellpadding="3" cellspacing="0">
* <tr class="TableHeadingColor">
*
<th>Field</th><th>Type</th><th>Description </th>
- * <tr><td>authorityname</td><td>VARCHAR(32)</td><td>Primary Key</td></tr>
+ * <tr><td>mappingname</td><td>VARCHAR(32)</td><td>Primary Key</td></tr>
* <tr><td>description</td><td>VARCHAR(255)</td><td></td></tr>
* <tr><td>classname</td><td>VARCHAR(255)</td><td></td></tr>
* <tr><td>maxcount</td><td>BIGINT</td><td></td></tr>
@@ -47,13 +47,14 @@ public class MappingConnectionManager ex
// Special field suffix
private final static String passwordSuffix = "password";
- protected final static String nameField = "authorityname"; // Changed
this to work around a bug in postgresql
+ protected final static String nameField = "mappingname"; // Changed
this to work around a bug in postgresql
protected final static String descriptionField = "description";
protected final static String classNameField = "classname";
protected final static String maxCountField = "maxcount";
protected final static String configField = "configxml";
- protected static Random random = new Random();
+ // Handle for throttle spec storage
+ protected MappingPrereqManager mappingPrereqManager;
// Cache manager
ICacheManager cacheManager;
@@ -68,6 +69,7 @@ public class MappingConnectionManager ex
{
super(database,"mapconnections");
+ mappingPrereqManager = new MappingPrereqManager(database);
cacheManager = CacheManagerFactory.make(threadContext);
this.threadContext = threadContext;
}
@@ -97,10 +99,15 @@ public class MappingConnectionManager ex
// Upgrade code goes here
}
+ // Install dependent tables.
+ mappingPrereqManager.install(getTableName(),nameField);
+
// Index management goes here
break;
}
+
+
}
/** Uninstall the manager.
@@ -108,7 +115,26 @@ public class MappingConnectionManager ex
public void deinstall()
throws ManifoldCFException
{
- performDrop(null);
+ beginTransaction();
+ try
+ {
+ mappingPrereqManager.deinstall();
+ performDrop(null);
+ }
+ catch (ManifoldCFException e)
+ {
+ signalRollback();
+ throw e;
+ }
+ catch (Error e)
+ {
+ signalRollback();
+ throw e;
+ }
+ finally
+ {
+ endTransaction();
+ }
}
/** Export configuration */
@@ -121,17 +147,23 @@ public class MappingConnectionManager ex
IMappingConnection[] list = getAllConnections();
// Write the number of authorities
ManifoldCF.writeDword(os,list.length);
- // Loop through the list and write the individual authority info
- int i = 0;
- while (i < list.length)
+ // Loop through the list and write the individual mapping info
+ for (IMappingConnection conn : list)
{
- IMappingConnection conn = list[i++];
ManifoldCF.writeString(os,conn.getName());
ManifoldCF.writeString(os,conn.getDescription());
ManifoldCF.writeString(os,conn.getClassName());
ManifoldCF.writeString(os,conn.getConfigParams().toXML());
ManifoldCF.writeDword(os,conn.getMaxConnections());
+
+ Set<String> prereqs = conn.getPrerequisites();
+ ManifoldCF.writeDword(os,prereqs.size());
+ for (String s : prereqs)
+ {
+ ManifoldCF.writeString(os,s);
+ }
}
+
}
/** Import configuration */
@@ -140,10 +172,9 @@ public class MappingConnectionManager ex
{
int version = ManifoldCF.readDword(is);
if (version != 1)
- throw new java.io.IOException("Unknown authority configuration version:
"+Integer.toString(version));
+ throw new java.io.IOException("Unknown mapping configuration version:
"+Integer.toString(version));
int count = ManifoldCF.readDword(is);
- int i = 0;
- while (i < count)
+ for (int i = 0; i < count; i++)
{
IMappingConnection conn = create();
conn.setName(ManifoldCF.readString(is));
@@ -151,9 +182,13 @@ public class MappingConnectionManager ex
conn.setClassName(ManifoldCF.readString(is));
conn.getConfigParams().fromXML(ManifoldCF.readString(is));
conn.setMaxConnections(ManifoldCF.readDword(is));
+ int prereqCount = ManifoldCF.readDword(is);
+ for (int j = 0; j < prereqCount; j++)
+ {
+ conn.getPrerequisites().add(ManifoldCF.readString(is));
+ }
// Attempt to save this connection
save(conn);
- i++;
}
}
@@ -297,7 +332,7 @@ public class MappingConnectionManager ex
{
// If the object is not supposed to be new, it is bad that we
did not find one.
if (!isNew)
- throw new ManifoldCFException("Authority connection
'"+object.getName()+"' no longer exists");
+ throw new ManifoldCFException("Mapping connection
'"+object.getName()+"' no longer exists");
isCreated = true;
// Insert
values.put(nameField,object.getName());
@@ -305,6 +340,9 @@ public class MappingConnectionManager ex
performInsert(values,null);
}
+ // Write secondary table stuff
+ mappingPrereqManager.writeRows(object.getName(),object);
+
cacheManager.invalidateKeys(ch);
return isCreated;
}
@@ -349,7 +387,6 @@ public class MappingConnectionManager ex
public void delete(String name)
throws ManifoldCFException
{
- // MHL to check on legality of deletion
StringSetBuffer ssb = new StringSetBuffer();
ssb.add(getMappingConnectionsKey());
@@ -361,11 +398,11 @@ public class MappingConnectionManager ex
beginTransaction();
try
{
- // Check if anything refers to this connection name
- // MHL
- //if (repoManager.isReferenced(name))
- // throw new ManifoldCFException("Can't delete mapping connection
'"+name+"': existing mapping connections refer to it");
+ // Check if any other mapping refers to this connection name
+ if (isReferenced(name))
+ throw new ManifoldCFException("Can't delete mapping connection
'"+name+"': existing mapping connections refer to it");
ManifoldCF.noteConfigurationChange();
+ mappingPrereqManager.deleteRows(name);
ArrayList params = new ArrayList();
String query = buildConjunctionClause(params,new ClauseDescription[]{
new UnitaryClause(nameField,name)});
@@ -402,6 +439,24 @@ public class MappingConnectionManager ex
return nameField;
}
+ /** Return true if the specified mapping name is referenced.
+ *@param mappingName is the mapping name.
+ *@return true if referenced, false otherwise.
+ */
+ protected boolean isReferenced(String mappingName)
+ throws ManifoldCFException
+ {
+ StringSetBuffer ssb = new StringSetBuffer();
+ ssb.add(getMappingConnectionsKey());
+ StringSet localCacheKeys = new StringSet(ssb);
+ ArrayList params = new ArrayList();
+ String query = buildConjunctionClause(params,new ClauseDescription[]{
+ new UnitaryClause(mappingPrereqManager.prereqField,mappingName)});
+ IResultSet set = performQuery("SELECT "+nameField+" FROM
"+mappingPrereqManager.getTableName()+" WHERE "+query,params,
+ localCacheKeys,null);
+ return set.getRowCount() > 0;
+ }
+
// Caching strategy: Individual connection descriptions are cached, and
there is a global cache key for the list of
// repository connections.
@@ -483,7 +538,8 @@ public class MappingConnectionManager ex
*/
protected int maxClauseGetMappingConnectionsChunk()
{
- return findConjunctionClauseMax(new ClauseDescription[]{});
+ return Math.min(findConjunctionClauseMax(new ClauseDescription[]{}),
+ mappingPrereqManager.maxClauseGetRows());
}
/** Read a chunk of mapping connections.
@@ -516,6 +572,8 @@ public class MappingConnectionManager ex
rc.getConfigParams().fromXML(xml);
rval[index] = rc;
}
+ // Do prereq part
+ mappingPrereqManager.getRows(rval,returnIndex,params);
}
// The cached instance will be a MappingConnection. The cached version will
be duplicated when it is returned
Added:
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingPrereqManager.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingPrereqManager.java?rev=1496062&view=auto
==============================================================================
---
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingPrereqManager.java
(added)
+++
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingPrereqManager.java
Mon Jun 24 14:09:56 2013
@@ -0,0 +1,200 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.authorities.mapping;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.authorities.interfaces.*;
+import java.util.*;
+
+/** This class manages the "mappingprereq" table, which contains the mapping
connection prerequisites for each connection.
+*
+* <br><br>
+* <b>mappingprereq</b>
+* <table border="1" cellpadding="3" cellspacing="0">
+* <tr class="TableHeadingColor">
+*
<th>Field</th><th>Type</th><th>Description </th>
+*
<tr><td>ownername</td><td>VARCHAR(32)</td><td>Reference:repoconnections.connectionname</td></tr>
+*
<tr><td>prereq</td><td>VARCHAR(32)</td><td>Reference:repoconnections.connectionname</td></tr>
+* </table>
+* <br><br>
+*
+*/
+public class MappingPrereqManager extends
org.apache.manifoldcf.core.database.BaseTable
+{
+ public static final String _rcsid = "@(#)$Id$";
+
+ // Schema
+ public final static String ownerNameField = "ownername";
+ public final static String prereqField = "prereq";
+
+ /** Constructor.
+ *@param database is the database instance.
+ */
+ public MappingPrereqManager(IDBInterface database)
+ throws ManifoldCFException
+ {
+ super(database,"mappingprereq");
+ }
+
+ /** Install or upgrade.
+ *@param ownerTable is the name of the table that owns this one.
+ *@param owningTablePrimaryKey is the primary key of the owning table.
+ */
+ public void install(String ownerTable, String owningTablePrimaryKey)
+ throws ManifoldCFException
+ {
+ // Always use a loop, in case upgrade needs it.
+ while (true)
+ {
+ Map existing = getTableSchema(null,null);
+ if (existing == null)
+ {
+ HashMap map = new HashMap();
+ map.put(ownerNameField,new
ColumnDescription("VARCHAR(32)",false,false,ownerTable,owningTablePrimaryKey,false));
+ map.put(prereqField,new
ColumnDescription("VARCHAR(32)",false,false,ownerTable,owningTablePrimaryKey,false));
+ performCreate(map,null);
+ }
+
+ // Index management
+ IndexDescription ownerIndex = new IndexDescription(false,new
String[]{ownerNameField});
+
+ // Get rid of indexes that shouldn't be there
+ Map indexes = getTableIndexes(null,null);
+ Iterator iter = indexes.keySet().iterator();
+ while (iter.hasNext())
+ {
+ String indexName = (String)iter.next();
+ IndexDescription id = (IndexDescription)indexes.get(indexName);
+
+ if (ownerIndex != null && id.equals(ownerIndex))
+ ownerIndex = null;
+ else if (indexName.indexOf("_pkey") == -1)
+ // This index shouldn't be here; drop it
+ performRemoveIndex(indexName);
+ }
+
+ // Add the ones we didn't find
+ if (ownerIndex != null)
+ performAddIndex(null,ownerIndex);
+
+ break;
+ }
+ }
+
+ /** Uninstall.
+ */
+ public void deinstall()
+ throws ManifoldCFException
+ {
+ performDrop(null);
+ }
+
+ /** Read rows for a given owner name.
+ *@param name is the owner name.
+ *@return a list, with columns: "prereq"
+ */
+ public IResultSet readRows(String name)
+ throws ManifoldCFException
+ {
+ ArrayList list = new ArrayList();
+ String query = buildConjunctionClause(list,new ClauseDescription[]{
+ new UnitaryClause(ownerNameField,name)});
+ return performQuery("SELECT "+prereqField+" AS prereq FROM "+
+ getTableName()+" WHERE "+query,list,null,null);
+ }
+
+ /** Calculate the maximum number of clauses we can use with getRows.
+ */
+ public int maxClauseGetRows()
+ {
+ return findConjunctionClauseMax(new ClauseDescription[]{});
+ }
+
+ /** Fill in a set of prereqs corresponding to a set of connection names.
+ *@param connections is the set of connections to fill in.
+ *@param indexMap maps the connection name to the index in the connections
array.
+ *@param ownerNameParams is the corresponding set of connection name
parameters.
+ */
+ public void getRows(IMappingConnection[] connections, Map indexMap,
ArrayList ownerNameParams)
+ throws ManifoldCFException
+ {
+ ArrayList list = new ArrayList();
+ String query = buildConjunctionClause(list,new ClauseDescription[]{
+ new MultiClause(ownerNameField,ownerNameParams)});
+ IResultSet set = performQuery("SELECT * FROM "+getTableName()+" WHERE
"+query,list,
+ null,null);
+ for (int i = 0; i < set.getRowCount(); i++)
+ {
+ IResultRow row = set.getRow(i);
+ String ownerName = (String)row.getValue(ownerNameField);
+ int index = ((Integer)indexMap.get(ownerName)).intValue();
+ String prereq = (String)row.getValue(prereqField);
+ connections[index].getPrerequisites().add(prereq);
+ }
+ }
+
+ /** Write a set of prereqs into the database.
+ *@param owner is the owning connection name.
+ *@param connection is the connection to write prereqs for.
+ */
+ public void writeRows(String owner, IMappingConnection connection)
+ throws ManifoldCFException
+ {
+ beginTransaction();
+ try
+ {
+ HashMap map = new HashMap();
+ Set<String> prereqs = connection.getPrerequisites();
+ for (String prereq : prereqs)
+ {
+ map.clear();
+ map.put(prereqField,prereq);
+ map.put(ownerNameField,owner);
+ performInsert(map,null);
+ }
+ }
+ catch (ManifoldCFException e)
+ {
+ signalRollback();
+ throw e;
+ }
+ catch (Error e)
+ {
+ signalRollback();
+ throw e;
+ }
+ finally
+ {
+ endTransaction();
+ }
+ }
+
+ /** Delete rows.
+ *@param owner is the owner whose rows to delete.
+ */
+ public void deleteRows(String owner)
+ throws ManifoldCFException
+ {
+ ArrayList list = new ArrayList();
+ String query = buildConjunctionClause(list,new ClauseDescription[]{
+ new UnitaryClause(ownerNameField,owner)});
+ performDelete("WHERE "+query,list,null);
+ }
+
+}
Propchange:
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingPrereqManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/mapping/MappingPrereqManager.java
------------------------------------------------------------------------------
svn:keywords = Id