Search in sources :

Example 86 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project torodb by torodb.

the class MemoryData method openWriteTransaction.

@SuppressFBWarnings(value = { "UL_UNRELEASED_LOCK" })
public MdWriteTransaction openWriteTransaction() {
    Lock writeLock = lock.writeLock();
    writeLock.lock();
    try {
        return new MdWriteTransaction(data, indexes, () -> idGenerator.incrementAndGet(), this::onCommit, writeLock);
    } catch (Throwable ex) {
        writeLock.unlock();
        throw ex;
    }
}
Also used : ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 87 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project torodb by torodb.

the class AbstractReadInterface method getCollectionDidsAndProjectionWithFieldsInBatch.

@SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION", "ODR_OPEN_DATABASE_RESOURCE" }, justification = "ResultSet is wrapped in a Cursor<Tuple2<Integer, KVValue<?>>>. " + "It's iterated and closed in caller code")
private Cursor<Tuple2<Integer, KvValue<?>>> getCollectionDidsAndProjectionWithFieldsInBatch(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCol, MetaDocPart metaDocPart, MetaField metaField, Collection<KvValue<?>> values) throws SQLException {
    String statement = getReadCollectionDidsAndProjectionWithFieldInStatement(metaDatabase.getIdentifier(), metaDocPart.getIdentifier(), metaField.getIdentifier(), values.size());
    Connection connection = dsl.configuration().connectionProvider().acquire();
    try {
        PreparedStatement preparedStatement = connection.prepareStatement(statement);
        int parameterIndex = 1;
        for (KvValue<?> value : values) {
            sqlHelper.setPreparedStatementValue(preparedStatement, parameterIndex, metaField.getType(), value);
            parameterIndex++;
        }
        return new AbstractCursor<Tuple2<Integer, KvValue<?>>>(errorHandler, preparedStatement.executeQuery()) {

            @Override
            protected Tuple2<Integer, KvValue<?>> read(ResultSet resultSet) throws SQLException {
                return new Tuple2<>(resultSet.getInt(1), sqlHelper.getResultSetKvValue(metaField.getType(), dataTypeProvider.getDataType(metaField.getType()), resultSet, 2));
            }
        };
    } finally {
        dsl.configuration().connectionProvider().release(connection);
    }
}
Also used : Tuple2(org.jooq.lambda.tuple.Tuple2) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KvValue(com.torodb.kvdocument.values.KvValue) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 88 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project torodb by torodb.

the class AbstractReadInterface method getCollectionDidsWithFieldEqualsTo.

@Override
@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")
public Cursor<Integer> getCollectionDidsWithFieldEqualsTo(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCol, MetaDocPart metaDocPart, MetaField metaField, KvValue<?> value) throws SQLException {
    assert metaDatabase.getMetaCollectionByIdentifier(metaCol.getIdentifier()) != null;
    assert metaCol.getMetaDocPartByIdentifier(metaDocPart.getIdentifier()) != null;
    assert metaDocPart.getMetaFieldByIdentifier(metaField.getIdentifier()) != null;
    String statement = getReadCollectionDidsWithFieldEqualsToStatement(metaDatabase.getIdentifier(), metaDocPart.getIdentifier(), metaField.getIdentifier());
    Connection connection = dsl.configuration().connectionProvider().acquire();
    try {
        PreparedStatement preparedStatement = connection.prepareStatement(statement);
        sqlHelper.setPreparedStatementValue(preparedStatement, 1, metaField.getType(), value);
        return new DefaultDidCursor(errorHandler, preparedStatement.executeQuery());
    } finally {
        dsl.configuration().connectionProvider().release(connection);
    }
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 89 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings 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);
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Connection(java.sql.Connection) Provider(javax.inject.Provider) IteratorCursor(com.torodb.core.cursors.IteratorCursor) Multimap(com.google.common.collect.Multimap) Seq(org.jooq.lambda.Seq) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) TableRefFactory(com.torodb.core.TableRefFactory) KvValue(com.torodb.kvdocument.values.KvValue) Tuple2(org.jooq.lambda.tuple.Tuple2) SQLException(java.sql.SQLException) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) ResultSetDocPartResult(com.torodb.backend.d2r.ResultSetDocPartResult) ResultSet(java.sql.ResultSet) Map(java.util.Map) DSLContext(org.jooq.DSLContext) Context(com.torodb.backend.ErrorHandler.Context) Nonnull(javax.annotation.Nonnull) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) Unchecked(org.jooq.lambda.Unchecked) Iterator(java.util.Iterator) Cursor(com.torodb.core.cursors.Cursor) Collection(java.util.Collection) EmptyCursor(com.torodb.core.cursors.EmptyCursor) DocPartTableFields(com.torodb.backend.tables.MetaDocPartTable.DocPartTableFields) PreparedStatement(java.sql.PreparedStatement) Collectors(java.util.stream.Collectors) TableRef(com.torodb.core.TableRef) List(java.util.List) MetaField(com.torodb.core.transaction.metainf.MetaField) Stream(java.util.stream.Stream) DocPartResult(com.torodb.core.d2r.DocPartResult) Entry(java.util.Map.Entry) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) MetaField(com.torodb.core.transaction.metainf.MetaField) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Entry(java.util.Map.Entry) Tuple2(org.jooq.lambda.tuple.Tuple2) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) Collection(java.util.Collection) Stream(java.util.stream.Stream) Map(java.util.Map) KvValue(com.torodb.kvdocument.values.KvValue) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 90 with SuppressFBWarnings

use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project torodb by torodb.

the class MvccMetainfoRepository method startSnapshotStage.

@Override
@Nonnull
@SuppressFBWarnings(value = { "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "UL_UNRELEASED_LOCK" })
public SnapshotStage startSnapshotStage() {
    ReadLock readLock = lock.readLock();
    LOGGER.trace("Trying to create a {}", MvccSnapshotStage.class);
    readLock.lock();
    SnapshotStage snapshotStage = null;
    try {
        snapshotStage = new MvccSnapshotStage(readLock);
        LOGGER.trace("{} created", MvccSnapshotStage.class);
    } finally {
        if (snapshotStage == null) {
            LOGGER.error("Error while trying to create a {}", MvccMergerStage.class);
            readLock.unlock();
        }
    }
    assert snapshotStage != null;
    return snapshotStage;
}
Also used : ReadLock(java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock) SnapshotStage(com.torodb.core.transaction.metainf.MetainfoRepository.SnapshotStage) Nonnull(javax.annotation.Nonnull) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)169 ArrayList (java.util.ArrayList)29 PreparedStatement (java.sql.PreparedStatement)27 File (java.io.File)24 IOException (java.io.IOException)24 SQLException (java.sql.SQLException)22 Connection (java.sql.Connection)21 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)21 JPanel (javax.swing.JPanel)14 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)13 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)13 ResultSet (java.sql.ResultSet)12 HashMap (java.util.HashMap)12 Map (java.util.Map)10 FlowLayout (java.awt.FlowLayout)8 BoxLayout (javax.swing.BoxLayout)7 Dimension (java.awt.Dimension)5 FileOutputStream (java.io.FileOutputStream)5 Iterator (java.util.Iterator)5 List (java.util.List)5