我正面临着一个奇怪的问题。我只想用DFC创建一个新文件夹。但是,当我执行代码(JUnit或应用程序内部)时,没有创建任何文件夹,令人惊讶的是,也没有抛出异常。所以我猜错误出在别的地方。
这是我的代码:
public void createNewFolder(String sFolderName, String sParentId)
{
IDfSession session = null;
try
{
session = getSession();
IDfFolder newFolder = (IDfFolder) session.newObject("dm_folder");
newFolder.setObjectName(sFolderName);
newFolder.link(sParentId);
newFolder.save();
String sDump = newFolder.dump();
System.out.println("Folder ["+sFolderName+"] saved.");
System.out.println("Folder has id ["+newFolder.getId("r_object_id")+"]");
}
catch (DfException e)
{
e.printStackTrace();
}
finally
{
m_sessionManager.release(session);
}我得到了一个sysobject id作为回报,但当我试图用dql语句获取它时,我找不到它。
我尝试执行创建文件夹的dql create查询。这不适用于JUnit或正在运行的应用程序,但当我手动执行它时,它很简单。
这是我的getSession()方法
private IDfSession getSession()
{
try
{
if (m_sessionManager == null)
{
return establishConnection();
}
else
{
return m_sessionManager.getSession(m_sRepository);
}
}
catch (DfException e)
{
e.printStackTrace();
}
return null;
}对此有什么想法吗?
发布于 2011-08-30 15:25:43
感谢unicron的评论。这实际上让我解决了这个问题。在我的establishConnection()方法中,我实际上使用了beginTransaction()。移除它解决了问题,一切都运行得很好。
public IDfSession establishConnection(String sUserName, String sPassword, String sRepository) throws DfException
{
System.out.println("Login");
IDfClientX clientX = new DfClientX();
IDfClient localClient = clientX.getLocalClient();
IDfSessionManager sessionManager = localClient.newSessionManager();
IDfLoginInfo loginInfo = new DfLoginInfo();
loginInfo.setUser(sUserName);
loginInfo.setPassword(sPassword);
sessionManager.setIdentity(sRepository, loginInfo);
// THIS IS THE EVIL LINE !
sessionManager.beginTransaction();
System.out.println("sessionmanager ist geladen");
IDfSession session = sessionManager.getSession(sRepository);
m_sUserName = sUserName;
m_sRepository = sRepository;
m_sessionManager = sessionManager;
return session;
}发布于 2011-08-24 21:35:49
当您尝试使用DFC创建文件夹时,您使用的是哪个用户?它是您稍后用于DQL检查的同一个DQL吗?如果不是,可能是文件夹的ACL不允许您看到具有不同用户的新创建的文件夹。
https://stackoverflow.com/questions/7118210
复制相似问题