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 StringDefault index file.static final StringPublic 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 voidaddProductLinks(long productId, Map<String, List<URI>> links) Save the links in the database and associate them to the given productIdprotected voidaddProductProperties(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 StringCreate the full SELECT query for the products table using the default clauseList.protected StringbuildProductQuery(ProductIndexQuery query, List<String> clauseList) Create the full SELECT query for the products table using a custom clauseList.voidGrab values from the Config object and put them into private variables.connect()Return a connection to the database.voideventsUpdated(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.booleanhasProduct(ProductId id) Check whether product summary is in index.protected voidloadProductSummaries(List<ProductSummary> summaries) Populate links and properties for provided product summaries.static doublenormalizeLongitude(double lon) Convert the given longitude to be between -180 and 180.static BigDecimalWrapper to normalize BigDecimal longitudesprotected ProductSummaryparseProductSummary(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, 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, startupMethods 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:
configurein interfaceConfigurable- Overrides:
configurein classJDBCConnection- Parameters:
config- Configuration for the product index- Throws:
Exception- Exception
-
connect
Return a connection to the database.- Overrides:
connectin 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:
getEventsin 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:
addEventin 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:
removeEventin 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:
getUnassociatedProductsin 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:
getProductsin 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:
hasProductin 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:
addProductSummaryin 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:
removeProductSummaryin 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:
addAssociationin 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:
removeAssociationin 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:
eventsUpdatedin interfaceProductIndex- Parameters:
events- the events that have been updated.- Throws:
Exception- if error occurs
-