2

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?

Benjamin Brandmeier
  • 724
  • 1
  • 9
  • 19
  • Did you make sure your dfc.properties points to the same instance you are looking in to confirm? Does the `newFolder.dump()` line in your code give you anything back? I don't see where you print it out. If it gives you an ID back, then it is getting created. – Brendan Hannemann Aug 24 '11 at 18:00
  • Yes, actually I'm getting a ID back, when I'm debugging and looking for it. But right after it is executed, I'm trying to fetch it with a DQL, but it is not there for some reason ... – Benjamin Brandmeier Aug 24 '11 at 20:42
  • 2
    Are you using a DFC transaction of any kind? That would require you to commit it first. I have seen strange behavior when mixing DFC transactions with DQL even within the same transaction. My only other suggestion is that you double check the Acl to make sure you really have rights to it. – Brendan Hannemann Aug 25 '11 at 19:25
  • No DFC transaction is used of any kind. I also double checked the dfc properties and the ACL. I mean, when I'm using webtop to create a folder at the destination with exactly the same user it just works... or if I execute a 'create query' within dql editor it works nicely. but if i execute this programmatically it doesn't neither the query nor the dfc code... – Benjamin Brandmeier Aug 27 '11 at 07:09
  • Sorry unicron, shame on me. You were absolutely right. I did not post my establishConnection() method and in that I actually did use a transaction.begin() call. Removing that fixes all the problems. Thank you. – Benjamin Brandmeier Aug 30 '11 at 07:20

2 Answers2

0

Which user you are using when you try folder creation with DFC? Is it the same one you're using later for DQL checking? If not, it could be that folder's ACL doesn't let you see newly created folder with different user.

0

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;
}
Benjamin Brandmeier
  • 724
  • 1
  • 9
  • 19
  • 1
    the line code doing the "beginTransaction" is not so bad, but if you open a transaction, you will have to commit it with a "commitTransaction", then your objectId will be definitely persisted in database. – Donatello Jul 03 '15 at 09:07