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 StringVariable for the default driverstatic final StringVariable for the default tablestatic final StringVariable 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 TypeMethodDescriptionvoidaddStorageListener(StorageListener listener) Adds aStorageListenerto be notified when a change occurs in thisProductStorage.voidImplement ConfigurablevoidAttempt to create schema.getProduct(ProductId id) Get a product from storage.Get a ProductSource for product in database.getTable()booleanhasProduct(ProductId id) Check whether product found in storage.booleanbooleanvoidnotifyListeners(StorageEvent event) NotifiesStorageListeners of the change to theProductStorage.voidRemove product from storage.voidremoveStorageListener(StorageListener listener) Removes aStorageListenerfrom being notified when a change occurs in thisProductStorage.booleanCheck whether schema exists.voidsetKeychain(ProductKeyChain keychain) voidsetRejectInvalidSignatures(boolean rejectInvalidSignatures) voidvoidsetTestSignatures(boolean testSignatures) voidstartup()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, verifyConnectionMethods inherited from class gov.usgs.util.DefaultConfigurable
getName, setNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:JDBCConnectionImplement Configurable- Specified by:
configurein interfaceConfigurable- Overrides:
configurein 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:
startupin interfaceConfigurable- Overrides:
startupin 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:
hasProductin 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:
getProductin 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:
storeProductin 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:
getProductSourcein 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:
storeProductSourcein 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:
removeProductin interfaceProductStorage- Parameters:
id- which product to remove.- Throws:
Exception- if errors occur while removing product.
-
notifyListeners
Description copied from interface:ProductStorageNotifiesStorageListeners of the change to theProductStorage.- Specified by:
notifyListenersin interfaceProductStorage- Parameters:
event- StorageEvent
-
addStorageListener
Description copied from interface:ProductStorageAdds aStorageListenerto be notified when a change occurs in thisProductStorage.- Specified by:
addStorageListenerin interfaceProductStorage- Parameters:
listener- The listener to notify of changes.
-
removeStorageListener
Description copied from interface:ProductStorageRemoves aStorageListenerfrom being notified when a change occurs in thisProductStorage.- Specified by:
removeStorageListenerin 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
-