use of com.torodb.core.transaction.metainf.MetaField in project torodb by torodb.
the class PostgreSqlWriteInterface method getInsertDocPartDataStatement.
@Override
protected String getInsertDocPartDataStatement(String schemaName, MetaDocPart metaDocPart, Iterator<MetaField> metaFieldIterator, Iterator<MetaScalar> metaScalarIterator, Collection<InternalField<?>> internalFields, List<FieldType> fieldTypeList) {
final StringBuilder insertStatementBuilder = new StringBuilder(2048);
final StringBuilder insertStatementValuesBuilder = new StringBuilder(1024);
insertStatementBuilder.append("INSERT INTO \"").append(schemaName).append("\".\"").append(metaDocPart.getIdentifier()).append("\" (");
insertStatementValuesBuilder.append(" VALUES (");
for (InternalField<?> internalField : internalFields) {
insertStatementBuilder.append("\"").append(internalField.getName()).append("\",");
insertStatementValuesBuilder.append("?,");
}
while (metaScalarIterator.hasNext()) {
MetaScalar metaScalar = metaScalarIterator.next();
FieldType type = metaScalar.getType();
insertStatementBuilder.append("\"").append(metaScalar.getIdentifier()).append("\",");
insertStatementValuesBuilder.append(sqlHelper.getPlaceholder(type)).append(',');
fieldTypeList.add(type);
}
while (metaFieldIterator.hasNext()) {
MetaField metaField = metaFieldIterator.next();
FieldType type = metaField.getType();
insertStatementBuilder.append("\"").append(metaField.getIdentifier()).append("\",");
insertStatementValuesBuilder.append(sqlHelper.getPlaceholder(type)).append(',');
fieldTypeList.add(type);
}
insertStatementBuilder.setCharAt(insertStatementBuilder.length() - 1, ')');
insertStatementValuesBuilder.setCharAt(insertStatementValuesBuilder.length() - 1, ')');
insertStatementBuilder.append(insertStatementValuesBuilder);
String statement = insertStatementBuilder.toString();
return statement;
}
use of com.torodb.core.transaction.metainf.MetaField in project torodb by torodb.
the class SqlTorodTransaction method findByAttRef.
@Override
public TorodCursor findByAttRef(String dbName, String colName, AttributeReference attRef, KvValue<?> value) {
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();
}
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();
}
MetaField field = docPart.getMetaFieldByNameAndType(lastKey, FieldType.from(value.getType()));
if (field == null) {
LOGGER.trace("Field " + dbName + '.' + colName + '.' + ref + '.' + lastKey + " does not exist. An empty cursor is returned");
return new EmptyTorodCursor();
}
return toToroCursor(getInternalTransaction().getBackendTransaction().findByField(db, col, docPart, field, value));
}
use of com.torodb.core.transaction.metainf.MetaField in project torodb by torodb.
the class ExclusiveWriteBackendTransactionImpl method copyFields.
private void copyFields(IdentifierFactory identifierFactory, MetaDocPart fromMetaDocPart, MetaDatabase toMetaDb, MetaCollection toMetaColl, MutableMetaDocPart toMetaDocPart) {
Iterator<? extends MetaField> fromMetaFieldIterator = fromMetaDocPart.streamFields().iterator();
while (fromMetaFieldIterator.hasNext()) {
MetaField fromMetaField = fromMetaFieldIterator.next();
MetaField toMetaField = toMetaDocPart.addMetaField(fromMetaField.getName(), identifierFactory.toFieldIdentifier(toMetaDocPart, fromMetaField.getName(), fromMetaField.getType()), fromMetaField.getType());
getSqlInterface().getMetaDataWriteInterface().addMetaField(getDsl(), toMetaDb, toMetaColl, toMetaDocPart, toMetaField);
}
}
use of com.torodb.core.transaction.metainf.MetaField in project torodb by torodb.
the class AbstractWriteInterface method insertDocPartData.
@Override
public void insertDocPartData(DSLContext dsl, String schemaName, DocPartData docPartData) throws UserException {
Iterator<DocPartRow> docPartRowIterator = docPartData.iterator();
if (!docPartRowIterator.hasNext()) {
return;
}
try {
MetaDocPart metaDocPart = docPartData.getMetaDocPart();
Iterator<MetaScalar> metaScalarIterator = docPartData.orderedMetaScalarIterator();
Iterator<MetaField> metaFieldIterator = docPartData.orderedMetaFieldIterator();
standardInsertDocPartData(dsl, schemaName, docPartData, metaDocPart, metaScalarIterator, metaFieldIterator, docPartRowIterator);
} catch (DataAccessException ex) {
throw errorHandler.handleUserException(Context.INSERT, ex);
}
}
use of com.torodb.core.transaction.metainf.MetaField in project torodb by torodb.
the class DerbyWriteInterface method getInsertDocPartDataStatement.
@Override
protected String getInsertDocPartDataStatement(String schemaName, MetaDocPart metaDocPart, Iterator<MetaField> metaFieldIterator, Iterator<MetaScalar> metaScalarIterator, Collection<InternalField<?>> internalFields, List<FieldType> fieldTypeList) {
final StringBuilder insertStatementBuilder = new StringBuilder(2048);
final StringBuilder insertStatementValuesBuilder = new StringBuilder(1024);
insertStatementBuilder.append("INSERT INTO \"").append(schemaName).append("\".\"").append(metaDocPart.getIdentifier()).append("\" (");
insertStatementValuesBuilder.append(" VALUES (");
for (InternalField<?> internalField : internalFields) {
insertStatementBuilder.append("\"").append(internalField.getName()).append("\",");
insertStatementValuesBuilder.append("?,");
}
while (metaScalarIterator.hasNext()) {
MetaScalar metaScalar = metaScalarIterator.next();
insertStatementBuilder.append("\"").append(metaScalar.getIdentifier()).append("\",");
insertStatementValuesBuilder.append("?,");
fieldTypeList.add(metaScalar.getType());
}
while (metaFieldIterator.hasNext()) {
MetaField metaField = metaFieldIterator.next();
insertStatementBuilder.append("\"").append(metaField.getIdentifier()).append("\",");
insertStatementValuesBuilder.append("?,");
fieldTypeList.add(metaField.getType());
}
insertStatementBuilder.setCharAt(insertStatementBuilder.length() - 1, ')');
insertStatementValuesBuilder.setCharAt(insertStatementValuesBuilder.length() - 1, ')');
insertStatementBuilder.append(insertStatementValuesBuilder);
String statement = insertStatementBuilder.toString();
return statement;
}
Aggregations