writing a DB connector plugin

Asked by Alex H

I have a JDBC/ODBC settings and I would like to know what step next to write a plugin in gephi to be able to pull out data from my DB.

What I've done so far is to add the DBDriver as a dependency of the module, but I don't know what to proceed next.

Please guide me through this

Question information

Language:
English Edit question
Status:
Expired
For:
Gephi Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Mathieu Bastian (mathieu.bastian) said :
#1

1. Create a new 'Library Wrapper' module with your JDBC JAR. In Netbeans, right click on the Gephi project, and module, and 'Add new Library'. Follow the steps to create a module. The module is embedding your JDBC JARs.

2. Add DBDrivers as a dependency of this module, as well as Lookup

3. Add a new class that implements SQLDriver interface.

4. Add this annotation to your class. That will register your driver, and make it available in the list on the 'Import Database' panel.
@ServiceProvider(service=SQLDriver.class)
public class MyDriver implements SQLDriver...

5. Now, your Driver is registered and can be used with the current 'Import Database' panel in Gephi. If you want to create your own importer, follow the steps on the importer HowTo (http://wiki.gephi.org/index.php/HowTo_write_an_import) but using Database instead of File.

Revision history for this message
Alex H (aditya15417) said :
#2

Some of the confusion that arise from your answer:

1. So I need to have a JDBC JAR in order to do this? What is inside this JAR?
2. I am assuming that I need to implement the two methods from SQLDriver, which are getPrefix() and getConnection(), what are these two methods supposed to do?

Revision history for this message
Mathieu Bastian (mathieu.bastian) said :
#3

I though you mentioned you have a JDBC Driver, like Oracle for instance, and need to add the library. What is the database you are trying to connect?

Revision history for this message
Alex H (aditya15417) said :
#4

Sorry, I might have to rephrase my previous question. I actually have the JDBC jar, I am just confused on how to embed that as a part of the module.

What code do I need to write in the new class that implements SQLDriver?

Revision history for this message
Mathieu Bastian (mathieu.bastian) said :
#5

Following my previous answer you might have the module with the JAR. The SQLDriver implementation are basically almost the same as others (e.g. MySQL). The prefix should be what is in the JDBC URL.

@ServiceProvider(service=SQLDriver.class)
public class NewDriver implements SQLDriver {

    public Connection getConnection(String connectionUrl, String username, String passwd) throws SQLException {
        return DriverManager.getConnection(connectionUrl, username, passwd);
    }

    @Override
    public String getPrefix() {
        return "newdriver";
    }

    @Override
    public String toString() {
        return "New Driver";
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof MySQLDriver) {
            return ((NewDriver) obj).getPrefix().equals(getPrefix());
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return getPrefix().hashCode();
    }
}

Revision history for this message
Mathieu Bastian (mathieu.bastian) said :
#6

EDIT:
if (obj instanceof MySQLDriver) ==> if (obj instanceof NewDriver)

Revision history for this message
Alex H (aditya15417) said :
#7

Ok, so with all of these then we can have a plugin.. but how do we pull out the nodes and edges? Is that then an importer?

Revision history for this message
Mathieu Bastian (mathieu.bastian) said :
#8

Yes, that is an Importer. But once you have done the Driver, you can already test queries with it using the 'Import Database' panel in Gephi.

Revision history for this message
Alex H (aditya15417) said :
#9

So all I need is just one class above?

Revision history for this message
Launchpad Janitor (janitor) said :
#10

This question was expired because it remained in the 'Open' state without activity for the last 15 days.