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;
}
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);
}
}
}
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;
}
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());
}
}
}
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);
}
}
Aggregations