Package gov.usgs.earthquake.aws
Class TrackingIndex
- java.lang.Object
-
- gov.usgs.util.DefaultConfigurable
-
- gov.usgs.earthquake.util.JDBCConnection
-
- gov.usgs.earthquake.aws.TrackingIndex
-
- All Implemented Interfaces:
Configurable
,java.lang.AutoCloseable
public class TrackingIndex extends JDBCConnection
Tracking index stores component state in a database. Only SQLITE or local development should rely on createSchema. Mysql Schema Example:
CREATE TABLE IF NOT EXISTS tracking_index (id INTEGER PRIMARY KEY AUTO_INCREMENT , created VARCHAR(255) , name VARCHAR(255) , data LONGTEXT , UNIQUE KEY name_index (name) ) ENGINE=innodb CHARSET=utf8;
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_DRIVER
Variable for the default driverstatic java.lang.String
DEFAULT_TABLE
Variable for the default tablestatic java.lang.String
DEFAULT_URL
Variable for the default URL
-
Constructor Summary
Constructors Constructor Description TrackingIndex()
Construct a TrackingIndex using defaults.TrackingIndex(java.lang.String driver, java.lang.String url)
Construct a TrackingIndex with the default table.TrackingIndex(java.lang.String driver, java.lang.String url, java.lang.String table)
Construct a TrackingIndex with custom driver, url, and table.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(Config config)
Implement Configurablevoid
createSchema()
Attempt to create schema.java.lang.String
getTable()
javax.json.JsonObject
getTrackingData(java.lang.String name)
Get tracking data for specified name.void
removeTrackingData(java.lang.String name)
Remove tracking data.boolean
schemaExists()
Check whether schema exists.void
setTable(java.lang.String table)
void
setTrackingData(java.lang.String name, javax.json.JsonObject data)
Add or update tracking data.void
startup()
After normal startup, check whether schema exists and attempt to create.-
Methods inherited from class gov.usgs.earthquake.util.JDBCConnection
beginTransaction, close, commitTransaction, connect, getConnection, getDriver, getUrl, rollbackTransaction, setDriver, setUrl, shutdown, verifyConnection
-
Methods inherited from class gov.usgs.util.DefaultConfigurable
getName, setName
-
-
-
-
Field Detail
-
DEFAULT_DRIVER
public static final java.lang.String DEFAULT_DRIVER
Variable for the default driver- See Also:
- Constant Field Values
-
DEFAULT_TABLE
public static final java.lang.String DEFAULT_TABLE
Variable for the default table- See Also:
- Constant Field Values
-
DEFAULT_URL
public static final java.lang.String DEFAULT_URL
Variable for the default URL- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TrackingIndex
public TrackingIndex()
Construct a TrackingIndex using defaults.
-
TrackingIndex
public TrackingIndex(java.lang.String driver, java.lang.String url)
Construct a TrackingIndex with the default table.- Parameters:
driver
- Driver to useurl
- URL to use
-
TrackingIndex
public TrackingIndex(java.lang.String driver, java.lang.String url, java.lang.String table)
Construct a TrackingIndex with custom driver, url, and table.- Parameters:
driver
- Driver to useurl
- URL to usetable
- Table to use
-
-
Method Detail
-
getTable
public java.lang.String getTable()
- Returns:
- table
-
setTable
public void setTable(java.lang.String table)
- Parameters:
table
- Table to set
-
configure
public void configure(Config config) throws java.lang.Exception
Description copied from class:JDBCConnection
Implement Configurable- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classJDBCConnection
- Parameters:
config
- Config to set driver and URL in- Throws:
java.lang.Exception
- Exception
-
startup
public void startup() throws java.lang.Exception
After normal startup, check whether schema exists and attempt to create.- Specified by:
startup
in interfaceConfigurable
- Overrides:
startup
in classJDBCConnection
- Throws:
java.lang.Exception
- if error occurs
-
schemaExists
public boolean schemaExists() throws java.lang.Exception
Check whether schema exists.- Returns:
- boolean
- Throws:
java.lang.Exception
- if error occurs
-
createSchema
public void createSchema() throws java.lang.Exception
Attempt to create schema. Only supports sqlite or mysql. When not using sqlite, relying on this method is only recommended for local development.- Throws:
java.lang.Exception
- if error occurs
-
getTrackingData
public javax.json.JsonObject getTrackingData(java.lang.String name) throws java.lang.Exception
Get tracking data for specified name.- Parameters:
name
- name of tracking data.- Returns:
- null if data not found.
- Throws:
java.lang.Exception
- if error occurs
-
removeTrackingData
public void removeTrackingData(java.lang.String name) throws java.lang.Exception
Remove tracking data.- Parameters:
name
- name of tracking data.- Throws:
java.lang.Exception
- if error occurs
-
setTrackingData
public void setTrackingData(java.lang.String name, javax.json.JsonObject data) throws java.lang.Exception
Add or update tracking data.- Parameters:
name
- name of tracking data.data
- data to store.- Throws:
java.lang.Exception
- if error occurs
-
-