Index: src/edu/ucsb/nceas/metacat/Eml200SAXHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/Eml200SAXHandler.java	(revision 6018)
+++ src/edu/ucsb/nceas/metacat/Eml200SAXHandler.java	(revision 6019)
@@ -52,11 +52,9 @@
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 
-import edu.ucsb.nceas.metacat.accesscontrol.AccessControlForSingleFile;
 import edu.ucsb.nceas.metacat.accesscontrol.AccessControlInterface;
 import edu.ucsb.nceas.metacat.accesscontrol.AccessRule;
 import edu.ucsb.nceas.metacat.accesscontrol.AccessSection;
-import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO;
 import edu.ucsb.nceas.metacat.database.DBConnection;
 import edu.ucsb.nceas.metacat.database.DBConnectionPool;
 import edu.ucsb.nceas.metacat.properties.PropertyService;
@@ -2081,7 +2079,7 @@
     }//writeTopAccessRuletoDB
 
     /* Write a gaven access rule into db */
-    private void writeGivenAccessRuleIntoDB(String permOrder, Vector<AccessRule> accessRules,
+    private void writeGivenAccessRuleIntoDB(String permOrder, Vector accessRules,
                      String dataId, String subTreeId) throws SAXException
     {
       if (permOrder == null || permOrder.trim().equals("") || dataId == null ||
@@ -2092,40 +2090,76 @@
                                   " write to xml_access table");
         throw new SAXException("The access object is null");
       }
-       try {
-           AccessControlForSingleFile acfsf = new AccessControlForSingleFile(dataId);
+       // get rid of rev from dataId
+       //dataId = MetacatUtil.getDocIdFromString(dataId);
+       //String permOrder = accessSection.getPermissionOrder();
+       String sql = null;
+       PreparedStatement pstmt = null;
+       sql = "INSERT INTO xml_access (docid, principal_name, permission, "
+               + "perm_type, perm_order, accessfileid, subtreeid) VALUES "
+               + " (?, ?, ?, ?, ?, ?, ?)";
+
+       try
+       {
+
+           pstmt = connection.prepareStatement(sql);
+           // Increase DBConnection usage count
+           connection.increaseUsageCount(1);
+           // Bind the values to the query
+           pstmt.setString(1, dataId);
+           logMetacat.info("Docid in accesstable: " + docid);
+           pstmt.setString(6, docid);
+           logMetacat.info("Accessfileid in accesstable: " + docid);
+           pstmt.setString(5, permOrder);
+           logMetacat.info("PermOder in accesstable: " + permOrder);
+           pstmt.setString(7, subTreeId);
+           logMetacat.info("subtree id in accesstable: " + subTreeId);
+           // if it is not top level, set s id
+
+           //Vector accessRules = accessSection.getAccessRules();
            // go through every rule
-           for (int i = 0; i < accessRules.size(); i++) {
-               AccessRule rule = accessRules.elementAt(i);
+           for (int i = 0; i < accessRules.size(); i++)
+           {
+               AccessRule rule = (AccessRule) accessRules.elementAt(i);
                String permType = rule.getPermissionType();
                int permission = rule.getPermission();
-               logMetacat.info("permission in accesstable: " + permission);
-               logMetacat.info("Permtype in accesstable: " + permType);
+               pstmt.setInt(3, permission);
+               logMetacat.info("permission in accesstable: "
+                       + permission);
+               pstmt.setString(4, permType);
+               logMetacat.info(
+                       "Permtype in accesstable: " + permType);
                // go through every principle in rule
                Vector nameVector = rule.getPrincipal();
-               for (int j = 0; j < nameVector.size(); j++) {
+               for (int j = 0; j < nameVector.size(); j++)
+               {
                    String prName = (String) nameVector.elementAt(j);
-					logMetacat.debug("Principal in accesstable: " + prName);
-					XMLAccessDAO dao = new XMLAccessDAO();
-					dao.setAccessFileId(docid);
-					dao.setDocId(dataId);
-					dao.setPermission(new Long(permission));
-					dao.setPermOrder(permOrder);
-					dao.setPermType(permType);
-					dao.setPrincipalName(prName);
-					dao.setSubTreeId(subTreeId);
-					// insert if it does not exist
-					if (!acfsf.accessControlExists(dao)) {
-						acfsf.insertPermissions(dao);
-					}
+                   pstmt.setString(2, prName);
+                   logMetacat.info("Principal in accesstable: "
+                           + prName);
+                   logMetacat.debug("running sql: " + pstmt.toString());
+                   pstmt.execute();
                }//for
            }//for
-           
+           pstmt.close();
        }//try
-       catch (Exception e) {
+       catch (SQLException e)
+       {
            throw new SAXException("EMLSAXHandler.writeAccessRuletoDB(): "
                    + e.getMessage());
        }//catch
+       finally
+       {
+           try
+           {
+               pstmt.close();
+           }
+           catch (SQLException ee)
+           {
+               throw new SAXException("EMLSAXHandler.writeAccessRuletoDB(): "
+                       + ee.getMessage());
+           }
+       }//finally
 
     }//writeGivenAccessRuleIntoDB
 
Index: src/edu/ucsb/nceas/metacat/Eml210SAXHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/Eml210SAXHandler.java	(revision 6018)
+++ src/edu/ucsb/nceas/metacat/Eml210SAXHandler.java	(revision 6019)
@@ -46,11 +46,9 @@
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 
-import edu.ucsb.nceas.metacat.accesscontrol.AccessControlForSingleFile;
 import edu.ucsb.nceas.metacat.accesscontrol.AccessControlInterface;
 import edu.ucsb.nceas.metacat.accesscontrol.AccessRule;
 import edu.ucsb.nceas.metacat.accesscontrol.AccessSection;
-import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO;
 import edu.ucsb.nceas.metacat.database.DBConnection;
 import edu.ucsb.nceas.metacat.database.DBConnectionPool;
 import edu.ucsb.nceas.metacat.properties.PropertyService;
@@ -1427,22 +1425,46 @@
 			throw new SAXException("The access object is null");
 		}
 
-		String currentDocId = null;
-		String accessFileId = null;
 		String permOrder = accessSection.getPermissionOrder();
+		String sql = null;
+		PreparedStatement pstmt = null;
 		if (topLevel) {
-			currentDocId = docid;
+			sql = "INSERT INTO xml_access (docid, principal_name, permission, "
+					+ "perm_type, perm_order, accessfileid) VALUES "
+					+ " (?, ?, ?, ?, ?, ?)";
 		} else {
-			currentDocId = accessSection.getDataFileName();
-			accessFileId = docid;
-			// for subtree should specify the
-			if (subSectionId == null) {
-				throw new SAXException("The subsection is null");
-			}
+			sql = "INSERT INTO xml_access (docid,principal_name, "
+					+ "permission, perm_type, perm_order, accessfileid, subtreeid"
+					+ ") VALUES" + " (?, ?, ?, ?, ?, ?, ?)";
 		}
 		try {
 
-			AccessControlForSingleFile acfsf = new AccessControlForSingleFile(currentDocId);
+			pstmt = connection.prepareStatement(sql);
+			// Increase DBConnection usage count
+			connection.increaseUsageCount(1);
+			// Bind the values to the query
+			pstmt.setString(6, docid);
+			logMetacat.debug("Accessfileid in accesstable: " + docid);
+			pstmt.setString(5, permOrder);
+			logMetacat.debug("PermOder in accesstable: " + permOrder);
+			// if it is not top level, set subsection id
+			if (topLevel) {
+				pstmt.setString(1, docid);
+				logMetacat.debug("Docid in accesstable: " + docid);
+			}
+			if (!topLevel) {
+				pstmt.setString(1, accessSection.getDataFileName());
+				logMetacat.debug("Docid in accesstable: " + inlineDataFileName);
+
+				// for subtree should specify the
+				if (subSectionId == null) {
+					throw new SAXException("The subsection is null");
+				}
+
+				pstmt.setString(7, subSectionId);
+				logMetacat.debug("SubSectionId in accesstable: " + subSectionId);
+			}
+
 			Vector<AccessRule> accessRules = accessSection.getAccessRules();
 			// go through every rule
 			for (int i = 0; i < accessRules.size(); i++) {
@@ -1449,36 +1471,102 @@
 				AccessRule rule = accessRules.elementAt(i);
 				String permType = rule.getPermissionType();
 				int permission = rule.getPermission();
+				pstmt.setInt(3, permission);
 				logMetacat.debug("permission in accesstable: " + permission);
+				pstmt.setString(4, permType);
 				logMetacat.debug("Permtype in accesstable: " + permType);
 				// go through every principle in rule
 				Vector<String> nameVector = rule.getPrincipal();
 				for (int j = 0; j < nameVector.size(); j++) {
 					String prName = nameVector.elementAt(j);
+					pstmt.setString(2, prName);
 					logMetacat.debug("Principal in accesstable: " + prName);
-					XMLAccessDAO dao = new XMLAccessDAO();
-					dao.setAccessFileId(accessFileId);
-					dao.setDocId(currentDocId);
-					dao.setPermission(new Long(permission));
-					dao.setPermOrder(permOrder);
-					dao.setPermType(permType);
-					dao.setPrincipalName(prName);
-					dao.setSubTreeId(subSectionId);
-					// insert if it does not exist
-					if (!acfsf.accessControlExists(dao)) {
-						acfsf.insertPermissions(dao);
-					}
-					
+					logMetacat.debug("running sql: " + pstmt.toString());
+					pstmt.execute();
 				}// for
 			}// for
+			pstmt.close();
 		}// try
-		catch (Exception e) {
+		catch (SQLException e) {
 			throw new SAXException("EMLSAXHandler.writeAccessRuletoDB(): "
 					+ e.getMessage());
 		}// catch
+		finally {
+			try {
+				pstmt.close();
+			} catch (SQLException ee) {
+				throw new SAXException("EMLSAXHandler.writeAccessRuletoDB(): "
+						+ ee.getMessage());
+			}
+		}// finally
 
 	}// writeGivenAccessRuleIntoDB
 
+	/* Write a gaven access rule into db */
+	private void writeAccessRuleForRelatedDataFileIntoDB(AccessSection accessSection,
+			String dataId) throws SAXException {
+		if (accessSection == null) {
+			throw new SAXException("The access object is null");
+		}
+		// get rid of rev from dataId
+		// dataId = MetacatUtil.getDocIdFromString(dataId);
+		String permOrder = accessSection.getPermissionOrder();
+		String sql = null;
+		PreparedStatement pstmt = null;
+		sql = "INSERT INTO xml_access (docid, principal_name, permission, "
+				+ "perm_type, perm_order, accessfileid) VALUES " + " (?, ?, ?, ?, ?, ?)";
+
+		try {
+
+			pstmt = connection.prepareStatement(sql);
+			// Increase DBConnection usage count
+			connection.increaseUsageCount(1);
+			// Bind the values to the query
+			pstmt.setString(1, dataId);
+			logMetacat.debug("Docid in accesstable: " + docid);
+			pstmt.setString(6, docid);
+			logMetacat.debug("Accessfileid in accesstable: " + docid);
+			pstmt.setString(5, permOrder);
+			logMetacat.debug("PermOder in accesstable: " + permOrder);
+			// if it is not top level, set subsection id
+
+			Vector<AccessRule> accessRules = accessSection.getAccessRules();
+			// go through every rule
+			for (int i = 0; i < accessRules.size(); i++) {
+				AccessRule rule = accessRules.elementAt(i);
+				String permType = rule.getPermissionType();
+				int permission = rule.getPermission();
+				pstmt.setInt(3, permission);
+				logMetacat.debug("permission in accesstable: " + permission);
+				pstmt.setString(4, permType);
+				logMetacat.debug("Permtype in accesstable: " + permType);
+				// go through every principle in rule
+				Vector<String> nameVector = rule.getPrincipal();
+				for (int j = 0; j < nameVector.size(); j++) {
+					String prName = nameVector.elementAt(j);
+					pstmt.setString(2, prName);
+					logMetacat.debug("Principal in accesstable: " + prName);
+					logMetacat.debug("running sql: " + pstmt.toString());
+					pstmt.execute();
+				}// for
+			}// for
+			pstmt.close();
+		}// try
+		catch (SQLException e) {
+			throw new SAXException("EMLSAXHandler.writeAccessRuletoDB(): "
+					+ e.getMessage());
+		}// catch
+		finally {
+			try {
+				pstmt.close();
+			} catch (SQLException ee) {
+				throw new SAXException("EMLSAXHandler.writeAccessRuletoDB(): "
+						+ ee.getMessage());
+			}
+		}// finally
+
+	}// writeAccessRuleForRalatedDataFileIntoDB
+
 	/* Delete from db all permission for resources related to @aclid if any. */
 	private void deletePermissionsInAccessTable(String aclid) throws SAXException {
 		Statement stmt = null;
