0

My problem is that com.tinkerpop.blueprints.Vertex class does not support multiple properties (Cardinality.SET or Cardinality.LIST). To get this option TitanVertex class that extends from Vertex must be used. I want use TransactionRetryHelper to make titan DB transaction.

User user = new TransactionRetryHelper.Builder<User>(tw.getConnection())
    .perform(new TransactionWork<User>() {
        @Override
        public User execute(final TransactionalGraph tg) throws Exception {
            return userDao.getUser(tg, userId);
        }
    }).build().oneAndDone();

But in this case TransactionWork interface pass TransactionalGraph to execute method and not TitanGraph that extends TransactionalGraph. The TitanVertex object I can get only from TitanGraph but not from TransactionalGraph. What is the alternative to TransactionRetryHelper that allows to use the TitanGraph?

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
OctopusSD
  • 147
  • 1
  • 4

1 Answers1

0

After more detailed research of my own problem I found the solution. In my case tw.getConnection returns TitanGraph that extends TransactionalGraph and it is the reason that I can cast (TitanGraph)TransactionalGraph tg and get TitanVertex from it. For example:

User user = new TransactionRetryHelper.Builder<User>(tw.getConnection())
.perform(new TransactionWork<User>() {
    @Override
    public User execute(final TransactionalGraph tg) throws Exception {
        TitanVertex vertex = ((TitanGraph)tg).getVertices(USER_ID, userId).iterator().next();
        User u = new User(vertex.getProperty(USER_ID));//Property USER_ID has Cardinality.SINGLE
        StringBuilder fullName = new StringBuilder();
        for (TitanProperty titanProperty : vertex.getProperties(NAME)) {//Property NAME has Cardinality.LIST
            fullName.append((String)titanProperty.getProperty(NAME));
        }
        u.setFullName(fullName);
        /*set other properties for User
        ...
        */
        return u;
    }
}).build().oneAndDone();
OctopusSD
  • 147
  • 1
  • 4