Package gov.usgs.earthquake.aws
Class JsonProductStorage
java.lang.Object
gov.usgs.util.DefaultConfigurable
gov.usgs.earthquake.util.JDBCConnection
gov.usgs.earthquake.aws.JsonProductStorage
- All Implemented Interfaces:
ProductStorage
,Configurable
,AutoCloseable
Store Products in a database.
Note that this storage does not store Product Content, and is intended for
Products that use URLContent and can be serialized using JsonProduct.
Only SQLITE or local development should rely on createSchema. Products (data
column) have exceeded 64kb, plan accordingly.
Mysql Schema Example:
CREATE TABLE IF NOT EXISTS indexer_storage (id INTEGER PRIMARY KEY AUTO_INCREMENT , source VARCHAR(255) , type VARCHAR(255) , code VARCHAR(255) , updatetime BIGINT , data LONGTEXT , UNIQUE KEY product_index (source, type, code, updatetime) ) ENGINE=innodb CHARSET=utf8;
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Variable for the default driverstatic final String
Variable for the default tablestatic final String
Variable for the default URLFields inherited from class gov.usgs.earthquake.util.JDBCConnection
DATABASE_SECRET_ARN_PROPERTY
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a JsonProductStorage using defaults.JsonProductStorage
(String driver, String url) Create a JsonProductStorage with a default table.JsonProductStorage
(String driver, String url, String table) Create a JsonProductStorage with a custom driver, url, and table. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addStorageListener
(StorageListener listener) Adds aStorageListener
to be notified when a change occurs in thisProductStorage
.void
Implement Configurablevoid
Attempt to create schema.getProduct
(ProductId id) Get a product from storage.Get a ProductSource for product in database.getTable()
boolean
hasProduct
(ProductId id) Check whether product found in storage.boolean
boolean
void
notifyListeners
(StorageEvent event) NotifiesStorageListener
s of the change to theProductStorage
.void
Remove product from storage.void
removeStorageListener
(StorageListener listener) Removes aStorageListener
from being notified when a change occurs in thisProductStorage
.boolean
Check whether schema exists.void
setKeychain
(ProductKeyChain keychain) void
setRejectInvalidSignatures
(boolean rejectInvalidSignatures) void
void
setTestSignatures
(boolean testSignatures) void
startup()
After normal startup, check whether schema exists and attempt to create.storeProduct
(Product product) Add product to storage.storeProductSource
(ProductSource input) Store a ProductSource.Methods inherited from class gov.usgs.earthquake.util.JDBCConnection
beginTransaction, buildUrl, close, commitTransaction, connect, getConnection, getDriver, getUrl, rollbackTransaction, setDriver, setUrl, shutdown, verifyConnection
Methods inherited from class gov.usgs.util.DefaultConfigurable
getName, setName
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface gov.usgs.util.Configurable
getName, setName, shutdown
-
Field Details
-
DEFAULT_DRIVER
Variable for the default driver- See Also:
-
DEFAULT_TABLE
Variable for the default table- See Also:
-
DEFAULT_URL
Variable for the default URL- See Also:
-
-
Constructor Details
-
JsonProductStorage
public JsonProductStorage()Create a JsonProductStorage using defaults. -
JsonProductStorage
Create a JsonProductStorage with a default table.- Parameters:
driver
- Driver to useurl
- URL to use
-
JsonProductStorage
Create a JsonProductStorage with a custom driver, url, and table.- Parameters:
driver
- Driver to useurl
- URL to usetable
- Table to use
-
-
Method Details
-
getTable
- Returns:
- table
-
setTable
- Parameters:
table
- Table to set
-
configure
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:
Exception
- Exception
-
startup
After normal startup, check whether schema exists and attempt to create.- Specified by:
startup
in interfaceConfigurable
- Overrides:
startup
in classJDBCConnection
- Throws:
Exception
- if error occurs
-
schemaExists
Check whether schema exists.- Returns:
- boolean
- Throws:
Exception
- if error occurs
-
createSchema
Attempt to create schema. Only supports sqlite or mysql. When not using sqlite, relying on this method is only recommended for local development.- Throws:
Exception
- if error occurs
-
hasProduct
Check whether product found in storage.- Specified by:
hasProduct
in interfaceProductStorage
- Parameters:
id
- the product to check.- Returns:
- true if the product is in this storage, false otherwise.
- Throws:
Exception
- if an error occurs while checking.
-
getProduct
Get a product from storage.- Specified by:
getProduct
in interfaceProductStorage
- Parameters:
id
- The product to get.- Returns:
- product if found, otherwise null.
- Throws:
Exception
- if errors occur while retrieving product.
-
storeProduct
public ProductId storeProduct(Product product) throws ContentTypeNotSupportedException, InvalidSignatureException, ProductAlreadyInStorageException, Exception Add product to storage.- Specified by:
storeProduct
in interfaceProductStorage
- Parameters:
product
- the product to store.- Returns:
- the stored product's id.
- Throws:
ContentTypeNotSupportedException
- if product content not supported.InvalidSignatureException
- if signature is invalid.ProductAlreadyInStorageException
- if product already in storage.Exception
- if errors occur while storing product.
-
getProductSource
Get a ProductSource for product in database.- Specified by:
getProductSource
in interfaceProductStorage
- Parameters:
id
- which product to retrieve.- Returns:
- ObjectProductSource or null if product not found.
- Throws:
Exception
- if any errors occur while getting the ProductInput.
-
storeProductSource
public ProductId storeProductSource(ProductSource input) throws ContentTypeNotSupportedException, InvalidSignatureException, ProductAlreadyInStorageException, Exception Store a ProductSource. Uses ObjectProductHandler to read Product, then calls storeProduct. Uses SignatureVerifier to check for signed products. Checks that the content type is allowed (currently only FileContent does not work).- Specified by:
storeProductSource
in interfaceProductStorage
- Parameters:
input
- the product to store.- Returns:
- the stored product's id.
- Throws:
ContentTypeNotSupportedException
- if product content not supported.InvalidSignatureException
- if signature is invalid.ProductAlreadyInStorageException
- if product already in storage.Exception
- if errors occur while storing product.
-
removeProduct
Remove product from storage.- Specified by:
removeProduct
in interfaceProductStorage
- Parameters:
id
- which product to remove.- Throws:
Exception
- if errors occur while removing product.
-
notifyListeners
Description copied from interface:ProductStorage
NotifiesStorageListener
s of the change to theProductStorage
.- Specified by:
notifyListeners
in interfaceProductStorage
- Parameters:
event
- StorageEvent
-
addStorageListener
Description copied from interface:ProductStorage
Adds aStorageListener
to be notified when a change occurs in thisProductStorage
.- Specified by:
addStorageListener
in interfaceProductStorage
- Parameters:
listener
- The listener to notify of changes.
-
removeStorageListener
Description copied from interface:ProductStorage
Removes aStorageListener
from being notified when a change occurs in thisProductStorage
.- Specified by:
removeStorageListener
in interfaceProductStorage
- Parameters:
listener
- The listener to remove
-
isRejectInvalidSignatures
public boolean isRejectInvalidSignatures()- Returns:
- the rejectInvalidSignatures
-
setRejectInvalidSignatures
public void setRejectInvalidSignatures(boolean rejectInvalidSignatures) - Parameters:
rejectInvalidSignatures
- the rejectInvalidSignatures to set
-
isTestSignatures
public boolean isTestSignatures()- Returns:
- the testSignatures
-
setTestSignatures
public void setTestSignatures(boolean testSignatures) - Parameters:
testSignatures
- the testSignatures to set
-
getKeychain
- Returns:
- the keychain
-
setKeychain
- Parameters:
keychain
- the keychain to set
-
getVerifier
-