com.partnersoft.modules.inspection.sql
Class SqlInspectionStore

java.lang.Object
  extended by com.partnersoft.modules.inspection.sql.SqlInspectionStore
All Implemented Interfaces:
InspectionStore

public class SqlInspectionStore
extends java.lang.Object
implements InspectionStore


Constructor Summary
SqlInspectionStore(com.partnersoft.system.Module module, InspectionKit kit, com.partnersoft.sql.DatabaseConnectionConfig database, com.partnersoft.cog.CogSchema schema, java.lang.String inspectionType)
           
 
Method Summary
 void addIndexing()
           
 void buildTables()
          Creates the Admin table and inspection table.
 int checkOutJobs(InspectionStore centralStore, java.lang.String user)
          Checks out only records with assigned_to values == user name or uses where clause returned by preCheckout script.
 int checkOutJobsWithQuery(InspectionStore centralStore, java.lang.String whereClause)
          Checks out only records with assigned_to values == user name.
 void connect()
           
 boolean databaseExists()
          Checks if the database this store has configuration for exists.
 void disconnect()
           
 java.lang.String getBlobTableName()
           
 com.partnersoft.sql.DatabaseConnection getConnection()
           
 com.partnersoft.sql.DatabaseConnectionConfig getDatabase()
           
 java.lang.String getFieldTableName()
           
 java.lang.String getInspectionTableName()
           
 java.lang.String getInspectionType()
           
 java.lang.String getName()
           
 java.lang.String getPicklistTableName()
           
 java.lang.String getPublishingTableName()
           
 java.lang.String getSyncTableName()
           
 com.partnersoft.data.DateAndTime lastSynchronizationWith(java.lang.String storeName)
           
 void matchDatabaseToSchema(java.lang.String tableName)
          Changes database to match schema.
 com.partnersoft.io.DataRecordSource query(java.lang.String sql)
          Queries this store using the passed String as an SQL statement
 com.partnersoft.io.DataRecordSource query(java.lang.String sql, int fetchSize)
          Queries this store using the passed String as an SQL statement Uses a streaming result set.
 com.partnersoft.io.DataRecordSource queryBlobs()
          Return record source for all Blobs in this store.
 com.partnersoft.io.DataRecordSource queryBlobs(int fetchSize)
          Return record source for all Blobs in this store.
 com.partnersoft.io.DataRecordSource queryBlobs(java.lang.String whereClause)
          Queries this store using the passed String as an SQL where clause.
 com.partnersoft.io.DataRecordSource queryBlobs(java.lang.String whereClause, int fetchSize)
          Queries this store using the passed String as an SQL where clause.
 com.partnersoft.io.DataRecordSource queryInspections()
          Return record source for all inspections in this store.
 com.partnersoft.io.DataRecordSource queryInspections(int fetchSize)
          Return record source for all inspections in this store.
 com.partnersoft.io.DataRecordSource queryInspections(java.lang.String whereClause)
          Queries this store using the passed String as an SQL where clause.
 com.partnersoft.io.DataRecordSource queryInspections(java.lang.String whereClause, int fetchSize)
          Queries this store using the passed String as an SQL where clause.
 void removeIndexing()
           
 void removeInspection(java.lang.String guid)
           
 Inspection retrieveInspection(java.lang.String guid)
          Return the stored inspection with this guid.
 void storeInspection(Inspection inspection)
          Stores inspection in the store.
 int synchronize(InspectionStore centralStore)
          Does a single synchronize.
 com.partnersoft.data.Naming<java.lang.Object> synchronizeWithAllRecords(InspectionStore centralStore)
          Uploads all modified content, clears local inspection and blob databases, then downloads all inspections and blobs.
 com.partnersoft.data.Naming<java.lang.Object> synchronizeWithCheckOut(InspectionStore centralStore)
          Updates all modified records on central store, and downloads all records from central store with module_assigned_to.
 void updateInspection(java.lang.String guid, com.partnersoft.data.Naming<java.lang.Object> data)
           
 void updateInspection(java.lang.String guid, java.lang.Object... data)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlInspectionStore

public SqlInspectionStore(com.partnersoft.system.Module module,
                          InspectionKit kit,
                          com.partnersoft.sql.DatabaseConnectionConfig database,
                          com.partnersoft.cog.CogSchema schema,
                          java.lang.String inspectionType)
Method Detail

databaseExists

public boolean databaseExists()
Checks if the database this store has configuration for exists. Returns false if database is null, database.getPath() == "", or the database.getPath()+".data" file doesn't exist. TODO make this work for hub database... no path value

Specified by:
databaseExists in interface InspectionStore
Returns:

matchDatabaseToSchema

public void matchDatabaseToSchema(java.lang.String tableName)
Changes database to match schema. Adds new columns, changes column types, but does not delete columns if schema is missing them. Schema meaning the values in fields.csv plus the standard fields.

Specified by:
matchDatabaseToSchema in interface InspectionStore
Parameters:
tableName - - Name of table to look at.

connect

public void connect()
             throws java.sql.SQLException
Specified by:
connect in interface InspectionStore
Throws:
java.sql.SQLException

disconnect

public void disconnect()
                throws java.sql.SQLException
Specified by:
disconnect in interface InspectionStore
Throws:
java.sql.SQLException

getInspectionType

public java.lang.String getInspectionType()
Specified by:
getInspectionType in interface InspectionStore

getName

public java.lang.String getName()
Specified by:
getName in interface InspectionStore

lastSynchronizationWith

public com.partnersoft.data.DateAndTime lastSynchronizationWith(java.lang.String storeName)
                                                         throws java.io.IOException,
                                                                java.sql.SQLException
Specified by:
lastSynchronizationWith in interface InspectionStore
Throws:
java.io.IOException
java.sql.SQLException

removeInspection

public void removeInspection(java.lang.String guid)
                      throws java.io.IOException,
                             java.sql.SQLException
Specified by:
removeInspection in interface InspectionStore
Throws:
java.io.IOException
java.sql.SQLException

retrieveInspection

public Inspection retrieveInspection(java.lang.String guid)
                              throws java.io.IOException,
                                     java.sql.SQLException
Description copied from interface: InspectionStore
Return the stored inspection with this guid.

Specified by:
retrieveInspection in interface InspectionStore
Returns:
Throws:
java.io.IOException
java.sql.SQLException

removeIndexing

public void removeIndexing()

addIndexing

public void addIndexing()

storeInspection

public void storeInspection(Inspection inspection)
                     throws java.io.IOException,
                            java.sql.SQLException
Stores inspection in the store.

Specified by:
storeInspection in interface InspectionStore
Throws:
java.io.IOException
java.sql.SQLException

checkOutJobsWithQuery

public int checkOutJobsWithQuery(InspectionStore centralStore,
                                 java.lang.String whereClause)
                          throws java.io.IOException,
                                 java.sql.SQLException
Description copied from interface: InspectionStore
Checks out only records with assigned_to values == user name. Returns number of records downloaded.

Where clause is appended to SQL of format 'Select * from '

Specified by:
checkOutJobsWithQuery in interface InspectionStore
Parameters:
centralStore - - hub database.
whereClause - - SQL where clause to execute.
Returns:
Throws:
java.io.IOException
java.sql.SQLException

checkOutJobs

public int checkOutJobs(InspectionStore centralStore,
                        java.lang.String user)
                 throws java.io.IOException,
                        java.sql.SQLException
Description copied from interface: InspectionStore
Checks out only records with assigned_to values == user name or uses where clause returned by preCheckout script. Returns number of records downloaded.

Specified by:
checkOutJobs in interface InspectionStore
Returns:
Throws:
java.io.IOException
java.sql.SQLException

synchronizeWithCheckOut

public com.partnersoft.data.Naming<java.lang.Object> synchronizeWithCheckOut(InspectionStore centralStore)
                                                                      throws java.io.IOException,
                                                                             java.sql.SQLException
Description copied from interface: InspectionStore
Updates all modified records on central store, and downloads all records from central store with module_assigned_to. Matching the user name stored in preferences. Returns naming of details.

Specified by:
synchronizeWithCheckOut in interface InspectionStore
Parameters:
centralStore - - Store to move updated records to.
Returns:
- The synch details.
Throws:
java.io.IOException
java.sql.SQLException

synchronizeWithAllRecords

public com.partnersoft.data.Naming<java.lang.Object> synchronizeWithAllRecords(InspectionStore centralStore)
                                                                        throws java.io.IOException,
                                                                               java.sql.SQLException
Uploads all modified content, clears local inspection and blob databases, then downloads all inspections and blobs. Stores a synchronization record on centralStore.

Specified by:
synchronizeWithAllRecords in interface InspectionStore
Parameters:
centralStore - - the InspectionStore to synchronize with and download all inspections from.
Returns:
a Naming containing the sync record. Stores a guid, hub_address, user_address, created_at, upload_count, and download_count.
Throws:
java.io.IOException
java.sql.SQLException

synchronize

public int synchronize(InspectionStore centralStore)
                throws java.io.IOException,
                       java.sql.SQLException
Does a single synchronize. Clears local database, but doesn't pull any inspections down. Stores a sync record for transaction.

Specified by:
synchronize in interface InspectionStore
Parameters:
centralStore - - InspectionStore to synch to.
Returns:
int count of inspections uploaded.
Throws:
java.io.IOException
java.sql.SQLException

buildTables

public void buildTables()
                 throws java.sql.SQLException
Description copied from interface: InspectionStore
Creates the Admin table and inspection table.

Specified by:
buildTables in interface InspectionStore
Throws:
java.sql.SQLException

queryInspections

public com.partnersoft.io.DataRecordSource queryInspections()
                                                     throws java.sql.SQLException
Description copied from interface: InspectionStore
Return record source for all inspections in this store.

Specified by:
queryInspections in interface InspectionStore
Returns:
Throws:
java.sql.SQLException

queryInspections

public com.partnersoft.io.DataRecordSource queryInspections(int fetchSize)
                                                     throws java.sql.SQLException
Description copied from interface: InspectionStore
Return record source for all inspections in this store. Uses a streaming result set to return the Inspections.

Specified by:
queryInspections in interface InspectionStore
Parameters:
fetchSize - - number of records to hold in memory at a time.
Returns:
Throws:
java.sql.SQLException

query

public com.partnersoft.io.DataRecordSource query(java.lang.String sql)
                                          throws java.sql.SQLException
Description copied from interface: InspectionStore
Queries this store using the passed String as an SQL statement

Specified by:
query in interface InspectionStore
Parameters:
sql - - query SQL to execute
Returns:
- DataRecordSource returned from querying this store.
Throws:
java.sql.SQLException - - When SQL badness occurs.

query

public com.partnersoft.io.DataRecordSource query(java.lang.String sql,
                                                 int fetchSize)
                                          throws java.sql.SQLException
Description copied from interface: InspectionStore
Queries this store using the passed String as an SQL statement Uses a streaming result set.

Specified by:
query in interface InspectionStore
Parameters:
sql - - query SQL to execute
fetchSize - - number of records to hold in memory at a time.
Returns:
- DataRecordSource returned from querying this store.
Throws:
java.sql.SQLException - - When SQL badness occurs.

queryBlobs

public com.partnersoft.io.DataRecordSource queryBlobs()
                                               throws java.sql.SQLException
Description copied from interface: InspectionStore
Return record source for all Blobs in this store.

Specified by:
queryBlobs in interface InspectionStore
Returns:
Throws:
java.sql.SQLException

queryBlobs

public com.partnersoft.io.DataRecordSource queryBlobs(int fetchSize)
                                               throws java.sql.SQLException
Description copied from interface: InspectionStore
Return record source for all Blobs in this store. Uses a streaming result set.

Specified by:
queryBlobs in interface InspectionStore
Parameters:
fetchSize - - number of records to hold in memory at a time.
Returns:
Throws:
java.sql.SQLException

queryInspections

public com.partnersoft.io.DataRecordSource queryInspections(java.lang.String whereClause)
                                                     throws java.sql.SQLException
Description copied from interface: InspectionStore
Queries this store using the passed String as an SQL where clause.

Specified by:
queryInspections in interface InspectionStore
Returns:
Throws:
java.sql.SQLException

queryInspections

public com.partnersoft.io.DataRecordSource queryInspections(java.lang.String whereClause,
                                                            int fetchSize)
                                                     throws java.sql.SQLException
Description copied from interface: InspectionStore
Queries this store using the passed String as an SQL where clause. Uses a streaming result set.

Specified by:
queryInspections in interface InspectionStore
Parameters:
whereClause - - Sql where clause to use.
fetchSize - - number of records to hold in memory at a time.
Returns:
Throws:
java.sql.SQLException

queryBlobs

public com.partnersoft.io.DataRecordSource queryBlobs(java.lang.String whereClause)
                                               throws java.sql.SQLException
Description copied from interface: InspectionStore
Queries this store using the passed String as an SQL where clause.

Specified by:
queryBlobs in interface InspectionStore
Parameters:
whereClause - - Sql where clause to use.
Returns:
Throws:
java.sql.SQLException

queryBlobs

public com.partnersoft.io.DataRecordSource queryBlobs(java.lang.String whereClause,
                                                      int fetchSize)
                                               throws java.sql.SQLException
Description copied from interface: InspectionStore
Queries this store using the passed String as an SQL where clause. Uses a streaming result set.

Specified by:
queryBlobs in interface InspectionStore
Parameters:
whereClause - - Sql where clause to use.
fetchSize - - number of records to hold in memory at a time.
Returns:
Throws:
java.sql.SQLException

updateInspection

public void updateInspection(java.lang.String guid,
                             com.partnersoft.data.Naming<java.lang.Object> data)
                      throws java.io.IOException,
                             java.sql.SQLException
Specified by:
updateInspection in interface InspectionStore
Throws:
java.io.IOException
java.sql.SQLException

updateInspection

public void updateInspection(java.lang.String guid,
                             java.lang.Object... data)
                      throws java.io.IOException,
                             java.sql.SQLException
Specified by:
updateInspection in interface InspectionStore
Throws:
java.io.IOException
java.sql.SQLException

getInspectionTableName

public java.lang.String getInspectionTableName()
Specified by:
getInspectionTableName in interface InspectionStore

getSyncTableName

public java.lang.String getSyncTableName()
Specified by:
getSyncTableName in interface InspectionStore

getBlobTableName

public java.lang.String getBlobTableName()
Specified by:
getBlobTableName in interface InspectionStore

getFieldTableName

public java.lang.String getFieldTableName()
Specified by:
getFieldTableName in interface InspectionStore

getPicklistTableName

public java.lang.String getPicklistTableName()
Specified by:
getPicklistTableName in interface InspectionStore

getPublishingTableName

public java.lang.String getPublishingTableName()
Specified by:
getPublishingTableName in interface InspectionStore

getConnection

public com.partnersoft.sql.DatabaseConnection getConnection()

getDatabase

public com.partnersoft.sql.DatabaseConnectionConfig getDatabase()