From c2cca0311b8da971a4c724c84b16dc4ef20caf18 Mon Sep 17 00:00:00 2001 From: Jan Vonka Date: Tue, 8 Sep 2009 09:55:22 +0000 Subject: [PATCH] AVM DAO refactor git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16138 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/attributes-service-context.xml | 25 +- config/alfresco/avm-services-context.xml | 129 +-- config/alfresco/bootstrap-context.xml | 1 + config/alfresco/cache-context.xml | 193 +++- config/alfresco/content-services-context.xml | 2 +- config/alfresco/dao/dao-context.xml | 44 + .../AlfrescoPostCreate-2.2-Extra.sql | 12 - .../AlfrescoPostCreate-3.2-AvmTables.sql | 248 +++++ config/alfresco/ehcache-default.xml | 93 +- .../avm-lookup-cache-context.xml.sample | 57 - .../ehcache-custom.xml.sample.cluster | 196 +--- config/alfresco/hibernate-context.xml | 7 +- .../alfresco/ibatis/alfresco-SqlMapConfig.xml | 2 + config/alfresco/ibatis/ibatis-context.xml | 153 +-- .../avm-common-SqlMap.xml | 988 ++++++++++++++++++ .../avm-insert-SqlMap.xml | 37 + .../alfresco/patch/patch-services-context.xml | 90 +- config/alfresco/public-services-context.xml | 1 - .../repo/admin/patch/impl/AVMGuidPatch.java | 22 +- .../patch/impl/AVMLayeredSnapshotPatch.java | 36 +- .../admin/patch/impl/AVMPermissionsPatch.java | 133 --- .../MoveWCMToGroupBasedPermissionsPatch.java | 67 -- .../admin/patch/impl/WCMPermissionPatch.java | 339 ------ .../hibernate/AttributeDAOHibernate.java | 7 +- .../java/org/alfresco/repo/avm/AVMDAOs.java | 32 +- .../repo/avm/AVMDiffPerformanceTest.java | 57 +- .../java/org/alfresco/repo/avm/AVMNode.java | 37 +- .../org/alfresco/repo/avm/AVMNodeDAO.java | 87 +- .../org/alfresco/repo/avm/AVMNodeImpl.java | 146 ++- .../alfresco/repo/avm/AVMNodeUnwrapper.java | 7 +- .../org/alfresco/repo/avm/AVMRepository.java | 158 ++- .../repo/avm/AVMServiceIndexTest.java | 7 +- .../repo/avm/AVMServiceLocalTest.java | 5 + .../alfresco/repo/avm/AVMServicePerfTest.java | 158 +-- .../repo/avm/AVMServicePermissionsTest.java | 21 +- .../org/alfresco/repo/avm/AVMServiceTest.java | 14 +- .../org/alfresco/repo/avm/AVMStoreImpl.java | 456 ++++---- .../alfresco/repo/avm/AVMStoreProperty.java | 11 +- .../repo/avm/AVMStorePropertyDAO.java | 18 +- .../repo/avm/AVMStorePropertyImpl.java | 19 +- .../alfresco/repo/avm/AVMSyncServiceImpl.java | 4 +- .../repo/avm/BasicAttributesImpl.java | 27 +- .../org/alfresco/repo/avm/ChildEntryDAO.java | 10 +- .../org/alfresco/repo/avm/ChildEntryImpl.java | 9 +- .../alfresco/repo/avm/DeletedNodeImpl.java | 22 +- .../alfresco/repo/avm/DirectoryNodeImpl.java | 19 +- .../alfresco/repo/avm/HistoryLinkImpl.java | 4 +- .../java/org/alfresco/repo/avm/Layered.java | 27 +- .../repo/avm/LayeredDirectoryNodeImpl.java | 203 ++-- .../repo/avm/LayeredFileNodeImpl.java | 45 +- source/java/org/alfresco/repo/avm/Lookup.java | 5 +- .../org/alfresco/repo/avm/MergeLinkImpl.java | 4 +- .../alfresco/repo/avm/NOOPLookupCache.java | 1 - .../org/alfresco/repo/avm/OrphanReaper.java | 12 +- .../repo/avm/PlainDirectoryNodeImpl.java | 61 +- .../alfresco/repo/avm/PlainFileNodeImpl.java | 49 +- .../repo/avm/TransactionalLookupCache.java | 3 +- .../org/alfresco/repo/avm/VersionRootDAO.java | 6 +- .../avm/actions/SimpleAVMSubmitAction.java | 2 - .../alfresco/repo/avm/hibernate/AVM.hbm.xml | 376 ------- .../avm/hibernate/AVMNodeDAOHibernate.java | 318 ------ .../avm/hibernate/AVMStoreDAOHibernate.java | 169 --- .../AVMStorePropertyDAOHibernate.java | 214 ---- .../avm/hibernate/ChildEntryDAOHibernate.java | 181 ---- .../hibernate/HistoryLinkDAOHibernate.java | 91 -- .../avm/hibernate/MergeLinkDAOHibernate.java | 91 -- .../avm/hibernate/SessionCacheChecker.java | 62 -- .../hibernate/VersionRootDAOHibernate.java | 210 ---- .../repo/avm/ibatis/AVMNodeDAOIbatis.java | 502 +++++++++ .../repo/avm/ibatis/AVMStoreDAOIbatis.java | 163 +++ .../avm/ibatis/AVMStorePropertyDAOIbatis.java | 143 +++ .../repo/avm/ibatis/ChildEntryDAOIbatis.java | 172 +++ .../repo/avm/ibatis/HistoryLinkDAOIbatis.java | 100 ++ .../repo/avm/ibatis/MergeLinkDAOIbatis.java | 100 ++ .../VersionLayeredNodeEntryDAOIbatis.java} | 153 +-- .../repo/avm/ibatis/VersionRootDAOIbatis.java | 191 ++++ .../alfresco/repo/avm/util/BulkLoader.java | 22 +- .../repo/avm/wf/AVMSubmitPackageHandler.java | 2 - .../repo/cache/lookup/EntityLookupCache.java | 15 +- .../content/cleanup/ContentStoreCleaner.java | 5 +- .../cleanup/ContentStoreCleanerTest.java | 6 +- .../repo/domain/avm/AVMAspectEntity.java | 70 ++ .../repo/domain/avm/AVMChildEntryEntity.java | 122 +++ .../repo/domain/avm/AVMHistoryLinkEntity.java | 72 ++ .../repo/domain/avm/AVMMergeLinkEntity.java | 69 ++ .../repo/domain/avm/AVMNodeAspectEntity.java | 72 ++ .../domain/avm/AVMNodeChildEntryEntity.java | 86 ++ .../alfresco/repo/domain/avm/AVMNodeDAO.java | 141 +++ .../repo/domain/avm/AVMNodeEntity.java | 410 ++++++++ .../repo/domain/avm/AVMNodeLinksDAO.java | 110 ++ .../domain/avm/AVMNodePropertyEntity.java | 104 ++ .../alfresco/repo/domain/avm/AVMStoreDAO.java | 126 +++ .../repo/domain/avm/AVMStoreDAOTest.java | 189 ++++ .../repo/domain/avm/AVMStoreEntity.java | 143 +++ .../domain/avm/AVMStorePropertyEntity.java | 128 +++ .../avm/AVMVersionLayeredNodeEntryEntity.java | 70 ++ .../repo/domain/avm/AVMVersionRootDAO.java | 112 ++ .../repo/domain/avm/AVMVersionRootEntity.java | 170 +++ .../domain/avm/AbstractAVMNodeDAOImpl.java | 713 +++++++++++++ .../avm/AbstractAVMNodeLinksDAOImpl.java | 527 ++++++++++ .../domain/avm/AbstractAVMStoreDAOImpl.java | 556 ++++++++++ .../avm/AbstractAVMVersionRootDAOImpl.java | 292 ++++++ .../domain/avm/ibatis/AVMNodeDAOImpl.java | 315 ++++++ .../avm/ibatis/AVMNodeLinksDAOImpl.java | 213 ++++ .../domain/avm/ibatis/AVMStoreDAOImpl.java | 196 ++++ .../avm/ibatis/AVMVersionRootDAOImpl.java | 206 ++++ .../domain/hibernate/AclDaoComponentImpl.java | 174 +-- .../repo/domain/hibernate/Permission.hbm.xml | 63 +- .../hibernate/SessionSizeResourceManager.java | 6 - .../domain/patch/AbstractPatchDAOImpl.java | 72 ++ .../alfresco/repo/domain/patch/PatchDAO.java | 49 + .../domain/patch/ibatis/PatchDAOImpl.java | 79 ++ .../alfresco/service/cmr/avm/AVMService.java | 8 +- 113 files changed, 9654 insertions(+), 3923 deletions(-) create mode 100644 config/alfresco/dbscripts/create/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-AvmTables.sql delete mode 100644 config/alfresco/extension/avm-lookup-cache-context.xml.sample create mode 100644 config/alfresco/ibatis/org.hibernate.dialect.Dialect/avm-common-SqlMap.xml create mode 100644 config/alfresco/ibatis/org.hibernate.dialect.MySQLInnoDBDialect/avm-insert-SqlMap.xml delete mode 100644 source/java/org/alfresco/repo/admin/patch/impl/AVMPermissionsPatch.java delete mode 100644 source/java/org/alfresco/repo/admin/patch/impl/WCMPermissionPatch.java delete mode 100644 source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml delete mode 100644 source/java/org/alfresco/repo/avm/hibernate/AVMNodeDAOHibernate.java delete mode 100644 source/java/org/alfresco/repo/avm/hibernate/AVMStoreDAOHibernate.java delete mode 100644 source/java/org/alfresco/repo/avm/hibernate/AVMStorePropertyDAOHibernate.java delete mode 100644 source/java/org/alfresco/repo/avm/hibernate/ChildEntryDAOHibernate.java delete mode 100644 source/java/org/alfresco/repo/avm/hibernate/HistoryLinkDAOHibernate.java delete mode 100644 source/java/org/alfresco/repo/avm/hibernate/MergeLinkDAOHibernate.java delete mode 100644 source/java/org/alfresco/repo/avm/hibernate/SessionCacheChecker.java delete mode 100644 source/java/org/alfresco/repo/avm/hibernate/VersionRootDAOHibernate.java create mode 100644 source/java/org/alfresco/repo/avm/ibatis/AVMNodeDAOIbatis.java create mode 100644 source/java/org/alfresco/repo/avm/ibatis/AVMStoreDAOIbatis.java create mode 100644 source/java/org/alfresco/repo/avm/ibatis/AVMStorePropertyDAOIbatis.java create mode 100644 source/java/org/alfresco/repo/avm/ibatis/ChildEntryDAOIbatis.java create mode 100644 source/java/org/alfresco/repo/avm/ibatis/HistoryLinkDAOIbatis.java create mode 100644 source/java/org/alfresco/repo/avm/ibatis/MergeLinkDAOIbatis.java rename source/java/org/alfresco/repo/avm/{hibernate/VersionLayeredNodeEntryDAOHibernate.java => ibatis/VersionLayeredNodeEntryDAOIbatis.java} (57%) create mode 100644 source/java/org/alfresco/repo/avm/ibatis/VersionRootDAOIbatis.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMAspectEntity.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMChildEntryEntity.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMHistoryLinkEntity.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMMergeLinkEntity.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMNodeAspectEntity.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMNodeChildEntryEntity.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMNodeDAO.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMNodeEntity.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMNodeLinksDAO.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMNodePropertyEntity.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMStoreDAO.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMStoreDAOTest.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMStoreEntity.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMStorePropertyEntity.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMVersionLayeredNodeEntryEntity.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMVersionRootDAO.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AVMVersionRootEntity.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AbstractAVMNodeDAOImpl.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AbstractAVMNodeLinksDAOImpl.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AbstractAVMStoreDAOImpl.java create mode 100644 source/java/org/alfresco/repo/domain/avm/AbstractAVMVersionRootDAOImpl.java create mode 100644 source/java/org/alfresco/repo/domain/avm/ibatis/AVMNodeDAOImpl.java create mode 100644 source/java/org/alfresco/repo/domain/avm/ibatis/AVMNodeLinksDAOImpl.java create mode 100644 source/java/org/alfresco/repo/domain/avm/ibatis/AVMStoreDAOImpl.java create mode 100644 source/java/org/alfresco/repo/domain/avm/ibatis/AVMVersionRootDAOImpl.java create mode 100644 source/java/org/alfresco/repo/domain/patch/AbstractPatchDAOImpl.java create mode 100644 source/java/org/alfresco/repo/domain/patch/PatchDAO.java create mode 100644 source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java diff --git a/config/alfresco/attributes-service-context.xml b/config/alfresco/attributes-service-context.xml index 4d468fa4c6..8f59d61e67 100644 --- a/config/alfresco/attributes-service-context.xml +++ b/config/alfresco/attributes-service-context.xml @@ -4,6 +4,29 @@ + + + + + + + + 500 + + + 250 + + + + + + + + + 100 + + + org.alfresco.service.cmr.attributes.AttributeService @@ -13,7 +36,7 @@ - avmSessionSizeResourceInterceptor + attrSessionSizeResourceInterceptor diff --git a/config/alfresco/avm-services-context.xml b/config/alfresco/avm-services-context.xml index 3d30520a9e..92412f7ced 100644 --- a/config/alfresco/avm-services-context.xml +++ b/config/alfresco/avm-services-context.xml @@ -4,79 +4,58 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + @@ -295,27 +274,5 @@ workspace://SpacesStore - - - - - - - - - 500 - - - 250 - - - - - - - - - 100 - - + diff --git a/config/alfresco/bootstrap-context.xml b/config/alfresco/bootstrap-context.xml index 415079a0e5..53c7e94a20 100644 --- a/config/alfresco/bootstrap-context.xml +++ b/config/alfresco/bootstrap-context.xml @@ -80,6 +80,7 @@ classpath:alfresco/dbscripts/create/3.2/${db.script.dialect}/AlfrescoPostCreate-3.2-ContentTables.sql classpath:alfresco/dbscripts/create/3.2/${db.script.dialect}/AlfrescoPostCreate-3.2-PropertyValueTables.sql classpath:alfresco/dbscripts/create/3.2/${db.script.dialect}/AlfrescoPostCreate-3.2-AuditTables.sql + classpath:alfresco/dbscripts/create/3.2/${db.script.dialect}/AlfrescoPostCreate-3.2-AvmTables.sql diff --git a/config/alfresco/cache-context.xml b/config/alfresco/cache-context.xml index d74d787452..4de375f170 100644 --- a/config/alfresco/cache-context.xml +++ b/config/alfresco/cache-context.xml @@ -530,42 +530,173 @@ + - + - - - - - - - - - - - org.alfresco.repo.avm.storeLookupSharedCache - - - - - - + + - - - - - - - - - org.alfresco.repo.avm.storeLookupTransactionalCache - - - 200 - + + + + + + + + org.alfresco.cache.avm.avmStoreCache + + + + + + + + + + + + + + + + + org.alfresco.cache.avmStoreTransactionalCache + + + 1000 + + + + + + + + + + + + + org.alfresco.cache.avm.avmEntityCache + + + + + + + + + + + + + + org.alfresco.cache.avmEntityTransactionalCache + + + 1000 + + + + + + + + + + + + + org.alfresco.cache.avm.avmVersionRootEntityCache + + + + + + + + + + + + + + + + org.alfresco.cache.avmVersionRootEntityTransactionalCache + + + 100 + + + + + + + + + + + + + org.alfresco.cache.avm.avmNodeCache + + + + + + + + + + + + + + + + org.alfresco.cache.avmNodeTransactionalCache + + + 1000 + + + + + + + + + + + + + + org.alfresco.cache.avm.avmNodeAspectsCache + + + + + + + + + + + + + + + + org.alfresco.cache.avmNodeAspectsTransactionalCache + + + 100 + + + diff --git a/config/alfresco/content-services-context.xml b/config/alfresco/content-services-context.xml index c3fb0224bb..54a7794934 100644 --- a/config/alfresco/content-services-context.xml +++ b/config/alfresco/content-services-context.xml @@ -53,7 +53,7 @@ - + diff --git a/config/alfresco/dao/dao-context.xml b/config/alfresco/dao/dao-context.xml index 3d45b80334..aa4cbbb7a5 100644 --- a/config/alfresco/dao/dao-context.xml +++ b/config/alfresco/dao/dao-context.xml @@ -64,4 +64,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/alfresco/dbscripts/create/2.2/org.hibernate.dialect.Dialect/AlfrescoPostCreate-2.2-Extra.sql b/config/alfresco/dbscripts/create/2.2/org.hibernate.dialect.Dialect/AlfrescoPostCreate-2.2-Extra.sql index 6599634fd8..59423d243f 100644 --- a/config/alfresco/dbscripts/create/2.2/org.hibernate.dialect.Dialect/AlfrescoPostCreate-2.2-Extra.sql +++ b/config/alfresco/dbscripts/create/2.2/org.hibernate.dialect.Dialect/AlfrescoPostCreate-2.2-Extra.sql @@ -39,15 +39,3 @@ ALTER TABLE alf_node_properties ADD CONSTRAINT fk_alf_nprop_loc FOREIGN KEY (loc CREATE INDEX fk_alf_perm_tqn ON alf_permission (type_qname_id); ALTER TABLE alf_permission ADD CONSTRAINT fk_alf_perm_tqn FOREIGN KEY (type_qname_id) REFERENCES alf_qname (id); -CREATE INDEX fk_avm_nasp_qn ON avm_aspects (qname_id); -ALTER TABLE avm_aspects ADD CONSTRAINT fk_avm_nasp_qn FOREIGN KEY (qname_id) REFERENCES alf_qname (id); - -CREATE INDEX fk_avm_nprop_qn ON avm_node_properties (qname_id); -ALTER TABLE avm_node_properties ADD CONSTRAINT fk_avm_nprop_qn FOREIGN KEY (qname_id) REFERENCES alf_qname (id); - -CREATE INDEX fk_avm_sprop_qname ON avm_store_properties (qname_id); -ALTER TABLE avm_store_properties ADD CONSTRAINT fk_avm_sprop_qname FOREIGN KEY (qname_id) REFERENCES alf_qname (id); - -CREATE INDEX idx_avm_hl_revpk ON avm_history_links (descendent, ancestor); - -CREATE INDEX idx_avm_vr_revuq ON avm_version_roots (avm_store_id, version_id); diff --git a/config/alfresco/dbscripts/create/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-AvmTables.sql b/config/alfresco/dbscripts/create/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-AvmTables.sql new file mode 100644 index 0000000000..a5552fda73 --- /dev/null +++ b/config/alfresco/dbscripts/create/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-AvmTables.sql @@ -0,0 +1,248 @@ +-- +-- Title: Create AVM tables +-- Database: MySQL InnoDB +-- Since: V3.2.0 Schema 3002 +-- Author: janv +-- +-- Please contact support@alfresco.com if you need assistance with the upgrade. +-- + + create table avm_aspects ( + node_id bigint not null, + qname_id bigint not null, + primary key (node_id, qname_id) + ) type=InnoDB; + + create table avm_child_entries ( + parent_id bigint not null, + name varchar(160) not null, + child_id bigint not null, + primary key (parent_id, name) + ) type=InnoDB; + + create table avm_history_links ( + ancestor bigint not null, + descendent bigint not null, + primary key (ancestor, descendent) + ) type=InnoDB; + + create table avm_merge_links ( + mfrom bigint not null, + mto bigint not null, + primary key (mfrom, mto) + ) type=InnoDB; + + create table avm_node_properties ( + node_id bigint not null, + actual_type_n integer not null, + persisted_type_n integer not null, + multi_valued bit not null, + boolean_value bit, + long_value bigint, + float_value float, + double_value double precision, + string_value text, + serializable_value blob, + qname_id bigint not null, + primary key (node_id, qname_id) + ) type=InnoDB; + + create table avm_nodes ( + id bigint not null auto_increment, + class_type varchar(20) not null, + vers bigint not null, + version_id integer not null, + guid varchar(36), + creator varchar(255) not null, + owner varchar(255) not null, + lastModifier varchar(255) not null, + createDate bigint not null, + modDate bigint not null, + accessDate bigint not null, + is_root bit, + store_new_id bigint, + acl_id bigint, + deletedType integer, + layer_id bigint, + indirection text, + indirection_version integer, + primary_indirection bit, + opacity bit, + content_url varchar(128), + mime_type varchar(100), + encoding varchar(16), + length bigint, + primary key (id) + ) type=InnoDB; + + create table avm_store_properties ( + id bigint not null auto_increment, + avm_store_id bigint, + qname_id bigint not null, + actual_type_n integer not null, + persisted_type_n integer not null, + multi_valued bit not null, + boolean_value bit, + long_value bigint, + float_value float, + double_value double precision, + string_value text, + serializable_value blob, + primary key (id) + ) type=InnoDB; + + create table avm_stores ( + id bigint not null auto_increment, + vers bigint not null, + name varchar(255) unique, + next_version_id integer not null, + current_root_id bigint, + acl_id bigint, + primary key (id) + ) type=InnoDB; + + create table avm_version_layered_node_entry ( + version_root_id bigint not null, + md5sum varchar(32) not null, + path text, + primary key (version_root_id, md5sum) + ) type=InnoDB; + + create table avm_version_roots ( + id bigint not null auto_increment, + version_id integer not null, + avm_store_id bigint not null, + create_date bigint not null, + creator varchar(255) not null, + root_id bigint not null, + tag varchar(255), + description text, + primary key (id), + unique (version_id, avm_store_id) + ) type=InnoDB; + + alter table avm_aspects + add index fk_avm_nasp_n (node_id), + add constraint fk_avm_nasp_n + foreign key (node_id) + references avm_nodes (id); + + alter table avm_child_entries + add index fk_avm_ce_child (child_id), + add constraint fk_avm_ce_child + foreign key (child_id) + references avm_nodes (id); + + alter table avm_child_entries + add index fk_avm_ce_parent (parent_id), + add constraint fk_avm_ce_parent + foreign key (parent_id) + references avm_nodes (id); + + alter table avm_history_links + add index fk_avm_hl_desc (descendent), + add constraint fk_avm_hl_desc + foreign key (descendent) + references avm_nodes (id); + + alter table avm_history_links + add index fk_avm_hl_ancestor (ancestor), + add constraint fk_avm_hl_ancestor + foreign key (ancestor) + references avm_nodes (id); + + alter table avm_merge_links + add index fk_avm_ml_from (mfrom), + add constraint fk_avm_ml_from + foreign key (mfrom) + references avm_nodes (id); + + alter table avm_merge_links + add index fk_avm_ml_to (mto), + add constraint fk_avm_ml_to + foreign key (mto) + references avm_nodes (id); + + alter table avm_node_properties + add index fk_avm_nprop_n (node_id), + add constraint fk_avm_nprop_n + foreign key (node_id) + references avm_nodes (id); + + create index idx_avm_n_pi on avm_nodes (primary_indirection); + + alter table avm_nodes + add index fk_avm_n_acl (acl_id), + add constraint fk_avm_n_acl + foreign key (acl_id) + references alf_access_control_list (id); + + alter table avm_nodes + add index fk_avm_n_store (store_new_id), + add constraint fk_avm_n_store + foreign key (store_new_id) + references avm_stores (id); + + alter table avm_store_properties + add index fk_avm_sprop_store (avm_store_id), + add constraint fk_avm_sprop_store + foreign key (avm_store_id) + references avm_stores (id); + + alter table avm_stores + add index fk_avm_s_root (current_root_id), + add constraint fk_avm_s_root + foreign key (current_root_id) + references avm_nodes (id); + + alter table avm_stores + add index fk_avm_s_acl (acl_id), + add constraint fk_avm_s_acl + foreign key (acl_id) + references alf_access_control_list (id); + + alter table avm_version_layered_node_entry + add index fk_avm_vlne_vr (version_root_id), + add constraint fk_avm_vlne_vr + foreign key (version_root_id) + references avm_version_roots (id); + + create index idx_avm_vr_version on avm_version_roots (version_id); + + alter table avm_version_roots + add index fk_avm_vr_store (avm_store_id), + add constraint fk_avm_vr_store + foreign key (avm_store_id) + references avm_stores (id); + + alter table avm_version_roots + add index fk_avm_vr_root (root_id), + add constraint fk_avm_vr_root + foreign key (root_id) + references avm_nodes (id); + +CREATE INDEX fk_avm_nasp_qn ON avm_aspects (qname_id); +ALTER TABLE avm_aspects ADD CONSTRAINT fk_avm_nasp_qn FOREIGN KEY (qname_id) REFERENCES alf_qname (id); + +CREATE INDEX fk_avm_nprop_qn ON avm_node_properties (qname_id); +ALTER TABLE avm_node_properties ADD CONSTRAINT fk_avm_nprop_qn FOREIGN KEY (qname_id) REFERENCES alf_qname (id); + +CREATE INDEX fk_avm_sprop_qname ON avm_store_properties (qname_id); +ALTER TABLE avm_store_properties ADD CONSTRAINT fk_avm_sprop_qname FOREIGN KEY (qname_id) REFERENCES alf_qname (id); + +CREATE INDEX idx_avm_hl_revpk ON avm_history_links (descendent, ancestor); + +CREATE INDEX idx_avm_vr_revuq ON avm_version_roots (avm_store_id, version_id); + + +-- +-- Record script finish +-- +DELETE FROM alf_applied_patch WHERE id = 'patch.db-V3.2-AvmTables'; +INSERT INTO alf_applied_patch + (id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report) + VALUES + ( + 'patch.db-V3.2-AvmTables', 'Manually executed script upgrade V3.2: AVM Tables', + 0, 3001, -1, 3002, null, 'UNKOWN', 1, 1, 'Script completed' + ); \ No newline at end of file diff --git a/config/alfresco/ehcache-default.xml b/config/alfresco/ehcache-default.xml index b72519221d..81523cfb77 100644 --- a/config/alfresco/ehcache-default.xml +++ b/config/alfresco/ehcache-default.xml @@ -195,76 +195,43 @@ /> - - - - - - - - - - - - + /> + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.alfresco.repo.avm.lookupSharedCache - - - - - - - - - - - - - - - - org.alfresco.repo.avm.lookupTransactionalCache - - - 100 - - - - diff --git a/config/alfresco/extension/ehcache-custom.xml.sample.cluster b/config/alfresco/extension/ehcache-custom.xml.sample.cluster index d535fa44f7..b829a6c757 100644 --- a/config/alfresco/extension/ehcache-custom.xml.sample.cluster +++ b/config/alfresco/extension/ehcache-custom.xml.sample.cluster @@ -442,149 +442,14 @@ replicateAsynchronously = false"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + + + + + + + + + + + + + + + + org/alfresco/repo/domain/hibernate/VersionCount.hbm.xml org/alfresco/repo/domain/hibernate/AppliedPatch.hbm.xml org/alfresco/repo/domain/hibernate/Permission.hbm.xml - org/alfresco/repo/avm/hibernate/AVM.hbm.xml org/alfresco/repo/attributes/hibernate/Attributes.hbm.xml org/alfresco/repo/domain/hibernate/UsageDelta.hbm.xml org/alfresco/repo/activities/hibernate/Activities.hbm.xml @@ -297,6 +296,12 @@ + + + + + + diff --git a/config/alfresco/ibatis/alfresco-SqlMapConfig.xml b/config/alfresco/ibatis/alfresco-SqlMapConfig.xml index 73e931a79b..4be2ba87b3 100644 --- a/config/alfresco/ibatis/alfresco-SqlMapConfig.xml +++ b/config/alfresco/ibatis/alfresco-SqlMapConfig.xml @@ -18,5 +18,7 @@ + + diff --git a/config/alfresco/ibatis/ibatis-context.xml b/config/alfresco/ibatis/ibatis-context.xml index 617351ad06..018e5e23f7 100644 --- a/config/alfresco/ibatis/ibatis-context.xml +++ b/config/alfresco/ibatis/ibatis-context.xml @@ -1,74 +1,79 @@ - - - - - - - - - - org.hibernate.dialect.Dialect - - - - - - - - - - - - - javax.sql.DataSource - - - - - - - - - - - - - - - getConnection - - - - - - - - - classpath:alfresco/ibatis/activities-SqlMapConfig.xml - - - - - - - - - classpath:alfresco/ibatis/alfresco-SqlMapConfig.xml - - - - - - - - - - - - - - - - + + + + + + + + + + org.hibernate.dialect.Dialect + + + + + + + + + + + + + javax.sql.DataSource + + + + + + + + + + + + + + + getConnection + + + + + + + + + classpath:alfresco/ibatis/activities-SqlMapConfig.xml + + + + + + + + + classpath:alfresco/ibatis/alfresco-SqlMapConfig.xml + + + + + + + + + + + + + + + + + + + + + diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/avm-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/avm-common-SqlMap.xml new file mode 100644 index 0000000000..e1b888d240 --- /dev/null +++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/avm-common-SqlMap.xml @@ -0,0 +1,988 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + insert into avm_stores (next_version_id, name, vers, current_root_id, acl_id) + values (#version#, #name#, 0, null, null) + + + + insert into avm_nodes (class_type, deletedType, version_id, vers, store_new_id, acl_id, guid, owner, creator, createDate, lastModifier, modDate, accessDate, is_root, layer_id, indirection, indirection_version, primary_indirection, opacity, content_url, mime_type, encoding, length) + values (#classType#, #deletedType#, #version#, 0, #storeNewId#, #aclId#, #guid#, #owner#, #creator#, #createdDate#, #modifier#, #modifiedDate#, #accessDate#, #isRoot#, #layerId#, #indirection#, #indirectionVersion#, #primaryIndirection#, #opacity#, #contentUrl#, #mimetype#, #encoding#, #length#) + + + + insert into avm_version_roots (avm_store_id, root_id, version_id, creator, create_date, tag, description) + values (#storeId#, #rootNodeId#, #version#, #creator#, #createdDate#, #tag#, #description#) + + + + insert into avm_store_properties (avm_store_id, qname_id, actual_type_n, persisted_type_n, multi_valued, boolean_value, long_value, float_value, double_value, string_value, serializable_value) + values (#avmStoreId#, #qnameId#, #actualType#, #persistedType#, #isMultiValued#, #booleanValue#, #longValue#, #floatValue#, #doubleValue#, #stringValue#, #serializable#) + + + + + + + + + insert into avm_aspects (node_id, qname_id) + values (#nodeId#, #qnameId#) + + + + insert into avm_child_entries (parent_id, name, child_id) + values (#parentNodeId#, #name#, #childNodeId#) + + + + insert into avm_history_links (ancestor, descendent) + values (#ancestorNodeId#, #descendentNodeId#) + + + + insert into avm_merge_links (mfrom, mto) + values (#mergeFromNodeId#, #mergeToNodeId#) + + + + insert into avm_version_layered_node_entry (version_root_id, md5sum, path) + values (#versionRootId#, #md5sum#, #path#) + + + + insert into avm_node_properties (node_id, qname_id, actual_type_n, persisted_type_n, multi_valued, boolean_value, long_value, float_value, double_value, string_value, serializable_value) + values (#nodeId#, #qnameId#, #actualType#, #persistedType#, #isMultiValued#, #booleanValue#, #longValue#, #floatValue#, #doubleValue#, #stringValue#, #serializable#) + + + + + + + + + + + + + + + + + + + + + update + avm_stores + set + next_version_id = #nextVersion#, + name = #name#, + current_root_id = #rootNodeId#, + acl_id = #aclId#, + vers = (#vers# + 1) + where + id = #id# and + vers = #vers# + + + + + delete + from + avm_stores + where + id = ? + + + + + + + + + + + + + + + + + update + avm_store_properties + set + actual_type_n = #actualType#, + persisted_type_n = #persistedType#, + multi_valued = #isMultiValued#, + boolean_value = #booleanValue#, + long_value = #longValue#, + float_value = #floatValue#, + double_value = #doubleValue#, + string_value = #stringValue#, + serializable_value = #serializable# + where + id = #id# + + + + delete + from + avm_store_properties + where + avm_store_id = #avmStoreId# and + qname_id = #qnameId# + + + + delete + from + avm_store_properties + where + avm_store_id = ? + + + + + + + + + + + + + + + + + + + + + + + + update + avm_nodes + set + store_new_id = null + where + store_new_id = ? + + + + + update + avm_nodes + set + store_new_id = #storeNewId#, + acl_id = #aclId#, + layer_id = #layerId#, + version_id = #version#, + class_type = #classType#, + deletedType = #deletedType#, + owner = #owner#, + lastModifier = #modifier#, + modDate = #modifiedDate#, + accessDate = #accessDate#, + is_root = #isRoot#, + lastModifier = #modifier#, + indirection = #indirection#, + indirection_version = #indirectionVersion#, + primary_indirection = #primaryIndirection#, + opacity = #opacity#, + content_url = #contentUrl#, + mime_type = #mimetype#, + encoding = #encoding#, + length = #length#, + guid = #guid#, + vers = (#vers# + 1) + where + id = #id# and + vers = #vers# + + + + update + avm_nodes + set + modDate = #modifiedDate#, + guid = #guid#, + vers = (#vers# + 1) + where + id = #id# and + vers = #vers# + + + + update + avm_nodes + set + modDate = #modifiedDate#, + content_url = #contentUrl#, + mime_type = #mimetype#, + encoding = #encoding#, + length = #length#, + vers = (#vers# + 1) + where + id = #id# and + vers = #vers# + + + + delete + from + avm_nodes + where + id = ? + + + + + + + + + + + + + update + avm_node_properties + set + actual_type_n = #actualType#, + persisted_type_n = #persistedType#, + multi_valued = #isMultiValued#, + boolean_value = #booleanValue#, + long_value = #longValue#, + float_value = #floatValue#, + double_value = #doubleValue#, + string_value = #stringValue#, + serializable_value = #serializable# + where + node_id = #nodeId# and + qname_id = #qnameId# + + + + delete + from + avm_node_properties + where + node_id = #nodeId# and + qname_id = #qnameId# + + + + delete + from + avm_node_properties + where + node_id = ? + + + + + + + + + + + + + + + + + + + + + + + + + + + update + avm_version_roots + set + tag = #tag#, + description = #description# + where + id = #id# + + + + delete + from + avm_version_roots + where + id = ? + + + + + + + + + + delete + from + avm_version_layered_node_entry + where + version_root_id = ? + + + + + + + + + + + + delete + from + avm_aspects + where + node_id = #nodeId# and + qname_id = #qnameId# + + + + delete + from + avm_aspects + where + node_id = ? + + + + + + + + + + + + + + + + + + + + + + + + delete + from + avm_child_entries + where + parent_id = #parentNodeId# and + name = #name# and + child_id = #childNodeId# + + + + + delete + from + avm_child_entries + where + parent_id = #parentNodeId# and + name = #name# + + + + + delete + from + avm_child_entries + where + parent_id = #parentNodeId# and + child_id = #childNodeId# + + + + + delete + from + avm_child_entries + where + parent_id = ? + + + + + + + + + + + + + + delete + from + avm_merge_links + where + mfrom = #mergeFromNodeId# and + mto = #mergeToNodeId# + + + + + + + + + + + + + + delete + from + avm_history_links + where + ancestor = #ancestorNodeId# and + descendent = #descendentNodeId# + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config/alfresco/ibatis/org.hibernate.dialect.MySQLInnoDBDialect/avm-insert-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.MySQLInnoDBDialect/avm-insert-SqlMap.xml new file mode 100644 index 0000000000..d70a735bbd --- /dev/null +++ b/config/alfresco/ibatis/org.hibernate.dialect.MySQLInnoDBDialect/avm-insert-SqlMap.xml @@ -0,0 +1,37 @@ + + + + + + + + + + KEY_COLUMN:GENERATED_KEY + + + + + + + KEY_COLUMN:GENERATED_KEY + + + + + + + KEY_COLUMN:GENERATED_KEY + + + + + + + KEY_COLUMN:GENERATED_KEY + + + + \ No newline at end of file diff --git a/config/alfresco/patch/patch-services-context.xml b/config/alfresco/patch/patch-services-context.xml index 1015ae3200..fcb207298b 100644 --- a/config/alfresco/patch/patch-services-context.xml +++ b/config/alfresco/patch/patch-services-context.xml @@ -658,7 +658,10 @@ 51 52 - + + + + @@ -704,8 +707,11 @@ 0 55 56 - - + + + + + @@ -1142,28 +1148,6 @@ - - - patch.db-V2.2-0-CreateMissingTables patch.schemaUpgradeScript.description @@ -1227,55 +1211,6 @@ - - - - - - - patch.avmWebProjectInheritPermissions02 patch.avmWebProjectInheritPermissions.description @@ -1291,13 +1226,6 @@ - diff --git a/config/alfresco/public-services-context.xml b/config/alfresco/public-services-context.xml index 8644e419a5..7a43bdd9ff 100644 --- a/config/alfresco/public-services-context.xml +++ b/config/alfresco/public-services-context.xml @@ -836,7 +836,6 @@ - avmSessionSizeResourceInterceptor checkTxnAdvisor diff --git a/source/java/org/alfresco/repo/admin/patch/impl/AVMGuidPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/AVMGuidPatch.java index a331c98c0c..778d7bfd98 100644 --- a/source/java/org/alfresco/repo/admin/patch/impl/AVMGuidPatch.java +++ b/source/java/org/alfresco/repo/admin/patch/impl/AVMGuidPatch.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -29,8 +29,9 @@ import java.util.List; import org.alfresco.i18n.I18NUtil; import org.alfresco.repo.admin.patch.AbstractPatch; -import org.alfresco.repo.avm.AVMNode; -import org.alfresco.repo.avm.AVMNodeDAO; +import org.alfresco.repo.domain.avm.AVMNodeDAO; +import org.alfresco.repo.domain.avm.AVMNodeEntity; +import org.alfresco.repo.domain.patch.PatchDAO; import org.alfresco.util.GUID; /** @@ -40,6 +41,7 @@ import org.alfresco.util.GUID; public class AVMGuidPatch extends AbstractPatch { private AVMNodeDAO fAVMNodeDAO; + private PatchDAO patchDAO; private static final String MSG_SUCCESS = "patch.AVMGuidPatch.result"; @@ -52,6 +54,11 @@ public class AVMGuidPatch extends AbstractPatch fAVMNodeDAO = dao; } + public void setPatchDao(PatchDAO dao) + { + patchDAO = dao; + } + /* (non-Javadoc) * @see org.alfresco.repo.admin.patch.AbstractPatch#applyInternal() */ @@ -60,16 +67,17 @@ public class AVMGuidPatch extends AbstractPatch { while (true) { - List batch = fAVMNodeDAO.getEmptyGUIDS(200); - for (AVMNode node : batch) + List batch = patchDAO.getEmptyGUIDS(200); + for (AVMNodeEntity nodeEntity : batch) { - node.setGuid(GUID.generate()); + nodeEntity.setGuid(GUID.generate()); + + fAVMNodeDAO.updateNode(nodeEntity); } if (batch.size() == 0) { break; } - fAVMNodeDAO.flush(); } return I18NUtil.getMessage(MSG_SUCCESS); diff --git a/source/java/org/alfresco/repo/admin/patch/impl/AVMLayeredSnapshotPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/AVMLayeredSnapshotPatch.java index 7d372113a4..a063102d32 100644 --- a/source/java/org/alfresco/repo/admin/patch/impl/AVMLayeredSnapshotPatch.java +++ b/source/java/org/alfresco/repo/admin/patch/impl/AVMLayeredSnapshotPatch.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -29,9 +29,9 @@ import java.util.List; import org.alfresco.i18n.I18NUtil; import org.alfresco.repo.admin.patch.AbstractPatch; -import org.alfresco.repo.avm.AVMNodeDAO; -import org.alfresco.repo.avm.LayeredDirectoryNode; -import org.alfresco.repo.avm.LayeredFileNode; +import org.alfresco.repo.domain.avm.AVMNodeDAO; +import org.alfresco.repo.domain.avm.AVMNodeEntity; +import org.alfresco.repo.domain.patch.PatchDAO; /** * Patch for changes to Layered Node path traversal. @@ -40,6 +40,7 @@ import org.alfresco.repo.avm.LayeredFileNode; public class AVMLayeredSnapshotPatch extends AbstractPatch { private AVMNodeDAO fAVMNodeDAO; + private PatchDAO patchDAO; private static final String MSG_SUCCESS = "patch.AVMLayeredSnapshot.result"; @@ -47,9 +48,14 @@ public class AVMLayeredSnapshotPatch extends AbstractPatch { } - public void setAvmNodeDAO(AVMNodeDAO dao) + public void setAvmNodeDao(AVMNodeDAO dao) { - fAVMNodeDAO = dao; + fAVMNodeDAO = dao; + } + + public void setPatchDao(PatchDAO dao) + { + patchDAO = dao; } /* (non-Javadoc) @@ -60,29 +66,31 @@ public class AVMLayeredSnapshotPatch extends AbstractPatch { while (true) { - List batch = fAVMNodeDAO.getNullVersionLayeredDirectories(200); - for (LayeredDirectoryNode node : batch) + List batch = patchDAO.getNullVersionLayeredDirectories(200); + for (AVMNodeEntity nodeEntity : batch) { - node.setIndirectionVersion(-1); + nodeEntity.setIndirectionVersion(-1); + + fAVMNodeDAO.updateNode(nodeEntity); } if (batch.size() == 0) { break; } - fAVMNodeDAO.flush(); } while (true) { - List batch = fAVMNodeDAO.getNullVersionLayeredFiles(200); - for (LayeredFileNode node : batch) + List batch = patchDAO.getNullVersionLayeredFiles(200); + for (AVMNodeEntity nodeEntity : batch) { - node.setIndirectionVersion(-1); + nodeEntity.setIndirectionVersion(-1); + + fAVMNodeDAO.updateNode(nodeEntity); } if (batch.size() == 0) { break; } - fAVMNodeDAO.flush(); } return I18NUtil.getMessage(MSG_SUCCESS); } diff --git a/source/java/org/alfresco/repo/admin/patch/impl/AVMPermissionsPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/AVMPermissionsPatch.java deleted file mode 100644 index fd4f4b99ed..0000000000 --- a/source/java/org/alfresco/repo/admin/patch/impl/AVMPermissionsPatch.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing - */ -package org.alfresco.repo.admin.patch.impl; - -import java.util.Map; - -import org.alfresco.i18n.I18NUtil; -import org.alfresco.repo.admin.patch.AbstractPatch; -import org.alfresco.repo.domain.AccessControlListDAO; -import org.alfresco.repo.domain.hibernate.AclDaoComponentImpl; -import org.alfresco.repo.security.permissions.ACLType; -import org.alfresco.repo.transaction.RetryingTransactionHelper; -import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; - -/** - * Migrate permissions from the OLD format to defining, shared and layered - */ -public class AVMPermissionsPatch extends AbstractPatch -{ - - private static final String MSG_SUCCESS = "patch.updateAvmPermissions.result"; - - private AccessControlListDAO accessControlListDao; - - private AclDaoComponentImpl aclDaoComponent; - - @Override - protected String applyInternal() throws Exception - { - Thread progressThread = null; - if (aclDaoComponent.supportsProgressTracking()) - { - progressThread = new Thread(new ProgressWatcher(), "WCMPactchProgressWatcher"); - progressThread.start(); - } - - Map summary = this.accessControlListDao.patchAcls(); - - if (progressThread != null) - { - progressThread.interrupt(); - progressThread.join(); - } - - // build the result message - String msg = I18NUtil.getMessage(AVMPermissionsPatch.MSG_SUCCESS, summary.get(ACLType.DEFINING), summary - .get(ACLType.LAYERED)); - // done - return msg; - } - - public void setAccessControlListDao(AccessControlListDAO accessControlListDao) - { - this.accessControlListDao = accessControlListDao; - } - - public void setAclDaoComponent(AclDaoComponentImpl aclDaoComponent) - { - this.aclDaoComponent = aclDaoComponent; - } - - private class ProgressWatcher implements Runnable - { - private boolean running = true; - - Long toDo; - - Long max; - - public void run() - { - while (this.running) - { - try - { - Thread.sleep(60000); - } - catch (InterruptedException e) - { - this.running = false; - } - - if (this.running) - { - RetryingTransactionHelper txHelper = AVMPermissionsPatch.this.transactionService - .getRetryingTransactionHelper(); - txHelper.setMaxRetries(1); - Long done = txHelper.doInTransaction(new RetryingTransactionCallback() - { - - public Long execute() throws Throwable - { - if (ProgressWatcher.this.toDo == null) - { - ProgressWatcher.this.toDo = AVMPermissionsPatch.this.aclDaoComponent - .getAVMHeadNodeCount(); - ProgressWatcher.this.max = AVMPermissionsPatch.this.aclDaoComponent.getMaxAclId(); - } - return AVMPermissionsPatch.this.aclDaoComponent - .getAVMNodeCountWithNewACLS(ProgressWatcher.this.max); - } - }, true, true); - - reportProgress(this.toDo, done); - } - } - } - - } - -} diff --git a/source/java/org/alfresco/repo/admin/patch/impl/MoveWCMToGroupBasedPermissionsPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/MoveWCMToGroupBasedPermissionsPatch.java index dfda2c96dd..3ab8620008 100644 --- a/source/java/org/alfresco/repo/admin/patch/impl/MoveWCMToGroupBasedPermissionsPatch.java +++ b/source/java/org/alfresco/repo/admin/patch/impl/MoveWCMToGroupBasedPermissionsPatch.java @@ -115,13 +115,6 @@ public class MoveWCMToGroupBasedPermissionsPatch extends AbstractPatch @Override protected String applyInternal() throws Exception { - Thread progressThread = null; - if (this.aclDaoComponent.supportsProgressTracking()) - { - progressThread = new Thread(new ProgressWatcher(), "WCMPactchProgressWatcher"); - progressThread.start(); - } - List stores = this.avmService.getStores(); for (AVMStoreDescriptor store : stores) { @@ -159,12 +152,6 @@ public class MoveWCMToGroupBasedPermissionsPatch extends AbstractPatch } } - if (progressThread != null) - { - progressThread.interrupt(); - progressThread.join(); - } - // build the result message String msg = I18NUtil.getMessage(MoveWCMToGroupBasedPermissionsPatch.MSG_SUCCESS); // done @@ -452,58 +439,4 @@ public class MoveWCMToGroupBasedPermissionsPatch extends AbstractPatch } return name.substring(0, index); } - - private class ProgressWatcher implements Runnable - { - private boolean running = true; - - Long toDo; - - Long max; - - ProgressWatcher() - { - } - - public void run() - { - while (this.running) - { - try - { - Thread.sleep(60000); - } - catch (InterruptedException e) - { - this.running = false; - } - - if (this.running) - { - RetryingTransactionHelper txHelper = MoveWCMToGroupBasedPermissionsPatch.this.transactionService - .getRetryingTransactionHelper(); - txHelper.setMaxRetries(1); - Long done = txHelper.doInTransaction(new RetryingTransactionCallback() - { - - public Long execute() throws Throwable - { - if (ProgressWatcher.this.toDo == null) - { - ProgressWatcher.this.toDo = MoveWCMToGroupBasedPermissionsPatch.this.aclDaoComponent - .getAVMHeadNodeCount(); - ProgressWatcher.this.max = MoveWCMToGroupBasedPermissionsPatch.this.aclDaoComponent - .getMaxAclId(); - } - return MoveWCMToGroupBasedPermissionsPatch.this.aclDaoComponent - .getAVMNodeCountWithNewACLS(org.alfresco.repo.admin.patch.impl.MoveWCMToGroupBasedPermissionsPatch.ProgressWatcher.this.max); - } - }, true, true); - - reportProgress(this.toDo, done); - } - } - } - - } } diff --git a/source/java/org/alfresco/repo/admin/patch/impl/WCMPermissionPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/WCMPermissionPatch.java deleted file mode 100644 index cd2fc774e2..0000000000 --- a/source/java/org/alfresco/repo/admin/patch/impl/WCMPermissionPatch.java +++ /dev/null @@ -1,339 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.admin.patch.impl; - -import java.util.List; -import java.util.Map; - -import org.alfresco.i18n.I18NUtil; -import org.alfresco.model.WCMAppModel; -import org.alfresco.repo.admin.patch.AbstractPatch; -import org.alfresco.repo.avm.AVMNodeConverter; -import org.alfresco.repo.avm.AVMRepository; -import org.alfresco.repo.domain.PropertyValue; -import org.alfresco.repo.domain.hibernate.AclDaoComponentImpl; -import org.alfresco.repo.search.AVMSnapShotTriggeredIndexingMethodInterceptor; -import org.alfresco.repo.search.AVMSnapShotTriggeredIndexingMethodInterceptor.StoreType; -import org.alfresco.repo.transaction.RetryingTransactionHelper; -import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; -import org.alfresco.service.cmr.avm.AVMNodeDescriptor; -import org.alfresco.service.cmr.avm.AVMService; -import org.alfresco.service.cmr.avm.AVMStoreDescriptor; -import org.alfresco.service.cmr.dictionary.DataTypeDefinition; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.namespace.QName; -import org.alfresco.service.namespace.RegexQNamePattern; - -/** - * Remove ACLs on all but staging area stores On staging area stores, set ACls according to the users and roles as set - * on the web site Note: runs as the system user - * - * @author andyh - */ -public class WCMPermissionPatch extends AbstractPatch -{ - private static final String MSG_SUCCESS = "patch.wcmPermissionPatch.result"; - - AVMSnapShotTriggeredIndexingMethodInterceptor avmSnapShotTriggeredIndexingMethodInterceptor; - - AVMService avmService; - - PermissionService permissionService; - - AclDaoComponentImpl aclDaoComponent; - - public void setAvmService(AVMService avmService) - { - this.avmService = avmService; - } - - public void setAvmSnapShotTriggeredIndexingMethodInterceptor( - AVMSnapShotTriggeredIndexingMethodInterceptor avmSnapShotTriggeredIndexingMethodInterceptor) - { - this.avmSnapShotTriggeredIndexingMethodInterceptor = avmSnapShotTriggeredIndexingMethodInterceptor; - } - - public void setPermissionService(PermissionService permissionService) - { - this.permissionService = permissionService; - } - - public void setAclDaoComponent(AclDaoComponentImpl aclDaoComponent) - { - this.aclDaoComponent = aclDaoComponent; - } - - @Override - protected String applyInternal() throws Exception - { - Thread progressThread = null; - if (this.aclDaoComponent.supportsProgressTracking()) - { - progressThread = new Thread(new ProgressWatcher(), "WCMPactchProgressWatcher"); - progressThread.start(); - } - - List stores = this.avmService.getStores(); - for (AVMStoreDescriptor store : stores) - { - Map storeProperties = this.avmService.getStoreProperties(store.getName()); - - switch (StoreType.getStoreType(store.getName(), store, storeProperties)) - { - /* Set permissions in staging */ - case STAGING: - setStagingAreaPermissions(store); - setStagingAreaMasks(store); - // TODO: mark read only - break; - /* Clear permissions */ - case AUTHOR: - case AUTHOR_PREVIEW: - case AUTHOR_WORKFLOW: - case AUTHOR_WORKFLOW_PREVIEW: - // TODO: add app access control - clearPermissions(store); - setSandBoxMasks(store); - break; - case STAGING_PREVIEW: - clearPermissions(store); - setStagingAreaMasks(store); - // TODO: mark read only - break; - case WORKFLOW: - case WORKFLOW_PREVIEW: - clearPermissions(store); - break; - /* non WCM stores - nothing to do */ - case UNKNOWN: - default: - } - } - - if (progressThread != null) - { - progressThread.interrupt(); - progressThread.join(); - } - - // build the result message - String msg = I18NUtil.getMessage(WCMPermissionPatch.MSG_SUCCESS); - // done - return msg; - } - - private void clearPermissions(AVMStoreDescriptor store) - { - AVMNodeDescriptor www = this.avmService.lookup(-1, store.getName() + ":/www"); - if (www.isLayeredDirectory() && www.isPrimary()) - { - // throw away any acl - AVMRepository.GetInstance().setACL(store.getName() + ":/www", null); - // build the default layer acl - this.avmService.retargetLayeredDirectory(store.getName() + ":/www", www.getIndirection()); - } - } - - private void setStagingAreaPermissions(AVMStoreDescriptor store) - { - QName propQName = QName.createQName(null, ".web_project.noderef"); - - NodeRef dirRef = AVMNodeConverter.ToNodeRef(-1, store.getName() + ":/www"); - this.permissionService.setPermission(dirRef, PermissionService.ALL_AUTHORITIES, PermissionService.READ, true); - - PropertyValue pValue = this.avmService.getStoreProperty(store.getName(), propQName); - - if (pValue != null) - { - NodeRef webProjectNodeRef = (NodeRef) pValue.getValue(DataTypeDefinition.NODE_REF); - - // Apply sepcific user permissions as set on the web project - List userInfoRefs = this.nodeService.getChildAssocs(webProjectNodeRef, - WCMAppModel.ASSOC_WEBUSER, RegexQNamePattern.MATCH_ALL); - for (ChildAssociationRef ref : userInfoRefs) - { - NodeRef userInfoRef = ref.getChildRef(); - String username = (String) this.nodeService.getProperty(userInfoRef, WCMAppModel.PROP_WEBUSERNAME); - String userrole = (String) this.nodeService.getProperty(userInfoRef, WCMAppModel.PROP_WEBUSERROLE); - - this.permissionService.setPermission(dirRef, username, userrole, true); - } - } - } - - private void setStagingAreaMasks(AVMStoreDescriptor store) - { - NodeRef dirRef = AVMNodeConverter.ToNodeRef(-1, store.getName() + ":/www"); - this.permissionService.setPermission(dirRef.getStoreRef(), PermissionService.ALL_AUTHORITIES, - PermissionService.READ, true); - - QName propQName = QName.createQName(null, ".web_project.noderef"); - - PropertyValue pValue = this.avmService.getStoreProperty(store.getName(), propQName); - - if (pValue != null) - { - NodeRef webProjectNodeRef = (NodeRef) pValue.getValue(DataTypeDefinition.NODE_REF); - - // Apply sepcific user permissions as set on the web project - List userInfoRefs = this.nodeService.getChildAssocs(webProjectNodeRef, - WCMAppModel.ASSOC_WEBUSER, RegexQNamePattern.MATCH_ALL); - for (ChildAssociationRef ref : userInfoRefs) - { - NodeRef userInfoRef = ref.getChildRef(); - String username = (String) this.nodeService.getProperty(userInfoRef, WCMAppModel.PROP_WEBUSERNAME); - String userrole = (String) this.nodeService.getProperty(userInfoRef, WCMAppModel.PROP_WEBUSERROLE); - - if (userrole.equals("ContentManager")) - { - this.permissionService.setPermission(dirRef.getStoreRef(), username, - PermissionService.CHANGE_PERMISSIONS, true); - this.permissionService.setPermission(dirRef.getStoreRef(), username, - PermissionService.READ_PERMISSIONS, true); - } - } - } - - } - - private void setSandBoxMasks(AVMStoreDescriptor sandBoxStore) - { - // get the settings from the staging store ... - - String owner = extractOwner(sandBoxStore.getName()); - String stagingAreaName = extractStagingAreaName(sandBoxStore.getName()); - - QName propQName = QName.createQName(null, ".web_project.noderef"); - - NodeRef dirRef = AVMNodeConverter.ToNodeRef(-1, sandBoxStore.getName() + ":/www"); - - this.avmService.getStoreProperties(stagingAreaName); - PropertyValue pValue = this.avmService.getStoreProperty(stagingAreaName, propQName); - - this.permissionService.setPermission(dirRef.getStoreRef(), PermissionService.ALL_AUTHORITIES, - PermissionService.READ, true); - - if (pValue != null) - { - NodeRef webProjectNodeRef = (NodeRef) pValue.getValue(DataTypeDefinition.NODE_REF); - - // Apply sepcific user permissions as set on the web project - List userInfoRefs = this.nodeService.getChildAssocs(webProjectNodeRef, - WCMAppModel.ASSOC_WEBUSER, RegexQNamePattern.MATCH_ALL); - for (ChildAssociationRef ref : userInfoRefs) - { - NodeRef userInfoRef = ref.getChildRef(); - String username = (String) this.nodeService.getProperty(userInfoRef, WCMAppModel.PROP_WEBUSERNAME); - String userrole = (String) this.nodeService.getProperty(userInfoRef, WCMAppModel.PROP_WEBUSERROLE); - - if (username.equals(owner)) - { - this.permissionService.setPermission(dirRef.getStoreRef(), username, - PermissionService.ALL_PERMISSIONS, true); - } - else if (userrole.equals("ContentManager")) - { - this.permissionService.setPermission(dirRef.getStoreRef(), username, userrole, true); - } - } - } - } - - private String extractOwner(String name) - { - int start = name.indexOf("--"); - if (start == -1) - { - throw new UnsupportedOperationException(name); - } - int end = name.indexOf("--", start + 1); - if (end == -1) - { - return name.substring(start + 2); - } - return name.substring(start + 2, end); - } - - private String extractStagingAreaName(String name) - { - int index = name.indexOf("--"); - if (index == -1) - { - throw new UnsupportedOperationException(name); - } - return name.substring(0, index); - } - - private class ProgressWatcher implements Runnable - { - private boolean running = true; - - Long toDo; - - Long max; - - public void run() - { - while (this.running) - { - try - { - Thread.sleep(60000); - } - catch (InterruptedException e) - { - this.running = false; - } - - if (this.running) - { - RetryingTransactionHelper txHelper = WCMPermissionPatch.this.transactionService - .getRetryingTransactionHelper(); - txHelper.setMaxRetries(1); - Long done = txHelper.doInTransaction(new RetryingTransactionCallback() - { - - public Long execute() throws Throwable - { - if (ProgressWatcher.this.toDo == null) - { - ProgressWatcher.this.toDo = WCMPermissionPatch.this.aclDaoComponent - .getAVMHeadNodeCount(); - ProgressWatcher.this.max = WCMPermissionPatch.this.aclDaoComponent.getMaxAclId(); - } - return WCMPermissionPatch.this.aclDaoComponent - .getAVMNodeCountWithNewACLS(ProgressWatcher.this.max); - } - }, true, true); - - reportProgress(this.toDo, done); - } - } - } - - } -} diff --git a/source/java/org/alfresco/repo/attributes/hibernate/AttributeDAOHibernate.java b/source/java/org/alfresco/repo/attributes/hibernate/AttributeDAOHibernate.java index ed6b235830..e25b286047 100644 --- a/source/java/org/alfresco/repo/attributes/hibernate/AttributeDAOHibernate.java +++ b/source/java/org/alfresco/repo/attributes/hibernate/AttributeDAOHibernate.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -26,11 +26,8 @@ package org.alfresco.repo.attributes.hibernate; import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import org.alfresco.repo.attributes.AttrQueryHelperImpl; import org.alfresco.repo.attributes.Attribute; @@ -42,7 +39,6 @@ import org.alfresco.repo.attributes.MapAttribute; import org.alfresco.repo.attributes.MapEntry; import org.alfresco.repo.attributes.MapEntryDAO; import org.alfresco.repo.attributes.Attribute.Type; -import org.alfresco.repo.avm.hibernate.SessionCacheChecker; import org.alfresco.repo.domain.hibernate.DirtySessionMethodInterceptor; import org.alfresco.service.cmr.attributes.AttrQuery; import org.alfresco.service.cmr.attributes.AttrQueryHelper; @@ -50,7 +46,6 @@ import org.alfresco.util.Pair; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.Query; -import org.hibernate.engine.EntityKey; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; /** diff --git a/source/java/org/alfresco/repo/avm/AVMDAOs.java b/source/java/org/alfresco/repo/avm/AVMDAOs.java index 2a08d5b2a8..56947e4df2 100644 --- a/source/java/org/alfresco/repo/avm/AVMDAOs.java +++ b/source/java/org/alfresco/repo/avm/AVMDAOs.java @@ -27,7 +27,6 @@ import org.alfresco.repo.attributes.AttributeDAO; import org.alfresco.repo.attributes.GlobalAttributeEntryDAO; import org.alfresco.repo.attributes.ListEntryDAO; import org.alfresco.repo.attributes.MapEntryDAO; -import org.alfresco.repo.domain.QNameDAO; /** * This is the (shudder) global context for AVM. It a rendezvous @@ -59,21 +58,23 @@ public class AVMDAOs */ public AVMNodeDAO fAVMNodeDAO; - /** - * The QName DAO - */ - public QNameDAO fQNameDAO; + public org.alfresco.repo.domain.avm.AVMNodeDAO newAVMNodeDAO; + public org.alfresco.repo.domain.avm.AVMNodeLinksDAO newAVMNodeLinksDAO; /** * The AVMStore DAO. */ public AVMStoreDAO fAVMStoreDAO; + public org.alfresco.repo.domain.avm.AVMStoreDAO newAVMStoreDAO; + /** * The VersionRootDAO. */ public VersionRootDAO fVersionRootDAO; + public org.alfresco.repo.domain.avm.AVMVersionRootDAO newAVMVersionRootDAO; + /** * The ChildEntryDAO. */ @@ -111,10 +112,15 @@ public class AVMDAOs { fAVMNodeDAO = nodeDAO; } - - public void setQnameDAO(QNameDAO qnameDAO) + + public void setNewAvmNodeDAO(org.alfresco.repo.domain.avm.AVMNodeDAO newAVMNodeDAO) { - this.fQNameDAO = qnameDAO; + this.newAVMNodeDAO = newAVMNodeDAO; + } + + public void setNewAvmNodeLinksDAO(org.alfresco.repo.domain.avm.AVMNodeLinksDAO newAVMNodeLinksDAO) + { + this.newAVMNodeLinksDAO = newAVMNodeLinksDAO; } /** @@ -148,6 +154,11 @@ public class AVMDAOs { fAVMStoreDAO = aVMStoreDAO; } + + public void setNewAvmStoreDAO(org.alfresco.repo.domain.avm.AVMStoreDAO newAVMStoreDAO) + { + this.newAVMStoreDAO = newAVMStoreDAO; + } /** * @param versionRootDAO the fVersionRootDAO to set @@ -157,6 +168,11 @@ public class AVMDAOs fVersionRootDAO = versionRootDAO; } + public void setNewAvmVersionRootDAO(org.alfresco.repo.domain.avm.AVMVersionRootDAO newAVMVersionRootDAO) + { + this.newAVMVersionRootDAO = newAVMVersionRootDAO; + } + public void setAvmStorePropertyDAO(AVMStorePropertyDAO avmStorePropertyDAO) { fAVMStorePropertyDAO = avmStorePropertyDAO; diff --git a/source/java/org/alfresco/repo/avm/AVMDiffPerformanceTest.java b/source/java/org/alfresco/repo/avm/AVMDiffPerformanceTest.java index d5240fd1b2..d71d33fe4d 100644 --- a/source/java/org/alfresco/repo/avm/AVMDiffPerformanceTest.java +++ b/source/java/org/alfresco/repo/avm/AVMDiffPerformanceTest.java @@ -1,3 +1,26 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" */ + package org.alfresco.repo.avm; import java.util.List; @@ -11,8 +34,27 @@ import org.alfresco.util.GUID; public class AVMDiffPerformanceTest extends AVMServiceTestBase { + public void testSetup() throws Exception + { + super.testSetup(); + } + + public void xtest_1000() throws Exception + { + runTest(1000); + } + + public void ytest_10000() throws Exception + { + runTest(10000); + } + + public void test_2000() throws Exception + { + runTest(2000); + } - public void test_10000() throws Exception + private void runTest(final int cnt) throws Exception { fTransactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() { @@ -28,7 +70,7 @@ public class AVMDiffPerformanceTest extends AVMServiceTestBase fService.createLayeredDirectory("StagingArea:/www", "SandBox:/", "www"); - for(int i = 0; i < 10000; i++) + for(int i = 0; i < cnt; i++) { String name = GUID.generate(); fService.createFile("SandBox:/www", name).close(); @@ -36,21 +78,21 @@ public class AVMDiffPerformanceTest extends AVMServiceTestBase System.out.println("Create SandBox:/www"); - for(int i = 0; i < 10000; i++) + for(int i = 0; i < cnt; i++) { String name = GUID.generate(); fService.createFile("SandBox:/www/test", name).close(); } System.out.println("Create SandBox:/www/test"); - for(int i = 0; i < 10000; i++) + for(int i = 0; i < cnt; i++) { String name = GUID.generate(); fService.createFile("StagingArea:/www", name).close(); } System.out.println("Create StagingArea:/www"); - for(int i = 0; i < 10000; i++) + for(int i = 0; i < cnt; i++) { String name = GUID.generate(); fService.createFile("StagingArea:/www/test", name).close(); @@ -62,9 +104,7 @@ public class AVMDiffPerformanceTest extends AVMServiceTestBase long end = System.nanoTime(); System.out.println("Diff in "+( (end-start)/1000000000.0f)); - assertEquals(20000, diffs.size()); - - + assertEquals(cnt*2, diffs.size()); } finally { @@ -73,7 +113,6 @@ public class AVMDiffPerformanceTest extends AVMServiceTestBase } return null; }}); - } } diff --git a/source/java/org/alfresco/repo/avm/AVMNode.java b/source/java/org/alfresco/repo/avm/AVMNode.java index 4f6dd7fc7a..b06a86178c 100644 --- a/source/java/org/alfresco/repo/avm/AVMNode.java +++ b/source/java/org/alfresco/repo/avm/AVMNode.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -28,6 +28,7 @@ import java.util.Set; import org.alfresco.repo.domain.DbAccessControlList; import org.alfresco.repo.domain.PropertyValue; import org.alfresco.service.cmr.avm.AVMNodeDescriptor; +import org.alfresco.service.namespace.QName; /** * The Interface for versionable objects. @@ -152,35 +153,41 @@ public interface AVMNode /** * Set a property. - * @param qnameEntityId the ID of the QName to set - * @param value The value to set. + * @param qname the QName + * @param value The value to set. */ - public void setProperty(Long qnameEntityId, PropertyValue value); + public void setProperty(QName qname, PropertyValue value); /** * Set a collection of properties on this node. - * @param properties The Map of QName entity IDs to PropertyValues. + * @param properties The Map of QNames to PropertyValues. */ - public void setProperties(Map properties); + public void setProperties(Map properties); /** + * Add properties to those that already exist. + * @param properties The properties to add. + */ + public void addProperties(Map properties); + + /** * Get a property by name. * @param name The name of the property to get. * @return A PropertyValue */ - public PropertyValue getProperty(Long name); + public PropertyValue getProperty(QName name); /** * Get all the properties associated with this node. * @return A Map of QNames to PropertyValues. */ - public Map getProperties(); + public Map getProperties(); /** * Delete a property from this node. * @param qnameEntityId the ID of the QName to delete */ - public void deleteProperty(Long qnameEntityId); + public void deleteProperty(QName qname); /** * Delete all properties from this node. @@ -233,13 +240,11 @@ public interface AVMNode * Get the Aspects that this node has. * @return A Set of Aspects IDs. */ - public Set getAspects(); - - /** - * Add properties to those that already exist. - * @param properties The properties to add. - */ - public void addProperties(Map properties); + public Set getAspects(); + + public void addAspect(QName aspectQName); + + public void removeAspect(QName aspectQName); /** * Get the Basic Attributes on this node. diff --git a/source/java/org/alfresco/repo/avm/AVMNodeDAO.java b/source/java/org/alfresco/repo/avm/AVMNodeDAO.java index 6bc58b0326..204c3b7c4a 100644 --- a/source/java/org/alfresco/repo/avm/AVMNodeDAO.java +++ b/source/java/org/alfresco/repo/avm/AVMNodeDAO.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,6 +23,11 @@ package org.alfresco.repo.avm; import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.service.namespace.QName; /** * DAO for AVMNodes interface. @@ -40,7 +45,23 @@ public interface AVMNodeDAO * @param node The node to delete. */ public void delete(AVMNode node); - + + public void createAspect(long nodeId, QName aspectQName); + + public void deleteAspect(long nodeId, QName aspectQName); + + public void deleteAspects(long nodeId); + + public Set getAspects(long nodeId); + + public void createOrUpdateProperty(long nodeId, QName propQName, PropertyValue value); + + public void deleteProperty(long nodeId, QName propQName); + + public void deleteProperties(long nodeId); + + public Map getProperties(long nodeId); + /** * Get by ID. * @param id The id to get. @@ -60,7 +81,10 @@ public interface AVMNodeDAO * @param node The node. */ public void update(AVMNode node); - + + // update optimisation, eg. when creating files + public void updateModTimeAndGuid(AVMNode node); + /** * Get the ancestor of a node. * @param node The node whose ancestor is desired. @@ -82,22 +106,6 @@ public interface AVMNodeDAO */ public List getOrphans(int batchSize); - /** - * Get all content urls in the AVM Repository. - * @param contentUrlHandler the handler that will be called with the URLs - */ - public void getContentUrls(ContentUrlHandler handler); - - /** - * A callback handler for iterating over the content URLs - * - * @author Derek Hulley - * @since 2.0 - */ - public interface ContentUrlHandler - { - void handle(String contentUrl); - } /** * Get all the nodes that are new in the given store. @@ -105,14 +113,7 @@ public interface AVMNodeDAO * @return A List of AVMNodes. */ public List getNewInStore(AVMStore store); - - /** - * Get the id's of all AVMNodes new in a given store. - * @param store - * @return - */ - public List getNewInStoreIDs(AVMStore store); - + /** * Clear newInStore field for a store. (Snapshot) * @param store @@ -125,50 +126,40 @@ public interface AVMNodeDAO * @return */ public List getNewLayeredInStoreIDs(AVMStore store); + + public List getNewLayeredInStore(AVMStore store); /** * Inappropriate hack to get Hibernate to play nice. + * + * @deprecated */ public void flush(); - /** - * Get a batch - * @return An iterator over all nodes. - */ - public List getEmptyGUIDS(int count); - - /** - * Get a batch of LayeredDirectories which have null indirectionVersions. - * @param count - * @return - */ - public List getNullVersionLayeredDirectories(int count); - - /** - * Get a batch of LayeredFiles which have null indirectionVersions. - * @param count - * @return - */ - public List getNullVersionLayeredFiles(int count); - /** * Evict an AVMNode that is no longer going to be used. * @param node + * + * @deprecated */ public void evict(AVMNode node); /** - * Clear the hibernate session cache. + * Clear the cache. */ public void clear(); /** * Turn off 2nd level caching. + * + * @deprecated */ public void noCache(); /** * Turn on 2nd level caching. + * + * @deprecated */ public void yesCache(); } diff --git a/source/java/org/alfresco/repo/avm/AVMNodeImpl.java b/source/java/org/alfresco/repo/avm/AVMNodeImpl.java index 865bb0b328..1dcfdb87eb 100644 --- a/source/java/org/alfresco/repo/avm/AVMNodeImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMNodeImpl.java @@ -23,7 +23,6 @@ package org.alfresco.repo.avm; -import java.io.Serializable; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -34,6 +33,7 @@ import org.alfresco.repo.domain.DbAccessControlList; import org.alfresco.repo.domain.PropertyValue; import org.alfresco.repo.security.permissions.ACLCopyMode; import org.alfresco.service.cmr.avm.AVMReadOnlyException; +import org.alfresco.service.namespace.QName; import org.alfresco.util.GUID; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -42,7 +42,7 @@ import org.apache.commons.logging.LogFactory; * Base class for all repository file system like objects. * @author britt */ -public abstract class AVMNodeImpl implements AVMNode, Serializable +public abstract class AVMNodeImpl implements AVMNode { private static Log fgLogger = LogFactory.getLog(AVMNodeImpl.class); @@ -72,7 +72,7 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable * The rootness of this node. */ private boolean fIsRoot; - + /** * The ACL on this node. */ @@ -91,29 +91,28 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable /** * The Aspects that belong to this node. */ - private Set fAspects; + private Set fAspects; - private Map fProperties; + private Map fProperties; /** * Default constructor. */ protected AVMNodeImpl() { - fAspects = new HashSet(); - fProperties = new HashMap(); } - + /** * Constructor used when creating a new concrete subclass instance. * @param store The AVMStore that owns this. */ protected AVMNodeImpl(AVMStore store) { - fAspects = new HashSet(); - fProperties = new HashMap(); - fVersionID = -1; - fIsRoot = false; + this(); + + setVersionID(-1); + setIsRoot(false); + long time = System.currentTimeMillis(); String user = RawServices.Instance().getAuthenticationContext().getCurrentUserName(); @@ -121,14 +120,14 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable { user = RawServices.Instance().getAuthenticationContext().getSystemUserName(); } - fBasicAttributes = new BasicAttributesImpl(user, + setBasicAttributes(new BasicAttributesImpl(user, user, user, time, time, - time); - fStoreNew = store; - fGUID = GUID.generate(); + time)); + setStoreNew(store); + setGuid(GUID.generate()); } /** @@ -211,7 +210,7 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable { return false; } - return fID == ((AVMNode)obj).getId(); + return getId() == ((AVMNode)obj).getId(); } /** @@ -221,14 +220,14 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable @Override public int hashCode() { - return (int)fID; + return (int)getId(); } /** - * Set the object id. For Hibernate. + * Set the object id. * @param id The id to set. */ - protected void setId(long id) + public void setId(long id) { fID = id; } @@ -261,10 +260,10 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable } /** - * Set the basic attributes. For Hibernate. + * Set the basic attributes. * @param attrs */ - protected void setBasicAttributes(BasicAttributes attrs) + public void setBasicAttributes(BasicAttributes attrs) { fBasicAttributes = attrs; } @@ -284,23 +283,23 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable */ public boolean getIsNew() { - return fStoreNew != null; + return getStoreNew() != null; } /** - * Set the version for concurrency control - * @param vers + * Set the version (for concurrency control). + * @param The version for optimistic locks. */ - protected void setVers(long vers) + public void setVers(long vers) { fVers = vers; } /** - * Get the version for concurrency control. - * @return The version for optimistic locks. + * Get the version (for concurrency control). + * @return vers The version for optimistic locks. */ - protected long getVers() + public long getVers() { return fVers; } @@ -337,8 +336,8 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable { user = RawServices.Instance().getAuthenticationContext().getSystemUserName(); } - fBasicAttributes.setModDate(System.currentTimeMillis()); - fBasicAttributes.setLastModifier(user); + getBasicAttributes().setModDate(System.currentTimeMillis()); + getBasicAttributes().setLastModifier(user); } /** @@ -347,11 +346,13 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable */ protected void copyProperties(AVMNode other) { - fProperties = new HashMap(); - for (Map.Entry entry : other.getProperties().entrySet()) + Map props = new HashMap(); + for (Map.Entry entry : other.getProperties().entrySet()) { - fProperties.put(entry.getKey(), entry.getValue()); + props.put(entry.getKey(), entry.getValue()); } + + setProperties(props); } /** @@ -360,14 +361,15 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable */ protected void copyAspects(AVMNode other) { - fAspects = new HashSet(other.getAspects()); + Set aspects = new HashSet(other.getAspects()); + setAspects(aspects); } protected void copyCreationAndOwnerBasicAttributes(AVMNode other) { - fBasicAttributes.setCreateDate(other.getBasicAttributes().getCreateDate()); - fBasicAttributes.setCreator(other.getBasicAttributes().getCreator()); - fBasicAttributes.setOwner(other.getBasicAttributes().getOwner()); + getBasicAttributes().setCreateDate(other.getBasicAttributes().getCreateDate()); + getBasicAttributes().setCreator(other.getBasicAttributes().getCreator()); + getBasicAttributes().setOwner(other.getBasicAttributes().getOwner()); } protected void copyACLs(AVMNode other, Long parentAcl, ACLCopyMode mode) @@ -396,20 +398,23 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable * @param name The name of the property. * @param value The value to set. */ - public void setProperty(Long qnameEntityId, PropertyValue value) + public void setProperty(QName qname, PropertyValue value) { if (DEBUG) { checkReadOnly(); } - fProperties.put(qnameEntityId, value); + + getProperties().put(qname, value); + + AVMDAOs.Instance().fAVMNodeDAO.createOrUpdateProperty(this.getId(), qname, value); } - public void addProperties(Map properties) + public void addProperties(Map properties) { - for (Map.Entry entry : properties.entrySet()) + for (Map.Entry entry : properties.entrySet()) { - fProperties.put(entry.getKey(), entry.getValue()); + setProperty(entry.getKey(), entry.getValue()); } } @@ -417,9 +422,14 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable * Set a collection of properties on this node. * @param properties The Map of QNames to PropertyValues. */ - public void setProperties(Map properties) + public void setProperties(Map properties) { fProperties = properties; + + for (Map.Entry entry : properties.entrySet()) + { + setProperty(entry.getKey(), entry.getValue()); + } } /** @@ -427,16 +437,20 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable * @param name The name of the property. * @return The PropertyValue or null if non-existent. */ - public PropertyValue getProperty(Long qnameEntityId) + public PropertyValue getProperty(QName qname) { - return fProperties.get(qnameEntityId); + return getProperties().get(qname); } /** * {@inheritDoc} */ - public Map getProperties() + public Map getProperties() { + if (fProperties == null) + { + fProperties = AVMDAOs.Instance().fAVMNodeDAO.getProperties(getId()); + } return fProperties; } @@ -444,13 +458,15 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable * Delete a property from this node. * @param name The name of the property. */ - public void deleteProperty(Long qnameEntityId) + public void deleteProperty(QName qname) { if (DEBUG) { checkReadOnly(); } - fProperties.remove(qnameEntityId); + getProperties().remove(qname); + + AVMDAOs.Instance().fAVMNodeDAO.deleteProperty(getId(), qname); } /** @@ -458,7 +474,9 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable */ public void deleteProperties() { - fProperties.clear(); + getProperties().clear(); + + AVMDAOs.Instance().fAVMNodeDAO.deleteProperties(getId()); } /** @@ -524,8 +542,12 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable /* (non-Javadoc) * @see org.alfresco.repo.avm.AVMNode#getAspects() */ - public Set getAspects() + public Set getAspects() { + if (fAspects == null) + { + fAspects = AVMDAOs.Instance().fAVMNodeDAO.getAspects(getId()); + } return fAspects; } @@ -533,8 +555,28 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable * Set the aspects on this node. * @param aspects */ - public void setAspects(Set aspects) + public void setAspects(Set aspects) { fAspects = aspects; + + if ((aspects != null) && (aspects.size() > 0)) + { + for (QName aspectQName : aspects) + { + AVMDAOs.Instance().fAVMNodeDAO.createAspect(this.getId(), aspectQName); + } + } + } + + public void addAspect(QName aspectQName) + { + fAspects = null; + AVMDAOs.Instance().fAVMNodeDAO.createAspect(this.getId(), aspectQName); + } + + public void removeAspect(QName aspectQName) + { + fAspects = null; + AVMDAOs.Instance().fAVMNodeDAO.deleteAspect(this.getId(), aspectQName); } } diff --git a/source/java/org/alfresco/repo/avm/AVMNodeUnwrapper.java b/source/java/org/alfresco/repo/avm/AVMNodeUnwrapper.java index a3d4086aab..cafcfe2a0a 100644 --- a/source/java/org/alfresco/repo/avm/AVMNodeUnwrapper.java +++ b/source/java/org/alfresco/repo/avm/AVMNodeUnwrapper.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -30,9 +30,14 @@ import org.hibernate.proxy.HibernateProxy; * may be a HibernateProxy. Bitter Hibernate note: Hibernate proxies for polymorphic * types are fundamentally broken. * @author britt + * + * @deprecated */ public class AVMNodeUnwrapper { + /** + * @deprecated + */ public static AVMNode Unwrap(AVMNode node) { if (node instanceof HibernateProxy) diff --git a/source/java/org/alfresco/repo/avm/AVMRepository.java b/source/java/org/alfresco/repo/avm/AVMRepository.java index 6d9b0708a7..401f02e517 100644 --- a/source/java/org/alfresco/repo/avm/AVMRepository.java +++ b/source/java/org/alfresco/repo/avm/AVMRepository.java @@ -26,7 +26,6 @@ package org.alfresco.repo.avm; import java.io.File; import java.io.InputStream; import java.io.OutputStream; -import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -40,7 +39,7 @@ import org.alfresco.repo.content.ContentStore; import org.alfresco.repo.domain.DbAccessControlList; import org.alfresco.repo.domain.PropertyValue; import org.alfresco.repo.domain.QNameDAO; -import org.alfresco.repo.search.AVMSnapShotTriggeredIndexingMethodInterceptor.StoreType; +import org.alfresco.repo.domain.avm.AVMStoreEntity; import org.alfresco.repo.security.permissions.ACLCopyMode; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.transaction.AlfrescoTransactionSupport; @@ -54,9 +53,7 @@ import org.alfresco.service.cmr.avm.AVMStoreDescriptor; import org.alfresco.service.cmr.avm.AVMWrongTypeException; import org.alfresco.service.cmr.avm.LayeringDescriptor; import org.alfresco.service.cmr.avm.VersionDescriptor; -import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DictionaryService; -import org.alfresco.service.cmr.dictionary.PropertyDefinition; import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentWriter; @@ -354,17 +351,28 @@ public class AVMRepository Long parentAcl = dir.getAcl() == null ? null : dir.getAcl().getId(); if (dir instanceof LayeredDirectoryNode) { + // TODO - collapse save/update child = new LayeredDirectoryNodeImpl((String) null, store, null, parentAcl, ACLCopyMode.INHERIT); ((LayeredDirectoryNode) child).setPrimaryIndirection(false); ((LayeredDirectoryNode) child).setLayerID(parent.getLayerID()); + + DbAccessControlList acl = dir.getAcl(); + child.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null); + + AVMDAOs.Instance().fAVMNodeDAO.update(child); } else { child = new PlainDirectoryNodeImpl(store); + + DbAccessControlList acl = dir.getAcl(); + child.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null); + + AVMDAOs.Instance().fAVMNodeDAO.save(child); } + dir.putChild(name, child); - DbAccessControlList acl = dir.getAcl(); - child.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null); + fLookupCache.onWrite(pathParts[0]); AVMNodeDescriptor desc = child.getDescriptor(parent.getPath(), name, parent.getIndirection(), parent.getIndirectionVersion()); return desc; @@ -449,8 +457,12 @@ public class AVMRepository } // Newing up the object causes it to be written to the db. AVMStore rep = new AVMStoreImpl(this, name); + // Special handling for AVMStore creation. - rep.getRoot().setStoreNew(null); + AVMNode rootNode = rep.getRoot(); + rootNode.setStoreNew(null); + fAVMNodeDAO.update(rootNode); + fCreateStoreTxnListener.storeCreated(name); } @@ -541,6 +553,8 @@ public class AVMRepository // note: re-use generated node id as a layer id ((LayeredDirectoryNode) dstNode).setLayerID(dstNode.getId()); + + AVMDAOs.Instance().fAVMNodeDAO.update(dstNode); } else if (srcNode.getType() == AVMNodeType.LAYERED_FILE) { @@ -770,6 +784,8 @@ public class AVMRepository // note: re-use generated node id as a layer id ((LayeredDirectoryNode) dstNode).setLayerID(dstNode.getId()); } + + AVMDAOs.Instance().fAVMNodeDAO.update(dstNode); } else { @@ -813,6 +829,8 @@ public class AVMRepository ((LayeredDirectoryNode) dstNode).setLayerID(dstNode.getId()); } } + + AVMDAOs.Instance().fAVMNodeDAO.update(dstNode); } else if (srcNode.getType() == AVMNodeType.LAYERED_FILE) { @@ -957,12 +975,15 @@ public class AVMRepository { throw new AccessDeniedException("Not allowed to purge: " + name); } - root.setIsRoot(false); + + fAVMNodeDAO.update(root); + List vRoots = fVersionRootDAO.getAllInAVMStore(store); for (VersionRoot vr : vRoots) { - AVMNode node = vr.getRoot(); - node.setIsRoot(false); + AVMNode node = fAVMNodeDAO.getByID(vr.getRoot().getId()); + fAVMNodeDAO.update(node); + fVersionLayeredNodeEntryDAO.delete(vr); fVersionRootDAO.delete(vr); } @@ -970,6 +991,8 @@ public class AVMRepository for (AVMNode newGuy : newGuys) { newGuy.setStoreNew(null); + + fAVMNodeDAO.update(newGuy); } fAVMStorePropertyDAO.delete(store); fAVMStoreDAO.delete(store); @@ -1243,12 +1266,16 @@ public class AVMRepository */ public List getAVMStores() { - List l = fAVMStoreDAO.getAll(); - List result = new ArrayList(); - for (AVMStore store : l) + List storeEntities = AVMDAOs.Instance().newAVMStoreDAO.getAllStores(); + + List result = new ArrayList(storeEntities.size()); + for (AVMStoreEntity storeEntity : storeEntities) { + AVMStore store = new AVMStoreImpl(); + store.setName(storeEntity.getName()); result.add(store.getDescriptor()); } + return result; } @@ -1711,7 +1738,7 @@ public class AVMRepository fgLogger.debug("Found component: " + name); } components.add(name); - Pair path = recursiveGetAPath(AVMNodeUnwrapper.Unwrap(entry.getKey().getParent()), components); + Pair path = recursiveGetAPath(entry.getKey().getParent(), components); if (path != null) { return path; @@ -2303,7 +2330,6 @@ public class AVMRepository * The sql 'like' pattern, inserted into a QName. * @return A Map of the matching key value pairs. */ - @SuppressWarnings("unchecked") public Map queryStorePropertyKey(String store, QName keyPattern) { AVMStore st = getAVMStoreByName(store); @@ -2311,14 +2337,8 @@ public class AVMRepository { throw new AVMNotFoundException("Store not found."); } - List matches = fAVMStorePropertyDAO.queryByKeyPattern(st, keyPattern); - Map matchesMap = new HashMap(); - for (AVMStoreProperty prop : matches) - { - matchesMap.put(prop.getQnameId(), prop.getValue()); - } - Map propertyMap = (Map) qnameDAO.convertIdMapToQNameMap(matchesMap); - return propertyMap; + + return fAVMStorePropertyDAO.queryByKeyPattern(st, keyPattern); } /** @@ -2330,21 +2350,7 @@ public class AVMRepository */ public Map> queryStoresPropertyKeys(QName keyPattern) { - List matches = fAVMStorePropertyDAO.queryByKeyPattern(keyPattern); - Map> results = new HashMap>(); - for (AVMStoreProperty prop : matches) - { - String storeName = prop.getStore().getName(); - QName propQName = qnameDAO.getQName(prop.getQnameId()).getSecond(); - Map pairs = null; - if ((pairs = results.get(storeName)) == null) - { - pairs = new HashMap(); - results.put(storeName, pairs); - } - pairs.put(propQName, prop.getValue()); - } - return results; + return fAVMStorePropertyDAO.queryByKeyPattern(keyPattern); } /** @@ -2941,6 +2947,9 @@ public class AVMRepository throw new AVMBadArgumentException("Bad store name: " + destName); } store.setName(destName); + + AVMDAOs.Instance().fAVMStoreDAO.update(store); + store.createSnapshot("Rename Store", "Rename Store from " + sourceName + " to " + destName, new HashMap()); fLookupCache.onDelete(sourceName); fAVMStoreDAO.invalidateCache(); @@ -3118,10 +3127,7 @@ public class AVMRepository { throw new AccessDeniedException("Not allowed to read properties: " + desc); } - QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; - @SuppressWarnings("unchecked") - Map converted = (Map) qnameDAO.convertIdMapToQNameMap(node.getProperties()); - return converted; + return node.getProperties(); } public ContentData getContentDataForRead(AVMNodeDescriptor desc) @@ -3154,9 +3160,7 @@ public class AVMRepository { throw new AccessDeniedException("Not allowed to read properties: " + desc); } - Set aspectIds = node.getAspects(); - // Convert to QNames - Set aspectQNames = qnameDAO.convertIdsToQNames(aspectIds); + Set aspectQNames = node.getAspects(); return aspectQNames; } @@ -3191,11 +3195,18 @@ public class AVMRepository } PermissionContext context = new PermissionContext(type); - // We're doing the hand unrolling of the proxy because Hibernate/CGLIB proxies are broken - context.addDynamicAuthorityAssignment(AVMNodeUnwrapper.Unwrap(node).getBasicAttributes().getOwner(), PermissionService.OWNER_AUTHORITY); + context.addDynamicAuthorityAssignment(node.getBasicAttributes().getOwner(), PermissionService.OWNER_AUTHORITY); if ((store != null) && isDirectlyContained) { + String storeOwner = getStoreUserName(store.getName()); + if (storeOwner != null) + { + // Special case: WCM author sandbox (author, author preview, author workflow, author workflow preview) + context.addDynamicAuthorityAssignment(storeOwner, PermissionService.WCM_STORE_OWNER_AUTHORITY); + } + + /* StoreType storeType = StoreType.getStoreType(store.getName(), store.getDescriptor(), store.getProperties()); switch (storeType) { @@ -3229,12 +3240,15 @@ public class AVMRepository case WORKFLOW_PREVIEW: default: } - + */ } + // Pass in node aspects - Set nodeAspectQNames = qnameDAO.convertIdsToQNames(node.getAspects()); + Set nodeAspectQNames = node.getAspects(); Set contextQNames = context.getAspects(); contextQNames.addAll(nodeAspectQNames); + + /* TODO review - PermissionContext.getProperties() not currently used ? // Pass in node properties Map nodeProperties = node.getProperties(); Map contextProperties = new HashMap(5); @@ -3253,6 +3267,8 @@ public class AVMRepository } } context.getProperties().putAll(contextProperties); + */ + Long aclId = null; if (acl != null) { @@ -3269,7 +3285,47 @@ public class AVMRepository } return fPermissionService.hasPermission(aclId, context, permission) == AccessStatus.ALLOWED; } - + + private final static String WCM_STORE_SEPARATOR = "--"; + private final static String WCM_STORE_PREVIEW = "--preview"; + private final static String WCM_STORE_WORKFLOW = "--workflow-"; + + // TODO - merge with WCM 3.x utils + // + // Note: relies on WCM sandbox naming convention + // + // Staging: mystore + // Staging preview: mystore--preview + // Author: mystore--myuserid + // Author preview: mystore--myuserid--preview + // Author workflow: mystore--myuserid--workflow-guid + // Author workflow preview: mystore--myuserid--workflow-guid--preview + // Workflow: mystore--workflow-guid + // Workflow preview: mystore--worklow-guid--preview + // + private static String getStoreUserName(String storeName) + { + String storeOwner = null; + int preview = storeName.indexOf(WCM_STORE_PREVIEW); + if (preview >= 0) + { + // strip off "--preview" + storeName = storeName.substring(0, preview); + } + int workflow = storeName.indexOf(WCM_STORE_WORKFLOW); + if (workflow >= 0) + { + // strip off "--workflow-" + storeName = storeName.substring(0, workflow); + } + int author = storeName.indexOf(WCM_STORE_SEPARATOR); + if (author >= 0) + { + storeOwner = storeName.substring(author + 2); + } + return storeOwner; + } + public boolean can(String storeName, int version, String path, String permission) { Lookup lookup = AVMRepository.GetInstance().lookup(version, path, true); @@ -3300,6 +3356,8 @@ public class AVMRepository throw new AVMNotFoundException("Store not found: " + storeName); } store.setStoreAcl(acl); + + AVMDAOs.Instance().fAVMStoreDAO.update(store); } /** diff --git a/source/java/org/alfresco/repo/avm/AVMServiceIndexTest.java b/source/java/org/alfresco/repo/avm/AVMServiceIndexTest.java index 201217b865..bee9f25e00 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceIndexTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceIndexTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2008 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -37,6 +37,7 @@ import org.alfresco.service.cmr.search.SearchService; */ public class AVMServiceIndexTest extends AVMServiceTestBase { + private final static long SLEEP = 180000; /** * Test async indexing. * @@ -130,7 +131,7 @@ public class AVMServiceIndexTest extends AVMServiceTestBase assertEquals(1, results.length()); results.close(); - Thread.sleep(180000); + Thread.sleep(SLEEP); results = searchService.query(storeRef, "lucene", "PATH:\"//.\""); assertEquals(4, results.length()); @@ -163,7 +164,7 @@ public class AVMServiceIndexTest extends AVMServiceTestBase fService.createDirectory("avmAsynchronousTest:/a/b", "c"); fService.createSnapshot("avmAsynchronousTest", null, null); - Thread.sleep(180000); + Thread.sleep(SLEEP); results = searchService.query(storeRef, "lucene", "PATH:\"//.\""); assertEquals(4, results.length()); diff --git a/source/java/org/alfresco/repo/avm/AVMServiceLocalTest.java b/source/java/org/alfresco/repo/avm/AVMServiceLocalTest.java index 4be7c0f210..1d1d5ccb33 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceLocalTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceLocalTest.java @@ -109,6 +109,11 @@ public class AVMServiceLocalTest extends TestCase fService.purgeStore("layer"); } + public void testSetup() throws Exception + { + setUp(); + } + public void testGetAPath() throws Exception { try diff --git a/source/java/org/alfresco/repo/avm/AVMServicePerfTest.java b/source/java/org/alfresco/repo/avm/AVMServicePerfTest.java index 1528a34b16..cbf1ebadc4 100644 --- a/source/java/org/alfresco/repo/avm/AVMServicePerfTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServicePerfTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -31,30 +31,74 @@ import java.io.PrintStream; */ public class AVMServicePerfTest extends AVMServiceTestBase { + public void testSetup() throws Exception + { + super.testSetup(); + } + + public void testAdd100x10a() throws Throwable + { + add(100, 10); + } + + public void testAdd100x10b() throws Throwable + { + add(100, 10); + } + + public void testAdd100x10c() throws Throwable + { + add(100, 10); + } + + public void testAdd100x10d() throws Throwable + { + add(100, 10); + } + + public void testAdd500x2e() throws Throwable + { + add(500, 2); + } + + public void testAdd500x4g() throws Throwable + { + add(500, 4); + } + /** - * Test adding 100 files to each directory. + * Test adding 100 files to each of 10 directories. */ - public void testAdd100a() throws Throwable + private void add(int fileCnt, int dirCnt) throws Throwable { try { - String [] dirs = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }; - for (String dir : dirs) + if ((dirCnt < 1) || (dirCnt > 10)) { + throw new Exception("Invalid ("+dirCnt+") - currently supports between 1 and 10 directories"); + } + + String [] dirs = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }; + for (int j = 0; j < dirCnt; j++) + { + String dir = dirs[j]; fService.createDirectory("main:/", dir); String ndir = "main:/" + dir; fService.createDirectory(ndir, dir); ndir = ndir + "/" + dir; - for (int i = 0; i < 100; i++) + for (int i = 0; i < fileCnt; i++) { PrintStream out = new PrintStream(fService.createFile(ndir, "file" + i)); out.println("I am " + ndir + "/file" + i); - System.out.println(ndir + "/file" + i); + + //System.out.println(ndir + "/file" + i); + out.close(); } fService.createSnapshot("main", null, null); } - // System.out.println(recursiveList("main", -1)); + + // System.out.println(recursiveList("main", -1)); } catch (Exception e) { @@ -62,100 +106,4 @@ public class AVMServicePerfTest extends AVMServiceTestBase throw e; } } - - /** - * Test adding 100 files to each directory. - */ - public void testAdd100b() throws Throwable - { - try - { - String [] dirs = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }; - for (String dir : dirs) - { - fService.createDirectory("main:/", dir); - String ndir = "main:/" + dir; - fService.createDirectory(ndir, dir); - ndir = ndir + "/" + dir; - for (int i = 0; i < 100; i++) - { - PrintStream out = new PrintStream(fService.createFile(ndir, "file" + i)); - out.println("I am " + ndir + "/file" + i); - System.out.println(ndir + "/file" + i); - out.close(); - } - fService.createSnapshot("main", null, null); - } - // System.out.println(recursiveList("main", -1)); - } - catch (Exception e) - { - e.printStackTrace(System.err); - throw e; - } - } - - /** - * Test adding 100 files to each directory. - */ - public void testAdd100c() throws Throwable - { - try - { - String [] dirs = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }; - for (String dir : dirs) - { - fService.createDirectory("main:/", dir); - String ndir = "main:/" + dir; - fService.createDirectory(ndir, dir); - ndir = ndir + "/" + dir; - for (int i = 0; i < 100; i++) - { - PrintStream out = new PrintStream(fService.createFile(ndir, "file" + i)); - out.println("I am " + ndir + "/file" + i); - System.out.println(ndir + "/file" + i); - out.close(); - } - fService.createSnapshot("main", null, null); - } - // System.out.println(recursiveList("main", -1)); - } - catch (Exception e) - { - e.printStackTrace(System.err); - throw e; - } - } - - /** - * Test adding 100 files to each directory. - */ - public void testAdd100d() throws Throwable - { - try - { - String [] dirs = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }; - for (String dir : dirs) - { - fService.createDirectory("main:/", dir); - String ndir = "main:/" + dir; - fService.createDirectory(ndir, dir); - ndir = ndir + "/" + dir; - for (int i = 0; i < 100; i++) - { - PrintStream out = new PrintStream(fService.createFile(ndir, "file" + i)); - out.println("I am " + ndir + "/file" + i); - out.close(); - System.out.println(ndir + "/file" + i); - } - fService.createSnapshot("main", null, null); - } - // System.out.println(recursiveList("main", -1)); - } - catch (Exception e) - { - e.printStackTrace(System.err); - throw e; - } - } -} +} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/avm/AVMServicePermissionsTest.java b/source/java/org/alfresco/repo/avm/AVMServicePermissionsTest.java index a5da2c15e9..759375ce57 100644 --- a/source/java/org/alfresco/repo/avm/AVMServicePermissionsTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServicePermissionsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2008 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -125,7 +125,8 @@ public class AVMServicePermissionsTest extends TestCase super(); } - public void setUp() throws Exception + @Override + protected void setUp() throws Exception { avmNodeDAO = (AVMNodeDAO) applicationContext.getBean("avmNodeDAO"); @@ -213,8 +214,14 @@ public class AVMServicePermissionsTest extends TestCase authenticationService.createAuthentication("reviewer", "reviewer".toCharArray()); authenticationComponent.clearCurrentSecurityContext(); + + if (avmService.getStore("main") != null) + { + avmService.purgeStore("main"); + } } + @Override protected void tearDown() throws Exception { @@ -398,7 +405,12 @@ public class AVMServicePermissionsTest extends TestCase runAs(curentUser); } } - + + public void testSetup() throws Exception + { + // test setUp & tearDown + } + public void testStoreAcls() throws Exception { runAs(AuthenticationUtil.getAdminUserName()); @@ -3096,8 +3108,7 @@ public class AVMServicePermissionsTest extends TestCase } } - // Comment-out for now due to intermittent failure: expected:<6> but was:<7> - public void x_testSimpleInternalLayer() + public void testSimpleInternalLayer() { runAs(AuthenticationUtil.getAdminUserName()); String storeName = "PermissionsTest-" + getName() + "-" + (new Date().getTime()); diff --git a/source/java/org/alfresco/repo/avm/AVMServiceTest.java b/source/java/org/alfresco/repo/avm/AVMServiceTest.java index 5f52443143..475fbe671c 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceTest.java @@ -54,7 +54,6 @@ import org.alfresco.repo.search.impl.lucene.LuceneQueryParser; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; -import org.alfresco.wcm.sandbox.SandboxConstants; import org.alfresco.service.cmr.avm.AVMBadArgumentException; import org.alfresco.service.cmr.avm.AVMCycleException; import org.alfresco.service.cmr.avm.AVMException; @@ -84,6 +83,7 @@ import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.GUID; import org.alfresco.util.Pair; +import org.alfresco.wcm.sandbox.SandboxConstants; /** * Big test of AVM behavior. @@ -92,6 +92,11 @@ import org.alfresco.util.Pair; */ public class AVMServiceTest extends AVMServiceTestBase { + public void testSetup() throws Exception + { + super.testSetup(); + } + public void testDiffOrder() { try @@ -186,7 +191,6 @@ public class AVMServiceTest extends AVMServiceTestBase assertEquals(1, diffs.size()); assertEquals("[SandBox:/www/TestFolder[-1] > StagingArea:/www/TestFolder[-1]]", diffs.toString()); fSyncService.update(diffs, null, true, true, false, false, "one", "one"); - AVMDAOs.Instance().fAVMNodeDAO.flush(); fSyncService.flatten("SandBox:/www", "StagingArea:/www"); StoreRef storeRef = AVMNodeConverter.ToStoreRef("StagingArea"); @@ -201,7 +205,6 @@ public class AVMServiceTest extends AVMServiceTestBase assertEquals(1, diffs.size()); assertEquals("[SandBox:/www/TestFolder[-1] > StagingArea:/www/TestFolder[-1]]", diffs.toString()); fSyncService.update(diffs, null, true, true, false, false, "one", "one"); - AVMDAOs.Instance().fAVMNodeDAO.flush(); fSyncService.flatten("SandBox:/www", "StagingArea:/www"); results = searchService.query(storeRef, "lucene", "@cm\\:name:test1"); @@ -215,7 +218,6 @@ public class AVMServiceTest extends AVMServiceTestBase assertEquals(1, diffs.size()); assertEquals("[SandBox:/www/TestFolder[-1] > StagingArea:/www/TestFolder[-1]]", diffs.toString()); fSyncService.update(diffs, null, true, true, false, false, "one", "one"); - AVMDAOs.Instance().fAVMNodeDAO.flush(); fSyncService.flatten("SandBox:/www", "StagingArea:/www"); results = searchService.query(storeRef, "lucene", "@cm\\:name:test1"); @@ -1293,8 +1295,10 @@ public class AVMServiceTest extends AVMServiceTestBase try { setupBasicTree(); - fService.getFileOutputStream("main:/a/b/c/foo").close(); AVMNodeDescriptor desc = fService.lookup(-1, "main:/a/b/c/foo"); + assertEquals(1, desc.getVersionID()); + fService.getFileOutputStream("main:/a/b/c/foo").close(); + desc = fService.lookup(-1, "main:/a/b/c/foo"); assertEquals(2, desc.getVersionID()); desc = fService.lookup(-1, "main:/a/b"); assertEquals(2, desc.getVersionID()); diff --git a/source/java/org/alfresco/repo/avm/AVMStoreImpl.java b/source/java/org/alfresco/repo/avm/AVMStoreImpl.java index d8f84b9ffc..199a2318f3 100644 --- a/source/java/org/alfresco/repo/avm/AVMStoreImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMStoreImpl.java @@ -26,10 +26,10 @@ package org.alfresco.repo.avm; import java.io.File; import java.io.InputStream; import java.io.OutputStream; -import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -42,7 +42,6 @@ import org.alfresco.repo.avm.util.RawServices; import org.alfresco.repo.avm.util.SimplePath; import org.alfresco.repo.domain.DbAccessControlList; import org.alfresco.repo.domain.PropertyValue; -import org.alfresco.repo.domain.QNameDAO; import org.alfresco.repo.security.permissions.ACLCopyMode; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.service.cmr.avm.AVMBadArgumentException; @@ -71,10 +70,8 @@ import org.alfresco.util.Pair; * operation. * @author britt */ -public class AVMStoreImpl implements AVMStore, Serializable +public class AVMStoreImpl implements AVMStore { - static final long serialVersionUID = -1485972568675732904L; - /** * The primary key. */ @@ -89,7 +86,7 @@ public class AVMStoreImpl implements AVMStore, Serializable * The current root directory. */ private DirectoryNode fRoot; - + /** * The next version id. */ @@ -104,20 +101,20 @@ public class AVMStoreImpl implements AVMStore, Serializable * Acl for this store. */ private DbAccessControlList fACL; - + /** * The AVMRepository. */ transient private AVMRepository fAVMRepository; - + /** * Default constructor. */ - protected AVMStoreImpl() + public AVMStoreImpl() { fAVMRepository = AVMRepository.GetInstance(); } - + /** * Make a brand new AVMStore. * @param repo The AVMRepository. @@ -127,10 +124,13 @@ public class AVMStoreImpl implements AVMStore, Serializable { // Make ourselves up and save. fAVMRepository = repo; - fName = name; - fNextVersionID = 0; - fRoot = null; + + setName(name); + setNextVersionID(0); + setRoot(null); + AVMDAOs.Instance().fAVMStoreDAO.save(this); + String creator = RawServices.Instance().getAuthenticationContext().getCurrentUserName(); if (creator == null) { @@ -138,31 +138,38 @@ public class AVMStoreImpl implements AVMStore, Serializable } setProperty(ContentModel.PROP_CREATOR, new PropertyValue(null, creator)); setProperty(ContentModel.PROP_CREATED, new PropertyValue(null, new Date(System.currentTimeMillis()))); + // Make up the initial version record and save. long time = System.currentTimeMillis(); - fRoot = new PlainDirectoryNodeImpl(this); - fRoot.setIsRoot(true); - AVMDAOs.Instance().fAVMNodeDAO.save(fRoot); + + PlainDirectoryNode dir = new PlainDirectoryNodeImpl(this); + dir.setIsRoot(true); + AVMDAOs.Instance().fAVMNodeDAO.save(dir); + + setRoot(dir); + VersionRoot versionRoot = new VersionRootImpl(this, - fRoot, - fNextVersionID, + getRoot(), + getNextVersionID(), time, creator, "Initial Empty Version.", "Initial Empty Version."); - fNextVersionID++; + setNextVersionID(getNextVersionID()+1); + + AVMDAOs.Instance().fAVMStoreDAO.update(this); AVMDAOs.Instance().fVersionRootDAO.save(versionRoot); } - + /** - * Setter for hibernate. + * Set the primary key * @param id The primary key. */ - protected void setId(long id) + public void setId(long id) { fID = id; } - + /** * Get the primary key. * @return The primary key. @@ -179,18 +186,16 @@ public class AVMStoreImpl implements AVMStore, Serializable public void setNewRoot(DirectoryNode root) { fRoot = root; - fRoot.setIsRoot(true); } /** * Snapshot this store. This creates a new version record. * @return The version id of the new snapshot. */ - @SuppressWarnings("unchecked") public Map createSnapshot(String tag, String description, Map snapShotMap) { - long rootID = fRoot.getId(); - AVMStoreImpl me = (AVMStoreImpl)AVMDAOs.Instance().fAVMStoreDAO.getByID(fID); + long rootID = getRoot().getId(); + AVMStoreImpl me = (AVMStoreImpl)AVMDAOs.Instance().fAVMStoreDAO.getByID(getId()); VersionRoot lastVersion = AVMDAOs.Instance().fVersionRootDAO.getMaxVersion(me); List layeredEntries = AVMDAOs.Instance().fVersionLayeredNodeEntryDAO.get(lastVersion); @@ -203,11 +208,13 @@ public class AVMStoreImpl implements AVMStore, Serializable { lastVersion.setTag(tag); lastVersion.setDescription(description); + + AVMDAOs.Instance().fVersionRootDAO.update(lastVersion); } - snapShotMap.put(fName, lastVersion.getVersionID()); + snapShotMap.put(getName(), lastVersion.getVersionID()); return snapShotMap; } - snapShotMap.put(fName, me.fNextVersionID); + snapShotMap.put(getName(), me.getNextVersionID()); // Force copies on all the layered nodes from last snapshot. for (VersionLayeredNodeEntry entry : layeredEntries) { @@ -291,24 +298,29 @@ public class AVMStoreImpl implements AVMStore, Serializable { layered.setIndirectionVersion(snapShotMap.get(storeName)); } + + AVMDAOs.Instance().fAVMNodeDAO.update(layered); } - AVMDAOs.Instance().fAVMNodeDAO.flush(); + // Make up a new version record. String user = RawServices.Instance().getAuthenticationContext().getCurrentUserName(); if (user == null) { user = RawServices.Instance().getAuthenticationContext().getSystemUserName(); } - me = (AVMStoreImpl)AVMDAOs.Instance().fAVMStoreDAO.getByID(fID); + me = (AVMStoreImpl)AVMDAOs.Instance().fAVMStoreDAO.getByID(getId()); VersionRoot versionRoot = new VersionRootImpl(me, - me.fRoot, - me.fNextVersionID++, + me.getRoot(), + me.getNextVersionID(), System.currentTimeMillis(), user, tag, description); - // Another embarassing flush needed. - AVMDAOs.Instance().fAVMNodeDAO.flush(); + + me.setNextVersionID(me.getNextVersionID()+1); + + AVMDAOs.Instance().fAVMStoreDAO.update(me); + AVMDAOs.Instance().fVersionRootDAO.save(versionRoot); for (Long nodeID : layeredNodeIDs) { @@ -352,14 +364,26 @@ public class AVMStoreImpl implements AVMStore, Serializable // a LayeredDirectoryNode that gets its indirection from // its parent. { + // TODO - collapse save/update newDir = new LayeredDirectoryNodeImpl((String)null, this, null, null, ACLCopyMode.INHERIT); ((LayeredDirectoryNodeImpl)newDir).setPrimaryIndirection(false); ((LayeredDirectoryNodeImpl)newDir).setLayerID(lPath.getTopLayer().getLayerID()); + + DbAccessControlList acl = dir.getAcl(); + newDir.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null); + + AVMDAOs.Instance().fAVMNodeDAO.update(newDir); } else { newDir = new PlainDirectoryNodeImpl(this); + + DbAccessControlList acl = dir.getAcl(); + newDir.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null); + + AVMDAOs.Instance().fAVMNodeDAO.save(newDir); } + // newDir.setVersionID(getNextVersionID()); if (child != null) { @@ -369,29 +393,16 @@ public class AVMStoreImpl implements AVMStore, Serializable dir.putChild(name, newDir); if (aspects != null) { - // Convert the aspect QNames to entities - QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; - Set aspectQNameEntityIds = newDir.getAspects(); - for (QName aspectQName : aspects) - { - Long qnameEntityId = qnameDAO.getOrCreateQName(aspectQName).getFirst(); - aspectQNameEntityIds.add(qnameEntityId); - } + Set aspectQNames = new HashSet(newDir.getAspects()); + aspectQNames.addAll(aspects); + ((DirectoryNodeImpl)newDir).setAspects(aspectQNames); } if (properties != null) { - // Convert the property QNames to entities - QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; - Map propertiesByQNameEntityId = new HashMap(properties.size() * 2 + 1); - for (Map.Entry entry : properties.entrySet()) - { - Long qnameEntityId = qnameDAO.getOrCreateQName(entry.getKey()).getFirst(); - propertiesByQNameEntityId.put(qnameEntityId, entry.getValue()); - } - newDir.getProperties().putAll(propertiesByQNameEntityId); + Map props = new HashMap(newDir.getProperties()); + props.putAll(properties); + ((DirectoryNodeImpl)newDir).setProperties(props); } - DbAccessControlList acl = dir.getAcl(); - newDir.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null); } /** @@ -416,8 +427,10 @@ public class AVMStoreImpl implements AVMStore, Serializable throw new AVMExistsException("Child exists: " + name); } Long parentAcl = dir.getAcl() == null ? null : dir.getAcl().getId(); + LayeredDirectoryNode newDir = new LayeredDirectoryNodeImpl(srcPath, this, null, parentAcl, ACLCopyMode.INHERIT); + if (lPath.isLayered()) { // When a layered directory is made inside of a layered context, @@ -433,13 +446,17 @@ public class AVMStoreImpl implements AVMStore, Serializable // note: re-use generated node id as a layer id newDir.setLayerID(newDir.getId()); } + + AVMDAOs.Instance().fAVMNodeDAO.update(newDir); + if (child != null) { newDir.setAncestor(child); } + + // newDir.setVersionID(getNextVersionID()); //dir.updateModTime(); dir.putChild(name, newDir); - // newDir.setVersionID(getNextVersionID()); } /** @@ -450,38 +467,7 @@ public class AVMStoreImpl implements AVMStore, Serializable */ public OutputStream createFile(String path, String name) { - Lookup lPath = lookupDirectory(-1, path, true); - if (lPath == null) - { - throw new AVMNotFoundException("Path " + path + " not found."); - } - DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); - if (!fAVMRepository.can(this, dir, PermissionService.ADD_CHILDREN, lPath.getDirectlyContained())) - { - throw new AccessDeniedException("Not allowed to write: " + path); - } - Pair temp = dir.lookupChild(lPath, name, true); - AVMNode child = (temp == null) ? null : temp.getFirst(); - if (child != null && child.getType() != AVMNodeType.DELETED_NODE) - { - throw new AVMExistsException("Child exists: " + name); - } - PlainFileNodeImpl file = new PlainFileNodeImpl(this); - // file.setVersionID(getNextVersionID()); - //dir.updateModTime(); - dir.putChild(name, file); - if (child != null) - { - file.setAncestor(child); - } - file.setContentData(new ContentData(null, - RawServices.Instance().getMimetypeService().guessMimetype(name), - -1, - "UTF-8")); - DbAccessControlList acl = dir.getAcl(); - file.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null); - ContentWriter writer = createContentWriter(AVMNodeConverter.ExtendAVMPath(path, name)); - return writer.getContentOutputStream(); + return createFile(path, name, null, null).getContentOutputStream(); } /** @@ -491,6 +477,11 @@ public class AVMStoreImpl implements AVMStore, Serializable * @param data The contents. */ public void createFile(String path, String name, File data, List aspects, Map properties) + { + createFile(path, name, aspects, properties).putContent(data); + } + + private ContentWriter createFile(String path, String name, List aspects, Map properties) { Lookup lPath = lookupDirectory(-1, path, true); if (lPath == null) @@ -508,7 +499,19 @@ public class AVMStoreImpl implements AVMStore, Serializable { throw new AVMExistsException("Child exists: " + name); } + PlainFileNodeImpl file = new PlainFileNodeImpl(this); + + file.setContentData(new ContentData(null, + RawServices.Instance().getMimetypeService().guessMimetype(name), + -1, + "UTF-8")); + + DbAccessControlList acl = dir.getAcl(); + file.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null); + + AVMDAOs.Instance().fAVMNodeDAO.save(file); + // file.setVersionID(getNextVersionID()); //dir.updateModTime(); dir.putChild(name, file); @@ -516,39 +519,21 @@ public class AVMStoreImpl implements AVMStore, Serializable { file.setAncestor(child); } - file.setContentData(new ContentData(null, - RawServices.Instance().getMimetypeService().guessMimetype(name), - -1, - "UTF-8")); + if (aspects != null) { - // Convert the aspect QNames to entities - QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; - Set aspectQNameEntityIds = file.getAspects(); - for (QName aspectQName : aspects) - { - Long qnameEntityId = qnameDAO.getOrCreateQName(aspectQName).getFirst(); - aspectQNameEntityIds.add(qnameEntityId); - } + Set aspectQNames = new HashSet(aspects.size()); + aspectQNames.addAll(aspects); + file.setAspects(aspectQNames); } if (properties != null) { - // Convert the property QNames to entities - QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; - Map propertiesByQNameEntityId = new HashMap(properties.size() * 2 + 1); - for (Map.Entry entry : properties.entrySet()) - { - Long qnameEntityId = qnameDAO.getOrCreateQName(entry.getKey()).getFirst(); - propertiesByQNameEntityId.put(qnameEntityId, entry.getValue()); - } - file.getProperties().putAll(propertiesByQNameEntityId); + Map props = new HashMap(properties.size()); + props.putAll(properties); + file.setProperties(props); } - DbAccessControlList acl = dir.getAcl(); - file.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null); - // Yet another flush. - AVMDAOs.Instance().fAVMNodeDAO.flush(); - ContentWriter writer = createContentWriter(AVMNodeConverter.ExtendAVMPath(path, name)); - writer.putContent(data); + + return createContentWriter(AVMNodeConverter.ExtendAVMPath(path, name)); } /** @@ -578,15 +563,20 @@ public class AVMStoreImpl implements AVMStore, Serializable // TODO Reexamine decision to not check validity of srcPath. LayeredFileNodeImpl newFile = new LayeredFileNodeImpl(srcPath, this, null); + + DbAccessControlList acl = dir.getAcl(); + newFile.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null); + + AVMDAOs.Instance().fAVMNodeDAO.save(newFile); + if (child != null) { newFile.setAncestor(child); } + + // newFile.setVersionID(getNextVersionID()); //dir.updateModTime(); dir.putChild(name, newFile); - DbAccessControlList acl = dir.getAcl(); - newFile.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null); - // newFile.setVersionID(getNextVersionID()); } /** @@ -615,7 +605,7 @@ public class AVMStoreImpl implements AVMStore, Serializable */ public ContentReader getContentReader(int version, String path) { - NodeRef nodeRef = AVMNodeConverter.ToNodeRef(version, fName + ":" + path); + NodeRef nodeRef = AVMNodeConverter.ToNodeRef(version, getName() + ":" + path); return RawServices.Instance().getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT); } @@ -626,7 +616,7 @@ public class AVMStoreImpl implements AVMStore, Serializable */ public ContentWriter createContentWriter(String path) { - NodeRef nodeRef = AVMNodeConverter.ToNodeRef(-1, fName + ":" + path); + NodeRef nodeRef = AVMNodeConverter.ToNodeRef(-1, getName() + ":" + path); ContentWriter writer = RawServices.Instance().getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true); return writer; @@ -696,7 +686,7 @@ public class AVMStoreImpl implements AVMStore, Serializable for (String name : listing.keySet()) { // TODO consider doing this at a lower level. - AVMNode child = AVMNodeUnwrapper.Unwrap(listing.get(name)); + AVMNode child = listing.get(name); AVMNodeDescriptor desc = child.getDescriptor(lPath, name); results.put(name, desc); } @@ -794,17 +784,14 @@ public class AVMStoreImpl implements AVMStore, Serializable } ((LayeredDirectoryNode)node).uncover(lPath, name); node.updateModTime(); + + AVMDAOs.Instance().fAVMNodeDAO.update(node); } - - // TODO This is problematic. As time goes on this returns - // larger and larger data sets. Perhaps what we should do is - // provide methods for getting versions by date range, n most - // recent etc. + /** * Get the set of all extant versions for this AVMStore. * @return A Set of version ids. */ - @SuppressWarnings("unchecked") public List getVersions() { List versions = AVMDAOs.Instance().fVersionRootDAO.getAllInAVMStore(this); @@ -812,7 +799,7 @@ public class AVMStoreImpl implements AVMStore, Serializable for (VersionRoot vr : versions) { VersionDescriptor desc = - new VersionDescriptor(fName, + new VersionDescriptor(getName(), vr.getVersionID(), vr.getCreator(), vr.getCreateDate(), @@ -830,7 +817,6 @@ public class AVMStoreImpl implements AVMStore, Serializable * @param to The latest date. * @return The Set of matching version IDs. */ - @SuppressWarnings("unchecked") public List getVersions(Date from, Date to) { List versions = AVMDAOs.Instance().fVersionRootDAO.getByDates(this, from, to); @@ -838,7 +824,7 @@ public class AVMStoreImpl implements AVMStore, Serializable for (VersionRoot vr : versions) { VersionDescriptor desc = - new VersionDescriptor(fName, + new VersionDescriptor(getName(), vr.getVersionID(), vr.getCreator(), vr.getCreateDate(), @@ -881,7 +867,7 @@ public class AVMStoreImpl implements AVMStore, Serializable AVMNode root = null; if (version < 0) { - root = fRoot; + root = getRoot(); } else { @@ -889,9 +875,9 @@ public class AVMStoreImpl implements AVMStore, Serializable } if (!fAVMRepository.can(this, root, PermissionService.READ_CHILDREN, true)) { - throw new AccessDeniedException("Not allowed to read: " + fName + "@" + version); + throw new AccessDeniedException("Not allowed to read: " + getName() + "@" + version); } - return root.getDescriptor(fName + ":", "", null, -1); + return root.getDescriptor(getName() + ":", "", null, -1); } /** @@ -975,6 +961,8 @@ public class AVMStoreImpl implements AVMStore, Serializable } dir.turnPrimary(lPath); dir.updateModTime(); + + AVMDAOs.Instance().fAVMNodeDAO.update(dir); } /** @@ -1000,6 +988,8 @@ public class AVMStoreImpl implements AVMStore, Serializable } dir.retarget(lPath, target); dir.updateModTime(); + + AVMDAOs.Instance().fAVMNodeDAO.update(dir); } /** @@ -1037,7 +1027,7 @@ public class AVMStoreImpl implements AVMStore, Serializable * Set the next version id. * @param nextVersionID */ - protected void setNextVersionID(int nextVersionID) + public void setNextVersionID(int nextVersionID) { fNextVersionID = nextVersionID; } @@ -1068,10 +1058,10 @@ public class AVMStoreImpl implements AVMStore, Serializable } /** - * Set the root directory. Hibernate. + * Set the root directory. * @param root */ - protected void setRoot(DirectoryNode root) + public void setRoot(DirectoryNode root) { fRoot = root; } @@ -1086,19 +1076,19 @@ public class AVMStoreImpl implements AVMStore, Serializable } /** - * Set the version (for concurrency control). Hibernate. - * @param vers + * Set the version (for concurrency control). + * @param vers The version for optimistic locks. */ - protected void setVers(long vers) + public void setVers(long vers) { fVers = vers; } /** - * Get the version (for concurrency control). Hibernate. - * @return The version. + * Get the version (for concurrency control). + * @return The version for optimistic locks. */ - protected long getVers() + public long getVers() { return fVers; } @@ -1119,7 +1109,7 @@ public class AVMStoreImpl implements AVMStore, Serializable { return false; } - return fID == ((AVMStore)obj).getId(); + return getId() == ((AVMStore)obj).getId(); } /** @@ -1129,14 +1119,13 @@ public class AVMStoreImpl implements AVMStore, Serializable @Override public int hashCode() { - return (int)fID; + return (int)getId(); } /** - * Purge all nodes reachable only via this version and repostory. + * Purge all nodes reachable only via this version and repository. * @param version */ - @SuppressWarnings("unchecked") public void purgeVersion(int version) { if (version == 0) @@ -1152,17 +1141,16 @@ public class AVMStoreImpl implements AVMStore, Serializable AVMNode root = vRoot.getRoot(); if (!fAVMRepository.can(null, root, PermissionService.DELETE_CHILDREN, true)) { - throw new AccessDeniedException("Not allowed to purge: " + fName + "@" + version); + throw new AccessDeniedException("Not allowed to purge: " + getName() + "@" + version); } root.setIsRoot(false); AVMDAOs.Instance().fAVMNodeDAO.update(root); AVMDAOs.Instance().fVersionRootDAO.delete(vRoot); - if (root.equals(fRoot)) + if (root.equals(getRoot())) { // We have to set a new current root. - // TODO More hibernate goofiness to compensate for: fSuper.getSession().flush(); vRoot = AVMDAOs.Instance().fVersionRootDAO.getMaxVersion(this); - fRoot = vRoot.getRoot(); + setRoot(vRoot.getRoot()); AVMDAOs.Instance().fAVMStoreDAO.update(this); } } @@ -1182,7 +1170,7 @@ public class AVMStoreImpl implements AVMStore, Serializable PropertyValue createdValue = getProperty(ContentModel.PROP_CREATED); Date created = createdValue == null ? (new Date()) : (Date) createdValue.getValue(DataTypeDefinition.DATE); created = (created == null) ? (new Date()) : created; - return new AVMStoreDescriptor(fName, creator, created.getTime()); + return new AVMStoreDescriptor(getName(), creator, created.getTime()); } /** @@ -1209,6 +1197,8 @@ public class AVMStoreImpl implements AVMStore, Serializable } ((LayeredDirectoryNode)node).setOpacity(opacity); node.updateModTime(); + + AVMDAOs.Instance().fAVMNodeDAO.update(node); } // TODO Does it make sense to set properties on DeletedNodes? @@ -1230,10 +1220,12 @@ public class AVMStoreImpl implements AVMStore, Serializable { throw new AccessDeniedException("Not allowed to write: " + path); } - Long qnameEntityId = AVMDAOs.Instance().fQNameDAO.getOrCreateQName(name).getFirst(); - - node.setProperty(qnameEntityId, value); + + node.setProperty(name, value); + node.setGuid(GUID.generate()); + + AVMDAOs.Instance().fAVMNodeDAO.update(node); // guid and property } /** @@ -1255,17 +1247,13 @@ public class AVMStoreImpl implements AVMStore, Serializable } if (properties != null) { - // Convert the property QNames to entities - QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; - Map propertiesByQNameEntityId = new HashMap(properties.size() * 2 + 1); - for (Map.Entry entry : properties.entrySet()) - { - Long qnameEntityId = qnameDAO.getOrCreateQName(entry.getKey()).getFirst(); - propertiesByQNameEntityId.put(qnameEntityId, entry.getValue()); - } - node.addProperties(propertiesByQNameEntityId); + Map props = new HashMap(properties.size()); + props.putAll(properties); + node.addProperties(props); } node.setGuid(GUID.generate()); + + AVMDAOs.Instance().fAVMNodeDAO.update(node); } /** @@ -1287,19 +1275,8 @@ public class AVMStoreImpl implements AVMStore, Serializable { throw new AccessDeniedException("Not allowed to read: " + path); } - // Convert the QName - QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; - Pair qnamePair = qnameDAO.getQName(name); - if (qnamePair == null) - { - // No such QName - return null; - } - else - { - PropertyValue prop = node.getProperty(qnamePair.getFirst()); - return prop; - } + + return node.getProperty(name); } /** @@ -1320,12 +1297,8 @@ public class AVMStoreImpl implements AVMStore, Serializable { throw new AccessDeniedException("Not allowed to read: " + path); } - Map props = node.getProperties(); - // Convert to QNames - QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; - @SuppressWarnings("unchecked") - Map convertedProps = (Map) qnameDAO.convertIdMapToQNameMap(props); - return convertedProps; + + return node.getProperties(); } /** @@ -1347,17 +1320,9 @@ public class AVMStoreImpl implements AVMStore, Serializable } node.setGuid(GUID.generate()); - // convert the QName - QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; - Pair qnamePair = qnameDAO.getQName(name); - if (qnamePair == null) - { - // No such property - } - else - { - node.deleteProperty(qnamePair.getFirst()); - } + node.deleteProperty(name); + + AVMDAOs.Instance().fAVMNodeDAO.update(node); } /** @@ -1378,6 +1343,8 @@ public class AVMStoreImpl implements AVMStore, Serializable } node.setGuid(GUID.generate()); node.deleteProperties(); + + AVMDAOs.Instance().fAVMNodeDAO.update(node); } /** @@ -1387,10 +1354,9 @@ public class AVMStoreImpl implements AVMStore, Serializable */ public void setProperty(QName name, PropertyValue value) { - Long qnameEntityId = AVMDAOs.Instance().fQNameDAO.getOrCreateQName(name).getFirst(); AVMStoreProperty prop = new AVMStorePropertyImpl(); prop.setStore(this); - prop.setQnameId(qnameEntityId); + prop.setQname(name); prop.setValue(value); AVMDAOs.Instance().fAVMStorePropertyDAO.save(prop); } @@ -1414,33 +1380,16 @@ public class AVMStoreImpl implements AVMStore, Serializable */ public PropertyValue getProperty(QName name) { - AVMStoreProperty prop = AVMDAOs.Instance().fAVMStorePropertyDAO.get(this, name); - if (prop == null) - { - return null; - } - return prop.getValue(); + return AVMDAOs.Instance().fAVMStorePropertyDAO.get(this, name); } /** - * Get all the properties associated with this node. + * Get all the properties associated with this store. * @return A Map of the properties. */ - @SuppressWarnings("unchecked") public Map getProperties() { - List props = AVMDAOs.Instance().fAVMStorePropertyDAO.get(this); - - Map propsIdMap = new HashMap(props.size() + 7); - for (AVMStoreProperty prop : props) - { - propsIdMap.put(prop.getQnameId(), prop.getValue()); - } - // Mass-convert - QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; - Map propsQNameMap = (Map) qnameDAO.convertIdMapToQNameMap(propsIdMap); - - return propsQNameMap; + return AVMDAOs.Instance().fAVMStorePropertyDAO.get(this); } /** @@ -1475,7 +1424,6 @@ public class AVMStoreImpl implements AVMStore, Serializable throw new AccessDeniedException("Not allowed to read: " + path); } ContentData content = ((FileNode)node).getContentData(lPath); - // AVMDAOs.Instance().fAVMNodeDAO.flush(); // AVMDAOs.Instance().fAVMNodeDAO.evict(node); return content; } @@ -1504,8 +1452,12 @@ public class AVMStoreImpl implements AVMStore, Serializable // TODO Set modifier. node.updateModTime(); node.setGuid(GUID.generate()); + + //AVMDAOs.Instance().fAVMNodeDAO.update(node); + // TODO review 'optimisation' + AVMDAOs.Instance().fAVMNodeDAO.updateModTimeAndGuid(node); + ContentData content = ((FileNode)node).getContentData(lPath); - // AVMDAOs.Instance().fAVMNodeDAO.flush(); // AVMDAOs.Instance().fAVMNodeDAO.evict(node); return content; } @@ -1531,6 +1483,8 @@ public class AVMStoreImpl implements AVMStore, Serializable } ((FileNode)node).setContentData(data); node.updateModTime(); + + AVMDAOs.Instance().fAVMNodeDAO.update(node); } /** @@ -1552,6 +1506,8 @@ public class AVMStoreImpl implements AVMStore, Serializable } node.copyMetaDataFrom(from, node.getAcl() == null ? null : node.getAcl().getInheritsFrom()); node.setGuid(GUID.generate()); + + AVMDAOs.Instance().fAVMNodeDAO.update(node); } /** @@ -1571,12 +1527,11 @@ public class AVMStoreImpl implements AVMStore, Serializable { throw new AccessDeniedException("Not allowed to write: " + path); } - // Convert the aspect QNames to entities - QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; - Long qnameEntityId = qnameDAO.getOrCreateQName(aspectName).getFirst(); - // Convert the - node.getAspects().add(qnameEntityId); + + node.addAspect(aspectName); node.setGuid(GUID.generate()); + + AVMDAOs.Instance().fAVMNodeDAO.update(node); } /** @@ -1597,10 +1552,8 @@ public class AVMStoreImpl implements AVMStore, Serializable { throw new AccessDeniedException("Not allowed to read properties: " + path); } - Set aspects = node.getAspects(); - QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; - Set aspectQNames = qnameDAO.convertIdsToQNames(aspects); - return aspectQNames; + + return node.getAspects(); } /** @@ -1620,23 +1573,20 @@ public class AVMStoreImpl implements AVMStore, Serializable { throw new AccessDeniedException("Not allowed to write properties: " + path); } - QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; - // Get the persistent ID for the QName and remove from the set - Pair qnamePair = qnameDAO.getQName(aspectName); - if (qnamePair != null) - { - node.getAspects().remove(qnamePair.getFirst()); - } + + node.removeAspect(aspectName); + AspectDefinition def = RawServices.Instance().getDictionaryService().getAspect(aspectName); Map properties = def.getProperties(); - Set propertyQNameIds = qnameDAO.convertQNamesToIds(properties.keySet(), false); - Map nodeProperties = node.getProperties(); - for (Long propertyQNameId : propertyQNameIds) + for (QName propertyQName : properties.keySet()) { - nodeProperties.remove(propertyQNameId); + node.deleteProperty(propertyQName); } + node.setGuid(GUID.generate()); + + AVMDAOs.Instance().fAVMNodeDAO.update(node); } /** @@ -1658,17 +1608,8 @@ public class AVMStoreImpl implements AVMStore, Serializable { throw new AccessDeniedException("Not allowed to read properties: " + path); } - QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; - // Get the persistent ID for the QName and remove from the set - Pair qnamePair = qnameDAO.getQName(aspectName); - if (qnamePair != null) - { - return node.getAspects().contains(qnamePair.getFirst()); - } - else - { - return false; - } + + return node.getAspects().contains(aspectName); } /** @@ -1690,6 +1631,8 @@ public class AVMStoreImpl implements AVMStore, Serializable } node.setAcl(acl); node.setGuid(GUID.generate()); + + AVMDAOs.Instance().fAVMNodeDAO.update(node); } /** @@ -1800,14 +1743,13 @@ public class AVMStoreImpl implements AVMStore, Serializable dir.putChild(name, toLink); toLink.changeAncestor(child); toLink.setVersionID(child.getVersionID() + 1); - // TODO This really shouldn't be here. Leaking layers. - QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO; - Pair revertedQNamePair = qnameDAO.getOrCreateQName(WCMModel.ASPECT_REVERTED); - toLink.getAspects().add(revertedQNamePair.getFirst()); + + toLink.addAspect(WCMModel.ASPECT_REVERTED); + PropertyValue value = new PropertyValue(null, toRevertTo.getId()); - - Pair qnamePair = AVMDAOs.Instance().fQNameDAO.getOrCreateQName(WCMModel.PROP_REVERTED_ID); - toLink.setProperty(qnamePair.getFirst(), value); + toLink.setProperty(WCMModel.PROP_REVERTED_ID, value); + + AVMDAOs.Instance().fAVMNodeDAO.update(toLink); } /* (non-Javadoc) @@ -1826,6 +1768,8 @@ public class AVMStoreImpl implements AVMStore, Serializable throw new AccessDeniedException("Not allowed to write properties: " + path); } node.setGuid(guid); + + AVMDAOs.Instance().fAVMNodeDAO.update(node); } /* (non-Javadoc) @@ -1849,6 +1793,8 @@ public class AVMStoreImpl implements AVMStore, Serializable } PlainFileNode file = (PlainFileNode)node; file.setEncoding(encoding); + + AVMDAOs.Instance().fAVMNodeDAO.update(file); } /* (non-Javadoc) @@ -1872,5 +1818,7 @@ public class AVMStoreImpl implements AVMStore, Serializable } PlainFileNode file = (PlainFileNode)node; file.setMimeType(mimeType); + + AVMDAOs.Instance().fAVMNodeDAO.update(file); } } diff --git a/source/java/org/alfresco/repo/avm/AVMStoreProperty.java b/source/java/org/alfresco/repo/avm/AVMStoreProperty.java index b9474efe19..fc441aabcc 100644 --- a/source/java/org/alfresco/repo/avm/AVMStoreProperty.java +++ b/source/java/org/alfresco/repo/avm/AVMStoreProperty.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -24,6 +24,7 @@ package org.alfresco.repo.avm; import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.service.namespace.QName; /** * Arbitrary properties associated with AVMStores. @@ -46,16 +47,16 @@ public interface AVMStoreProperty /** * Set the property type. * - * @param qnameId the ID of the property QName + * @param qname the store property QName */ - public void setQnameId(Long qnameId); + public void setQname(QName qname); /** * Get the property type. * - * @return returns the ID of the property QName + * @return returns the store property QName */ - public Long getQnameId(); + public QName getQname(); /** * Set the actual property value. diff --git a/source/java/org/alfresco/repo/avm/AVMStorePropertyDAO.java b/source/java/org/alfresco/repo/avm/AVMStorePropertyDAO.java index 5df09045e9..c85362a41b 100644 --- a/source/java/org/alfresco/repo/avm/AVMStorePropertyDAO.java +++ b/source/java/org/alfresco/repo/avm/AVMStorePropertyDAO.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -24,7 +24,9 @@ package org.alfresco.repo.avm; import java.util.List; +import java.util.Map; +import org.alfresco.repo.domain.PropertyValue; import org.alfresco.service.namespace.QName; /** @@ -45,29 +47,29 @@ public interface AVMStorePropertyDAO * @param name The QName of the property. * @return The given AVMStoreProperty or null if not found. */ - public AVMStoreProperty get(AVMStore store, QName name); + public PropertyValue get(AVMStore store, QName name); /** * Get all the properties associated with a store. * @param store The AVMStore whose properties should be fetched. - * @return A List of properties associated with the store. + * @return A map of properties associated with the store. */ - public List get(AVMStore store); + public Map get(AVMStore store); /** * Query store properties by key pattern. * @param store The store. * @param keyPattern An sql 'like' pattern wrapped up in a QName - * @return A List of matching AVMStoreProperties. + * @return A map of matching properties. */ - public List queryByKeyPattern(AVMStore store, QName keyPattern); + public Map queryByKeyPattern(AVMStore store, QName keyPattern); /** * Query all stores' properties by key pattern. * @param keyPattern The sql 'like' pattern wrapped up in a QName - * @return A List of match AVMStoreProperties. + * @return A list of matching properties. */ - public List queryByKeyPattern(QName keyPattern); + public Map> queryByKeyPattern(QName keyPattern); /** * Update a modified property. diff --git a/source/java/org/alfresco/repo/avm/AVMStorePropertyImpl.java b/source/java/org/alfresco/repo/avm/AVMStorePropertyImpl.java index 8aac37943b..a086f674c7 100644 --- a/source/java/org/alfresco/repo/avm/AVMStorePropertyImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMStorePropertyImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -26,12 +26,13 @@ package org.alfresco.repo.avm; import java.io.Serializable; import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.service.namespace.QName; /** * Simple bean to hold properties attached to AVMStores. * @author britt */ -class AVMStorePropertyImpl implements AVMStoreProperty, Serializable +public class AVMStorePropertyImpl implements AVMStoreProperty, Serializable { private static final long serialVersionUID = -5419606158990318723L; @@ -48,7 +49,7 @@ class AVMStorePropertyImpl implements AVMStoreProperty, Serializable /** * The name of the property. */ - private Long qnameId; + private QName qname; /** * The actual PropertyValue. @@ -62,17 +63,17 @@ class AVMStorePropertyImpl implements AVMStoreProperty, Serializable /** * {@inheritDoc} */ - public Long getQnameId() + public QName getQname() { - return qnameId; + return qname; } /** * {@inheritDoc} */ - public void setQnameId(Long qnameId) + public void setQname(QName qname) { - this.qnameId = qnameId; + this.qname = qname; } /** @@ -141,13 +142,13 @@ class AVMStorePropertyImpl implements AVMStoreProperty, Serializable return false; } AVMStoreProperty o = (AVMStoreProperty)other; - return fStore.equals(o.getStore()) && qnameId.equals(o.getQnameId()); + return fStore.equals(o.getStore()) && qname.equals(o.getQname()); } @Override public int hashCode() { - return fStore.hashCode() + qnameId.hashCode(); + return fStore.hashCode() + qname.hashCode(); } } diff --git a/source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java b/source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java index 8baf1c08d8..b91b3c66ca 100644 --- a/source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2008 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -627,6 +627,8 @@ public class AVMSyncServiceImpl implements AVMSyncService AVMDAOs.Instance().fAVMNodeDAO.evict(node); node = AVMDAOs.Instance().fAVMNodeDAO.getByID(node.getId()); node.setAcl(acl); + + AVMDAOs.Instance().fAVMNodeDAO.update(node); } else { diff --git a/source/java/org/alfresco/repo/avm/BasicAttributesImpl.java b/source/java/org/alfresco/repo/avm/BasicAttributesImpl.java index 5a467272a8..08e0d21c0f 100644 --- a/source/java/org/alfresco/repo/avm/BasicAttributesImpl.java +++ b/source/java/org/alfresco/repo/avm/BasicAttributesImpl.java @@ -1,6 +1,25 @@ -/** - * - */ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" */ package org.alfresco.repo.avm; import java.io.Serializable; @@ -10,7 +29,7 @@ import java.io.Serializable; * Implementation of the BasicAttributesBean. * @author britt */ -class BasicAttributesImpl implements BasicAttributes, Serializable +public class BasicAttributesImpl implements BasicAttributes, Serializable { private static final long serialVersionUID = -3796354564923670005L; diff --git a/source/java/org/alfresco/repo/avm/ChildEntryDAO.java b/source/java/org/alfresco/repo/avm/ChildEntryDAO.java index acf1093cab..e58ed8ac4e 100644 --- a/source/java/org/alfresco/repo/avm/ChildEntryDAO.java +++ b/source/java/org/alfresco/repo/avm/ChildEntryDAO.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -54,12 +54,12 @@ public interface ChildEntryDAO public List getByParent(DirectoryNode parent, String childNamePattern); /** - * Get the entry for a given child in a given parent. + * Does the entry exist for a given child in a given parent. * @param parent The parent. * @param child The child. - * @return The ChildEntry or null. + * @return True if it exists */ - public ChildEntry getByParentChild(DirectoryNode parent, AVMNode child); + public boolean existsParentChild(DirectoryNode parent, AVMNode child); /** * Get all the ChildEntries corresponding to the given child. @@ -89,6 +89,8 @@ public interface ChildEntryDAO /** * Evict a child entry. * @param entry + * + * @deprecated */ public void evict(ChildEntry entry); } diff --git a/source/java/org/alfresco/repo/avm/ChildEntryImpl.java b/source/java/org/alfresco/repo/avm/ChildEntryImpl.java index 9ee75067f1..5295410fb3 100644 --- a/source/java/org/alfresco/repo/avm/ChildEntryImpl.java +++ b/source/java/org/alfresco/repo/avm/ChildEntryImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,16 +23,13 @@ package org.alfresco.repo.avm; -import java.io.Serializable; /** * An entry in a directory. Contains a name, parent, and child. * @author britt */ -public class ChildEntryImpl implements ChildEntry, Serializable +public class ChildEntryImpl implements ChildEntry { - private static final long serialVersionUID = -307752114272916930L; - /** * The key. */ @@ -46,7 +43,7 @@ public class ChildEntryImpl implements ChildEntry, Serializable /** * Default constructor for Hibernate. */ - protected ChildEntryImpl() + public ChildEntryImpl() { } diff --git a/source/java/org/alfresco/repo/avm/DeletedNodeImpl.java b/source/java/org/alfresco/repo/avm/DeletedNodeImpl.java index 6f9c0e53b6..a8213f51cb 100644 --- a/source/java/org/alfresco/repo/avm/DeletedNodeImpl.java +++ b/source/java/org/alfresco/repo/avm/DeletedNodeImpl.java @@ -39,11 +39,11 @@ public class DeletedNodeImpl extends AVMNodeImpl implements DeletedNode * The type of node that this is a deleted node for. */ private int fDeletedType; - + /** - * For Hibernate's use. + * Default constructor. */ - protected DeletedNodeImpl() + public DeletedNodeImpl() { } @@ -61,12 +61,16 @@ public class DeletedNodeImpl extends AVMNodeImpl implements DeletedNode AVMStore store, Long parentAcl, ACLCopyMode mode) { super(store); + + setDeletedType(other.getDeletedType()); + + copyACLs(other, parentAcl, mode); + copyCreationAndOwnerBasicAttributes(other); + AVMDAOs.Instance().fAVMNodeDAO.save(this); - AVMDAOs.Instance().fAVMNodeDAO.flush(); + copyProperties(other); copyAspects(other); - copyACLs(other, parentAcl, mode); - copyCreationAndOwnerBasicAttributes(other); } /** @@ -138,7 +142,7 @@ public class DeletedNodeImpl extends AVMNodeImpl implements DeletedNode -1, false, -1, - fDeletedType); + getDeletedType()); } /** @@ -168,7 +172,7 @@ public class DeletedNodeImpl extends AVMNodeImpl implements DeletedNode -1, false, -1, - fDeletedType); + getDeletedType()); } /** @@ -200,7 +204,7 @@ public class DeletedNodeImpl extends AVMNodeImpl implements DeletedNode -1, false, -1, - fDeletedType); + getDeletedType()); } /** diff --git a/source/java/org/alfresco/repo/avm/DirectoryNodeImpl.java b/source/java/org/alfresco/repo/avm/DirectoryNodeImpl.java index 29ddf6cb99..d254f28a77 100644 --- a/source/java/org/alfresco/repo/avm/DirectoryNodeImpl.java +++ b/source/java/org/alfresco/repo/avm/DirectoryNodeImpl.java @@ -23,7 +23,6 @@ package org.alfresco.repo.avm; -import org.alfresco.repo.domain.DbAccessControlList; import org.alfresco.service.cmr.avm.AVMBadArgumentException; import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMNotFoundException; @@ -32,7 +31,7 @@ import org.alfresco.service.cmr.avm.AVMNotFoundException; * Base class for Directories. * @author britt */ -abstract class DirectoryNodeImpl extends AVMNodeImpl implements DirectoryNode +public abstract class DirectoryNodeImpl extends AVMNodeImpl implements DirectoryNode { /** * Default constructor. @@ -40,7 +39,7 @@ abstract class DirectoryNodeImpl extends AVMNodeImpl implements DirectoryNode protected DirectoryNodeImpl() { } - + /** * A pass through constructor. Called when a new concrete subclass * instance is created. @@ -72,8 +71,20 @@ abstract class DirectoryNodeImpl extends AVMNodeImpl implements DirectoryNode ChildKey key = new ChildKey(this, name); ChildEntry newChild = new ChildEntryImpl(key, node); AVMDAOs.Instance().fChildEntryDAO.save(newChild); - AVMDAOs.Instance().fAVMNodeDAO.flush(); + AVMDAOs.Instance().fChildEntryDAO.evict(newChild); AVMDAOs.Instance().fAVMNodeDAO.evict(node); } + + /** + * Does this node directly contain the indicated node. + * + * @param node + * The node we are checking. + * @return Whether node is directly contained. + */ + public boolean directlyContains(AVMNode node) + { + return AVMDAOs.Instance().fChildEntryDAO.existsParentChild(this, node); + } } diff --git a/source/java/org/alfresco/repo/avm/HistoryLinkImpl.java b/source/java/org/alfresco/repo/avm/HistoryLinkImpl.java index 154d140074..c09aaede89 100644 --- a/source/java/org/alfresco/repo/avm/HistoryLinkImpl.java +++ b/source/java/org/alfresco/repo/avm/HistoryLinkImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -29,7 +29,7 @@ import java.io.Serializable; * Holds a ancestor-descendent relationship. * @author britt */ -class HistoryLinkImpl implements HistoryLink, Serializable +public class HistoryLinkImpl implements HistoryLink, Serializable { private static final long serialVersionUID = -430859344980137718L; diff --git a/source/java/org/alfresco/repo/avm/Layered.java b/source/java/org/alfresco/repo/avm/Layered.java index 1d93173dee..196599fce6 100644 --- a/source/java/org/alfresco/repo/avm/Layered.java +++ b/source/java/org/alfresco/repo/avm/Layered.java @@ -1,13 +1,32 @@ -/** - * - */ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" */ package org.alfresco.repo.avm; /** * Layered nodes share these methods. * @author britt */ -interface Layered +public interface Layered extends AVMNode { /** * Get the indirection, or underlying path that this diff --git a/source/java/org/alfresco/repo/avm/LayeredDirectoryNodeImpl.java b/source/java/org/alfresco/repo/avm/LayeredDirectoryNodeImpl.java index 09645de1f9..ce124423c4 100644 --- a/source/java/org/alfresco/repo/avm/LayeredDirectoryNodeImpl.java +++ b/source/java/org/alfresco/repo/avm/LayeredDirectoryNodeImpl.java @@ -49,7 +49,7 @@ import org.alfresco.util.Pair; * * @author britt */ -class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirectoryNode +public class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirectoryNode { static final long serialVersionUID = 4623043057918181724L; @@ -77,14 +77,14 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec * The indirection version. */ private int fIndirectionVersion; - + /** - * Default constructor. Called by Hibernate. + * Default constructor. */ - protected LayeredDirectoryNodeImpl() + public LayeredDirectoryNodeImpl() { } - + /** * Make a new one from a specified indirection path. * @@ -96,30 +96,24 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec public LayeredDirectoryNodeImpl(String indirection, AVMStore store, AVMNode toCopy, Long parentAcl, ACLCopyMode mode) { super(store); - fLayerID = -1; - fIndirection = indirection; - fIndirectionVersion = -1; - fPrimaryIndirection = true; - fOpacity = false; + + setLayerID(-1); + setIndirection(indirection); + setIndirectionVersion(-1); + setPrimaryIndirection(true); + setOpacity(false); + if (toCopy != null) { setVersionID(toCopy.getVersionID() + 1); - } - else - { - setVersionID(1); - } - AVMDAOs.Instance().fAVMNodeDAO.save(this); - AVMDAOs.Instance().fAVMNodeDAO.flush(); - if (toCopy != null) - { - copyProperties(toCopy); + copyACLs(toCopy, parentAcl, mode); - copyAspects(toCopy); copyCreationAndOwnerBasicAttributes(toCopy); } else { + setVersionID(1); + if (indirection != null) { Lookup lookup = AVMRepository.GetInstance().lookupDirectory(-1, indirection); @@ -147,6 +141,14 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec setAcl(DbAccessControlListImpl.createLayeredAcl(null)); } } + + AVMDAOs.Instance().fAVMNodeDAO.save(this); + + if (toCopy != null) + { + copyProperties(toCopy); + copyAspects(toCopy); + } } /** @@ -160,12 +162,23 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec public LayeredDirectoryNodeImpl(LayeredDirectoryNode other, AVMStore repos, Lookup lookup, boolean copyAll, Long parentAcl, ACLCopyMode mode) { super(repos); - fIndirection = other.getIndirection(); - fPrimaryIndirection = other.getPrimaryIndirection(); - fIndirectionVersion = -1; - fLayerID = -1; - fOpacity = false; + + setLayerID(-1); + setIndirection(other.getIndirection()); + setIndirectionVersion(-1); + setPrimaryIndirection(other.getPrimaryIndirection()); + setOpacity(false); + + setVersionID(other.getVersionID() + 1); + + copyACLs(other, parentAcl, mode); + copyCreationAndOwnerBasicAttributes(other); + AVMDAOs.Instance().fAVMNodeDAO.save(this); + + copyProperties(other); + copyAspects(other); + Map children = null; if (copyAll) { @@ -181,12 +194,6 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec ChildEntry entry = new ChildEntryImpl(key, child.getValue()); AVMDAOs.Instance().fChildEntryDAO.save(entry); } - setVersionID(other.getVersionID() + 1); - AVMDAOs.Instance().fAVMNodeDAO.flush(); - copyProperties(other); - copyAspects(other); - copyACLs(other, parentAcl, mode); - copyCreationAndOwnerBasicAttributes(other); } /** @@ -202,12 +209,23 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec public LayeredDirectoryNodeImpl(PlainDirectoryNode other, AVMStore store, Lookup lPath, boolean copyContents, Long parentAcl, ACLCopyMode mode) { super(store); - fIndirection = null; - fPrimaryIndirection = false; - fIndirectionVersion = -1; - fLayerID = -1; - fOpacity = false; + + setLayerID(-1); + setIndirection(null); + setIndirectionVersion(-1); + setPrimaryIndirection(false); + setOpacity(false); + + setVersionID(other.getVersionID() + 1); + + copyACLs(other, parentAcl, mode); + copyCreationAndOwnerBasicAttributes(other); + AVMDAOs.Instance().fAVMNodeDAO.save(this); + + copyProperties(other); + copyAspects(other); + if (copyContents) { for (ChildEntry child : AVMDAOs.Instance().fChildEntryDAO.getByParent(other, null)) @@ -217,12 +235,6 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec AVMDAOs.Instance().fChildEntryDAO.save(newChild); } } - setVersionID(other.getVersionID() + 1); - AVMDAOs.Instance().fAVMNodeDAO.flush(); - copyProperties(other); - copyAspects(other); - copyACLs(other, parentAcl, mode); - copyCreationAndOwnerBasicAttributes(other); } /** @@ -241,13 +253,23 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec public LayeredDirectoryNodeImpl(DirectoryNode dir, AVMStore store, Lookup srcLookup, String name, Long inheritedAcl, ACLCopyMode mode) { super(store); - fIndirection = srcLookup.getIndirectionPath() + "/" + name; - fPrimaryIndirection = true; - fIndirectionVersion = -1; - fLayerID = -1; - fOpacity = false; + + setLayerID(-1); + setIndirection(srcLookup.getIndirectionPath() + "/" + name); + setIndirectionVersion(-1); + setPrimaryIndirection(true); + setOpacity(false); + setVersionID(dir.getVersionID() + 1); + + copyACLs(dir, inheritedAcl, mode); + copyCreationAndOwnerBasicAttributes(dir); + AVMDAOs.Instance().fAVMNodeDAO.save(this); + + copyProperties(dir); + copyAspects(dir); + Map children = dir.getListing(srcLookup, true); for (Map.Entry child : children.entrySet()) { @@ -255,11 +277,6 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec ChildEntry entry = new ChildEntryImpl(key, child.getValue()); AVMDAOs.Instance().fChildEntryDAO.save(entry); } - AVMDAOs.Instance().fAVMNodeDAO.flush(); - copyProperties(dir); - copyAspects(dir); - copyACLs(dir, inheritedAcl, mode); - copyCreationAndOwnerBasicAttributes(dir); } /** @@ -302,9 +319,9 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec */ public String getUnderlying(Lookup lPath) { - if (fPrimaryIndirection) + if (getPrimaryIndirection()) { - return fIndirection; + return getIndirection(); } return lPath.getCurrentIndirection(); } @@ -322,9 +339,9 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec { return -1; } - if (fPrimaryIndirection) + if (getPrimaryIndirection()) { - return fIndirectionVersion; + return getIndirectionVersion(); } return lPath.getCurrentIndirectionVersion(); } @@ -383,6 +400,9 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec newMe.setLayerID(getLayerID()); } newMe.setAncestor(this); + + AVMDAOs.Instance().fAVMNodeDAO.update(newMe); + return newMe; } @@ -405,23 +425,9 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec AVMDAOs.Instance().fChildEntryDAO.delete(existing); } ChildEntry entry = new ChildEntryImpl(key, node); - AVMDAOs.Instance().fAVMNodeDAO.flush(); AVMDAOs.Instance().fChildEntryDAO.save(entry); - AVMDAOs.Instance().fAVMNodeDAO.flush(); } - - /** - * Does this node directly contain the indicated node. - * - * @param node - * The node we are checking. - * @return Whether node is directly contained. - */ - public boolean directlyContains(AVMNode node) - { - return AVMDAOs.Instance().fChildEntryDAO.getByParentChild(this, node) != null; - } - + /** * Get a listing of the virtual contents of this directory. * @@ -445,7 +451,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec { // Get the base listing from the thing we indirect to. Map listing = new HashMap(); - if (!fOpacity) + if (!getOpacity()) { Lookup lookup = AVMRepository.GetInstance().lookupDirectory(getUnderlyingVersion(lPath), getUnderlying(lPath)); if (lookup != null) @@ -585,7 +591,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec } SortedMap baseListing = new TreeMap(String.CASE_INSENSITIVE_ORDER); // If we are not opaque, get the underlying base listing. - if (!fOpacity) + if (!getOpacity()) { Lookup lookup = AVMRepository.GetInstance().lookupDirectory(-1, dir.getIndirection()); if (lookup != null) @@ -675,11 +681,11 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec { return null; } - Pair result = new Pair(AVMNodeUnwrapper.Unwrap(entry.getChild()), true); + Pair result = new Pair(entry.getChild(), true); return result; } // Don't check our underlying directory if we are opaque. - if (fOpacity) + if (getOpacity()) { return null; } @@ -729,7 +735,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec return desc; } // If we are opaque don't check underneath. - if (fOpacity) + if (getOpacity()) { return null; } @@ -795,16 +801,15 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec { DeletedNodeImpl ghost = new DeletedNodeImpl(lPath.getAVMStore(), child.getAcl()); AVMDAOs.Instance().fAVMNodeDAO.save(ghost); - AVMDAOs.Instance().fAVMNodeDAO.flush(); + ghost.setAncestor(child); ghost.setDeletedType(child.getType()); ghost.copyCreationAndOwnerBasicAttributes(child); + + AVMDAOs.Instance().fAVMNodeDAO.update(ghost); + this.putChild(name, ghost); } - else - { - AVMDAOs.Instance().fAVMNodeDAO.flush(); - } } /** @@ -842,15 +847,16 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec checkReadOnly(); } - fIndirection = path; - fPrimaryIndirection = true; + setIndirection(path); + setPrimaryIndirection(true); + // Need to change the permission we point to .... - if (fIndirection != null) + if (getIndirection() != null) { if ((getAcl() == null) || (getAcl().getAclType() == ACLType.LAYERED)) { DbAccessControlList acl = null; - Lookup lookup = AVMRepository.GetInstance().lookupDirectory(-1, fIndirection); + Lookup lookup = AVMRepository.GetInstance().lookupDirectory(-1, getIndirection()); if (lookup != null) { DirectoryNode dir = (DirectoryNode) lookup.getCurrentNode(); @@ -903,6 +909,9 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec { // Note ACLS may COW on next ACL change layeredDirectory.setAcl(acl); + + AVMDAOs.Instance().fAVMNodeDAO.update(layeredDirectory); + Map directChildren = layeredDirectory.getListingDirect((Lookup) null, true); for (String key : directChildren.keySet()) { @@ -961,6 +970,8 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec childNode.setAcl(currentAcl.getCopy(acl.getId(), ACLCopyMode.REDIRECT)); } } + + AVMDAOs.Instance().fAVMNodeDAO.update(childNode); } } } @@ -1036,10 +1047,10 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec path = AVMNodeConverter.ExtendAVMPath(path, name); String indirect = null; int indirectionVersion = -1; - if (fPrimaryIndirection) + if (getPrimaryIndirection()) { - indirect = fIndirection; - indirectionVersion = fIndirectionVersion; + indirect = getIndirection(); + indirectionVersion = getIndirectionVersion(); } else { @@ -1047,7 +1058,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec indirectionVersion = lPath.getCurrentIndirectionVersion(); } return new AVMNodeDescriptor(path, name, AVMNodeType.LAYERED_DIRECTORY, attrs.getCreator(), attrs.getOwner(), attrs.getLastModifier(), attrs.getCreateDate(), attrs - .getModDate(), attrs.getAccessDate(), getId(), getGuid(), getVersionID(), indirect, indirectionVersion, fPrimaryIndirection, fLayerID, fOpacity, -1, -1); + .getModDate(), attrs.getAccessDate(), getId(), getGuid(), getVersionID(), indirect, indirectionVersion, getPrimaryIndirection(), getLayerID(), getOpacity(), -1, -1); } /** @@ -1063,8 +1074,8 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec String path = lPath.getRepresentedPath(); String name = path.substring(path.lastIndexOf("/") + 1); return new AVMNodeDescriptor(path, name, AVMNodeType.LAYERED_DIRECTORY, attrs.getCreator(), attrs.getOwner(), attrs.getLastModifier(), attrs.getCreateDate(), attrs - .getModDate(), attrs.getAccessDate(), getId(), getGuid(), getVersionID(), getUnderlying(lPath), getUnderlyingVersion(lPath), fPrimaryIndirection, fLayerID, - fOpacity, -1, -1); + .getModDate(), attrs.getAccessDate(), getId(), getGuid(), getVersionID(), getUnderlying(lPath), getUnderlyingVersion(lPath), getPrimaryIndirection(), getLayerID(), + getOpacity(), -1, -1); } /** @@ -1084,10 +1095,10 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec String path = parentPath.endsWith("/") ? parentPath + name : parentPath + "/" + name; String indirection = null; int indirectionVersion = -1; - if (fPrimaryIndirection) + if (getPrimaryIndirection()) { - indirection = fIndirection; - indirectionVersion = fIndirectionVersion; + indirection = getIndirection(); + indirectionVersion = getIndirectionVersion(); } else { @@ -1095,7 +1106,7 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec indirectionVersion = parentIndirectionVersion; } return new AVMNodeDescriptor(path, name, AVMNodeType.LAYERED_DIRECTORY, attrs.getCreator(), attrs.getOwner(), attrs.getLastModifier(), attrs.getCreateDate(), attrs - .getModDate(), attrs.getAccessDate(), getId(), getGuid(), getVersionID(), indirection, indirectionVersion, fPrimaryIndirection, fLayerID, fOpacity, -1, -1); + .getModDate(), attrs.getAccessDate(), getId(), getGuid(), getVersionID(), indirection, indirectionVersion, getPrimaryIndirection(), getLayerID(), getOpacity(), -1, -1); } /** diff --git a/source/java/org/alfresco/repo/avm/LayeredFileNodeImpl.java b/source/java/org/alfresco/repo/avm/LayeredFileNodeImpl.java index fa84a33da1..8492a143a0 100644 --- a/source/java/org/alfresco/repo/avm/LayeredFileNodeImpl.java +++ b/source/java/org/alfresco/repo/avm/LayeredFileNodeImpl.java @@ -35,7 +35,7 @@ import org.alfresco.service.cmr.repository.ContentData; * * @author britt */ -class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode +public class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode { static final long serialVersionUID = 9208423010479156363L; @@ -43,19 +43,19 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode * The indirection. */ private String fIndirection; - + /** * The indirection version. */ private int fIndirectionVersion; - + /** - * Anonymous constructor. + * Default constructor. */ - protected LayeredFileNodeImpl() + public LayeredFileNodeImpl() { } - + /** * Basically a copy constructor. Used when a branch is created from a layered file. * @@ -67,15 +67,17 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode public LayeredFileNodeImpl(LayeredFileNode other, AVMStore store, Long parentAcl, ACLCopyMode mode) { super(store); - fIndirection = other.getIndirection(); - fIndirectionVersion = -1; + setIndirection(other.getIndirection()); + setIndirectionVersion(-1); setVersionID(other.getVersionID() + 1); - AVMDAOs.Instance().fAVMNodeDAO.save(this); - AVMDAOs.Instance().fAVMNodeDAO.flush(); - copyProperties(other); - copyAspects(other); + copyACLs(other, parentAcl, mode); copyCreationAndOwnerBasicAttributes(other); + + AVMDAOs.Instance().fAVMNodeDAO.save(this); + + copyProperties(other); + copyAspects(other); } /** @@ -89,14 +91,13 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode public LayeredFileNodeImpl(String indirection, AVMStore store, DbAccessControlList acl) { super(store); - fIndirection = indirection; - fIndirectionVersion = -1; + setIndirection(indirection); + setIndirectionVersion(-1); setVersionID(1); - AVMDAOs.Instance().fAVMNodeDAO.save(this); - AVMDAOs.Instance().fAVMNodeDAO.flush(); + if (acl != null) { - this.setAcl(acl); + setAcl(acl); } else { @@ -136,7 +137,7 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode public AVMNode copy(Lookup lPath) { // LayeredFileNodes are always copied. - Lookup lookup = AVMRepository.GetInstance().lookup(-1, fIndirection, false); + Lookup lookup = AVMRepository.GetInstance().lookup(-1, getIndirection(), false); if (lookup == null) { throw new AVMException("Unbacked layered file node."); @@ -178,7 +179,7 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode */ public String getUnderlying(Lookup lookup) { - return fIndirection; + return getIndirection(); } /** @@ -190,7 +191,7 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode */ public String toString(Lookup lPath) { - return "[LF:" + getId() + ":" + fIndirection + "]"; + return "[LF:" + getId() + ":" + getIndirection() + "]"; } /** @@ -248,7 +249,7 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode BasicAttributes attrs = getBasicAttributes(); String path = parentPath.endsWith("/") ? parentPath + name : parentPath + "/" + name; return new AVMNodeDescriptor(path, name, AVMNodeType.LAYERED_FILE, attrs.getCreator(), attrs.getOwner(), attrs.getLastModifier(), attrs.getCreateDate(), - attrs.getModDate(), attrs.getAccessDate(), getId(), getGuid(), getVersionID(), fIndirection, fIndirectionVersion, false, -1, false, 0, -1); + attrs.getModDate(), attrs.getAccessDate(), getId(), getGuid(), getVersionID(), getIndirection(), getIndirectionVersion(), false, -1, false, 0, -1); } /** @@ -315,7 +316,7 @@ class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode { return -1; } - return fIndirectionVersion; + return getIndirectionVersion(); } /* diff --git a/source/java/org/alfresco/repo/avm/Lookup.java b/source/java/org/alfresco/repo/avm/Lookup.java index 679825cb5b..3b68871f7c 100644 --- a/source/java/org/alfresco/repo/avm/Lookup.java +++ b/source/java/org/alfresco/repo/avm/Lookup.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -317,6 +317,9 @@ class Lookup implements Serializable { // Inform the store of a new root. fAVMStore.setNewRoot((DirectoryNode)node); + + ((DirectoryNode)node).setIsRoot(true); + AVMDAOs.Instance().fAVMNodeDAO.update(((DirectoryNode)node)); AVMDAOs.Instance().fAVMStoreDAO.update(fAVMStore); return; } diff --git a/source/java/org/alfresco/repo/avm/MergeLinkImpl.java b/source/java/org/alfresco/repo/avm/MergeLinkImpl.java index 04506168e4..d40a268c3b 100644 --- a/source/java/org/alfresco/repo/avm/MergeLinkImpl.java +++ b/source/java/org/alfresco/repo/avm/MergeLinkImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -29,7 +29,7 @@ import java.io.Serializable; * This contains a single merged from-to relationship. * @author britt */ -class MergeLinkImpl implements MergeLink, Serializable +public class MergeLinkImpl implements MergeLink, Serializable { private static final long serialVersionUID = 6672271083042424944L; diff --git a/source/java/org/alfresco/repo/avm/NOOPLookupCache.java b/source/java/org/alfresco/repo/avm/NOOPLookupCache.java index f2f0f965a7..84188c90d0 100644 --- a/source/java/org/alfresco/repo/avm/NOOPLookupCache.java +++ b/source/java/org/alfresco/repo/avm/NOOPLookupCache.java @@ -80,7 +80,6 @@ public class NOOPLookupCache implements LookupCache { return null; } - dir = (DirectoryNode)AVMNodeUnwrapper.Unwrap(dir); // Add an entry for the root. result.add(dir, "", true, write); dir = (DirectoryNode)result.getCurrentNode(); diff --git a/source/java/org/alfresco/repo/avm/OrphanReaper.java b/source/java/org/alfresco/repo/avm/OrphanReaper.java index 29aec69fb1..1f3754f71a 100644 --- a/source/java/org/alfresco/repo/avm/OrphanReaper.java +++ b/source/java/org/alfresco/repo/avm/OrphanReaper.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,7 +32,6 @@ import org.alfresco.service.transaction.TransactionService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.SessionFactory; -import org.springframework.orm.hibernate3.HibernateTemplate; /** * This is the background thread for reaping no longer referenced nodes in the AVM repository. These orphans arise from @@ -292,7 +291,7 @@ public class OrphanReaper mergedFrom = mlink.getMfrom(); AVMDAOs.Instance().fMergeLinkDAO.delete(mlink); } - AVMDAOs.Instance().fAVMNodeDAO.flush(); + // Get all the nodes that have this node as ancestor. List links = AVMDAOs.Instance().fHistoryLinkDAO.getByAncestor(node); for (HistoryLink link : links) @@ -312,10 +311,13 @@ public class OrphanReaper link.getMto().setMergedFrom(ancestor); AVMDAOs.Instance().fMergeLinkDAO.delete(link); } + // Get rid of all properties belonging to this node. - // AVMDAOs.Instance().fAVMNodePropertyDAO.deleteAll(node); + AVMDAOs.Instance().fAVMNodeDAO.deleteProperties(node.getId()); + // Get rid of all aspects belonging to this node. - // AVMDAOs.Instance().fAVMAspectNameDAO.delete(node); + AVMDAOs.Instance().fAVMNodeDAO.deleteAspects(node.getId()); + // Get rid of ACL. DbAccessControlList acl = node.getAcl(); node.setAcl(null); diff --git a/source/java/org/alfresco/repo/avm/PlainDirectoryNodeImpl.java b/source/java/org/alfresco/repo/avm/PlainDirectoryNodeImpl.java index f160ac4206..cbaaa67d72 100644 --- a/source/java/org/alfresco/repo/avm/PlainDirectoryNodeImpl.java +++ b/source/java/org/alfresco/repo/avm/PlainDirectoryNodeImpl.java @@ -42,7 +42,7 @@ import org.alfresco.util.Pair; * A plain directory. No monkey tricks except for possiblyCopy. * @author britt */ -class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectoryNode +public class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectoryNode { static final long serialVersionUID = 9423813734583003L; @@ -54,27 +54,30 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory { super(store); setVersionID(1); - AVMDAOs.Instance().fAVMNodeDAO.save(this); - AVMDAOs.Instance().fAVMNodeDAO.flush(); } - + /** - * Anonymous constructor. + * Default constructor. */ - protected PlainDirectoryNodeImpl() + public PlainDirectoryNodeImpl() { } - + /** * Copy like constructor. * @param other The other directory. * @param repos The AVMStore Object that will own us. */ - @SuppressWarnings("unchecked") public PlainDirectoryNodeImpl(PlainDirectoryNode other, AVMStore store, Long parentAcl, ACLCopyMode mode) { super(store); + + setVersionID(other.getVersionID() + 1); + + copyACLs(other, parentAcl, mode); + copyCreationAndOwnerBasicAttributes(other); + AVMDAOs.Instance().fAVMNodeDAO.save(this); for (ChildEntry child : AVMDAOs.Instance().fChildEntryDAO.getByParent(other, null)) { @@ -83,30 +86,16 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory child.getChild()); AVMDAOs.Instance().fChildEntryDAO.save(newChild); } - setVersionID(other.getVersionID() + 1); - AVMDAOs.Instance().fAVMNodeDAO.flush(); + copyProperties(other); copyAspects(other); - copyACLs(other, parentAcl, mode); - copyCreationAndOwnerBasicAttributes(other); } - - /** - * Does this directory directly contain the given node. - * @param node The node to check. - * @return Whether it was found. - */ - public boolean directlyContains(AVMNode node) - { - return AVMDAOs.Instance().fChildEntryDAO.getByParentChild(this, node) != null; - } - + /** * Get a directory listing. * @param lPath The lookup path. * @return The listing. */ - @SuppressWarnings("unchecked") public Map getListing(Lookup lPath, boolean includeDeleted) { return getListing(lPath, null, includeDeleted); @@ -119,7 +108,6 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory * @param includeDeleted Include deleted nodes. * @return The listing. */ - @SuppressWarnings("unchecked") public Map getListing(Lookup lPath, String childNamePattern, boolean includeDeleted) { Map result = new HashMap(); @@ -138,7 +126,7 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory { continue; } - result.put(child.getKey().getName(), AVMNodeUnwrapper.Unwrap(child.getChild())); + result.put(child.getKey().getName(), child.getChild()); } return result; } @@ -228,7 +216,6 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory * @param includeDeleted Whether to lookup deleted nodes. * @return The child or null. */ - @SuppressWarnings("unchecked") public Pair lookupChild(Lookup lPath, String name, boolean includeDeleted) { ChildKey key = new ChildKey(this, name); @@ -241,10 +228,7 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory { return null; } - // We're doing the hand unrolling of the proxy because - // Hibernate/CGLIB proxies are broken. - - Pair result = new Pair(AVMNodeUnwrapper.Unwrap(entry.getChild()), true); + Pair result = new Pair(entry.getChild(), true); return result; } @@ -276,7 +260,6 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory * @param lPath The path by which this was found. * @param name The name of the child to remove. */ - @SuppressWarnings("unchecked") public void removeChild(Lookup lPath, String name) { if (DEBUG) @@ -297,16 +280,15 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory { DeletedNodeImpl ghost = new DeletedNodeImpl(lPath.getAVMStore(), child.getAcl()); AVMDAOs.Instance().fAVMNodeDAO.save(ghost); - AVMDAOs.Instance().fAVMNodeDAO.flush(); + ghost.setAncestor(child); ghost.setDeletedType(child.getType()); ghost.copyCreationAndOwnerBasicAttributes(child); + + AVMDAOs.Instance().fAVMNodeDAO.update(ghost); + putChild(name, ghost); } - else - { - AVMDAOs.Instance().fAVMNodeDAO.flush(); - } } } @@ -328,7 +310,6 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory AVMDAOs.Instance().fChildEntryDAO.delete(existing); } ChildEntry entry = new ChildEntryImpl(key, node); - AVMDAOs.Instance().fAVMNodeDAO.flush(); AVMDAOs.Instance().fChildEntryDAO.save(entry); } @@ -357,6 +338,8 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory newMe = new LayeredDirectoryNodeImpl(this, lPath.getAVMStore(), lPath, lPath.isInThisLayer(), parentAclId, ACLCopyMode.COPY); ((LayeredDirectoryNodeImpl)newMe).setLayerID(lPath.getTopLayer().getLayerID()); + + AVMDAOs.Instance().fAVMNodeDAO.update(newMe); } else { @@ -541,8 +524,6 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory } // Get rid of the DELETED_NODE child. AVMDAOs.Instance().fChildEntryDAO.delete(child); - // Another &*#*&#$ flush. - AVMDAOs.Instance().fAVMNodeDAO.flush(); } // Make the new entry and save. ChildEntry newChild = new ChildEntryImpl(key, node); diff --git a/source/java/org/alfresco/repo/avm/PlainFileNodeImpl.java b/source/java/org/alfresco/repo/avm/PlainFileNodeImpl.java index 52520a10ea..ff273a8bda 100644 --- a/source/java/org/alfresco/repo/avm/PlainFileNodeImpl.java +++ b/source/java/org/alfresco/repo/avm/PlainFileNodeImpl.java @@ -35,13 +35,14 @@ import org.alfresco.service.cmr.avm.AVMException; import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentReader; +import org.alfresco.service.namespace.QName; /** * A plain old file. Contains a Content object. * @author britt */ -class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode +public class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode { static final long serialVersionUID = 8720376837929735294L; @@ -68,10 +69,10 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode /** * Default constructor. */ - protected PlainFileNodeImpl() + public PlainFileNodeImpl() { } - + /** * Make one from just an AVMStore. * This is the constructor used when a brand new plain file is being made. @@ -80,9 +81,7 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode public PlainFileNodeImpl(AVMStore store) { super(store); - setVersionID(1); - AVMDAOs.Instance().fAVMNodeDAO.save(this); - AVMDAOs.Instance().fAVMNodeDAO.flush(); + setVersionID(1); } /** @@ -98,12 +97,14 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode // layered files. setContentData(other.getContentData(null)); setVersionID(other.getVersionID() + 1); + + copyACLs(other, parentAcl, mode); + copyCreationAndOwnerBasicAttributes(other); + AVMDAOs.Instance().fAVMNodeDAO.save(this); - AVMDAOs.Instance().fAVMNodeDAO.flush(); + copyProperties(other); copyAspects(other); - copyACLs(other, parentAcl, mode); - copyCreationAndOwnerBasicAttributes(other); } // TODO Is there a reason for passing all these parameters instead @@ -118,8 +119,8 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode public PlainFileNodeImpl(AVMStore store, BasicAttributes attrs, ContentData content, - Map props, - Set aspects, + Map props, + Set aspects, DbAccessControlList acl, int versionID, Long parentAcl, ACLCopyMode mode) { @@ -127,14 +128,16 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode setContentData(content); setBasicAttributes(attrs); setVersionID(versionID + 1); - AVMDAOs.Instance().fAVMNodeDAO.save(this); - AVMDAOs.Instance().fAVMNodeDAO.flush(); - addProperties(props); - setAspects(new HashSet(aspects)); + if (acl != null) { setAcl(acl.getCopy(parentAcl, mode)); } + + AVMDAOs.Instance().fAVMNodeDAO.save(this); + + addProperties(props); + setAspects(new HashSet(aspects)); } /** @@ -325,11 +328,11 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode */ private long getFileLength() { - if (fContentURL == null) + if (getContentURL() == null) { return 0L; } - ContentReader reader = RawServices.Instance().getContentStore().getReader(fContentURL); + ContentReader reader = RawServices.Instance().getContentStore().getReader(getContentURL()); return reader.getSize(); } @@ -366,14 +369,14 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode */ public void setContentData(ContentData contentData) { - fContentURL = contentData.getContentUrl(); - fMimeType = contentData.getMimetype(); - if (fMimeType == null) + setContentURL(contentData.getContentUrl()); + setMimeType(contentData.getMimetype()); + if (getMimeType() == null) { throw new AVMException("Null mime type."); } - fEncoding = contentData.getEncoding(); - fLength = contentData.getSize(); + setEncoding(contentData.getEncoding()); + setLength(contentData.getSize()); } /** @@ -391,7 +394,7 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode */ public ContentData getContentData() { - return new ContentData(fContentURL, fMimeType, fLength, fEncoding); + return new ContentData(getContentURL(), getMimeType(), getLength(), getEncoding()); } } diff --git a/source/java/org/alfresco/repo/avm/TransactionalLookupCache.java b/source/java/org/alfresco/repo/avm/TransactionalLookupCache.java index 94b0537126..e3365bc0b1 100644 --- a/source/java/org/alfresco/repo/avm/TransactionalLookupCache.java +++ b/source/java/org/alfresco/repo/avm/TransactionalLookupCache.java @@ -40,6 +40,8 @@ import org.springframework.beans.factory.InitializingBean; * A Transactional? implementation of AVM path lookup cache * * @author britt + * + * @deprecated */ public class TransactionalLookupCache implements LookupCache, InitializingBean { @@ -153,7 +155,6 @@ public class TransactionalLookupCache implements LookupCache, InitializingBean { return null; } - dir = (DirectoryNode)AVMNodeUnwrapper.Unwrap(dir); // Add an entry for the root. result.add(dir, "", true, write); dir = (DirectoryNode)result.getCurrentNode(); diff --git a/source/java/org/alfresco/repo/avm/VersionRootDAO.java b/source/java/org/alfresco/repo/avm/VersionRootDAO.java index 7b1f545bbd..2089d752cf 100644 --- a/source/java/org/alfresco/repo/avm/VersionRootDAO.java +++ b/source/java/org/alfresco/repo/avm/VersionRootDAO.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -37,7 +37,9 @@ public interface VersionRootDAO * @param vr The VersionRoot to save. */ public void save(VersionRoot vr); - + + public void update(VersionRoot vr); + /** * Delete a VersionRoot. * @param vr The VersionRoot to delete. diff --git a/source/java/org/alfresco/repo/avm/actions/SimpleAVMSubmitAction.java b/source/java/org/alfresco/repo/avm/actions/SimpleAVMSubmitAction.java index eb3f7edbe2..b0deb9d7df 100644 --- a/source/java/org/alfresco/repo/avm/actions/SimpleAVMSubmitAction.java +++ b/source/java/org/alfresco/repo/avm/actions/SimpleAVMSubmitAction.java @@ -143,8 +143,6 @@ public class SimpleAVMSubmitAction extends ActionExecuterAbstractBase fAVMSyncService.update(diffs, fExcluder, false, false, true, true, "Submit of item: " + AVMNodeConverter.SplitBase(path)[1], null); // Cleanup by flattening the source relative to the destination. - // This is an ugliness to prevent database write misorderings in flatten. - AVMDAOs.Instance().fAVMNodeDAO.flush(); fAVMSyncService.flatten(storePath[0] + ":/" + JNDIConstants.DIR_DEFAULT_WWW, websiteName + ":/" + JNDIConstants.DIR_DEFAULT_WWW); } diff --git a/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml b/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml deleted file mode 100644 index c17357d428..0000000000 --- a/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml +++ /dev/null @@ -1,376 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SELECT - {asp.*} - FROM - avm_store_properties asp - JOIN alf_qname qn ON (qn.id = asp.qname_id) - JOIN alf_namespace ns ON (ns.id = qn.ns_id) - WHERE - ns.uri LIKE :uri AND - upper(qn.local_name) LIKE upper(:localName) - - - - - SELECT - {asp.*} - FROM - avm_store_properties asp - JOIN alf_qname qn ON (qn.id = asp.qname_id) - JOIN alf_namespace ns ON (ns.id = qn.ns_id) - WHERE - asp.avm_store_id = :storeId AND - ns.uri LIKE :uri AND - upper(qn.local_name) LIKE upper(:localName) - - - - DELETE - FROM - avm_store_properties - WHERE - avm_store_id = :storeId AND - qname_id = :qnameId - - - - DELETE - FROM - avm_store_properties - WHERE - avm_store_id = :storeId - - - diff --git a/source/java/org/alfresco/repo/avm/hibernate/AVMNodeDAOHibernate.java b/source/java/org/alfresco/repo/avm/hibernate/AVMNodeDAOHibernate.java deleted file mode 100644 index 5a7eff01bc..0000000000 --- a/source/java/org/alfresco/repo/avm/hibernate/AVMNodeDAOHibernate.java +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" */ - -package org.alfresco.repo.avm.hibernate; - -import java.util.List; - -import org.alfresco.repo.avm.AVMNode; -import org.alfresco.repo.avm.AVMNodeDAO; -import org.alfresco.repo.avm.AVMNodeImpl; -import org.alfresco.repo.avm.AVMNodeUnwrapper; -import org.alfresco.repo.avm.AVMStore; -import org.alfresco.repo.avm.DirectoryNode; -import org.alfresco.repo.avm.LayeredDirectoryNode; -import org.alfresco.repo.avm.LayeredFileNode; -import org.alfresco.repo.domain.hibernate.SessionSizeResourceManager; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.CacheMode; -import org.hibernate.Query; -import org.hibernate.ScrollMode; -import org.hibernate.ScrollableResults; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - -/** - * @author britt - * - */ -class AVMNodeDAOHibernate extends HibernateDaoSupport implements - AVMNodeDAO -{ - private static Log fgLogger = LogFactory.getLog(AVMNodeDAOHibernate.class); - - /** - * Do nothing constructor. - */ - public AVMNodeDAOHibernate() - { - super(); - } - - /** - * Save the given node, having never been saved before. - */ - public void save(AVMNode node) - { - getSession().save(node); - SessionCacheChecker.instance.check(); - } - - /** - * Delete a single node. - * @param node The node to delete. - */ - public void delete(AVMNode node) - { - getSession().delete(node); - SessionCacheChecker.instance.check(); - } - - /** - * Get by ID. - * @param id The id to get. - */ - public AVMNode getByID(long id) - { - SessionCacheChecker.instance.check(); - return AVMNodeUnwrapper.Unwrap((AVMNode)getSession().get(AVMNodeImpl.class, id)); - } - - /** - * Update a node that has been dirtied. - * @param node The node. - */ - public void update(AVMNode node) - { - getSession().flush(); - } - - /** - * Get the root of a particular version. - * @param store The store we're querying. - * @param version The version. - * @return The VersionRoot or null. - */ - public DirectoryNode getAVMStoreRoot(AVMStore store, int version) - { - Query query = - getSession().getNamedQuery("VersionRoot.GetVersionRoot"); - query.setEntity("store", store); - query.setInteger("version", version); - AVMNode root = (AVMNode)query.uniqueResult(); - if (root == null) - { - return null; - } - return (DirectoryNode)AVMNodeUnwrapper.Unwrap(root); - } - - /** - * Get the ancestor of a node. - * @param node The node whose ancestor is desired. - * @return The ancestor or null. - */ - public AVMNode getAncestor(AVMNode node) - { - Query query = getSession().createQuery("select hl.ancestor from HistoryLinkImpl hl where hl.descendent = :desc"); - query.setEntity("desc", node); - return (AVMNode)query.uniqueResult(); - } - - /** - * Get the node the given node was merged from. - * @param node The node whose merged from is desired. - * @return The merged from node or null. - */ - public AVMNode getMergedFrom(AVMNode node) - { - Query query = getSession().createQuery("select ml.mfrom from MergeLinkImpl ml where ml.mto = :to"); - query.setEntity("to", node); - return (AVMNode)query.uniqueResult(); - } - - /** - * Get up to batchSize orphans. - * @param batchSize Get no more than this number. - * @return A List of orphaned AVMNodes. - */ - @SuppressWarnings("unchecked") - public List getOrphans(int batchSize) - { - Query query = getSession().getNamedQuery("FindOrphans2"); - query.setMaxResults(batchSize); - return (List)query.list(); - } - - /** - * Get all content urls in he AVM Repository. - * @return A List of URL Strings. - */ - @SuppressWarnings("unchecked") - public void getContentUrls(ContentUrlHandler handler) - { - Query query = getSession().getNamedQuery("PlainFileNode.GetContentUrls"); - ScrollableResults results = null; - try - { - results = query.scroll(ScrollMode.FORWARD_ONLY); - while (results.next()) - { - String contentUrl = results.getText(0); - handler.handle(contentUrl); - } - } - finally - { - if (results != null) - { - results.close(); - } - } - } - - /** - * Get all AVMNodes that are new in the given store. - * @param store The given store. - * @return A List of AVMNodes. - */ - @SuppressWarnings("unchecked") - public List getNewInStore(AVMStore store) - { - Query query = getSession().getNamedQuery("AVMNode.GetNewInStore"); - query.setEntity("store", store); - return (List)query.list(); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.avm.AVMNodeDAO#getNewInStoreIDs(org.alfresco.repo.avm.AVMStore) - */ - @SuppressWarnings("unchecked") - public List getNewInStoreIDs(AVMStore store) - { - Query query = getSession().getNamedQuery("AVMNode.GetNewInStoreID"); - query.setEntity("store", store); - return (List)query.list(); - } - - /** - * Inappropriate hack to get Hibernate to play nice. - */ - public void flush() - { - getSession().flush(); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.avm.AVMNodeDAO#getEmptyGUIDS(int) - */ - @SuppressWarnings("unchecked") - public List getEmptyGUIDS(int count) - { - Query query = getSession().createQuery("from AVMNodeImpl an where an.guid is null"); - query.setMaxResults(count); - return (List)query.list(); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.avm.AVMNodeDAO#getNullVersionLayeredDirectories(int) - */ - @SuppressWarnings("unchecked") - public List getNullVersionLayeredDirectories(int count) - { - Query query = getSession().createQuery("from LayeredDirectoryNodeImpl ldn " + - "where ldn.indirectionVersion is null"); - query.setMaxResults(count); - return (List)query.list(); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.avm.AVMNodeDAO#getNullVersionLayeredFiles(int) - */ - @SuppressWarnings("unchecked") - public List getNullVersionLayeredFiles(int count) - { - Query query = getSession().createQuery("from LayeredFileNodeImpl lfn " + - "where lfn.indirectionVersion is null"); - query.setMaxResults(count); - return (List)query.list(); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.avm.AVMNodeDAO#evict(org.alfresco.repo.avm.AVMNode) - */ - public void evict(AVMNode node) - { - getSession().flush(); - getSession().evict(node); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.avm.AVMNodeDAO#clear() - */ - public void clear() - { - if (fgLogger.isDebugEnabled()) - { - fgLogger.debug(getSession().getStatistics()); - } - getSession().flush(); - SessionSizeResourceManager.clear(getSession()); - if (fgLogger.isDebugEnabled()) - { - fgLogger.debug(getSession().getStatistics()); - } - } - - /* (non-Javadoc) - * @see org.alfresco.repo.avm.AVMNodeDAO#noCache() - */ - public void noCache() - { - getSession().getSessionFactory().evict(AVMNodeImpl.class); - getSession().setCacheMode(CacheMode.IGNORE); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.avm.AVMNodeDAO#yesCache() - */ - public void yesCache() - { - getSession().setCacheMode(CacheMode.NORMAL); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.avm.AVMNodeDAO#clearNewInStore(org.alfresco.repo.avm.AVMStore) - */ - public void clearNewInStore(AVMStore store) - { - Query query = getSession().getNamedQuery("AVMNode.ClearNewInStore"); - query.setEntity("store", store); - query.executeUpdate(); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.avm.AVMNodeDAO#getNewLayeredInStoreIDs(org.alfresco.repo.avm.AVMStore) - */ - @SuppressWarnings("unchecked") - public List getNewLayeredInStoreIDs(AVMStore store) - { - Query query = getSession().getNamedQuery("AVMNode.GetNewLayeredDirectory"); - query.setEntity("store", store); - List ids = (List)query.list(); - query = getSession().getNamedQuery("AVMNode.GetNewLayeredFile"); - query.setEntity("store", store); - ids.addAll((List)query.list()); - return ids; - } -} diff --git a/source/java/org/alfresco/repo/avm/hibernate/AVMStoreDAOHibernate.java b/source/java/org/alfresco/repo/avm/hibernate/AVMStoreDAOHibernate.java deleted file mode 100644 index 3d30eddad4..0000000000 --- a/source/java/org/alfresco/repo/avm/hibernate/AVMStoreDAOHibernate.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" */ - -package org.alfresco.repo.avm.hibernate; - -import java.util.ArrayList; -import java.util.List; - -import org.alfresco.repo.avm.AVMNode; -import org.alfresco.repo.avm.AVMStore; -import org.alfresco.repo.avm.AVMStoreDAO; -import org.alfresco.repo.avm.AVMStoreImpl; -import org.alfresco.repo.cache.SimpleCache; -import org.hibernate.Query; -import org.hibernate.proxy.HibernateProxy; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - -/** - * The Hibernate version for AVMStoreDAO - * @author britt - */ -class AVMStoreDAOHibernate extends HibernateDaoSupport implements - AVMStoreDAO -{ - /** - * An in memory cache of name to primary key mappings. - */ - private SimpleCache fNameCache; - - /** - * Do nothing constructor. - */ - public AVMStoreDAOHibernate() - { - super(); - } - - public void setCache(SimpleCache cache) - { - fNameCache = cache; - } - - /** - * Save a store, never before saved. - * @param store The store - */ - public void save(AVMStore store) - { - getSession().save(store); - } - - /** - * Delete the given AVMStore. - * @param store The AVMStore. - */ - public void delete(AVMStore store) - { - getSession().delete(store); - } - - /** - * Get all stores. - * @return A List of all the AVMStores. - */ - @SuppressWarnings("unchecked") - public List getAll() - { - Query query = getSession().createQuery("from AVMStoreImpl r"); - List result = (List)query.list(); - List ret = new ArrayList(result.size()); - for (AVMStore store : result) - { - ret.add(forceNonLazy(store)); - } - return ret; - } - - /** - * Get a store by name. - * @param name The name of the store. - * @return The store or null if not found. - */ - public AVMStore getByName(String name) - { - Long id = null; - id = fNameCache.get(name); - if (id != null) - { - return forceNonLazy((AVMStore)getSession().get(AVMStoreImpl.class, id)); - } - Query query = getSession().createQuery("from AVMStoreImpl st " + - "where st.name = :name"); - query.setParameter("name", name); - AVMStore result = (AVMStore)query.uniqueResult(); - if (result != null) - { - fNameCache.put(name, result.getId()); - } - return forceNonLazy(result); - } - - /** - * Get the AVM Store that has the given root as HEAD. - * @param root The root to query. - * @return The matching store or null. - */ - public AVMStore getByRoot(AVMNode root) - { - Query query = getSession().createQuery("from AVMStoreImpl st " + - "where st.root = :root"); - query.setEntity("root", root); - return forceNonLazy((AVMStore)query.uniqueResult()); - } - - /** - * Update the given AVMStore record. - * @param store The dirty AVMStore. - */ - public void update(AVMStore store) - { - // No op in Hibernate. - } - - /* (non-Javadoc) - * @see org.alfresco.repo.avm.AVMStoreDAO#getByID(long) - */ - public AVMStore getByID(long id) - { - AVMStore result = (AVMStore)getSession().get(AVMStoreImpl.class, id); - return forceNonLazy(result); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.avm.AVMStoreDAO#invalidateCache() - */ - public void invalidateCache() - { - fNameCache.clear(); - } - - private AVMStore forceNonLazy(AVMStore store) - { - if (store instanceof HibernateProxy) - { - return (AVMStore)((HibernateProxy)store).getHibernateLazyInitializer().getImplementation(); - } - return store; - } -} diff --git a/source/java/org/alfresco/repo/avm/hibernate/AVMStorePropertyDAOHibernate.java b/source/java/org/alfresco/repo/avm/hibernate/AVMStorePropertyDAOHibernate.java deleted file mode 100644 index 4db40dada3..0000000000 --- a/source/java/org/alfresco/repo/avm/hibernate/AVMStorePropertyDAOHibernate.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" */ - -package org.alfresco.repo.avm.hibernate; - -import java.util.List; - -import org.alfresco.repo.avm.AVMStore; -import org.alfresco.repo.avm.AVMStoreProperty; -import org.alfresco.repo.avm.AVMStorePropertyDAO; -import org.alfresco.repo.domain.QNameDAO; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.Pair; -import org.hibernate.Query; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - -/** - * The Hibernate implementation of the DAO for AVMNodeProperties. - * @author britt - */ -class AVMStorePropertyDAOHibernate extends HibernateDaoSupport implements AVMStorePropertyDAO -{ - private QNameDAO qnameDAO; - - /** - * Set the DAO for accessing QName entities - */ - public void setQnameDAO(QNameDAO qnameDAO) - { - this.qnameDAO = qnameDAO; - } - - /** - * Persist a property. - * @param prop The AVMStoreProperty to persist. - */ - public void save(AVMStoreProperty prop) - { - getSession().save(prop); - } - - /** - * Get a property by store and name. - * @param store The AVMStore. - * @param name The QName of the property. - * @return The given AVMStoreProperty or null if not found. - */ - public AVMStoreProperty get(AVMStore store, QName name) - { - Pair qnamePair = qnameDAO.getQName(name); - if (qnamePair == null) - { - // No such QName - return null; - } - else - { - Query query = - getSession().createQuery( - "select asp " + - "from AVMStorePropertyImpl asp " + - "where " + - "asp.store = :store and " + - "asp.qnameId = :qnameId"); - query.setEntity("store", store); - query.setLong("qnameId", qnamePair.getFirst()); - return (AVMStoreProperty)query.uniqueResult(); - } - } - - /** - * Get all the properties associated with a store. - * @param store The AVMStore whose properties should be fetched. - * @return A List of properties associated with the store. - */ - @SuppressWarnings("unchecked") - public List get(AVMStore store) - { - Query query = - getSession().createQuery("from AVMStorePropertyImpl asp where asp.store = :store"); - query.setEntity("store", store); - return (List)query.list(); - } - - /** - * Query store properties by key pattern. - * @param store The store. - * @param keyPattern An sql 'like' pattern wrapped up in a QName - * @return A List of matching AVMStoreProperties. - */ - @SuppressWarnings("unchecked") - public List queryByKeyPattern(AVMStore store, QName keyPattern) - { - // Get the URI and LocalName parts - String uri = keyPattern.getNamespaceURI(); - if (uri == null || uri.length() == 0) - { - uri = "%"; - } - String localName = keyPattern.getLocalName(); - if (localName == null || localName.length() == 0) - { - localName = "%"; - } - Query query = getSession().getNamedQuery("avm.GetStorePropertiesByStoreAndKeyPattern"); - query.setLong("storeId", store.getId()); - query.setParameter("uri", uri); - query.setParameter("localName", localName); -// Query query = -// getSession().createQuery( -// "select asp " + -// "from AVMStorePropertyImpl asp " + -// "join asp.name name " + -// "join name.namespace namespace " + -// "where " + -// "asp.store = :store and " + -// "namespace.safeUri like :uri and " + -// "name.localName like :localName"); - return (List)query.list(); - } - - /** - * Query all stores' properties by key pattern. - * @param keyPattern The sql 'like' pattern wrapped up in a QName - * @return A List of match AVMStoreProperties. - */ - @SuppressWarnings("unchecked") - public List queryByKeyPattern(QName keyPattern) - { - // Get the URI and LocalName parts - String uri = keyPattern.getNamespaceURI(); - if (uri == null || uri.length() == 0) - { - uri = "%"; - } - String localName = keyPattern.getLocalName(); - if (localName == null || localName.length() == 0) - { - localName = "%"; - } - Query query = getSession().getNamedQuery("avm.GetStorePropertiesByKeyPattern"); - query.setParameter("uri", uri); - query.setParameter("localName", localName); -// Query query = -// getSession().createQuery( -// "select asp " + -// "from AVMStorePropertyImpl asp " + -// "join asp.name name " + -// "join name.namespace namespace " + -// "where " + -// "namespace.safeUri like :uri and " + -// "name.localName like :localName"); -// query.setParameter("uri", uri); -// query.setParameter("localName", localName); - return (List)query.list(); - } - - /** - * Update a modified property. - * @param prop The AVMStoreProperty to update. - */ - public void update(AVMStoreProperty prop) - { - // This is a no op for hibernate. - } - - /** - * Delete a property from a store by name. - * @param store The AVMStore to delete from. - * @param name The name of the property. - */ - public void delete(AVMStore store, QName name) - { - Pair qnamePair = qnameDAO.getQName(name); - if (qnamePair != null) - { - Query delete = getSession().getNamedQuery("avm.DeleteStorePropertiesByType"); - delete.setParameter("storeId", store.getId()); - delete.setParameter("qnameId", qnamePair.getFirst()); - delete.executeUpdate(); - } - } - - /** - * Delete all properties associated with a store. - * @param store The AVMStore whose properties are to be deleted. - */ - public void delete(AVMStore store) - { - Query delete = getSession().getNamedQuery("avm.DeleteStoreProperties"); - delete.setParameter("storeId", store.getId()); - delete.executeUpdate(); - } -} diff --git a/source/java/org/alfresco/repo/avm/hibernate/ChildEntryDAOHibernate.java b/source/java/org/alfresco/repo/avm/hibernate/ChildEntryDAOHibernate.java deleted file mode 100644 index 1207719497..0000000000 --- a/source/java/org/alfresco/repo/avm/hibernate/ChildEntryDAOHibernate.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" */ - -package org.alfresco.repo.avm.hibernate; - -import java.util.List; - -import org.alfresco.repo.avm.AVMNode; -import org.alfresco.repo.avm.ChildEntry; -import org.alfresco.repo.avm.ChildEntryDAO; -import org.alfresco.repo.avm.ChildEntryImpl; -import org.alfresco.repo.avm.ChildKey; -import org.alfresco.repo.avm.DirectoryNode; -import org.alfresco.util.SearchLanguageConversion; -import org.hibernate.Criteria; -import org.hibernate.FetchMode; -import org.hibernate.Query; -import org.hibernate.criterion.MatchMode; -import org.hibernate.criterion.Restrictions; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - -/** - * The Hibernate version of the ChildEntry DAO. - * - * @author britt - */ -class ChildEntryDAOHibernate extends HibernateDaoSupport implements ChildEntryDAO -{ - /** - * Do nothing constructor. - */ - public ChildEntryDAOHibernate() - { - super(); - } - - /** - * Save an unsaved ChildEntry. - * - * @param entry - * The entry to save. - */ - public void save(ChildEntry entry) - { - getSession().save(entry); - } - - /** - * Get an entry by name and parent. - * - * @param name - * The name of the child to find. - * @param parent - * The parent to look in. - * @return The ChildEntry or null if not foun. - */ - public ChildEntry get(ChildKey key) - { - SessionCacheChecker.instance.check(); - return (ChildEntry) getSession().get(ChildEntryImpl.class, key); - } - - /** - * Get all the children of a given parent. - * - * @param parent - * The parent. - * @return A List of ChildEntries. - */ - @SuppressWarnings("unchecked") - public List getByParent(DirectoryNode parent, String childNamePattern) - { - Criteria criteria = getSession().createCriteria(ChildEntryImpl.class, "ce"); - criteria.add(Restrictions.eq("ce.key.parent", parent)); - if(childNamePattern != null) - { - String pattern = SearchLanguageConversion.convert(SearchLanguageConversion.DEF_LUCENE, SearchLanguageConversion.DEF_SQL_LIKE, childNamePattern); - criteria.add(Restrictions.like("ce.key.name", pattern)); - } - criteria.createCriteria("child", "cld").setFetchMode("ce.child", FetchMode.JOIN); - criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); - return (List) criteria.list(); - } - - /** - * Get the entry for a given child in a given parent. - * - * @param parent - * The parent. - * @param child - * The child. - * @return The ChildEntry or null. - */ - public ChildEntry getByParentChild(DirectoryNode parent, AVMNode child) - { - Query query = getSession().createQuery("from ChildEntryImpl ce where ce.key.parent = :parent " + "and ce.child = :child"); - query.setEntity("parent", parent); - query.setEntity("child", child); - SessionCacheChecker.instance.check(); - return (ChildEntry) query.uniqueResult(); - } - - /** - * Get all the ChildEntries corresponding to the given child. - * - * @param child - * The child for which to look up entries. - * @return The matching entries. - */ - @SuppressWarnings("unchecked") - public List getByChild(AVMNode child) - { - Query query = getSession().createQuery("from ChildEntryImpl ce " + "where ce.child = :child"); - query.setEntity("child", child); - return (List) query.list(); - } - - /** - * Update a dirty ChildEntry. - * - * @param child - * The dirty entry. - */ - public void update(ChildEntry child) - { - // NO OP in Hibernate. - } - - /** - * Delete one. - * - * @param child - * The one to delete. - */ - public void delete(ChildEntry child) - { - getSession().delete(child); - } - - /** - * Delete all children of the given parent. - * - * @param parent - * The parent. - */ - public void deleteByParent(AVMNode parent) - { - Query delete = getSession().getNamedQuery("ChildEntry.DeleteByParent"); - delete.setEntity("parent", parent); - delete.executeUpdate(); - } - - /* - * (non-Javadoc) - * - * @see org.alfresco.repo.avm.ChildEntryDAO#evict(org.alfresco.repo.avm.ChildEntry) - */ - public void evict(ChildEntry entry) - { - } -} diff --git a/source/java/org/alfresco/repo/avm/hibernate/HistoryLinkDAOHibernate.java b/source/java/org/alfresco/repo/avm/hibernate/HistoryLinkDAOHibernate.java deleted file mode 100644 index 39fdadad8f..0000000000 --- a/source/java/org/alfresco/repo/avm/hibernate/HistoryLinkDAOHibernate.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" */ - -package org.alfresco.repo.avm.hibernate; - -import java.util.List; - -import org.alfresco.repo.avm.AVMNode; -import org.alfresco.repo.avm.HistoryLink; -import org.alfresco.repo.avm.HistoryLinkDAO; -import org.hibernate.Query; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - -/** - * The Hibernate implementation of the DAO for HistoryLinks. - * @author britt - */ -class HistoryLinkDAOHibernate extends HibernateDaoSupport implements - HistoryLinkDAO -{ - /** - * Do nothing constructor. - */ - public HistoryLinkDAOHibernate() - { - super(); - } - - /** - * Save an unsaved HistoryLink. - * @param link - */ - public void save(HistoryLink link) - { - getSession().save(link); - } - - /** - * Get the history link with the given descendent. - * @param descendent The descendent. - * @return The HistoryLink or null if not found. - */ - public HistoryLink getByDescendent(AVMNode descendent) - { - Query query = getSession().createQuery("from HistoryLinkImpl hl where hl.descendent = :desc"); - query.setEntity("desc", descendent); - return (HistoryLink)query.uniqueResult(); - } - - /** - * Get all the descendents of a node. - * @param ancestor The ancestor node. - * @return A List of AVMNode descendents. - */ - @SuppressWarnings("unchecked") - public List getByAncestor(AVMNode ancestor) - { - Query query = getSession().getNamedQuery("HistoryLink.ByAncestor"); - query.setEntity("node", ancestor); - return (List)query.list(); - } - - /** - * Delete a HistoryLink - * @param link The link to delete. - */ - public void delete(HistoryLink link) - { - getSession().delete(link); - } -} diff --git a/source/java/org/alfresco/repo/avm/hibernate/MergeLinkDAOHibernate.java b/source/java/org/alfresco/repo/avm/hibernate/MergeLinkDAOHibernate.java deleted file mode 100644 index e4493a8143..0000000000 --- a/source/java/org/alfresco/repo/avm/hibernate/MergeLinkDAOHibernate.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" */ - -package org.alfresco.repo.avm.hibernate; - -import java.util.List; - -import org.alfresco.repo.avm.AVMNode; -import org.alfresco.repo.avm.MergeLink; -import org.alfresco.repo.avm.MergeLinkDAO; -import org.hibernate.Query; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - -/** - * The Hibernate implementation of the DAO for a MergeLink - * @author britt - */ -class MergeLinkDAOHibernate extends HibernateDaoSupport implements - MergeLinkDAO -{ - /** - * Do nothing constructor. - */ - public MergeLinkDAOHibernate() - { - super(); - } - - /** - * Save an unsaved MergeLink. - * @param link The link to save. - */ - public void save(MergeLink link) - { - getSession().save(link); - } - - /** - * Get a link from the merged to node. - * @param to The node merged to. - * @return An AVMNode or null if not found. - */ - public MergeLink getByTo(AVMNode to) - { - Query query = getSession().createQuery("from MergeLinkImpl ml where ml.mto = :to"); - query.setEntity("to", to); - return (MergeLink)query.uniqueResult(); - } - - /** - * Get all the link that the given node was merged to. - * @param from The node that was merged from - * @return A List of MergeLinks. - */ - @SuppressWarnings("unchecked") - public List getByFrom(AVMNode from) - { - Query query = getSession().getNamedQuery("MergeLink.ByFrom"); - query.setEntity("merged", from); - return (List)query.list(); - } - - /** - * Delete a link. - * @param link The link to delete. - */ - public void delete(MergeLink link) - { - getSession().delete(link); - } -} diff --git a/source/java/org/alfresco/repo/avm/hibernate/SessionCacheChecker.java b/source/java/org/alfresco/repo/avm/hibernate/SessionCacheChecker.java deleted file mode 100644 index b83b6bc627..0000000000 --- a/source/java/org/alfresco/repo/avm/hibernate/SessionCacheChecker.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * - */ -package org.alfresco.repo.avm.hibernate; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.engine.EntityKey; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - -/** - * @author britt - */ -public class SessionCacheChecker extends HibernateDaoSupport -{ - public static SessionCacheChecker instance = null; - - private static Log fgLogger = LogFactory.getLog(SessionCacheChecker.class); - - private int fCount = 0; - - public SessionCacheChecker() - { - instance = this; - } - - public void check() - { - if (!fgLogger.isDebugEnabled()) - { - return; - } - if (fCount % 1000 == 0) - { - Map types = new HashMap(); - Set keys = (Set)getSession().getStatistics().getEntityKeys(); - if (keys.size() > 200) - { - for (EntityKey key : keys) - { - String name = key.getEntityName(); - if (!types.containsKey(name)) - { - types.put(name, 0); - } - types.put(name, types.get(name) + 1); - } - fgLogger.debug(types); -// for (Object it : Thread.currentThread().getStackTrace()) -// { -// fgLogger.debug(it); -// } -// fCount = 0; - } - } - fCount++; - } -} diff --git a/source/java/org/alfresco/repo/avm/hibernate/VersionRootDAOHibernate.java b/source/java/org/alfresco/repo/avm/hibernate/VersionRootDAOHibernate.java deleted file mode 100644 index 2b5fbeecc3..0000000000 --- a/source/java/org/alfresco/repo/avm/hibernate/VersionRootDAOHibernate.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" */ - -package org.alfresco.repo.avm.hibernate; - -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; - -import org.alfresco.repo.avm.AVMNode; -import org.alfresco.repo.avm.AVMStore; -import org.alfresco.repo.avm.VersionRoot; -import org.alfresco.repo.avm.VersionRootImpl; -import org.alfresco.repo.avm.VersionRootDAO; -import org.alfresco.util.Pair; -import org.hibernate.Query; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - -/** - * This is the Hibernate version of the DAO for version roots. - * @author britt - */ -class VersionRootDAOHibernate extends HibernateDaoSupport implements - VersionRootDAO -{ - private LinkedHashMap, Long> fCache; - - /** - * Do nothing constructor. - */ - public VersionRootDAOHibernate() - { - super(); - fCache = new LinkedHashMap, Long>(); - } - - /** - * Save an unsaved VersionRoot. - * @param vr The VersionRoot to save. - */ - public void save(VersionRoot vr) - { - getSession().save(vr); - } - - /** - * Delete a VersionRoot. - * @param vr The VersionRoot to delete. - */ - public void delete(VersionRoot vr) - { - getSession().delete(vr); - getSession().flush(); - } - - /** - * Get all the version roots in a given store. - * @param store The store. - * @return A List of VersionRoots. In id order. - */ - @SuppressWarnings("unchecked") - public List getAllInAVMStore(AVMStore store) - { - Query query = getSession().createQuery("from VersionRootImpl v where v.avmStore = :store order by v.versionID"); - query.setEntity("store", store); - return (List)query.list(); - } - - /** - * Get the version of a store by dates. - * @param store The store. - * @param from The starting date. May be null but not with to null also. - * @param to The ending date. May be null but not with from null also. - * @return A List of VersionRoots. - */ - @SuppressWarnings("unchecked") - public List getByDates(AVMStore store, Date from, Date to) - { - Query query; - if (from == null) - { - query = - getSession().createQuery("from VersionRootImpl vr where vr.createDate <= :to " + - "and vr.avmStore = :store " + - "order by vr.versionID"); - query.setLong("to", to.getTime()); - } - else if (to == null) - { - query = - getSession().createQuery("from VersionRootImpl vr " + - "where vr.createDate >= :from " + - "and vr.avmStore = :store " + - "order by vr.versionID"); - query.setLong("from", from.getTime()); - } - else - { - query = - getSession().createQuery("from VersionRootImpl vr "+ - "where vr.createDate between :from and :to " + - "and vr.avmStore = :store " + - "order by vr.versionID"); - query.setLong("from", from.getTime()); - query.setLong("to", to.getTime()); - } - query.setEntity("store", store); - return (List)query.list(); - } - - /** - * Get the VersionRoot corresponding to the given id. - * @param store The store - * @param id The version id. - * @return The VersionRoot or null if not found. - */ - public synchronized VersionRoot getByVersionID(AVMStore store, int id) - { - Long vID = fCache.get(new Pair(store.getId(), id)); - if (vID != null) - { - VersionRoot root = (VersionRoot)getSession().get(VersionRootImpl.class, vID); - if (root != null) - { - return root; - } - fCache.remove(new Pair(store.getId(), id)); - } - Query query = getSession().getNamedQuery("VersionRoot.VersionByID"); - query.setEntity("store", store); - query.setInteger("version", id); - VersionRoot root = (VersionRoot)query.uniqueResult(); - if (root != null) - { - vID = root.getId(); - if (vID != null) - { - if (fCache.size() >= 10) - { - Iterator> iter = fCache.keySet().iterator(); - iter.next(); - iter.remove(); - } - fCache.put(new Pair(store.getId(), id), vID); - } - } - return root; - } - - /** - * Get one from its root. - * @param root The root to match. - * @return The version root or null. - */ - public VersionRoot getByRoot(AVMNode root) - { - Query query = getSession().createQuery("from VersionRootImpl vr " + - "where vr.root = :root"); - query.setEntity("root", root); - return (VersionRoot)query.uniqueResult(); - } - - /** - * Get the highest numbered version in a repository. - * @param rep The repository. - * @return The highest numbered version. - */ - public VersionRoot getMaxVersion(AVMStore rep) - { - Query query = getSession().createQuery("from VersionRootImpl vr " + - "where vr.avmStore = :store and vr.versionID = " + - "(select max(v.versionID) from VersionRootImpl v where v.avmStore = :store)"); - query.setEntity("store", rep); - return (VersionRoot)query.uniqueResult(); - } - - /** - * Get the highest numbered id from all the versions in a store. - * @param store The store. - * @return The highest numbered id. - */ - public Integer getMaxVersionID(AVMStore store) - { - Query query = getSession().createQuery("select max(vr.versionID) from VersionRootImpl vr " + - "where vr.avmStore = :store"); - query.setEntity("store", store); - return (Integer)query.uniqueResult(); - } -} diff --git a/source/java/org/alfresco/repo/avm/ibatis/AVMNodeDAOIbatis.java b/source/java/org/alfresco/repo/avm/ibatis/AVMNodeDAOIbatis.java new file mode 100644 index 0000000000..0bafedea0d --- /dev/null +++ b/source/java/org/alfresco/repo/avm/ibatis/AVMNodeDAOIbatis.java @@ -0,0 +1,502 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" */ + +package org.alfresco.repo.avm.ibatis; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.avm.AVMDAOs; +import org.alfresco.repo.avm.AVMNode; +import org.alfresco.repo.avm.AVMNodeDAO; +import org.alfresco.repo.avm.AVMNodeImpl; +import org.alfresco.repo.avm.AVMNodeType; +import org.alfresco.repo.avm.AVMStore; +import org.alfresco.repo.avm.BasicAttributes; +import org.alfresco.repo.avm.BasicAttributesImpl; +import org.alfresco.repo.avm.DeletedNode; +import org.alfresco.repo.avm.DeletedNodeImpl; +import org.alfresco.repo.avm.DirectoryNode; +import org.alfresco.repo.avm.HistoryLink; +import org.alfresco.repo.avm.Layered; +import org.alfresco.repo.avm.LayeredDirectoryNode; +import org.alfresco.repo.avm.LayeredDirectoryNodeImpl; +import org.alfresco.repo.avm.LayeredFileNode; +import org.alfresco.repo.avm.LayeredFileNodeImpl; +import org.alfresco.repo.avm.MergeLink; +import org.alfresco.repo.avm.PlainDirectoryNode; +import org.alfresco.repo.avm.PlainDirectoryNodeImpl; +import org.alfresco.repo.avm.PlainFileNode; +import org.alfresco.repo.avm.PlainFileNodeImpl; +import org.alfresco.repo.domain.DbAccessControlList; +import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.repo.domain.avm.AVMNodeEntity; +import org.alfresco.repo.domain.avm.AVMVersionRootEntity; +import org.alfresco.repo.domain.hibernate.DbAccessControlListImpl; +import org.alfresco.service.cmr.repository.ContentData; +import org.alfresco.service.namespace.QName; +import org.springframework.orm.hibernate3.support.HibernateDaoSupport; + +/** + * iBATIS DAO wrapper for AVMNode + * + * @author janv + * + */ +class AVMNodeDAOIbatis extends HibernateDaoSupport implements AVMNodeDAO +{ + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#save(org.alfresco.repo.avm.AVMNode) + */ + public void save(AVMNode node) + { + AVMNodeEntity nodeEntity = AVMDAOs.Instance().newAVMNodeDAO.createNode(convertNodeToNodeEntity(node)); + ((AVMNodeImpl)node).setId(nodeEntity.getId()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#delete(org.alfresco.repo.avm.AVMNode) + */ + public void delete(AVMNode node) + { + AVMDAOs.Instance().newAVMNodeDAO.deleteNode(node.getId()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#createAspect(long, long) + */ + public void createAspect(long nodeId, QName aspectQName) + { + AVMDAOs.Instance().newAVMNodeDAO.createAspect(nodeId, aspectQName); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#deleteAspect(long, long) + */ + public void deleteAspect(long nodeId, QName aspectQName) + { + AVMDAOs.Instance().newAVMNodeDAO.deleteAspect(nodeId, aspectQName); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#deleteAspects(long) + */ + public void deleteAspects(long nodeId) + { + AVMDAOs.Instance().newAVMNodeDAO.deleteAspects(nodeId); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#getAspects(long) + */ + public Set getAspects(long nodeId) + { + return AVMDAOs.Instance().newAVMNodeDAO.getAspects(nodeId); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#createOrUpdateProperty(long, QName, org.alfresco.repo.domain.PropertyValue) + */ + public void createOrUpdateProperty(long nodeId, QName qname, PropertyValue value) + { + AVMDAOs.Instance().newAVMNodeDAO.createOrUpdateNodeProperty(nodeId, qname, value); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#deleteProperty(long, QName) + */ + public void deleteProperty(long nodeId, QName propQName) + { + AVMDAOs.Instance().newAVMNodeDAO.deleteNodeProperty(nodeId, propQName); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#deleteProperties(long) + */ + public void deleteProperties(long nodeId) + { + AVMDAOs.Instance().newAVMNodeDAO.deleteNodeProperties(nodeId); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#getProperties(long) + */ + public Map getProperties(long nodeId) + { + return AVMDAOs.Instance().newAVMNodeDAO.getNodeProperties(nodeId); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#getByID(long) + */ + public AVMNode getByID(long id) + { + return convertNodeEntityToNode(AVMDAOs.Instance().newAVMNodeDAO.getNode(id)); + } + + /* package */ AVMNode getRootNodeByID(AVMStore store, long rootNodeId) + { + AVMNodeEntity rootNodeEntity = AVMDAOs.Instance().newAVMNodeDAO.getNode(rootNodeId); + + AVMNode rootNode = null; + if (rootNodeEntity.getStoreNewId() != null) + { + rootNode = convertNodeEntityToNode(rootNodeEntity, false); + rootNode.setStoreNew(store); + } + else + { + rootNode = convertNodeEntityToNode(rootNodeEntity); + } + + return rootNode; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#update(org.alfresco.repo.avm.AVMNode) + */ + public void update(AVMNode node) + { + AVMNodeEntity nodeEntity = convertNodeToNodeEntity(node); + AVMDAOs.Instance().newAVMNodeDAO.updateNode(nodeEntity); + ((AVMNodeImpl)node).setVers(nodeEntity.getVers()); + } + + /** + * TODO review + * + * @deprecated + */ + public void updateModTimeAndGuid(AVMNode node) + { + AVMNodeEntity nodeEntity = convertNodeToNodeEntity(node); + AVMDAOs.Instance().newAVMNodeDAO.updateNodeModTimeAndGuid(nodeEntity); + ((AVMNodeImpl)node).setVers(nodeEntity.getVers()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#getAVMStoreRoot(org.alfresco.repo.avm.AVMStore, int) + */ + public DirectoryNode getAVMStoreRoot(AVMStore store, int version) + { + AVMVersionRootEntity vrEntity = AVMDAOs.Instance().newAVMVersionRootDAO.getByVersionID(store.getId(), version); + + if (vrEntity == null) + { + return null; + } + + return (DirectoryNode) getByID(vrEntity.getRootNodeId()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#getAncestor(org.alfresco.repo.avm.AVMNode) + */ + public AVMNode getAncestor(AVMNode descendent) + { + HistoryLink hl = AVMDAOs.Instance().fHistoryLinkDAO.getByDescendent(descendent); + if (hl == null) + { + return null; + } + return hl.getAncestor(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#getMergedFrom(org.alfresco.repo.avm.AVMNode) + */ + public AVMNode getMergedFrom(AVMNode mTo) + { + MergeLink ml = AVMDAOs.Instance().fMergeLinkDAO.getByTo(mTo); + if (ml == null) + { + return null; + } + return ml.getMfrom(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#getOrphans(int) + */ + public List getOrphans(int batchSize) + { + // TODO - limit to batch size + List nodeEntities = AVMDAOs.Instance().newAVMNodeDAO.getNodeOrphans(); + + if (nodeEntities == null) + { + return new ArrayList(0); + } + + List nodes = new ArrayList(nodeEntities.size()); + for (AVMNodeEntity nodeEntity : nodeEntities) + { + nodes.add(convertNodeEntityToNode(nodeEntity)); + } + return nodes; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#getNewInStore(org.alfresco.repo.avm.AVMStore) + */ + public List getNewInStore(AVMStore store) + { + List nodeEntities = AVMDAOs.Instance().newAVMNodeDAO.getNodesNewInStore(store.getId()); + + if (nodeEntities == null) + { + return new ArrayList(0); + } + + List nodes = new ArrayList(nodeEntities.size()); + for (AVMNodeEntity nodeEntity : nodeEntities) + { + nodes.add(convertNodeEntityToNode(nodeEntity)); + } + return nodes; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#flush() + */ + public void flush() + { + // NOOP + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#evict(org.alfresco.repo.avm.AVMNode) + */ + public void evict(AVMNode node) + { + // NOOP + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#clear() + */ + public void clear() + { + AVMDAOs.Instance().newAVMNodeDAO.clearNodeEntityCache(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#noCache() + */ + public void noCache() + { + // NOOP + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#yesCache() + */ + public void yesCache() + { + // NOOP + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#clearNewInStore(org.alfresco.repo.avm.AVMStore) + */ + public void clearNewInStore(AVMStore store) + { + AVMDAOs.Instance().newAVMNodeDAO.updateNodesClearNewInStore(store.getId()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#getNewLayeredInStoreIDs(org.alfresco.repo.avm.AVMStore) + */ + public List getNewLayeredInStoreIDs(AVMStore store) + { + return AVMDAOs.Instance().newAVMNodeDAO.getLayeredNodesNewInStoreIDs(store.getId()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#getNewLayeredInStore(org.alfresco.repo.avm.AVMStore) + */ + public List getNewLayeredInStore(AVMStore store) + { + List nodeEntities = AVMDAOs.Instance().newAVMNodeDAO.getLayeredNodesNewInStore(store.getId()); + + if (nodeEntities == null) + { + return new ArrayList(0); + } + + List nodes = new ArrayList(nodeEntities.size()); + for (AVMNodeEntity nodeEntity : nodeEntities) + { + nodes.add((Layered)convertNodeEntityToNode(nodeEntity)); + } + return nodes; + } + + private AVMNodeEntity convertNodeToNodeEntity(AVMNode node) + { + AVMNodeEntity nodeEntity = new AVMNodeEntity(); + + nodeEntity.setId(node.getId()); + + nodeEntity.setAccessDate(node.getBasicAttributes().getAccessDate()); + nodeEntity.setOwner(node.getBasicAttributes().getOwner()); + nodeEntity.setCreator(node.getBasicAttributes().getCreator()); + nodeEntity.setCreatedDate(node.getBasicAttributes().getCreateDate()); + nodeEntity.setModifier(node.getBasicAttributes().getLastModifier()); + nodeEntity.setModifiedDate(node.getBasicAttributes().getModDate()); + + nodeEntity.setType(node.getType()); + nodeEntity.setVersion(new Long(node.getVersionID())); + nodeEntity.setVers(((AVMNodeImpl)node).getVers()); + nodeEntity.setAclId((node.getAcl() == null ? null : node.getAcl().getId())); + + nodeEntity.setGuid(node.getGuid()); + nodeEntity.setStoreNewId(node.getStoreNew() == null ? null : node.getStoreNew().getId()); + nodeEntity.setRoot(node.getIsRoot()); + + if (node instanceof PlainFileNode) + { + PlainFileNode pfNode = (PlainFileNode)node; + nodeEntity.setEncoding(pfNode.getContentData().getEncoding()); + nodeEntity.setMimetype(pfNode.getContentData().getMimetype()); + nodeEntity.setContentUrl(pfNode.getContentData().getContentUrl()); + nodeEntity.setLength(pfNode.getContentData().getSize()); + } + else if (node instanceof LayeredFileNode) + { + LayeredFileNode lfNode = (LayeredFileNode)node; + nodeEntity.setIndirection(lfNode.getIndirection()); + nodeEntity.setIndirectionVersion(lfNode.getIndirectionVersion()); + } + else if (node instanceof PlainDirectoryNode) + { + // no additional + } + else if (node instanceof LayeredDirectoryNode) + { + LayeredDirectoryNode ldNode = (LayeredDirectoryNode)node; + nodeEntity.setIndirection(ldNode.getIndirection()); + nodeEntity.setIndirectionVersion(ldNode.getIndirectionVersion()); + nodeEntity.setLayerId(ldNode.getLayerID()); + nodeEntity.setPrimaryIndirection(ldNode.getPrimaryIndirection()); + nodeEntity.setOpacity(ldNode.getOpacity()); + } + else if (node instanceof DeletedNode) + { + DeletedNode dNode = (DeletedNode)node; + nodeEntity.setDeletedType(dNode.getDeletedType()); + } + + return nodeEntity; + } + + private AVMNode convertNodeEntityToNode(AVMNodeEntity nodeEntity) + { + return convertNodeEntityToNode(nodeEntity, true); + } + + private AVMNode convertNodeEntityToNode(AVMNodeEntity nodeEntity, boolean withStore) + { + AVMNodeImpl node = null; + if (nodeEntity.getType() == AVMNodeType.PLAIN_FILE) + { + node = new PlainFileNodeImpl(); + + ContentData cd = new ContentData(nodeEntity.getContentUrl(), nodeEntity.getMimetype(), nodeEntity.getLength(), nodeEntity.getEncoding()); + ((PlainFileNodeImpl)node).setContentData(cd); + } + else if (nodeEntity.getType() == AVMNodeType.PLAIN_DIRECTORY) + { + node = new PlainDirectoryNodeImpl(); + + // no additional + } + else if (nodeEntity.getType() == AVMNodeType.LAYERED_FILE) + { + node = new LayeredFileNodeImpl(); + + ((LayeredFileNodeImpl)node).setIndirection(nodeEntity.getIndirection()); + ((LayeredFileNodeImpl)node).setIndirectionVersion(nodeEntity.getIndirectionVersion()); + } + else if (nodeEntity.getType() == AVMNodeType.LAYERED_DIRECTORY) + { + node = new LayeredDirectoryNodeImpl(); + + ((LayeredDirectoryNodeImpl)node).setIndirection(nodeEntity.getIndirection()); + ((LayeredDirectoryNodeImpl)node).setIndirectionVersion(nodeEntity.getIndirectionVersion()); + ((LayeredDirectoryNodeImpl)node).setPrimaryIndirection(nodeEntity.isPrimaryIndirection()); + ((LayeredDirectoryNodeImpl)node).setLayerID(nodeEntity.getLayerId()); + ((LayeredDirectoryNodeImpl)node).setOpacity(nodeEntity.getOpacity()); + } + else if (nodeEntity.getType() == AVMNodeType.DELETED_NODE) + { + node = new DeletedNodeImpl(); + ((DeletedNodeImpl)node).setDeletedType(nodeEntity.getDeletedType()); + } + else + { + // belts-and-braces + throw new AlfrescoRuntimeException("Unexpected node type: "+nodeEntity.getType()); + } + + node.setId(nodeEntity.getId()); + node.setIsRoot(nodeEntity.isRoot()); + node.setGuid(nodeEntity.getGuid()); + node.setVersionID(nodeEntity.getVersion().intValue()); + node.setVers(nodeEntity.getVers()); + + BasicAttributes ba = new BasicAttributesImpl(); + ba.setAccessDate(nodeEntity.getAccessDate()); + ba.setModDate(nodeEntity.getModifiedDate()); + ba.setCreateDate(nodeEntity.getCreatedDate()); + ba.setLastModifier(nodeEntity.getModifier()); + ba.setCreator(nodeEntity.getCreator()); + ba.setOwner(nodeEntity.getOwner()); + + node.setBasicAttributes(ba); + + AVMStore store = null; + if (withStore) + { + if (nodeEntity.getStoreNewId() != null) + { + store = AVMDAOs.Instance().fAVMStoreDAO.getByID(nodeEntity.getStoreNewId()); + } + } + + node.setStoreNew(store); + + DbAccessControlList acl = null; + if (nodeEntity.getAclId() != null) + { + acl = (DbAccessControlList) getHibernateTemplate().get(DbAccessControlListImpl.class, nodeEntity.getAclId()); + } + node.setAcl(acl); + + return node; + } +} diff --git a/source/java/org/alfresco/repo/avm/ibatis/AVMStoreDAOIbatis.java b/source/java/org/alfresco/repo/avm/ibatis/AVMStoreDAOIbatis.java new file mode 100644 index 0000000000..ccaac0e4ab --- /dev/null +++ b/source/java/org/alfresco/repo/avm/ibatis/AVMStoreDAOIbatis.java @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" */ + +package org.alfresco.repo.avm.ibatis; + +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.repo.avm.AVMDAOs; +import org.alfresco.repo.avm.AVMNode; +import org.alfresco.repo.avm.AVMStore; +import org.alfresco.repo.avm.AVMStoreDAO; +import org.alfresco.repo.avm.AVMStoreImpl; +import org.alfresco.repo.avm.DirectoryNode; +import org.alfresco.repo.domain.DbAccessControlList; +import org.alfresco.repo.domain.avm.AVMStoreEntity; +import org.alfresco.repo.domain.hibernate.DbAccessControlListImpl; +import org.springframework.orm.hibernate3.support.HibernateDaoSupport; + +/** + * iBATIS DAO wrapper for AVMStore + * + * @author janv + */ +class AVMStoreDAOIbatis extends HibernateDaoSupport implements AVMStoreDAO +{ + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMStoreDAO#save(org.alfresco.repo.avm.AVMStore) + */ + public void save(AVMStore store) + { + AVMStoreEntity storeEntity = AVMDAOs.Instance().newAVMStoreDAO.createStore(store.getName()); + ((AVMStoreImpl)store).setId(storeEntity.getId()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMStoreDAO#delete(org.alfresco.repo.avm.AVMStore) + */ + public void delete(AVMStore store) + { + AVMDAOs.Instance().newAVMStoreDAO.deleteStore(store.getId()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMStoreDAO#getAll() + */ + public List getAll() + { + List storeEntities = AVMDAOs.Instance().newAVMStoreDAO.getAllStores(); + List result = new ArrayList(storeEntities.size()); + for (AVMStoreEntity storeEntity : storeEntities) + { + result.add(getByID(storeEntity.getId())); + } + return result; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMStoreDAO#getByName(java.lang.String) + */ + public AVMStore getByName(String name) + { + AVMStoreEntity storeEntity = AVMDAOs.Instance().newAVMStoreDAO.getStore(name); + return convertStoreEntityToStore(storeEntity); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMStoreDAO#getByRoot(org.alfresco.repo.avm.AVMNode) + */ + public AVMStore getByRoot(AVMNode root) + { + AVMStoreEntity storeEntity = AVMDAOs.Instance().newAVMStoreDAO.getStoreByRoot(root.getId()); + return convertStoreEntityToStore(storeEntity); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMStoreDAO#update(org.alfresco.repo.avm.AVMStore) + */ + public void update(AVMStore store) + { + AVMStoreEntity storeEntity = convertStoreToStoreEntity(store); + AVMDAOs.Instance().newAVMStoreDAO.updateStore(storeEntity); + ((AVMStoreImpl)store).setVers(storeEntity.getVers()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMStoreDAO#getByID(long) + */ + public AVMStore getByID(long id) + { + AVMStoreEntity storeEntity = AVMDAOs.Instance().newAVMStoreDAO.getStore(id); + return convertStoreEntityToStore(storeEntity); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMStoreDAO#invalidateCache() + */ + public void invalidateCache() + { + AVMDAOs.Instance().newAVMStoreDAO.clearStoreEntityCache(); + } + + private AVMStore convertStoreEntityToStore(AVMStoreEntity storeEntity) + { + if (storeEntity == null) + { + return null; + } + + AVMStoreImpl store = new AVMStoreImpl(); + store.setId(storeEntity.getId()); + store.setName(storeEntity.getName()); + + store.setNextVersionID(storeEntity.getVersion().intValue()); + store.setVers(storeEntity.getVers()); + + DbAccessControlList acl = null; + if (storeEntity.getAclId() != null) + { + acl = (DbAccessControlList) getHibernateTemplate().get(DbAccessControlListImpl.class, storeEntity.getAclId()); + } + store.setStoreAcl(acl); + + DirectoryNode rootNode = (DirectoryNode) ((AVMNodeDAOIbatis)AVMDAOs.Instance().fAVMNodeDAO).getRootNodeByID(store, storeEntity.getRootNodeId()); + store.setRoot(rootNode); + + return store; + } + + private AVMStoreEntity convertStoreToStoreEntity(AVMStore store) + { + AVMStoreEntity storeEntity = new AVMStoreEntity(); + + storeEntity.setId(store.getId()); + storeEntity.setName(store.getName()); + storeEntity.setRootNodeId(store.getRoot().getId()); + storeEntity.setVersion(new Long(store.getNextVersionID())); + storeEntity.setVers(((AVMStoreImpl)store).getVers()); + storeEntity.setAclId((store.getStoreAcl() == null ? null : store.getStoreAcl().getId())); + + return storeEntity; + } +} diff --git a/source/java/org/alfresco/repo/avm/ibatis/AVMStorePropertyDAOIbatis.java b/source/java/org/alfresco/repo/avm/ibatis/AVMStorePropertyDAOIbatis.java new file mode 100644 index 0000000000..921cabde3b --- /dev/null +++ b/source/java/org/alfresco/repo/avm/ibatis/AVMStorePropertyDAOIbatis.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" */ + +package org.alfresco.repo.avm.ibatis; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.repo.avm.AVMDAOs; +import org.alfresco.repo.avm.AVMStore; +import org.alfresco.repo.avm.AVMStoreProperty; +import org.alfresco.repo.avm.AVMStorePropertyDAO; +import org.alfresco.repo.avm.AVMStorePropertyImpl; +import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.repo.domain.QNameDAO; +import org.alfresco.repo.domain.avm.AVMStorePropertyEntity; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.Pair; +import org.springframework.orm.hibernate3.support.HibernateDaoSupport; + +/** + * iBATIS DAO wrapper for AVMStoreProperty + * + * @author janv + */ +class AVMStorePropertyDAOIbatis extends HibernateDaoSupport implements AVMStorePropertyDAO +{ + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMStorePropertyDAO#save(org.alfresco.repo.avm.AVMStoreProperty) + */ + public void save(AVMStoreProperty prop) + { + AVMDAOs.Instance().newAVMStoreDAO.createOrUpdateStoreProperty(prop.getStore().getId(), prop.getQname(), prop.getValue()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMStorePropertyDAO#get(org.alfresco.repo.avm.AVMStore, org.alfresco.service.namespace.QName) + */ + public PropertyValue get(AVMStore store, QName name) + { + return AVMDAOs.Instance().newAVMStoreDAO.getStoreProperty(store.getId(), name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMStorePropertyDAO#get(org.alfresco.repo.avm.AVMStore) + */ + public Map get(AVMStore store) + { + return AVMDAOs.Instance().newAVMStoreDAO.getStoreProperties(store.getId()); + } + + /** + * Query store properties by key pattern. + * @param store The store. + * @param keyPattern An sql 'like' pattern wrapped up in a QName + * @return A List of matching AVMStoreProperties. + */ + public Map queryByKeyPattern(AVMStore store, QName keyPattern) + { + // Get the URI and LocalName parts + String uri = keyPattern.getNamespaceURI(); + if (uri == null || uri.length() == 0) + { + uri = "%"; + } + String localName = keyPattern.getLocalName(); + if (localName == null || localName.length() == 0) + { + localName = "%"; + } + + return AVMDAOs.Instance().newAVMStoreDAO.getStorePropertiesByStoreAndKeyPattern(store.getId(), uri, localName); + } + + /** + * Query all stores' properties by key pattern. + * @param keyPattern The sql 'like' pattern wrapped up in a QName + * @return A List of match AVMStoreProperties. + */ + public Map> queryByKeyPattern(QName keyPattern) + { + // Get the URI and LocalName parts + String uri = keyPattern.getNamespaceURI(); + if (uri == null || uri.length() == 0) + { + uri = "%"; + } + String localName = keyPattern.getLocalName(); + if (localName == null || localName.length() == 0) + { + localName = "%"; + } + + return AVMDAOs.Instance().newAVMStoreDAO.getStorePropertiesByKeyPattern(uri, localName); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMStorePropertyDAO#update(org.alfresco.repo.avm.AVMStoreProperty) + */ + public void update(AVMStoreProperty prop) + { + // NOOP + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMStorePropertyDAO#delete(org.alfresco.repo.avm.AVMStore, org.alfresco.service.namespace.QName) + */ + public void delete(AVMStore store, QName name) + { + AVMDAOs.Instance().newAVMStoreDAO.deleteStoreProperty(store.getId(), name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMStorePropertyDAO#delete(org.alfresco.repo.avm.AVMStore) + */ + public void delete(AVMStore store) + { + AVMDAOs.Instance().newAVMStoreDAO.deleteStoreProperties(store.getId()); + } +} diff --git a/source/java/org/alfresco/repo/avm/ibatis/ChildEntryDAOIbatis.java b/source/java/org/alfresco/repo/avm/ibatis/ChildEntryDAOIbatis.java new file mode 100644 index 0000000000..156f19eeb1 --- /dev/null +++ b/source/java/org/alfresco/repo/avm/ibatis/ChildEntryDAOIbatis.java @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" */ + +package org.alfresco.repo.avm.ibatis; + +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.repo.avm.AVMDAOs; +import org.alfresco.repo.avm.AVMNode; +import org.alfresco.repo.avm.ChildEntry; +import org.alfresco.repo.avm.ChildEntryDAO; +import org.alfresco.repo.avm.ChildEntryImpl; +import org.alfresco.repo.avm.ChildKey; +import org.alfresco.repo.avm.DirectoryNode; +import org.alfresco.repo.domain.avm.AVMChildEntryEntity; + +/** + * iBATIS DAO wrapper for ChildEntry + * + * @author jan + */ +class ChildEntryDAOIbatis implements ChildEntryDAO +{ + /* (non-Javadoc) + * @see org.alfresco.repo.avm.ChildEntryDAO#save(org.alfresco.repo.avm.ChildEntry) + */ + public void save(ChildEntry entry) + { + AVMDAOs.Instance().newAVMNodeLinksDAO.createChildEntry(entry.getKey().getParent().getId(), entry.getKey().getName(), entry.getChild().getId()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.ChildEntryDAO#get(org.alfresco.repo.avm.ChildKey) + */ + public ChildEntry get(ChildKey key) + { + AVMChildEntryEntity childEntryEntity = AVMDAOs.Instance().newAVMNodeLinksDAO.getChildEntry(key.getParent().getId(), key.getName()); + return getChildEntryForParent(key.getParent(), childEntryEntity); + + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.ChildEntryDAO#getByParent(org.alfresco.repo.avm.DirectoryNode, java.lang.String) + */ + public List getByParent(DirectoryNode parent, String childNamePattern) + { + // TODO - add option for childNamePattern + + List childEntryEntities = AVMDAOs.Instance().newAVMNodeLinksDAO.getChildEntriesByParent(parent.getId()); + + List result = new ArrayList(childEntryEntities.size()); + for (AVMChildEntryEntity childEntryEntity : childEntryEntities) + { + result.add(getChildEntryForParent(parent, childEntryEntity)); + } + + return result; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.ChildEntryDAO#getByParentChild(org.alfresco.repo.avm.DirectoryNode, org.alfresco.repo.avm.AVMNode) + */ + public boolean existsParentChild(DirectoryNode parent, AVMNode child) + { + AVMChildEntryEntity childEntryEntity = AVMDAOs.Instance().newAVMNodeLinksDAO.getChildEntry(parent.getId(), child.getId()); + return (childEntryEntity != null); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.ChildEntryDAO#getByChild(org.alfresco.repo.avm.AVMNode) + */ + public List getByChild(AVMNode child) + { + List childEntryEntities = AVMDAOs.Instance().newAVMNodeLinksDAO.getChildEntriesByChild(child.getId()); + + List result = new ArrayList(childEntryEntities.size()); + for (AVMChildEntryEntity childEntryEntity : childEntryEntities) + { + result.add(getChildEntryForChild(child, childEntryEntity)); + } + + return result; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.ChildEntryDAO#update(org.alfresco.repo.avm.ChildEntry) + */ + public void update(ChildEntry child) + { + // NOOP + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.ChildEntryDAO#delete(org.alfresco.repo.avm.ChildEntry) + */ + public void delete(ChildEntry child) + { + AVMChildEntryEntity childEntryEntity = new AVMChildEntryEntity(); + childEntryEntity.setParentNodeId(child.getKey().getParent().getId()); + childEntryEntity.setName(child.getKey().getName()); + childEntryEntity.setChildNodeId(child.getChild().getId()); + + AVMDAOs.Instance().newAVMNodeLinksDAO.deleteChildEntry(childEntryEntity); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.ChildEntryDAO#deleteByParent(org.alfresco.repo.avm.AVMNode) + */ + public void deleteByParent(AVMNode parent) + { + AVMDAOs.Instance().newAVMNodeLinksDAO.deleteChildEntriesByParent(parent.getId()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.ChildEntryDAO#evict(org.alfresco.repo.avm.ChildEntry) + */ + public void evict(ChildEntry entry) + { + // NOOP + } + + private ChildEntry getChildEntryForParent(DirectoryNode parentNode, AVMChildEntryEntity childEntryEntity) + { + if (childEntryEntity == null) + { + return null; + } + + AVMNode childNode = AVMDAOs.Instance().fAVMNodeDAO.getByID(childEntryEntity.getChildId()); + + ChildEntry ce = new ChildEntryImpl(new ChildKey(parentNode, childEntryEntity.getName()), childNode); + ce.setKey(new ChildKey(parentNode, childEntryEntity.getName())); + ce.setChild(childNode); + return ce; + } + + private ChildEntry getChildEntryForChild(AVMNode childNode, AVMChildEntryEntity childEntryEntity) + { + if (childEntryEntity == null) + { + return null; + } + + DirectoryNode parentNode = (DirectoryNode)AVMDAOs.Instance().fAVMNodeDAO.getByID(childEntryEntity.getParentNodeId()); + + ChildEntry ce = new ChildEntryImpl(new ChildKey(parentNode, childEntryEntity.getName()), childNode); + ce.setKey(new ChildKey(parentNode, childEntryEntity.getName())); + ce.setChild(childNode); + return ce; + } +} diff --git a/source/java/org/alfresco/repo/avm/ibatis/HistoryLinkDAOIbatis.java b/source/java/org/alfresco/repo/avm/ibatis/HistoryLinkDAOIbatis.java new file mode 100644 index 0000000000..2b5e69afbe --- /dev/null +++ b/source/java/org/alfresco/repo/avm/ibatis/HistoryLinkDAOIbatis.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" */ + +package org.alfresco.repo.avm.ibatis; + +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.repo.avm.AVMDAOs; +import org.alfresco.repo.avm.AVMNode; +import org.alfresco.repo.avm.HistoryLink; +import org.alfresco.repo.avm.HistoryLinkDAO; +import org.alfresco.repo.avm.HistoryLinkImpl; +import org.alfresco.repo.domain.avm.AVMHistoryLinkEntity; + +/** + * iBATIS DAO wrapper for HistoryLink + * + * @author janv + */ +class HistoryLinkDAOIbatis implements HistoryLinkDAO +{ + /* (non-Javadoc) + * @see org.alfresco.repo.avm.HistoryLinkDAO#save(org.alfresco.repo.avm.HistoryLink) + */ + public void save(HistoryLink link) + { + AVMDAOs.Instance().newAVMNodeLinksDAO.createHistoryLink(link.getAncestor().getId(), link.getDescendent().getId()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.HistoryLinkDAO#getByDescendent(org.alfresco.repo.avm.AVMNode) + */ + public HistoryLink getByDescendent(AVMNode descendent) + { + AVMHistoryLinkEntity hlEntity = AVMDAOs.Instance().newAVMNodeLinksDAO.getHistoryLinkByDescendent(descendent.getId()); + + if (hlEntity == null) + { + return null; + } + + AVMNode ancestor = AVMDAOs.Instance().fAVMNodeDAO.getByID(hlEntity.getAncestorNodeId()); + + HistoryLink hl = new HistoryLinkImpl(); + hl.setAncestor(ancestor); + hl.setDescendent(descendent); + return hl; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.HistoryLinkDAO#getByAncestor(org.alfresco.repo.avm.AVMNode) + */ + public List getByAncestor(AVMNode ancestor) + { + List hlEntities = AVMDAOs.Instance().newAVMNodeLinksDAO.getHistoryLinksByAncestor(ancestor.getId()); + + List hls = new ArrayList(hlEntities.size()); + for (AVMHistoryLinkEntity hlEntity : hlEntities) + { + AVMNode descendent = AVMDAOs.Instance().fAVMNodeDAO.getByID(hlEntity.getDescendentNodeId()); + + HistoryLink hl = new HistoryLinkImpl(); + hl.setAncestor(ancestor); + hl.setDescendent(descendent); + + hls.add(hl); + } + + return hls; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.HistoryLinkDAO#delete(org.alfresco.repo.avm.HistoryLink) + */ + public void delete(HistoryLink link) + { + AVMDAOs.Instance().newAVMNodeLinksDAO.deleteHistoryLink(link.getAncestor().getId(), link.getDescendent().getId()); + } +} diff --git a/source/java/org/alfresco/repo/avm/ibatis/MergeLinkDAOIbatis.java b/source/java/org/alfresco/repo/avm/ibatis/MergeLinkDAOIbatis.java new file mode 100644 index 0000000000..9236d65c72 --- /dev/null +++ b/source/java/org/alfresco/repo/avm/ibatis/MergeLinkDAOIbatis.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" */ + +package org.alfresco.repo.avm.ibatis; + +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.repo.avm.AVMDAOs; +import org.alfresco.repo.avm.AVMNode; +import org.alfresco.repo.avm.MergeLink; +import org.alfresco.repo.avm.MergeLinkDAO; +import org.alfresco.repo.avm.MergeLinkImpl; +import org.alfresco.repo.domain.avm.AVMMergeLinkEntity; + +/** + * iBATIS DAO wrapper for MergeLink + * + * @author janv + */ +class MergeLinkDAOIbatis implements MergeLinkDAO +{ + /* (non-Javadoc) + * @see org.alfresco.repo.avm.MergeLinkDAO#save(org.alfresco.repo.avm.MergeLink) + */ + public void save(MergeLink link) + { + AVMDAOs.Instance().newAVMNodeLinksDAO.createMergeLink(link.getMfrom().getId(), link.getMto().getId()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.MergeLinkDAO#getByTo(org.alfresco.repo.avm.AVMNode) + */ + public MergeLink getByTo(AVMNode to) + { + AVMMergeLinkEntity mlEntity = AVMDAOs.Instance().newAVMNodeLinksDAO.getMergeLinkByTo(to.getId()); + + if (mlEntity == null) + { + return null; + } + + AVMNode from = AVMDAOs.Instance().fAVMNodeDAO.getByID(mlEntity.getMergeFromNodeId()); + + MergeLink ml = new MergeLinkImpl(); + ml.setMfrom(from); + ml.setMto(to); + return ml; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.MergeLinkDAO#getByFrom(org.alfresco.repo.avm.AVMNode) + */ + public List getByFrom(AVMNode from) + { + List mlEntities = AVMDAOs.Instance().newAVMNodeLinksDAO.getMergeLinksByFrom(from.getId()); + + List mls = new ArrayList(mlEntities.size()); + for (AVMMergeLinkEntity mlEntity : mlEntities) + { + AVMNode to = AVMDAOs.Instance().fAVMNodeDAO.getByID(mlEntity.getMergeToNodeId()); + + MergeLink ml = new MergeLinkImpl(); + ml.setMfrom(from); + ml.setMto(to); + + mls.add(ml); + } + + return mls; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.MergeLinkDAO#delete(org.alfresco.repo.avm.MergeLink) + */ + public void delete(MergeLink link) + { + AVMDAOs.Instance().newAVMNodeLinksDAO.deleteMergeLink(link.getMfrom().getId(), link.getMto().getId()); + } +} diff --git a/source/java/org/alfresco/repo/avm/hibernate/VersionLayeredNodeEntryDAOHibernate.java b/source/java/org/alfresco/repo/avm/ibatis/VersionLayeredNodeEntryDAOIbatis.java similarity index 57% rename from source/java/org/alfresco/repo/avm/hibernate/VersionLayeredNodeEntryDAOHibernate.java rename to source/java/org/alfresco/repo/avm/ibatis/VersionLayeredNodeEntryDAOIbatis.java index 33a600b28c..9d5d9bd0a2 100644 --- a/source/java/org/alfresco/repo/avm/hibernate/VersionLayeredNodeEntryDAOHibernate.java +++ b/source/java/org/alfresco/repo/avm/ibatis/VersionLayeredNodeEntryDAOIbatis.java @@ -1,72 +1,81 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing - */ - -package org.alfresco.repo.avm.hibernate; - -import java.util.List; - -import org.alfresco.repo.avm.VersionLayeredNodeEntry; -import org.alfresco.repo.avm.VersionLayeredNodeEntryDAO; -import org.alfresco.repo.avm.VersionRoot; -import org.hibernate.Query; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - -/** - * Hibernate implementation of DAO for VersionLayeredNodeEntries. - * @author britt - */ -public class VersionLayeredNodeEntryDAOHibernate extends HibernateDaoSupport - implements VersionLayeredNodeEntryDAO -{ - /* (non-Javadoc) - * @see org.alfresco.repo.avm.VersionLayeredNodeEntryDAO#delete(org.alfresco.repo.avm.VersionRoot) - */ - public void delete(VersionRoot version) - { - Query query = getSession().createQuery("delete from VersionLayeredNodeEntryImpl vln where vln.version = :version"); - query.setEntity("version", version); - query.executeUpdate(); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.avm.VersionLayeredNodeEntryDAO#get(org.alfresco.repo.avm.VersionRoot) - */ - @SuppressWarnings("unchecked") - public List get(VersionRoot version) - { - Query query = getSession().createQuery("from VersionLayeredNodeEntryImpl vln " + - "where vln.version = :version"); - query.setEntity("version", version); - return (List)query.list(); - } - - /* (non-Javadoc) - * @see org.alfresco.repo.avm.VersionLayeredNodeEntryDAO#save(org.alfresco.repo.avm.VersionLayeredNodeEntry) - */ - public void save(VersionLayeredNodeEntry entry) - { - getSession().save(entry); - } -} +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.avm.ibatis; + +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.repo.avm.AVMDAOs; +import org.alfresco.repo.avm.VersionLayeredNodeEntry; +import org.alfresco.repo.avm.VersionLayeredNodeEntryDAO; +import org.alfresco.repo.avm.VersionLayeredNodeEntryImpl; +import org.alfresco.repo.avm.VersionRoot; +import org.alfresco.repo.domain.avm.AVMVersionLayeredNodeEntryEntity; + +/** + * iBATIS DAO wrapper for VersionLayeredNodeEntry + * + * @author janv + */ +class VersionLayeredNodeEntryDAOIbatis implements VersionLayeredNodeEntryDAO +{ + /* (non-Javadoc) + * @see org.alfresco.repo.avm.VersionLayeredNodeEntryDAO#delete(org.alfresco.repo.avm.VersionRoot) + */ + public void delete(VersionRoot version) + { + AVMDAOs.Instance().newAVMVersionRootDAO.deleteVersionLayeredNodeEntries(version.getId()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.VersionLayeredNodeEntryDAO#get(org.alfresco.repo.avm.VersionRoot) + */ + public List get(VersionRoot version) + { + List vlneEntities = AVMDAOs.Instance().newAVMVersionRootDAO.getVersionLayeredNodeEntries(version.getId()); + + List vlnes = new ArrayList(vlneEntities.size()); + for(AVMVersionLayeredNodeEntryEntity vlneEntity : vlneEntities) + { + VersionLayeredNodeEntryImpl vlne = new VersionLayeredNodeEntryImpl(); + vlne.setVersion(version); + vlne.setMd5Sum(vlneEntity.getMd5sum()); + vlne.setPath(vlneEntity.getPath()); + + vlnes.add(vlne); + } + + return vlnes; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.VersionLayeredNodeEntryDAO#save(org.alfresco.repo.avm.VersionLayeredNodeEntry) + */ + public void save(VersionLayeredNodeEntry entry) + { + AVMDAOs.Instance().newAVMVersionRootDAO.createVersionLayeredNodeEntry(entry.getVersion().getId(), entry.getMd5Sum(), entry.getPath()); + } +} diff --git a/source/java/org/alfresco/repo/avm/ibatis/VersionRootDAOIbatis.java b/source/java/org/alfresco/repo/avm/ibatis/VersionRootDAOIbatis.java new file mode 100644 index 0000000000..a20f481008 --- /dev/null +++ b/source/java/org/alfresco/repo/avm/ibatis/VersionRootDAOIbatis.java @@ -0,0 +1,191 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" */ + +package org.alfresco.repo.avm.ibatis; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.alfresco.repo.avm.AVMDAOs; +import org.alfresco.repo.avm.AVMNode; +import org.alfresco.repo.avm.AVMStore; +import org.alfresco.repo.avm.DirectoryNode; +import org.alfresco.repo.avm.VersionRoot; +import org.alfresco.repo.avm.VersionRootDAO; +import org.alfresco.repo.avm.VersionRootImpl; +import org.alfresco.repo.domain.avm.AVMVersionRootEntity; + +/** + * iBATIS DAO wrapper for VersionRoot + * + * @author janv + */ +class VersionRootDAOIbatis implements VersionRootDAO +{ + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.VersionRootDAO#save(org.alfresco.repo.avm.VersionRoot) + */ + public void save(VersionRoot vr) + { + AVMVersionRootEntity vrEntity = AVMDAOs.Instance().newAVMVersionRootDAO.createVersionRoot( + vr.getAvmStore().getId(), + vr.getRoot().getId(), + vr.getVersionID(), + vr.getCreator(), + vr.getTag(), + vr.getDescription()); + + ((VersionRootImpl)vr).setId(vrEntity.getId()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.VersionRootDAO#update(org.alfresco.repo.avm.VersionRoot) + */ + public void update(VersionRoot vr) + { + // note: tag and description only + AVMDAOs.Instance().newAVMVersionRootDAO.updateVersionRoot(convertVersionRootToVersionRootEntity(vr)); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.VersionRootDAO#delete(org.alfresco.repo.avm.VersionRoot) + */ + public void delete(VersionRoot vr) + { + AVMDAOs.Instance().newAVMVersionRootDAO.deleteVersionRoot(vr.getId()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.VersionRootDAO#getAllInAVMStore(org.alfresco.repo.avm.AVMStore) + */ + public List getAllInAVMStore(AVMStore store) + { + List vrEntities = AVMDAOs.Instance().newAVMVersionRootDAO.getAllInStore(store.getId()); + List vrs = new ArrayList(vrEntities.size()); + for (AVMVersionRootEntity vrEntity : vrEntities) + { + vrs.add(convertVersionRootEntityToVersionRoot(vrEntity)); + } + return vrs; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.VersionRootDAO#getByDates(org.alfresco.repo.avm.AVMStore, java.util.Date, java.util.Date) + */ + public List getByDates(AVMStore store, Date from, Date to) + { + List vrEntities = AVMDAOs.Instance().newAVMVersionRootDAO.getByDates(store.getId(), from, to); + List vrs = new ArrayList(vrEntities.size()); + for (AVMVersionRootEntity vrEntity : vrEntities) + { + vrs.add(convertVersionRootEntityToVersionRoot(vrEntity)); + } + return vrs; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.VersionRootDAO#getByVersionID(org.alfresco.repo.avm.AVMStore, int) + */ + public synchronized VersionRoot getByVersionID(AVMStore store, int id) + { + AVMVersionRootEntity vrEntity = AVMDAOs.Instance().newAVMVersionRootDAO.getByVersionID(store.getId(), id); + return convertVersionRootEntityToVersionRoot(vrEntity); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.VersionRootDAO#getByRoot(org.alfresco.repo.avm.AVMNode) + */ + public VersionRoot getByRoot(AVMNode root) + { + AVMVersionRootEntity vrEntity = AVMDAOs.Instance().newAVMVersionRootDAO.getByRoot(root.getId()); + return convertVersionRootEntityToVersionRoot(vrEntity); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.VersionRootDAO#getMaxVersion(org.alfresco.repo.avm.AVMStore) + */ + public VersionRoot getMaxVersion(AVMStore rep) + { + AVMVersionRootEntity vrEntity = AVMDAOs.Instance().newAVMVersionRootDAO.getMaxVersion(rep.getId()); + return convertVersionRootEntityToVersionRoot(vrEntity); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.VersionRootDAO#getMaxVersionID(org.alfresco.repo.avm.AVMStore) + */ + public Integer getMaxVersionID(AVMStore store) + { + Long maxVersionId = AVMDAOs.Instance().newAVMVersionRootDAO.getMaxVersionID(store.getId()); + if (maxVersionId == null) + { + return null; + } + return new Integer(maxVersionId.intValue()); + } + + private AVMVersionRootEntity convertVersionRootToVersionRootEntity(VersionRoot vr) + { + if (vr == null) + { + return null; + } + + AVMVersionRootEntity vrEntity = new AVMVersionRootEntity(); + vrEntity.setCreatedDate(vr.getCreateDate()); + vrEntity.setCreator(vr.getCreator()); + vrEntity.setDescription(vr.getDescription()); + vrEntity.setId(vr.getId()); + vrEntity.setRootNodeId(vr.getRoot().getId()); + vrEntity.setStoreId(vr.getAvmStore().getId()); + vrEntity.setTag(vr.getTag()); + vrEntity.setVersion(vr.getVersionID()); + + return vrEntity; + } + + private VersionRoot convertVersionRootEntityToVersionRoot(AVMVersionRootEntity vrEntity) + { + if (vrEntity == null) + { + return null; + } + + AVMStore store = AVMDAOs.Instance().fAVMStoreDAO.getByID(vrEntity.getStoreId()); + AVMNode rootNode = AVMDAOs.Instance().fAVMNodeDAO.getByID(vrEntity.getRootNodeId()); + + VersionRootImpl vr = new VersionRootImpl( + store, + (DirectoryNode)rootNode, + vrEntity.getVersion().intValue(), + vrEntity.getCreatedDate(), + vrEntity.getCreator(), + vrEntity.getTag(), + vrEntity.getDescription()); + + vr.setId(vrEntity.getId()); + + return vr; + } +} diff --git a/source/java/org/alfresco/repo/avm/util/BulkLoader.java b/source/java/org/alfresco/repo/avm/util/BulkLoader.java index cc9be28d64..bf5184b05f 100644 --- a/source/java/org/alfresco/repo/avm/util/BulkLoader.java +++ b/source/java/org/alfresco/repo/avm/util/BulkLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2008 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -38,6 +38,7 @@ import org.alfresco.service.cmr.avm.AVMService; import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.remote.AVMRemote; import org.alfresco.service.namespace.QName; +import org.alfresco.util.Pair; /** * This takes a filesystem directory path and a repository path and name @@ -88,6 +89,12 @@ public class BulkLoader * @param repPath */ public void recursiveLoad(String fsPath, String repPath) + { + Pair cnts = recursiveLoadImpl(fsPath, repPath, 0, 0); + + System.out.println("Loaded: "+cnts.getFirst()+" directories, "+cnts.getSecond()+" files"); + } + private Pair recursiveLoadImpl(String fsPath, String repPath, int dirCount, int fileCount) { Map props = new HashMap(); for (int i = 0; i < fPropertyCount; i++) @@ -99,13 +106,19 @@ public class BulkLoader if (file.isDirectory()) { fService.createDirectory(repPath, name); + dirCount++; + String[] children = file.list(); String baseName = repPath.endsWith("/") ? repPath + name : repPath + "/" + name; fService.setNodeProperties(baseName, props); for (String child : children) { - recursiveLoad(fsPath + "/" + child, baseName); + Pair cnts = recursiveLoadImpl(fsPath + "/" + child, baseName, dirCount, fileCount); + dirCount = cnts.getFirst(); + fileCount = cnts.getSecond(); } + + return new Pair(dirCount, fileCount); } else { @@ -113,6 +126,7 @@ public class BulkLoader { InputStream in = new FileInputStream(file); OutputStream out = fService.createFile(repPath, name); + fileCount++; fService.setNodeProperties(repPath + "/" + name, props); byte[] buff = new byte[8192]; int read = 0; @@ -122,6 +136,8 @@ public class BulkLoader } out.close(); in.close(); + + return new Pair(dirCount, fileCount); } catch (IOException e) { @@ -130,4 +146,4 @@ public class BulkLoader } } } -} +} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/avm/wf/AVMSubmitPackageHandler.java b/source/java/org/alfresco/repo/avm/wf/AVMSubmitPackageHandler.java index c52ce5638f..c71f2654db 100644 --- a/source/java/org/alfresco/repo/avm/wf/AVMSubmitPackageHandler.java +++ b/source/java/org/alfresco/repo/avm/wf/AVMSubmitPackageHandler.java @@ -128,7 +128,6 @@ public class AVMSubmitPackageHandler extends JBPMSpringActionHandler implements public Object doWork() throws Exception { fAVMSyncService.update(stagingDiffs, null, false, false, true, true, tag, description); - AVMDAOs.Instance().fAVMNodeDAO.flush(); fAVMSyncService.flatten(pkgPath.getSecond(), targetPath); for (final AVMDifference diff : stagingDiffs) @@ -150,7 +149,6 @@ public class AVMSubmitPackageHandler extends JBPMSpringActionHandler implements // may get lost when the item is finally approved final List sandboxDiffs = fAVMSyncService.compare(pkgPath.getFirst(), pkgPath.getSecond(), -1, from, null); fAVMSyncService.update(sandboxDiffs, null, true, true, false, false, tag, description); - AVMDAOs.Instance().fAVMNodeDAO.flush(); fAVMSyncService.flatten(from, targetPath); } diff --git a/source/java/org/alfresco/repo/cache/lookup/EntityLookupCache.java b/source/java/org/alfresco/repo/cache/lookup/EntityLookupCache.java index 2caaa8d0f1..7c77c1a6ac 100644 --- a/source/java/org/alfresco/repo/cache/lookup/EntityLookupCache.java +++ b/source/java/org/alfresco/repo/cache/lookup/EntityLookupCache.java @@ -395,7 +395,7 @@ public class EntityLookupCache(key, value); + return getByKey(key); } } // Resolve it @@ -412,7 +412,7 @@ public class EntityLookupCacheavm_aspects table + * + * @author janv + * @since 3.2 + */ + +public class AVMAspectEntity +{ + private Long nodeId; + private Long qnameId; + + public AVMAspectEntity() + { + // default constructor + } + + public AVMAspectEntity(Long nodeId, Long qnameId) + { + this.nodeId = nodeId; + this.qnameId = qnameId; + } + + public Long getNodeId() + { + return nodeId; + } + + public void setNodeId(Long nodeId) + { + this.nodeId = nodeId; + } + + public Long getQnameId() + { + return qnameId; + } + + public void setQnameId(Long qnameId) + { + this.qnameId = qnameId; + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMChildEntryEntity.java b/source/java/org/alfresco/repo/domain/avm/AVMChildEntryEntity.java new file mode 100644 index 0000000000..70af7015c2 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMChildEntryEntity.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import org.alfresco.util.EqualsHelper; + +/** + * Entity bean for avm_child_entries table + * + * @author janv + * @since 3.2 + */ +public class AVMChildEntryEntity +{ + private Long parentNodeId; + private String name; + private Long childNodeId; + + public AVMChildEntryEntity() + { + // default constructor + } + + public AVMChildEntryEntity(long parentNodeId, String name, long childNodeId) + { + this.parentNodeId = parentNodeId; + this.name = name; + this.childNodeId = childNodeId; + } + + public AVMChildEntryEntity(long parentNodeId, String name) + { + this.parentNodeId = parentNodeId; + this.name = name; + } + + public AVMChildEntryEntity(long parentNodeId, long childNodeId) + { + this.parentNodeId = parentNodeId; + this.childNodeId = childNodeId; + } + + public Long getParentNodeId() + { + return parentNodeId; + } + + public void setParentNodeId(Long parentNodeId) + { + this.parentNodeId = parentNodeId; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public Long getChildId() + { + return childNodeId; + } + + public void setChildNodeId(Long childNodeId) + { + this.childNodeId = childNodeId; + } + + @Override + public int hashCode() + { + return ((parentNodeId == null ? 0 : parentNodeId.hashCode()) + + (name == null ? 0 : name.hashCode()) + + (childNodeId == null ? 0 : childNodeId.hashCode())); + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + else if (obj instanceof AVMChildEntryEntity) + { + AVMChildEntryEntity that = (AVMChildEntryEntity) obj; + return (EqualsHelper.nullSafeEquals(this.parentNodeId, that.parentNodeId) && + EqualsHelper.nullSafeEquals(this.name, that.name) && + EqualsHelper.nullSafeEquals(this.childNodeId, that.childNodeId)); + } + else + { + return false; + } + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMHistoryLinkEntity.java b/source/java/org/alfresco/repo/domain/avm/AVMHistoryLinkEntity.java new file mode 100644 index 0000000000..25e372985e --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMHistoryLinkEntity.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import java.io.Serializable; + + +/** + * Entity bean for avm_history_links table + * + * @author janv + * @since 3.2 + */ +public class AVMHistoryLinkEntity implements Serializable +{ + private static final long serialVersionUID = 1578072747215533879L; + + private Long ancestorNodeId; + private Long descendentNodeId; + + public AVMHistoryLinkEntity() + { + // default constructor + } + public AVMHistoryLinkEntity(Long ancestorNodeId, Long descendentNodeId) + { + this.ancestorNodeId = ancestorNodeId; + this.descendentNodeId = descendentNodeId; + } + + public Long getDescendentNodeId() + { + return descendentNodeId; + } + + public void setDescendentNodeId(Long descendentNodeId) + { + this.descendentNodeId = descendentNodeId; + } + + public Long getAncestorNodeId() + { + return ancestorNodeId; + } + + public void setAncestorNodeId(Long ancestorNodeId) + { + this.ancestorNodeId = ancestorNodeId; + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMMergeLinkEntity.java b/source/java/org/alfresco/repo/domain/avm/AVMMergeLinkEntity.java new file mode 100644 index 0000000000..3d66f1ad4e --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMMergeLinkEntity.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + + +/** + * Entity bean for avm_merge_links table + * + * @author janv + * @since 3.2 + */ +public class AVMMergeLinkEntity +{ + private Long mergeFromNodeId; + private Long mergeToNodeId; + + public AVMMergeLinkEntity() + { + // default constructor + } + + public AVMMergeLinkEntity(Long mergeFromNodeId, Long mergeToNodeId) + { + this.mergeFromNodeId = mergeFromNodeId; + this.mergeToNodeId = mergeToNodeId; + } + + public Long getMergeFromNodeId() + { + return mergeFromNodeId; + } + + public void setMergeFromNodeId(Long mergeFromNodeId) + { + this.mergeFromNodeId = mergeFromNodeId; + } + + public Long getMergeToNodeId() + { + return mergeToNodeId; + } + + public void setMergeToNodeId(Long mergeToNodeId) + { + this.mergeToNodeId = mergeToNodeId; + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMNodeAspectEntity.java b/source/java/org/alfresco/repo/domain/avm/AVMNodeAspectEntity.java new file mode 100644 index 0000000000..edb1c4e816 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMNodeAspectEntity.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + + +/** + * Entity bean for avm_aspects table + * + * @author janv + * @since 3.2 + */ + +public class AVMNodeAspectEntity +{ + public static final Long CONST_LONG_ZERO = new Long(0L); + + private Long nodeId; + private Long qnameId; + + public AVMNodeAspectEntity() + { + // default constructor + } + + public AVMNodeAspectEntity(Long nodeId, Long qnameId) + { + this.nodeId = nodeId; + this.qnameId = qnameId; + } + + public Long getNodeId() + { + return nodeId; + } + + public void setNodeId(Long nodeId) + { + this.nodeId = nodeId; + } + + public Long getQnameId() + { + return qnameId; + } + + public void setQnameId(Long qnameId) + { + this.qnameId = qnameId; + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMNodeChildEntryEntity.java b/source/java/org/alfresco/repo/domain/avm/AVMNodeChildEntryEntity.java new file mode 100644 index 0000000000..edb030c784 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMNodeChildEntryEntity.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + + +/** + * Entity bean for avm_child_entries table + * + * @author janv + * @since 3.2 + */ + +public class AVMNodeChildEntryEntity +{ + public static final Long CONST_LONG_ZERO = new Long(0L); + + private Long parentNodeId; + private String name; + private Long childNodeId; + + public AVMNodeChildEntryEntity() + { + // default constructor + } + + /* + public AVMNodeChildEntryEntity(Long parentNodeId, String name, Long childNodeId) + { + this.parentNodeId = parentNodeId; + this.name = name; + this.childNodeId = childNodeId; + } + */ + + public Long getParentNodeId() + { + return parentNodeId; + } + + public void setParentNodeId(Long parentNodeId) + { + this.parentNodeId = parentNodeId; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public Long getChildId() + { + return childNodeId; + } + + public void setChildNodeId(Long childNodeId) + { + this.childNodeId = childNodeId; + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMNodeDAO.java b/source/java/org/alfresco/repo/domain/avm/AVMNodeDAO.java new file mode 100644 index 0000000000..96a09ca425 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMNodeDAO.java @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.service.namespace.QName; +import org.springframework.dao.ConcurrencyFailureException; + +/** + * DAO services for + * avm_nodes, + * avm_aspects, + * avm_node_properties + * tables + * + * @author janv + * @since 3.2 + */ +public interface AVMNodeDAO +{ + // + // AVM Nodes + // + + public AVMNodeEntity createNode(AVMNodeEntity nodeEntity); + + public AVMNodeEntity getNode(long nodeId); + + public void updateNode(AVMNodeEntity nodeEntity); + + public void updateNodeModTimeAndGuid(AVMNodeEntity nodeEntity); + + public void updateNodeModTimeAndContentData(AVMNodeEntity nodeEntity); + + public List getNodesNewInStore(long storeId); + + public List getLayeredNodesNewInStore(long storeId); + + public List getLayeredNodesNewInStoreIDs(long storeId); + + public List getNodeOrphans(); + + public void updateNodesClearNewInStore(long storeId); + + public void deleteNode(long nodeId); + + public List getAllLayeredDirectories(); + + public List getAllLayeredFiles(); + + public List getAVMNodesByAclId(long aclId); + + public void clearNodeEntityCache(); + + /** + * Get all content urls in the AVM Repository. + * @param contentUrlHandler the handler that will be called with the URLs + */ + public void getContentUrls(ContentUrlHandler handler); + + /** + * A callback handler for iterating over the content URLs + */ + public interface ContentUrlHandler + { + void handle(String contentUrl); + } + + + // + // AVM Node Aspects + // + + /** + * Add aspect to given Node + * + * @param nodeId the unique ID of the node entity + * @param qname the qname + * @throws ConcurrencyFailureException if the aspect already exists + */ + public void createAspect(long nodeId, QName qname); + + /** + * Get set of aspects for given Node + * + * @param nodeId the unique ID of the node entity + * @return the set of qnames (never null) + * @throws AlfrescoRuntimeException if the ID provided is invalid + */ + public Set getAspects(long nodeId); + + /** + * Remove aspect from given Node + * + * @param nodeId the unique ID of the node entity + * @param qnameId the qname + * @throws ConcurrencyFailureException if the aspect does not exist + */ + public void deleteAspect(long nodeId, QName qname); + + public void deleteAspects(long nodeId); + + // + // AVM Node Properties + // + + public void createOrUpdateNodeProperty(long nodeId, QName qname, PropertyValue value); + + public Map getNodeProperties(long nodeId); + + public void deleteNodeProperty(long nodeId, QName qname); + + public void deleteNodeProperties(long nodeId); +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMNodeEntity.java b/source/java/org/alfresco/repo/domain/avm/AVMNodeEntity.java new file mode 100644 index 0000000000..54ee182074 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMNodeEntity.java @@ -0,0 +1,410 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.avm.AVMNodeType; +import org.alfresco.util.EqualsHelper; + +/** + * Entity bean for avm_nodes table. + *

+ * + * @author janv + * @since 3.2 + */ +public class AVMNodeEntity +{ + private Long id; + private Long version; + private Integer type; + private String classType; + private Long storeNewId; + private Long aclId; + private Long layerId; + private String guid; + private boolean isRoot; + private Integer deletedType; + private String indirection; + private Integer indirectionVersion; + private boolean primaryIndirection; + private boolean opacity; + private String contentUrl; + private String mimetype; + private String encoding; + private Long length; + + // basic attributes + private String owner; + private String creator; + private Long createdDate; + private String modifier; + private Long modifiedDate; + private Long accessDate; + + private Long vers; // for concurrency control + + + public Long getId() + { + return id; + } + + public void setId(Long id) + { + this.id = id; + } + + public String getClassType() + { + return classType; + } + + public void setClassType(String classType) + { + this.classType = classType; + + this.type = null; + if (classType != null) + { + if (classType.equals("plainfile")) + { + type = AVMNodeType.PLAIN_FILE; + } + else if (classType.equals("plaindirectory")) + { + type = AVMNodeType.PLAIN_DIRECTORY; + } + else if (classType.equals("layeredfile")) + { + type = AVMNodeType.LAYERED_FILE; + } + else if (classType.equals("layereddirectory")) + { + type = AVMNodeType.LAYERED_DIRECTORY; + } + else if (classType.equals("deletednode")) + { + type = AVMNodeType.DELETED_NODE; + } + else + { + // belts-and-braces + throw new AlfrescoRuntimeException("Unexpected node class_type: "+classType); + } + } + } + + public int getType() + { + return type; + } + + public void setType(Integer type) + { + this.type = type; + + this.classType = null; + if (type != null) + { + switch (type) + { + case AVMNodeType.PLAIN_FILE : + classType = "plainfile"; + break; + case AVMNodeType.PLAIN_DIRECTORY : + classType = "plaindirectory"; + break; + case AVMNodeType.LAYERED_FILE : + classType = "layeredfile"; + break; + case AVMNodeType.LAYERED_DIRECTORY : + classType = "layereddirectory"; + break; + case AVMNodeType.DELETED_NODE : + classType = "deletednode"; + break; + default: + // belts-and-braces + throw new AlfrescoRuntimeException("Unexpected node type: "+type); + } + } + } + + public Long getVersion() + { + return version; + } + + public void setVersion(Long version) + { + this.version = version; + } + + public Long getStoreNewId() + { + return storeNewId; + } + + public void setStoreNewId(Long storeNewId) + { + this.storeNewId = storeNewId; + } + + public Long getAclId() + { + return aclId; + } + + public void setAclId(Long aclId) + { + this.aclId = aclId; + } + + public Long getLayerId() + { + return layerId; + } + + public void setLayerId(Long layerId) + { + this.layerId = layerId; + } + + public String getGuid() + { + return guid; + } + + public void setGuid(String guid) + { + this.guid = guid; + } + + public boolean isRoot() + { + return isRoot; + } + + public void setRoot(boolean isRoot) + { + this.isRoot = isRoot; + } + + public Integer getDeletedType() + { + return deletedType; + } + + public void setDeletedType(Integer deletedType) + { + this.deletedType = deletedType; + } + + public String getIndirection() + { + return indirection; + } + + public void setIndirection(String indirection) + { + this.indirection = indirection; + } + + public Integer getIndirectionVersion() + { + return indirectionVersion; + } + + public void setIndirectionVersion(Integer indirectionVersion) + { + this.indirectionVersion = indirectionVersion; + } + + public boolean isPrimaryIndirection() + { + return primaryIndirection; + } + + public void setPrimaryIndirection(boolean primaryIndirection) + { + this.primaryIndirection = primaryIndirection; + } + + public boolean getOpacity() + { + return opacity; + } + + public void setOpacity(boolean opacity) + { + this.opacity = opacity; + } + + public String getContentUrl() + { + return contentUrl; + } + + public void setContentUrl(String contentUrl) + { + this.contentUrl = contentUrl; + } + + public String getMimetype() + { + return mimetype; + } + + public void setMimetype(String mimetype) + { + this.mimetype = mimetype; + } + + public String getEncoding() + { + return encoding; + } + + public void setEncoding(String encoding) + { + this.encoding = encoding; + } + + public Long getLength() + { + return length; + } + + public void setLength(Long length) + { + this.length = length; + } + + public String getOwner() + { + return owner; + } + + public void setOwner(String owner) + { + this.owner = owner; + } + + public String getCreator() + { + return creator; + } + + public void setCreator(String creator) + { + this.creator = creator; + } + + public Long getCreatedDate() + { + return createdDate; + } + + public void setCreatedDate(Long createdDate) + { + this.createdDate = createdDate; + } + + public String getModifier() + { + return modifier; + } + + public void setModifier(String modifier) + { + this.modifier = modifier; + } + + public Long getModifiedDate() + { + return modifiedDate; + } + + public void setModifiedDate(Long modifiedDate) + { + this.modifiedDate = modifiedDate; + } + + public Long getAccessDate() + { + return accessDate; + } + + public void setAccessDate(Long accessDate) + { + this.accessDate = accessDate; + } + + public Long getVers() + { + return vers; + } + + public void setVers(Long vers) + { + this.vers = vers; + } + + @Override + public int hashCode() + { + return (id == null ? 0 : id.hashCode()); + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + else if (obj instanceof AVMNodeEntity) + { + AVMNodeEntity that = (AVMNodeEntity) obj; + return EqualsHelper.nullSafeEquals(this.id, that.id); + } + else + { + return false; + } + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder(512); + sb.append("AVMNodeEntity") + .append("[ ID=").append(id) + .append(", nextVersion=").append(version) + .append("]"); + return sb.toString(); + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMNodeLinksDAO.java b/source/java/org/alfresco/repo/domain/avm/AVMNodeLinksDAO.java new file mode 100644 index 0000000000..492066430a --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMNodeLinksDAO.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import java.util.List; + +/** + * DAO services for + * avm_child_entries, + * avm_history_links, + * avm_merge_links + * tables + * + * @author janv + * @since 3.2 + */ +public interface AVMNodeLinksDAO +{ + // + // Node Entries (parent/child) + // + + /** + * Get an entry by name and parent + */ + public void createChildEntry(long parentNodeId, String name, long childNodeId); + + /** + * Get all the children of a given parent + */ + public List getChildEntriesByParent(long parentNodeId); + + /** + * Get all the ChildEntries corresponding to the given child + */ + public List getChildEntriesByChild(long childNodeId); + + /** + * Get an entry by name and parent + */ + public AVMChildEntryEntity getChildEntry(long parentNodeId, String name); + + /** + * Get all the children of a given parent + * + * NOTE: pattern can use * or % (TBC) + */ + //public List findChildEntriesByParent(String parentNodeId, String childNamePattern); + + /** + * Get the entry for a given child in a given parent + */ + public AVMChildEntryEntity getChildEntry(long parentNodeId, long childNodeId); + + /** + * Delete one + */ + public void deleteChildEntry(AVMChildEntryEntity childEntryEntity); + + /** + * Delete all children of the given parent + */ + public void deleteChildEntriesByParent(long parentNodeId); + + // + // MergeLink Entries + // + + public void createMergeLink(long mergeFromNodeId, long mergeToNodeId); + + public void deleteMergeLink(long mergeFromNodeId, long mergeToNodeId); + + public AVMMergeLinkEntity getMergeLinkByTo(long mergeToNodeId); + + public List getMergeLinksByFrom(long mergeFromNodeId); + + // + // HistoryLink Entries + // + + public void createHistoryLink(long ancestorNodeId, long descendentNodeId); + + public void deleteHistoryLink(long ancestorNodeId, long descendentNodeId); + + public AVMHistoryLinkEntity getHistoryLinkByDescendent(long descendentNodeId); + + public List getHistoryLinksByAncestor(long ancestorNodeId); +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMNodePropertyEntity.java b/source/java/org/alfresco/repo/domain/avm/AVMNodePropertyEntity.java new file mode 100644 index 0000000000..f62c190908 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMNodePropertyEntity.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.util.EqualsHelper; + +/** + * Entity bean for avm_node_properties table. + *

+ * + * @author janv + * @since 3.2 + */ +public class AVMNodePropertyEntity extends PropertyValue +{ + private static final long serialVersionUID = 1867663274306415601L; + + private Long nodeId; + private Long qnameId; + + public AVMNodePropertyEntity() + { + } + + // TODO redo + public AVMNodePropertyEntity(long nodeId, Long qnameId, PropertyValue value) + { + setNodeId(nodeId); + setQnameId(qnameId); + + this.setActualType(value.getActualType()); + this.setAttributeValue(value.getAttributeValue()); + this.setBooleanValue(value.getBooleanValue()); + this.setDoubleValue(value.getDoubleValue()); + this.setFloatValue(value.getFloatValue()); + this.setLongValue(value.getLongValue()); + this.setMultiValued(value.isMultiValued()); + this.setPersistedType(value.getPersistedType()); + this.setSerializableValue(value.getSerializableValue()); + this.setStringValue(value.getStringValue()); + } + + public Long getNodeId() + { + return nodeId; + } + public void setNodeId(Long nodeId) + { + this.nodeId = nodeId; + } + public Long getQnameId() + { + return qnameId; + } + public void setQnameId(Long qnameId) + { + this.qnameId = qnameId; + } + + public void setSerializable(byte[] data) + { + setSerializableValue(data); + } + + public byte[] getSerializable() + { + return (byte[])getSerializableValue(); + } + + @Override + public int hashCode() + { + return super.hashCode(); + } + + @Override + public boolean equals(Object obj) + { + return super.equals(obj); + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMStoreDAO.java b/source/java/org/alfresco/repo/domain/avm/AVMStoreDAO.java new file mode 100644 index 0000000000..bf538f6110 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMStoreDAO.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import java.util.List; +import java.util.Map; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.service.namespace.QName; +import org.springframework.dao.ConcurrencyFailureException; + +/** + * DAO services for + * avm_stores, + * avm_store_properties + * tables + * + * @author janv + * @since 3.2 + */ +public interface AVMStoreDAO +{ + // + // AVM Stores + // + + /** + * Get an existing AVM store by Store ID + * + * @param id the unique ID of the store entity + * @return the store (never null) + * @throws AlfrescoRuntimeException if the ID provided is invalid + */ + public AVMStoreEntity getStore(long id); + + /** + * Get an existing AVM store by Root Node ID + * + * @param rootNodeId the unique ID of the root node entity + * @return the store (never null) + * @throws AlfrescoRuntimeException if the ID provided is invalid + */ + public AVMStoreEntity getStoreByRoot(long rootNodeId); + + /** + * Get an existing AVM store by name + * + * @param name the name to query for + * @return the store or null if it doesn't exist + */ + public AVMStoreEntity getStore(String name); + + /** + * Get all AVM stores + * + * @return list of stores or empty if no stores (never null) + */ + public List getAllStores(); + + /** + * Create a new AVM store + * + * @param name the name + * @return the store (never null) + * @throws ConcurrencyFailureException if the name already exists + */ + public AVMStoreEntity createStore(String name); + + /** + * Update an existing AVM store + * + * @param storeEntity the store + */ + public void updateStore(AVMStoreEntity storeEntity); + + /** + * Delete an existing AVM store + * + * @param storeEntity the store + * @throws ConcurrencyFailureException if the store does not exist + */ + public void deleteStore(long storeId); + + public void clearStoreEntityCache(); + + // + // AVM Store Properties + // + + public void createOrUpdateStoreProperty(long storeId, QName qname, PropertyValue value); + + public PropertyValue getStoreProperty(long storeId, QName qname); + + public Map getStoreProperties(long storeId); + + public Map> getStorePropertiesByKeyPattern(String uri, String localName); + + public Map getStorePropertiesByStoreAndKeyPattern(long storeId, String uri, String localName); + + public void deleteStoreProperty(long storeId, QName qname); + + public void deleteStoreProperties(long storeId); +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMStoreDAOTest.java b/source/java/org/alfresco/repo/domain/avm/AVMStoreDAOTest.java new file mode 100644 index 0000000000..dcdc7de6ca --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMStoreDAOTest.java @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import junit.framework.TestCase; + +import org.alfresco.repo.transaction.RetryingTransactionHelper; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.transaction.TransactionService; +import org.alfresco.util.ApplicationContextHelper; +import org.alfresco.util.GUID; +import org.alfresco.util.Pair; +import org.springframework.context.ApplicationContext; + +/** + * @see AVMStoreDAO + * + * @author janv + * @since 3.2 + */ +public class AVMStoreDAOTest extends TestCase +{ + private ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); + + private TransactionService transactionService; + private RetryingTransactionHelper txnHelper; + private AVMStoreDAO avmStoreDAO; + + @Override + public void setUp() throws Exception + { + ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); + transactionService = serviceRegistry.getTransactionService(); + txnHelper = transactionService.getRetryingTransactionHelper(); + + avmStoreDAO = (AVMStoreDAO) ctx.getBean("newAvmStoreDAO"); + } + + private AVMStoreEntity get(final String avmStoreName, final boolean autoCreate, boolean expectSuccess) + { + RetryingTransactionCallback callback = new RetryingTransactionCallback() + { + public AVMStoreEntity execute() throws Throwable + { + AVMStoreEntity avmStoreEntity = null; + if (autoCreate) + { + avmStoreEntity = avmStoreDAO.createStore(avmStoreName); + } + else + { + avmStoreEntity = avmStoreDAO.getStore(avmStoreName); + } + return avmStoreEntity; + } + }; + try + { + return txnHelper.doInTransaction(callback, !autoCreate, false); + } + catch (Throwable e) + { + if (expectSuccess) + { + // oops + throw new RuntimeException("Expected to get avmStore '" + avmStoreName + "'.", e); + } + else + { + return null; + } + } + } + + public void testCreateWithCommit() throws Exception + { + // Create an avmStore + String avmStore = GUID.generate(); + AVMStoreEntity avmStoreEntity = get(avmStore, true, true); + // Check that it can be retrieved + AVMStoreEntity avmStoreCheck = get(avmStoreEntity.getName(), false, true); + assertEquals("avmStore ID changed", avmStoreEntity.getId(), avmStoreCheck.getId()); + } + + public void testCreateWithRollback() throws Exception + { + final String avmStore = GUID.generate(); + // Create an avmStore + RetryingTransactionCallback> callback = new RetryingTransactionCallback>() + { + public Pair execute() throws Throwable + { + get(avmStore, true, true); + // Now force a rollback + throw new RuntimeException("Forced"); + } + }; + try + { + txnHelper.doInTransaction(callback); + fail("Transaction didn't roll back"); + } + catch (RuntimeException e) + { + // Expected + } + // Check that it doesn't exist + get(avmStore, false, false); + } + + // TODO - review + public void testCaseInsensitivity() throws Exception + { + String avmStore = "AAA-" + GUID.generate(); + AVMStoreEntity lowercase = get(avmStore.toLowerCase(), true, true); + // Check that the same pair is retrievable using uppercase + AVMStoreEntity uppercase = get(avmStore.toUpperCase(), false, true); + assertNotNull(uppercase); + assertEquals( + "Upper and lowercase avmStore instance IDs were not the same", + lowercase.getId(), uppercase.getId()); + } + + public void testDelete() throws Exception + { + // Create an avmStore + String avmStore = GUID.generate(); + AVMStoreEntity avmStoreEntity = get(avmStore, true, true); + + getAndCheck(avmStoreEntity.getId(), avmStoreEntity); + + avmStoreDAO.deleteStore(avmStoreEntity.getId()); + try + { + getAndCheck(avmStoreEntity.getId(), avmStoreEntity); + fail("Entity still exists"); + } + catch (Throwable e) + { + // Expected + } + } + + public void testUpdate() throws Exception + { + // TODO + } + + /** + * Retrieves and checks the AVMStore for equality + */ + private void getAndCheck(final Long avmStoreId, AVMStoreEntity checkAVMStoreEntity) + { + RetryingTransactionCallback callback = new RetryingTransactionCallback() + { + public AVMStoreEntity execute() throws Throwable + { + AVMStoreEntity storeEntity = avmStoreDAO.getStore(avmStoreId); + return storeEntity; + } + }; + AVMStoreEntity result = txnHelper.doInTransaction(callback, true, false); + assertNotNull("Failed to find result for ID " + avmStoreId, result); + assertEquals("ContentData retrieved not the same as persisted: ", checkAVMStoreEntity, result); + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMStoreEntity.java b/source/java/org/alfresco/repo/domain/avm/AVMStoreEntity.java new file mode 100644 index 0000000000..69501557a6 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMStoreEntity.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import org.alfresco.util.EqualsHelper; + +/** + * Entity bean for avm_stores table. + *

+ * + * @author janv + * @since 3.2 + */ +public class AVMStoreEntity +{ + private Long id; + private Long nextVersion; + private String name; + private Long aclId; + private Long rootNodeId; + private Long vers; // for concurrency control + + + public Long getId() + { + return id; + } + + public void setId(Long id) + { + this.id = id; + } + + public Long getVersion() + { + return nextVersion; + } + + public void setVersion(Long version) + { + this.nextVersion = version; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public Long getRootNodeId() + { + return rootNodeId; + } + + public void setRootNodeId(Long rootNodeId) + { + this.rootNodeId = rootNodeId; + } + + public Long getAclId() + { + return aclId; + } + + public void setAclId(Long aclId) + { + this.aclId = aclId; + } + + public Long getVers() + { + return vers; + } + + public void setVers(Long vers) + { + this.vers = vers; + } + + @Override + public int hashCode() + { + return (name == null ? 0 : name.hashCode()); + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + else if (obj instanceof AVMStoreEntity) + { + AVMStoreEntity that = (AVMStoreEntity) obj; + return EqualsHelper.nullSafeEquals(this.name, that.name); + } + else + { + return false; + } + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder(512); + sb.append("AVMStoreEntity") + .append("[ ID=").append(id) + .append(", name=").append(name) + .append(", nextVersion=").append(nextVersion) + .append(", rootNodeId=").append(rootNodeId) + .append(", aclId=").append(aclId) + .append("]"); + return sb.toString(); + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMStorePropertyEntity.java b/source/java/org/alfresco/repo/domain/avm/AVMStorePropertyEntity.java new file mode 100644 index 0000000000..b5d0a1b604 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMStorePropertyEntity.java @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.util.EqualsHelper; + +/** + * Entity bean for avm_store_properties table. + *

+ * + * @author janv + * @since 3.2 + */ +public class AVMStorePropertyEntity extends PropertyValue +{ + private static final long serialVersionUID = -3125922581571555965L; + + private Long id; + private Long avmStoreId; + private Long qnameId; + + public AVMStorePropertyEntity() + { + // default constructor + } + + // TODO redo + public AVMStorePropertyEntity(long storeId, Long qnameId, PropertyValue value) + { + setAvmStoreId(storeId); + setQnameId(qnameId); + + this.setActualType(value.getActualType()); + this.setAttributeValue(value.getAttributeValue()); + this.setBooleanValue(value.getBooleanValue()); + this.setDoubleValue(value.getDoubleValue()); + this.setFloatValue(value.getFloatValue()); + this.setLongValue(value.getLongValue()); + this.setMultiValued(value.isMultiValued()); + this.setPersistedType(value.getPersistedType()); + this.setSerializableValue(value.getSerializableValue()); + this.setStringValue(value.getStringValue()); + } + + public Long getId() + { + return id; + } + public void setId(Long id) + { + this.id = id; + } + public Long getAvmStoreId() + { + return avmStoreId; + } + public void setAvmStoreId(Long avmStoreId) + { + this.avmStoreId = avmStoreId; + } + public Long getQnameId() + { + return qnameId; + } + public void setQnameId(Long qnameId) + { + this.qnameId = qnameId; + } + + public void setSerializable(byte[] data) + { + setSerializableValue(data); + } + + public byte[] getSerializable() + { + return (byte[])getSerializableValue(); + } + + @Override + public int hashCode() + { + return ((avmStoreId == null ? 0 : avmStoreId.hashCode()) + + (qnameId == null ? 0 : qnameId.hashCode())); + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + else if (obj instanceof AVMStorePropertyEntity) + { + AVMStorePropertyEntity that = (AVMStorePropertyEntity) obj; + return (EqualsHelper.nullSafeEquals(this.avmStoreId, that.avmStoreId) && + EqualsHelper.nullSafeEquals(this.qnameId, that.qnameId)); + } + else + { + return false; + } + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMVersionLayeredNodeEntryEntity.java b/source/java/org/alfresco/repo/domain/avm/AVMVersionLayeredNodeEntryEntity.java new file mode 100644 index 0000000000..39b59a5857 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMVersionLayeredNodeEntryEntity.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import java.io.Serializable; + +/** + * Entity bean for avm_version_layered_node_entry table + * + * @author janv + * @since 3.2 + */ +public class AVMVersionLayeredNodeEntryEntity +{ + private Long versionRootId; + private String md5sum; + private String path; + + public Long getVersionRootId() + { + return versionRootId; + } + + public void setVersionRootId(Long versionRootId) + { + this.versionRootId = versionRootId; + } + + public String getMd5sum() + { + return md5sum; + } + + public void setMd5sum(String md5sum) + { + this.md5sum = md5sum; + } + + public String getPath() + { + return path; + } + + public void setPath(String path) + { + this.path = path; + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMVersionRootDAO.java b/source/java/org/alfresco/repo/domain/avm/AVMVersionRootDAO.java new file mode 100644 index 0000000000..d47d317a7b --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMVersionRootDAO.java @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import java.util.Date; +import java.util.List; + +import org.springframework.dao.ConcurrencyFailureException; + +/** + * DAO services for avm_version_roots table + * + * @author janv + * @since 3.2 + */ +public interface AVMVersionRootDAO +{ + /** + * Create a new AVM version root + * + */ + public AVMVersionRootEntity createVersionRoot(long storeId, long rootNodeId, int version, String creator, String tag, String description); + + /** + * Update an AVM version root (tag and description only) + * + * @param vrEntity + */ + public void updateVersionRoot(AVMVersionRootEntity vrEntity); + + /** + * Delete an existing AVM version root + * + * @param vrEntity the version root entity + * @throws ConcurrencyFailureException if the ID does not exist + */ + public void deleteVersionRoot(long versionRootId); + + /** + * Get all the version roots in a given store + * + * @param store The store. + * @return A List of VersionRoots. In id order. + */ + public List getAllInStore(long storeId); + + /** + * Get the VersionRoot corresponding to the given id. + * @param store The store + * @param id The version id. + * @return The VersionRoot or null if not found. + */ + public AVMVersionRootEntity getByVersionID(long storeId, int version); + + /** + * Get one from its root. + * @param root The root to match. + * @return The version root or null. + */ + public AVMVersionRootEntity getByRoot(long rootNodeId); + + /** + * Get the version of a store by dates. + * @param store The store. + * @param from The starting date. May be null but not with to null also. + * @param to The ending date. May be null but not with from null also. + * @return A List of VersionRoots. + */ + public List getByDates(long storeId, Date from, Date to); + + /** + * Get the highest numbered version in a store. + * @param store The store. + * @return The highest numbered version. + */ + public AVMVersionRootEntity getMaxVersion(long storeId); + + /** + * Get the highest numbered id from all the versions in a store. + * @param store The store. + * @return The highest numbered id. + */ + public Long getMaxVersionID(long storeId); + + public AVMVersionLayeredNodeEntryEntity createVersionLayeredNodeEntry(long versionRootId, String md5sum, String path); + + public void deleteVersionLayeredNodeEntries(long versionRootId); + + public List getVersionLayeredNodeEntries(long versionRootId); +} diff --git a/source/java/org/alfresco/repo/domain/avm/AVMVersionRootEntity.java b/source/java/org/alfresco/repo/domain/avm/AVMVersionRootEntity.java new file mode 100644 index 0000000000..5075ac631c --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AVMVersionRootEntity.java @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import java.io.Serializable; + +import org.alfresco.util.EqualsHelper; + +/** + * Entity bean for avm_version_roots table + * + * @author janv + * @since 3.2 + */ +public class AVMVersionRootEntity implements Serializable +{ + private static final long serialVersionUID = -3373271203895368258L; + + private Long id; + private Integer version; + private Long storeId; + private Long rootNodeId; + private Long createdDate; + private String creator; + private String tag; + private String description; + + public Long getId() + { + return id; + } + + public void setId(Long id) + { + this.id = id; + } + + public Integer getVersion() + { + return version; + } + + public void setVersion(Integer version) + { + this.version = version; + } + + public Long getRootNodeId() + { + return rootNodeId; + } + + public void setRootNodeId(Long rootNodeId) + { + this.rootNodeId = rootNodeId; + } + + public Long getStoreId() + { + return storeId; + } + + public void setStoreId(Long storeId) + { + this.storeId = storeId; + } + + public Long getCreatedDate() + { + return createdDate; + } + + public void setCreatedDate(Long createdDate) + { + this.createdDate = createdDate; + } + + public String getCreator() + { + return creator; + } + + public void setCreator(String creator) + { + this.creator = creator; + } + + public String getTag() + { + return tag; + } + + public void setTag(String tag) + { + this.tag = tag; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + @Override + public int hashCode() + { + return (id == null ? 0 : id.hashCode()); + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + else if (obj instanceof AVMVersionRootEntity) + { + AVMVersionRootEntity that = (AVMVersionRootEntity) obj; + return (EqualsHelper.nullSafeEquals(this.id, that.id)); + } + else + { + return false; + } + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder(512); + sb.append("AVMVersionRootEntity") + .append("[ ID=").append(id) + .append(", version=").append(version) + .append(", storeId=").append(storeId) + .append(", rootNodeId=").append(rootNodeId) + .append(", createdDate=").append(createdDate) + .append(", creator=").append(creator) + .append(", tag=").append(tag) + .append(", description=").append(description) + .append("]"); + return sb.toString(); + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/AbstractAVMNodeDAOImpl.java b/source/java/org/alfresco/repo/domain/avm/AbstractAVMNodeDAOImpl.java new file mode 100644 index 0000000000..5772a8c033 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AbstractAVMNodeDAOImpl.java @@ -0,0 +1,713 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.alfresco.repo.cache.NullCache; +import org.alfresco.repo.cache.SimpleCache; +import org.alfresco.repo.cache.lookup.EntityLookupCache; +import org.alfresco.repo.cache.lookup.EntityLookupCache.EntityLookupCallbackDAO; +import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.repo.domain.QNameDAO; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.Pair; +import org.alfresco.util.ParameterCheck; +import org.springframework.dao.ConcurrencyFailureException; + +/** + * Abstract implementation for AVMNode DAO. + *

+ * This provides basic services such as caching but defers to the underlying implementation + * for CRUD operations. + * + * @author janv + * @since 3.2 + */ +public abstract class AbstractAVMNodeDAOImpl implements AVMNodeDAO +{ + private static final String CACHE_REGION_AVM_NODE = "AVMNode"; + private static final String CACHE_REGION_AVM_NODE_PROP = "AVMNodeProp"; + + private final AVMNodeEntityCallbackDAO avmNodeEntityDaoCallback; + private final AVMNodePropertyEntityCallbackDAO avmNodePropEntityDaoCallback; + + private QNameDAO qnameDAO; + + /** + * Cache for the AVM node entity:
+ * KEY: ID (node)
+ * VALUE: AVMNodeEntity
+ * VALUE KEY: None
+ */ + private EntityLookupCache avmNodeCache; + + /** + * Cache for the AVM node property entity:
+ * KEY: Pair of IDs (node, qname)
+ * VALUE: AVMNodePropertyEntity
+ * VALUE KEY: None
+ */ + private EntityLookupCache, AVMNodePropertyEntity, Serializable> avmNodePropCache; + + /** + * Set the cache to use for avm_aspects lookups (optional). + * + * @param avmNodeAspectsCache + */ + private SimpleCache avmNodeAspectsCache; + + /** + * Set the cache to use for avm_nodes lookups (optional). + * + * @param avmNodeCache the cache of IDs to AVMNodeEntities + */ + public void setAvmNodeCache(SimpleCache avmNodeCache) + { + this.avmNodeCache = new EntityLookupCache( + avmNodeCache, + CACHE_REGION_AVM_NODE, + avmNodeEntityDaoCallback); + } + + /** + * Set the cache to use for avm_node_properties lookups (optional). + * + * @param avmNodePropCache the cache of IDs to AVMNodePropertyEntities + */ + public void setAvmNodePropertyCache(SimpleCache avmNodePropCache) + { + this.avmNodePropCache = new EntityLookupCache, AVMNodePropertyEntity, Serializable>( + avmNodePropCache, + CACHE_REGION_AVM_NODE_PROP, + avmNodePropEntityDaoCallback); + } + + /** + * Set the cache to use for avm_aspects lookups (optional). + * + * @param avmNodeAspectsCache + */ + public void setAvmNodeAspectsCache(SimpleCache avmNodeAspectsCache) + { + this.avmNodeAspectsCache = avmNodeAspectsCache; + } + + public void setQnameDAO(QNameDAO qnameDAO) + { + this.qnameDAO = qnameDAO; + } + + + /** + * Default constructor. + *

+ * This sets up the DAO accessors to bypass any caching to handle the case where the caches are not + * supplied in the setters. + */ + @SuppressWarnings("unchecked") + public AbstractAVMNodeDAOImpl() + { + this.avmNodeEntityDaoCallback = new AVMNodeEntityCallbackDAO(); + this.avmNodeCache = new EntityLookupCache(avmNodeEntityDaoCallback); + + this.avmNodePropEntityDaoCallback = new AVMNodePropertyEntityCallbackDAO(); + this.avmNodePropCache = new EntityLookupCache, AVMNodePropertyEntity, Serializable>(avmNodePropEntityDaoCallback); + + this.avmNodeAspectsCache = (SimpleCache)new NullCache(); + } + + public AVMNodeEntity createNode(AVMNodeEntity nodeEntity) + { + ParameterCheck.mandatory("nodeEntity", nodeEntity); + + nodeEntity.setVers(0L); + + Pair entityPair = avmNodeCache.getOrCreateByValue(nodeEntity); + return entityPair.getSecond(); + } + + /** + * {@inheritDoc} + */ + public AVMNodeEntity getNode(long nodeId) + { + Pair entityPair = avmNodeCache.getByKey(nodeId); + if (entityPair == null) + { + return null; + } + return entityPair.getSecond(); + } + + /** + * {@inheritDoc} + */ + public void clearNodeEntityCache() + { + avmNodeCache.clear(); + } + + /** + * {@inheritDoc} + */ + public void updateNode(AVMNodeEntity nodeEntity) + { + ParameterCheck.mandatory("nodeEntity", nodeEntity); + ParameterCheck.mandatory("nodeEntity.getId()", nodeEntity.getId()); + ParameterCheck.mandatory("nodeEntity.getVers()", nodeEntity.getVers()); + + int updated = avmNodeCache.updateValue(nodeEntity.getId(), nodeEntity); + if (updated < 1) + { + throw new ConcurrencyFailureException("AVMNode with ID (" + nodeEntity.getId() + ") no longer exists or has been updated concurrently"); + } + nodeEntity.setVers(nodeEntity.getVers()+1); + } + + /** + * {@inheritDoc} + * @deprecated + */ + public void updateNodeModTimeAndGuid(AVMNodeEntity nodeEntity) + { + ParameterCheck.mandatory("nodeEntity", nodeEntity); + ParameterCheck.mandatory("nodeEntity.getId()", nodeEntity.getId()); + ParameterCheck.mandatory("nodeEntity.getGuid()", nodeEntity.getGuid()); + ParameterCheck.mandatory("nodeEntity.getModifiedDate()", nodeEntity.getModifiedDate()); + ParameterCheck.mandatory("nodeEntity.getVers()", nodeEntity.getVers()); + + int updated = updateNodeEntityModTimeAndGuid(nodeEntity); + if (updated < 1) + { + throw new ConcurrencyFailureException("AVMNode with ID (" + nodeEntity.getId() + ") no longer exists or has been updated concurrently"); + } + nodeEntity.setVers(nodeEntity.getVers()+1); + + // update cache + avmNodeCache.removeByKey(nodeEntity.getId()); + avmNodeCache.getByKey(nodeEntity.getId()); + } + + /** + * {@inheritDoc} + * @deprecated + */ + public void updateNodeModTimeAndContentData(AVMNodeEntity nodeEntity) + { + ParameterCheck.mandatory("nodeEntity", nodeEntity); + ParameterCheck.mandatory("nodeEntity.getId()", nodeEntity.getId()); + ParameterCheck.mandatory("nodeEntity.getModifiedDate()", nodeEntity.getModifiedDate()); + ParameterCheck.mandatory("nodeEntity.getVers()", nodeEntity.getVers()); + + int updated = updateNodeEntityModTimeAndContentData(nodeEntity); + if (updated < 1) + { + throw new ConcurrencyFailureException("AVMNode with ID (" + nodeEntity.getId() + ") no longer exists or has been updated concurrently"); + } + nodeEntity.setVers(nodeEntity.getVers()+1); + + // update cache + avmNodeCache.removeByKey(nodeEntity.getId()); + avmNodeCache.getByKey(nodeEntity.getId()); + } + + /** + * {@inheritDoc} + */ + public List getNodesNewInStore(long storeId) + { + return getNodeEntitiesNewInStore(storeId); + } + + /** + * {@inheritDoc} + */ + public List getLayeredNodesNewInStore(long storeId) + { + return getLayeredNodeEntitiesNewInStore(storeId); + } + + /** + * {@inheritDoc} + */ + public List getLayeredNodesNewInStoreIDs(long storeId) + { + return getLayeredNodeEntityIdsNewInStore(storeId); + } + + /** + * {@inheritDoc} + */ + public List getNodeOrphans() + { + return getNodeEntityOrphans(); + } + + /** + * {@inheritDoc} + */ + public void updateNodesClearNewInStore(long storeId) + { + updateNodeEntitiesClearNewInStore(storeId); + } + + /** + * {@inheritDoc} + */ + public void deleteNode(long nodeId) + { + Pair entityPair = avmNodeCache.getByKey(nodeId); + if (entityPair == null) + { + return; + } + + int deleted = avmNodeCache.deleteByKey(nodeId); + if (deleted < 1) + { + throw new ConcurrencyFailureException("AVMNode with ID " + nodeId + " no longer exists"); + } + } + + /** + * {@inheritDoc} + */ + public List getAllLayeredDirectories() + { + return getAllLayeredDirectoryNodeEntities(); + } + + /** + * {@inheritDoc} + */ + public List getAllLayeredFiles() + { + return getAllLayeredFileNodeEntities(); + } + + /** + * {@inheritDoc} + */ + public List getAVMNodesByAclId(long aclId) + { + return getAVMNodeEntityIdsByAclId(aclId); + } + + /** + * {@inheritDoc} + */ + public void getContentUrls(ContentUrlHandler handler) + { + getPlainFileContentUrls(handler); + } + + /** + * Callback for avm_nodes DAO + */ + private class AVMNodeEntityCallbackDAO implements EntityLookupCallbackDAO + { + private final Pair convertEntityToPair(AVMNodeEntity nodeEntity) + { + if (nodeEntity == null) + { + return null; + } + else + { + return new Pair(nodeEntity.getId(), nodeEntity); + } + } + + public Serializable getValueKey(AVMNodeEntity value) + { + return null; + } + + public Pair createValue(AVMNodeEntity value) + { + AVMNodeEntity entity = createNodeEntity(value); + return convertEntityToPair(entity); + } + + public Pair findByKey(Long key) + { + AVMNodeEntity entity = getNodeEntity(key); + return convertEntityToPair(entity); + } + + public Pair findByValue(AVMNodeEntity value) + { + if ((value != null) && (value.getId() != null)) + { + return findByKey(value.getId()); + } + return null; + } + + public int updateValue(Long key, AVMNodeEntity value) + { + return updateNodeEntity(value); + } + + public int deleteByKey(Long key) + { + return deleteNodeEntity(key); + } + + public int deleteByValue(AVMNodeEntity value) + { + // TODO + throw new UnsupportedOperationException("deleteByValue(AVMNodeEntity)"); + } + } + + protected abstract AVMNodeEntity createNodeEntity(AVMNodeEntity nodeEntity); + protected abstract AVMNodeEntity getNodeEntity(long nodeId); + protected abstract int updateNodeEntity(AVMNodeEntity nodeEntity); + protected abstract int updateNodeEntityModTimeAndGuid(AVMNodeEntity nodeEntity); + protected abstract int updateNodeEntityModTimeAndContentData(AVMNodeEntity nodeEntity); + protected abstract int deleteNodeEntity(long nodeId); + protected abstract void updateNodeEntitiesClearNewInStore(long storeId); + protected abstract List getNodeEntitiesNewInStore(long storeId); + protected abstract List getLayeredNodeEntitiesNewInStore(long storeId); + protected abstract List getLayeredNodeEntityIdsNewInStore(long storeId); + protected abstract List getNodeEntityOrphans(); + protected abstract List getAllLayeredDirectoryNodeEntities(); + protected abstract List getAllLayeredFileNodeEntities(); + protected abstract List getAVMNodeEntityIdsByAclId(long aclId); + protected abstract void getPlainFileContentUrls(ContentUrlHandler handler); + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public Set getAspects(long nodeId) + { + Set aspects = (Set)avmNodeAspectsCache.get(nodeId); + if (aspects != null) + { + return aspects; + } + + Set aspectQNames = null; + + // Get it from the DB + List aspectIds = getAspectEntities(nodeId); + if (aspectIds != null) + { + // Convert to QNames + aspectQNames = qnameDAO.convertIdsToQNames(new HashSet(aspectIds)); + } + else + { + aspectQNames = new HashSet(0); + } + + // Cache it + avmNodeAspectsCache.put(nodeId, aspectQNames); + + return aspectQNames; + } + + /** + * {@inheritDoc} + */ + public void createAspect(long nodeId, QName qname) + { + Set aspects = getAspects(nodeId); + if (aspects.contains(qname)) + { + return; + } + + // Get the persistent ID for the QName + Pair qnamePair = qnameDAO.getQName(qname); + if (qnamePair != null) + { + Long qnameId = qnamePair.getFirst(); + createAspectEntity(nodeId, qnameId); + + // Cache it + aspects.add(qname); + avmNodeAspectsCache.put(new Long(nodeId), aspects); + } + } + + /** + * {@inheritDoc} + */ + public void deleteAspect(long nodeId, QName qname) + { + Set aspects = getAspects(nodeId); + if (! aspects.contains(qname)) + { + return; + } + + // Get the persistent ID for the QName + Pair qnamePair = qnameDAO.getQName(qname); + if (qnamePair != null) + { + Long qnameId = qnamePair.getFirst(); + + int deleted = deleteAspectEntity(nodeId, qnameId); + if (deleted < 1) + { + throw new ConcurrencyFailureException("AVMNodeAspect (" + nodeId + ", " + qnameId + ") no longer exists"); + } + + // Remove from cache + aspects.remove(qname); + avmNodeAspectsCache.put(new Long(nodeId), aspects); + } + } + + /** + * {@inheritDoc} + */ + public void deleteAspects(long nodeId) + { + Set naEntities = getAspects(nodeId); + if (naEntities.size() == 0) + { + return; + } + + int deleted = deleteAspectEntities(nodeId); + if (deleted < 1) + { + throw new ConcurrencyFailureException("AVMNodeAspects for node ID " + nodeId + " no longer exist"); + } + + // Remove from cache + avmNodeAspectsCache.remove(nodeId); + } + + protected abstract List getAspectEntities(long nodeId); + protected abstract void createAspectEntity(long nodeId, long qnameId); + protected abstract int deleteAspectEntity(long nodeId, long qnameId); + protected abstract int deleteAspectEntities(long nodeId); + + /** + * {@inheritDoc} + */ + public void createOrUpdateNodeProperty(long nodeId, QName qname, PropertyValue value) + { + ParameterCheck.mandatory("qname", qname); + + // Get the persistent ID for the QName + Pair qnamePair = qnameDAO.getOrCreateQName(qname); + Long qnameId = qnamePair.getFirst(); + + AVMNodePropertyEntity propEntity = new AVMNodePropertyEntity(nodeId, qnameId, value); + + Pair key = new Pair(nodeId, propEntity.getQnameId()); + Pair, AVMNodePropertyEntity> entityPair = avmNodePropCache.getByKey(key); + + if (entityPair != null) + { + int updated = avmNodePropCache.updateValue(key, propEntity); + if (updated < 1) + { + throw new ConcurrencyFailureException("AVMNodePropertyEntity with key (" + propEntity.getNodeId() + ", " + propEntity.getQnameId() + ") no longer exists"); + } + } + else + { + avmNodePropCache.getOrCreateByValue(propEntity); + } + } + + /** + * {@inheritDoc} + */ + /* + public AVMNodePropertyEntity getNodeProperty(long nodeId, QName qname) + { + // Get the persistent ID for the QName + Pair qnamePair = qnameDAO.getQName(qname); + if (qnamePair != null) + { + Long qnameId = qnamePair.getFirst(); + + Pair key = new Pair(nodeId, qnameId); + Pair, AVMNodePropertyEntity> entityPair = avmNodePropCache.getByKey(key); + if (entityPair == null) + { + return null; + } + return entityPair.getSecond(); + } + } + */ + + /** + * {@inheritDoc} + */ + public Map getNodeProperties(long nodeId) + { + // TODO not via cache + List npEntities = getNodePropertyEntities(nodeId); + Map nProps = new HashMap(npEntities.size()); + + for (AVMNodePropertyEntity npEntity : npEntities) + { + Pair qnamePair = qnameDAO.getQName(npEntity.getQnameId()); + if (qnamePair != null) + { + nProps.put(qnamePair.getSecond(), npEntity); + } + } + + return nProps; + } + + /** + * {@inheritDoc} + */ + public void deleteNodeProperty(long nodeId, QName qname) + { + // Get the persistent ID for the QName + Pair qnamePair = qnameDAO.getQName(qname); + if (qnamePair != null) + { + Long qnameId = qnamePair.getFirst(); + + Pair key = new Pair(nodeId, qnameId); + Pair, AVMNodePropertyEntity> entityPair = avmNodePropCache.getByKey(key); + if (entityPair == null) + { + return; + } + + int deleted = avmNodePropCache.deleteByKey(key); + if (deleted < 1) + { + throw new ConcurrencyFailureException("AVMNodeProperty (" + nodeId + ", " + qnameId + ") no longer exists"); + } + } + } + + /** + * {@inheritDoc} + */ + public void deleteNodeProperties(long nodeId) + { + Map nProps = getNodeProperties(nodeId); + if (nProps.size() == 0) + { + return; + } + + for (QName propQName : nProps.keySet()) + { + deleteNodeProperty(nodeId, propQName); + } + + // TODO single delete + cache(s) + /* + int deleted = deleteNodePropertyEntities(nodeId); + if (deleted < 1) + { + throw new ConcurrencyFailureException("AVMNodeProperties for node ID " + nodeId + " no longer exist"); + } + + // TODO clear node property cache for this node id + */ + } + + /** + * Callback for avm_node_properties DAO + */ + private class AVMNodePropertyEntityCallbackDAO implements EntityLookupCallbackDAO, AVMNodePropertyEntity, Serializable> + { + private final Pair, AVMNodePropertyEntity> convertEntityToPair(AVMNodePropertyEntity nodePropEntity) + { + if (nodePropEntity == null) + { + return null; + } + else + { + Pair key = new Pair(nodePropEntity.getNodeId(), nodePropEntity.getQnameId()); + return new Pair, AVMNodePropertyEntity>(key, nodePropEntity); + } + } + + public Serializable getValueKey(AVMNodePropertyEntity value) + { + return null; + } + + public Pair, AVMNodePropertyEntity> createValue(AVMNodePropertyEntity value) + { + insertNodePropertyEntity(value); + return convertEntityToPair(value); + } + + public Pair, AVMNodePropertyEntity> findByKey(Pair key) + { + AVMNodePropertyEntity entity = getNodePropertyEntity(key.getFirst(), key.getSecond()); + return convertEntityToPair(entity); + } + + public Pair, AVMNodePropertyEntity> findByValue(AVMNodePropertyEntity value) + { + if ((value.getNodeId() != null) && (value.getQnameId() != null)) + { + return findByKey(new Pair(value.getNodeId(), value.getQnameId())); + } + return null; + } + + public int updateValue(Pair key, AVMNodePropertyEntity value) + { + return updateNodePropertyEntity(value); + } + + public int deleteByKey(Pair key) + { + return deleteNodePropertyEntity(key.getFirst(), key.getSecond()); + } + + public int deleteByValue(AVMNodePropertyEntity value) + { + throw new UnsupportedOperationException("deleteByValue(AVMNodePropertyEntity)"); + } + } + + protected abstract void insertNodePropertyEntity(AVMNodePropertyEntity propEntity); + protected abstract int updateNodePropertyEntity(AVMNodePropertyEntity propEntity); + protected abstract AVMNodePropertyEntity getNodePropertyEntity(long nodeId, long qnameId); + protected abstract List getNodePropertyEntities(long nodeId); + protected abstract int deleteNodePropertyEntity(long nodeId, long qnameId); + protected abstract int deleteNodePropertyEntities(long nodeId); +} diff --git a/source/java/org/alfresco/repo/domain/avm/AbstractAVMNodeLinksDAOImpl.java b/source/java/org/alfresco/repo/domain/avm/AbstractAVMNodeLinksDAOImpl.java new file mode 100644 index 0000000000..18084ce18d --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AbstractAVMNodeLinksDAOImpl.java @@ -0,0 +1,527 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.repo.cache.SimpleCache; +import org.alfresco.repo.cache.lookup.EntityLookupCache; +import org.alfresco.repo.cache.lookup.EntityLookupCache.EntityLookupCallbackDAO; +import org.alfresco.util.Pair; +import org.alfresco.util.ParameterCheck; +import org.springframework.dao.ConcurrencyFailureException; + +/** + * Abstract implementation for AVMNodeLinks DAO. + *

+ * This provides basic services such as caching but defers to the underlying implementation + * for CRUD operations. + * + * @author janv + * @since 3.2 + */ +public abstract class AbstractAVMNodeLinksDAOImpl implements AVMNodeLinksDAO +{ + private static final String CACHE_REGION_AVM_CHILD_ENTRY = "AVMChildEntry"; + private static final String CACHE_REGION_AVM_HISTORY_LINK = "AVMHistoryLink"; + + private final AVMChildEntryEntityCallbackDAO avmChildEntryEntityDaoCallback; + private final AVMHistoryLinkEntityCallbackDAO avmHistoryLinkEntityDaoCallback; + + /** + * Cache for the AVM child entry entity:
+ * KEY: ChildKey
+ * VALUE: AVMChildEntryEntity
+ * VALUE KEY: Pair of node IDs (parent, child)
+ */ + private EntityLookupCache> avmChildEntryCache; + + /** + * Cache for the AVM history link entity:
+ * KEY: Descendent ID
+ * VALUE: AVMHistoryLinkEntity
+ * VALUE KEY: AVMHistoryLinkEntity
+ */ + private EntityLookupCache avmHistoryLinkCache; + + /** + * Set the cache to use for avm_child_entry lookups (optional). + * + * @param avmChildEntryCache the cache of IDs to AVMChildEntryEntities + */ + public void setAvmChildEntryCache(SimpleCache avmChildEntryCache) + { + this.avmChildEntryCache = new EntityLookupCache>( + avmChildEntryCache, + CACHE_REGION_AVM_CHILD_ENTRY, + avmChildEntryEntityDaoCallback); + } + + /** + * Set the cache to use for avm_history_link lookups (optional). + * + * @param avmHistoryLinkCache the cache of ID to ID (from descendent to ancestor) + */ + public void setAvmHistoryLinkCache(SimpleCache avmHistoryLinkCache) + { + this.avmHistoryLinkCache = new EntityLookupCache( + avmHistoryLinkCache, + CACHE_REGION_AVM_HISTORY_LINK, + avmHistoryLinkEntityDaoCallback); + } + + /** + * Default constructor. + *

+ * This sets up the DAO accessors to bypass any caching to handle the case where the caches are not + * supplied in the setters. + */ + public AbstractAVMNodeLinksDAOImpl() + { + this.avmChildEntryEntityDaoCallback = new AVMChildEntryEntityCallbackDAO(); + this.avmChildEntryCache = new EntityLookupCache>(avmChildEntryEntityDaoCallback); + + this.avmHistoryLinkEntityDaoCallback = new AVMHistoryLinkEntityCallbackDAO(); + this.avmHistoryLinkCache = new EntityLookupCache(avmHistoryLinkEntityDaoCallback); + } + + /** + * {@inheritDoc} + */ + public void createChildEntry(long parentNodeId, String name, long childNodeId) + { + ParameterCheck.mandatory("name", name); + + AVMChildEntryEntity ceEntity = new AVMChildEntryEntity(); + ceEntity.setParentNodeId(parentNodeId); + ceEntity.setName(name); + ceEntity.setChildNodeId(childNodeId); + + Pair entityPair = avmChildEntryCache.getOrCreateByValue(ceEntity); + entityPair.getSecond(); + } + + /** + * {@inheritDoc} + */ + public AVMChildEntryEntity getChildEntry(long parentNodeId, String name) + { + ParameterCheck.mandatory("name", name); + + Pair entityPair = avmChildEntryCache.getByKey(new ChildKey(parentNodeId, name)); + if (entityPair == null) + { + return null; + } + return entityPair.getSecond(); + } + + /** + * {@inheritDoc} + */ + public List getChildEntriesByParent(long parentNodeId) + { + List result = getChildEntryEntitiesByParent(parentNodeId); + if (result == null) + { + result = new ArrayList(0); + } + + return result; + } + + /** + * {@inheritDoc} + */ + public AVMChildEntryEntity getChildEntry(long parentNodeId, long childNodeId) + { + AVMChildEntryEntity ceEntity = new AVMChildEntryEntity(); + ceEntity.setParentNodeId(parentNodeId); + ceEntity.setChildNodeId(childNodeId); + + Pair entityPair = avmChildEntryCache.getByValue(ceEntity); + if (entityPair == null) + { + return null; + } + return entityPair.getSecond(); + } + + /** + * {@inheritDoc} + */ + public List getChildEntriesByChild(long childNodeId) + { + List result = getChildEntryEntitiesByChild(childNodeId); + if (result == null) + { + result = new ArrayList(0); + } + + return result; + } + + /** + * {@inheritDoc} + */ + public void deleteChildEntry(AVMChildEntryEntity childEntryEntity) + { + ParameterCheck.mandatory("childEntryEntity", childEntryEntity); + + ParameterCheck.mandatory("childEntryEntity.getParentNodeId()", childEntryEntity.getParentNodeId()); + ParameterCheck.mandatory("childEntryEntity.getName()", childEntryEntity.getName()); + + ChildKey key = new ChildKey(childEntryEntity.getParentNodeId(), childEntryEntity.getName()); + Pair entityPair = avmChildEntryCache.getByKey(key); + if (entityPair == null) + { + return; + } + + int deleted = avmChildEntryCache.deleteByKey(key); + if (deleted < 1) + { + throw new ConcurrencyFailureException("AVMChildEntry for parent/name (" + key.getParentNodeId() + ", " + key.getName() + ") no longer exists"); + } + } + + /** + * {@inheritDoc} + */ + public void deleteChildEntriesByParent(long parentNodeId) + { + List ceEntities = getChildEntriesByParent(parentNodeId); + if (ceEntities.size() == 0) + { + return; + } + + for (AVMChildEntryEntity ceEntity : ceEntities) + { + deleteChildEntry(ceEntity); + } + + // TODO single delete + cache(s) + + /* + int deleted = deleteChildEntryEntities(parentNodeId); + if (deleted < 1) + { + throw new ConcurrencyFailureException("AVMChildEntries for parent node ID " + parentNodeId + " no longer exist"); + } + + // TODO clear child entry cache for this parent node id + */ + } + + private class ChildKey implements Serializable + { + private static final long serialVersionUID = 848161072437569305L; + + /** + * The Parent Node Id + */ + private Long parentNodeId; + + /** + * The child's name. + */ + private String name; + + public ChildKey(Long parentNodeId, String name) + { + this.parentNodeId = parentNodeId; + this.name = name; + } + + public Long getParentNodeId() + { + return parentNodeId; + } + + public String getName() + { + return name; + } + + /** + * Override of equals. + */ + @Override + public boolean equals(Object other) + { + if (this == other) + { + return true; + } + if (!(other instanceof ChildKey)) + { + return false; + } + ChildKey o = (ChildKey)other; + return parentNodeId.equals(o.getParentNodeId()) && + name.equalsIgnoreCase(o.getName()); + } + + /** + * Override of hashCode. + */ + public int hashCode() + { + return parentNodeId.hashCode() + name.toLowerCase().hashCode(); + } + } + + /** + * Callback for avm_child_entry DAO + */ + private class AVMChildEntryEntityCallbackDAO implements EntityLookupCallbackDAO> + { + private final Pair convertEntityToPair(AVMChildEntryEntity ceEntity) + { + if (ceEntity == null) + { + return null; + } + else + { + return new Pair(new ChildKey(ceEntity.getParentNodeId(), ceEntity.getName()), ceEntity); + } + } + + public Pair getValueKey(AVMChildEntryEntity value) + { + return new Pair(value.getParentNodeId(), value.getChildId()); + } + + public Pair createValue(AVMChildEntryEntity value) + { + createChildEntryEntity(value); + return convertEntityToPair(value); + } + + public Pair findByKey(ChildKey key) + { + AVMChildEntryEntity entity = getChildEntryEntity(key.getParentNodeId(), key.getName()); + return convertEntityToPair(entity); + } + + public Pair findByValue(AVMChildEntryEntity value) + { + AVMChildEntryEntity entity = getChildEntryEntity(value.getParentNodeId(), value.getChildId()); + return convertEntityToPair(entity); + } + + public int updateValue(ChildKey key, AVMChildEntryEntity value) + { + throw new UnsupportedOperationException("updateValue(Long, AVMChildEntryEntity"); + } + + public int deleteByKey(ChildKey key) + { + return deleteChildEntryEntity(key.getParentNodeId(), key.getName()); + } + + public int deleteByValue(AVMChildEntryEntity value) + { + return deleteChildEntryEntity(value.getParentNodeId(), value.getChildId()); + } + } + + protected abstract List getChildEntryEntitiesByParent(long parentNodeId); + protected abstract List getChildEntryEntitiesByChild(long childNodeId); + + protected abstract AVMChildEntryEntity getChildEntryEntity(long parentNodeId, String name); + protected abstract AVMChildEntryEntity getChildEntryEntity(long parentNodeId, long childNodeId); + protected abstract AVMChildEntryEntity getChildEntryEntity(AVMChildEntryEntity childEntryEntity); + + protected abstract void createChildEntryEntity(AVMChildEntryEntity childEntryEntity); + protected abstract int deleteChildEntryEntity(long parentNodeId, String name); + protected abstract int deleteChildEntryEntity(long parentNodeId, long childNodeId); + protected abstract int deleteChildEntryEntities(long parentNodeId); + + /** + * {@inheritDoc} + */ + public void createMergeLink(long mergeFromNodeId, long mergeToNodeId) + { + createMergeLinkEntity(mergeFromNodeId, mergeToNodeId); + } + + /** + * {@inheritDoc} + */ + public void deleteMergeLink(long mergeFromNodeId, long mergeToNodeId) + { + AVMMergeLinkEntity mlEntity = getMergeLinkByTo(mergeToNodeId); + if (mlEntity == null) + { + return; + } + + int deleted = deleteMergeLinkEntity(mergeFromNodeId, mergeToNodeId); + if (deleted < 1) + { + throw new ConcurrencyFailureException("AVMMergeLink (" + mergeFromNodeId + ", " + mergeToNodeId + ") no longer exists"); + } + } + + /** + * {@inheritDoc} + */ + public AVMMergeLinkEntity getMergeLinkByTo(long mergeToNodeId) + { + return getMergeLinkEntityByTo(mergeToNodeId); + } + + /** + * {@inheritDoc} + */ + public List getMergeLinksByFrom(long mergeFromNodeId) + { + return getMergeLinkEntitiesByFrom(mergeFromNodeId); + } + + protected abstract void createMergeLinkEntity(long mergeFromNodeId, long mergeToNodeId); + protected abstract int deleteMergeLinkEntity(long mergeFromNodeId, long mergeToNodeId); + protected abstract AVMMergeLinkEntity getMergeLinkEntityByTo(long mergeToNodeId); + protected abstract List getMergeLinkEntitiesByFrom(long mergeFromNodeId); + + /** + * {@inheritDoc} + */ + public void createHistoryLink(long ancestorNodeId, long descendentNodeId) + { + AVMHistoryLinkEntity hlEntity = new AVMHistoryLinkEntity(ancestorNodeId, descendentNodeId); + + avmHistoryLinkCache.getOrCreateByValue(hlEntity); // ignore return value + } + + /** + * {@inheritDoc} + */ + public void deleteHistoryLink(long ancestorNodeId, long descendentNodeId) + { + AVMHistoryLinkEntity hlEntity = new AVMHistoryLinkEntity(ancestorNodeId, descendentNodeId); + Pair entityPair = avmHistoryLinkCache.getByValue(hlEntity); + if (entityPair == null) + { + return; + } + + int deleted = avmHistoryLinkCache.deleteByValue(hlEntity); + if (deleted < 1) + { + throw new ConcurrencyFailureException("AVMHistoryLinkEntity (" + ancestorNodeId + ", " + descendentNodeId + ") no longer exists"); + } + } + + /** + * {@inheritDoc} + */ + public AVMHistoryLinkEntity getHistoryLinkByDescendent(long descendentNodeId) + { + Pair entityPair = avmHistoryLinkCache.getByKey(descendentNodeId); + if (entityPair == null) + { + return null; + } + return entityPair.getSecond(); + } + + /** + * {@inheritDoc} + */ + public List getHistoryLinksByAncestor(long ancestorNodeId) + { + // not via cache + return getHistoryLinkEntitiesByAncestor(ancestorNodeId); + } + + /** + * Callback for avm_history_link DAO + */ + private class AVMHistoryLinkEntityCallbackDAO implements EntityLookupCallbackDAO + { + private final Pair convertEntityToPair(AVMHistoryLinkEntity hlEntity) + { + if (hlEntity == null) + { + return null; + } + else + { + return new Pair(hlEntity.getDescendentNodeId(), hlEntity); + } + } + + public AVMHistoryLinkEntity getValueKey(AVMHistoryLinkEntity value) + { + return value; + } + + public Pair createValue(AVMHistoryLinkEntity value) + { + createHistoryLinkEntity(value.getAncestorNodeId(), value.getDescendentNodeId()); + return convertEntityToPair(value); + } + + public Pair findByKey(Long key) + { + AVMHistoryLinkEntity entity = getHistoryLinkEntityByDescendent(key); + return convertEntityToPair(entity); + } + + public Pair findByValue(AVMHistoryLinkEntity value) + { + AVMHistoryLinkEntity entity = getHistoryLinkEntity(value.getAncestorNodeId(), value.getDescendentNodeId()); + return convertEntityToPair(entity); + } + + public int updateValue(Long key, AVMHistoryLinkEntity value) + { + throw new UnsupportedOperationException("updateValue(Long, AVMHistoryLinkEntity"); + } + + public int deleteByKey(Long key) + { + AVMHistoryLinkEntity entity = getHistoryLinkEntityByDescendent(key); + return deleteHistoryLinkEntity(entity.getAncestorNodeId(), entity.getDescendentNodeId()); + } + + public int deleteByValue(AVMHistoryLinkEntity value) + { + return deleteHistoryLinkEntity(value.getAncestorNodeId(), value.getDescendentNodeId()); + } + } + + protected abstract void createHistoryLinkEntity(long ancestorNodeId, long descendentNodeId); + protected abstract int deleteHistoryLinkEntity(long ancestorNodeId, long descendentNodeId); + protected abstract AVMHistoryLinkEntity getHistoryLinkEntity(long ancestorNodeId, long descendentNodeId); + protected abstract AVMHistoryLinkEntity getHistoryLinkEntityByDescendent(long descendentNodeId); + protected abstract List getHistoryLinkEntitiesByAncestor(long ancestorNodeId); +} diff --git a/source/java/org/alfresco/repo/domain/avm/AbstractAVMStoreDAOImpl.java b/source/java/org/alfresco/repo/domain/avm/AbstractAVMStoreDAOImpl.java new file mode 100644 index 0000000000..cba0426093 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AbstractAVMStoreDAOImpl.java @@ -0,0 +1,556 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.cache.SimpleCache; +import org.alfresco.repo.cache.lookup.EntityLookupCache; +import org.alfresco.repo.cache.lookup.EntityLookupCache.EntityLookupCallbackDAO; +import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.repo.domain.QNameDAO; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.Pair; +import org.alfresco.util.ParameterCheck; +import org.springframework.dao.ConcurrencyFailureException; + +/** + * Abstract implementation for AVMStore DAO. + *

+ * This provides basic services such as caching but defers to the underlying implementation + * for CRUD operations. + * + * @author janv + * @since 3.2 + */ +public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO +{ + private static final String CACHE_REGION_AVM_STORE = "AVMStore"; + private static final String CACHE_REGION_AVM_STORE_PROP = "AVMStoreProp"; + + private final AVMStoreEntityCallbackDAO avmStoreEntityDaoCallback; + private final AVMStorePropertyEntityCallbackDAO avmStorePropEntityDaoCallback; + + private QNameDAO qnameDAO; + + /** + * Cache for the AVM store entity:
+ * KEY: ID
+ * VALUE: AVMStoreEntity
+ * VALUE KEY: Name
+ */ + private EntityLookupCache avmStoreCache; + + /** + * Cache for the AVM store property entity:
+ * KEY: Pair of IDs (store, qname)
+ * VALUE: AVMStorePropertyEntity
+ * VALUE KEY: None
+ */ + private EntityLookupCache, AVMStorePropertyEntity, Serializable> avmStorePropCache; + + /** + * Set the cache to use for avm_stores lookups (optional). + * + * @param avmStoreCache the cache of IDs to AVMStoreEntities + */ + public void setAvmStoreCache(SimpleCache avmStoreCache) + { + this.avmStoreCache = new EntityLookupCache( + avmStoreCache, + CACHE_REGION_AVM_STORE, + avmStoreEntityDaoCallback); + } + + /** + * Set the cache to use for avm_store_properties lookups (optional). + * + * @param avmStorePropCache the cache of IDs to AVMStorePropertyEntities + */ + public void setAvmStorePropertyCache(SimpleCache avmStorePropCache) + { + this.avmStorePropCache = new EntityLookupCache, AVMStorePropertyEntity, Serializable>( + avmStorePropCache, + CACHE_REGION_AVM_STORE_PROP, + avmStorePropEntityDaoCallback); + } + + public void setQnameDAO(QNameDAO qnameDAO) + { + this.qnameDAO = qnameDAO; + } + + + /** + * Default constructor. + *

+ * This sets up the DAO accessors to bypass any caching to handle the case where the caches are not + * supplied in the setters. + */ + public AbstractAVMStoreDAOImpl() + { + this.avmStoreEntityDaoCallback = new AVMStoreEntityCallbackDAO(); + this.avmStoreCache = new EntityLookupCache(avmStoreEntityDaoCallback); + + this.avmStorePropEntityDaoCallback = new AVMStorePropertyEntityCallbackDAO(); + this.avmStorePropCache = new EntityLookupCache, AVMStorePropertyEntity, Serializable>(avmStorePropEntityDaoCallback); + } + + /** + * {@inheritDoc} + */ + public AVMStoreEntity createStore(String name) + { + ParameterCheck.mandatory("name", name); + + AVMStoreEntity storeEntity = new AVMStoreEntity(); + + storeEntity.setVersion(0L); + storeEntity.setName(name); + storeEntity.setVers(0L); + + Pair entityPair = avmStoreCache.getOrCreateByValue(storeEntity); + return entityPair.getSecond(); + } + + /** + * {@inheritDoc} + */ + public AVMStoreEntity getStore(long storeId) + { + Pair entityPair = avmStoreCache.getByKey(storeId); + if (entityPair == null) + { + return null; + } + return entityPair.getSecond(); + } + + /** + * {@inheritDoc} + */ + public AVMStoreEntity getStoreByRoot(long rootNodeId) + { + // TODO review - not via cache + return getStoreEntityByRoot(rootNodeId); + } + + /** + * {@inheritDoc} + */ + public AVMStoreEntity getStore(String name) + { + ParameterCheck.mandatory("name", name); + + AVMStoreEntity storeEntity = new AVMStoreEntity(); + storeEntity.setName(name); + + Pair entityPair = avmStoreCache.getByValue(storeEntity); + if (entityPair == null) + { + return null; + } + return entityPair.getSecond(); + } + + /** + * {@inheritDoc} + */ + public List getAllStores() + { + // not via cache + return getAllStoreEntities(); + } + + /** + * {@inheritDoc} + */ + public void updateStore(AVMStoreEntity storeEntity) + { + ParameterCheck.mandatory("storeEntity", storeEntity); + ParameterCheck.mandatory("storeEntity.getId()", storeEntity.getId()); + ParameterCheck.mandatory("storeEntity.getVers()", storeEntity.getVers()); + + int updated = avmStoreCache.updateValue(storeEntity.getId(), storeEntity); + if (updated < 1) + { + throw new ConcurrencyFailureException("AVMStore with ID (" + storeEntity.getId() + ") no longer exists or has been updated concurrently"); + } + storeEntity.setVers(storeEntity.getVers()+1); + } + + /** + * {@inheritDoc} + */ + public void deleteStore(long storeId) + { + Pair entityPair = avmStoreCache.getByKey(storeId); + if (entityPair == null) + { + return; + } + + int deleted = avmStoreCache.deleteByKey(storeId); + if (deleted < 1) + { + throw new ConcurrencyFailureException("AVMStore with ID " + storeId + " no longer exists"); + } + } + + /** + * Callback for avm_stores DAO + */ + private class AVMStoreEntityCallbackDAO implements EntityLookupCallbackDAO + { + private final Pair convertEntityToPair(AVMStoreEntity storeEntity) + { + if (storeEntity == null) + { + return null; + } + else + { + return new Pair(storeEntity.getId(), storeEntity); + } + } + + public String getValueKey(AVMStoreEntity value) + { + return value.getName(); + } + + public Pair createValue(AVMStoreEntity value) + { + AVMStoreEntity entity = createStoreEntity(value); + return convertEntityToPair(entity); + } + + public Pair findByKey(Long key) + { + AVMStoreEntity entity = getStoreEntity(key); + return convertEntityToPair(entity); + } + + public Pair findByValue(AVMStoreEntity value) + { + if ((value == null) || (value.getName() == null)) + { + throw new AlfrescoRuntimeException("Unexpected: AVMStoreEntity / name must not be null"); + } + return convertEntityToPair(getStoreEntity(value.getName())); + } + + public int updateValue(Long key, AVMStoreEntity value) + { + return updateStoreEntity(value); + } + + public int deleteByKey(Long key) + { + return deleteStoreEntity(key); + } + + public int deleteByValue(AVMStoreEntity value) + { + // TODO + throw new UnsupportedOperationException("deleteByValue(AVMStoreEntity)"); + } + } + + /** + * {@inheritDoc} + */ + public void clearStoreEntityCache() + { + avmStoreCache.clear(); + } + + protected abstract AVMStoreEntity getStoreEntity(long id); + protected abstract AVMStoreEntity getStoreEntity(String name); + protected abstract AVMStoreEntity getStoreEntityByRoot(long rootNodeId); + protected abstract List getAllStoreEntities(); + protected abstract AVMStoreEntity createStoreEntity(AVMStoreEntity storeEntity); + protected abstract int deleteStoreEntity(long id); + protected abstract int updateStoreEntity(AVMStoreEntity storeEntity); + + /** + * {@inheritDoc} + */ + public void createOrUpdateStoreProperty(long storeId, QName qname, PropertyValue value) + { + ParameterCheck.mandatory("qname", qname); + ParameterCheck.mandatory("value", value); + + // Get the persistent ID for the QName + Pair qnamePair = qnameDAO.getOrCreateQName(qname); + Long qnameId = qnamePair.getFirst(); + + AVMStorePropertyEntity propEntity = new AVMStorePropertyEntity(storeId, qnameId, value); + + Pair key = new Pair(storeId, propEntity.getQnameId()); + Pair, AVMStorePropertyEntity> entityPair = avmStorePropCache.getByKey(key); + + if (entityPair != null) + { + int updated = avmStorePropCache.updateValue(key, propEntity); + if (updated < 1) + { + throw new ConcurrencyFailureException("AVMStorePropertyEntity with IDs (" + propEntity.getAvmStoreId() + ", " + propEntity.getQnameId() + ") no longer exists"); + } + } + else + { + avmStorePropCache.getOrCreateByValue(propEntity); + } + } + + /** + * {@inheritDoc} + */ + public PropertyValue getStoreProperty(long storeId, QName qname) + { + // Get the persistent ID for the QName + Pair qnamePair = qnameDAO.getQName(qname); + if (qnamePair != null) + { + Long qnameId = qnamePair.getFirst(); + + Pair key = new Pair(storeId, qnameId); + Pair, AVMStorePropertyEntity> entityPair = avmStorePropCache.getByKey(key); + if (entityPair == null) + { + return null; + } + return entityPair.getSecond(); + } + return null; + } + + /** + * {@inheritDoc} + */ + public Map getStoreProperties(long storeId) + { + // not via cache + List propEntities = getStorePropertyEntities(storeId); + + Map props = new HashMap(propEntities.size()); + for (AVMStorePropertyEntity propEntity : propEntities) + { + Pair qnamePair = qnameDAO.getQName(propEntity.getQnameId()); + if (qnamePair != null) + { + props.put(qnamePair.getSecond(), propEntity); + } + } + return props; + } + + /** + * {@inheritDoc} + */ + public Map> getStorePropertiesByKeyPattern(String uriPattern, String localNamePattern) + { + ParameterCheck.mandatoryString("uriPattern", uriPattern); + ParameterCheck.mandatoryString("localNamePattern", localNamePattern); + + // not via cache + List spEntities = getStorePropertyEntitiesByKeyPattern(uriPattern, localNamePattern); + + Map> results = new HashMap>(10); + + for (AVMStorePropertyEntity spEntity : spEntities) + { + String storeName = getStore(spEntity.getAvmStoreId()).getName(); + + Pair qnamePair = qnameDAO.getQName(spEntity.getQnameId()); + if (qnamePair != null) + { + QName propQName = qnamePair.getSecond(); + + Map pairs = null; + if ((pairs = results.get(storeName)) == null) + { + pairs = new HashMap(); + results.put(storeName, pairs); + } + pairs.put(propQName, spEntity); + } + + } + return results; + } + + /** + * {@inheritDoc} + */ + public Map getStorePropertiesByStoreAndKeyPattern(long storeId, String uriPattern, String localNamePattern) + { + ParameterCheck.mandatoryString("uriPattern", uriPattern); + ParameterCheck.mandatoryString("localNamePattern", localNamePattern); + + // not via cache + List propEntities = getStorePropertyEntitiesByStoreAndKeyPattern(storeId, uriPattern, localNamePattern); + + Map props = new HashMap(propEntities.size()); + for (AVMStorePropertyEntity propEntity : propEntities) + { + Pair qnamePair = qnameDAO.getQName(propEntity.getQnameId()); + if (qnamePair != null) + { + props.put(qnamePair.getSecond(), propEntity); + } + } + return props; + } + + /** + * {@inheritDoc} + */ + public void deleteStoreProperty(long storeId, QName qname) + { + // Get the persistent ID for the QName + Pair qnamePair = qnameDAO.getQName(qname); + if (qnamePair != null) + { + Long qnameId = qnamePair.getFirst(); + + Pair key = new Pair(storeId, qnameId); + Pair, AVMStorePropertyEntity> entityPair = avmStorePropCache.getByKey(key); + if (entityPair == null) + { + return; + } + + int deleted = avmStorePropCache.deleteByKey(key); + if (deleted < 1) + { + throw new ConcurrencyFailureException("AVMStoreProperty with key (" + storeId + ", " + qnameId + ") no longer exists"); + } + } + } + + /** + * {@inheritDoc} + */ + public void deleteStoreProperties(long storeId) + { + Map props = getStoreProperties(storeId); + if (props.size() == 0) + { + return; + } + + for (QName qname : props.keySet()) + { + deleteStoreProperty(storeId, qname); + } + + // TODO single delete + cache(s) + + /* + int deleted = deleteStorePropertyEntities(storeId); + if (deleted < 1) + { + throw new ConcurrencyFailureException("AVMStoreProperties for store ID " + storeId + " no longer exist"); + } + + // TODO clear store property cache for this store id + */ + } + + /** + * Callback for avm_store_properties DAO + */ + private class AVMStorePropertyEntityCallbackDAO implements EntityLookupCallbackDAO, AVMStorePropertyEntity, Serializable> + { + private final Pair, AVMStorePropertyEntity> convertEntityToPair(AVMStorePropertyEntity storePropEntity) + { + if (storePropEntity == null) + { + return null; + } + else + { + Pair key = new Pair(storePropEntity.getAvmStoreId(), storePropEntity.getQnameId()); + return new Pair, AVMStorePropertyEntity>(key, storePropEntity); + } + } + + public Serializable getValueKey(AVMStorePropertyEntity value) + { + return null; + } + + public Pair, AVMStorePropertyEntity> createValue(AVMStorePropertyEntity value) + { + insertStorePropertyEntity(value); + return convertEntityToPair(value); + } + + public Pair, AVMStorePropertyEntity> findByKey(Pair key) + { + AVMStorePropertyEntity entity = getStorePropertyEntity(key.getFirst(), key.getSecond()); + return convertEntityToPair(entity); + } + + public Pair, AVMStorePropertyEntity> findByValue(AVMStorePropertyEntity value) + { + if ((value.getAvmStoreId() != null) && (value.getQnameId() != null)) + { + return findByKey(new Pair(value.getAvmStoreId(), value.getQnameId())); + } + return null; + } + + public int updateValue(Pair key, AVMStorePropertyEntity value) + { + return updateStorePropertyEntity(value); + } + + public int deleteByKey(Pair key) + { + return deleteStorePropertyEntity(key.getFirst(), key.getSecond()); + } + + public int deleteByValue(AVMStorePropertyEntity value) + { + throw new UnsupportedOperationException("deleteByValue(AVMStorePropertyEntity)"); + } + } + + protected abstract void insertStorePropertyEntity(AVMStorePropertyEntity propEntity); + protected abstract int updateStorePropertyEntity(AVMStorePropertyEntity propEntity); + protected abstract AVMStorePropertyEntity getStorePropertyEntity(long storeId, long qnameId); + protected abstract List getStorePropertyEntities(long storeId); + protected abstract List getStorePropertyEntitiesByKeyPattern(String uriPattern, String localNamePattern); + protected abstract List getStorePropertyEntitiesByStoreAndKeyPattern(long storeId, String uriPattern, String localNamePattern); + protected abstract int deleteStorePropertyEntity(long storeId, long qnameId); + protected abstract int deleteStorePropertyEntities(long storeId); +} diff --git a/source/java/org/alfresco/repo/domain/avm/AbstractAVMVersionRootDAOImpl.java b/source/java/org/alfresco/repo/domain/avm/AbstractAVMVersionRootDAOImpl.java new file mode 100644 index 0000000000..4cfb266945 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/AbstractAVMVersionRootDAOImpl.java @@ -0,0 +1,292 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.cache.NullCache; +import org.alfresco.repo.cache.SimpleCache; +import org.alfresco.util.Pair; +import org.alfresco.util.ParameterCheck; +import org.springframework.dao.ConcurrencyFailureException; + +/** + * Abstract implementation for AVMVersionRoot DAO. + *

+ * This provides basic services such as caching but defers to the underlying implementation + * for CRUD operations. + * + * @author janv + * @since 3.2 + */ +public abstract class AbstractAVMVersionRootDAOImpl implements AVMVersionRootDAO +{ + private SimpleCache vrEntityCache; + + /** + * Set the cache to use for avm_version_roots lookups (optional). + * + * @param vrEntityCache + */ + public void setVersionRootEntityCache(SimpleCache vrEntityCache) + { + this.vrEntityCache = vrEntityCache; + } + + @SuppressWarnings("unchecked") + public AbstractAVMVersionRootDAOImpl() + { + this.vrEntityCache = (SimpleCache)new NullCache(); + } + + /** + * {@inheritDoc} + */ + public AVMVersionRootEntity createVersionRoot(long storeId, long rootNodeId, int version, String creator, String tag, String description) + { + ParameterCheck.mandatory("creator", creator); + + AVMVersionRootEntity vrEntity = new AVMVersionRootEntity(); + vrEntity.setStoreId(storeId); + vrEntity.setRootNodeId(rootNodeId); + vrEntity.setVersion(version); + vrEntity.setCreator(creator); + vrEntity.setCreatedDate(new Date().getTime()); // app server date/time + vrEntity.setTag(tag); + vrEntity.setDescription(description); + + vrEntity = createVersionRootEntity(vrEntity); + + // Cache it + vrEntityCache.put(new Pair(storeId, version), vrEntity.getId()); + vrEntityCache.put(vrEntity.getId(), vrEntity); + + return vrEntity; + } + + /** + * {@inheritDoc} + */ + public void updateVersionRoot(AVMVersionRootEntity vrEntity) + { + ParameterCheck.mandatory("vrEntity", vrEntity); + + ParameterCheck.mandatory("vrEntity.storeId", vrEntity.getStoreId()); + ParameterCheck.mandatory("vrEntity.id", vrEntity.getId()); + ParameterCheck.mandatory("vrEntity.version", vrEntity.getVersion()); + + updateVersionRootEntity(vrEntity); + + // Cache it + vrEntityCache.put(new Pair(vrEntity.getStoreId(), vrEntity.getVersion()), vrEntity.getId()); + vrEntityCache.put(vrEntity.getId(), vrEntity); + } + + /** + * {@inheritDoc} + */ + public List getAllInStore(long storeId) + { + return getAllVersionRootEntitiesByStoreId(storeId); + } + + /** + * {@inheritDoc} + */ + protected AVMVersionRootEntity getByID(long vrEntityId) + { + AVMVersionRootEntity vrEntity = (AVMVersionRootEntity) vrEntityCache.get(vrEntityId); + if (vrEntity != null) + { + return vrEntity; + } + + // Get it from the DB + vrEntity = getVersionRootEntityById(vrEntityId); + if (vrEntity != null) + { + // Cache it + vrEntityCache.put(new Pair(vrEntity.getStoreId(), vrEntity.getVersion()), vrEntity.getId()); + vrEntityCache.put(vrEntity.getId(), vrEntity); + } + + return vrEntity; + } + + /** + * {@inheritDoc} + */ + public AVMVersionRootEntity getByVersionID(long storeId, int version) + { + // Check the cache + Long vrEntityId = (Long) vrEntityCache.get(new Pair(storeId, version)); + AVMVersionRootEntity vrEntity = null; + if (vrEntityId != null) + { + vrEntity = (AVMVersionRootEntity) vrEntityCache.get(vrEntityId); + if (vrEntity != null) + { + return vrEntity; + } + } + + // Get it from the DB + vrEntity = getVersionRootEntityByStoreVersion(storeId, version); + if (vrEntity != null) + { + // Cache it + vrEntityCache.put(new Pair(vrEntity.getStoreId(), vrEntity.getVersion()), vrEntity.getId()); + vrEntityCache.put(vrEntity.getId(), vrEntity); + } + + return vrEntity; + } + + /** + * {@inheritDoc} + */ + public AVMVersionRootEntity getByRoot(long rootNodeId) + { + return getVersionRootEntityByRootNodeId(rootNodeId); + } + + /** + * {@inheritDoc} + */ + public List getByDates(long storeId, Date from, Date to) + { + if ((from != null) && (to != null)) + { + return getVersionRootEntitiesByBetween(storeId, from.getTime(), to.getTime()); + } + else if ((from == null) && (to != null)) + { + return getVersionRootEntitiesByTo(storeId, to.getTime()); + } + else if ((to == null) && (from != null)) + { + return getVersionRootEntitiesByFrom(storeId, from.getTime()); + } + else + { + throw new AlfrescoRuntimeException("getByDates: from and to are both null for store id: "+storeId); + } + } + + /** + * {@inheritDoc} + */ + public AVMVersionRootEntity getMaxVersion(long storeId) + { + return getVersionRootEntityMaxVersion(storeId); + } + + /** + * {@inheritDoc} + */ + public Long getMaxVersionID(long storeId) + { + return getVersionRootEntityMaxVersionId(storeId); + } + + /** + * {@inheritDoc} + */ + public void deleteVersionRoot(long vrEntityId) + { + AVMVersionRootEntity vrEntity = getByID(vrEntityId); + if (vrEntity == null) + { + return; + } + + int deleted = deleteVersionRootEntity(vrEntityId); + if (deleted < 1) + { + throw new ConcurrencyFailureException("AVMVersionRoot with ID " + vrEntityId + " no longer exists"); + } + + // Remove from cache + vrEntityCache.remove(new Pair(vrEntity.getStoreId(), vrEntity.getVersion())); + vrEntityCache.remove(vrEntityId); + } + + protected abstract AVMVersionRootEntity createVersionRootEntity(AVMVersionRootEntity vrEntity); + protected abstract void updateVersionRootEntity(AVMVersionRootEntity updateVersionRootEntity); + protected abstract int deleteVersionRootEntity(long vrEntityId); + protected abstract AVMVersionRootEntity getVersionRootEntityMaxVersion(long storeId); + protected abstract Long getVersionRootEntityMaxVersionId(long storeId); + protected abstract AVMVersionRootEntity getVersionRootEntityById(long vrEntityId); + protected abstract AVMVersionRootEntity getVersionRootEntityByStoreVersion(long storeId, int version); + protected abstract AVMVersionRootEntity getVersionRootEntityByRootNodeId(long rootNodeId); + protected abstract List getAllVersionRootEntitiesByStoreId(long storeId); + protected abstract List getVersionRootEntitiesByTo(long storeId, long to); + protected abstract List getVersionRootEntitiesByFrom(long storeId, long from); + protected abstract List getVersionRootEntitiesByBetween(long storeId, long from, long to); + + /** + * {@inheritDoc} + */ + public AVMVersionLayeredNodeEntryEntity createVersionLayeredNodeEntry(long versionRootId, String md5sum, String path) + { + ParameterCheck.mandatory("md5sum", md5sum); + ParameterCheck.mandatory("path", path); + + return createVersionLayeredNodeEntryEntity(versionRootId, md5sum, path); + } + + /** + * {@inheritDoc} + */ + public void deleteVersionLayeredNodeEntries(long versionRootId) + { + List vlneEntities = getVersionLayeredNodeEntries(versionRootId); + if (vlneEntities.size() == 0) + { + return; + } + + int deleted = deleteVersionLayeredNodeEntryEntities(versionRootId); + if (deleted < 1) + { + throw new ConcurrencyFailureException("AVMVersionLayeredNodeEntries with version root id " + versionRootId + " no longer exist"); + } + } + + /** + * {@inheritDoc} + */ + public List getVersionLayeredNodeEntries(long versionRootId) + { + return getVersionLayeredNodeEntryEntities(versionRootId); + } + + protected abstract AVMVersionLayeredNodeEntryEntity createVersionLayeredNodeEntryEntity(long versionRootId, String md5sum, String path); + protected abstract int deleteVersionLayeredNodeEntryEntities(long versionRootId); + protected abstract List getVersionLayeredNodeEntryEntities(long storeId); +} diff --git a/source/java/org/alfresco/repo/domain/avm/ibatis/AVMNodeDAOImpl.java b/source/java/org/alfresco/repo/domain/avm/ibatis/AVMNodeDAOImpl.java new file mode 100644 index 0000000000..cab5d9220b --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/ibatis/AVMNodeDAOImpl.java @@ -0,0 +1,315 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm.ibatis; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.repo.domain.avm.AVMAspectEntity; +import org.alfresco.repo.domain.avm.AVMNodeEntity; +import org.alfresco.repo.domain.avm.AVMNodePropertyEntity; +import org.alfresco.repo.domain.avm.AbstractAVMNodeDAOImpl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.orm.ibatis.SqlMapClientTemplate; + +import com.ibatis.sqlmap.client.event.RowHandler; + +/** + * iBatis-specific implementation of the AVMNode DAO. + * + * @author janv + * @since 3.2 + */ +public class AVMNodeDAOImpl extends AbstractAVMNodeDAOImpl +{ + private static Log logger = LogFactory.getLog(AVMNodeDAOImpl.class); + + private static final String INSERT_AVM_NODE = "alfresco.avm.insert_AVMNode"; + private static final String SELECT_AVM_NODE_BY_ID = "alfresco.avm.select_AVMNodeById"; + private static final String UPDATE_AVM_NODE = "alfresco.avm.update_AVMNode"; + private static final String UPDATE_AVM_NODE_MODTIME_AND_GUID = "alfresco.avm.update_AVMNode_modTimeAndGuid"; + private static final String UPDATE_AVM_NODE_MODTIME_AND_CDATA = "alfresco.avm.update_AVMNode_modTimeAndContentData"; + private static final String DELETE_AVM_NODE = "alfresco.avm.delete_AVMNode"; + + private static final String SELECT_AVM_NODES_NEW_IN_STORE = "alfresco.avm.select_AVMNodes_newInStore"; + private static final String SELECT_AVM_NODES_NEW_LAYERED_IN_STORE = "alfresco.avm.select_AVMNodes_newLayeredInStore"; + private static final String SELECT_AVM_NODE_IDS_NEW_LAYERED_IN_STORE = "alfresco.avm.select_AVMNodes_IDs_newLayeredInStore"; + private static final String UPDATE_AVM_NODES_CLEAR_NEW_IN_STORE = "alfresco.avm.update_AVMNodes_clearNewInStore"; + private static final String SELECT_AVM_NODES_ORPHANS = "alfresco.avm.select_AVMNodes_orphans"; + private static final String SELECT_AVM_NODES_LAYERED_DIRECTORIES = "alfresco.avm.select_AVMNodes_layeredDirectories"; + private static final String SELECT_AVM_NODES_LAYERED_FILES = "alfresco.avm.select_AVMNodes_layeredFiles"; + private static final String SELECT_AVM_NODE_IDS_BY_ACL_ID = "alfresco.avm.select_AVMNodes_IDs_byAcl"; + + private static final String SELECT_AVM_CONTENT_URLS_FOR_PLAIN_FILES = "alfresco.avm.select_ContentUrlsForPlainFiles"; + + private static final String SELECT_AVM_NODE_ASPECTS = "alfresco.avm.select_AVMNodeAspects"; + private static final String INSERT_AVM_NODE_ASPECT = "alfresco.avm.insert_AVMNodeAspect"; + private static final String DELETE_AVM_NODE_ASPECT = "alfresco.avm.delete_AVMNodeAspect"; + private static final String DELETE_AVM_NODE_ASPECTS = "alfresco.avm.delete_AVMNodeAspects"; + + private static final String INSERT_AVM_NODE_PROP = "alfresco.avm.insert_AVMNodeProperty"; + private static final String UPDATE_AVM_NODE_PROP = "alfresco.avm.update_AVMNodeProperty"; + private static final String SELECT_AVM_NODE_PROP = "alfresco.avm.select_AVMNodeProperty"; + private static final String SELECT_AVM_NODE_PROPS = "alfresco.avm.select_AVMNodeProperties"; + private static final String DELETE_AVM_NODE_PROP = "alfresco.avm.delete_AVMNodeProperty"; + private static final String DELETE_AVM_NODE_PROPS = "alfresco.avm.delete_AVMNodeProperties"; + + private SqlMapClientTemplate template; + + public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) + { + this.template = sqlMapClientTemplate; + } + + @Override + protected AVMNodeEntity createNodeEntity(AVMNodeEntity nodeEntity) + { + Long id = (Long) template.insert(INSERT_AVM_NODE, nodeEntity); + nodeEntity.setId(id); + return nodeEntity; + } + + @Override + protected AVMNodeEntity getNodeEntity(long id) + { + Map params = new HashMap(1); + params.put("id", id); + return (AVMNodeEntity) template.queryForObject(SELECT_AVM_NODE_BY_ID, params); + } + + @Override + protected int updateNodeEntity(AVMNodeEntity updateNodeEntity) + { + return template.update(UPDATE_AVM_NODE, updateNodeEntity); + } + + @Override + protected int updateNodeEntityModTimeAndGuid(AVMNodeEntity updateNodeEntity) + { + // partial update + return template.update(UPDATE_AVM_NODE_MODTIME_AND_GUID, updateNodeEntity); + } + + @Override + protected int updateNodeEntityModTimeAndContentData(AVMNodeEntity updateNodeEntity) + { + // partial update + return template.update(UPDATE_AVM_NODE_MODTIME_AND_CDATA, updateNodeEntity); + } + + @Override + protected int deleteNodeEntity(long nodeId) + { + Map params = new HashMap(1); + params.put("id", nodeId); + return template.delete(DELETE_AVM_NODE, params); + } + + @Override + protected void updateNodeEntitiesClearNewInStore(long storeId) + { + Map params = new HashMap(1); + params.put("id", storeId); + template.update(UPDATE_AVM_NODES_CLEAR_NEW_IN_STORE, params); + } + + @SuppressWarnings("unchecked") + @Override + protected List getNodeEntitiesNewInStore(long storeId) + { + Map params = new HashMap(1); + params.put("id", storeId); + return (List) template.queryForList(SELECT_AVM_NODES_NEW_IN_STORE, params); + } + + @SuppressWarnings("unchecked") + @Override + protected List getLayeredNodeEntitiesNewInStore(long storeId) + { + Map params = new HashMap(1); + params.put("id", storeId); + return (List) template.queryForList(SELECT_AVM_NODES_NEW_LAYERED_IN_STORE, params); + } + + @SuppressWarnings("unchecked") + @Override + protected List getLayeredNodeEntityIdsNewInStore(long storeId) + { + Map params = new HashMap(1); + params.put("id", storeId); + return (List) template.queryForList(SELECT_AVM_NODE_IDS_NEW_LAYERED_IN_STORE, params); + } + + @SuppressWarnings("unchecked") + @Override + protected List getNodeEntityOrphans() + { + return (List) template.queryForList(SELECT_AVM_NODES_ORPHANS); + } + + @SuppressWarnings("unchecked") + @Override + protected List getAllLayeredDirectoryNodeEntities() + { + return (List) template.queryForList(SELECT_AVM_NODES_LAYERED_DIRECTORIES); + } + + @SuppressWarnings("unchecked") + @Override + protected List getAllLayeredFileNodeEntities() + { + return (List) template.queryForList(SELECT_AVM_NODES_LAYERED_FILES); + } + + @SuppressWarnings("unchecked") + @Override + protected List getAVMNodeEntityIdsByAclId(long aclId) + { + Map params = new HashMap(1); + params.put("id", aclId); + return (List) template.queryForList(SELECT_AVM_NODE_IDS_BY_ACL_ID, params); + } + + @Override + protected void getPlainFileContentUrls(ContentUrlHandler handler) + { + CleanRowHandler rowHandler = new CleanRowHandler(handler); + + template.queryWithRowHandler(SELECT_AVM_CONTENT_URLS_FOR_PLAIN_FILES, rowHandler); + + if (logger.isDebugEnabled()) + { + logger.debug(" Listed " + rowHandler.total + " content URLs"); + } + } + + /** + * Row handler for cleaning content URLs + */ + private static class CleanRowHandler implements RowHandler + { + private final ContentUrlHandler handler; + + private int total = 0; + + private CleanRowHandler(ContentUrlHandler handler) + { + this.handler = handler; + } + public void handleRow(Object valueObject) + { + handler.handle((String)valueObject); + total++; + if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) )) + { + logger.debug(" Listed " + total + " content URLs"); + } + } + } + + @SuppressWarnings("unchecked") + @Override + protected List getAspectEntities(long nodeId) + { + Map params = new HashMap(1); + params.put("id", nodeId); + return (List) template.queryForList(SELECT_AVM_NODE_ASPECTS, params); + } + + @Override + protected void createAspectEntity(long nodeId, long qnameId) + { + AVMAspectEntity aspectEntity = new AVMAspectEntity(nodeId, qnameId); + template.insert(INSERT_AVM_NODE_ASPECT, aspectEntity); + } + + @Override + protected int deleteAspectEntity(long nodeId, long qnameId) + { + AVMAspectEntity aspectEntity = new AVMAspectEntity(nodeId, qnameId); + return template.delete(DELETE_AVM_NODE_ASPECT, aspectEntity); + } + + @Override + protected int deleteAspectEntities(long nodeId) + { + Map params = new HashMap(1); + params.put("id", nodeId); + return template.delete(DELETE_AVM_NODE_ASPECTS, params); + } + + @Override + protected void insertNodePropertyEntity(AVMNodePropertyEntity propEntity) + { + template.insert(INSERT_AVM_NODE_PROP, propEntity); + } + + @Override + protected int updateNodePropertyEntity(AVMNodePropertyEntity updatePropEntity) + { + return template.update(UPDATE_AVM_NODE_PROP, updatePropEntity); + } + + @Override + protected AVMNodePropertyEntity getNodePropertyEntity(long nodeId, long qnameId) + { + AVMNodePropertyEntity propEntity = new AVMNodePropertyEntity(); + propEntity.setNodeId(nodeId); + propEntity.setQnameId(qnameId); + + return (AVMNodePropertyEntity) template.queryForObject(SELECT_AVM_NODE_PROP, propEntity); + } + + @Override + @SuppressWarnings("unchecked") + protected List getNodePropertyEntities(long nodeId) + { + Map params = new HashMap(1); + params.put("id", nodeId); + + return (List) template.queryForList(SELECT_AVM_NODE_PROPS, params); + } + + @Override + protected int deleteNodePropertyEntity(long nodeId, long qnameId) + { + AVMNodePropertyEntity propEntity = new AVMNodePropertyEntity(); + propEntity.setNodeId(nodeId); + propEntity.setQnameId(qnameId); + + return template.delete(DELETE_AVM_NODE_PROP, propEntity); + } + + @Override + protected int deleteNodePropertyEntities(long nodeId) + { + Map params = new HashMap(1); + params.put("id", nodeId); + + return template.delete(DELETE_AVM_NODE_PROPS, params); + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/ibatis/AVMNodeLinksDAOImpl.java b/source/java/org/alfresco/repo/domain/avm/ibatis/AVMNodeLinksDAOImpl.java new file mode 100644 index 0000000000..44ebe30944 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/ibatis/AVMNodeLinksDAOImpl.java @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm.ibatis; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.repo.domain.avm.AVMHistoryLinkEntity; +import org.alfresco.repo.domain.avm.AVMMergeLinkEntity; +import org.alfresco.repo.domain.avm.AVMChildEntryEntity; +import org.alfresco.repo.domain.avm.AbstractAVMNodeLinksDAOImpl; +import org.springframework.orm.ibatis.SqlMapClientTemplate; + +/** + * iBatis-specific implementation of the AVMNodeLinks DAO. + * + * @author janv + * @since 3.2 + */ +public class AVMNodeLinksDAOImpl extends AbstractAVMNodeLinksDAOImpl +{ + private static final String SELECT_AVM_NODE_CHILD_ENTRY ="alfresco.avm.select_AVMChildEntry"; // parent + name + child + private static final String SELECT_AVM_NODE_CHILD_ENTRY_BY_PARENT_AND_NAME ="alfresco.avm.select_AVMChildEntryByParentAndName"; // parent + name + private static final String SELECT_AVM_NODE_CHILD_ENTRY_BY_PARENT_AND_CHILD ="alfresco.avm.select_AVMChildEntryByParentAndChild"; // parent + child + private static final String SELECT_AVM_NODE_CHILD_ENTRIES_BY_PARENT ="alfresco.avm.select_AVMNodeChildEntriesByParent"; // parent + private static final String SELECT_AVM_NODE_CHILD_ENTRIES_BY_CHILD ="alfresco.avm.select_AVMNodeChildEntriesByChild"; // child + + private static final String INSERT_AVM_NODE_CHILD_ENTRY ="alfresco.avm.insert_AVMChildEntry"; // parent + name + child + + private static final String DELETE_AVM_NODE_CHILD_ENTRY_BY_PARENT_AND_NAME ="alfresco.avm.delete_AVMChildEntryByParentAndName"; // parent + name + private static final String DELETE_AVM_NODE_CHILD_ENTRY_BY_PARENT_AND_CHILD ="alfresco.avm.delete_AVMChildEntryByParentAndChild"; // parent + child + private static final String DELETE_AVM_NODE_CHILD_ENTRIES_BY_PARENT ="alfresco.avm.delete_AVMNodeChildEntriesByParent"; // parent + + private static final String INSERT_AVM_MERGE_LINK ="alfresco.avm.insert_AVMMergeLink"; + private static final String DELETE_AVM_MERGE_LINK ="alfresco.avm.delete_AVMMergeLink"; + + private static final String SELECT_AVM_MERGE_LINKS_BY_FROM ="alfresco.avm.select_AVMMergeLinksByFrom"; + private static final String SELECT_AVM_MERGE_LINK_BY_TO ="alfresco.avm.select_AVMMergeLinkByTo"; + + private static final String INSERT_AVM_HISTORY_LINK ="alfresco.avm.insert_AVMHistoryLink"; + private static final String DELETE_AVM_HISTORY_LINK ="alfresco.avm.delete_AVMHistoryLink"; + + private static final String SELECT_AVM_HISTORY_LINKS_BY_ANCESTOR ="alfresco.avm.select_AVMHistoryLinksByAncestor"; + private static final String SELECT_AVM_HISTORY_LINK_BY_DESCENDENT ="alfresco.avm.select_AVMHistoryLinkByDescendent"; + private static final String SELECT_AVM_HISTORY_LINK ="alfresco.avm.select_AVMHistoryLink"; + + private SqlMapClientTemplate template; + + public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) + { + this.template = sqlMapClientTemplate; + } + + @Override + protected AVMChildEntryEntity getChildEntryEntity(AVMChildEntryEntity childEntryEntity) + { + return (AVMChildEntryEntity) template.queryForObject(SELECT_AVM_NODE_CHILD_ENTRY, childEntryEntity); + } + + @Override + protected AVMChildEntryEntity getChildEntryEntity(long parentNodeId, String name) + { + AVMChildEntryEntity childEntryEntity = new AVMChildEntryEntity(parentNodeId, name); + return (AVMChildEntryEntity) template.queryForObject(SELECT_AVM_NODE_CHILD_ENTRY_BY_PARENT_AND_NAME, childEntryEntity); + } + + @Override + protected AVMChildEntryEntity getChildEntryEntity(long parentNodeId, long childNodeId) + { + AVMChildEntryEntity childEntryEntity = new AVMChildEntryEntity(parentNodeId, childNodeId); + return (AVMChildEntryEntity) template.queryForObject(SELECT_AVM_NODE_CHILD_ENTRY_BY_PARENT_AND_CHILD, childEntryEntity); + } + + @SuppressWarnings("unchecked") + @Override + protected List getChildEntryEntitiesByParent(long parentNodeId) + { + Map params = new HashMap(1); + params.put("id", parentNodeId); + return (List) template.queryForList(SELECT_AVM_NODE_CHILD_ENTRIES_BY_PARENT, params); + } + + @SuppressWarnings("unchecked") + @Override + protected List getChildEntryEntitiesByChild(long childNodeId) + { + Map params = new HashMap(1); + params.put("id", childNodeId); + return (List) template.queryForList(SELECT_AVM_NODE_CHILD_ENTRIES_BY_CHILD, params); + } + + @Override + protected void createChildEntryEntity(AVMChildEntryEntity childEntryEntity) + { + template.insert(INSERT_AVM_NODE_CHILD_ENTRY, childEntryEntity); + } + + @Override + protected int deleteChildEntryEntity(long parentNodeId, String name) + { + AVMChildEntryEntity childEntryEntity = new AVMChildEntryEntity(parentNodeId, name); + return template.delete(DELETE_AVM_NODE_CHILD_ENTRY_BY_PARENT_AND_NAME, childEntryEntity); + } + + @Override + protected int deleteChildEntryEntity(long parentNodeId, long childNodeId) + { + AVMChildEntryEntity childEntryEntity = new AVMChildEntryEntity(parentNodeId, childNodeId); + return template.delete(DELETE_AVM_NODE_CHILD_ENTRY_BY_PARENT_AND_CHILD, childEntryEntity); + } + + @Override + protected int deleteChildEntryEntities(long parentNodeId) + { + Map params = new HashMap(1); + params.put("id", parentNodeId); + return template.delete(DELETE_AVM_NODE_CHILD_ENTRIES_BY_PARENT, params); + } + + + @Override + protected void createMergeLinkEntity(long mergeFromNodeId, long mergeToNodeId) + { + AVMMergeLinkEntity mergeLinkEntity = new AVMMergeLinkEntity(mergeFromNodeId, mergeToNodeId); + template.insert(INSERT_AVM_MERGE_LINK, mergeLinkEntity); + } + + @Override + protected int deleteMergeLinkEntity(long mergeFromNodeId, long mergeToNodeId) + { + AVMMergeLinkEntity mLinkEntity = new AVMMergeLinkEntity(mergeFromNodeId, mergeToNodeId); + return template.delete(DELETE_AVM_MERGE_LINK, mLinkEntity); + } + + @Override + protected AVMMergeLinkEntity getMergeLinkEntityByTo(long mergeToNodeId) + { + Map params = new HashMap(1); + params.put("id", mergeToNodeId); + return (AVMMergeLinkEntity) template.queryForObject(SELECT_AVM_MERGE_LINK_BY_TO, params); + } + + @SuppressWarnings("unchecked") + @Override + protected List getMergeLinkEntitiesByFrom(long mergeFromNodeId) + { + Map params = new HashMap(1); + params.put("id", mergeFromNodeId); + return (List) template.queryForList(SELECT_AVM_MERGE_LINKS_BY_FROM, params); + } + + + @Override + protected void createHistoryLinkEntity(long ancestorNodeId, long mergeToNodeId) + { + AVMHistoryLinkEntity hLinkEntity = new AVMHistoryLinkEntity(ancestorNodeId, mergeToNodeId); + template.insert(INSERT_AVM_HISTORY_LINK, hLinkEntity); + } + + @Override + protected int deleteHistoryLinkEntity(long ancestorNodeId, long descendentNodeId) + { + AVMHistoryLinkEntity hLinkEntity = new AVMHistoryLinkEntity(ancestorNodeId, descendentNodeId); + return template.delete(DELETE_AVM_HISTORY_LINK, hLinkEntity); + } + + @Override + protected AVMHistoryLinkEntity getHistoryLinkEntityByDescendent(long descendentNodeId) + { + Map params = new HashMap(1); + params.put("id", descendentNodeId); + return (AVMHistoryLinkEntity) template.queryForObject(SELECT_AVM_HISTORY_LINK_BY_DESCENDENT, params); + } + + @Override + protected AVMHistoryLinkEntity getHistoryLinkEntity(long ancestorNodeId, long descendentNodeId) + { + AVMHistoryLinkEntity hLinkEntity = new AVMHistoryLinkEntity(ancestorNodeId, descendentNodeId); + return (AVMHistoryLinkEntity) template.queryForObject(SELECT_AVM_HISTORY_LINK, hLinkEntity); + } + + @SuppressWarnings("unchecked") + @Override + protected List getHistoryLinkEntitiesByAncestor(long ancestorNodeId) + { + Map params = new HashMap(1); + params.put("id", ancestorNodeId); + return (List) template.queryForList(SELECT_AVM_HISTORY_LINKS_BY_ANCESTOR, params); + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/ibatis/AVMStoreDAOImpl.java b/source/java/org/alfresco/repo/domain/avm/ibatis/AVMStoreDAOImpl.java new file mode 100644 index 0000000000..9aa26161aa --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/ibatis/AVMStoreDAOImpl.java @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm.ibatis; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.repo.domain.avm.AVMStoreEntity; +import org.alfresco.repo.domain.avm.AVMStorePropertyEntity; +import org.alfresco.repo.domain.avm.AbstractAVMStoreDAOImpl; +import org.springframework.orm.ibatis.SqlMapClientTemplate; + +/** + * iBatis-specific implementation of the AVMStore DAO. + * + * @author janv + * @since 3.2 + */ +public class AVMStoreDAOImpl extends AbstractAVMStoreDAOImpl +{ + private static final String SELECT_AVM_STORE_BY_ID ="alfresco.avm.select_AVMStoreById"; + private static final String SELECT_AVM_STORE_BY_KEY ="alfresco.avm.select_AVMStoreByKey"; + private static final String SELECT_AVM_STORE_BY_ROOT_NODE_ID ="alfresco.avm.select_AVMStoreByRootNodeId"; + private static final String SELECT_AVM_STORE_ALL ="alfresco.avm.select_AVMStoreAll"; + + private static final String INSERT_AVM_STORE ="alfresco.avm.insert_AVMStore"; + private static final String DELETE_AVM_STORE ="alfresco.avm.delete_AVMStore"; + private static final String UPDATE_AVM_STORE ="alfresco.avm.update_AVMStore"; + + private static final String INSERT_AVM_STORE_PROP ="alfresco.avm.insert_AVMStoreProperty"; + private static final String UPDATE_AVM_STORE_PROP ="alfresco.avm.update_AVMStoreProperty"; + private static final String SELECT_AVM_STORE_PROP ="alfresco.avm.select_AVMStoreProperty"; + private static final String SELECT_AVM_STORE_PROPS ="alfresco.avm.select_AVMStoreProperties"; + private static final String SELECT_AVM_STORE_PROPS_BY_KEY_PATTERN ="alfresco.avm.select_AVMStorePropertiesByKeyPattern"; + private static final String SELECT_AVM_STORE_PROPS_BY_STORE_AND_KEY_PATTERN ="alfresco.avm.select_AVMStorePropertiesByStoreAndKeyPattern"; + private static final String DELETE_AVM_STORE_PROP ="alfresco.avm.delete_AVMStoreProperty"; + private static final String DELETE_AVM_STORE_PROPS ="alfresco.avm.delete_AVMStoreProperties"; + + + private SqlMapClientTemplate template; + + public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) + { + this.template = sqlMapClientTemplate; + } + + @Override + protected AVMStoreEntity getStoreEntity(long id) + { + Map params = new HashMap(1); + params.put("id", id); + return (AVMStoreEntity) template.queryForObject(SELECT_AVM_STORE_BY_ID, params); + } + + @Override + protected AVMStoreEntity getStoreEntity(String name) + { + AVMStoreEntity storeEntity = new AVMStoreEntity(); + storeEntity.setName(name); + return (AVMStoreEntity) template.queryForObject(SELECT_AVM_STORE_BY_KEY, storeEntity); + } + + @Override + protected AVMStoreEntity getStoreEntityByRoot(long rootNodeId) + { + Map params = new HashMap(1); + params.put("id", rootNodeId); + return (AVMStoreEntity) template.queryForObject(SELECT_AVM_STORE_BY_ROOT_NODE_ID, params); + } + + @SuppressWarnings("unchecked") + @Override + protected List getAllStoreEntities() + { + return (List) template.queryForList(SELECT_AVM_STORE_ALL); + } + + @Override + protected AVMStoreEntity createStoreEntity(AVMStoreEntity storeEntity) + { + Long id = (Long) template.insert(INSERT_AVM_STORE, storeEntity); + storeEntity.setId(id); + return storeEntity; + } + + @Override + protected int updateStoreEntity(AVMStoreEntity updateStoreEntity) + { + return template.update(UPDATE_AVM_STORE, updateStoreEntity); + } + + @Override + protected int deleteStoreEntity(long id) + { + Map params = new HashMap(1); + params.put("id", id); + return template.delete(DELETE_AVM_STORE, params); + } + + @Override + protected void insertStorePropertyEntity(AVMStorePropertyEntity propEntity) + { + template.insert(INSERT_AVM_STORE_PROP, propEntity); + } + + @Override + protected int updateStorePropertyEntity(AVMStorePropertyEntity updatePropEntity) + { + return template.update(UPDATE_AVM_STORE_PROP, updatePropEntity); + } + + @Override + protected AVMStorePropertyEntity getStorePropertyEntity(long storeId, long qnameId) + { + AVMStorePropertyEntity propEntity = new AVMStorePropertyEntity(); + propEntity.setAvmStoreId(storeId); + propEntity.setQnameId(qnameId); + + return (AVMStorePropertyEntity) template.queryForObject(SELECT_AVM_STORE_PROP, propEntity); + } + + @SuppressWarnings("unchecked") + @Override + protected List getStorePropertyEntities(long storeId) + { + Map params = new HashMap(1); + params.put("id", storeId); + + return (List) template.queryForList(SELECT_AVM_STORE_PROPS, params); + } + + @SuppressWarnings("unchecked") + @Override + protected List getStorePropertyEntitiesByKeyPattern(String uriPattern, String localNamePattern) + { + Map params = new HashMap(2); + params.put("uri", uriPattern); + params.put("localname", localNamePattern); + + return (List) template.queryForList(SELECT_AVM_STORE_PROPS_BY_KEY_PATTERN, params); + } + + @SuppressWarnings("unchecked") + @Override + protected List getStorePropertyEntitiesByStoreAndKeyPattern(long storeId, String uriPattern, String localNamePattern) + { + Map params = new HashMap(3); + params.put("id", storeId); + params.put("uri", uriPattern); + params.put("localname", localNamePattern); + + return (List) template.queryForList(SELECT_AVM_STORE_PROPS_BY_STORE_AND_KEY_PATTERN, params); + } + + @Override + protected int deleteStorePropertyEntity(long storeId, long qnameId) + { + AVMStorePropertyEntity propEntity = new AVMStorePropertyEntity(); + propEntity.setAvmStoreId(storeId); + propEntity.setQnameId(qnameId); + + return template.delete(DELETE_AVM_STORE_PROP, propEntity); + } + + @Override + protected int deleteStorePropertyEntities(long storeId) + { + Map params = new HashMap(1); + params.put("id", storeId); + + return template.delete(DELETE_AVM_STORE_PROPS, params); + } +} diff --git a/source/java/org/alfresco/repo/domain/avm/ibatis/AVMVersionRootDAOImpl.java b/source/java/org/alfresco/repo/domain/avm/ibatis/AVMVersionRootDAOImpl.java new file mode 100644 index 0000000000..1adb299f57 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/avm/ibatis/AVMVersionRootDAOImpl.java @@ -0,0 +1,206 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.avm.ibatis; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.repo.domain.avm.AVMStoreEntity; +import org.alfresco.repo.domain.avm.AVMVersionLayeredNodeEntryEntity; +import org.alfresco.repo.domain.avm.AVMVersionRootEntity; +import org.alfresco.repo.domain.avm.AbstractAVMVersionRootDAOImpl; +import org.springframework.orm.ibatis.SqlMapClientTemplate; + +/** + * iBatis-specific implementation of the AVMVersionRoot DAO + * + * @author janv + * @since 3.2 + */ +public class AVMVersionRootDAOImpl extends AbstractAVMVersionRootDAOImpl +{ + private static final String INSERT_AVM_VERSION_ROOT ="alfresco.avm.insert_AVMVersionRoot"; + private static final String DELETE_AVM_VERSION_ROOT ="alfresco.avm.delete_AVMVersionRoot"; + private static final String UPDATE_AVM_VERSION_ROOT ="alfresco.avm.update_AVMVersionRoot"; + + private static final String SELECT_AVM_VERSION_ROOT_MAX_VERSION ="alfresco.avm.select_AVMVersionRootMaxVersion"; + private static final String SELECT_AVM_VERSION_ROOT_MAX_VERSION_ID ="alfresco.avm.select_AVMVersionRootMaxVersionID"; + private static final String SELECT_AVM_VERSION_ROOT_BY_ID ="alfresco.avm.select_AVMVersionRootById"; + private static final String SELECT_AVM_VERSION_ROOT_BY_STORE_VERSION ="alfresco.avm.select_AVMVersionRootByStoreVersion"; + private static final String SELECT_AVM_VERSION_ROOT_BY_ROOT_NODE_ID ="alfresco.avm.select_AVMVersionRootByRootNodeId"; + private static final String SELECT_AVM_VERSION_ROOTS_BY_STORE_ID ="alfresco.avm.select_AVMVersionRootsByStoreId"; + private static final String SELECT_AVM_VERSION_ROOTS_BY_TO ="alfresco.avm.select_AVMVersionRootsByTo"; + private static final String SELECT_AVM_VERSION_ROOTS_BY_FROM ="alfresco.avm.select_AVMVersionRootsByFrom"; + private static final String SELECT_AVM_VERSION_ROOTS_BETWEEN ="alfresco.avm.select_AVMVersionRootsBetween"; + + private static final String INSERT_AVM_VERSION_LAYERED_NODE_ENTRY ="alfresco.avm.insert_AVMVersionLayeredNodeEntry"; + private static final String DELETE_AVM_VERSION_LAYERED_NODE_ENTRIES ="alfresco.avm.delete_AVMVersionLayeredNodeEntries"; + private static final String SELECT_AVM_VERSION_LAYERED_NODE_ENTRIES ="alfresco.avm.select_AVMVersionLayeredNodeEntries"; + + + private SqlMapClientTemplate template; + + public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) + { + this.template = sqlMapClientTemplate; + } + + @Override + protected AVMVersionRootEntity createVersionRootEntity(AVMVersionRootEntity newVersionRootEntity) + { + Long id = (Long) template.insert(INSERT_AVM_VERSION_ROOT, newVersionRootEntity); + newVersionRootEntity.setId(id); + return newVersionRootEntity; + } + + @Override + protected void updateVersionRootEntity(AVMVersionRootEntity updateVersionRootEntity) + { + template.update(UPDATE_AVM_VERSION_ROOT, updateVersionRootEntity, 1); + } + + @Override + protected AVMVersionRootEntity getVersionRootEntityMaxVersion(long storeId) + { + AVMStoreEntity storeEntity = new AVMStoreEntity(); + storeEntity.setId(storeId); + return (AVMVersionRootEntity) template.queryForObject(SELECT_AVM_VERSION_ROOT_MAX_VERSION, storeEntity); + } + + @Override + protected Long getVersionRootEntityMaxVersionId(long storeId) + { + Map params = new HashMap(1); + params.put("id", storeId); + Integer maxVersionId = (Integer) template.queryForObject(SELECT_AVM_VERSION_ROOT_MAX_VERSION_ID, params); + if (maxVersionId == null) + { + return null; + } + return new Long(maxVersionId); + } + + @Override + protected AVMVersionRootEntity getVersionRootEntityById(long vrEntityId) + { + Map params = new HashMap(1); + params.put("id", vrEntityId); + return (AVMVersionRootEntity) template.queryForObject(SELECT_AVM_VERSION_ROOT_BY_ID, params); + } + + @Override + protected AVMVersionRootEntity getVersionRootEntityByStoreVersion(long storeId, int version) + { + AVMVersionRootEntity vrEntity = new AVMVersionRootEntity(); + vrEntity.setStoreId(storeId); + vrEntity.setVersion(version); + + return (AVMVersionRootEntity) template.queryForObject(SELECT_AVM_VERSION_ROOT_BY_STORE_VERSION, vrEntity); + } + + @Override + protected AVMVersionRootEntity getVersionRootEntityByRootNodeId(long rootNodeId) + { + Map params = new HashMap(1); + params.put("id", rootNodeId); + return (AVMVersionRootEntity) template.queryForObject(SELECT_AVM_VERSION_ROOT_BY_ROOT_NODE_ID, params); + } + + @SuppressWarnings("unchecked") + @Override + protected List getAllVersionRootEntitiesByStoreId(long storeId) + { + Map params = new HashMap(1); + params.put("id", storeId); + return (List) template.queryForList(SELECT_AVM_VERSION_ROOTS_BY_STORE_ID, params); + } + + @SuppressWarnings("unchecked") + protected List getVersionRootEntitiesByTo(long storeId, long to) + { + Map params = new HashMap(3); + params.put("id", storeId); + params.put("to", to); + params.put("from", null); + return (List) template.queryForList(SELECT_AVM_VERSION_ROOTS_BY_TO, params); + } + + @SuppressWarnings("unchecked") + protected List getVersionRootEntitiesByFrom(long storeId, long from) + { + Map params = new HashMap(3); + params.put("id", storeId); + params.put("from", from); + params.put("to", null); + return (List) template.queryForList(SELECT_AVM_VERSION_ROOTS_BY_FROM, params); + } + + @SuppressWarnings("unchecked") + protected List getVersionRootEntitiesByBetween(long storeId, long from, long to) + { + Map params = new HashMap(3); + params.put("id", storeId); + params.put("from", from); + params.put("to", to); + return (List) template.queryForList(SELECT_AVM_VERSION_ROOTS_BETWEEN, params); + } + + @Override + protected int deleteVersionRootEntity(long vrEntityId) + { + Map params = new HashMap(1); + params.put("id", vrEntityId); + return template.delete(DELETE_AVM_VERSION_ROOT, params); + } + + @Override + protected AVMVersionLayeredNodeEntryEntity createVersionLayeredNodeEntryEntity(long versionRootId, String md5sum, String path) + { + AVMVersionLayeredNodeEntryEntity vlneEntity = new AVMVersionLayeredNodeEntryEntity(); + vlneEntity.setVersionRootId(versionRootId); + vlneEntity.setMd5sum(md5sum); + vlneEntity.setPath(path); + template.insert(INSERT_AVM_VERSION_LAYERED_NODE_ENTRY, vlneEntity); + return vlneEntity; + } + + @Override + protected int deleteVersionLayeredNodeEntryEntities(long versionRootId) + { + Map params = new HashMap(1); + params.put("id", versionRootId); + return template.delete(DELETE_AVM_VERSION_LAYERED_NODE_ENTRIES, params); + } + + @SuppressWarnings("unchecked") + @Override + protected List getVersionLayeredNodeEntryEntities(long versionRootId) + { + Map params = new HashMap(1); + params.put("id", versionRootId); + return (List) template.queryForList(SELECT_AVM_VERSION_LAYERED_NODE_ENTRIES, params); + } +} diff --git a/source/java/org/alfresco/repo/domain/hibernate/AclDaoComponentImpl.java b/source/java/org/alfresco/repo/domain/hibernate/AclDaoComponentImpl.java index 5709ae3592..9dbc4d3642 100644 --- a/source/java/org/alfresco/repo/domain/hibernate/AclDaoComponentImpl.java +++ b/source/java/org/alfresco/repo/domain/hibernate/AclDaoComponentImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -44,6 +44,9 @@ import org.alfresco.repo.domain.DbAuthority; import org.alfresco.repo.domain.DbPermission; import org.alfresco.repo.domain.Node; import org.alfresco.repo.domain.QNameDAO; +import org.alfresco.repo.domain.avm.AVMNodeDAO; +import org.alfresco.repo.domain.avm.AVMNodeEntity; +import org.alfresco.repo.domain.patch.PatchDAO; import org.alfresco.repo.security.permissions.ACEType; import org.alfresco.repo.security.permissions.ACLCopyMode; import org.alfresco.repo.security.permissions.ACLType; @@ -105,14 +108,14 @@ public class AclDaoComponentImpl extends HibernateDaoSupport implements AclDaoCo static String QUERY_GET_LATEST_ACL_BY_ACLID = "permission.FindLatestAclByGuid"; - static String QUERY_GET_LAYERED_DIRECTORIES = "permission.GetLayeredDirectories"; - - static String QUERY_GET_LAYERED_FILES = "permission.GetLayeredFiles"; - - static String QUERY_GET_NEW_IN_STORE = "permission.GetNewInStore"; - /** Access to QName entities */ private QNameDAO qnameDAO; + + /** Access to AVMNode queries */ + private AVMNodeDAO avmNodeDAO; + + /** Access to additional Patch queries */ + private PatchDAO patchDAO; /** a transactionally-safe cache to be injected */ private SimpleCache aclCache; @@ -168,7 +171,17 @@ public class AclDaoComponentImpl extends HibernateDaoSupport implements AclDaoCo { this.qnameDAO = qnameDAO; } - + + public void setPatchDAO(PatchDAO patchDAO) + { + this.patchDAO = patchDAO; + } + + public void setAvmNodeDAO(AVMNodeDAO avmNodeDAO) + { + this.avmNodeDAO = avmNodeDAO; + } + /** * Set the ACL cache * @@ -1108,8 +1121,7 @@ public class AclDaoComponentImpl extends HibernateDaoSupport implements AclDaoCo { throw new UnsupportedOperationException(); } - - @SuppressWarnings("unchecked") + public AccessControlList getAccessControlList(Long id) { AccessControlList acl = aclCache.get(id); @@ -1249,7 +1261,6 @@ public class AclDaoComponentImpl extends HibernateDaoSupport implements AclDaoCo throw new UnsupportedOperationException(); } - @SuppressWarnings("unchecked") public List mergeInheritedAccessControlList(Long inherited, Long target) { @@ -1688,23 +1699,13 @@ public class AclDaoComponentImpl extends HibernateDaoSupport implements AclDaoCo DbAccessControlList acl = (DbAccessControlList) getHibernateTemplate().get(DbAccessControlListImpl.class, id); return acl; } - - @SuppressWarnings("unchecked") + public List getAvmNodesByACL(final Long id) { - HibernateCallback callback = new HibernateCallback() - { - public Object doInHibernate(Session session) - { - Query query = session.getNamedQuery(QUERY_GET_AVM_NODES_BY_ACL); - query.setParameter("acl", id); - return query.list(); - } - }; - List avmNodeIds = (List) getHibernateTemplate().execute(callback); + List avmNodeIds = avmNodeDAO.getAVMNodesByAclId(id); return avmNodeIds; } - + @SuppressWarnings("unchecked") private List disableInheritanceImpl(Long id, boolean setInheritedOnAcl, DbAccessControlList acl) { @@ -1995,36 +1996,6 @@ public class AclDaoComponentImpl extends HibernateDaoSupport implements AclDaoCo } - /** - * Get the total number of head nodes in the repository - * - * @return count - */ - public Long getAVMHeadNodeCount() - { - try - { - Session session = getSession(); - int isolationLevel = session.connection().getTransactionIsolation(); - try - { - session.connection().setTransactionIsolation(1); - Query query = getSession().getNamedQuery("permission.GetAVMHeadNodeCount"); - Long answer = (Long) query.uniqueResult(); - return answer; - } - finally - { - session.connection().setTransactionIsolation(isolationLevel); - } - } - catch (SQLException e) - { - throw new AlfrescoRuntimeException("Failed to set TX isolation level", e); - } - - } - /** * Get the max acl id * @@ -2073,109 +2044,56 @@ public class AclDaoComponentImpl extends HibernateDaoSupport implements AclDaoCo } - /** - * Get the acl count canges so far for progress tracking - * - * @param above - * @return - the count - */ - public Long getAVMNodeCountWithNewACLS(Long above) - { - try - { - Session session = getSession(); - int isolationLevel = session.connection().getTransactionIsolation(); - try - { - session.connection().setTransactionIsolation(1); - Query query = getSession().getNamedQuery("permission.GetAVMHeadNodeCountWherePermissionsHaveChanged"); - query.setParameter("above", above); - Long answer = (Long) query.uniqueResult(); - return answer; - } - finally - { - session.connection().setTransactionIsolation(isolationLevel); - } - } - catch (SQLException e) - { - throw new AlfrescoRuntimeException("Failed to set TX isolation level", e); - } - } - /** * How many nodes are noew in store (approximate) * - * @return - the number fo new nodes - approximate + * @return - the number of new nodes - approximate */ public Long getNewInStore() { - HibernateCallback callback = new HibernateCallback() - { - public Object doInHibernate(Session session) - { - Query query = session.getNamedQuery(QUERY_GET_NEW_IN_STORE); - return query.uniqueResult(); - } - }; - Long count = (Long) getHibernateTemplate().execute(callback); + Long count = patchDAO.getAVMNodesCountWhereNewInStore(); return count; } /** - * Find layered directories Used to imporove performance during patching and cascading the effect fo permission + * Find layered directories Used to improve performance during patching and cascading the effect of permission * changes between layers * * @return - layered directories */ - @SuppressWarnings("unchecked") public List getLayeredDirectories() { - HibernateCallback callback = new HibernateCallback() + List ldNodeEntities = avmNodeDAO.getAllLayeredDirectories(); + + ArrayList indirections = new ArrayList(ldNodeEntities.size()); + + for (AVMNodeEntity ldNodeEntity : ldNodeEntities) { - public Object doInHibernate(Session session) - { - Query query = session.getNamedQuery(QUERY_GET_LAYERED_DIRECTORIES); - return query.list(); - } - }; - List results = (List) getHibernateTemplate().execute(callback); - ArrayList indirections = new ArrayList(results.size()); - for (Object[] row : results) - { - Long from = (Long) row[0]; - String to = (String) row[1]; - Integer version = (Integer) row[2]; + Long from = ldNodeEntity.getId(); + String to = ldNodeEntity.getIndirection(); + Integer version = ldNodeEntity.getIndirectionVersion(); indirections.add(new Indirection(from, to, version)); } return indirections; } /** - * Find layered files Used to imporove performance during patching and cascading the effect fo permission changes + * Find layered files Used to improve performance during patching and cascading the effect of permission changes * between layers * - * @return - layerd files + * @return - layered files */ - @SuppressWarnings("unchecked") public List getLayeredFiles() { - HibernateCallback callback = new HibernateCallback() + List lfNodeEntities = avmNodeDAO.getAllLayeredFiles(); + + ArrayList indirections = new ArrayList(lfNodeEntities.size()); + + for (AVMNodeEntity lfNodeEntity : lfNodeEntities) { - public Object doInHibernate(Session session) - { - Query query = session.getNamedQuery(QUERY_GET_LAYERED_FILES); - return query.list(); - } - }; - List results = (List) getHibernateTemplate().execute(callback); - ArrayList indirections = new ArrayList(results.size()); - for (Object[] row : results) - { - Long from = (Long) row[0]; - String to = (String) row[1]; - Integer version = (Integer) row[2]; + Long from = lfNodeEntity.getId(); + String to = lfNodeEntity.getIndirection(); + Integer version = lfNodeEntity.getIndirectionVersion(); indirections.add(new Indirection(from, to, version)); } return indirections; diff --git a/source/java/org/alfresco/repo/domain/hibernate/Permission.hbm.xml b/source/java/org/alfresco/repo/domain/hibernate/Permission.hbm.xml index 19d5f679aa..c168d7a2fa 100644 --- a/source/java/org/alfresco/repo/domain/hibernate/Permission.hbm.xml +++ b/source/java/org/alfresco/repo/domain/hibernate/Permission.hbm.xml @@ -367,23 +367,7 @@ org.alfresco.repo.domain.hibernate.DbAccessControlListImpl as acl where acl.inheritsFrom = :id and acl.inherits = true - - - select - node.id - from - org.alfresco.repo.avm.AVMNodeImpl node - where node.acl.id = :acl - - - - select - node.id - from - org.alfresco.repo.avm.LayeredDirectoryNodeImpl node - where node.primaryIndirection = true and node.indirection = :indirection - - + select acl.id @@ -392,26 +376,6 @@ where acl.aclId = :aclId and latest = true - - - - - - - - :above - ]]> - - - - - - - - - - - - - - - diff --git a/source/java/org/alfresco/repo/domain/hibernate/SessionSizeResourceManager.java b/source/java/org/alfresco/repo/domain/hibernate/SessionSizeResourceManager.java index 506d3d6614..a985f27725 100644 --- a/source/java/org/alfresco/repo/domain/hibernate/SessionSizeResourceManager.java +++ b/source/java/org/alfresco/repo/domain/hibernate/SessionSizeResourceManager.java @@ -29,7 +29,6 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.alfresco.repo.avm.hibernate.SessionCacheChecker; import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.util.resource.MethodResourceManager; import org.apache.commons.logging.Log; @@ -127,11 +126,6 @@ public class SessionSizeResourceManager extends HibernateDaoSupport implements M long transactionElapsedTimeNs, Method currentMethod) { - if (logger.isDebugEnabled()) - { - logger.debug("Session Size Manager Invoked."); - SessionCacheChecker.instance.check(); - } if (isDisableInTransaction()) { // Don't do anything diff --git a/source/java/org/alfresco/repo/domain/patch/AbstractPatchDAOImpl.java b/source/java/org/alfresco/repo/domain/patch/AbstractPatchDAOImpl.java new file mode 100644 index 0000000000..eead711fdd --- /dev/null +++ b/source/java/org/alfresco/repo/domain/patch/AbstractPatchDAOImpl.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.patch; + +import java.util.List; + +import org.alfresco.repo.domain.avm.AVMNodeEntity; + + +/** + * Abstract implementation for Patch DAO. + *

+ * This provides additional queries used by patches. + * + * @author janv + * @since 3.2 + */ +public abstract class AbstractPatchDAOImpl implements PatchDAO +{ + public Long getAVMNodesCountWhereNewInStore() + { + return getAVMNodeEntitiesCountWhereNewInStore(); + } + + protected abstract Long getAVMNodeEntitiesCountWhereNewInStore(); + + public List getEmptyGUIDS(int count) + { + // TODO limit results - count is currently ignored + return getAVMNodeEntitiesWithEmptyGUID(); + } + + protected abstract List getAVMNodeEntitiesWithEmptyGUID(); + + public List getNullVersionLayeredDirectories(int count) + { + // TODO limit results - count is currently ignored + return getNullVersionLayeredDirectoryNodeEntities(); + } + + public List getNullVersionLayeredFiles(int count) + { + // TODO limit results - count is currently ignored + return getNullVersionLayeredFileNodeEntities(); + } + + protected abstract List getNullVersionLayeredDirectoryNodeEntities(); + + protected abstract List getNullVersionLayeredFileNodeEntities(); +} diff --git a/source/java/org/alfresco/repo/domain/patch/PatchDAO.java b/source/java/org/alfresco/repo/domain/patch/PatchDAO.java new file mode 100644 index 0000000000..fc33e76c93 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/patch/PatchDAO.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.patch; + +import java.util.List; + +import org.alfresco.repo.domain.avm.AVMNodeEntity; + + +/** + * Additional DAO services for patches + * + * @author janv + * @since 3.2 + */ +public interface PatchDAO +{ + // AVM-related + + public Long getAVMNodesCountWhereNewInStore(); + + public List getEmptyGUIDS(int count); + + public List getNullVersionLayeredDirectories(int count); + + public List getNullVersionLayeredFiles(int count); +} diff --git a/source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java b/source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java new file mode 100644 index 0000000000..34a3bb10c2 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.patch.ibatis; + +import java.util.List; + +import org.alfresco.repo.domain.avm.AVMNodeEntity; +import org.alfresco.repo.domain.patch.AbstractPatchDAOImpl; +import org.springframework.orm.ibatis.SqlMapClientTemplate; + +/** + * iBatis-specific implementation of the AVMPatch DAO. + * + * @author janv + * @since 3.2 + */ +public class PatchDAOImpl extends AbstractPatchDAOImpl +{ + private static final String SELECT_AVM_NODE_ENTITIES_COUNT_WHERE_NEW_IN_STORE = "select.AVMNodeEntitiesCountWhereNewInStore"; + private static final String SELECT_AVM_NODE_ENTITIES_WITH_EMPTY_GUID = "select.AVMNodesWithEmptyGUID"; + private static final String SELECT_AVM_LD_NODE_ENTITIES_NULL_VERSION = "select.AVMNodes.nullVersionLayeredDirectories"; + private static final String SELECT_AVM_LF_NODE_ENTITIES_NULL_VERSION = "select.AVMNodes.nullVersionLayeredFiles"; + + private SqlMapClientTemplate avmTemplate; + + public void setAvmSqlMapClientTemplate(SqlMapClientTemplate avmSqlMapClientTemplate) + { + this.avmTemplate = avmSqlMapClientTemplate; + } + + @Override + protected Long getAVMNodeEntitiesCountWhereNewInStore() + { + return (Long) avmTemplate.queryForObject(SELECT_AVM_NODE_ENTITIES_COUNT_WHERE_NEW_IN_STORE); + } + + @SuppressWarnings("unchecked") + @Override + protected List getAVMNodeEntitiesWithEmptyGUID() + { + return (List) avmTemplate.queryForList(SELECT_AVM_NODE_ENTITIES_WITH_EMPTY_GUID); + } + + @SuppressWarnings("unchecked") + @Override + protected List getNullVersionLayeredDirectoryNodeEntities() + { + return (List) avmTemplate.queryForList(SELECT_AVM_LD_NODE_ENTITIES_NULL_VERSION); + } + + @SuppressWarnings("unchecked") + @Override + protected List getNullVersionLayeredFileNodeEntities() + { + return (List) avmTemplate.queryForList(SELECT_AVM_LF_NODE_ENTITIES_NULL_VERSION); + } +} diff --git a/source/java/org/alfresco/service/cmr/avm/AVMService.java b/source/java/org/alfresco/service/cmr/avm/AVMService.java index dcee00138c..df3dde59b0 100644 --- a/source/java/org/alfresco/service/cmr/avm/AVMService.java +++ b/source/java/org/alfresco/service/cmr/avm/AVMService.java @@ -805,7 +805,7 @@ public interface AVMService * @param store The store to set the property on. * @param name The name of the property. * @param value The value of the property. - * @throws AVMNotFoundException + * @throws AVMNotFoundException (if store does not exist) */ public void setStoreProperty(String store, QName name, PropertyValue value); @@ -814,7 +814,7 @@ public interface AVMService * * @param store The name of the store. * @param props A Map of the properties to set. - * @throws AVMNotFoundException + * @throws AVMNotFoundException (if store does not exist) */ public void setStoreProperties(String store, Map props); @@ -824,7 +824,7 @@ public interface AVMService * @param store The name of the store. * @param name The name of the property. * @return A PropertyValue or null if non-existent. - * @throws AVMNotFoundException + * @throws AVMNotFoundException (if store does not exist) */ public PropertyValue getStoreProperty(String store, QName name); @@ -833,7 +833,7 @@ public interface AVMService * * @param store The name of the store. * @return A Map of the stores properties. - * @throws AVMNotFoundException + * @throws AVMNotFoundException (if store does not exist) */ public Map getStoreProperties(String store);