com.sparsity.dex.io
Class TypeLoader

java.lang.Object
  extended by com.sparsity.dex.io.TypeLoader
Direct Known Subclasses:
EdgeTypeLoader, NodeTypeLoader

public class TypeLoader
extends java.lang.Object

Base TypeLoader class.

Base class to load a node or edge type from a graph using a RowReader.

TypeLoaderListener can be registered to receive information about the progress of the load process by means of TypeLoaderEvent.

The default frequency of notification to listeners is 100000.

Timestamp formats accepted by default (see ScriptParser):

"yyyy-MM-dd hh:mm:ss.SSS"

"yyyy-MM-dd hh:mm:ss"

"yyyy-MM-dd"

Author:
Sparsity Technologies http://www.sparsity-technologies.com

Method Summary
 void register(TypeLoaderListener tel)
          Registers a new listener.
 void run()
          Run the loader.
 void runNPhases(int partitions)
          Run the loader for N phases loading.
 void runTwoPhases()
          Run the loader for two phases loading.
 void setAttributePositions(Int32List attrsPos)
          Sets the list of attribute positions.
 void setAttributes(AttributeList attrs)
          Sets the list of Attributes.
 void setFrequency(int freq)
          Sets the frequency of listener notification.
 void setGraph(Graph g)
          Sets the graph where the data will be loaded.
 void setLocale(java.lang.String localeStr)
          Sets the locale that will be used to read the data.
 void setLogError(java.lang.String path)
          Sets a log error file.
 void setLogOff()
          Truns off all the error reporting.
 void setRowReader(RowReader rr)
          Sets the input data source.
 void setTimestampFormat(java.lang.String timestampFormat)
          Sets a specific timestamp format.
 void setType(int t)
          Sets the type to be loaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

runTwoPhases

public void runTwoPhases()
                  throws java.io.IOException,
                         java.lang.RuntimeException
Run the loader for two phases loading.

Firstly load all objects (and create them if necessary) and secondly loads all the attributes.

Working on this mode it is necessary to build a temporary file.

Throws:
java.io.IOException - null
java.lang.RuntimeException - null

setLogOff

public void setLogOff()
Truns off all the error reporting.

The log file will not be created and no exceptions for invalid data will be thrown. If you just want to turn off the logs, but abort at the first error what you should do is not call this method and not set a logError file.


run

public void run()
         throws java.io.IOException,
                java.lang.RuntimeException
Run the loader.

Throws:
java.io.IOException - null
java.lang.RuntimeException - null

setLogError

public void setLogError(java.lang.String path)
                 throws java.io.IOException
Sets a log error file.

By default errors are thrown as a exception and the load process ends. If a log file is set, errors are logged there and the load process does not stop.

Parameters:
path - null
Throws:
java.io.IOException - If bad things happen opening the file.

setAttributes

public void setAttributes(AttributeList attrs)
Sets the list of Attributes.

Parameters:
attrs - [in] Attribute identifiers to be loaded

setRowReader

public void setRowReader(RowReader rr)
Sets the input data source.

Parameters:
rr - [in] Input RowReader.

register

public void register(TypeLoaderListener tel)
Registers a new listener.

Parameters:
tel - TypeLoaderListener to be registered.

setLocale

public void setLocale(java.lang.String localeStr)
Sets the locale that will be used to read the data.

It should match the locale used in the rowreader.

Parameters:
localeStr - [in] The locale string for the read data. See CSVReader.

setAttributePositions

public void setAttributePositions(Int32List attrsPos)
Sets the list of attribute positions.

attrsPos [in] Attribute positions (column index >=0).

Parameters:
attrsPos - null

runNPhases

public void runNPhases(int partitions)
                throws java.io.IOException,
                       java.lang.RuntimeException
Run the loader for N phases loading.

Firstly load all objects (and create them if necessary) and secondly loads all the attributes. But in this case, attributes are loaded one by one. This way, if there are three attributes, then 4 traverses are necessary.

Working on this mode it is necessary to build a temporary file.

Parameters:
partitions - [in] Number of horizontal partitions to perform the load.
Throws:
java.io.IOException - null
java.lang.RuntimeException - null

setFrequency

public void setFrequency(int freq)
Sets the frequency of listener notification.

freq [in] Frequency in number of rows managed to notify progress to all listeners

Parameters:
freq - null

setGraph

public void setGraph(Graph g)
Sets the graph where the data will be loaded.

Parameters:
g - [in] Graph.

setTimestampFormat

public void setTimestampFormat(java.lang.String timestampFormat)
Sets a specific timestamp format.

Parameters:
timestampFormat - null

setType

public void setType(int t)
Sets the type to be loaded.

Parameters:
t - [in] Type identifier.