use of com.torodb.core.transaction.metainf.MetaDocPart in project torodb by torodb.
the class InsertBackendJobImpl method toString.
@Override
public String toString() {
MetaDocPart docPart = data.getMetaDocPart();
int rowCount = data.rowCount();
return "insert{db:" + db + ", col:" + col + ", docPart:" + docPart + ", rows:" + rowCount + '}';
}
use of com.torodb.core.transaction.metainf.MetaDocPart in project torodb by torodb.
the class R2DTranslatorImpl method translate.
@Override
public List<ToroDocument> translate(Iterator<DocPartResult> docPartResultIt) {
ImmutableList.Builder<ToroDocument> readedDocuments = ImmutableList.builder();
Table<TableRef, Integer, Map<String, List<KvValue<?>>>> currentFieldDocPartTable = HashBasedTable.<TableRef, Integer, Map<String, List<KvValue<?>>>>create();
Table<TableRef, Integer, Map<String, List<KvValue<?>>>> childFieldDocPartTable = HashBasedTable.<TableRef, Integer, Map<String, List<KvValue<?>>>>create();
int previousDepth = -1;
while (docPartResultIt.hasNext()) {
DocPartResult docPartResult = docPartResultIt.next();
MetaDocPart metaDocPart = docPartResult.getMetaDocPart();
TableRef tableRef = metaDocPart.getTableRef();
if (previousDepth != -1 && previousDepth != tableRef.getDepth()) {
Table<TableRef, Integer, Map<String, List<KvValue<?>>>> previousFieldChildDocPartTable = childFieldDocPartTable;
childFieldDocPartTable = currentFieldDocPartTable;
currentFieldDocPartTable = previousFieldChildDocPartTable;
if (!tableRef.isRoot()) {
currentFieldDocPartTable.clear();
}
}
previousDepth = tableRef.getDepth();
Map<Integer, Map<String, List<KvValue<?>>>> childFieldDocPartRow = childFieldDocPartTable.row(tableRef);
Map<Integer, Map<String, List<KvValue<?>>>> currentFieldDocPartRow;
if (tableRef.isRoot()) {
currentFieldDocPartRow = null;
} else {
currentFieldDocPartRow = currentFieldDocPartTable.row(tableRef.getParent().get());
}
readResult(metaDocPart, tableRef, docPartResult, currentFieldDocPartRow, childFieldDocPartRow, readedDocuments);
}
return readedDocuments.build();
}
use of com.torodb.core.transaction.metainf.MetaDocPart in project torodb by torodb.
the class AbstractReadInterface method getCollectionDidsWithFieldsInBatch.
@SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION", "ODR_OPEN_DATABASE_RESOURCE" }, justification = "ResultSet is wrapped in a Cursor<Integer>. It's iterated and closed in caller code")
private Cursor<Integer> getCollectionDidsWithFieldsInBatch(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCol, MetaDocPart metaDocPart, Multimap<MetaField, KvValue<?>> valuesMultimap) throws SQLException {
@SuppressWarnings("checkstyle:LineLength") Provider<Stream<Map.Entry<MetaField, Collection<KvValue<?>>>>> valuesMultimapSortedStreamProvider = () -> valuesMultimap.asMap().entrySet().stream().sorted((e1, e2) -> e1.getKey().getIdentifier().compareTo(e2.getKey().getIdentifier()));
String statement = getReadCollectionDidsWithFieldInStatement(metaDatabase.getIdentifier(), metaDocPart.getIdentifier(), valuesMultimapSortedStreamProvider.get().map(e -> new Tuple2<String, Integer>(e.getKey().getIdentifier(), e.getValue().size())));
Connection connection = dsl.configuration().connectionProvider().acquire();
try {
PreparedStatement preparedStatement = connection.prepareStatement(statement);
int parameterIndex = 1;
Iterator<Map.Entry<MetaField, Collection<KvValue<?>>>> valuesMultimapSortedIterator = valuesMultimapSortedStreamProvider.get().iterator();
while (valuesMultimapSortedIterator.hasNext()) {
Map.Entry<MetaField, Collection<KvValue<?>>> valuesMultimapEntry = valuesMultimapSortedIterator.next();
for (KvValue<?> value : valuesMultimapEntry.getValue()) {
sqlHelper.setPreparedStatementValue(preparedStatement, parameterIndex, valuesMultimapEntry.getKey().getType(), value);
parameterIndex++;
}
}
return new DefaultDidCursor(errorHandler, preparedStatement.executeQuery());
} finally {
dsl.configuration().connectionProvider().release(connection);
}
}
use of com.torodb.core.transaction.metainf.MetaDocPart in project torodb by torodb.
the class AbstractStructureInterface method renameCollection.
@Override
public void renameCollection(DSLContext dsl, String fromSchemaName, MetaCollection fromCollection, String toSchemaName, MetaCollection toCollection) {
Iterator<? extends MetaDocPart> metaDocPartIterator = fromCollection.streamContainedMetaDocParts().iterator();
while (metaDocPartIterator.hasNext()) {
MetaDocPart fromMetaDocPart = metaDocPartIterator.next();
MetaDocPart toMetaDocPart = toCollection.getMetaDocPartByTableRef(fromMetaDocPart.getTableRef());
String renameStatement = getRenameTableStatement(fromSchemaName, fromMetaDocPart.getIdentifier(), toMetaDocPart.getIdentifier());
sqlHelper.executeUpdate(dsl, renameStatement, Context.RENAME_TABLE);
Iterator<? extends MetaIdentifiedDocPartIndex> metaDocPartIndexIterator = fromMetaDocPart.streamIndexes().iterator();
while (metaDocPartIndexIterator.hasNext()) {
MetaIdentifiedDocPartIndex fromMetaIndex = metaDocPartIndexIterator.next();
MetaIdentifiedDocPartIndex toMetaIndex = toMetaDocPart.streamIndexes().filter(index -> index.hasSameColumns(fromMetaIndex)).findAny().get();
String renameIndexStatement = getRenameIndexStatement(fromSchemaName, fromMetaIndex.getIdentifier(), toMetaIndex.getIdentifier());
sqlHelper.executeUpdate(dsl, renameIndexStatement, Context.RENAME_INDEX);
}
if (!fromSchemaName.equals(toSchemaName)) {
String setSchemaStatement = getSetTableSchemaStatement(fromSchemaName, fromMetaDocPart.getIdentifier(), toSchemaName);
sqlHelper.executeUpdate(dsl, setSchemaStatement, Context.SET_TABLE_SCHEMA);
}
}
}
use of com.torodb.core.transaction.metainf.MetaDocPart in project torodb by torodb.
the class AbstractWriteInterface method deleteCollectionDocParts.
private void deleteCollectionDocParts(Connection c, String schemaName, MetaCollection metaCollection, Collection<Integer> dids) {
Iterator<? extends MetaDocPart> iterator = metaCollection.streamContainedMetaDocParts().sorted(TableRefComparator.MetaDocPart.DESC).iterator();
while (iterator.hasNext()) {
MetaDocPart metaDocPart = iterator.next();
String statement = getDeleteDocPartsStatement(schemaName, metaDocPart.getIdentifier(), dids);
sqlHelper.executeUpdate(c, statement, Context.DELETE);
LOGGER.trace("Executed {}", statement);
}
}
Aggregations