Class ViewManager


  • public class ViewManager
    extends java.lang.Object
    A DatabaseConnection view manager. This controls adding, updating, deleting, and processing views inside the system view table.
    • Field Detail

      • view_table_changed

        private boolean view_table_changed
        Set to true when the connection makes changes to the view table through this manager.
      • local_cache

        private java.util.HashMap local_cache
        A local cache of ViewDef objects mapped by row id in the system view table. This cache is invalidated when changes are committed to the system view table.
    • Constructor Detail

      • ViewManager

        ViewManager​(DatabaseConnection connection)
        Constructs the ViewManager for a DatabaseConnection.
    • Method Detail

      • getViewCache

        private java.util.HashMap getViewCache()
        Returns the local cache of ViewDef objects. This cache is mapped from row_id to view object. The cache is invalidated when changes are committed to the system view table.
      • invalidateViewCache

        private void invalidateViewCache()
        Invalidates the view cache.
      • findViewEntry

        private Table findViewEntry​(DataTable table,
                                    TableName view_name)
        Given the SYS_VIEW table, this returns a new table that contains the entry with the given view name, or an empty result if the view is not found. Generates an error if more than 1 entry found.
      • viewExists

        public boolean viewExists​(TableName view_name)
        Returns true if the view with the given name exists.
      • defineView

        public void defineView​(ViewDef view,
                               SQLQuery query,
                               User user)
                        throws DatabaseException
        Defines a view. If the view with the name has not been defined it is defined. If the view has been defined then it is overwritten with this information.
        Parameters:
        view - information that defines the view.
        query - the query that forms the view.
        user - the user that owns this view being defined.
        Throws:
        DatabaseException
      • deleteView

        public boolean deleteView​(TableName view_name)
                           throws DatabaseException
        Deletes the view with the given name, or returns false if no entries were deleted from the view table.
        Throws:
        DatabaseException
      • getViewDef

        private static ViewDef getViewDef​(java.util.HashMap cache,
                                          TableDataSource view_table,
                                          TableName view_name)
        Creates a ViewDef object for the given view name in the table. The access is cached through the given HashMap object.

        We assume the access to the cache is limited to the current thread calling this method. We don't synchronize over the cache at any time.

      • getViewDef

        private static ViewDef getViewDef​(java.util.HashMap cache,
                                          TableDataSource view_table,
                                          int index)
        Creates a ViewDef object for the given index value in the table. The access is cached through the given HashMap object.

        We assume the access to the cache is limited to the current thread calling this method. We don't synchronize over the cache at any time.

      • createViewQueryPlanNode

        public QueryPlanNode createViewQueryPlanNode​(TableName view_name)
        Returns a freshly deserialized QueryPlanNode object for the given view object.
      • createInternalTableInfo

        static InternalTableInfo createInternalTableInfo​(ViewManager manager,
                                                         Transaction transaction)
        Returns an InternalTableInfo object used to model the list of views that are accessible within the given Transaction object. This is used to model all views as regular tables accessible within a transaction.

        Note that the 'ViewManager' parameter can be null if there is no backing view manager. The view manager is intended as a cache to improve the access speed of the manager.