JBoss.orgCommunity Documentation
There is two methods of DBCleanerService:
Table 43.1. API
| public static void removeWorkspaceData(WorkspaceEntry wsConfig) | If workspace is multiDB - drops JCR_SITEM,JCR_SVALUE, JCR_SREF tables, otherwise, it removes all rows of this workspace. |
| public static void removeRepositoryData(RepositoryEntry repoConfig) | Removes data of all worksapces of this repository. |
removeWorkspaceData takes workspaces configs from RepositoryEntry and clean each workspace using removeRepositoryData.
Lets see removeWorkspaceData in detail:
at first, it ejects workspace name (aka container name), data source of databse, and and deside is workspase multiDB or singleDB;
than it deside which script must be used to remove (databse dialect and isMultiDb used);
than this script is parsed to list of queries, and executed in order of occurance;
Single and Multi DB scripts examples
In case of: dbDialect = "MySQL" and isMultiDB="true", will use "conf/storage/cleanup/jcr-mjdbc.mysql.sql"
DROP TABLE JCR_MREF; DROP TABLE JCR_MVALUE; DROP TABLE JCR_MITEM;
In case of: dbDialect = "PgSQL" and isMultiDB="false", will use "conf/storage/cleanup/jcr-sjdbc.pgsql.sql"
delete from JCR_SVALUE where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME=?); delete from JCR_SREF where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SREF.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME=?); delete from JCR_SITEM where CONTAINER_NAME=?;
"?" will be replased with container name on execution.
But what is the strage coment is in "conf/storage/cleanup/jcr-sjdbc.sql" ?
delete from JCR_SVALUE where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME=?); delete from JCR_SREF where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SREF.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME=?); delete from JCR_SITEM where I_CLASS=2 and CONTAINER_NAME=?; /*$CLEAN_JCR_SITEM_DEFAULT*/;
/*$CLEAN_JCR_SITEM_DEFAULT*/ - some database may throw constraint violaion exception according to JCR_FK_SITEM_PARENT FOREIGN KEY in case of ordinary "" delete from JCR_SITEM where CONTAINER_NAME=? query. So there is special method, that will be executed on /*$CLEAN_JCR_SITEM_DEFAULT*/. It a bit slowly, but safe.
"conf/storage/cleanup/jcr-sjdbc.sql" or "conf/storage/cleanup/jcr-mjdbc.sql" are used if dialect is not recognized.