servicenow.community.sql
Class TableWriter

java.lang.Object
  extended by servicenow.community.sql.TableWriter

public class TableWriter
extends java.lang.Object

Used to read or write to a table in an SQL database. The SQL table is maps to a table in a ServiceNow instance. The glidetable property is the ServiceNow table.

Author:
LewisGF

Constructor Summary
TableWriter(DatabaseWriter dbwriter, GlideTable glidetable, java.lang.String sqlTableName, Metrics metrics)
           
 
Method Summary
 void commit()
           
 void createTable()
          Create a table in the target database.
 boolean deleteRecord(GlideKey key)
           
 java.lang.String generateCreateTable()
           
 java.lang.String generateInsert()
           
 java.lang.String generateUpdate()
           
 Metrics getMetrics()
           
 GlideDateTime getTimestamp(GlideKey key)
          Get sys_updated_on from the SQL table so that we can compare it with the Glide Record to determine if the SQL table needs to be updated.
 int processRecordSet(GlideRecordList data, LoadMethod method)
           
 void setMetrics(Metrics metrics)
           
 java.lang.String sqlFieldDefinition(GlideFieldDefinition fd)
           
 SqlGenerator sqlGenerator()
           
 boolean tableExists()
          Determine if a table already exists in the target database.
 void truncateTable()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableWriter

public TableWriter(DatabaseWriter dbwriter,
                   GlideTable glidetable,
                   java.lang.String sqlTableName,
                   Metrics metrics)
            throws java.sql.SQLException,
                   PumperException,
                   java.io.IOException,
                   org.jdom2.JDOMException
Throws:
java.sql.SQLException
PumperException
java.io.IOException
org.jdom2.JDOMException
Method Detail

setMetrics

public void setMetrics(Metrics metrics)

getMetrics

public Metrics getMetrics()

sqlGenerator

public SqlGenerator sqlGenerator()

truncateTable

public void truncateTable()
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

generateInsert

public java.lang.String generateInsert()
                                throws java.sql.SQLException
Throws:
java.sql.SQLException

generateUpdate

public java.lang.String generateUpdate()
                                throws java.sql.SQLException
Throws:
java.sql.SQLException

getTimestamp

public GlideDateTime getTimestamp(GlideKey key)
                           throws java.sql.SQLException,
                                  java.text.ParseException
Get sys_updated_on from the SQL table so that we can compare it with the Glide Record to determine if the SQL table needs to be updated.

Parameters:
key - sys_id of record to be retrieved from SQL table
Returns:
sys_updated_on from the SQL table
Throws:
java.sql.SQLException
java.text.ParseException

deleteRecord

public boolean deleteRecord(GlideKey key)
                     throws java.sql.SQLException
Throws:
java.sql.SQLException

processRecordSet

public int processRecordSet(GlideRecordList data,
                            LoadMethod method)
                     throws java.text.ParseException,
                            java.io.IOException,
                            org.jdom2.JDOMException,
                            java.sql.SQLException
Throws:
java.text.ParseException
java.io.IOException
org.jdom2.JDOMException
java.sql.SQLException

commit

public void commit()
            throws java.sql.SQLException
Throws:
java.sql.SQLException

tableExists

public boolean tableExists()
                    throws java.sql.SQLException
Determine if a table already exists in the target database.

Returns:
true if table exists; otherwise false
Throws:
java.sql.SQLException

sqlFieldDefinition

public java.lang.String sqlFieldDefinition(GlideFieldDefinition fd)

generateCreateTable

public java.lang.String generateCreateTable()
                                     throws java.sql.SQLException,
                                            java.io.IOException,
                                            org.jdom2.JDOMException
Throws:
java.sql.SQLException
java.io.IOException
org.jdom2.JDOMException

createTable

public void createTable()
                 throws java.sql.SQLException,
                        java.io.IOException,
                        org.jdom2.JDOMException
Create a table in the target database.

Throws:
java.sql.SQLException
java.io.IOException
org.jdom2.JDOMException