Class JDBCProductIndex

    • Field Detail

      • JDBC_DEFAULT_FILE

        public static final java.lang.String 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:
        Constant Field Values
      • SUMMARY_PRODUCT_INDEX_ID

        public static final java.lang.String SUMMARY_PRODUCT_INDEX_ID
        Public var for summary product index IDs
        See Also:
        Constant Field Values
    • Constructor Detail

      • JDBCProductIndex

        public JDBCProductIndex()
                         throws java.lang.Exception
        Constructor. Sets index_file to the default value JDBC_DEFAULT_FILE
        Throws:
        java.lang.Exception - if error occurs
      • JDBCProductIndex

        public JDBCProductIndex​(java.lang.String sqliteFileName)
                         throws java.lang.Exception
        Constructor. Uses custom index_file
        Parameters:
        sqliteFileName - String for sqlite file name
        Throws:
        java.lang.Exception - if error occurs
    • Method Detail

      • configure

        public void configure​(Config config)
                       throws java.lang.Exception
        Grab values from the Config object and put them into private variables.
        Specified by:
        configure in interface Configurable
        Overrides:
        configure in class JDBCConnection
        Parameters:
        config - Configuration for the product index
        Throws:
        java.lang.Exception - Exception
      • connect

        public java.sql.Connection connect()
                                    throws java.lang.Exception
        Return a connection to the database.
        Overrides:
        connect in class JDBCConnection
        Returns:
        Connection object
        Throws:
        java.lang.Exception - if error occurs
      • getEvents

        public java.util.List<Event> getEvents​(ProductIndexQuery query)
                                        throws java.lang.Exception
        Return all events from the database that meet the parameters specified in the ProductIndexQuery object.
        Specified by:
        getEvents in interface ProductIndex
        Parameters:
        query - A description of which events to retrieve.
        Returns:
        List of Event objects
        Throws:
        java.lang.Exception - if error occurs
      • addEvent

        public Event addEvent​(Event event)
                       throws java.lang.Exception
        Add an event to the database
        Specified by:
        addEvent in interface ProductIndex
        Parameters:
        event - Event to store
        Returns:
        Event object with eventId set to the database id
        Throws:
        java.lang.Exception - if error occurs
      • removeEvent

        public java.util.List<ProductId> removeEvent​(Event event)
                                              throws java.lang.Exception
        Delete an event from the database.
        Specified by:
        removeEvent in interface ProductIndex
        Parameters:
        event - Event to remove
        Returns:
        List containing all the ProductIds that were deleted by the method call
        Throws:
        java.lang.Exception - if the event is associated to products.
      • getUnassociatedProducts

        public java.util.List<ProductSummary> getUnassociatedProducts​(ProductIndexQuery query)
                                                               throws java.lang.Exception
        Return all products that aren't associated with an event.
        Specified by:
        getUnassociatedProducts in interface ProductIndex
        Parameters:
        query - ProductIndexQuery used to further limit the results
        Returns:
        List of unassociated Products
        Throws:
        java.lang.IllegalArgumentException - when query event search type is SEARCH_EVENT_PREFERRED.
        java.lang.Exception - if error occurs
      • getProducts

        public java.util.List<ProductSummary> getProducts​(ProductIndexQuery query)
                                                   throws java.lang.Exception
        Return all products that meet the parameters specified in the ProductIndexQuery object.
        Specified by:
        getProducts in interface ProductIndex
        Parameters:
        query - A description of which products to retrieve.
        Returns:
        List of ProductSummary objects
        Throws:
        java.lang.IllegalArgumentException - when query event search type is SEARCH_EVENT_PREFERRED.
        java.lang.Exception - if error occurs
      • getProducts

        public java.util.List<ProductSummary> getProducts​(ProductIndexQuery query,
                                                          boolean loadDetails)
                                                   throws java.lang.Exception
        Load product summaries.
        Parameters:
        query - product query
        loadDetails - whether to call loadProductSummaries(List), which loads links and properties with additional queries.
        Returns:
        A list of loaded product summaries
        Throws:
        java.lang.Exception - if error occurs
      • hasProduct

        public boolean hasProduct​(ProductId id)
                           throws java.lang.Exception
        Check whether product summary is in index.
        Specified by:
        hasProduct in interface ProductIndex
        Parameters:
        id - product to search.
        Returns:
        boolean if index has product
        Throws:
        java.lang.Exception - if error occurs
      • addProductSummary

        public ProductSummary addProductSummary​(ProductSummary summary)
                                         throws java.lang.Exception
        Add a product summary to the database
        Specified by:
        addProductSummary in interface ProductIndex
        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:
        java.lang.Exception - if error occurs
      • removeProductSummary

        public ProductId removeProductSummary​(ProductSummary summary)
                                       throws java.lang.Exception
        Delete a product summary from the database If the summary doesn't have an indexId value set, throw an exception
        Specified by:
        removeProductSummary in interface ProductIndex
        Parameters:
        summary - ProductSummary object to delete
        Returns:
        id of removed summary.
        Throws:
        java.lang.Exception - if error occurs
      • addAssociation

        public Event addAssociation​(Event event,
                                    ProductSummary summary)
                             throws java.lang.Exception
        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 interface ProductIndex
        Parameters:
        event - Event to add association to
        summary - ProductSummary to add association to
        Returns:
        Copy of event with summary added to the event's products list
        Throws:
        java.lang.Exception - if error occurs
      • removeAssociation

        public Event removeAssociation​(Event event,
                                       ProductSummary summary)
                                throws java.lang.Exception
        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 interface ProductIndex
        Parameters:
        event - An event to remove an association with
        summary - A ProductSummary to remove an association with
        Returns:
        Copy of event with summary removed from the products list
        Throws:
        java.lang.Exception - if error occurs
      • buildProductClauses

        protected java.util.List<java.lang.String> buildProductClauses​(ProductIndexQuery query)
        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

        protected java.lang.String buildProductQuery​(ProductIndexQuery query)
        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:
        buildProductClauses(ProductIndexQuery)
      • buildProductQuery

        protected java.lang.String buildProductQuery​(ProductIndexQuery query,
                                                     java.util.List<java.lang.String> clauseList)
        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

        protected void loadProductSummaries​(java.util.List<ProductSummary> summaries)
                                     throws java.lang.Exception
        Populate links and properties for provided product summaries.
        Parameters:
        summaries - List of ProductSummaries
        Throws:
        java.lang.Exception - if error occurs
      • parseProductSummary

        protected ProductSummary parseProductSummary​(java.sql.ResultSet results)
                                              throws java.lang.Exception
        Parse ProductSummary without loading links or properties.
        Parameters:
        results - ResultSet to parse
        Returns:
        ProductSummary object without links or properties.
        Throws:
        java.lang.Exception - if error occurs
      • removeProductSummaries

        public java.util.List<ProductId> removeProductSummaries​(java.util.List<ProductSummary> summaries)
                                                         throws java.lang.Exception
        Parameters:
        summaries - List of product summaries to remove
        Returns:
        List of ProductIds that were removed
        Throws:
        java.lang.Exception - if error occurs
      • addProductProperties

        protected void addProductProperties​(long productId,
                                            java.util.Map<java.lang.String,​java.lang.String> properties)
                                     throws java.sql.SQLException
        Save the properties in the database and associate them to the given productId
        Parameters:
        productId - long product ID to associate to
        properties - Map of properties to save
        Throws:
        java.sql.SQLException - if SQL error occurs
      • addProductLinks

        protected void addProductLinks​(long productId,
                                       java.util.Map<java.lang.String,​java.util.List<java.net.URI>> links)
                                throws java.sql.SQLException
        Save the links in the database and associate them to the given productId
        Parameters:
        productId - Index id of the product to select
        links - Map of relations to URIs
        Throws:
        java.sql.SQLException - if sql error occurs
      • normalizeLongitude

        protected 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

        protected java.math.BigDecimal normalizeLongitude​(java.math.BigDecimal lon)
        Wrapper to normalize BigDecimal longitudes
        Parameters:
        lon - BigDecimal Longitude
        Returns:
        Normalized BigDecimal latitude
      • eventsUpdated

        public void eventsUpdated​(java.util.List<Event> events)
                           throws java.lang.Exception
        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 interface ProductIndex
        Parameters:
        events - the events that have been updated.
        Throws:
        java.lang.Exception - if error occurs