Package gov.usgs.earthquake.indexer
Class JDBCProductIndex
java.lang.Object
gov.usgs.util.DefaultConfigurable
gov.usgs.earthquake.util.JDBCConnection
gov.usgs.earthquake.indexer.JDBCProductIndex
- All Implemented Interfaces:
ProductIndex
,Configurable
,AutoCloseable
- Direct Known Subclasses:
ExtentIndex
JDBC Implementation of
ProductIndex
.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Default index file.static final String
Public var for summary product index IDsFields inherited from class gov.usgs.earthquake.util.JDBCConnection
DATABASE_SECRET_ARN_PROPERTY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAssociation
(Event event, ProductSummary summary) Create an association between the given event and product summary.Add an event to the databaseprotected void
addProductLinks
(long productId, Map<String, List<URI>> links) Save the links in the database and associate them to the given productIdprotected void
addProductProperties
(long productId, Map<String, String> properties) Save the properties in the database and associate them to the given productIdaddProductSummary
(ProductSummary summary) Add a product summary to the databaseBuild a list of all the pieces of the WHERE clause relevant to the productSummary table.protected String
Create the full SELECT query for the products table using the default clauseList.protected String
buildProductQuery
(ProductIndexQuery query, List<String> clauseList) Create the full SELECT query for the products table using a custom clauseList.void
Grab values from the Config object and put them into private variables.connect()
Return a connection to the database.void
eventsUpdated
(List<Event> events) Called when the indexer is done updating events after a product is processed.getEvents
(ProductIndexQuery query) Return all events from the database that meet the parameters specified in the ProductIndexQuery object.getProducts
(ProductIndexQuery query) Return all products that meet the parameters specified in the ProductIndexQuery object.getProducts
(ProductIndexQuery query, boolean loadDetails) Load product summaries.Return all products that aren't associated with an event.boolean
hasProduct
(ProductId id) Check whether product summary is in index.protected void
loadProductSummaries
(List<ProductSummary> summaries) Populate links and properties for provided product summaries.static double
normalizeLongitude
(double lon) Convert the given longitude to be between -180 and 180.static BigDecimal
Wrapper to normalize BigDecimal longitudesprotected ProductSummary
parseProductSummary
(ResultSet results) Parse ProductSummary without loading links or properties.removeAssociation
(Event event, ProductSummary summary) Delete the association, if it exists, between the given event and product summary.removeEvent
(Event event) Delete an event from the database.removeProductSummaries
(List<ProductSummary> summaries) removeProductSummary
(ProductSummary summary) Delete a product summary from the database If the summary doesn't have an indexId value set, throw an exceptionMethods inherited from class gov.usgs.earthquake.util.JDBCConnection
beginTransaction, buildUrl, close, commitTransaction, getConnection, getDriver, getUrl, rollbackTransaction, setDriver, setUrl, shutdown, startup, 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, startup
Methods inherited from interface gov.usgs.earthquake.indexer.ProductIndex
beginTransaction, commitTransaction, rollbackTransaction
-
Field Details
-
JDBC_DEFAULT_FILE
Default index file. Created by copying JDBC_DEFAULT_INDEX out of Jar if doesn't already exist in file system- See Also:
-
SUMMARY_PRODUCT_INDEX_ID
Public var for summary product index IDs- See Also:
-
-
Constructor Details
-
Method Details
-
configure
Grab values from the Config object and put them into private variables.- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classJDBCConnection
- Parameters:
config
- Configuration for the product index- Throws:
Exception
- Exception
-
connect
Return a connection to the database.- Overrides:
connect
in classJDBCConnection
- Returns:
- Connection object
- Throws:
Exception
- if error occurs
-
getEvents
Return all events from the database that meet the parameters specified in the ProductIndexQuery object.- Specified by:
getEvents
in interfaceProductIndex
- Parameters:
query
- A description of which events to retrieve.- Returns:
- List of Event objects
- Throws:
Exception
- if error occurs
-
addEvent
Add an event to the database- Specified by:
addEvent
in interfaceProductIndex
- Parameters:
event
- Event to store- Returns:
- Event object with eventId set to the database id
- Throws:
Exception
- if error occurs
-
removeEvent
Delete an event from the database.- Specified by:
removeEvent
in interfaceProductIndex
- Parameters:
event
- Event to remove- Returns:
- List containing all the ProductIds that were deleted by the method call
- Throws:
Exception
- if the event is associated to products.
-
getUnassociatedProducts
Return all products that aren't associated with an event.- Specified by:
getUnassociatedProducts
in interfaceProductIndex
- Parameters:
query
- ProductIndexQuery used to further limit the results- Returns:
- List of unassociated Products
- Throws:
IllegalArgumentException
- when query event search type is SEARCH_EVENT_PREFERRED.Exception
- if error occurs
-
getProducts
Return all products that meet the parameters specified in the ProductIndexQuery object.- Specified by:
getProducts
in interfaceProductIndex
- Parameters:
query
- A description of which products to retrieve.- Returns:
- List of ProductSummary objects
- Throws:
IllegalArgumentException
- when query event search type is SEARCH_EVENT_PREFERRED.Exception
- if error occurs
-
getProducts
public List<ProductSummary> getProducts(ProductIndexQuery query, boolean loadDetails) throws Exception Load product summaries.- Parameters:
query
- product queryloadDetails
- whether to callloadProductSummaries(List)
, which loads links and properties with additional queries.- Returns:
- A list of loaded product summaries
- Throws:
Exception
- if error occurs
-
hasProduct
Check whether product summary is in index.- Specified by:
hasProduct
in interfaceProductIndex
- Parameters:
id
- product to search.- Returns:
- boolean if index has product
- Throws:
Exception
- if error occurs
-
addProductSummary
Add a product summary to the database- Specified by:
addProductSummary
in interfaceProductIndex
- Parameters:
summary
- ProductSummary object to store. Must not be null.- Returns:
- Copy of the product summary object with the indexId set to the newly inserted id.
- Throws:
Exception
- if error occurs
-
removeProductSummary
Delete a product summary from the database If the summary doesn't have an indexId value set, throw an exception- Specified by:
removeProductSummary
in interfaceProductIndex
- Parameters:
summary
- ProductSummary object to delete- Returns:
- id of removed summary.
- Throws:
Exception
- if error occurs
-
addAssociation
Create an association between the given event and product summary. This assumes that both the event and the product are already stored in their respective tables.- Specified by:
addAssociation
in interfaceProductIndex
- Parameters:
event
- Event to add association tosummary
- ProductSummary to add association to- Returns:
- Copy of event with summary added to the event's products list
- Throws:
Exception
- if error occurs
-
removeAssociation
Delete the association, if it exists, between the given event and product summary. NOTE: this removes the association between the event and ALL versions of the product summary.- Specified by:
removeAssociation
in interfaceProductIndex
- Parameters:
event
- An event to remove an association withsummary
- A ProductSummary to remove an association with- Returns:
- Copy of event with summary removed from the products list
- Throws:
Exception
- if error occurs
-
buildProductClauses
Build a list of all the pieces of the WHERE clause relevant to the productSummary table. If the query doesn't set any properties, this method will return an empty list. It is up to the calling methods to check if the clause list is empty when they build their WHERE clause.- Parameters:
query
- ProductIndexQuery- Returns:
- list containing clauses in the form: column="value"
-
buildProductQuery
Create the full SELECT query for the products table using the default clauseList.- Parameters:
query
- Query to build.- Returns:
- String containing the full SELECT query
- See Also:
-
buildProductQuery
Create the full SELECT query for the products table using a custom clauseList.- Parameters:
query
- Query to build.clauseList
- List of clauses for WHERE- Returns:
- String containing the full SELECT query
-
loadProductSummaries
Populate links and properties for provided product summaries.- Parameters:
summaries
- List of ProductSummaries- Throws:
Exception
- if error occurs
-
parseProductSummary
Parse ProductSummary without loading links or properties.- Parameters:
results
- ResultSet to parse- Returns:
- ProductSummary object without links or properties.
- Throws:
Exception
- if error occurs
-
removeProductSummaries
- Parameters:
summaries
- List of product summaries to remove- Returns:
- List of ProductIds that were removed
- Throws:
Exception
- if error occurs
-
addProductProperties
protected void addProductProperties(long productId, Map<String, String> properties) throws SQLExceptionSave the properties in the database and associate them to the given productId- Parameters:
productId
- long product ID to associate toproperties
- Map of properties to save- Throws:
SQLException
- if SQL error occurs
-
addProductLinks
Save the links in the database and associate them to the given productId- Parameters:
productId
- Index id of the product to selectlinks
- Map of relations to URIs- Throws:
SQLException
- if sql error occurs
-
normalizeLongitude
public static double normalizeLongitude(double lon) Convert the given longitude to be between -180 and 180. If the given value is already in the range, this method just returns the value.- Parameters:
lon
- Double longitude- Returns:
- double normalized between -180 and 180
-
normalizeLongitude
Wrapper to normalize BigDecimal longitudes- Parameters:
lon
- BigDecimal Longitude- Returns:
- Normalized BigDecimal latitude
-
eventsUpdated
Called when the indexer is done updating events after a product is processed. Stores the preferred attributes for each event in the list- Specified by:
eventsUpdated
in interfaceProductIndex
- Parameters:
events
- the events that have been updated.- Throws:
Exception
- if error occurs
-