Package com.mckoi.database
Class ViewManager
- java.lang.Object
-
- com.mckoi.database.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ViewManager.ViewInternalTableInfo
An object that models the list of views as table objects in a transaction.
-
Field Summary
Fields Modifier and Type Field Description private DatabaseConnection
connection
The DatabaseConnection.private DatabaseQueryContext
context
The context.private java.util.HashMap
local_cache
A local cache of ViewDef objects mapped by row id in the system view table.private boolean
view_table_changed
Set to true when the connection makes changes to the view table through this manager.
-
Constructor Summary
Constructors Constructor Description ViewManager(DatabaseConnection connection)
Constructs the ViewManager for a DatabaseConnection.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) 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.QueryPlanNode
createViewQueryPlanNode(TableName view_name)
Returns a freshly deserialized QueryPlanNode object for the given view object.void
defineView(ViewDef view, SQLQuery query, User user)
Defines a view.boolean
deleteView(TableName view_name)
Deletes the view with the given name, or returns false if no entries were deleted from the view table.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.private java.util.HashMap
getViewCache()
Returns the local cache of ViewDef objects.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.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.private void
invalidateViewCache()
Invalidates the view cache.boolean
viewExists(TableName view_name)
Returns true if the view with the given name exists.
-
-
-
Field Detail
-
connection
private DatabaseConnection connection
The DatabaseConnection.
-
context
private DatabaseQueryContext context
The context.
-
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.
-
-