Skip to content

Commit

Permalink
Minor: small fix thanks to findbugs
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Jul 27, 2015
1 parent 5ff2d9c commit 84d8dd2
Show file tree
Hide file tree
Showing 33 changed files with 163 additions and 176 deletions.
Expand Up @@ -319,7 +319,7 @@ public void end() {
db.declareIntent(null); db.declareIntent(null);
db.close(); db.close();
if (walActive) if (walActive)
OGlobalConfiguration.USE_WAL.setValue(walActive); OGlobalConfiguration.USE_WAL.setValue(true);
} }
} }


Expand Down Expand Up @@ -382,7 +382,7 @@ public void setVertexProperties(Long id, Map<String, Object> properties) {
return; return;
} }
settingProperties = true; settingProperties = true;
int cluster = (int) (id % parallel); final int cluster = (int) (id % parallel);
if (nextVerticesToCreate[cluster] <= id) { if (nextVerticesToCreate[cluster] <= id) {
if (oVertexClass == null) { if (oVertexClass == null) {
oVertexClass = db.getMetadata().getSchema().getClass(vertexClass); oVertexClass = db.getMetadata().getSchema().getClass(vertexClass);
Expand All @@ -392,7 +392,7 @@ public void setVertexProperties(Long id, Map<String, Object> properties) {
} }
new BatchImporterJob(cluster, oVertexClass, id).createVertex(db, id, properties); new BatchImporterJob(cluster, oVertexClass, id).createVertex(db, id, properties);
} else { } else {
ODocument doc = (ODocument) db.load(new ORecordId(getClusterId(id), getClusterPosition(id))); final ODocument doc = db.load(new ORecordId(getClusterId(id), getClusterPosition(id)));
if (doc == null) { if (doc == null) {
throw new RuntimeException("trying to insert properties on non existing document"); throw new RuntimeException("trying to insert properties on non existing document");
} }
Expand Down
Expand Up @@ -73,7 +73,7 @@ public class OGraphBatchInsertBasic {
private boolean walActive; private boolean walActive;


private int parallel = 4; private int parallel = 4;
private AtomicInteger runningThreads = new AtomicInteger(0); private AtomicInteger runningThreads;


class BatchImporterJob extends Thread { class BatchImporterJob extends Thread {


Expand Down Expand Up @@ -243,7 +243,7 @@ public void end() {
db.declareIntent(null); db.declareIntent(null);
db.close(); db.close();
if (walActive) if (walActive)
OGlobalConfiguration.USE_WAL.setValue(walActive); OGlobalConfiguration.USE_WAL.setValue(true);
} }
} }


Expand Down
Expand Up @@ -274,7 +274,7 @@ public OGraphMLReader inputGraph(final Graph inputGraph, final InputStream graph


String value = reader.getElementText(); String value = reader.getElementText();


if (inVertex == true) { if (inVertex) {
if ((vertexIdKey != null) && (key.equals(vertexIdKey))) { if ((vertexIdKey != null) && (key.equals(vertexIdKey))) {
// Should occur at most once per Vertex // Should occur at most once per Vertex
vertexId = value; vertexId = value;
Expand All @@ -291,7 +291,7 @@ public OGraphMLReader inputGraph(final Graph inputGraph, final InputStream graph
if (attributeName != null) if (attributeName != null)
vertexProps.put(attributeName, attrValue); vertexProps.put(attributeName, attrValue);
} }
} else if (inEdge == true) { } else if (inEdge) {
if ((edgeLabelKey != null) && (key.equals(edgeLabelKey))) if ((edgeLabelKey != null) && (key.equals(edgeLabelKey)))
edgeLabel = value; edgeLabel = value;
else if ((edgeIdKey != null) && (key.equals(edgeIdKey))) else if ((edgeIdKey != null) && (key.equals(edgeIdKey)))
Expand Down
Expand Up @@ -19,7 +19,6 @@
*/ */
package com.orientechnologies.orient.graph.gremlin; package com.orientechnologies.orient.graph.gremlin;


import com.orientechnologies.common.io.OIOUtils;
import com.orientechnologies.orient.core.command.OCommandRequestTextAbstract; import com.orientechnologies.orient.core.command.OCommandRequestTextAbstract;


/** /**
Expand Down
Expand Up @@ -19,19 +19,6 @@
*/ */
package com.orientechnologies.orient.graph.gremlin; package com.orientechnologies.orient.graph.gremlin;


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Method;
import java.util.*;
import java.util.Map.Entry;

import javax.script.ScriptContext;
import javax.script.ScriptEngine;

import com.orientechnologies.common.concur.resource.OReentrantResourcePool;
import com.orientechnologies.common.concur.resource.OResourcePoolListener;
import com.orientechnologies.common.log.OLogManager; import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.command.OCommandManager; import com.orientechnologies.orient.core.command.OCommandManager;
import com.orientechnologies.orient.core.config.OGlobalConfiguration; import com.orientechnologies.orient.core.config.OGlobalConfiguration;
Expand All @@ -46,23 +33,37 @@
import com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineFactory; import com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineFactory;
import com.tinkerpop.gremlin.java.GremlinPipeline; import com.tinkerpop.gremlin.java.GremlinPipeline;


import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class OGremlinHelper { public class OGremlinHelper {
private static final String PARAM_OUTPUT = "output"; private static final String PARAM_OUTPUT = "output";
private static GremlinGroovyScriptEngineFactory factory = new GremlinGroovyScriptEngineFactory(); private static GremlinGroovyScriptEngineFactory factory = new GremlinGroovyScriptEngineFactory();
private static OGremlinHelper instance = new OGremlinHelper(); private static OGremlinHelper instance = new OGremlinHelper();


private int maxPool = 50; private int maxPool = 50;


private long timeout; public interface OGremlinCallback {

boolean call(ScriptEngine iEngine, OrientBaseGraph iGraph);
public static interface OGremlinCallback {
public boolean call(ScriptEngine iEngine, OrientBaseGraph iGraph);
} }


public OGremlinHelper() { public OGremlinHelper() {
OCommandManager.instance().registerRequester("gremlin", OCommandGremlin.class); OCommandManager.instance().registerRequester("gremlin", OCommandGremlin.class);
OCommandManager.instance().registerExecutor(OCommandGremlin.class, OCommandGremlinExecutor.class); OCommandManager.instance().registerExecutor(OCommandGremlin.class, OCommandGremlinExecutor.class);
timeout = OGlobalConfiguration.STORAGE_LOCK_TIMEOUT.getValueAsLong(); final long timeout = OGlobalConfiguration.STORAGE_LOCK_TIMEOUT.getValueAsLong();
} }


@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Expand Down Expand Up @@ -225,15 +226,14 @@ public static Object cloneObject(final Object objectToClone, final Object previo
return objectToClone; return objectToClone;
// Clone Date // Clone Date
} else if (objectToClone instanceof Date) { } else if (objectToClone instanceof Date) {
Date clonedDate = (Date) ((Date) objectToClone).clone(); return (Date) ((Date) objectToClone).clone();
return clonedDate;


} else { } else {
// *************************************************************************************************************************************** // ***************************************************************************************************************************************
// 2. Polymorphic clone (by reflection, looks for a clone() method in hierarchy and invoke it) // 2. Polymorphic clone (by reflection, looks for a clone() method in hierarchy and invoke it)
// *************************************************************************************************************************************** // ***************************************************************************************************************************************
try { try {
Object newClone = null; Object newClone;
for (Class<?> obj = objectToClone.getClass(); !obj.equals(Object.class); obj = obj.getSuperclass()) { for (Class<?> obj = objectToClone.getClass(); !obj.equals(Object.class); obj = obj.getSuperclass()) {
Method m[] = obj.getDeclaredMethods(); Method m[] = obj.getDeclaredMethods();
for (int i = 0; i < m.length; i++) { for (int i = 0; i < m.length; i++) {
Expand Down
Expand Up @@ -64,7 +64,7 @@ public Object command(final String language, final String iText) {


@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Object command(final String language, final String iText, final Object[] iArgs) { public Object command(final String language, final String iText, final Object[] iArgs) {
Object result = null; Object result;
if (language.equalsIgnoreCase("sql")) if (language.equalsIgnoreCase("sql"))
result = graph.command(new OCommandSQL(iText)).execute(iArgs); result = graph.command(new OCommandSQL(iText)).execute(iArgs);
else if (language.equalsIgnoreCase("gremlin")) else if (language.equalsIgnoreCase("gremlin"))
Expand Down Expand Up @@ -103,22 +103,22 @@ public void rollback() {


public boolean isAutoStartTx() { public boolean isAutoStartTx() {
if (graph instanceof OrientGraph) if (graph instanceof OrientGraph)
return ((OrientGraph) graph).isAutoStartTx(); return graph.isAutoStartTx();


return false; return false;
} }


public void setAutoStartTx(boolean autoStartTx) { public void setAutoStartTx(boolean autoStartTx) {
if (graph instanceof OrientGraph) if (graph instanceof OrientGraph)
((OrientGraph) graph).setAutoStartTx(autoStartTx); graph.setAutoStartTx(autoStartTx);
} }


public void stopTransaction(Conclusion conclusion) { public void stopTransaction(Conclusion conclusion) {
if (graph instanceof OrientGraph) if (graph instanceof OrientGraph)
((OrientGraph) graph).stopTransaction(conclusion); ((OrientGraph) graph).stopTransaction(conclusion);
} }


public boolean equals(Object obj) { public boolean equals(final Object obj) {
return graph.equals(obj); return graph.equals(obj);
} }


Expand Down
Expand Up @@ -84,7 +84,7 @@ else if (language.equals("gremlin")) {
vertices = new ArrayList<OrientVertex>(result.size()); vertices = new ArrayList<OrientVertex>(result.size());


for (Object o : result) { for (Object o : result) {
((ArrayList<OrientVertex>) vertices).add(graph.getVertex((OIdentifiable) o)); ((ArrayList<OrientVertex>) vertices).add(graph.getVertex(o));
} }
} else } else
throw new IllegalArgumentException("Language '" + language + "' is not supported. Use 'sql' or 'gremlin'"); throw new IllegalArgumentException("Language '" + language + "' is not supported. Use 'sql' or 'gremlin'");
Expand Down
Expand Up @@ -43,7 +43,6 @@


import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
Expand Down Expand Up @@ -163,8 +162,7 @@ public List<Object> call(OrientBaseGraph graph) {


if (fields != null) if (fields != null)
// EVALUATE FIELDS // EVALUATE FIELDS
for (Iterator<OPair<String, Object>> it = fields.iterator(); it.hasNext();) { for (final OPair<String, Object> f : fields) {
final OPair<String, Object> f = it.next();
if (f.getValue() instanceof OSQLFunctionRuntime) if (f.getValue() instanceof OSQLFunctionRuntime)
f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(to, null, context)); f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(to, null, context));
} }
Expand Down
Expand Up @@ -125,8 +125,7 @@ public ODocument call(OrientBaseGraph graph) {


if (fields != null) if (fields != null)
// EVALUATE FIELDS // EVALUATE FIELDS
for (Iterator<OPair<String, Object>> it = fields.iterator(); it.hasNext();) { for (final OPair<String, Object> f : fields) {
final OPair<String, Object> f = it.next();
if (f.getValue() instanceof OSQLFunctionRuntime) if (f.getValue() instanceof OSQLFunctionRuntime)
f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(vertex.getRecord(), null, context)); f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(vertex.getRecord(), null, context));
} }
Expand Down
Expand Up @@ -280,7 +280,7 @@ public Object call(OrientBaseGraph graph) {
// ADDITIONAL FILTERING // ADDITIONAL FILTERING
for (Iterator<OrientEdge> it = edges.iterator(); it.hasNext();) { for (Iterator<OrientEdge> it = edges.iterator(); it.hasNext();) {
final OrientEdge edge = it.next(); final OrientEdge edge = it.next();
if (!(Boolean) compiledFilter.evaluate((ODocument) edge.getRecord(), null, context)) if (!(Boolean) compiledFilter.evaluate(edge.getRecord(), null, context))
it.remove(); it.remove();
} }
} }
Expand Down Expand Up @@ -330,7 +330,7 @@ public boolean result(final Object iRecord) {


if (compiledFilter != null) { if (compiledFilter != null) {
// ADDITIONAL FILTERING // ADDITIONAL FILTERING
if (!(Boolean) compiledFilter.evaluate((ODocument) id.getRecord(), null, context)) if (!(Boolean) compiledFilter.evaluate(id.getRecord(), null, context))
return true; return true;
} }


Expand Down
Expand Up @@ -159,7 +159,7 @@ public OCommandExecutorSQLDeleteVertex parse(final OCommandRequest iRequest) {
} }
queryString.append(where); queryString.append(where);
if (limit > -1) { if (limit > -1) {
queryString.append(" LIMIT " + limit); queryString.append(" LIMIT ").append(limit);
} }
query = database.command(new OSQLAsynchQuery<ODocument>(queryString.toString(), this)); query = database.command(new OSQLAsynchQuery<ODocument>(queryString.toString(), this));
} }
Expand Down
Expand Up @@ -41,7 +41,6 @@
import com.tinkerpop.blueprints.impls.orient.OrientVertex; import com.tinkerpop.blueprints.impls.orient.OrientVertex;


import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
Expand Down Expand Up @@ -149,8 +148,7 @@ public Object execute(final Map<Object, Object> iArgs) {


if (fields != null) { if (fields != null) {
// EVALUATE FIELDS // EVALUATE FIELDS
for (Iterator<OPair<String, Object>> it = fields.iterator(); it.hasNext();) { for (final OPair<String, Object> f : fields) {
final OPair<String, Object> f = it.next();
if (f.getValue() instanceof OSQLFunctionRuntime) if (f.getValue() instanceof OSQLFunctionRuntime)
f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(newVertex.getRecord(), null, context)); f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(newVertex.getRecord(), null, context));
} }
Expand Down
Expand Up @@ -19,9 +19,6 @@
*/ */
package com.orientechnologies.orient.graph.sql.functions; package com.orientechnologies.orient.graph.sql.functions;


import java.util.Iterator;
import java.util.LinkedList;

import com.orientechnologies.common.collection.OMultiValue; import com.orientechnologies.common.collection.OMultiValue;
import com.orientechnologies.common.types.OModifiableBoolean; import com.orientechnologies.common.types.OModifiableBoolean;
import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.command.OCommandContext;
Expand All @@ -37,6 +34,9 @@
import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph; import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph;
import com.tinkerpop.blueprints.impls.orient.OrientVertex; import com.tinkerpop.blueprints.impls.orient.OrientVertex;


import java.util.Iterator;
import java.util.LinkedList;

/** /**
* Dijkstra's algorithm describes how to find the cheapest path from one node to another node in a directed weighted graph. * Dijkstra's algorithm describes how to find the cheapest path from one node to another node in a directed weighted graph.
* *
Expand Down Expand Up @@ -64,7 +64,7 @@ public LinkedList<OrientVertex> execute(Object iThis, OIdentifiable iCurrentReco
final OrientBaseGraph graph = OGraphCommandExecutorSQLFactory.getGraph(false, shutdownFlag); final OrientBaseGraph graph = OGraphCommandExecutorSQLFactory.getGraph(false, shutdownFlag);
try { try {


final ORecord record = (ORecord) (iCurrentRecord != null ? iCurrentRecord.getRecord() : null); final ORecord record = iCurrentRecord != null ? iCurrentRecord.getRecord() : null;


Object source = iParams[0]; Object source = iParams[0];
if (OMultiValue.isMultiValue(source)) { if (OMultiValue.isMultiValue(source)) {
Expand Down
Expand Up @@ -70,9 +70,6 @@ public Object execute(Object iThis, final OIdentifiable iCurrentRecord, Object i


@Override @Override
public boolean call(ScriptEngine iEngine, OrientBaseGraph iGraph) { public boolean call(ScriptEngine iEngine, OrientBaseGraph iGraph) {
if (iCurrentRecord == null || !(iCurrentRecord instanceof ODocument))
return false;

final ODocument document = (ODocument) iCurrentRecord; final ODocument document = (ODocument) iCurrentRecord;
OClass clazz =ODocumentInternal.getImmutableSchemaClass(document); OClass clazz =ODocumentInternal.getImmutableSchemaClass(document);
if (clazz != null && clazz.isSubClassOf(OrientEdgeType.CLASS_NAME)) { if (clazz != null && clazz.isSubClassOf(OrientEdgeType.CLASS_NAME)) {
Expand Down
Expand Up @@ -34,9 +34,7 @@
import com.orientechnologies.orient.graph.sql.OGraphCommandExecutorSQLFactory; import com.orientechnologies.orient.graph.sql.OGraphCommandExecutorSQLFactory;
import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph; import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph;
import com.tinkerpop.blueprints.impls.orient.OrientEdge; import com.tinkerpop.blueprints.impls.orient.OrientEdge;
import com.tinkerpop.blueprints.impls.orient.OrientEdgeType;
import com.tinkerpop.blueprints.impls.orient.OrientVertex; import com.tinkerpop.blueprints.impls.orient.OrientVertex;
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;


/** /**
* Hi-level function that return the label for both edges and vertices. The label could be bound to the class name. * Hi-level function that return the label for both edges and vertices. The label could be bound to the class name.
Expand Down
Expand Up @@ -136,8 +136,7 @@ protected Object e2v(final OrientBaseGraph graph, final OIdentifiable iRecord, f
result.add(edge.getVertex(Direction.IN)); result.add(edge.getVertex(Direction.IN));
return result; return result;
} else { } else {
final OrientVertex out = (OrientVertex) edge.getVertex(iDirection); return edge.getVertex(iDirection);
return out;
} }
} }
} }
Expand Down
Expand Up @@ -43,7 +43,6 @@
import com.orientechnologies.orient.core.index.OIndexManager; import com.orientechnologies.orient.core.index.OIndexManager;
import com.orientechnologies.orient.core.index.OPropertyIndexDefinition; import com.orientechnologies.orient.core.index.OPropertyIndexDefinition;
import com.orientechnologies.orient.core.intent.OIntent; import com.orientechnologies.orient.core.intent.OIntent;
import com.orientechnologies.orient.core.metadata.OMetadataInternal;
import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OImmutableClass; import com.orientechnologies.orient.core.metadata.schema.OImmutableClass;
import com.orientechnologies.orient.core.metadata.schema.OProperty; import com.orientechnologies.orient.core.metadata.schema.OProperty;
Expand Down Expand Up @@ -836,7 +835,7 @@ public Iterable<Vertex> getVertices(final String iKey, Object iValue) {
final String className = iKey.substring(0, pos); final String className = iKey.substring(0, pos);
key = iKey.substring(iKey.indexOf('.') + 1); key = iKey.substring(iKey.indexOf('.') + 1);


final OClass clazz = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass(className); final OClass clazz = database.getMetadata().getImmutableSchemaSnapshot().getClass(className);


final Collection<? extends OIndex<?>> indexes = clazz.getIndexes(); final Collection<? extends OIndex<?>> indexes = clazz.getIndexes();
for (OIndex<?> index : indexes) { for (OIndex<?> index : indexes) {
Expand Down Expand Up @@ -1613,7 +1612,7 @@ public <T extends Element> Set<String> getIndexedKeys(final Class<T> elementClas
if (elementClass == null) if (elementClass == null)
throw ExceptionFactory.classForElementCannotBeNull(); throw ExceptionFactory.classForElementCannotBeNull();


final OSchema schema = ((OMetadataInternal) getRawGraph().getMetadata()).getImmutableSchemaSnapshot(); final OSchema schema = getRawGraph().getMetadata().getImmutableSchemaSnapshot();
final String elementOClassName = getClassName(elementClass); final String elementOClassName = getClassName(elementClass);


Set<String> result = new HashSet<String>(); Set<String> result = new HashSet<String>();
Expand Down
Expand Up @@ -34,7 +34,10 @@
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInput; import java.io.ObjectInput;
import java.io.ObjectOutput; import java.io.ObjectOutput;
import java.util.*; import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;


/** /**
* OrientDB Edge implementation of TinkerPop Blueprints standard. Edges can be classic or lightweight. Lightweight edges have no * OrientDB Edge implementation of TinkerPop Blueprints standard. Edges can be classic or lightweight. Lightweight edges have no
Expand Down Expand Up @@ -227,7 +230,6 @@ public OIdentifiable getInVertex() {
*/ */
@Override @Override
public String getLabel() { public String getLabel() {
final OrientBaseGraph graph = getGraph();
if (label != null) if (label != null)
// LIGHTWEIGHT EDGE // LIGHTWEIGHT EDGE
return label; return label;
Expand All @@ -241,7 +243,7 @@ else if (rawElement != null) {


setCurrentGraphInThreadLocal(); setCurrentGraphInThreadLocal();


final ODocument doc = (ODocument) rawElement.getRecord(); final ODocument doc = rawElement.getRecord();
if (doc == null) if (doc == null)
return null; return null;


Expand All @@ -256,7 +258,7 @@ else if (rawElement != null) {
public boolean equals(final Object object) { public boolean equals(final Object object) {
if (rawElement == null && object instanceof OrientEdge) { if (rawElement == null && object instanceof OrientEdge) {
final OrientEdge other = (OrientEdge) object; final OrientEdge other = (OrientEdge) object;
return vOut.equals(other.vOut) && vIn.equals(other.vIn) && ((label == other.label) || (label != null && label.equals(other.label))); return vOut.equals(other.vOut) && vIn.equals(other.vIn) && (label != null && label.equals(other.label));
} }
return super.equals(object); return super.equals(object);
} }
Expand All @@ -266,7 +268,6 @@ public boolean equals(final Object object) {
*/ */
@Override @Override
public Object getId() { public Object getId() {
final OrientBaseGraph graph = getGraph();
if (rawElement == null) if (rawElement == null)
// CREATE A TEMPORARY ID // CREATE A TEMPORARY ID
return vOut.getIdentity() + "->" + vIn.getIdentity(); return vOut.getIdentity() + "->" + vIn.getIdentity();
Expand Down

0 comments on commit 84d8dd2

Please sign in to comment.