Package edu.upc.dama.dex.io

Provides funcionality to load DEX node or edge types from relational databases or CSV files as data sources as well as utilities to dump data.

See:
          Description

Interface Summary
ExporterListener Interface to receive events from a Exporter.
LoaderListener Interface to receive events from a Loader.
RowReader Common interface for those readers which get the data as String [].
RowWriter Common interface for those writers which store the data as String [].
 

Class Summary
CSVReader A very simple CSV reader.
CSVWriter A very simple CSV writer.
EdgeTypeExporter Exporter implementation for edge types.
EdgeTypeLoader Loader implementation for edge types.
Exporter Export data of node or edge type.
JDBCReader A very simple JDBC reader.
Loader Loads data in a node or edge type.
Loader.Mode Load can work in different ways.
NodeTypeExporter Exporter implementation for node types.
NodeTypeLoader Loader implementation for node types.
 

Package edu.upc.dama.dex.io Description

Provides funcionality to load DEX node or edge types from relational databases or CSV files as data sources as well as utilities to dump data. Specifically, this package contains the following classes:

Example

We can suppose there is a table with the following schema:
            TABLE_NAME {
              ID (INT),
              ATTR1 (Integer),
              ATTR2 (String)
            }
        
In this sample, we can create a NodeTypeLoader using a JDBCReader. The reader allows for retrieving all the data as rows and the loader allows for storing these rows into a DEX node or edge type. We referee the user to the documentation of these classes to learn in deep how to use them. Following code example shows how to load a DEX node type with data from the given relational table:
            
            public static void main(String[] args) throws IOException {
                /*
                 * DEX graph
                 */
                DEX dex = new DEX();
                GraphPool gp = dex.create("image.dex");
                Session sess = gp.newSession();
                DbGraph dbgraph = sess.getDbGraph();
                /*
                 * Create node type and attributes
                 */
                int nodeType = dbgraph.newNodeType("NAME");
                long attr1 = dbgraph.newAttribute(nodeType, "ATTR1", Value.INT);
                long attr2 = dbgraph.newAttribute(nodeType, "ATTR2", Value.STRING);
                /*
                 * Create the JDBC reader using the MySQL sample database 
                 */
                RowReader rr = new JDBCReader("com.mysql.jdbc.Driver", 
                            "jdbc:mysql://localhost/sample", 
                            "SELECT * FROM `TABLE_NAME`");
                /*
                 * Create a new loader listener to receive events
                 */ 
                LoaderListener ll = new NodeTypeListener();
                /*
                 * Create a new loader 
                 */
                NodeTypeLoader ntl = new NodeTypeLoader(rr, dbgraph, nodeType);
                /*
                 * Assign the two columns (attributes) to the loader
                 */
                ntl.setAttribute(attr1, 1);
                ntl.setAttribute(attr2, 2);
                /*
                 * Register the loader listener to the loader
                 */
                ntl.registerLoaderListener(ll);
                /*
                 * Start the loader
                 */
                ntl.run(NodeTypeLoader.Mode.TWO_PHASES, 1);
                /*
                 * Close DEX
                 */
                sess.close();
                gp.close();
                dex.close();
            }
        
NodeTypeListener
Implementation of the listener used in this example. This listener writes a line to the standard output with the total time of the execution.
         public class NodeTypeListener implements LoaderListener {

            public NodeTypeListener()
            {    
            }

            public void loadProgress(ListenerEvent le) {
                System.out.println("Node type listener called! Objects loaded: " + le.objects);
            }
         }