1 package org
.argeo
.slc
.hibernate
.structure
.tree
;
5 import org
.springframework
.orm
.hibernate3
.support
.HibernateDaoSupport
;
7 import org
.apache
.commons
.logging
.Log
;
8 import org
.apache
.commons
.logging
.LogFactory
;
10 import org
.argeo
.slc
.core
.structure
.SimpleSElement
;
11 import org
.argeo
.slc
.core
.structure
.StructureElement
;
12 import org
.argeo
.slc
.core
.structure
.StructureRegistry
;
13 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
14 import org
.argeo
.slc
.core
.structure
.tree
.TreeSRegistry
;
15 import org
.argeo
.slc
.dao
.structure
.tree
.TreeSPathDao
;
16 import org
.argeo
.slc
.dao
.structure
.tree
.TreeSRegistryDao
;
19 * The Hibernate implementation for tree-based structure registry.
23 public class TreeSRegistryDaoHibernate
extends HibernateDaoSupport
implements
26 private TreeSPathDao treeSPathDao
;
28 private static Log log
= LogFactory
.getLog(TreeSRegistryDaoHibernate
.class);
30 public void create(TreeSRegistry registry
) {
31 getHibernateTemplate().save(registry
);
34 public void update(TreeSRegistry registry
) {
35 getHibernateTemplate().update(registry
);
38 public TreeSRegistry
getActiveTreeSRegistry() {
39 List
<?
> list
= getHibernateTemplate().find(
40 "from TreeSRegistry where status=?",
41 TreeSRegistry
.STATUS_ACTIVE
);
42 if (list
.size() == 0) {
45 return (TreeSRegistry
) list
.get(0);
49 public void syncPath(TreeSRegistry registry
,
50 StructureRegistry
<TreeSPath
> localRegistry
, TreeSPath path
) {
51 if (path
.getParent() != null) {
52 TreeSPath parent
= treeSPathDao
.getOrCreate(path
.getParent());
53 syncPath(registry
, localRegistry
, parent
);
56 if (log
.isTraceEnabled())
57 log
.trace("Synchronize path " + path
);
59 if (registry
.getElement(path
) == null) {
60 if (localRegistry
!= null) {
61 registry
.register(path
, getElement(registry
, localRegistry
, path
));
63 registry
.register(path
, new SimpleSElement(path
.getName()));
67 if (localRegistry
!= null) {
68 StructureElement sElement
= getElement(registry
, localRegistry
, path
);
69 if (sElement
!= null) {
70 registry
.register(path
, sElement
);
78 public void setTreeSPathDao(TreeSPathDao treeSPathDao
) {
79 this.treeSPathDao
= treeSPathDao
;
82 protected StructureElement
getElement(TreeSRegistry registry
,
83 StructureRegistry
<TreeSPath
> localRegistry
, TreeSPath path
){
84 return localRegistry
.getElement(path
);