Search in sources :

Example 81 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)

Example 82 with SuppressFBWarnings

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

the class SnapshotMerger method merge.

@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
private void merge(MetaDatabase oldDb, MutableMetaCollection newCol, ImmutableMetaCollection oldCol, MetaDocPart newStructure, ImmutableMetaDocPart oldStructure, ImmutableMetaDocPart.Builder parentBuilder, ImmutableMetaIdentifiedDocPartIndex changed, MetaElementState newState) throws UnmergeableException {
    ImmutableMetaIdentifiedDocPartIndex byId = oldStructure.getMetaDocPartIndexByIdentifier(changed.getIdentifier());
    ImmutableMetaIdentifiedDocPartIndex bySameColumns = oldStructure.streamIndexes().filter(oldDocPartIndex -> oldDocPartIndex.hasSameColumns(changed)).findAny().orElse(null);
    switch(newState) {
        default:
        case NOT_CHANGED:
        case NOT_EXISTENT:
            throw new AssertionError("A modification was expected, but the new state is " + newState);
        case ADDED:
        case MODIFIED:
            {
                Optional<? extends MetaIndex> anyRelatedIndex = newCol.getAnyRelatedIndex(oldCol, newStructure, changed);
                if (!anyRelatedIndex.isPresent()) {
                    throw createUnmergeableExceptionForOrphan(oldDb, oldCol, oldStructure, changed);
                }
                if (byId == null) {
                    parentBuilder.put(changed);
                    return;
                }
                assert byId != null;
                ImmutableMetaIdentifiedDocPartIndex.Builder childBuilder = new ImmutableMetaIdentifiedDocPartIndex.Builder(byId);
                Iterator<ImmutableMetaDocPartIndexColumn> indexColumnIterator = changed.iteratorColumns();
                while (indexColumnIterator.hasNext()) {
                    ImmutableMetaDocPartIndexColumn indexColumn = indexColumnIterator.next();
                    merge(oldDb, oldCol, oldStructure, byId, childBuilder, indexColumn);
                }
                parentBuilder.put(childBuilder);
                break;
            }
        case REMOVED:
            {
                Optional<? extends MetaIndex> oldMissedIndex = newCol.getAnyMissedIndex(oldCol, changed);
                if (oldMissedIndex.isPresent()) {
                    throw createUnmergeableExceptionForMissing(oldDb, oldCol, oldStructure, changed, oldMissedIndex.get());
                }
                if (byId == null || bySameColumns == null) {
                    /*
           * it has been removed on another transaction or created and removed on the current one.
           * No change must be done
           */
                    return;
                }
                assert byId != null;
                assert bySameColumns != null;
                /*
         * In this case, we can delegate on the backend transaction check. If it thinks everything
         * is fine, we can remove the element. If it thinks there is an error, then we have to
         * rollback the transaction.
         */
                parentBuilder.remove(byId);
            }
    }
}
Also used : MutableMetaIndex(com.torodb.core.transaction.metainf.MutableMetaIndex) MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) ImmutableMetaIndex(com.torodb.core.transaction.metainf.ImmutableMetaIndex) ImmutableMetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.ImmutableMetaIdentifiedDocPartIndex) Optional(java.util.Optional) Iterator(java.util.Iterator) ImmutableMetaDocPartIndexColumn(com.torodb.core.transaction.metainf.ImmutableMetaDocPartIndexColumn) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 83 with SuppressFBWarnings

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

the class FilterListDeserializer method deserialize.

@Override
@SuppressFBWarnings("REC_CATCH_EXCEPTION")
public FilterList deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    FilterList filterList = new FilterList();
    JsonNode node = jp.getCodec().readTree(jp);
    if (node instanceof ObjectNode) {
        Iterator<Entry<String, JsonNode>> databaseEntriesIterator = node.fields();
        while (databaseEntriesIterator.hasNext()) {
            Entry<String, JsonNode> databaseEntry = databaseEntriesIterator.next();
            try {
                Map<String, List<IndexFilter>> collections = new HashMap<>();
                if (databaseEntry.getValue() instanceof ObjectNode) {
                    readCollectionObject(jp, (ObjectNode) databaseEntry.getValue(), collections);
                } else if (databaseEntry.getValue() instanceof ArrayNode) {
                    ArrayNode collectionsArray = (ArrayNode) databaseEntry.getValue();
                    Iterator<JsonNode> collectionsIterator = collectionsArray.elements();
                    int position = 0;
                    while (collectionsIterator.hasNext()) {
                        try {
                            JsonNode collection = collectionsIterator.next();
                            if (collection instanceof ObjectNode) {
                                readCollectionObject(jp, (ObjectNode) collection, collections);
                            } else if (collection instanceof ArrayNode) {
                                throw new JsonMappingException("wrong filter format: collection value inside " + "database array can not be an array", jp.getCurrentLocation());
                            } else {
                                collections.put(collection.asText(), new ArrayList<>());
                            }
                            position++;
                        } catch (Exception e) {
                            throw JsonMappingException.wrapWithPath(e, collections, position);
                        }
                    }
                }
                filterList.put(databaseEntry.getKey(), collections);
            } catch (Exception e) {
                throw JsonMappingException.wrapWithPath(e, filterList, databaseEntry.getKey());
            }
        }
    } else {
        throw new JsonMappingException("wrong filter format: filter list was not an object", jp.getCurrentLocation());
    }
    return filterList;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) FilterList(com.torodb.packaging.config.model.protocol.mongo.FilterList) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Entry(java.util.Map.Entry) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) FilterList(com.torodb.packaging.config.model.protocol.mongo.FilterList) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 84 with SuppressFBWarnings

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

the class FilterListDeserializer method readCollectionObject.

@SuppressFBWarnings("REC_CATCH_EXCEPTION")
private void readCollectionObject(JsonParser jp, ObjectNode collection, Map<String, List<IndexFilter>> collections) throws JsonProcessingException, JsonMappingException {
    Iterator<Entry<String, JsonNode>> collectionEntriesIterator = collection.fields();
    while (collectionEntriesIterator.hasNext()) {
        List<IndexFilter> indexFilters = new ArrayList<>();
        Map.Entry<String, JsonNode> collectionEntry = collectionEntriesIterator.next();
        try {
            if (collectionEntry.getValue() instanceof ObjectNode) {
                readIndexFilter(jp, collectionEntry.getValue(), indexFilters);
            } else if (collectionEntry.getValue() instanceof ArrayNode) {
                Iterator<JsonNode> indexFiltersIterator = collectionEntry.getValue().elements();
                int position = 0;
                while (indexFiltersIterator.hasNext()) {
                    try {
                        JsonNode indexFilter = indexFiltersIterator.next();
                        if (indexFilter instanceof ObjectNode) {
                            readIndexFilter(jp, indexFilter, indexFilters);
                        } else {
                            throw new JsonMappingException("wrong filter format: index filter should be an " + "object", jp.getCurrentLocation());
                        }
                        position++;
                    } catch (Exception e) {
                        throw JsonMappingException.wrapWithPath(e, indexFilters, position);
                    }
                }
            }
            collections.put(collectionEntry.getKey(), indexFilters);
        } catch (Exception e) {
            throw JsonMappingException.wrapWithPath(e, collections, collectionEntry.getKey());
        }
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Entry(java.util.Map.Entry) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Iterator(java.util.Iterator) IndexFilter(com.torodb.packaging.config.model.protocol.mongo.FilterList.IndexFilter) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HashMap(java.util.HashMap) Map(java.util.Map) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 85 with SuppressFBWarnings

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

the class AbstractSchemaUpdater method executeSql.

@SuppressFBWarnings(value = "UI_INHERITANCE_UNSAFE_GETRESOURCE", justification = "We want to read resources from the subclass")
protected void executeSql(DSLContext dsl, String resourcePath, SqlHelper sqlHelper) {
    try (InputStream resourceAsStream = getClass().getResourceAsStream(resourcePath)) {
        if (resourceAsStream == null) {
            throw new SystemException("Resource '" + resourcePath + "' does not exist");
        }
        String statementAsString = CharStreams.toString(new BufferedReader(new InputStreamReader(resourceAsStream, Charset.forName("UTF-8"))));
        sqlHelper.executeStatement(dsl, statementAsString, Context.UNKNOWN);
    } catch (IOException ex) {
        throw new ToroRuntimeException(ex);
    }
}
Also used : ToroRuntimeException(com.torodb.core.exceptions.ToroRuntimeException) SystemException(com.torodb.core.exceptions.SystemException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)142 IOException (java.io.IOException)23 File (java.io.File)22 ArrayList (java.util.ArrayList)20 JPanel (javax.swing.JPanel)14 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)13 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)13 FlowLayout (java.awt.FlowLayout)8 BoxLayout (javax.swing.BoxLayout)7 Location (jmri.jmrit.operations.locations.Location)7 Dimension (java.awt.Dimension)5 FileOutputStream (java.io.FileOutputStream)5 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 Iterator (java.util.Iterator)5 JScrollPane (javax.swing.JScrollPane)5 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)4 Entry (java.util.Map.Entry)4