Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote-tracking branch 'gekkio/hibernate4'

  • Loading branch information...
commit 0991ae92728d61e35be4970cbb48d1b8185de651 2 parents 2506a1c + f9ddaee
Ville Seppä authored
Showing with 438 additions and 1,320 deletions.
  1. +0 −8 distribution/assembly.xml
  2. +0 −48 distribution/doc/Summary_about_used_libraries.txt
  3. +0 −8 distribution/doc/dev/Actions.txt
  4. +0 −6 distribution/doc/dev/DAOs.txt
  5. +0 −68 distribution/doc/dev/README_for_developers.txt
  6. +0 −6 distribution/doc/dev/hibernate_DAOs.txt
  7. +0 −5 distribution/doc/dev/tags.txt
  8. +0 −21 distribution/doc/upgrade/README.txt
  9. +16 −49 pom.xml
  10. +0 −12 webapp/legacy/database-mysql5.properties
  11. +0 −82 webapp/legacy/hibernate.cfg.xml
  12. +10 −4 webapp/pom.xml
  13. +21 −6 webapp/src/main/java/fi/hut/soberit/agilefant/business/impl/SettingBusinessImpl.java
  14. +3 −3 webapp/src/main/java/fi/hut/soberit/agilefant/config/DaoConfiguration.java
  15. +1 −1  webapp/src/main/java/fi/hut/soberit/agilefant/config/TransactionConfiguration.java
  16. +1 −1  webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/AssignmentDAOHibernate.java
  17. +7 −8 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/BacklogDAOHibernate.java
  18. +2 −2 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/BacklogHistoryEntryDAOHibernate.java
  19. +4 −7 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/BacklogHourEntryDAOHibernate.java
  20. +8 −3 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/Email.java
  21. +11 −20 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/EmailValidator.java
  22. +0 −116 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/EnumUserType.java
  23. +34 −27 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/GenericDAOHibernate.java
  24. +1 −1  webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/HolidayDAOHibernate.java
  25. +22 −34 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/HourEntryDAOHibernate.java
  26. +20 −21 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/IterationDAOHibernate.java
  27. +7 −8 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/IterationHistoryEntryDAOHibernate.java
  28. +3 −3 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/LabelDAOHibernate.java
  29. +7 −8 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/ProductDAOHibernate.java
  30. +11 −14 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/ProjectDAOHibernate.java
  31. +33 −25 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/SettingDAOHibernate.java
  32. +1 −1  webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/StoryAccessDAOHibernate.java
  33. +15 −15 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/StoryDAOHibernate.java
  34. +23 −28 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/StoryHierarchyDAOHibernate.java
  35. +3 −3 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/StoryRankDAOHibernate.java
  36. +12 −12 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/TaskDAOHibernate.java
  37. +4 −8 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/TaskHourEntryDAOHibernate.java
  38. +17 −12 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/TextUserType.java
  39. +17 −12 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/TruncatedStringUserType.java
  40. +4 −4 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/UserDAOHibernate.java
  41. +28 −26 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/UserTypeFilter.java
  42. +17 −12 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/VarcharUserType.java
  43. +6 −6 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/WhatsNextEntryDAOHibernate.java
  44. +1 −1  webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/WidgetCollectionDAOHibernate.java
  45. +9 −12 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/notification/NotificationEventListener.java
  46. +6 −7 webapp/src/main/java/fi/hut/soberit/agilefant/db/history/impl/BacklogHistoryDAOImpl.java
  47. +2 −1  webapp/src/main/java/fi/hut/soberit/agilefant/model/BacklogHistoryEntry.java
  48. +2 −1  webapp/src/main/java/fi/hut/soberit/agilefant/model/HourEntry.java
  49. +3 −2 webapp/src/main/java/fi/hut/soberit/agilefant/model/Iteration.java
  50. +1 −1  webapp/src/main/java/fi/hut/soberit/agilefant/model/IterationHistoryEntry.java
  51. +2 −1  webapp/src/main/java/fi/hut/soberit/agilefant/model/Label.java
  52. +3 −2 webapp/src/main/java/fi/hut/soberit/agilefant/model/Project.java
  53. +2 −1  webapp/src/main/java/fi/hut/soberit/agilefant/model/StoryAccess.java
  54. +1 −1  webapp/src/main/webapp/WEB-INF/applicationContext-security.xml
  55. +2 −47 webapp/src/main/webapp/WEB-INF/hibernate.cfg.xml
  56. +1 −1  webapp/src/main/webapp/WEB-INF/web.xml
  57. +26 −4 webapp/src/test/java/fi/hut/soberit/agilefant/business/SettingBusinessTest.java
  58. +0 −6 webapp/src/test/resources/WEB-INF/configuration.properties
  59. +0 −8 webapp/src/test/resources/WEB-INF/database.properties
  60. +0 −46 webapp/src/test/resources/WEB-INF/hibernate.cfg.xml
  61. +0 −178 webapp/src/test/resources/checkstyle/checkstyle-noframes-sorted.xsl
  62. +0 −171 webapp/src/test/resources/checkstyle/sun_checks.xml
  63. +2 −3 webapp/src/test/resources/fi/hut/soberit/agilefant/db/GenericDAOTest-context.xml
  64. +2 −15 webapp/src/test/resources/testApplicationContext-forDaos.xml
  65. +2 −33 webapp/src/test/resources/testApplicationContext-forHistory.xml
  66. +2 −14 webapp/src/test/resources/testApplicationContext-forIntegration.xml
View
8 distribution/assembly.xml
@@ -25,20 +25,12 @@
<outputDirectory>/</outputDirectory>
</file>
<file>
- <source>doc/Summary_about_used_libraries.txt</source>
- <outputDirectory>/</outputDirectory>
- </file>
- <file>
<source>doc/Install.txt</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
<fileSets>
<fileSet>
- <directory>doc/upgrade</directory>
- <outputDirectory>/upgrade</outputDirectory>
- </fileSet>
- <fileSet>
<directory>doc/sql/upgrader</directory>
<outputDirectory>/upgrade</outputDirectory>
</fileSet>
View
48 distribution/doc/Summary_about_used_libraries.txt
@@ -1,48 +0,0 @@
-Agilefant employs several third party libraries, which are listed below.
-Agilefant itself doesn't directly use all these libraries, but their
-existence may be required by some other included library (e.g. Spring).
-
---------------------------
-spring-security: http://static.springframework.org/spring-security/site/
-spring-security-tiger:
-antlr: http://www.antlr.org/
-asm: http://asm.objectweb.org/
-asm-attrs: http://asm.objectweb.org/jdiff153to223/changes/pkg_org.objectweb.asm.attrs.html
-cglib: http://cglib.sourceforge.net/
-commons-beanutils: http://jakarta.apache.org/commons/beanutils/
-commons-codec: http://jakarta.apache.org/commons/codec/
-commons-collections: http://jakarta.apache.org/commons/collections/
-commons-dbcp: http://jakarta.apache.org/commons/dbcp/
-commons-lang: http://jakarta.apache.org/commons/lang/
-commons-logging: http://jakarta.apache.org/commons/logging/
-commons-pool: http://jakarta.apache.org/commons/pool/
-displytag: http://displaytag.sourceforge.net/
-dom4j: http://www.dom4j.org/
-ehcache: http://ehcache.sourceforge.net/
-ejb3-persistence:
-freemaker: http://freemarker.sourceforge.net/
-hibernate3: http://www.hibernate.org/
-hibernate-annotations: http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/
-javamail: http://java.sun.com/products/javamail/
-jcommon: http://www.jfree.org/jcommon/
-jfreechart: http://www.jfree.org/jfreechart/index.html
-jstl: http://java.sun.com/products/jsp/jstl/
-jstree: http://www.jstree.com/
-jta: http://java.sun.com/products/jta/
-log4j: http://logging.apache.org/log4j/docs/
-mysql-connector-java: http://www.mysql.com/products/connector/j/
-ognl: http://www.ognl.org/about.html
-oro: http://jakarta.apache.org/oro/
-oscore: http://www.opensymphony.com/oscore/
-postgresql-8.1-407.jdbc3:
-rife-continuations: http://rifers.org/wiki/display/RIFECNT/Home
-serializer: http://xml.apache.org
-spring: http://www.springframework.org/
-spring-mock:
-standard:
-webwork: http://www.opensymphony.com/webwork/
-xalan: http://xml.apache.org
-xercesimp: http://xml.apache.org
-xml-apis: http://xml.apache.org
-xwork: powering webwork, http://www.opensymphony.com/xwork/
-xwork-tiger: j2s2 5 support for webwork
View
8 distribution/doc/dev/Actions.txt
@@ -1,8 +0,0 @@
-TODO comments ekantola, kheleniu, jmrantal
-
- -How (for what) are the files in \src\...\agilefant\web\ (XXXAction.java) used?
- -Who calls, and what parts of the system are called from here.
- -Relating libraries?
-
- CRUDAction contains basic Actions such as create and delete, which are widely applicable.
-
View
6 distribution/doc/dev/DAOs.txt
@@ -1,6 +0,0 @@
-TODO comments kheleniu, tiaijala
- How the files in \db\ (XXXDAO.java) are used?
- Who calls, and what parts of the system is called from here).
- Relating libraries?
-
- DAO = Data Access Object
View
68 distribution/doc/dev/README_for_developers.txt
@@ -1,68 +0,0 @@
-README for AgilEfant developers
--------------------------------
-This document is intended for people who are interested in developing
-AgilEfant by fixing old bugs or adding new functionality. It mainly
-describes where to look for first and which files to put focus on.
-
-Before starting any development work with AgilEfant, one should familiarize
-himself with Cycles Of Control concept, Hibernate, WebWork, Spring and
-their configurations and with concepts like dependency injection and
-transaction management. Very good knowledge of J2EE is also required for
-good results.
-
-Directory structure
----
-Directory structure is self explaining enough for any experienced developer
-so there's no need to go it through here.
-
-Important configuration files
----
-- Hibernate
-When adding classes for Hibernate to be persisted, remember to add your class
-to also to conf/hibernate.cfg.xml so that Hibernate will use it to load
-mappings.
-
-- WebWork
-WebWork configuation is located in conf/classes/xwork.xml and
-conf/classes/webwork.properties. All classes used in xwork.xml are loaded
-using Spring as a object factory. This means that the classes are declared
-as a non-singleton beans in Springs application context. Read WebWork
-documentation for information.
-
-System wide converters are declared in xwork-conversion.properties.
-
-XWork annotations are used in certain classes. XWork 1.2.1 (current version when
-writing this) had all annotation classes missing @Retention annotation causing
-them not to work. web/WEB-INF/classes contains fixed binaries for required
-classes. This bug has been reported to OpenSymphony and will be fixed in
-XWork 1.2.1.
-
-- Spring
-Beans are initialized by reading all applicationContext*.xml files from conf.
-Suffix of the file tries to describe the area where it belongs. Feel free
-to add your own files if needed to keep configuration files small enough.
-
-Keep in mind that all WebWork classes (actions and interceptors) are
-configured in applicationContext-actions.xml. To avoid unnecessary
-configuration lines byName autowire strategy is used, so keep that in mind when
-declaring your own beans. Remember also that all actions MUST be
-declared as singleton set to false. Forgetting this makes same
-instance of class to be shared between all requests causing odd behaviour.
-
-Where to start
----
-Most of the actual business logic of AgilEfant is located in package
-fi.hut.soberit.agilefant.web. When adding new functionality, that's the
-place to start.
-
-
-
-
-
-
-
-
-
-
-
-
View
6 distribution/doc/dev/hibernate_DAOs.txt
@@ -1,6 +0,0 @@
-TODO comments kheleniu, tiaijala
- How the files in \db\hibernate\event (XXXDAOHibernate.java) are used?
- Who calls them, and what parts of the system is called from here?
- Relating ibraries?
-
- DAO = Data Access Object
View
5 distribution/doc/dev/tags.txt
@@ -1,5 +0,0 @@
-TODO comments kheleniu jmrantal
-
- Files in \web\tag\:
- What are the Tags for.
- Who uses them for what?
View
21 distribution/doc/upgrade/README.txt
@@ -1,21 +0,0 @@
-+-------------------------------+
-| NOTICE ON UPGRADING AGILEFANT |
-+-------------------------------+
-
-See http://www.agilefant.org/wiki/display/AEF/Upgrade+instructions for full
-upgrade instructions.
-
-If you are upgrading from a version older than 2.0, please upgrade to 2.0 first.
-
-
-NOTE!
-The script will generate a backup of your MySQL database. Please move it to a
-secure location after running the update.
-
-
-Windows:
- * In command prompt, run the agilefant_upgrader.bat
-
-Unix (Linux/OS X):
- * In terminal, run the agilefant_upgrader.sh
-
View
65 pom.xml
@@ -25,8 +25,8 @@
<glassfish.jstl.version>1.2</glassfish.jstl.version>
<guava.version>13.0.1</guava.version>
<h2.version>1.1.114</h2.version>
- <hibernate.version>3.5.3-Final</hibernate.version>
- <hibernate.validator.version>3.1.0.GA</hibernate.validator.version>
+ <hibernate.version>4.1.9.Final</hibernate.version>
+ <hibernate.validator.version>4.3.1.Final</hibernate.validator.version>
<httpclient.version>4.1.3</httpclient.version>
<javax.annotation.version>1.0</javax.annotation.version>
<javax.mail.version>1.4.5</javax.mail.version>
@@ -36,7 +36,6 @@
<jersey.version>1.17</jersey.version>
<jfreechart.version>1.0.14</jfreechart.version>
<joda.time.version>2.1</joda.time.version>
- <joda.time.hibernate.version>1.2</joda.time.hibernate.version>
<joda.time.jsptags.version>1.1.1</joda.time.jsptags.version>
<junit.version>4.11</junit.version>
<logback.version>1.0.9</logback.version>
@@ -47,8 +46,9 @@
<spring.version>3.2.1.RELEASE</spring.version>
<spring.security.version>3.1.3.RELEASE</spring.security.version>
<stringtemplate.version>3.0</stringtemplate.version>
- <struts.version>2.1.8.1</struts.version>
+ <struts.version>2.2.3.1</struts.version>
<typesafe.config.version>1.0.0</typesafe.config.version>
+ <usertype.version>3.0.0.GA</usertype.version>
<maven.compiler.version>3.0</maven.compiler.version>
<maven.war.version>2.3</maven.war.version>
@@ -199,37 +199,6 @@
</dependency>
<dependency>
<groupId>joda-time</groupId>
- <artifactId>joda-time-hibernate</artifactId>
- <version>${joda.time.hibernate.version}</version>
- <exclusions>
- <exclusion>
- <artifactId>antlr</artifactId>
- <groupId>antlr</groupId>
- </exclusion>
- <exclusion>
- <artifactId>cglib-full</artifactId>
- <groupId>cglib</groupId>
- </exclusion>
- <exclusion>
- <artifactId>commons-logging-api</artifactId>
- <groupId>commons-logging</groupId>
- </exclusion>
- <exclusion>
- <artifactId>hsqldb</artifactId>
- <groupId>hsqldb</groupId>
- </exclusion>
- <exclusion>
- <artifactId>ehcache</artifactId>
- <groupId>ehcache</groupId>
- </exclusion>
- <exclusion>
- <artifactId>hibernate</artifactId>
- <groupId>org.hibernate</groupId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>joda-time</groupId>
<artifactId>joda-time-jsptags</artifactId>
<version>${joda.time.jsptags.version}</version>
</dependency>
@@ -284,18 +253,18 @@
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts.version}</version>
+ <exclusions>
+ <exclusion>
+ <!-- Invalid groupId -->
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-junit-plugin</artifactId>
<version>${struts.version}</version>
- <exclusions>
- <!-- No longer exists in Spring >= 2.5 -->
- <exclusion>
- <groupId>org.springframework</groupId>
- <artifactId>spring-mock</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
@@ -316,13 +285,6 @@
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>${easymock.version}</version>
- <exclusions>
- <!-- Prevent duplicate cglib + cglib-nodep dependencies -->
- <exclusion>
- <groupId>cglib</groupId>
- <artifactId>cglib-nodep</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
@@ -381,6 +343,11 @@
<version>${hibernate.validator.version}</version>
</dependency>
<dependency>
+ <groupId>org.jadira.usertype</groupId>
+ <artifactId>usertype.core</artifactId>
+ <version>${usertype.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>${jfreechart.version}</version>
View
12 webapp/legacy/database-mysql5.properties
@@ -1,12 +0,0 @@
-#TODO comments ekantola - Hibernate uses this file if database in is MySql5(?)
-#(Where this is used, and, for what? One line of comment is good enough.
-
-hibernate.connection.username=agilefant
-hibernate.connection.password=agilefant
-hibernate.connection.url=jdbc:mysql://localhost/agilefant?relaxAutoCommit\=true&amp;autoReconnect\=true&amp;useUnicode\=true&amp;characterEncoding\=utf-8&amp;autoReconnectForPools\=true
-hibernate.connection.driver_class=com.mysql.jdbc.Driver
-hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
-hibernate.show_sql=false
-hibernate.max_fetch_depth=1
-#hibernate.hbm2ddl.auto=
-#hibernate.jdbc.batch_size=
View
82 webapp/legacy/hibernate.cfg.xml
@@ -1,82 +0,0 @@
-<?xml version='1.0' encoding='utf-8'?>
-<!DOCTYPE hibernate-configuration PUBLIC
-"-//Hibernate/Hibernate Configuration DTD//EN"
-"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
-
-
-
-<!-- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
- Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException:
- Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception
- is java.lang.ClassFormatError: Illegal class name "fi/hut/soberit/agilefant/model/package-info" in class file fi/hut/soberit/agilefant/model/package-info -->
-
-<hibernate-configuration>
- <session-factory name="hibernateSessionFactory">
- <!-- we need the package mapping to make package-info.java work, but it won't map all the package classes -->
- <property name="org.hibernate.envers.store_data_at_delete">true</property>
-
- <mapping package="fi.hut.soberit.agilefant.model" />
-
- <mapping class="fi.hut.soberit.agilefant.model.Assignment" />
- <mapping class="fi.hut.soberit.agilefant.model.Backlog" />
- <mapping class="fi.hut.soberit.agilefant.model.BacklogHistoryEntry" />
- <mapping class="fi.hut.soberit.agilefant.model.BacklogHourEntry" />
- <mapping class="fi.hut.soberit.agilefant.model.ExactEstimate" />
- <mapping class="fi.hut.soberit.agilefant.model.SignedExactEstimate" />
- <mapping class="fi.hut.soberit.agilefant.model.Iteration" />
- <mapping class="fi.hut.soberit.agilefant.model.IterationHistoryEntry" />
- <mapping class="fi.hut.soberit.agilefant.model.Label" />
- <mapping class="fi.hut.soberit.agilefant.model.Product" />
- <mapping class="fi.hut.soberit.agilefant.model.Project" />
- <mapping class="fi.hut.soberit.agilefant.model.Setting" />
- <mapping class="fi.hut.soberit.agilefant.model.Story" />
- <mapping class="fi.hut.soberit.agilefant.model.StoryHourEntry" />
- <mapping class="fi.hut.soberit.agilefant.model.Task" />
- <mapping class="fi.hut.soberit.agilefant.model.TaskHourEntry" />
- <mapping class="fi.hut.soberit.agilefant.model.Team" />
- <mapping class="fi.hut.soberit.agilefant.model.User" />
- <mapping class="fi.hut.soberit.agilefant.model.Holiday" />
- <mapping class="fi.hut.soberit.agilefant.model.HolidayAnomaly" />
- <mapping class="fi.hut.soberit.agilefant.model.AgilefantRevisionEntity" />
- <mapping class="fi.hut.soberit.agilefant.model.WhatsNextEntry" />
- <mapping class="fi.hut.soberit.agilefant.model.StoryRank" />
- <mapping class="fi.hut.soberit.agilefant.model.AgilefantWidget" />
- <mapping class="fi.hut.soberit.agilefant.model.WidgetCollection" />
- <mapping class="fi.hut.soberit.agilefant.model.StoryAccess" />
-
- <!-- <mapping class="fi.hut.soberit.agilefant.model.BusinessTheme" /> <mapping class="fi.hut.soberit.agilefant.model.BacklogThemeBinding" /> -->
-
-
- <!-- Activate hibernate validation: these listeners will raise an exception if an annotation validation constraint is violated. -->
- <event type="pre-update">
- <listener class="org.hibernate.validator.event.ValidatePreUpdateEventListener" />
- </event>
- <event type="pre-insert">
- <listener class="org.hibernate.validator.event.ValidatePreInsertEventListener" />
- </event>
-
- <!-- Envers version listeners -->
-
- <event type="post-insert">
- <listener class="org.hibernate.envers.event.AuditEventListener" />
- <listener class="fi.hut.soberit.agilefant.db.hibernate.notification.NotificationEventListener" />
- </event>
- <event type="post-update">
- <listener class="org.hibernate.envers.event.AuditEventListener" />
- <listener class="fi.hut.soberit.agilefant.db.hibernate.notification.NotificationEventListener" />
- </event>
- <event type="post-delete">
- <listener class="org.hibernate.envers.event.AuditEventListener" />
- <listener class="fi.hut.soberit.agilefant.db.hibernate.notification.NotificationEventListener" />
- </event>
- <event type="pre-collection-update">
- <listener class="org.hibernate.envers.event.AuditEventListener" />
- </event>
- <event type="pre-collection-remove">
- <listener class="org.hibernate.envers.event.AuditEventListener" />
- </event>
- <event type="post-collection-recreate">
- <listener class="org.hibernate.envers.event.AuditEventListener" />
- </event>
- </session-factory>
-</hibernate-configuration>
View
14 webapp/pom.xml
@@ -75,10 +75,6 @@
</dependency>
<dependency>
<groupId>joda-time</groupId>
- <artifactId>joda-time-hibernate</artifactId>
- </dependency>
- <dependency>
- <groupId>joda-time</groupId>
<artifactId>joda-time-jsptags</artifactId>
</dependency>
<dependency>
@@ -142,6 +138,16 @@
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
+ <groupId>org.jadira.usertype</groupId>
+ <artifactId>usertype.core</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.joda</groupId>
+ <artifactId>joda-money</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
</dependency>
View
27 webapp/src/main/java/fi/hut/soberit/agilefant/business/impl/SettingBusinessImpl.java
@@ -12,7 +12,11 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.support.TransactionCallbackWithoutResult;
+import org.springframework.transaction.support.TransactionTemplate;
import fi.hut.soberit.agilefant.business.SettingBusiness;
import fi.hut.soberit.agilefant.db.SettingDAO;
@@ -53,21 +57,32 @@ public SettingBusinessImpl() {
@Autowired
private SettingDAO settingDAO;
+ @Autowired
+ private PlatformTransactionManager transactionManager;
private Map<String,Setting> settingCache = new HashMap<String, Setting>();
-
public void setSettingDAO(SettingDAO settingDAO) {
this.genericDAO = settingDAO;
this.settingDAO = settingDAO;
}
-
+
+ public void setTransactionManager(PlatformTransactionManager transactionManager) {
+ this.transactionManager = transactionManager;
+ }
+
@PostConstruct
public void loadSettingCache() {
this.settingCache.clear();
- Collection<Setting> allSettings = this.settingDAO.getAll();
- for(Setting setting : allSettings) {
- this.settingCache.put(setting.getName(), setting);
- }
+ TransactionTemplate tx = new TransactionTemplate(transactionManager);
+ tx.execute(new TransactionCallbackWithoutResult() {
+ @Override
+ protected void doInTransactionWithoutResult(TransactionStatus ts) {
+ Collection<Setting> allSettings = settingDAO.getAll();
+ for(Setting setting : allSettings) {
+ settingCache.put(setting.getName(), setting);
+ }
+ }
+ });
}
@Transactional(readOnly = true)
View
6 webapp/src/main/java/fi/hut/soberit/agilefant/config/DaoConfiguration.java
@@ -10,7 +10,7 @@
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader;
-import org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean;
+import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import com.googlecode.flyway.core.Flyway;
import com.typesafe.config.Config;
@@ -44,11 +44,11 @@ public DatabaseInitializer databaseInitializer() {
}
@Bean
- public AnnotationSessionFactoryBean sessionFactory() throws Exception {
+ public LocalSessionFactoryBean sessionFactory() throws Exception {
flyway();
databaseInitializer();
- AnnotationSessionFactoryBean bean = new AnnotationSessionFactoryBean();
+ LocalSessionFactoryBean bean = new LocalSessionFactoryBean();
bean.setConfigLocation(resourceLoader.getResource("/WEB-INF/hibernate.cfg.xml"));
bean.setDataSource(dataSource);
View
2  webapp/src/main/java/fi/hut/soberit/agilefant/config/TransactionConfiguration.java
@@ -6,7 +6,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.orm.hibernate3.HibernateTransactionManager;
+import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;
View
2  webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/AssignmentDAOHibernate.java
@@ -23,7 +23,7 @@ public AssignmentDAOHibernate() {
public List<Assignment> assigmentsInBacklogTimeframe(Interval interval,
User user) {
- Criteria crit = getCurrentSession().createCriteria(Assignment.class);
+ Criteria crit = this.createCriteria(Assignment.class);
Criteria backlog = crit.createCriteria("backlog");
crit.createCriteria("user").add(Restrictions.idEq(user.getId()));
DateTime startDate = interval.getStart();
View
15 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/BacklogDAOHibernate.java
@@ -29,22 +29,21 @@ public BacklogDAOHibernate() {
/** {@inheritDoc} */
public int getNumberOfChildren(Backlog backlog) {
- Criteria criteria = getCurrentSession().createCriteria(Backlog.class);
+ Criteria criteria = this.createCriteria(Backlog.class);
criteria.add(Restrictions.idEq(backlog.getId()));
criteria.createCriteria("children");
criteria.setProjection(Projections.rowCount());
- return ((Long) criteria.list().get(0)).intValue();
+ return ((Long)this.asList(criteria).get(0)).intValue();
}
@SuppressWarnings("unchecked")
public List<Object[]> getResponsiblesByBacklog(Backlog backlog) {
String hql = "from Story as story left outer join story.responsibles as resp WHERE story.backlog = ?";
- return (List<Object[]>) hibernateTemplate.find(hql,
- new Object[] { backlog });
+ return this.asTuplesList(this.getCurrentSession().createQuery(hql).setEntity(0, backlog));
}
public int calculateStoryPointSum(int iterationId) {
- Criteria crit = getCurrentSession().createCriteria(Story.class);
+ Criteria crit = this.createCriteria(Story.class);
crit.setProjection(Projections.sum("storyPoints"));
crit.createCriteria("iteration").add(Restrictions.idEq(iterationId));
Long result = uniqueResult(crit);
@@ -53,7 +52,7 @@ public int calculateStoryPointSum(int iterationId) {
}
public int calculateDoneStoryPointSum(int iterationId) {
- Criteria crit = getCurrentSession().createCriteria(Story.class);
+ Criteria crit = this.createCriteria(Story.class);
crit.setProjection(Projections.sum("storyPoints"));
crit.createCriteria("iteration").add(Restrictions.idEq(iterationId));
crit.add(Restrictions.eq("state", StoryState.DONE));
@@ -68,7 +67,7 @@ public int calculateDoneStoryPointSum(int iterationId) {
}
public List<Backlog> searchByName(String name, Class<?> type) {
- Criteria crit = getCurrentSession().createCriteria(type);
+ Criteria crit = this.createCriteria(type);
crit.add(Restrictions.like("name", name, MatchMode.ANYWHERE));
crit.addOrder(Order.asc("class"));
crit.addOrder(Order.asc("name"));
@@ -77,7 +76,7 @@ public int calculateDoneStoryPointSum(int iterationId) {
}
public Collection<Backlog> retrieveStandaloneIterations() {
- Criteria crit = getCurrentSession().createCriteria(Backlog.class);
+ Criteria crit = this.createCriteria(Backlog.class);
crit.add(Restrictions.sqlRestriction("{alias}.parent_id is NULL"));
crit.add(Restrictions.sqlRestriction("{alias}.backlogType like 'Iteration'"));
crit.setMaxResults(SearchBusiness.MAX_RESULTS_PER_TYPE);
View
4 .../src/main/java/fi/hut/soberit/agilefant/db/hibernate/BacklogHistoryEntryDAOHibernate.java
@@ -23,7 +23,7 @@ public BacklogHistoryEntryDAOHibernate() {
}
public BacklogHistoryEntry retrieveLatest(DateTime timestamp, int backlogId) {
- Criteria crit = getCurrentSession().createCriteria(
+ Criteria crit = this.createCriteria(
BacklogHistoryEntry.class);
crit.add(Restrictions.eq("backlog.id", backlogId));
crit.add(Restrictions.le("timestamp", timestamp));
@@ -33,7 +33,7 @@ public BacklogHistoryEntry retrieveLatest(DateTime timestamp, int backlogId) {
}
public ProjectBurnupData retrieveBurnupData(int projectId) {
- Criteria crit = getCurrentSession().createCriteria(
+ Criteria crit = this.createCriteria(
BacklogHistoryEntry.class);
crit.add(Restrictions.eq("backlog.id", projectId));
crit.addOrder(Order.asc("timestamp"));
View
11 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/BacklogHourEntryDAOHibernate.java
@@ -2,7 +2,7 @@
import java.util.List;
-import org.hibernate.criterion.DetachedCriteria;
+import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
@@ -20,12 +20,9 @@ public BacklogHourEntryDAOHibernate() {
@SuppressWarnings("unchecked")
public List<BacklogHourEntry> retrieveByBacklog(Backlog target) {
- DetachedCriteria criteria = DetachedCriteria.forClass(this
- .getPersistentClass());
- criteria.add(Restrictions.eq("backlog", target));
-
- return (List<BacklogHourEntry>) hibernateTemplate
- .findByCriteria(criteria);
+ Criteria criteria = this.createCriteria(this.getPersistentClass());
+ criteria.add(Restrictions.eq("backlog", target));
+ return this.asList(criteria);
}
}
View
11 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/Email.java
@@ -6,7 +6,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.hibernate.validator.ValidatorClass;
+import javax.validation.Constraint;
+import javax.validation.Payload;
/**
* Annotation to enable our hibernate custom email validator.
@@ -15,10 +16,14 @@
* @see fi.fi.hut.soberit.agilefant.db.hibernate.EmailValidator
*/
@Documented
-@ValidatorClass(EmailValidator.class)
+@Constraint(validatedBy = EmailValidator.class)
// bind to EmailValidator
-@Target( { ElementType.METHOD, ElementType.FIELD })
+@Target({ ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
public @interface Email {
String message() default "is not a proper email address";
+
+ Class<? extends Payload>[] payload() default {};
+
+ Class<?>[] groups() default {};
}
View
31 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/EmailValidator.java
@@ -2,7 +2,10 @@
import java.io.Serializable;
-import org.hibernate.validator.Validator;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+import com.google.common.base.Strings;
/**
* Implementation of the email validator. When using the email annotation in the
@@ -12,31 +15,19 @@
* @author Turkka Äijälä
* @see fi.fi.hut.soberit.agilefant.db.hibernate.Email
*/
-public class EmailValidator implements Validator<Email>, Serializable {
+public class EmailValidator implements ConstraintValidator<Email, String>, Serializable {
private static final long serialVersionUID = 4334203403474352735L;
+ @Override
public void initialize(Email parameters) {
}
- public boolean isValid(Object value) {
-
- // nulls qualify
- if (value == null)
- return true;
-
- // non-string objects don't qualify
- if (!(value instanceof String))
- return false;
-
- String string = (String) value;
-
- // empty strings qualify
- if (string.equals(""))
+ @Override
+ public boolean isValid(String value, ConstraintValidatorContext context) {
+ if (Strings.isNullOrEmpty(value))
return true;
-
- // use commons-validator to validate email addresses
- return org.apache.commons.validator.EmailValidator.getInstance()
- .isValid(string);
+ return org.apache.commons.validator.routines.EmailValidator.getInstance().isValid(value);
}
+
}
View
116 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/EnumUserType.java
@@ -1,116 +0,0 @@
-package fi.hut.soberit.agilefant.db.hibernate;
-
-import java.io.Serializable;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.Properties;
-
-import org.hibernate.HibernateException;
-import org.hibernate.MappingException;
-import org.hibernate.usertype.ParameterizedType;
-import org.hibernate.usertype.UserType;
-
-public class EnumUserType implements UserType, ParameterizedType {
-
- public static final String USE_ORDINAL_PARAM = "useOrdinal";
-
- public static final String ENUM_CLASS_NAME = "enumClassName";
-
- @SuppressWarnings("unchecked")
- private Class<Enum> clazz = null;
-
- private boolean useOrdinal;
-
- private static final int[] VARCHAR_SQL_TYPES = { Types.VARCHAR };
-
- private static final int[] INT_SQL_TYPES = { Types.INTEGER };
-
- @SuppressWarnings("unchecked")
- public Class returnedClass() {
- return clazz;
- }
-
- @SuppressWarnings("unchecked")
- public void setParameterValues(Properties params) {
- String enumClassName = params.getProperty(ENUM_CLASS_NAME);
- try {
- clazz = (Class<Enum>) Class.forName(enumClassName);
- } catch (Exception e) {
- throw new MappingException("Failed to create class "
- + enumClassName + ". Check param " + ENUM_CLASS_NAME);
- }
- useOrdinal = "true".equalsIgnoreCase(params
- .getProperty(USE_ORDINAL_PARAM));
- }
-
- public int[] sqlTypes() {
- return useOrdinal ? INT_SQL_TYPES : VARCHAR_SQL_TYPES;
- }
-
- @SuppressWarnings("unchecked")
- public Object nullSafeGet(ResultSet rs, String[] names, Object obj)
- throws HibernateException, SQLException {
- if (useOrdinal) {
- int ordinal = rs.getInt(names[0]);
- if (rs.wasNull()) {
- return null;
- } else {
- return clazz.getEnumConstants()[ordinal];
- }
- } else {
- String value = rs.getString(names[0]);
- if (rs.wasNull()) {
- return null;
- } else {
- return Enum.valueOf(clazz, value);
- }
- }
- }
-
- public void nullSafeSet(PreparedStatement stmt, Object obj, int index)
- throws HibernateException, SQLException {
- if (obj == null) {
- stmt.setNull(index, this.sqlTypes()[0]);
- } else if (useOrdinal) {
- stmt.setInt(index, ((Enum<?>) obj).ordinal());
- } else {
- stmt.setString(index, ((Enum<?>) obj).name());
- }
- }
-
- public Object assemble(Serializable cached, Object obj)
- throws HibernateException {
- return cached;
- }
-
- public Object deepCopy(Object obj) throws HibernateException {
- return obj;
- }
-
- public Serializable disassemble(Object obj) throws HibernateException {
- return (Serializable) obj;
- }
-
- public int hashCode(Object x) throws HibernateException {
- return x.hashCode();
- }
-
- public boolean equals(Object x, Object y) throws HibernateException {
- if (x == y)
- return true;
- if (null == x || null == y)
- return false;
- return x.equals(y);
- }
-
- public boolean isMutable() {
- return false;
- }
-
- public Object replace(Object obj, Object obj1, Object obj2)
- throws HibernateException {
- return obj;
- }
-}
View
61 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/GenericDAOHibernate.java
@@ -9,13 +9,12 @@
import javax.annotation.PostConstruct;
import org.hibernate.Criteria;
+import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
-import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.orm.hibernate3.HibernateTemplate;
import fi.hut.soberit.agilefant.db.GenericDAO;
@@ -36,8 +35,6 @@
protected SessionFactory sessionFactory;
- protected HibernateTemplate hibernateTemplate;
-
@PostConstruct
public void init() {
if (sessionFactory == null) {
@@ -48,7 +45,6 @@ public void init() {
@Autowired
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
- this.hibernateTemplate = new HibernateTemplate(sessionFactory);
}
protected GenericDAOHibernate(Class<T> clazz) {
@@ -61,7 +57,7 @@ protected GenericDAOHibernate(Class<T> clazz) {
/** {@inheritDoc} */
public T get(int id) {
- return hibernateTemplate.get(this.getPersistentClass(), id);
+ return (T) this.getCurrentSession().get(getPersistentClass(), id);
}
/** {@inheritDoc} */
@@ -70,18 +66,18 @@ public T getAndDetach(int id) {
this.sessionFactory.getCurrentSession().evict(object);
return object;
}
-
+
/** {@inheritDoc} */
- public List<T> getAll() {
- return hibernateTemplate.loadAll(getPersistentClass());
+ public Collection<T> getAll() {
+ return this.asList(this.createCriteria(this.getPersistentClass()));
}
-
+
/** {@inheritDoc} */
public Collection<T> getMultiple(Collection<Integer> ids) {
if (ids == null || ids.isEmpty()) {
return new HashSet<T>();
}
- Criteria c = getCurrentSession().createCriteria(getPersistentClass());
+ Criteria c = this.createCriteria(getPersistentClass());
c.add(Restrictions.in("id", ids));
return asCollection(c);
}
@@ -93,17 +89,17 @@ public void remove(int id) {
/** {@inheritDoc} */
public void remove(T object) {
- hibernateTemplate.delete(object);
+ this.getCurrentSession().delete(object);
}
/** {@inheritDoc} */
public void store(T object) {
- hibernateTemplate.saveOrUpdate(object);
+ this.getCurrentSession().saveOrUpdate(object);
}
/** {@inheritDoc} */
public Serializable create(T object) {
- return hibernateTemplate.save(object);
+ return this.getCurrentSession().save(object);
}
protected T getFirst(Collection<T> list) {
@@ -113,30 +109,31 @@ protected T getFirst(Collection<T> list) {
return list.iterator().next();
}
- protected <ResultType> ResultType getFirstTypeSafe(
- Collection<ResultType> list) {
+ protected <ResultType> ResultType getFirstTypeSafe(Collection<ResultType> list) {
if (list == null || list.isEmpty()) {
return null;
}
return list.iterator().next();
}
- protected DetachedCriteria createCriteria() {
- return DetachedCriteria.forClass(this.getPersistentClass());
+ protected Criteria createCriteria(Class clazz) {
+ return this.getCurrentSession().createCriteria(clazz);
+ }
+
+ protected Criteria createCriteria(Class clazz, String alias) {
+ return this.getCurrentSession().createCriteria(clazz, alias);
}
public int count() {
- DetachedCriteria criteria = createCriteria().setProjection(
- Projections.rowCount());
- return ((Long) hibernateTemplate.findByCriteria(criteria).get(0))
- .intValue();
+ Criteria criteria = this.createCriteria(this.getPersistentClass());
+ criteria.setProjection(Projections.rowCount());
+ return ((Long) this.uniqueResult(criteria)).intValue();
}
public boolean exists(int id) {
- DetachedCriteria crit = createCriteria().add(Restrictions.idEq(id))
- .setProjection(Projections.rowCount());
- return ((Long) hibernateTemplate.findByCriteria(crit).get(0))
- .intValue() > 0;
+ Criteria criteria = this.createCriteria(this.getPersistentClass());
+ criteria.add(Restrictions.idEq(id)).setProjection(Projections.rowCount());
+ return ((Long) this.uniqueResult(criteria)).intValue() > 0;
}
public Session getCurrentSession() {
@@ -145,7 +142,7 @@ public Session getCurrentSession() {
@SuppressWarnings("unchecked")
protected <ResultType> Collection<ResultType> asCollection(Criteria criteria) {
- Collection<ResultType> list = criteria.list();
+ Collection<ResultType> list = this.asList(criteria);
if (list == null) {
return Collections.EMPTY_LIST;
}
@@ -171,4 +168,14 @@ public Session getCurrentSession() {
return (ResultType) criteria.uniqueResult();
}
+ @SuppressWarnings("unchecked")
+ protected List<T> asList(Query query) {
+ return query.list();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected List<Object[]> asTuplesList(Query query) {
+ return query.list();
+ }
+
}
View
2  webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/HolidayDAOHibernate.java
@@ -22,7 +22,7 @@ public HolidayDAOHibernate() {
}
public List<Holiday> retrieveFutureHolidaysByUser(User user) {
- Criteria crit = sessionFactory.getCurrentSession().createCriteria(Holiday.class);
+ Criteria crit = this.createCriteria(Holiday.class);
crit.add(Restrictions.eq("user", user));
crit.add(Restrictions.ge("endDate", new DateTime()));
crit.addOrder(Order.asc("startDate"));
View
56 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/HourEntryDAOHibernate.java
@@ -33,11 +33,11 @@ public HourEntryDAOHibernate() {
public long calculateSumByUserAndTimeInterval(int userId,
DateTime startDate, DateTime endDate) {
- Criteria crit = getCurrentSession().createCriteria(HourEntry.class);
+ Criteria crit = this.createCriteria(HourEntry.class);
crit.createCriteria("user").add(Restrictions.idEq(userId));
crit.add(Restrictions.between("date", startDate, endDate));
crit.setProjection(Projections.sum("minutesSpent"));
- Long result = (Long) crit.uniqueResult();
+ Long result = (Long) this.uniqueResult(crit);
if (result == null)
return 0;
return result;
@@ -45,13 +45,13 @@ public long calculateSumByUserAndTimeInterval(int userId,
private long calculateHourSum(boolean task, int storyId) {
Class<?> type = task ? TaskHourEntry.class : StoryHourEntry.class;
- Criteria crit = getCurrentSession().createCriteria(type);
+ Criteria crit = this.createCriteria(type);
crit.setProjection(Projections.sum("minutesSpent"));
if (task)
crit = crit.createCriteria("task");
crit = crit.createCriteria("story").add(Restrictions.idEq(storyId))
.add(Restrictions.ne("state", TaskState.DEFERRED));
- Long result = (Long) crit.uniqueResult();
+ Long result = (Long) this.uniqueResult(crit);
if (result == null)
return 0;
@@ -64,13 +64,13 @@ public long calculateSumByStory(int storyId) {
}
public long calculateSumFromTasksWithoutStory(int iterationId) {
- Criteria crit = getCurrentSession().createCriteria(TaskHourEntry.class);
+ Criteria crit = this.createCriteria(TaskHourEntry.class);
crit.setProjection(Projections.sum("minutesSpent"));
Criteria taskCrit = crit.createCriteria("task");
taskCrit.add(Restrictions.isNull("story"));
taskCrit.createCriteria("iteration")
.add(Restrictions.idEq(iterationId));
- Long result = (Long) crit.uniqueResult();
+ Long result = (Long) this.uniqueResult(crit);
if (result == null)
return 0;
return result;
@@ -96,8 +96,7 @@ private void setDateUserFilter(Criteria crit, DateTime start, DateTime end,
if (backlogIds == null || backlogIds.size() == 0) {
return Collections.emptyList();
}
- Criteria crit = getCurrentSession().createCriteria(
- BacklogHourEntry.class);
+ Criteria crit = this.createCriteria(BacklogHourEntry.class);
crit.createAlias("backlog", "bl", CriteriaSpecification.LEFT_JOIN);
crit.createAlias("backlog.parent", "blParent",
CriteriaSpecification.LEFT_JOIN);
@@ -118,8 +117,7 @@ private void setDateUserFilter(Criteria crit, DateTime start, DateTime end,
return Collections.emptyList();
}
- Criteria crit = getCurrentSession()
- .createCriteria(StoryHourEntry.class);
+ Criteria crit = this.createCriteria(StoryHourEntry.class);
crit.createAlias("story.iteration", "iteration",
CriteriaSpecification.LEFT_JOIN);
crit.createAlias("story.backlog", "backlog",
@@ -142,7 +140,7 @@ private void setDateUserFilter(Criteria crit, DateTime start, DateTime end,
return Collections.emptyList();
}
- Criteria crit = getCurrentSession().createCriteria(TaskHourEntry.class);
+ Criteria crit = this.createCriteria(TaskHourEntry.class);
String[] backlogs = { "iteration", "backlog", "backlogParent",
"task_without_story_iteration", "task_without_story_project",
@@ -187,8 +185,7 @@ public long calculateIterationHourEntriesSum(int iterationId) {
private List<HourEntry> getHourEntriesForTaskWithoutStoryForIteration(
int iterationId) {
- Criteria criteria = getCurrentSession().createCriteria(
- TaskHourEntry.class);
+ Criteria criteria = this.createCriteria(TaskHourEntry.class);
criteria = criteria.createCriteria("task");
criteria.add(Restrictions.isNull("story"));
@@ -200,8 +197,7 @@ public long calculateIterationHourEntriesSum(int iterationId) {
private long getSumForTaskHourEntriesWithoutStoryForIteration(
int iterationId) {
- Criteria criteria = getCurrentSession().createCriteria(
- TaskHourEntry.class);
+ Criteria criteria = this.createCriteria(TaskHourEntry.class);
criteria.setProjection(Projections.sum("minutesSpent"));
@@ -220,8 +216,7 @@ private long getSumForTaskHourEntriesWithoutStoryForIteration(
private List<HourEntry> getHourEntriesForTaskWithStoryForIteration(
int iterationId) {
- Criteria criteria = getCurrentSession().createCriteria(
- TaskHourEntry.class);
+ Criteria criteria = this.createCriteria(TaskHourEntry.class);
criteria = criteria.createCriteria("task");
criteria.add(Restrictions.isNotNull("story"));
@@ -233,8 +228,7 @@ private long getSumForTaskHourEntriesWithoutStoryForIteration(
}
private long getSumForTaskHourEntriesWithStoryForIteration(int iterationId) {
- Criteria criteria = getCurrentSession().createCriteria(
- TaskHourEntry.class);
+ Criteria criteria = this.createCriteria(TaskHourEntry.class);
criteria.setProjection(Projections.sum("minutesSpent"));
@@ -253,8 +247,7 @@ private long getSumForTaskHourEntriesWithStoryForIteration(int iterationId) {
}
private List<HourEntry> getHourEntriesForStoryForIteration(int iterationId) {
- Criteria criteria = getCurrentSession().createCriteria(
- StoryHourEntry.class);
+ Criteria criteria = this.createCriteria(StoryHourEntry.class);
criteria = criteria.createCriteria("story");
criteria = criteria.createCriteria("iteration");
@@ -264,8 +257,7 @@ private long getSumForTaskHourEntriesWithStoryForIteration(int iterationId) {
}
private long getSumForStoryHourEntriesForIteration(int iterationId) {
- Criteria criteria = getCurrentSession().createCriteria(
- StoryHourEntry.class);
+ Criteria criteria = this.createCriteria(StoryHourEntry.class);
criteria.setProjection(Projections.sum("minutesSpent"));
@@ -282,8 +274,7 @@ private long getSumForStoryHourEntriesForIteration(int iterationId) {
}
private long getSumForBacklogHourEntriesForIteration(int iterationId) {
- Criteria criteria = getCurrentSession().createCriteria(
- BacklogHourEntry.class);
+ Criteria criteria = this.createCriteria(BacklogHourEntry.class);
criteria.setProjection(Projections.sum("minutesSpent"));
@@ -310,8 +301,7 @@ public long calculateSumByUserAndTimeInterval(User user,
public List<HourEntry> getHourEntriesByFilter(DateTime startTime,
DateTime endTime, int userId) {
- Criteria crit = this.getCurrentSession()
- .createCriteria(HourEntry.class);
+ Criteria crit = this.createCriteria(HourEntry.class);
if (startTime != null) {
crit.add(Restrictions.ge("date", startTime));
}
@@ -336,8 +326,7 @@ public long calculateSumByUserAndTimeInterval(User user,
}
public List<HourEntry> getBacklogHourEntries(int backlogId, int limit) {
- Criteria crit = getCurrentSession().createCriteria(
- BacklogHourEntry.class);
+ Criteria crit = this.createCriteria(BacklogHourEntry.class);
crit.add(Restrictions.eq("backlog.id", backlogId));
crit.addOrder(Order.desc("date"));
if (limit > 0) {
@@ -347,7 +336,7 @@ public long calculateSumByUserAndTimeInterval(User user,
}
public List<HourEntry> getTaskHourEntries(int taskId, int limit) {
- Criteria crit = getCurrentSession().createCriteria(TaskHourEntry.class);
+ Criteria crit = this.createCriteria(TaskHourEntry.class);
crit.add(Restrictions.eq("task.id", taskId));
crit.addOrder(Order.desc("date"));
if (limit > 0) {
@@ -357,8 +346,7 @@ public long calculateSumByUserAndTimeInterval(User user,
}
public List<HourEntry> getStoryHourEntries(int storyId, int limit) {
- Criteria crit = getCurrentSession()
- .createCriteria(StoryHourEntry.class);
+ Criteria crit = this.createCriteria(StoryHourEntry.class);
crit.add(Restrictions.eq("story.id", storyId));
crit.addOrder(Order.desc("date"));
if (limit > 0) {
@@ -369,7 +357,7 @@ public long calculateSumByUserAndTimeInterval(User user,
public List<HourEntry> retrieveByUserAndInterval(User user,
Interval interval) {
- Criteria crit = getCurrentSession().createCriteria(HourEntry.class);
+ Criteria crit = this.createCriteria(HourEntry.class);
crit.add(Restrictions.eq("user", user));
crit.add(Restrictions.between("date", interval.getStart(),
interval.getEnd()));
@@ -379,7 +367,7 @@ public long calculateSumByUserAndTimeInterval(User user,
@Override
public long retrieveLatestHourEntryDelta(int userId) {
- Criteria crit = getCurrentSession().createCriteria(HourEntry.class);
+ Criteria crit = this.createCriteria(HourEntry.class);
crit.add(Restrictions.eq("user.id", userId));
crit.addOrder(Order.desc("date"));
crit.setMaxResults(1);
View
41 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/IterationDAOHibernate.java
@@ -54,12 +54,12 @@ private Criteria addIterationRestriction(Criteria criteria,
}
public List<Task> getAllTasksForIteration(Iteration iteration) {
- Criteria storyTaskCrit = getCurrentSession().createCriteria(Task.class);
+ Criteria storyTaskCrit = this.createCriteria(Task.class);
storyTaskCrit.setFetchMode("iteration",FetchMode.SELECT);
storyTaskCrit = storyTaskCrit.createCriteria("story").createCriteria("iteration");
storyTaskCrit.add(Restrictions.idEq(iteration.getId()));
- Criteria tasksWoStoryCrit = getCurrentSession().createCriteria(Task.class);
+ Criteria tasksWoStoryCrit = this.createCriteria(Task.class);
tasksWoStoryCrit.setFetchMode("story", FetchMode.SELECT);
tasksWoStoryCrit = tasksWoStoryCrit.createCriteria("iteration");
tasksWoStoryCrit.add(Restrictions.idEq(iteration.getId()));
@@ -74,7 +74,7 @@ private Criteria addIterationRestriction(Criteria criteria,
}
public Map<StoryState, Integer> countIterationStoriesByState(int iterationId) {
- Criteria criteria = getCurrentSession().createCriteria(Story.class);
+ Criteria criteria = this.createCriteria(Story.class);
criteria.add(Restrictions.eq("iteration.id", iterationId));
criteria.setProjection(Projections.projectionList().add(
Projections.property("state")).add(Projections.rowCount(),
@@ -100,7 +100,7 @@ private Criteria addIterationRestriction(Criteria criteria,
private Pair<Integer, Integer> getGenericCountDoneNonDeferred(Class<?> type,
Collection<String> joins, Iteration iteration) {
- Criteria criteria = getCurrentSession().createCriteria(type);
+ Criteria criteria = this.createCriteria(type);
criteria.setProjection(Projections.projectionList().add(
Projections.property("state")).add(Projections.rowCount(),
"taskCount").add(Projections.groupProperty("state"), "state"));
@@ -119,7 +119,7 @@ private Criteria addIterationRestriction(Criteria criteria,
private Pair<Integer, Integer> getCounOfDoneAndAllNonDeffered(Class<?> type,
Object doneValue, Collection<String> joins, Iteration iteration) {
- Criteria criteria = getCurrentSession().createCriteria(type);
+ Criteria criteria = this.createCriteria(type);
criteria.setProjection(Projections.projectionList().add(
Projections.property("state")).add(Projections.rowCount(),
"taskCount").add(Projections.groupProperty("state"), "state"));
@@ -192,7 +192,7 @@ else if(task.getStory() == null && task.getState() != TaskState.DEFERRED) {
if (iterationIds == null || iterationIds.size() == 0) {
return Collections.emptyMap();
}
- Criteria crit = getCurrentSession().createCriteria(Iteration.class);
+ Criteria crit = this.createCriteria(Iteration.class);
crit.add(Restrictions.in("id", iterationIds));
crit.createAlias("assignments", "assignments");
crit.setProjection(Projections.projectionList().add(
@@ -208,7 +208,7 @@ else if(task.getStory() == null && task.getState() != TaskState.DEFERRED) {
public List<Iteration> retrieveEmptyIterationsWithPlannedSize(
DateTime startDate, DateTime endDate, User assignee) {
- Criteria crit = getCurrentSession().createCriteria(Iteration.class);
+ Criteria crit = this.createCriteria(Iteration.class);
// interval limitations
Criterion startDateLimit = Restrictions.between("startDate", startDate,
@@ -238,20 +238,20 @@ else if(task.getStory() == null && task.getState() != TaskState.DEFERRED) {
public List<Iteration> retrieveCurrentAndFutureIterationsAt(DateTime point) {
- Criteria crit = getCurrentSession().createCriteria(Iteration.class);
+ Criteria crit = this.createCriteria(Iteration.class);
crit.add(Restrictions.ge("endDate", point));
return asList(crit);
}
public List<Iteration> retrieveAllStandAloneIterations() {
- final Criteria crit = getCurrentSession().createCriteria(Iteration.class);
+ final Criteria crit = this.createCriteria(Iteration.class);
crit.add(Restrictions.isNull("parent"));
crit.addOrder(Order.asc("name"));
return asList(crit);
}
public Iteration retrieveDeep(int iterationId) {
- Criteria crit = getCurrentSession().createCriteria(Iteration.class);
+ Criteria crit = this.createCriteria(Iteration.class);
//doesn't work: will cause the same task responsible to be inserted too many times
//Criteria iterationTasksCrit = crit.createCriteria("tasks", CriteriaSpecification.LEFT_JOIN);
@@ -271,13 +271,13 @@ public Iteration retrieveDeep(int iterationId) {
crit.add(Restrictions.idEq(iterationId));
crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
- return (Iteration) crit.uniqueResult();
+ return this.uniqueResult(crit);
}
public Map<Integer, StoryMetrics> calculateIterationDirectStoryMetrics(
Iteration iteration) {
- Criteria taskMetrics = this.getCurrentSession().createCriteria(
+ Criteria taskMetrics = this.createCriteria(
Task.class);
taskMetrics.add(Restrictions.ne("state", TaskState.DEFERRED));
taskMetrics.createCriteria("story", "story").add(
@@ -288,7 +288,7 @@ public Iteration retrieveDeep(int iterationId) {
taskSums.add(Projections.sum("originalEstimate"));
taskMetrics.setProjection(taskSums);
- Criteria storySpentEffort = this.getCurrentSession().createCriteria(
+ Criteria storySpentEffort = this.createCriteria(
StoryHourEntry.class);
storySpentEffort.createCriteria("story", "story").add(
Restrictions.eq("iteration", iteration));
@@ -297,7 +297,7 @@ public Iteration retrieveDeep(int iterationId) {
storySpentEffortSums.add(Projections.sum("minutesSpent"));
storySpentEffort.setProjection(storySpentEffortSums);
- Criteria taskSpentEffort = this.getCurrentSession().createCriteria(
+ Criteria taskSpentEffort = this.createCriteria(
TaskHourEntry.class);
taskSpentEffort.createCriteria("task", "task").createCriteria("story",
"story").add(Restrictions.eq("iteration", iteration));
@@ -343,7 +343,7 @@ public Iteration retrieveDeep(int iterationId) {
}
public Map<Integer, Long> calculateIterationTaskEffortSpent(Iteration iteration) {
- Criteria crit = getCurrentSession().createCriteria(TaskHourEntry.class);
+ Criteria crit = this.createCriteria(TaskHourEntry.class);
Criteria taskCrit = crit.createCriteria("task");
taskCrit.createAlias("story", "story", CriteriaSpecification.LEFT_JOIN);
taskCrit.add(Restrictions.or(Restrictions.eq("iteration", iteration), Restrictions.eq("story.iteration", iteration)));
@@ -362,8 +362,7 @@ public Iteration retrieveDeep(int iterationId) {
}
public List<Iteration> retrieveActiveWithUserAssigned(int userId) {
- Session session = sessionFactory.getCurrentSession();
- Criteria crit = session.createCriteria(Iteration.class);
+ Criteria crit = this.createCriteria(Iteration.class);
crit.setFetchMode("parent", FetchMode.JOIN);
crit.add(Restrictions.gt("endDate", new DateTime()));
crit = crit.createCriteria("assignments");
@@ -380,7 +379,7 @@ public Iteration retrieveDeep(int iterationId) {
* @return true if iteration has an associated readonly token, false otherwise
*/
public boolean hasReadonlyToken(int iterationId) {
- Criteria crit = getCurrentSession().createCriteria(Iteration.class);
+ Criteria crit = this.createCriteria(Iteration.class);
crit.add(Restrictions.idEq(iterationId));
crit.add(Restrictions.and(Restrictions.isNotNull("readonlyToken"), Restrictions.ne("readonlyToken", "")));
@@ -401,7 +400,7 @@ public boolean isValidReadonlyToken(String token) {
return false;
}
- Criteria crit = getCurrentSession().createCriteria(Iteration.class);
+ Criteria crit = this.createCriteria(Iteration.class);
crit.add(Restrictions.eq("readonlyToken", token));
return !asList(crit).isEmpty();
@@ -421,7 +420,7 @@ public Iteration getIterationFromReadonlyToken(String token) {
return null;
}
- Criteria crit = getCurrentSession().createCriteria(Iteration.class);
+ Criteria crit = this.createCriteria(Iteration.class);
crit.add(Restrictions.eq("readonlyToken", token));
List<Iteration> dummy = asList(crit);
return dummy.get(0);
@@ -442,7 +441,7 @@ public int getIterationCountFromReadonlyToken(String token) {
return 0;
}
- Criteria crit = getCurrentSession().createCriteria(Iteration.class);
+ Criteria crit = this.createCriteria(Iteration.class);
crit.add(Restrictions.eq("readonlyToken", token));
List<Iteration> dummy = asList(crit);
return dummy.size();
View
15 ...rc/main/java/fi/hut/soberit/agilefant/db/hibernate/IterationHistoryEntryDAOHibernate.java
@@ -32,15 +32,14 @@ public IterationHistoryEntry retrieveByDate(int iterationId, LocalDate timestamp
}
private IterationHistoryEntry retrieveByDateInternal(int iterationId, LocalDate timestamp) {
- Criteria crit = getCurrentSession().createCriteria(
- IterationHistoryEntry.class);
+ Criteria crit = this.createCriteria(IterationHistoryEntry.class);
crit.setMaxResults(1);
if (timestamp != null) {
crit.add(Restrictions.le("timestamp", timestamp));
}
crit.addOrder(Order.desc("timestamp"));
crit.add(Restrictions.eq("iteration.id", iterationId));
- return (IterationHistoryEntry) crit.uniqueResult();
+ return (IterationHistoryEntry) this.uniqueResult(crit);
}
public IterationHistoryEntry retrieveLatest(int iterationId) {
@@ -63,19 +62,19 @@ public IterationHistoryEntry retrieveLatest(int iterationId) {
}
private Pair<ExactEstimate, ExactEstimate> calculateCurrentHistoryData_tasksWithoutStory(int iterationId) {
- Criteria crit = getCurrentSession().createCriteria(Task.class);
+ Criteria crit = this.createCriteria(Task.class);
crit.add(Restrictions.eq("iteration.id", iterationId));
crit.add(Restrictions.ne("state", TaskState.DEFERRED));
crit.setProjection(Projections.projectionList().add(
Projections.sum("effortLeft")).add(
Projections.sum("originalEstimate")));
- Object[] results = (Object[]) crit.uniqueResult();
+ Object[] results = (Object[]) this.uniqueResult(crit);
return parseResultToPair(results);
}
private Pair<ExactEstimate, ExactEstimate> calculateCurrentHistoryData_tasksInsideStory(int iterationId) {
- Criteria crit = getCurrentSession().createCriteria(Task.class);
+ Criteria crit = this.createCriteria(Task.class);
crit.setProjection(Projections.projectionList().add(
Projections.sum("effortLeft")).add(
@@ -89,7 +88,7 @@ public IterationHistoryEntry retrieveLatest(int iterationId) {
crit = crit.createCriteria("iteration");
crit.add(Restrictions.idEq(iterationId));
- Object[] results = (Object[]) crit.uniqueResult();
+ Object[] results = (Object[]) this.uniqueResult(crit);
return parseResultToPair(results);
}
@@ -109,7 +108,7 @@ public IterationHistoryEntry retrieveLatest(int iterationId) {
public List<IterationHistoryEntry> getHistoryEntriesForIteration(
int iterationId) {
- Criteria crit = getCurrentSession().createCriteria(IterationHistoryEntry.class);
+ Criteria crit = this.createCriteria(IterationHistoryEntry.class);
crit.add(Restrictions.eq("iteration.id", iterationId));
crit.addOrder(Order.asc("timestamp"));
return asList(crit);
View
6 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/LabelDAOHibernate.java
@@ -23,17 +23,17 @@ public LabelDAOHibernate() {
}
public boolean labelExists(String labelName, Story story) {
- Criteria crit = getCurrentSession().createCriteria(Label.class);
+ Criteria crit = this.createCriteria(Label.class);
crit.add(Restrictions.eq("story", story));
crit.add(Restrictions.eq("name", labelName.toLowerCase()));
crit.setProjection(Projections.projectionList().add(Projections.count("id")));
- Object ret = crit.uniqueResult();
+ Object ret = this.uniqueResult(crit);
long count = (Long)ret;
return count > 0;
}
public List<Label> lookupLabelsLike(String labelName) {
- Criteria crit = getCurrentSession().createCriteria(Label.class);
+ Criteria crit = this.createCriteria(Label.class);
crit.add(Restrictions.like("name", labelName.toLowerCase() + "%"));
crit.addOrder(Order.asc("name"));
ProjectionList plist = Projections.projectionList();
View
15 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/ProductDAOHibernate.java
@@ -5,7 +5,6 @@
import org.hibernate.Criteria;
import org.hibernate.criterion.CriteriaSpecification;
-import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.ProjectionList;
import org.hibernate.criterion.Projections;
@@ -31,14 +30,14 @@ public ProductDAOHibernate() {
super(Product.class);
}
- @SuppressWarnings("unchecked")
public Collection<Product> getAllOrderByName() {
- DetachedCriteria crit = createCriteria().addOrder(Order.asc("name"));
- return hibernateTemplate.findByCriteria(crit);
+ Criteria criteria = this.createCriteria(this.getPersistentClass());
+ criteria.addOrder(Order.asc("name"));
+ return this.asList(criteria);
}
public List<Product> retrieveBacklogTree() {
- Criteria crit = this.getCurrentSession().createCriteria(this.getPersistentClass());
+ Criteria crit = this.createCriteria(this.getPersistentClass());
crit.createAlias("children", "projects", CriteriaSpecification.LEFT_JOIN);
crit.createAlias("projects.children", "iterations", CriteriaSpecification.LEFT_JOIN);
crit.addOrder(Order.asc("name"));
@@ -49,7 +48,7 @@ public ProductDAOHibernate() {
public List<Story> retrieveLeafStories(Product product) {
int productId = product.getId();
- Criteria leaftStoryCrit = getCurrentSession().createCriteria(Story.class);
+ Criteria leaftStoryCrit = this.createCriteria(Story.class);
leaftStoryCrit.createAlias(
"backlog.parent", "secondParent", CriteriaSpecification.LEFT_JOIN)
.createAlias("secondParent.parent", "thirdParent",
@@ -63,8 +62,8 @@ public ProductDAOHibernate() {
}
public Pair<DateTime, DateTime> retrieveScheduleStartAndEnd(Product product) {
- Criteria iterations = getCurrentSession().createCriteria(Iteration.class);
- Criteria projects = getCurrentSession().createCriteria(Project.class);
+ Criteria iterations = this.createCriteria(Iteration.class);
+ Criteria projects = this.createCriteria(Project.class);
iterations.createCriteria("parent").add(Restrictions.eq("parent", product));
View
25 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/ProjectDAOHibernate.java
@@ -35,8 +35,7 @@ public ProjectDAOHibernate() {
}
public Collection<User> getAssignedUsers(Project project) {
- Session sess = sessionFactory.getCurrentSession();
- Criteria crit = sess.createCriteria(User.class);
+ Criteria crit = this.createCriteria(User.class);
crit = crit.createCriteria("assignments");
crit = crit.createCriteria("backlog");
crit.add(Restrictions.idEq(project.getId()));
@@ -44,8 +43,7 @@ public ProjectDAOHibernate() {
}
public Collection<Project> getProjectsWithUserAssigned(User user) {
- Session session = sessionFactory.getCurrentSession();
- Criteria criteria = session.createCriteria(User.class);
+ Criteria criteria = this.createCriteria(User.class);
criteria.add(Restrictions.idEq(user.getId()));
criteria = criteria.createCriteria("assignments");
criteria = criteria.createCriteria("backlog");
@@ -53,20 +51,20 @@ public ProjectDAOHibernate() {
}
public List<Project> getActiveProjectsSortedByRank() {
- Criteria crit = getCurrentSession().createCriteria(Project.class);
+ Criteria crit = this.createCriteria(Project.class);
crit.add(Restrictions.gt("endDate", new DateTime()));
crit.addOrder(Order.desc("rank"));
return asList(crit);
}
public Collection<Project> getProjectsWithRankBetween(int lower, int upper) {
- Criteria crit = getCurrentSession().createCriteria(Project.class);
+ Criteria crit = this.createCriteria(Project.class);
crit.add(Restrictions.between("rank", lower, upper));
return asCollection(crit);
}
public Collection<Project> getUnrankedProjects(LocalDate startDate, LocalDate endDate) {
- Criteria crit = getCurrentSession().createCriteria(Project.class);
+ Criteria crit = this.createCriteria(Project.class);
crit.add(Restrictions.ge("endDate", startDate.toDateTimeAtStartOfDay()));
crit.add(Restrictions.le("startDate", endDate.toDateTimeAtStartOfDay()));
crit.add(Restrictions.lt("rank", 1));
@@ -74,7 +72,7 @@ public ProjectDAOHibernate() {
}
public List<Project> getRankedProjects(LocalDate startDate, LocalDate endDate) {
- Criteria crit = getCurrentSession().createCriteria(Project.class);
+ Criteria crit = this.createCriteria(Project.class);
crit.add(Restrictions.ge("endDate", startDate.toDateTimeAtStartOfDay()));
crit.add(Restrictions.le("startDate", endDate.toDateTimeAtStartOfDay()));
crit.add(Restrictions.gt("rank", 0));
@@ -83,7 +81,7 @@ public ProjectDAOHibernate() {
}
public Project getMaxRankedProject() {
- Criteria crit = getCurrentSession().createCriteria(Project.class);
+ Criteria crit = this.createCriteria(Project.class);
crit.add(Restrictions.gt("rank", 0));
crit.addOrder(Order.desc("rank"));
crit.setMaxResults(1);
@@ -91,7 +89,7 @@ public Project getMaxRankedProject() {
}
public Project getProjectWithRankLessThan(int rank) {
- Criteria crit = getCurrentSession().createCriteria(Project.class);
+ Criteria crit = this.createCriteria(Project.class);
crit.add(Restrictions.lt("rank", rank));
crit.add(Restrictions.gt("rank", 0));
crit.addOrder(Order.asc("rank"));
@@ -105,8 +103,7 @@ public void increaseRankedProjectRanks() {
}
public List<Project> retrieveActiveWithUserAssigned(int userId) {
- Session session = sessionFactory.getCurrentSession();
- Criteria crit = session.createCriteria(Project.class);
+ Criteria crit = this.createCriteria(Project.class);
crit.add(Restrictions.gt("endDate", new DateTime()));
crit = crit.createCriteria("assignments");
crit = crit.createCriteria("user");
@@ -116,7 +113,7 @@ public void increaseRankedProjectRanks() {
public List<BacklogHistoryEntry> getHistoryEntriesForProject(
int projectId) {
- Criteria crit = getCurrentSession().createCriteria(BacklogHistoryEntry.class);
+ Criteria crit = this.createCriteria(BacklogHistoryEntry.class);
crit.add(Restrictions.eq("backlog.id", projectId));
crit.addOrder(Order.asc("timestamp"));
return asList(crit);
@@ -129,7 +126,7 @@ private int toInt(Object obj) {
return 0;
}
public ProjectMetrics calculateProjectStoryMetrics(int backlogId) {
- Criteria crit = getCurrentSession().createCriteria(Story.class);
+ Criteria crit = this.createCriteria(Story.class);
ProjectionList proj = Projections.projectionList();
proj.add(Projections.sum("storyPoints"));
proj.add(Projections.sum("storyValue"));
View
58 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/SettingDAOHibernate.java
@@ -1,8 +1,10 @@
package fi.hut.soberit.agilefant.db.hibernate;
+import java.util.Collection;
import java.util.List;
-import org.hibernate.criterion.DetachedCriteria;
+import org.hibernate.Criteria;
+import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
@@ -11,28 +13,34 @@
@Repository("settingDAO")
public class SettingDAOHibernate extends GenericDAOHibernate<Setting> implements SettingDAO {
-
- public SettingDAOHibernate() {
- super(Setting.class);
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- public Setting getByName(String name) {
- DetachedCriteria criteria = DetachedCriteria.forClass(this
- .getPersistentClass());
- criteria.add(Restrictions.eq("name", name));
- return super.getFirst(hibernateTemplate.findByCriteria(criteria));
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- public List<Setting> getAllOrderByName(){
- final String query = "from Setting s order by s.name asc";
- return (List<Setting>) hibernateTemplate.find(query);
- }
+
+ public SettingDAOHibernate() {
+ super(Setting.class);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Setting getByName(String name) {
+ Criteria criteria = this.createCriteria(this.getPersistentClass());
+ criteria.add(Restrictions.eq("name", name));
+ List<Setting> list = this.asList(criteria);
+ return super.getFirst(list);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<Setting> getAllOrderByName() {
+ Criteria criteria = this.createCriteria(this.getPersistentClass());
+ criteria.addOrder(Order.asc("name"));
+ return this.asList(criteria);
+ }
+
+ @Override
+ public Collection<Setting> getAll() {
+ Criteria criteria = this.createCriteria(this.getPersistentClass());
+ return this.asList(criteria);
+ }
+
}
View
2  webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/StoryAccessDAOHibernate.java
@@ -26,7 +26,7 @@ protected StoryAccessDAOHibernate() {
public Map<Story, Long> calculateAccessCounts(DateTime start,
DateTime end, User user) {
- Criteria crit = this.getCurrentSession().createCriteria(StoryAccess.class);
+ Criteria crit = this.createCriteria(StoryAccess.class);
crit.add(Restrictions.eq("user", user));
crit.add(Restrictions.between("date", start, end));
ProjectionList proj = Projections.projectionList();
View
30 webapp/src/main/java/fi/hut/soberit/agilefant/db/hibernate/StoryDAOHibernate.java
@@ -39,7 +39,7 @@ public StoryDAOHibernate() {
public StoryMetrics calculateMetrics(int storyId) {
StoryMetrics metrics = new StoryMetrics();
- Criteria criteria = getCurrentSession().createCriteria(Task.class);
+ Criteria criteria = this.createCriteria(Task.class);
criteria.setProjection(
Projections.projectionList()
.add(Projections.sum("originalEstimate"), "originalEstimateSum")
@@ -47,7 +47,7 @@ public StoryMetrics calculateMetrics(int storyId) {
);
criteria.add(Restrictions.eq("story.id", storyId));
criteria.add(Restrictions.ne("state", TaskState.DEFERRED));
- Object[] result = (Object[])criteria.uniqueResult();
+ Object[] result = (Object[])this.uniqueResult(criteria);
if (result[0] != null) {
metrics.setOriginalEstimate((Long)result[0]);
}
@@ -58,12 +58,12 @@ public StoryMetrics calculateMetrics(int storyId) {
}
public int getStoryPointSumByIteration(int iterationId) {
- Criteria criteria = getCurrentSession().createCriteria(Story.class);
+ Criteria criteria = this.createCriteria(Story.class);
criteria.add(Restrictions.eq("iteration.id", iterationId));
criteria.add(Restrictions.isNotNull("storyPoints"));
criteria.add(Restrictions.ne("state", StoryState.DEFERRED));
criteria.setProjection(Projections.sum("storyPoints"));
- Object result = criteria.uniqueResult();
+ Object result = this.uniqueResult(criteria);
if (result == null) {
return 0;
}
@@ -71,12 +71,12 @@ public int getStoryPointSumByIteration(int iterationId) {
}
public int getStoryValueSumByIteration(int iterationId) {
- Criteria criteria = getCurrentSession().createCriteria(Story.class);
+ Criteria criteria = this.createCriteria(Story.class);
criteria.add(Restrictions.eq("iteration.id", iterationId));
criteria.add(Restrictions.isNotNull("storyValue"));
criteria.add(Restrictions.not(Restrictions.eq("state", StoryState.DEFERRED)));
criteria.setProjection(Projections.sum("storyValue"));
- Object result = criteria.uniqueResult();
+ Object result = this.uniqueResult(criteria);
if (result == null) {
return 0;
}
@@ -84,13 +84,13 @@ public int getStoryValueSumByIteration(int iterationId) {
}
public int getCompletedStoryValueSumByIteration(int iterationId) {
- Criteria criteria = getCurrentSession().createCriteria(Story.class);
+ Criteria criteria = this.createCriteria(Story.class);
criteria.add(Restrictions.eq("iteration.id", iterationId));
criteria.add(Restrictions.isNotNull("storyValue"));
criteria.add(Restrictions.not(Restrictions.eq("state", StoryState.DEFERRED)));
criteria.add(Restrictions.eq("state", StoryState.DONE));
criteria.setProjection(Projections.sum("storyValue"));
- Object result = criteria.uniqueResult();
+ Object result = this.uniqueResult(criteria);
if (result == null) {
return 0;
}
@@ -102,7 +102,7 @@ public int getCompletedStoryValueSumByIteration(int iterationId) {
if(storyIds == null || storyIds.size() == 0) {
return Collections.emptyMap();
}
- Criteria crit = getCurrentSession().createCriteria(Story.class);
+ Criteria crit = this.createCriteria(Story.class);
crit.add(Restrictions.in("id", storyIds));
crit.createAlias("responsibles", "responsible");
ProjectionList sums = Projections.projectionList();
@@ -125,7 +125,7 @@ public int getCompletedStoryValueSumByIteration(int iterationId) {
ArrayList<Story> stories = new ArrayList<Story>();
// Add stories that don't have an iteration
- Criteria crit = getCurrentSession().createCriteria(Story.class);
+ Criteria crit = this.createCriteria(Story.class);
crit.createCriteria("responsibles").add(Restrictions.idEq(user.getId()));
Criteria backlogCriteria = crit.createCriteria("backlog");
@@ -136,7 +136,7 @@ public int getCompletedStoryValueSumByIteration(int iterationId) {
stories.addAll(dummy);
// Add stories in iterations
- Criteria standaloneCrit = getCurrentSession().createCriteria(Story.class);
+ Criteria standaloneCrit = this.createCriteria(Story.class);
standaloneCrit.createCriteria("responsibles").add(Restrictions.idEq(user.getId()));
Criteria iterationCrit = standaloneCrit.createCriteria("iteration");
@@ -153,7 +153,7 @@ public int getCompletedStoryValueSumByIteration(int iterationId) {
ArrayList<Story> stories = new ArrayList<Story>();
// all stories in iteration
- Criteria criteria = getCurrentSession().createCriteria(Story.class);
+ Criteria criteria = this.createCriteria(Story.class);
criteria.add(Restrictions.eq("iteration.id", iteration.getId()));