其中一个应用程序(比如ABC)仅将FileNet用于存储文档。现在其中一些引用被清除在ABC中(但清除的文档ID存储在ABC的数据库中)并且不再需要存储在FileNet中的那些文档,需要删除它们来清理空间。
为达到上述目的,我们有以下逻辑:
问题是如何连接到CE之外的其他数据库以及
答案 0 :(得分:0)
一个简单的自定义批处理Java / .NET程序可以用于此目的。如果您计划每月/每季度安排此活动,它还将有助于定期运行。
您可以使用下面的代码段作为参考。当然,这不是最佳选择,只是潦草地写下来。
String query = "select DOCID from ......."; //appropriate query to return document ids.
try{
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
Document doc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id(<<doc Id in the loop>>));
doc.delete();
doc.save(RefreshMode.NO_REFRESH);
}
} catch (SQLException e)
{
//something went wrong with the sql
}
关于自定义事件,我不确定您将触发器与哪个自定义事件关联?
答案 1 :(得分:0)
我有一个自定义数据库,我将从中获取GUID,然后从CE中删除该文档(如果可用)。与GUID关联的所有记录都将从表中删除。
此外,该方法已同步以启用多个线程以加速该过程。随着记录数量的增加,批量删除肯定需要时间。输出消息仍然需要安排。
/**
* This method "HARD" deletes the document from CE in <B>BATCH</B>.
* @param filenetDocGUID
* @throws Exception
*/
public static synchronized String batchDeleteDocumentFromCE_DB(List<String> filenetDocGUID, String QUERY) throws Exception {
System.out.println("Start of batchDeleteDocumentFromCE_DB() method");
System.out.println("Input Parameter filenetDocGUID is : " + filenetDocGUID);
long startTime = System.currentTimeMillis();
Document document = null;
UserContext uc = null;
ObjectStore os = null;
Subject subject = null;
VersionSeries vs = null;
UpdatingBatch ub = null;
int deletedRecordsFromDB [] = null ;
List<String> deletedRecordsFromCE = null;
PreparedStatement preparedStatement = null;
Connection dbConnection = null;
String messageBody = "<table border=\"1\" align=\"center\"><tr><td>GUID</td><td>DB Records</td><td>CE Records</td></tr>";
List<String> processedfilenetDocGUID = null;
try {
if (filenetDocGUID != null) {
getCESession(); // This will get CE Session
os = ceSessionData.getObjectStore();
System.out.println("Domain fetched from CESession static reference is : " + ceSessionData.getDomain());
// The RefreshMode parameter indicates that the property cache for this instance is to be
// refreshed with the updated data.
ub = UpdatingBatch.createUpdatingBatchInstance(ceSessionData.getDomain(), RefreshMode.NO_REFRESH);
System.out.println("Batch update object created");
subject = ceSessionData.getSubject();
System.out.println("Subject fetched from CESession static reference.");
uc = UserContext.get();
uc.pushSubject(subject);
dbConnection = getDataBaseConnection();
dbConnection.setAutoCommit(false); // auto commit is set to false so that DB is not committed before deleting the records
preparedStatement = dbConnection.prepareStatement(QUERY);
//QUERY will be for the db from where you need to remove the data
deletedRecordsFromCE = new ArrayList<String>();
if (os != null)
{
processedfilenetDocGUID = new ArrayList<String>();
for(String GUID : filenetDocGUID)
{
try
{
//get document versions from CE
document = Factory.Document.fetchInstance(os, GUID.trim(), null);
vs = document.get_VersionSeries();
vs.delete();
ub.add(vs, null);// add documents to the batch
//prepare statement for deleting records from DB with the GUID
preparedStatement.setString(1, GUID.trim());
preparedStatement.addBatch(); // add records to dB batch for deletion
deletedRecordsFromCE.add("1");
processedfilenetDocGUID.add(GUID);
}
catch(Exception exp)
{
if(exp.getMessage().contains("The requested item was not found.")||exp.getMessage().contains("E_OBJECT_NOT_FOUND"))
{
log.error("The requested item with GUID : "+GUID.trim()+" was not found in CE.");
//If document is not available in CE, then delete all records associated with it from DB
//document not present in CE but available in DB so delete all the DB records referring to this GUID
//prepare statement for deleting records from DB with the GUID
preparedStatement.setString(1, GUID.trim());
preparedStatement.addBatch();
deletedRecordsFromCE.add("The requested item was not found.");
processedfilenetDocGUID.add(GUID);
}
else
{
log.error("Exception occurred while fetching Document Version Series from DB");
}
}
}
deletedRecordsFromDB = preparedStatement.executeBatch();
System.out.println("Batch Records deleted from DB >>>>>>>>>>>>>>>>>>>>");
if(ub.hasPendingExecute())
{
//execute the batch only if there are records in the batch
ub.updateBatch();
System.out.println("Batch Records deleted from CE>>>>>>>>>>>>>>>>>>>>>>>>>>");
}
else
{
System.out.println("No records to be deleted from CE>>>>>>>>>>>>>>>>>>>>>>>>>>");
}
dbConnection.commit();
System.out.println("DB delete records commit successful");
//below will create a html to view the report for deletion
for(int i=0; i<processedfilenetDocGUID.size(); i++)
{
messageBody = messageBody+("<tr><td>"+processedfilenetDocGUID.get(i)+"</td>");
if(deletedRecordsFromCE.get(i)!=null)
{
//only if document was present in CE or document version series was not obtained from CE
messageBody = messageBody+("<td>"+deletedRecordsFromDB[i]+"</td><td>"+deletedRecordsFromCE.get(i)+"</td>");
}
else
{
//if any other exception occurs then neglect the record and proceed with others
messageBody = messageBody+("<td>"+deletedRecordsFromDB[i]+"</td><td>Exception occured while deleting from CE.</td>");
}
messageBody = messageBody+(messageBody + "</tr>");
}
}
}
}
catch (Exception e)
{
System.out.println("Exception in deleteDocumentFromCE() Method of CEManager.class");
dbConnection.rollback(); // rollback from dB in case of issues
log.error(e.getMessage());
throw new Exception("System Error occurred while deleting the document in CE.. "+e.getMessage());
}
finally
{
messageBody = messageBody+("<tr><td colspan=\"3\">Time taken for Batch in msec : "+(System.currentTimeMillis()-startTime)+"</td></tr>");
messageBody = messageBody+("<tr><td colspan=\"3\">Records deleted : "+processedfilenetDocGUID.size()+" from input "+filenetDocGUID.size()+"</td></tr>");
messageBody = messageBody+("</table>");
System.out.println("Message : "+messageBody);
document = null;
vs = null;
ub = null;
deletedRecordsFromCE = null;
closeDBResources(dbConnection, preparedStatement, null);
if (uc != null)
uc.popSubject();
}
System.out.println("End of batchDeleteDocumentFromCE_DB() method.");
return messageBody;
}