+++ /dev/null
-package org.argeo.slc.hibernate.structure.tree;\r
-\r
-import java.util.List;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.dao.structure.tree.TreeSPathDao;\r
-import org.springframework.orm.hibernate3.support.HibernateDaoSupport;\r
-\r
-/**\r
- * The Hibernate implementation for tree-based result of the test result dao.\r
- * \r
- * @see TreeTestResult\r
- */\r
-public class TreeSPathDaoHibernate extends HibernateDaoSupport implements\r
- TreeSPathDao {\r
-\r
- private static Log log = LogFactory.getLog(TreeSPathDaoHibernate.class);\r
-\r
- public void create(TreeSPath path) {\r
- createImpl(path);\r
- }\r
-\r
- private void createImpl(TreeSPath path) {\r
- if (path.getParent() != null) {\r
- TreeSPath parent = getTreeSPath(path.getParent()\r
- .getAsUniqueString());\r
- if (parent == null) {\r
- createImpl(path.getParent());\r
- }\r
- }\r
- getHibernateTemplate().save(path);\r
- if (log.isTraceEnabled())\r
- log.trace("Saved TreeSPath " + path.getAsUniqueString());\r
- }\r
-\r
- public TreeSPath getTreeSPath(String pathString) {\r
- List<?> list = getHibernateTemplate().find(\r
- "from TreeSPath where asUniqueString=?", pathString);\r
- if (list.size() == 0) {\r
- return null;\r
- } else {\r
- return (TreeSPath) list.get(0);\r
- }\r
- }\r
-\r
- public TreeSPath getOrCreate(TreeSPath pathTransient) {\r
- TreeSPath path = getTreeSPath(pathTransient.getAsUniqueString());\r
- if (path != null) {\r
- return path;\r
- } else {\r
- create(pathTransient);\r
- // TODO: optimize\r
- return getTreeSPath(pathTransient.getAsUniqueString());\r
- }\r
-\r
- }\r
-\r
-}\r
+++ /dev/null
-package org.argeo.slc.hibernate.structure.tree;\r
-\r
-import java.util.List;\r
-\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
-import org.hibernate.Session;\r
-\r
-/**\r
- * The Hibernate implementation for tree-based structure registry.\r
- * \r
- * @see TreeSRegistry\r
- */\r
-public class TreeSRegistryDaoHibernate extends HibernateDaoSupport implements\r
- TreeSRegistryDao {\r
-\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
- }\r
-\r
- public void update(TreeSRegistry registryArg) {\r
- Session session = getSession();\r
- session.beginTransaction();\r
- TreeSRegistry registry = (TreeSRegistry) session.merge(registryArg);\r
- session.update(registry);\r
- session.getTransaction().commit();\r
- }\r
-\r
- public TreeSRegistry getActiveTreeSRegistry() {\r
- List<?> list = getHibernateTemplate().find(\r
- "from TreeSRegistry where status=?",\r
- TreeSRegistry.STATUS_ACTIVE);\r
- if (list.size() == 0) {\r
- return null;\r
- } else {\r
- return (TreeSRegistry) list.get(0);\r
- }\r
- }\r
-\r
- public void syncPath(TreeSRegistry registryArg,\r
- StructureRegistry<TreeSPath> localRegistry, TreeSPath pathArg) {\r
- Session session = getSession();\r
- session.beginTransaction();\r
- TreeSRegistry registry = (TreeSRegistry) session.merge(registryArg);\r
- TreeSPath path = (TreeSPath) session.merge(pathArg);\r
- if (log.isTraceEnabled())\r
- log.trace("Session#" + session.hashCode() + " " + session);\r
- syncPathImpl(registry, localRegistry, path, session);\r
- session.update(registry);\r
- session.getTransaction().commit();\r
- }\r
-\r
- private void syncPathImpl(TreeSRegistry registry,\r
- StructureRegistry<TreeSPath> localRegistry, TreeSPath path,\r
- Session session) {\r
- if (path.getParent() != null) {\r
- TreeSPath parent = treeSPathDao.getOrCreate(path.getParent());\r
- syncPathImpl(registry, localRegistry, parent, session);\r
- }\r
-\r
- if (log.isTraceEnabled())\r
- log.trace("Synchronize path " + path);\r
-\r
- if (registry.getElement(path) == null) {\r
- final StructureElement element = getElement(registry,\r
- localRegistry, path, session);\r
- StructureElement elementPersisted = (StructureElement) session\r
- .merge(element);\r
- registry.register(path, elementPersisted);\r
- // update(registry);\r
-\r
- if (log.isTraceEnabled())\r
- log.trace("No element in persisted structure for " + path\r
- + ", merged to " + elementPersisted);\r
- } else {\r
- if (localRegistry != null) {\r
- StructureElement element = getElement(registry, localRegistry,\r
- path, session);\r
-\r
- if (element != null) {\r
- StructureElement elementPersisted = (StructureElement) session\r
- .merge(element);\r
- registry.register(path, elementPersisted);\r
- // update(registry);\r
- if (log.isTraceEnabled())\r
- log\r
- .trace("Update existing element in persisted structure for "\r
- + path\r
- + ", merged to "\r
- + elementPersisted);\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
- Session session) {\r
- StructureElement element;\r
- if (localRegistry != null) {\r
- element = localRegistry.getElement(path);\r
- if (session.getSessionFactory()\r
- .getClassMetadata(element.getClass()) == null) {\r
- if (log.isTraceEnabled())\r
- log.trace("Replace non-hibernate element " + element\r
- + " by a simple element.");\r
- element = new SimpleSElement(element.getLabel());\r
- }\r
- } else {\r
- element = new SimpleSElement(path.getName());\r
- }\r
- return element;\r
- }\r
-}\r
+++ /dev/null
-<html>\r
-<head></head>\r
-<body>\r
-Hibernate based DAO implementations for tree-based structure objects.\r
-</body>\r
-</html>
\ No newline at end of file
<value>\r
org/argeo/slc/hibernate/structure/SimpleSElement.hbm.xml\r
</value>\r
- <value>\r
- org/argeo/slc/hibernate/structure/tree/TreeSPath.hbm.xml\r
- </value>\r
- <value>\r
- org/argeo/slc/hibernate/structure/tree/TreeSRegistry.hbm.xml\r
- </value>\r
- <value>\r
- org/argeo/slc/hibernate/test/SimpleResultPart.hbm.xml\r
- </value>\r
<value>\r
org/argeo/slc/hibernate/test/tree/TreeTestResult.hbm.xml\r
</value>\r
</property>\r
</bean>\r
\r
- <bean id="slcTemplates.dao.treeSPathDao"\r
- class="org.argeo.slc.hibernate.structure.tree.TreeSPathDaoHibernate"\r
- abstract="true">\r
- </bean>\r
-\r
- <bean id="slcTemplates.dao.treeSRegistryDao"\r
- class="org.argeo.slc.hibernate.structure.tree.TreeSRegistryDaoHibernate"\r
- abstract="true">\r
- </bean>\r
-\r
<bean id="slcTemplates.dao.testResultDao"\r
class="org.argeo.slc.hibernate.test.tree.TestResultDaoHibernate"\r
abstract="true">\r
+++ /dev/null
-<?xml version="1.0"?>\r
-<!DOCTYPE hibernate-mapping PUBLIC\r
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"\r
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">\r
-<hibernate-mapping package="org.argeo.slc.core.structure.tree">\r
- <class name="TreeSPath" table="TREE_SPATH">\r
- <id name="tid" column="T_ID">\r
- <generator class="native" />\r
- </id>\r
- <property name="asUniqueString" column="PATH" not-null="true"\r
- unique="true" />\r
- </class>\r
-</hibernate-mapping>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0"?>\r
-<!DOCTYPE hibernate-mapping PUBLIC\r
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"\r
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">\r
-<hibernate-mapping package="org.argeo.slc.core.structure.tree">\r
- <class name="TreeSRegistry" table="TREE_SREGISTRY">\r
- <id name="tid" column="T_ID">\r
- <generator class="native" />\r
- </id>\r
-\r
- <property name="status" column="STATUS" not-null="true"\r
- unique="true" />\r
-\r
- <map name="elements" table="REGISTRY_ELEMENTS" cascade="all"\r
- lazy="false" sort="natural">\r
- <key column="PARENT_ID" />\r
- <map-key-many-to-many class="TreeSPath" column="PATH" />\r
-\r
- <many-to-many\r
- class="org.argeo.slc.core.structure.SimpleSElement"\r
- column="ELEMENT_ID" unique="true" lazy="false" />\r
- </map>\r
-\r
- </class>\r
-</hibernate-mapping>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0"?>\r
-<!DOCTYPE hibernate-mapping PUBLIC\r
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"\r
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">\r
-<hibernate-mapping package="org.argeo.slc.core.test">\r
- <class name="SimpleResultPart" table="SIMPLE_RESULT_PART">\r
- <id name="tid" column="T_ID">\r
- <generator class="native" />\r
- </id>\r
- <property name="status" column="STATUS" not-null="true" />\r
- <property name="message" column="MESSAGE" not-null="true" />\r
- <property name="exceptionMessage" column="EXCEPTION_MESSAGE"\r
- not-null="false" />\r
- </class>\r
-</hibernate-mapping>
\ No newline at end of file
+++ /dev/null
-package org.argeo.slc.hibernate.structure.tree;\r
-\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.dao.structure.tree.TreeSPathDao;\r
-import org.argeo.slc.unit.AbstractSpringTestCase;\r
-\r
-public class TreeSPathDaoHibernateTest extends AbstractSpringTestCase {\r
-\r
- public void testCreate() {\r
- TreeSPathDao treeSPathDao = getBean(TreeSPathDao.class);\r
-\r
- String pathParentStr = "/root/testParent";\r
- String pathStr = pathParentStr + "/test";\r
- TreeSPath path = TreeSPath.parseToCreatePath(pathStr);\r
- treeSPathDao.create(path);\r
-\r
- TreeSPath pathChild = treeSPathDao.getTreeSPath(pathStr);\r
- assertEquals(path, pathChild);\r
-\r
- TreeSPath pathParent = treeSPathDao.getTreeSPath(pathParentStr);\r
- assertEquals(path.getParent(), pathParent);\r
- }\r
-\r
- @Override\r
- protected String getApplicationContextLocation() {\r
- return "org/argeo/slc/hibernate/applicationContext.xml";\r
- }\r
-\r
-}\r
+++ /dev/null
-package org.argeo.slc.hibernate.structure.tree;\r
-\r
-import org.argeo.slc.core.structure.SimpleSElement;\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
-import org.argeo.slc.unit.AbstractSpringTestCase;\r
-\r
-public class TreeSRegistryDaoHibernateTest extends AbstractSpringTestCase {\r
-\r
- public void testCreate() {\r
- TreeSRegistryDao treeSRegistryDao = getBean(TreeSRegistryDao.class);\r
-\r
- TreeSPathDao treeSPathDao = (TreeSPathDao) getContext().getBean(\r
- "treeSPathDao");\r
-\r
- TreeSPath root = TreeSPath.parseToCreatePath("/root");\r
- TreeSPath path = root.createChild("test");\r
-\r
- treeSPathDao.create(root);\r
- treeSPathDao.create(path);\r
-\r
- TreeSRegistry registry = new TreeSRegistry();\r
- registry.setStatus(TreeSRegistry.STATUS_ACTIVE);\r
- String desc = "desc";\r
- registry.register(path, new SimpleSElement(desc));\r
-\r
- treeSRegistryDao.create(registry);\r
-\r
- TreeSRegistry registry2 = treeSRegistryDao.getActiveTreeSRegistry();\r
- SimpleSElement element = registry2.getElements().get(path);\r
- assertEquals(desc, element.getLabel());\r
- }\r
-\r
- @Override\r
- protected String getApplicationContextLocation() {\r
- return "org/argeo/slc/hibernate/applicationContext.xml";\r
- }\r
-\r
-}\r
parent="slcTemplates.dao.slcExecutionDao">\r
<property name="sessionFactory" ref="sessionFactory" />\r
</bean>\r
- \r
- <bean id="treeSPathDao"\r
- parent="slcTemplates.dao.treeSPathDao">\r
- <property name="sessionFactory" ref="sessionFactory" />\r
- </bean>\r
-\r
- <bean id="treeSRegistryDao"\r
- parent="slcTemplates.dao.treeSRegistryDao">\r
- <property name="sessionFactory" ref="sessionFactory" />\r
- </bean>\r
</beans>
\ No newline at end of file