monitor.log().debug("Copy " + src.getObjectId() + " to " + trg.getObjectId());
if (src instanceof IDfFolder) {
String dql = "dm_folder WHERE FOLDER(ID('"+trg.getObjectId()+"')) and object_name='"+MSql.escape(src.getObjectName())+"'";
IDfPersistentObject existing = session.getObjectByQualification(dql);
if ( existing != null ) {
// Target folder already exists - this is the short way, use the existing folder to continue
monitor.log().debug(" Target folder already exists " + existing.getObjectId());
cnt++;
monitor.worked(cnt);
dql = "select r_object_id from dm_sysobject where FOLDER(ID('"+src.getObjectId()+"'))";
IDfCollection res = new DfQuery(dql).execute(session, IDfQuery.READ_QUERY);
LinkedList<String> children = new LinkedList<String>();
while (res.next())
children.add(res.getString("r_object_id"));
res.close();
for(String id : children) {
IDfSysObject newSrc = (IDfSysObject) session.getObject(new DfId(id));
cnt = copy((IDfFolder)existing,newSrc,cnt);
}
return cnt;
}
}
LinkedList<String> tmp = new LinkedList<String>();
for ( int i = 0; i < src.getFolderIdCount(); i++)
tmp.add(src.getFolderId(i).getId());
src.link(trg.getObjectId().getId());
for (String id : tmp )
src.unlink(id);
IDfId newId = src.saveAsNew(true);
monitor.log().debug(" Created: " + newId);
src.revert();
IDfPersistentObject newItem = session.getObject(newId);
cnt++;
monitor.worked(cnt);
// fire events
if (useTransaction) {