I'm facing a strange problem. All I want is to create a new folder with the DFC. But when I execute the code (JUnit or inside the Application) no folder is created and surprisingly no exception is thrown. So I guess the error is somewhere else.
This is my code:
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);
}
I'm getting a sysobject id in return, but when I'm trying to fetch it with a dql statement then I cannot find it.
I tried to execute a dql create query alternatively which creates the folder. This does not work with JUnit or in the running Application, but when I execute it manually it simply works.
This is my getSession() method
private IDfSession getSession()
{
try
{
if (m_sessionManager == null)
{
return establishConnection();
}
else
{
return m_sessionManager.getSession(m_sRepository);
}
}
catch (DfException e)
{
e.printStackTrace();
}
return null;
}
Any ideas on that?
Thanks to the comments of unicron. This actually let me fix the problem. In my establishConnection() method, which I did not post in the question, I actually used beginTransaction(). Removing that fixed the problem and everything worked fine.
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;
}