public class BasicDataManager extends java.lang.Object implements DataManager
Modifier and Type | Field and Description |
---|---|
protected CacheReaderWriter |
cacher |
protected CacheBlock |
currentCacheBlock |
protected java.util.Map<java.lang.String,DataNode> |
currentDataNodes |
protected EventEngine |
eventEngine |
protected java.util.Set<java.lang.String> |
mergeable |
protected RootNode |
root |
protected java.lang.Object |
rootLock |
protected DatabaseSchema |
schema |
protected java.util.Set<java.lang.String> |
updateable |
Constructor and Description |
---|
BasicDataManager()
Creates a DataManager tied to a screen-scraper session
|
Modifier and Type | Method and Description |
---|---|
void |
addData(DataNode dataNode)
Manually add a created DataNode to the DataManager for writing.
|
void |
addData(java.lang.String schema,
java.util.Map<java.lang.String,java.lang.Object> data)
Add data to to the table represented by schema.
|
void |
addData(java.lang.String schema,
java.lang.String columnName,
java.lang.Object value)
Add data from the session variables to the table.
|
DataManagerEventListener |
addDataAssertion(DataAssertion d)
Adds a data assertion to be performed when the write is called.
|
DataManagerEventListener |
addDataAssertion(DataAssertion d,
DataManagerEventSource.EventFireTime when)
Adds a DataAssertion to be run A DataAssertion is a special case of a DataManagerEvent that executes onSuccess if the assertion passes and onFail if the assertion
fails
|
DataManagerEventListener |
addEventListener(java.lang.String schema,
DataManagerEventSource.EventFireTime when,
DataManagerEventListener listener)
Add an even listener.
|
DataManagerEventListener |
addEventListener(java.lang.String schema,
java.lang.String when,
DataManagerEventListener listener)
Adds an event listener
|
DataManagerEventListener |
addEventListenerWithPriority(java.lang.String schema,
DataManagerEventSource.EventFireTime when,
DataManagerEventListener listener,
int priority)
Add an event listener with a specified execution priority
|
EventHandler<DataManagerSchemalessEvent> |
addSchemalessEventListener(DataManagerSchemalessEvent.FireTime fireTime,
EventHandler<DataManagerSchemalessEvent> listener)
Adds a callback that will trigger at the specified time
|
EventHandler<DataManagerSchemalessEvent> |
addSchemalessEventListenerWithPriority(DataManagerSchemalessEvent.FireTime fireTime,
EventHandler<DataManagerSchemalessEvent> listener,
int priority)
Adds a callback that will trigger at the specified time
|
void |
buildSchemas()
Builds the schemas from a database.
|
void |
cacheContent(java.lang.String name,
java.lang.String content)
Caches the current content and links it to the main record.
|
void |
cacheContent(java.lang.String name,
java.lang.String content,
java.lang.String url)
Caches the current content and links it to the main record.
|
void |
cacheContent(java.lang.String name,
java.lang.String content,
java.lang.String url,
java.lang.String contentType)
Caches the current content and links it to the main record.
|
void |
cacheContext(java.util.Map<java.lang.String,?> contextValues)
Cache the current context, as passed in
|
void |
cacheScrapeableFile(ScrapeableFile scrapeableFile)
Caches the scrapeable file
|
void |
cacheScrapeableFile(ScrapeableFile scrapeableFile,
boolean includeHeaders)
Caches the scrapeable file
|
static java.lang.String |
catData(DataNode dataNode,
java.util.Set<java.lang.String> columns)
Concatenates the key value pairs of the specified columns in the DataNode
|
static java.lang.String |
catData(java.util.SortedMap<java.lang.String,DataObject> m)
Concatenates the key value pairs of the map
|
boolean |
checkDataNode(java.lang.String schema)
verifies that the data is ready to be inserted.
|
void |
clearAllData()
Clears out all the nodes of the DataManager.
|
void |
clearData(java.lang.String schema)
Clear out all the uncommitted data for the given schema
|
void |
close()
close should be called when you are done with the DataManager
|
boolean |
commit(java.lang.String schema)
commits the row of data corresponding to the schema, so the next time addData is called it will be in a new row.
|
protected void |
connectTree(DataNode dataNode)
Commit calls this method to create necessary parent nodes and connect this node to the active DataNode tree
|
void |
enablePageAndContextCaching(java.lang.String mainSchema,
CacheReaderWriter cacher)
Enables page and context caching for the given main table
|
boolean |
flush()
writes the current data to the Database and clears out all the data.
|
static java.lang.String |
generateUID(java.lang.String name)
generates a 40 character UID comprised of 0-9a-z based on a SHA1 hash
|
CacheReaderWriter |
getCacheReaderWriter()
Returns the Cacher for the object
|
java.util.Set<java.lang.String> |
getColumns(java.lang.String table)
Retrieve the columns for a given schema
|
DataNode |
getCurrentDataNode(java.lang.String schema)
retrieves the current DataNode that is in scope for the schema
|
DatabaseSchema |
getDatabaseSchema()
Retrieve Database schema, for a Relational Database this contains all the information about the tables
|
DataNode |
getNewDataNode(java.lang.String table)
Returns a new data node from the provided schema identifier.
|
DataWriter |
getNewDataWriter() |
RootNode |
getRoot()
returns the root node of the DataNode tree.
|
RelationalSchema |
getSchema(java.lang.String table)
returns a schema with the given identifier
|
static java.lang.String |
hashData(DataNode dataNode,
java.util.Set<java.lang.String> columns)
hashes the return of catData(n,columns) with a SHA1 hash
|
static java.lang.String |
hashData(java.util.SortedMap<java.lang.String,DataObject> map)
Hashes the return of catData(m) with a SHA1 hash
|
boolean |
hasSchema(java.lang.String table)
returns whether or not th
|
boolean |
importSchemas(java.lang.String file) |
void |
removeEventListener(java.lang.String schema,
DataManagerEventSource.EventFireTime when,
DataManagerEventListener listener)
Removes an event listener
|
void |
removeSchemalessEventListener(DataManagerSchemalessEvent.FireTime fireTime,
EventHandler<DataManagerSchemalessEvent> listener)
Removes an event listener
|
void |
rollback(java.lang.String schema)
removes the DataNode corresponding to the schema prior to flush being called
|
DataManager |
setDatabaseSchema(DatabaseSchema s)
Manually set the DatabaseSchema.
|
void |
setMergeEnabled(java.lang.String table,
boolean merge)
Sets all the nodes to be able to merge the values with the corresponding rows in the table when there is a primary key match.
|
void |
setUpdateEnabled(java.lang.String table,
boolean update)
Sets all the nodes to be able to overwrite columns in the table with the new values when there is a primary key match.
|
boolean |
write()
writes out the root dataNode(without clearing the data structure) with the default DataWriter
|
protected final java.lang.Object rootLock
protected RootNode root
@NotNull protected final EventEngine eventEngine
@Nullable protected CacheReaderWriter cacher
@Nullable protected CacheBlock currentCacheBlock
@Nullable protected DatabaseSchema schema
protected java.util.Set<java.lang.String> updateable
protected java.util.Set<java.lang.String> mergeable
public BasicDataManager()
public void buildSchemas()
DataManager
buildSchemas
in interface DataManager
@NotNull @InternalOnly public DataWriter getNewDataWriter()
@InternalOnly public boolean importSchemas(java.lang.String file)
@NotNull @InternalOnly public java.util.Set<java.lang.String> getColumns(java.lang.String table)
DataManager
getColumns
in interface DataManager
table
- The schema to get columns for@NotNull public RelationalSchema getSchema(@NotNull java.lang.String table)
getSchema
in interface DataManager
table
- The table for which to get a schemapublic boolean hasSchema(@NotNull java.lang.String table)
DataManager
hasSchema
in interface DataManager
table
- The schema to check forpublic void setUpdateEnabled(java.lang.String table, boolean update)
table
- The name of the tableupdate
- Sets whether updates should occur for the tablepublic void setMergeEnabled(java.lang.String table, boolean merge)
table
- The name of the tablemerge
- Sets whether merging should occur for the tablepublic void addData(java.lang.String schema, java.util.Map<java.lang.String,java.lang.Object> data)
addData
in interface DataManager
schema
- The schema to add data fordata
- The data to addpublic void addData(java.lang.String schema, java.lang.String columnName, java.lang.Object value)
addData
in interface DataManager
schema
- The schema for which to add datacolumnName
- The name of the column in the databasevalue
- The value to addpublic boolean commit(java.lang.String schema)
commit
in interface DataManager
schema
- The name of the schema for which to commit datapublic boolean checkDataNode(java.lang.String schema)
checkDataNode
in interface DataManager
schema
- The name of the schema for which to check the current nodepublic DataNode getCurrentDataNode(java.lang.String schema)
getCurrentDataNode
in interface DataManager
schema
- The name of the schema for which to retrieve the current nodepublic void rollback(java.lang.String schema)
schema
- The name of the schema to rollbackprotected void connectTree(@NotNull DataNode dataNode)
dataNode
- Connects tree elements for this node@NotNull public DataNode getNewDataNode(@NotNull java.lang.String table)
getNewDataNode
in interface DataManager
table
- The name of the table for which to create a new nodepublic void addData(@Nullable DataNode dataNode)
addData
in interface DataManager
dataNode
- The node to addpublic void enablePageAndContextCaching(@Nullable java.lang.String mainSchema, @Nullable CacheReaderWriter cacher)
mainSchema
- The name of the main schema (must have a integer or long value for the primary key)cacher
- The cacher to usepublic void cacheScrapeableFile(@NotNull ScrapeableFile scrapeableFile)
scrapeableFile
- The scrapeable file to cachepublic void cacheScrapeableFile(@NotNull ScrapeableFile scrapeableFile, boolean includeHeaders)
scrapeableFile
- The scrapeable file to cacheincludeHeaders
- True if headers should be included in the cached content, false to exclude thempublic void cacheContent(@NotNull java.lang.String name, @NotNull java.lang.String content)
name
- The name to use when caching the datacontent
- The content to cachepublic void cacheContent(@NotNull java.lang.String name, @NotNull java.lang.String content, @Nullable java.lang.String url)
name
- The name to use when caching the datacontent
- The content to cacheurl
- The url the content came from.public void cacheContent(@NotNull java.lang.String name, @NotNull java.lang.String content, @Nullable java.lang.String url, @Nullable java.lang.String contentType)
name
- The name to use when caching the datacontent
- The content to cacheurl
- The url the content came from.contentType
- The content type, such as application/json or text/htmlpublic void cacheContext(@NotNull java.util.Map<java.lang.String,?> contextValues)
contextValues
- The values to save as context@Nullable public CacheReaderWriter getCacheReaderWriter()
public void clearAllData()
clearAllData
in interface DataManager
public boolean flush()
DataManager
flush
in interface DataManager
@InternalOnly public boolean write()
public RootNode getRoot()
getRoot
in interface DataManager
@InternalOnly public static java.lang.String generateUID(java.lang.String name) throws java.security.NoSuchAlgorithmException
name
- A name to generate a UID forjava.security.NoSuchAlgorithmException
- If the needed digest algorithm isn't available (this should never happen)@NotNull @InternalOnly public static java.lang.String hashData(java.util.SortedMap<java.lang.String,DataObject> map)
map
- The map of data to hash@NotNull @InternalOnly public static java.lang.String hashData(@Nullable DataNode dataNode, @Nullable java.util.Set<java.lang.String> columns)
dataNode
- The node for which to hash datacolumns
- The columns to hash@InternalOnly public static java.lang.String catData(@Nullable java.util.SortedMap<java.lang.String,DataObject> m)
m
- Sorted map to generate a cat String from.@InternalOnly public static java.lang.String catData(@Nullable DataNode dataNode, @Nullable java.util.Set<java.lang.String> columns)
dataNode
- The node for which to cat datacolumns
- The columns to catpublic void close()
DataManager
close
in interface DataManager
public void clearData(java.lang.String schema)
DataManager
clearData
in interface DataManager
schema
- The name of the schema@NotNull public DataManager setDatabaseSchema(DatabaseSchema s)
DataManager
setDatabaseSchema
in interface DataManager
s
- The schema to set@Nullable public DatabaseSchema getDatabaseSchema()
DataManager
getDatabaseSchema
in interface DataManager
@NotNull public DataManagerEventListener addDataAssertion(@NotNull DataAssertion d)
d
- The assertion to add@NotNull public DataManagerEventListener addDataAssertion(@NotNull DataAssertion d, DataManagerEventSource.EventFireTime when)
d
- The assertion to addwhen
- The time to fire the assertion@NotNull public EventHandler<DataManagerSchemalessEvent> addSchemalessEventListener(@NotNull DataManagerSchemalessEvent.FireTime fireTime, @NotNull EventHandler<DataManagerSchemalessEvent> listener)
fireTime
- The time at which to fire the eventlistener
- The listener to handle the event@NotNull public EventHandler<DataManagerSchemalessEvent> addSchemalessEventListenerWithPriority(@NotNull DataManagerSchemalessEvent.FireTime fireTime, @NotNull EventHandler<DataManagerSchemalessEvent> listener, int priority)
fireTime
- The time at which to fire the eventlistener
- The listener to handle the eventpriority
- The priority, with lower numbers being higher prioritypublic void removeSchemalessEventListener(@NotNull DataManagerSchemalessEvent.FireTime fireTime, @NotNull EventHandler<DataManagerSchemalessEvent> listener)
fireTime
- The time at which the listener was set to firelistener
- The listener to remove@NotNull public DataManagerEventListener addEventListener(@NotNull java.lang.String schema, java.lang.String when, DataManagerEventListener listener)
schema
- The schema to add the listener towhen
- When the event should firelistener
- The listener that will handle the event@NotNull public DataManagerEventListener addEventListener(@NotNull java.lang.String schema, DataManagerEventSource.EventFireTime when, DataManagerEventListener listener)
DataManager
addEventListener
in interface DataManager
schema
- The schema the event will be added forwhen
- The time the event should firelistener
- The listener that will handle the event@NotNull public DataManagerEventListener addEventListenerWithPriority(@NotNull java.lang.String schema, DataManagerEventSource.EventFireTime when, DataManagerEventListener listener, int priority)
DataManager
addEventListenerWithPriority
in interface DataManager
schema
- The schema the event will be added forwhen
- The time when the event should firelistener
- The listener that will handle the eventpriority
- The priority for the event, with lower numbers being higher prioritypublic void removeEventListener(@NotNull java.lang.String schema, DataManagerEventSource.EventFireTime when, DataManagerEventListener listener)
schema
- The schema to remove the listener fromwhen
- When the event would firelistener
- The listener that will be removed