OctopusSD
OctopusSD

Reputation: 147

Get multiple properties from blueprints Vertex

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?

Upvotes: 0

Views: 220

Answers (1)

OctopusSD
OctopusSD

Reputation: 147

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();

Upvotes: 0

Related Questions