Search in sources :

Example 1 with InternalField

use of com.torodb.backend.InternalField 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)

Aggregations

InternalField (com.torodb.backend.InternalField)1 DocPartRow (com.torodb.core.d2r.DocPartRow)1 MetaDocPart (com.torodb.core.transaction.metainf.MetaDocPart)1 CopyManager (org.postgresql.copy.CopyManager)1