summaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-07-01 13:43:04 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-07-01 13:51:23 +0200
commitef3e590d1ba5372d825216f85816463fa8e50a99 (patch)
treed43b93223e5440c3f4d8582eae406ff9863cc8a5 /sonar-core
parentcbe3819ae9e045049816761ff598ae5e74eac2e2 (diff)
downloadsonarqube-ef3e590d1ba5372d825216f85816463fa8e50a99.tar.gz
sonarqube-ef3e590d1ba5372d825216f85816463fa8e50a99.zip
Fix some quality flaws
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java56
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/BatchSession.java41
2 files changed, 49 insertions, 48 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java b/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java
index f529267ab80..fae97eca964 100644
--- a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java
+++ b/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java
@@ -77,12 +77,12 @@ class GraphsonUtil {
* A GraphSONUtility that includes the specified properties.
*/
GraphsonUtil(GraphsonMode mode, ElementFactory factory,
- Set<String> vertexPropertyKeys, Set<String> edgePropertyKeys) {
+ Set<String> vertexPropertyKeys, Set<String> edgePropertyKeys) {
this(mode, factory, ElementPropertyConfig.includeProperties(vertexPropertyKeys, edgePropertyKeys));
}
GraphsonUtil(GraphsonMode mode, ElementFactory factory,
- ElementPropertyConfig config) {
+ ElementPropertyConfig config) {
this.vertexPropertyKeys = config.getVertexPropertyKeys();
this.edgePropertyKeys = config.getEdgePropertyKeys();
this.vertexPropertiesRule = config.getVertexPropertiesRule();
@@ -110,7 +110,7 @@ class GraphsonUtil {
*/
static JSONObject jsonFromElement(Element element, @Nullable Set<String> propertyKeys, GraphsonMode mode) {
GraphsonUtil graphson = element instanceof Edge ? new GraphsonUtil(mode, null, null, propertyKeys)
- : new GraphsonUtil(mode, null, propertyKeys, null);
+ : new GraphsonUtil(mode, null, propertyKeys, null);
return graphson.jsonFromElement(element);
}
@@ -123,7 +123,7 @@ class GraphsonUtil {
* @param propertyKeys a list of keys to include on reading of element properties
*/
static Vertex vertexFromJson(JSONObject json, ElementFactory factory, GraphsonMode mode,
- Set<String> propertyKeys) throws IOException {
+ Set<String> propertyKeys) throws IOException {
GraphsonUtil graphson = new GraphsonUtil(mode, factory, propertyKeys, null);
return graphson.vertexFromJson(json);
}
@@ -137,7 +137,7 @@ class GraphsonUtil {
* @param propertyKeys a list of keys to include on reading of element properties
*/
static Vertex vertexFromJson(String json, ElementFactory factory, GraphsonMode mode,
- Set<String> propertyKeys) throws ParseException {
+ Set<String> propertyKeys) throws ParseException {
GraphsonUtil graphson = new GraphsonUtil(mode, factory, propertyKeys, null);
return graphson.vertexFromJson(json);
}
@@ -151,39 +151,35 @@ class GraphsonUtil {
* @param propertyKeys a list of keys to include on reading of element properties
*/
static Vertex vertexFromJson(InputStream json, ElementFactory factory, GraphsonMode mode,
- Set<String> propertyKeys) throws IOException, ParseException {
+ Set<String> propertyKeys) throws IOException, ParseException {
GraphsonUtil graphson = new GraphsonUtil(mode, factory, propertyKeys, null);
return graphson.vertexFromJson(json);
}
private static boolean includeReservedKey(GraphsonMode mode, String key,
- Set<String> propertyKeys,
- ElementPropertiesRule rule) {
- // the key is always included in modes other than compact. if it is compact, then validate that the
+ Set<String> propertyKeys,
+ ElementPropertiesRule rule) {
+ // the key is always included in modes other than compact. if it is compact, then validate that the
// key is in the property key list
return mode != GraphsonMode.COMPACT || includeKey(key, propertyKeys, rule);
}
private static boolean includeKey(String key, Set<String> propertyKeys,
- ElementPropertiesRule rule) {
+ ElementPropertiesRule rule) {
if (propertyKeys == null) {
// when null always include the key and shortcut this piece
return true;
}
- // default the key situation. if it's included then it should be explicitly defined in the
+ // default the key situation. if it's included then it should be explicitly defined in the
// property keys list to be included or the reverse otherwise
boolean keySituation = rule == ElementPropertiesRule.INCLUDE;
- switch (rule) {
- case INCLUDE:
- keySituation = propertyKeys.contains(key);
- break;
- case EXCLUDE:
- keySituation = !propertyKeys.contains(key);
- break;
+ if (rule == ElementPropertiesRule.INCLUDE) {
+ keySituation = propertyKeys.contains(key);
+ } else if (rule == ElementPropertiesRule.EXCLUDE) {
+ keySituation = !propertyKeys.contains(key);
}
-
return keySituation;
}
@@ -196,8 +192,8 @@ class GraphsonUtil {
* @param propertyKeys a list of keys to include when reading of element properties
*/
static Edge edgeFromJson(String json, Vertex out, Vertex in,
- ElementFactory factory, GraphsonMode mode,
- Set<String> propertyKeys) throws IOException, ParseException {
+ ElementFactory factory, GraphsonMode mode,
+ Set<String> propertyKeys) throws IOException, ParseException {
GraphsonUtil graphson = new GraphsonUtil(mode, factory, null, propertyKeys);
return graphson.edgeFromJson(json, out, in);
}
@@ -211,8 +207,8 @@ class GraphsonUtil {
* @param propertyKeys a list of keys to include when reading of element properties
*/
static Edge edgeFromJson(InputStream json, Vertex out, Vertex in,
- ElementFactory factory, GraphsonMode mode,
- Set<String> propertyKeys) throws IOException, ParseException {
+ ElementFactory factory, GraphsonMode mode,
+ Set<String> propertyKeys) throws IOException, ParseException {
GraphsonUtil graphson = new GraphsonUtil(mode, factory, null, propertyKeys);
return graphson.edgeFromJson(json, out, in);
}
@@ -226,8 +222,8 @@ class GraphsonUtil {
* @param propertyKeys a list of keys to include when reading of element properties
*/
static Edge edgeFromJson(JSONObject json, Vertex out, Vertex in,
- ElementFactory factory, GraphsonMode mode,
- Set<String> propertyKeys) throws IOException {
+ ElementFactory factory, GraphsonMode mode,
+ Set<String> propertyKeys) throws IOException {
GraphsonUtil graphson = new GraphsonUtil(mode, factory, null, propertyKeys);
return graphson.edgeFromJson(json, out, in);
}
@@ -249,7 +245,7 @@ class GraphsonUtil {
private static boolean isReservedKey(String key) {
return key.equals(GraphsonTokens._ID) || key.equals(GraphsonTokens._TYPE) || key.equals(GraphsonTokens._LABEL)
- || key.equals(GraphsonTokens._OUT_V) || key.equals(GraphsonTokens._IN_V);
+ || key.equals(GraphsonTokens._OUT_V) || key.equals(GraphsonTokens._IN_V);
}
private static JSONArray createJSONList(List list, Set<String> propertyKeys, boolean showTypes) {
@@ -285,7 +281,7 @@ class GraphsonUtil {
value = createJSONMap((Map) value, propertyKeys, showTypes);
} else if (value instanceof Element) {
value = jsonFromElement((Element) value, propertyKeys,
- showTypes ? GraphsonMode.EXTENDED : GraphsonMode.NORMAL);
+ showTypes ? GraphsonMode.EXTENDED : GraphsonMode.NORMAL);
} else if (value.getClass().isArray()) {
value = createJSONList(convertArrayToList(value), propertyKeys, showTypes);
}
@@ -466,7 +462,7 @@ class GraphsonUtil {
} else if (type.equals(GraphsonTokens.TYPE_MAP)) {
- // maps are converted to a ObjectNode. called recursively to traverse
+ // maps are converted to a ObjectNode. called recursively to traverse
// the entire object graph within the map.
JSONObject convertedMap = new JSONObject();
JSONObject jsonObject = (JSONObject) value;
@@ -482,7 +478,7 @@ class GraphsonUtil {
} else {
- // this must be a primitive value or a complex object. if a complex
+ // this must be a primitive value or a complex object. if a complex
// object it will be handled by a call to toString and stored as a
// string value
putObject(valueAndType, GraphsonTokens.VALUE, value);
@@ -637,7 +633,7 @@ class GraphsonUtil {
putObject(jsonElement, GraphsonTokens._ID, element.getId());
}
- // it's important to keep the order of these straight. check Edge first and then Vertex because there
+ // it's important to keep the order of these straight. check Edge first and then Vertex because there
// are graph implementations that have Edge extend from Vertex
if (element instanceof Edge) {
Edge edge = (Edge) element;
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/BatchSession.java b/sonar-core/src/main/java/org/sonar/core/persistence/BatchSession.java
index a12942e13a9..d7f3d8255bd 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/BatchSession.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/BatchSession.java
@@ -29,7 +29,6 @@ import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.sonar.core.cluster.WorkQueue;
-import java.sql.Connection;
import java.util.List;
import java.util.Map;
@@ -40,7 +39,6 @@ public class BatchSession extends DbSession {
private final int batchSize;
private int count = 0;
-
BatchSession(WorkQueue queue, SqlSession session) {
this(queue, session, MAX_BATCH_SIZE);
}
@@ -50,67 +48,80 @@ public class BatchSession extends DbSession {
this.batchSize = batchSize;
}
+ @Override
public void select(String statement, Object parameter, ResultHandler handler) {
reset();
super.select(statement, parameter, handler);
}
+ @Override
public void select(String statement, ResultHandler handler) {
reset();
super.select(statement, handler);
}
+ @Override
public <T> T selectOne(String statement) {
reset();
return (T) super.selectOne(statement);
}
+ @Override
public <T> T selectOne(String statement, Object parameter) {
reset();
return (T) super.selectOne(statement, parameter);
}
+ @Override
public <E> List<E> selectList(String statement) {
reset();
return super.selectList(statement);
}
+ @Override
public <E> List<E> selectList(String statement, Object parameter) {
reset();
return super.selectList(statement, parameter);
}
+ @Override
public <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds) {
reset();
return super.selectList(statement, parameter, rowBounds);
}
+ @Override
public <K, V> Map<K, V> selectMap(String statement, String mapKey) {
reset();
return super.selectMap(statement, mapKey);
}
+ @Override
public <K, V> Map<K, V> selectMap(String statement, Object parameter, String mapKey) {
reset();
return super.selectMap(statement, parameter, mapKey);
}
+ @Override
public <K, V> Map<K, V> selectMap(String statement, Object parameter, String mapKey, RowBounds rowBounds) {
reset();
return super.selectMap(statement, parameter, mapKey, rowBounds);
}
+ @Override
public void select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler) {
reset();
super.select(statement, parameter, rowBounds, handler);
}
+ @Override
public int insert(String statement) {
makeSureGeneratedKeysAreNotUsedInBatchInserts(statement);
increment();
return super.insert(statement);
}
+ @Override
public int insert(String statement, Object parameter) {
makeSureGeneratedKeysAreNotUsedInBatchInserts(statement);
increment();
@@ -130,72 +141,66 @@ public class BatchSession extends DbSession {
}
}
+ @Override
public int update(String statement) {
increment();
return super.update(statement);
}
+ @Override
public int update(String statement, Object parameter) {
increment();
return super.update(statement, parameter);
}
+ @Override
public int delete(String statement) {
increment();
return super.delete(statement);
}
+ @Override
public int delete(String statement, Object parameter) {
increment();
return super.delete(statement, parameter);
}
+ @Override
public void commit() {
super.commit();
reset();
}
+ @Override
public void commit(boolean force) {
super.commit(force);
reset();
}
+ @Override
public void rollback() {
super.rollback();
reset();
}
+ @Override
public void rollback(boolean force) {
super.rollback(force);
reset();
}
+ @Override
public List<BatchResult> flushStatements() {
List<BatchResult> batchResults = super.flushStatements();
reset();
return batchResults;
}
- public void close() {
- super.close();
- }
-
- public void clearCache() {
- super.clearCache();
- }
-
- public Configuration getConfiguration() {
- return super.getConfiguration();
- }
-
+ @Override
public <T> T getMapper(Class<T> type) {
return getConfiguration().getMapper(type, this);
}
- public Connection getConnection() {
- return super.getConnection();
- }
-
private BatchSession increment() {
count += 1;
if (count >= batchSize) {