Search in sources :

Example 16 with MetaDocPart

use of com.torodb.core.transaction.metainf.MetaDocPart in project torodb by torodb.

the class BackendServiceImpl method enableIndexJobs.

private Stream<Consumer<DSLContext>> enableIndexJobs(MetaDatabase db, MetaCollection col) {
    List<Consumer<DSLContext>> consumerList = new ArrayList<>();
    Iterator<? extends MetaDocPart> docPartIterator = col.streamContainedMetaDocParts().iterator();
    while (docPartIterator.hasNext()) {
        MetaDocPart docPart = docPartIterator.next();
        Iterator<? extends MetaIdentifiedDocPartIndex> docPartIndexIterator = docPart.streamIndexes().iterator();
        while (docPartIndexIterator.hasNext()) {
            MetaIdentifiedDocPartIndex docPartIndex = docPartIndexIterator.next();
            consumerList.add(createIndexJob(db, docPart, docPartIndex));
        }
    }
    return consumerList.stream();
}
Also used : MetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex) Consumer(java.util.function.Consumer) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) ArrayList(java.util.ArrayList)

Example 17 with MetaDocPart

use of com.torodb.core.transaction.metainf.MetaDocPart in project torodb by torodb.

the class PostgreSqlWriteInterface method copyInsertDocPartData.

private void copyInsertDocPartData(PGConnection connection, String schemaName, DocPartData docPartData) throws SQLException, IOException {
    final int maxBatchSize = 1024;
    final CopyManager copyManager = connection.getCopyAPI();
    final MetaDocPart metaDocPart = docPartData.getMetaDocPart();
    Collection<InternalField<?>> internalFields = postgreSqlMetaDataReadInterface.getInternalFields(metaDocPart);
    final StringBuilder sb = new StringBuilder(65536);
    final String copyStatement = getCopyInsertDocPartDataStatement(schemaName, docPartData, metaDocPart, internalFields);
    Iterator<DocPartRow> docPartRowIterator = docPartData.iterator();
    int docCounter = 0;
    while (docPartRowIterator.hasNext()) {
        DocPartRow tableRow = docPartRowIterator.next();
        docCounter++;
        addValuesToCopy(sb, tableRow, internalFields);
        assert sb.length() != 0;
        if (docCounter % maxBatchSize == 0 || !docPartRowIterator.hasNext()) {
            executeCopy(copyManager, copyStatement, sb);
            sb.setLength(0);
        }
    }
}
Also used : MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) InternalField(com.torodb.backend.InternalField) DocPartRow(com.torodb.core.d2r.DocPartRow) CopyManager(org.postgresql.copy.CopyManager)

Example 18 with MetaDocPart

use of com.torodb.core.transaction.metainf.MetaDocPart 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 19 with MetaDocPart

use of com.torodb.core.transaction.metainf.MetaDocPart in project torodb by torodb.

the class SqlTorodTransaction method findByAttRefInProjection.

@Override
public Cursor<Tuple2<Integer, KvValue<?>>> findByAttRefInProjection(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 EmptyCursor<>();
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        LOGGER.trace("Collection " + dbName + '.' + colName + " does not exist. An empty cursor is returned");
        return new EmptyCursor<>();
    }
    if (values.isEmpty()) {
        LOGGER.trace("An empty list of values have been given as in condition. An empty cursor is returned");
        return new EmptyCursor<>();
    }
    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 EmptyCursor<>();
    }
    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 getInternalTransaction().getBackendTransaction().findByFieldInProjection(db, col, docPart, valuesMap);
}
Also used : 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) EmptyCursor(com.torodb.core.cursors.EmptyCursor) TableRef(com.torodb.core.TableRef) KvValue(com.torodb.kvdocument.values.KvValue)

Example 20 with MetaDocPart

use of com.torodb.core.transaction.metainf.MetaDocPart in project torodb by torodb.

the class SqlWriteTorodTransaction method deleteByAttRef.

@Override
public long deleteByAttRef(String dbName, String colName, AttributeReference attRef, KvValue<?> value) {
    MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
    if (db == null) {
        return 0;
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        return 0;
    }
    TableRef tableRef = extractTableRef(attRef);
    String lastKey = extractKeyName(attRef.getKeys().get(attRef.getKeys().size() - 1));
    MetaDocPart docPart = col.getMetaDocPartByTableRef(tableRef);
    if (docPart == null) {
        return 0;
    }
    MetaField field = docPart.getMetaFieldByNameAndType(lastKey, FieldType.from(value.getType()));
    if (field == null) {
        return 0;
    }
    Collection<Integer> dids = getInternalTransaction().getBackendTransaction().findByField(db, col, docPart, field, value).asDidCursor().getRemaining();
    getInternalTransaction().getBackendTransaction().deleteDids(db, col, dids);
    return dids.size();
}
Also used : MutableMetaDatabase(com.torodb.core.transaction.metainf.MutableMetaDatabase) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) MetaField(com.torodb.core.transaction.metainf.MetaField) MutableMetaCollection(com.torodb.core.transaction.metainf.MutableMetaCollection) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) TableRef(com.torodb.core.TableRef)

Aggregations

MetaDocPart (com.torodb.core.transaction.metainf.MetaDocPart)20 TableRef (com.torodb.core.TableRef)7 MetaCollection (com.torodb.core.transaction.metainf.MetaCollection)7 MetaDatabase (com.torodb.core.transaction.metainf.MetaDatabase)6 MetaField (com.torodb.core.transaction.metainf.MetaField)6 KvValue (com.torodb.kvdocument.values.KvValue)4 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)4 EmptyCursor (com.torodb.core.cursors.EmptyCursor)3 DocPartResult (com.torodb.core.d2r.DocPartResult)3 MetaIdentifiedDocPartIndex (com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex)3 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ArrayList (java.util.ArrayList)3 Context (com.torodb.backend.ErrorHandler.Context)2 ResultSetDocPartResult (com.torodb.backend.d2r.ResultSetDocPartResult)2 DocPartRow (com.torodb.core.d2r.DocPartRow)2 MetaIndex (com.torodb.core.transaction.metainf.MetaIndex)2 EmptyTorodCursor (com.torodb.torod.cursors.EmptyTorodCursor)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2