[英]How do I use the Titan API?
I would like to configure Titan Db using the API. 我想使用API配置Titan Db。 I have created a Groovy script like so... 我已经创建了一个类似这样的Groovy脚本...
import static com.thinkaurelius.titan.core
Then on the command line... 然后在命令行上...
bin/groovy -cp "/Users/Ian/titan/lib/:titan-core-0.5.0.jar" "../webstormprojects/project1/titan.groovy"
Then... 然后...
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: /Users/Ian/WebstormProjects/project1/titan.groovy: 1: unable to resolve class com.thinkaurelius.titan @ line 1, column 1. import static com.thinkaurelius.titan.core ^ org.codehaus.groovy.control.MultipleCompilationErrorsException:启动失败:/Users/Ian/WebstormProjects/project1/titan.groovy:1:无法解析类com.thinkaurelius.titan @第1行,第1列。导入静态com.thinkaurelius。 titan.core ^
1 error 1个错误
What am I doing wrong? 我究竟做错了什么?
I never use the titan
api, however looking at titan-core source on github the com.thinkaurelius.titan.core
it's not a class, it's a package, so if you want to import all the classes in that package you have to use .*
, also the static
modifier imports the static
members of the classes so if you want to use the classes not only the static
members do: 我从来没有使用titan
API,但是在看着泰坦核心源的github的com.thinkaurelius.titan.core
它不是一类,它是一个包,所以如果你想要导入该包中你必须使用所有类.*
,而且static
修饰符还会导入类的static
成员,因此,如果要使用这些类,不仅static
成员会这样做:
import com.thinkaurelius.titan.core.*
Instead of: 代替:
import static com.thinkaurelius.titan.core
Alternatively if you want to import a specific class in this package, add it to the import, for example if you want to add Titan
class: 另外,如果您想在此程序包中导入特定的类,请将其添加到导入中,例如,如果要添加Titan
类:
import com.thinkaurelius.titan.core.Titan
For more information about static
modifier you can take a look at this answer . 有关static
修饰符的更多信息,请查看此答案 。
Hope this helps, 希望这可以帮助,
For any one as clueless as me this is what I have done: 对于像我这样一无所知的人,我所做的就是:
1) Download Groovy 2) Create a text file. 1)下载Groovy 2)创建一个文本文件。 For example... 例如...
import com.thinkaurelius.titan.core.*
import com.thinkaurelius.titan.core.titan.*
TitanGraph graph = TitanFactory.open("/Users/Ian/titan/conf/titan-cassandra-es.properties");
m = graph.getManagementSystem()
m.commit()
graph.shutdown()
You can see I have some class references to the API and I've connected to the database using the config file that was installed with the Titan distribution I downloaded from the website. 您可以看到我对API有一些类引用,并且已经使用从网站上下载的Titan发行版中安装的配置文件连接到数据库。
You need the graph.shutdown()
else the console blocks. 您需要graph.shutdown()
否则控制台会阻塞。 Although the documentation makes it sound like this shuts down the entire database. 尽管文档听起来像这样,但是会关闭整个数据库。 But it only seems to close the connection. 但这似乎只是关闭了连接。
3) From the command line... 3)从命令行...
bin/groovy -cp "../titan/lib/*" "../webstormprojects/myproject/titan.groovy"
The class path is set to the lib
folder in my Titan instillation folder. 类路径设置为我的Titan灌输文件夹中的lib
文件夹。 The *
includes all the packages. *
包括所有软件包。
And now hopefully I'm all set to add some indexes. 现在希望我都准备添加一些索引。 Be aware that the Titan API has been through some significant changes so some of the online info is out of date. 请注意,Titan API已进行了一些重大更改,因此某些在线信息已过时。 This is quite helpful. 这很有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.