我正在尝试加载使用 TinkerGraph.FileType.GRAPHML 类型保存的 tinkerpop 数据库。
这是我的代码:
public Graph getDatabase(String path) {
org.apache.commons.configuration.Configuration conf = new BaseConfiguration();
conf.setProperty("blueprints.tg.directory", path);
conf.setProperty("blueprints.tg.file-type", "GRAPHML");
conf.setProperty("blueprints.graph", "com.tinkerpop.blueprints.impls.tg.TinkerGraph");
return GraphFactory.open(conf);
}
这段代码给了我一个 java.lang.RuntimeException:GraphFactory 无法实例化这个 Graph 实现 [com.tinkerpop.blueprints.impls.tg.TinkerGraph]。
原因是数字格式异常
Caused by: java.lang.NumberFormatException: For input string: "2306416072"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:495)
at java.lang.Integer.valueOf(Integer.java:582)
at com.tinkerpop.blueprints.util.io.graphml.GraphMLReader.typeCastValue(GraphMLReader.java:313)
at com.tinkerpop.blueprints.util.io.graphml.GraphMLReader.inputGraph(GraphMLReader.java:252)
at com.tinkerpop.blueprints.util.io.graphml.GraphMLReader.inputGraph(GraphMLReader.java:116)
at com.tinkerpop.blueprints.impls.tg.TinkerStorageFactory$GraphMLTinkerStorage.loadGraphData(TinkerStorageFactory.java:187)
at com.tinkerpop.blueprints.impls.tg.TinkerStorageFactory$AbstractSeparateTinkerStorage.load(TinkerStorageFactory.java:94)
at com.tinkerpop.blueprints.impls.tg.TinkerGraph.init(TinkerGraph.java:134)
... 51 more
我在 xml 文件(数据库)中搜索了“2306416072”。这是一个属性 id <-data key="user_id"->2306416072</-/data->
不知道为什么我会收到数字格式异常。我在类 GraphMLReader 中导航,这就是方法
private static Object typeCastValue(String key, String value, Map<String, String> keyTypes) {
String type = keyTypes.get(key);
if (null == type || type.equals(GraphMLTokens.STRING))
return value;
else if (type.equals(GraphMLTokens.FLOAT))
return Float.valueOf(value);
else if (type.equals(GraphMLTokens.INT))
return Integer.valueOf(value);
else if (type.equals(GraphMLTokens.DOUBLE))
return Double.valueOf(value);
else if (type.equals(GraphMLTokens.BOOLEAN))
return Boolean.valueOf(value);
else if (type.equals(GraphMLTokens.LONG))
return Long.valueOf(value);
else
return value;
}