Connecting to an embedded OrientDB server in Java - java

I'm looking to run a Java process on several machines, each of which will need to start a local OrientBD server, load a graph, perform our processes, then close. As such, I need to be able to embed the OServer start process from within Java.
There is plenty of advice about how to do so, including SA questions, however most seem to be out of date (so please don't mark this as a duplicate prematurely). The most directly relevant seems to be this, however it doesn't work - at least for me. With the below code, I get the subsequent error:
try {
final OServer server = OServerMain.create();
server.startup(server.getClass().getResourceAsStream("/orientdb-server-config.xml"));
server.activate();
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
2021-12-07 21:47:39:323 INFO Loading configuration from input stream [OServerConfigurationLoaderXml]
2021-12-07 21:47:39:633 INFO OrientDB Server v3.2.3 (build dc98198215aa57baf29b32adb657dc3733acdb55, branch develop) is starting up... [OServer]java.lang.NullPointerException
at com.orientechnologies.orient.core.Orient.onEmbeddedFactoryInit(Orient.java:957)
at com.orientechnologies.orient.core.db.OrientDBEmbedded.<init>(OrientDBEmbedded.java:97)
at com.orientechnologies.orient.core.db.OrientDBInternal.embedded(OrientDBInternal.java:119)
at com.orientechnologies.orient.server.OServer.startupFromConfiguration(OServer.java:388)
at com.orientechnologies.orient.server.OServer.startup(OServer.java:314)
at ems.definitions.instance.Graph.<init>(Graph.java:47)
I am using OrientDB version 3.2.3; the 'ALL' .jar downloaded from here. Note that this jar does not contain the parameters file orientdb-server-config.xml, so I have downloaded it directly from the source GitHub.
Is there an issue with my specific implementation, my approach in general or with the default config file I'm using? I look forward to hearing your thoughts.

The issue was three-fold:
I was using the 'ALL' .jar provided by the website. Instead I needed to use the libraries provided in the full source.
I did not account for the fact that when the code failed, it did not delete the database it half-created, thus could not execute the code I tried to remedy. I had to implement a temporary fail-safe to drop the database prior to initialisation to avoid this.
I was using the wrong(?) strategy in general.
My working method is as below.
orientDB = new OrientDB("embedded:/tmp/","admin","adminpwd", OrientDBConfig.defaultConfig());
/** THIS IS VERY MUCH ONLY FOR LOCAL TESTING **/
if(orientDB.exists(name))
orientDB.drop(name);
if(!orientDB.exists(name)) // if the database does not already exist, create it.
orientDB.execute("create database " + name + " PLOCAL users ( admin identified by 'adminpwd' role admin)");
db = orientDB.open(name, "admin", "adminpwd");

Related

How we can get forest data directory in MarkLogic

I am trying to get the forest Data directory in MarkLogic. I used the following method to get data directory...using the Server Evaluation Call Interface running queries as admin. If not, please let me know how I can get forest data directory
ServerEvaluationCall forestDataDirCall = client.newServerEval()
.xquery("admin:forest-get-data-directory(admin:get-configuration(), admin:forest-get-id(admin:get-configuration(), \"" + forestName +"\"))");
for (EvalResult forestDataDirResult : forestDataDirCall.eval()) {
String forestDataDir = null;
forestDataDir = forestDataDirResult.getString();
System.out.println("forestDataDir is " + forestDataDir);
}
I see no reason for needing to hit the server evaluation endpoint to ask this question to the server. MarkLogic comes with a robust REST based management API including getters for almost all items of interest.
Knowing that, you can use what is documented here:
http://yourserver:8002/manage/v2/forests
Results can be in JSON, XML or HTML
It is the getter for forest configurations. Which forests you care about can be found by iterating over all forests or by reaching through the database config and then to the forests. It all depends on what you already know from the outside.
References:
Management API
Scripting Administrative Tasks

Wikidata Toolkit: Is it possible to access properties of entities?

First of all, I want to clarify that my experience working with wikidata is very limited, so feel free to correct if any of my terminology is wrong.
I've been playing with wikidata toolkit, more specifically their wdtk-wikibaseapi. This allows you to get entity information and their different properties as such:
WikibaseDataFetcher wbdf = WikibaseDataFetcher.getWikidataDataFetcher();
EntityDocument q42 = wbdf.getEntityDocument("Q42");
List<StatementGroup> groups = ((ItemDocument) q42).getStatementGroups();
for(StatementGroup g : groups) {
List<Statement> statements = g.getStatements();
for(Statement s : statements) {
System.out.println(s.getMainSnak().getPropertyId().getId());
System.out.println(s.getValue());
}
}
The above would get me the entity Douglas Adams and all the properties under his site: https://www.wikidata.org/wiki/Q42
Now wikidata toolkit has the ability to load and process dump files, meaning you can download a dump to your local and process it using their DumpProcessingController class under the wdtk-dumpfiles library. I'm just not sure what is meant by processing.
Can anyone explain me what does processing mean in this context?
Can you do something similar to what was done using wdtk-wikibaseapi in the example above but using a local dump file and wdtk-dumpfiles i.e. get an entity and it's respective properties? I don't want to get the info from online source, only from the dump (offline).
If this is not possible using wikidata-toolkit, could you point me to somewhere that can get me started on getting entities and their properties from a dump file for wikidata please? I am using Java.

Java exception error during RJDBC::dbConnect: how to silently ignore?

I am trying to connect to a SAS-driven remote database from within R, using RJDBC. The first time I do a dbConnect, I get an error:
Error in .jcall(drv#jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1],
: java.lang.NoClassDefFoundError: com/sas/net/crypto/CryptoException
When I do the dbConnect a second time after the first call, it connects fine, and I get back an object of class JDBCConnection.
I looked in the sas.core.jar file (from the latest 94M2 SAS JDBC drivers), and can see CryptoException listed in there. However, I am also curious why it was trying to throw a CryptoException.
Question 1: How can I silently ignore the error on the first dbConnect call?
Question 2: Why was it trying to throw a CryptoException? What can I do to prevent this? (This may cancel question 1.)
This is the same question as shared on the SAS Support Communities page:
https://communities.sas.com/thread/80620
There you shared the code you are using
https://github.com/wthielen/wrds/blob/7edfbfe89ddc329618be72e591cc0bd50e294ea4/R/wrds.R#L47
In this code, the problem appears to be that you are trying to set the classpath before initializing the JVM. Using .jinit() before the call to .jaddClassPath should correct the issue. In the doc for .jinit and since you are developing a package, you may want to use .jpackage instead of .jinit
https://www.rforge.net/doc/packages/rJava/jpackage.html
I was having the same problems and tried the above solutions with no change.
The solution on my computer was modifying the .Renviron file which holds the classpath to the java drivers. Replacing "JDBC_Drivers" with "WRDS_Drivers" was all that was needed:
CLASSPATH="C:/Users/nicol/Documents/WRDS_Drivers/sas.core.jar;C:/Users/nicol/Documents/WRDS_Drivers/sas.intrnet.javatools.jar"

Setting the HornetQ Embedded-Remote Example

I am having some troubles setting the example in the hornetq-2.3.0.Final jar under the core folder named Embedded-Remote, I am trying to run the example in a "remote enviroment" using for this two computers in the same LAN, if i run the two classes without changing anything in the same computer "EmbeddedRemotExample.java" runs ok, but as this example lacks configuration files I am not sure about how to set this class to connect to a server running in another computer. reading the api I found that this was a valid code:
`
HashMap map = new HashMap();
map.put("host", "192.168.XXX.XXX");
map.put("port", 5445);
ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(
new TransportConfiguration(NettyConnectorFactory.class.getName(),map));
ClientSessionFactory sf = serverLocator.createSessionFactory();`
but this produces the next exception
HornetQException[errorType=NOT_CONNECTED message=HQ119007: Cannot connect to server(s). Tried with all available servers.]
at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:852)
at org.hornetq.core.example.EmbeddedRemoteExample.main(EmbeddedRemoteExample.java:49)`
How could i set this specific example to work?
in one computer : org.hornetq.core.example.EmbeddedServer
in other one : org.hornetq.core.example.EmbeddedRemoteExample
You need to add the same configuration to the server's Acceptor at EmbeddedServer.java. As by default it would be set to localhost.
I reckon that that example needs a code clean-up:
https://github.com/hornetq/hornetq/pull/1062
This specific commit would make clear what you need to change:
https://github.com/FranciscoBorges/hornetq/commit/fbed7e8394c843e4528df90d4c2ef155a7d032c0

Get table names from lotus notes database

I'm trying to write a program that would dump a whole lotus notes database to a file via NotesSQL driver. I'm connecting via jdbc:odbc and have
I can execute selects and get data from Lotus notes database
here is the code
try {
System.out.print("Connecting... ");
Connection con = DriverManager.getConnection("jdbc:odbc:NRC", "UserName", "Passw0rd1337");
System.out.println("OK");
DatabaseMetaData dmd = con.getMetaData();
String[] tableTypes = new String[] {"TABLE", "VIEW"};
ResultSet rs = dmd.getTables(null, null, "%", tableTypes);
ResultSetMetaData rsd = rs.getMetaData();
while (rs.next()) {
for (int i=1; i<=rsd.getColumnCount();i++)
System.out.println(i+" - "+rsd.getColumnName(i) + " - " + rs.getString(1));
}
con.close();
System.out.println("Connection closed");
} catch (Exception e) {
System.out.println(e);
}
And is there a better way to connect to Lotus notes databases via NotesSQL? Because with my code i get only null values for the names...
I know you are trying to use JDBC and NotesSQL. But, depending on your needs, and using Eclipse, you can access Notes databases natively via Java, which frankly is alot easier than trying to use JDBC, bit of a square peg in a round hole when you're using JDBC with Domino. Even if you don't have Lotus Notes installed on the host machine you can still write and deploy java applets and servlets to get into the data.
You will need to get the relevant Lotus Domino jar's though. So, my recommendation is an alternative approach to JDBC.
So, providing you have the Lotus Domino jar files in your Eclipse project you should be able to code any kind of extract from a view or even run adhoc searches on a database.
Setup
If this sounds like the direction you need to go, then firstly, have a look at setting up Eclipse with relevant Notes jar's here. There are only a few. (Sometimes you'll read about using CORBA and/or IIOP. Try avoid that, it's just a world of hurt).
Samples and snippets
This developer works article (although 6 years old) still works for Domino and is a sound foundation for the approach I am advocating. That article starts to address the initialization of the NotesFactory and Session classes to get you into the Notes API. More online help here for the NotesFactory class.
If you have a Lotus Notes client available you can have a look through code snippets here. A classic example for accessing documents via Views in Java can be found here.
After that you can easily access Views and documents with examples from here, and learn from the guru, (Bob Balaban), about memory management here.
If you're processing high volumes or running servlets, then memory management is important, otherwise don't stress about it too much. You can execute Native searches on a Notes database by writing it in formula, and then using the "search" methods to execute the query natively.
Iterating through documents or views ?
The easiest approach is to traverse documents via views and/or use "getdocumentByKey" methods to get a collection and work on that. In Domino "Views" are the equivalent of Tables. You can also get a list of Views via the Database.Views property
Native Queries
It's difficult to find definitive instructions on native queries for Notes, but I have managed to find it online here.

Categories

Resources