public class AsynchronousDBConnection extends java.lang.Object implements DBConnection
All the tasks are queued and executed parallel to the processing tasks. We plan to use this kind of connection for operations like saving a model that require a lot of processing.
Constructor and Description |
---|
AsynchronousDBConnection()
Construct an instance that creates the taskQueue to enqueue tasks
and the executor thread that enables task execution in parallel.
|
Modifier and Type | Method and Description |
---|---|
void |
abortConnection()
Abort the execution by setting the execution flag as false.
|
void |
closeConnection()
Close the connection if all tasks in the queue
are executed successfully.
|
void |
commitConnection()
Commit the transaction running over the connection.
|
java.util.ArrayList<XMLDBModel> |
executeAttributeSearchTask(AttributeSearchTask task)
Search models that contain the given attributes in the database.
|
XMLDBAttribute |
executeCreateAttributeTask(CreateAttributeTask task)
Execute the necessary commands to create a new attribute in the database
according to the attribute specification given in the task parameter.
|
java.lang.String |
executeCreateModelTask(CreateModelTask task)
Execute the necessary commands to create a new model in the database according
to the model specification given in the task parameter.
|
void |
executeDeleteAttributeTask(DeleteAttributeTask task)
Execute the necessary commands to delete an attribute from the database
according to the attribute specification given in the task parameter.
|
java.util.ArrayList<XMLDBModel> |
executeFetchHierarchyTask(FetchHierarchyTask task)
Execute Fetch Hierarchy task.
|
java.util.List<XMLDBAttribute> |
executeGetAttributesTask(GetAttributesTask task)
Get Attributes Task is not supported by the asynchronous connection.
|
XMLDBModel |
executeGetCompleteModelTask(GetModelTask task)
Execute the necessary commands to retrieve a model from the database
and resolve all the references in it if any.
|
java.util.List<XMLDBModel> |
executeGetFirstLevelParents(GetFirstLevelParentsTask task)
Fetch the first level parents for the given model is not supported by
this connection.
|
java.util.List<XMLDBModel> |
executeGetListOfAllModels()
Retrieve and return the list of all models in the database.
|
XMLDBModel |
executeGetModelTask(GetModelTask task)
Execute the necessary commands to retrieve a model from the database.
|
java.lang.String |
executeGetReferenceStringTask(GetReferenceStringTask task)
Get the model reference string is not supported by the asynchronous
connection.
|
java.util.ArrayList<XMLDBModel> |
executeGraphSearchTask(GraphSearchTask task)
Search for graph is not supported by the asynchronous connection.
|
java.util.ArrayList<XMLDBModel> |
executeModelNameSearchTask(ModelNameSearchTask modelNameSearchTask)
Execute the model name search task is not supported by the asynchronous
connection.
|
void |
executeRemoveModelsTask(RemoveModelsTask task)
Execute remove models task to delete a list of models from the database.
|
void |
executeRenameModelTask(RenameModelTask task)
Execute rename model task which will change the name of the model in
the database and reflect the change in the reference file.
|
java.lang.String |
executeSaveModelTask(SaveModelTask task)
Execute the necessary commands to save/update a model in the
database according
to the model specification given in the task parameter.
|
void |
executeUpdateAttributeTask(UpdateAttributeTask task)
Execute the necessary commands to update an attribute in the database
according to the attribute specification given in the task parameter.
|
void |
executeUpdateModelInCache(XMLDBModel xmlDBModel)
Execute the necessary commands to update the cache with the given model.
|
void |
executeUpdateParentsToNewVersion(UpdateParentsToNewVersionTask task)
Execute the given task to update the referenced version for the given
parents from the old model to the new model.
|
java.lang.String |
toString()
Return a string representation for the
internal parameters of the class.
|
public AsynchronousDBConnection() throws DBConnectionException
DBConnectionException
- If thrown while
creating a connection.public void abortConnection()
abortConnection
in interface DBConnection
public void closeConnection() throws DBConnectionException
closeConnection
in interface DBConnection
DBConnectionException
- If thrown while
closing a connection.public void commitConnection() throws DBConnectionException
commitConnection
in interface DBConnection
DBConnectionException
- If thrown while committing a
transaction in the database.public java.util.ArrayList<XMLDBModel> executeAttributeSearchTask(AttributeSearchTask task) throws DBExecutionException
executeAttributeSearchTask
in interface DBConnection
task
- Task that contains a list of attributes that
need to be searched in the database.DBExecutionException
- If thrown while searching.public XMLDBAttribute executeCreateAttributeTask(CreateAttributeTask task) throws DBExecutionException
executeCreateAttributeTask
in interface DBConnection
task
- The task to be completed. In this case, CreateAttributeTask.
This will tell the DB layer to create a new attribute in the database.DBExecutionException
- Thrown if the operation fails.public java.lang.String executeCreateModelTask(CreateModelTask task) throws DBExecutionException, ModelAlreadyExistException
executeCreateModelTask
in interface DBConnection
task
- The task to be completed. In this case, CreateModelTask.
This will tell the DB layer to create a new model in the database.DBExecutionException
- If thrown while creating a model.ModelAlreadyExistException
- Thrown if the model being created already exists.public void executeDeleteAttributeTask(DeleteAttributeTask task) throws DBExecutionException
executeDeleteAttributeTask
in interface DBConnection
task
- The task to be completed. In this case, DeleteAttributeTask.
This will tell the DB layer to delete an attribute from the database.DBExecutionException
- Thrown if the operation fails.public java.util.ArrayList<XMLDBModel> executeFetchHierarchyTask(FetchHierarchyTask task) throws DBExecutionException
Fetch the parent model hierarchies is not supported by the asynchronous connection. Use a synchronous connection for that.
executeFetchHierarchyTask
in interface DBConnection
task
- Task that contains the list of models.DBExecutionException
- If thrown while searching.public java.util.List<XMLDBAttribute> executeGetAttributesTask(GetAttributesTask task) throws DBExecutionException
executeGetAttributesTask
in interface DBConnection
task
- The task to be completed.DBExecutionException
- If thrown while getting attributes from the
database.public java.util.List<XMLDBModel> executeGetFirstLevelParents(GetFirstLevelParentsTask task) throws DBExecutionException
executeGetFirstLevelParents
in interface DBConnection
task
- Task that contains the model for which the first level
parents list needs to be fetched.DBExecutionException
- If thrown while fetching the parents list
from the database.public java.lang.String executeGetReferenceStringTask(GetReferenceStringTask task) throws DBExecutionException
executeGetReferenceStringTask
in interface DBConnection
task
- Task that contains the model name.DBExecutionException
- If thrown while fetching the reference
string.public XMLDBModel executeGetModelTask(GetModelTask task) throws DBExecutionException
executeGetModelTask
in interface DBConnection
task
- The task to be completed. In this case, GetModelTask.
This will tell the DB layer to return the specified model.DBExecutionException
- Thrown if the operations fails.public XMLDBModel executeGetCompleteModelTask(GetModelTask task) throws DBExecutionException
executeGetCompleteModelTask
in interface DBConnection
task
- The task to be completed. In this case, GetModelTask.
This will tell the DB layer to return the specified model.DBExecutionException
- Thrown if the operations fails.public java.util.List<XMLDBModel> executeGetListOfAllModels() throws DBExecutionException
executeGetListOfAllModels
in interface DBConnection
DBExecutionException
- thrown if there is an error while reading
the model list from the database.public java.util.ArrayList<XMLDBModel> executeGraphSearchTask(GraphSearchTask task) throws DBExecutionException
executeGraphSearchTask
in interface DBConnection
task
- - Task that contains the graph search criteria.DBExecutionException
- If thrown while searching
in the database.public java.util.ArrayList<XMLDBModel> executeModelNameSearchTask(ModelNameSearchTask modelNameSearchTask) throws DBExecutionException
executeModelNameSearchTask
in interface DBConnection
modelNameSearchTask
- Task that contains the model name to be
searched for.DBExecutionException
- If thrown while searching the database.public java.lang.String executeSaveModelTask(SaveModelTask task) throws DBExecutionException
executeSaveModelTask
in interface DBConnection
task
- The task to be completed. In this case, SaveModelTask.
This will tell the DB layer to save/update a model
already existing in the database.DBExecutionException
- If thrown while saving model
in the database.public void executeRemoveModelsTask(RemoveModelsTask task) throws DBExecutionException
executeRemoveModelsTask
in interface DBConnection
task
- Contains a list of models to be deleted from the database.DBExecutionException
- Thrown if the operation fails.public void executeRenameModelTask(RenameModelTask task) throws DBConnectionException, DBExecutionException, ModelAlreadyExistException, DBModelNotFoundException
executeRenameModelTask
in interface DBConnection
task
- RenameModelTask object that contains the XMLDBModel
object and the new name.DBConnectionException
- Thrown if there was a problem with the connection.DBExecutionException
- Thrown if there is a problem in executing the task.DBModelNotFoundException
- Thrown if the model with the name to be changed does not exist.ModelAlreadyExistException
- Thrown if the new name is a name of a model that is already in the database.public void executeUpdateAttributeTask(UpdateAttributeTask task) throws DBExecutionException
executeUpdateAttributeTask
in interface DBConnection
task
- The task to be completed. In this case, UpdateAttributeTask.
This will tell the DB layer to update an attribute in the database.DBExecutionException
- Thrown if the operation fails.public void executeUpdateModelInCache(XMLDBModel xmlDBModel) throws DBExecutionException
If the model exists, replace it with the new model.
If the model does not exist, save it in the cache.
executeUpdateModelInCache
in interface DBConnection
xmlDBModel
- The model object that needs to be added to the cache.DBExecutionException
- Thrown if the operation fails.
already exists.public void executeUpdateParentsToNewVersion(UpdateParentsToNewVersionTask task) throws DBExecutionException
executeUpdateParentsToNewVersion
in interface DBConnection
task
- Task that contains the list of parents, the old model and the
new model.DBExecutionException
- If thrown while updating the parents in the
database.public java.lang.String toString()
toString
in class java.lang.Object