Search in sources :

Example 1 with TableRefFactory

use of com.torodb.core.TableRefFactory in project torodb by torodb.

the class ReservedIdGeneratorImplTest method whenTableRefDoesntExistsCallsToFactory.

@Test
public void whenTableRefDoesntExistsCallsToFactory() {
    ReservedIdInfoFactory factory = new MockedReservedIdInfoFactory();
    factory.startAsync();
    factory.awaitRunning();
    TableRefFactory tableRefFactory = new TableRefFactoryImpl();
    ReservedIdInfoFactory reservedIdInfoFactory = Mockito.spy(factory);
    ReservedIdGeneratorImpl container = new ReservedIdGeneratorImpl(reservedIdInfoFactory, new ThreadFactoryBuilder().build());
    DocPartRidGenerator docPartRidGenerator = container.getDocPartRidGenerator("myDB", "myCollection");
    int nextRid = docPartRidGenerator.nextRid(tableRefFactory.createRoot());
    Mockito.verify(reservedIdInfoFactory).create("myDB", "myCollection", tableRefFactory.createRoot());
    assertEquals(1, nextRid);
}
Also used : DocPartRidGenerator(com.torodb.core.d2r.ReservedIdGenerator.DocPartRidGenerator) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) TableRefFactory(com.torodb.core.TableRefFactory) TableRefFactoryImpl(com.torodb.core.impl.TableRefFactoryImpl) Test(org.junit.Test)

Example 2 with TableRefFactory

use of com.torodb.core.TableRefFactory in project torodb by torodb.

the class SqlTorodTransaction method extractTableRef.

protected TableRef extractTableRef(AttributeReference attRef) {
    TableRefFactory tableRefFactory = getConnection().getServer().getTableRefFactory();
    TableRef ref = tableRefFactory.createRoot();
    if (attRef.getKeys().isEmpty()) {
        throw new IllegalArgumentException("The empty attribute reference is not valid");
    }
    if (attRef.getKeys().size() > 1) {
        List<Key<?>> keys = attRef.getKeys();
        List<Key<?>> tableKeys = keys.subList(0, keys.size() - 1);
        for (Key<?> key : tableKeys) {
            ref = tableRefFactory.createChild(ref, extractKeyName(key));
        }
    }
    return ref;
}
Also used : TableRefFactory(com.torodb.core.TableRefFactory) TableRef(com.torodb.core.TableRef) ObjectKey(com.torodb.core.language.AttributeReference.ObjectKey) Key(com.torodb.core.language.AttributeReference.Key)

Aggregations

TableRefFactory (com.torodb.core.TableRefFactory)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 TableRef (com.torodb.core.TableRef)1 DocPartRidGenerator (com.torodb.core.d2r.ReservedIdGenerator.DocPartRidGenerator)1 TableRefFactoryImpl (com.torodb.core.impl.TableRefFactoryImpl)1 Key (com.torodb.core.language.AttributeReference.Key)1 ObjectKey (com.torodb.core.language.AttributeReference.ObjectKey)1 Test (org.junit.Test)1