Skip to content

Commit

Permalink
Clean up warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
soklakov committed Jan 12, 2016
1 parent 53f91cc commit 3a6c3ff
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
15 changes: 8 additions & 7 deletions src/com/mysql/fabric/Response.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/J is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
Expand Down Expand Up @@ -36,9 +36,10 @@ public class Response {
private String fabricUuid;
private int ttl;
private String errorMessage;
private List<Map> resultSet;
private List<Map<String, ?>> resultSet;

public Response(List responseData) throws FabricCommunicationException {
@SuppressWarnings("unchecked")
public Response(List<?> responseData) throws FabricCommunicationException {
// parser of protocol version 1 as defined by WL#7760
this.protocolVersion = (Integer) responseData.get(0);
if (this.protocolVersion != 1) {
Expand All @@ -50,10 +51,10 @@ public Response(List responseData) throws FabricCommunicationException {
if ("".equals(this.errorMessage)) {
this.errorMessage = null;
}
List resultSets = (List) responseData.get(4);
List<Map<String, ?>> resultSets = (List<Map<String, ?>>) responseData.get(4);
if (resultSets.size() > 0) {
Map<String, ?> resultData = (Map<String, ?>) resultSets.get(0);
this.resultSet = new ResultSetParser().parse((Map) resultData.get("info"), (List<List>) resultData.get("rows"));
Map<String, ?> resultData = resultSets.get(0);
this.resultSet = new ResultSetParser().parse((Map<String, ?>) resultData.get("info"), (List<List<Object>>) resultData.get("rows"));
}
}

Expand All @@ -73,7 +74,7 @@ public String getErrorMessage() {
return this.errorMessage;
}

public List<Map> getResultSet() {
public List<Map<String, ?>> getResultSet() {
return this.resultSet;
}
}
9 changes: 5 additions & 4 deletions src/com/mysql/fabric/proto/xmlrpc/ResultSetParser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/J is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
Expand Down Expand Up @@ -39,15 +39,16 @@ public ResultSetParser() {
* Transform the Fabric formatted result into a list of
* hashes/rows.
*/
public List<Map> parse(Map info, List<List> rows) {
public List<Map<String, ?>> parse(Map<String, ?> info, List<List<Object>> rows) {
@SuppressWarnings("unchecked")
List<String> fieldNames = (List<String>) info.get("names");
Map<String, Integer> fieldNameIndexes = new HashMap<String, Integer>();
for (int i = 0; i < fieldNames.size(); ++i) {
fieldNameIndexes.put(fieldNames.get(i), i);
}

List<Map> result = new ArrayList<Map>(rows.size());
for (List r : rows) {
List<Map<String, ?>> result = new ArrayList<Map<String, ?>>(rows.size());
for (List<Object> r : rows) {
Map<String, Object> resultRow = new HashMap<String, Object>();
for (Map.Entry<String, Integer> f : fieldNameIndexes.entrySet()) {
resultRow.put(f.getKey(), r.get(f.getValue()));
Expand Down
20 changes: 10 additions & 10 deletions src/com/mysql/fabric/proto/xmlrpc/XmlRpcClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/J is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
Expand Down Expand Up @@ -98,7 +98,7 @@ public XmlRpcClient(String url, String username, String password) throws FabricC
/**
* Unmarshall a response representing a server.
*/
private static Server unmarshallServer(Map serverData) throws FabricCommunicationException {
private static Server unmarshallServer(Map<String, ?> serverData) throws FabricCommunicationException {
ServerMode mode;
ServerRole role;

Expand Down Expand Up @@ -131,9 +131,9 @@ private static Server unmarshallServer(Map serverData) throws FabricCommunicatio
/**
* Convert a list of string/string/bool to Server objects.
*/
private static Set<Server> toServerSet(List<Map> l) throws FabricCommunicationException {
private static Set<Server> toServerSet(List<Map<String, ?>> l) throws FabricCommunicationException {
Set<Server> servers = new HashSet<Server>();
for (Map serverData : l) {
for (Map<String, ?> serverData : l) {
servers.add(unmarshallServer(serverData));
}
return servers;
Expand All @@ -160,7 +160,7 @@ private Response errorSafeCallMethod(String methodName, Object args[]) throws Fa
public Set<String> getFabricNames() throws FabricCommunicationException {
Response resp = errorSafeCallMethod(METHOD_DUMP_FABRIC_NODES, new Object[] {});
Set<String> names = new HashSet<String>();
for (Map node : resp.getResultSet()) {
for (Map<String, ?> node : resp.getResultSet()) {
names.add(node.get(FIELD_HOST) + ":" + node.get(FIELD_PORT));
}
return names;
Expand All @@ -171,7 +171,7 @@ public Set<String> getFabricNames() throws FabricCommunicationException {
*/
public Set<String> getGroupNames() throws FabricCommunicationException {
Set<String> groupNames = new HashSet<String>();
for (Map row : errorSafeCallMethod(METHOD_GROUP_LOOKUP_GROUPS, null).getResultSet()) {
for (Map<String, ?> row : errorSafeCallMethod(METHOD_GROUP_LOOKUP_GROUPS, null).getResultSet()) {
groupNames.add((String) row.get(FIELD_GROUP_ID));
}
return groupNames;
Expand All @@ -198,7 +198,7 @@ public FabricStateResponse<Set<ServerGroup>> getServerGroups(String groupPattern
Response response = errorSafeCallMethod(METHOD_DUMP_SERVERS, new Object[] { version, groupPattern });
// collect all servers by group name
Map<String, Set<Server>> serversByGroupName = new HashMap<String, Set<Server>>();
for (Map server : response.getResultSet()) {
for (Map<String, ?> server : response.getResultSet()) {
Server s = unmarshallServer(server);
if (serversByGroupName.get(s.getGroupName()) == null) {
serversByGroupName.put(s.getGroupName(), new HashSet<Server>());
Expand All @@ -224,7 +224,7 @@ private FabricStateResponse<Set<ShardTable>> getShardTables(int shardMappingId)
Response tablesResponse = errorSafeCallMethod(METHOD_DUMP_SHARD_TABLES, args);
Set<ShardTable> tables = new HashSet<ShardTable>();
// construct the tables
for (Map rawTable : tablesResponse.getResultSet()) {
for (Map<String, ?> rawTable : tablesResponse.getResultSet()) {
String database = (String) rawTable.get(FIELD_SCHEMA_NAME);
String table = (String) rawTable.get(FIELD_TABLE_NAME);
String column = (String) rawTable.get(FIELD_COLUMN_NAME);
Expand All @@ -241,7 +241,7 @@ private FabricStateResponse<Set<ShardIndex>> getShardIndices(int shardMappingId)
Set<ShardIndex> indices = new HashSet<ShardIndex>();

// construct the index
for (Map rawIndexEntry : indexResponse.getResultSet()) {
for (Map<String, ?> rawIndexEntry : indexResponse.getResultSet()) {
String bound = (String) rawIndexEntry.get(FIELD_LOWER_BOUND);
int shardId = (Integer) rawIndexEntry.get(FIELD_SHARD_ID);
String groupName = (String) rawIndexEntry.get(FIELD_GROUP_ID);
Expand All @@ -267,7 +267,7 @@ public FabricStateResponse<Set<ShardMapping>> getShardMappings(String shardMappi

// construct the maps
Set<ShardMapping> mappings = new HashSet<ShardMapping>();
for (Map rawMapping : mapsResponse.getResultSet()) {
for (Map<String, ?> rawMapping : mapsResponse.getResultSet()) {
int mappingId = (Integer) rawMapping.get(FIELD_MAPPING_ID);
ShardingType shardingType = ShardingType.valueOf((String) rawMapping.get(FIELD_TYPE_NAME));
String globalGroupName = (String) rawMapping.get(FIELD_GLOBAL_GROUP_ID);
Expand Down
25 changes: 15 additions & 10 deletions src/testsuite/fabric/TestResultSetParser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/J is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
Expand Down Expand Up @@ -28,10 +28,10 @@
import java.util.List;
import java.util.Map;

import junit.framework.TestCase;

import com.mysql.fabric.proto.xmlrpc.ResultSetParser;

import junit.framework.TestCase;

/**
* Tests for Fabric XML-RPC ResultSetParser.
*/
Expand All @@ -44,29 +44,34 @@ public class TestResultSetParser extends TestCase {
// [07eee140-d466-11e3-abdf-dfb2de41aa92, fabric_test1_shard1, 127.0.0.1, 3402, 1, 2, 1.0]],
// info={names=[server_uuid, group_id, host, port, mode, status, weight]}}
// ]]
List<Map> exampleServersResultSet;
List<Map<String, ?>> exampleServersResultSet;

public TestResultSetParser(String name) {
super(name);
}

@SuppressWarnings("unchecked")
@Override
public void setUp() throws Exception {
final Map columns = new HashMap() {
final Map<String, ?> columns = new HashMap<String, List<String>>() {
private static final long serialVersionUID = 1L;

{
put("names", Arrays.asList(new String[] { "server_uuid", "group_id", "host", "port", "mode", "status", "weight" }));
}
};
final List row1 = Arrays.asList(new Object[] { "5e26a7ab-de84-11e2-a885-df73a3d95316", "fabric_test1_global", "127.0.0.1", 3401, 3, 3, 1.0 });
final List row2 = Arrays.asList(new Object[] { "07eee140-d466-11e3-abdf-dfb2de41aa92", "fabric_test1_shard1", "127.0.0.1", 3402, 1, 2, 1.0 });
final List rows = Arrays.asList(new List[] { row1, row2 });
Map resultData = new HashMap() {
final List<?> row1 = Arrays.asList(new Object[] { "5e26a7ab-de84-11e2-a885-df73a3d95316", "fabric_test1_global", "127.0.0.1", 3401, 3, 3, 1.0 });
final List<?> row2 = Arrays.asList(new Object[] { "07eee140-d466-11e3-abdf-dfb2de41aa92", "fabric_test1_shard1", "127.0.0.1", 3402, 1, 2, 1.0 });
final List<?> rows = Arrays.asList(new List[] { row1, row2 });
Map<String, ?> resultData = new HashMap<String, Object>() {
private static final long serialVersionUID = 1L;

{
put("info", columns);
put("rows", rows);
}
};
this.exampleServersResultSet = new ResultSetParser().parse((Map) resultData.get("info"), (List<List>) resultData.get("rows"));
this.exampleServersResultSet = new ResultSetParser().parse((Map<String, ?>) resultData.get("info"), (List<List<Object>>) resultData.get("rows"));
}

public void testExampleData() throws Exception {
Expand Down

0 comments on commit 3a6c3ff

Please sign in to comment.