\r
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;\r
\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+\r
+import org.argeo.slc.core.structure.SimpleSElement;\r
+import org.argeo.slc.core.structure.StructureElement;\r
+import org.argeo.slc.core.structure.StructureRegistry;\r
import org.argeo.slc.core.structure.tree.TreeSPath;\r
import org.argeo.slc.core.structure.tree.TreeSRegistry;\r
+import org.argeo.slc.dao.structure.tree.TreeSPathDao;\r
import org.argeo.slc.dao.structure.tree.TreeSRegistryDao;\r
\r
/**\r
public class TreeSRegistryDaoHibernate extends HibernateDaoSupport implements\r
TreeSRegistryDao {\r
\r
- // private static Log log =\r
- // LogFactory.getLog(TreeSRegistryDaoHibernate.class);\r
+ private TreeSPathDao treeSPathDao;\r
+\r
+ private static Log log = LogFactory.getLog(TreeSRegistryDaoHibernate.class);\r
\r
public void create(TreeSRegistry registry) {\r
getHibernateTemplate().save(registry);\r
getHibernateTemplate().update(registry);\r
}\r
\r
- public TreeSRegistry getTreeSRegistry(TreeSPath treeSPath) {\r
+ public TreeSRegistry getActiveTreeSRegistry() {\r
List<?> list = getHibernateTemplate().find(\r
- "from TreeSRegistry where root.asUniqueString=?",\r
- treeSPath.getRoot().getAsUniqueString());\r
+ "from TreeSRegistry where status=?",\r
+ TreeSRegistry.STATUS_ACTIVE);\r
if (list.size() == 0) {\r
return null;\r
} else {\r
}\r
}\r
\r
+ public void syncPath(TreeSRegistry registry,\r
+ StructureRegistry<TreeSPath> localRegistry, TreeSPath path) {\r
+ if (path.getParent() != null) {\r
+ TreeSPath parent = treeSPathDao.getOrCreate(path.getParent());\r
+ syncPath(registry, localRegistry, parent);\r
+ }\r
+\r
+ if (log.isDebugEnabled())\r
+ log.debug("Synchronize path " + path);\r
+ \r
+ if (registry.getElement(path) == null) {\r
+ if (localRegistry != null) {\r
+ registry.register(path, getElement(registry, localRegistry, path));\r
+ } else {\r
+ registry.register(path, new SimpleSElement(path.getName()));\r
+ }\r
+ update(registry);\r
+ } else {\r
+ if (localRegistry != null) {\r
+ StructureElement sElement = getElement(registry, localRegistry, path);\r
+ if (sElement != null) {\r
+ registry.register(path, sElement);\r
+ update(registry);\r
+ }\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ public void setTreeSPathDao(TreeSPathDao treeSPathDao) {\r
+ this.treeSPathDao = treeSPathDao;\r
+ }\r
+\r
+ protected StructureElement getElement(TreeSRegistry registry,\r
+ StructureRegistry<TreeSPath> localRegistry, TreeSPath path){\r
+ return localRegistry.getElement(path);\r
+ }\r
}\r