Search in sources :

Example 26 with TableRef

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

the class PostgreSqlReadInterface method getLastRowIdUsedStatement.

@Override
protected String getLastRowIdUsedStatement(MetaDatabase metaDatabase, MetaDocPart metaDocPart) {
    TableRef tableRef = metaDocPart.getTableRef();
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT max(\"").append(getPrimaryKeyColumnIdentifier(tableRef)).append("\") FROM \"").append(metaDatabase.getIdentifier()).append("\".\"").append(metaDocPart.getIdentifier()).append("\"");
    String statement = sb.toString();
    return statement;
}
Also used : TableRef(com.torodb.core.TableRef)

Example 27 with TableRef

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

the class TableRefImplTest method rootArrayTest.

@Test
public void rootArrayTest() throws Exception {
    TableRef tableRef = createTableRef("array");
    Assert.assertEquals("array", tableRef.getName());
    Assert.assertEquals(1, tableRef.getDepth());
    Assert.assertEquals(0, tableRef.getArrayDimension());
    Assert.assertEquals(false, tableRef.isRoot());
    Assert.assertEquals(false, tableRef.isInArray());
    Assert.assertEquals(true, tableRef.getParent().isPresent());
}
Also used : TableRef(com.torodb.core.TableRef) Test(org.junit.Test)

Example 28 with TableRef

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

the class BatchMetaCollectionTest method testNewBatch.

@Test
public void testNewBatch() {
    TableRef tableRef = tableRefFactory.createChild(tableRefFactory.createRoot(), "aPath");
    String tableId = "aTableId";
    BatchMetaDocPart newDocPart = collection.addMetaDocPart(tableRef, tableId);
    assertTrue("addMetaDocPart is not working properly", newDocPart.isCreatedOnCurrentBatch());
    assertFalse(Iterables.isEmpty(collection.getOnBatchModifiedMetaDocParts()));
    collection.newBatch();
    assertFalse("A doc part created on the previous batch still thinks it is created on the next batch", newDocPart.isCreatedOnCurrentBatch());
    assertTrue(Iterables.isEmpty(collection.getOnBatchModifiedMetaDocParts()));
}
Also used : TableRef(com.torodb.core.TableRef) Test(org.junit.Test)

Example 29 with TableRef

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

the class SqlTorodTransaction method findByAttRefIn.

@Override
public TorodCursor findByAttRefIn(String dbName, String colName, AttributeReference attRef, Collection<KvValue<?>> values) {
    MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
    if (db == null) {
        LOGGER.trace("Db with name " + dbName + " does not exist. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        LOGGER.trace("Collection " + dbName + '.' + colName + " does not exist. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    if (values.isEmpty()) {
        LOGGER.trace("An empty list of values have been given as in condition. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    TableRef ref = extractTableRef(attRef);
    String lastKey = extractKeyName(attRef.getKeys().get(attRef.getKeys().size() - 1));
    MetaDocPart docPart = col.getMetaDocPartByTableRef(ref);
    if (docPart == null) {
        LOGGER.trace("DocPart " + dbName + '.' + colName + '.' + ref + " does not exist. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    Multimap<MetaField, KvValue<?>> valuesMap = ArrayListMultimap.create();
    for (KvValue<?> value : values) {
        MetaField field = docPart.getMetaFieldByNameAndType(lastKey, FieldType.from(value.getType()));
        if (field != null) {
            valuesMap.put(field, value);
        }
    }
    return toToroCursor(getInternalTransaction().getBackendTransaction().findByFieldIn(db, col, docPart, valuesMap));
}
Also used : EmptyTorodCursor(com.torodb.torod.cursors.EmptyTorodCursor) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) MetaField(com.torodb.core.transaction.metainf.MetaField) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) TableRef(com.torodb.core.TableRef) KvValue(com.torodb.kvdocument.values.KvValue)

Example 30 with TableRef

use of com.torodb.core.TableRef 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

TableRef (com.torodb.core.TableRef)32 Test (org.junit.Test)13 MetaDocPart (com.torodb.core.transaction.metainf.MetaDocPart)6 DocPartResult (com.torodb.core.d2r.DocPartResult)5 ToroDocument (com.torodb.core.document.ToroDocument)5 MetaCollection (com.torodb.core.transaction.metainf.MetaCollection)5 MetaDatabase (com.torodb.core.transaction.metainf.MetaDatabase)5 R2DTranslator (com.torodb.core.d2r.R2DTranslator)4 MetaField (com.torodb.core.transaction.metainf.MetaField)4 KvDocument (com.torodb.kvdocument.values.KvDocument)4 KvArray (com.torodb.kvdocument.values.KvArray)3 KvValue (com.torodb.kvdocument.values.KvValue)3 MetaIdentifiedDocPartIndex (com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex)2 MutableMetaCollection (com.torodb.core.transaction.metainf.MutableMetaCollection)2 MutableMetaDatabase (com.torodb.core.transaction.metainf.MutableMetaDatabase)2 MutableMetaDocPart (com.torodb.core.transaction.metainf.MutableMetaDocPart)2 EmptyTorodCursor (com.torodb.torod.cursors.EmptyTorodCursor)2 ArrayList (java.util.ArrayList)2 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1