Sandbox-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- 1825 discussions
r447 - jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence
by fdesbois@users.nuiton.org 29 Dec '10
by fdesbois@users.nuiton.org 29 Dec '10
29 Dec '10
Author: fdesbois
Date: 2010-12-29 17:32:38 +0100 (Wed, 29 Dec 2010)
New Revision: 447
Url: http://nuiton.org/repositories/revision/sandbox/447
Log:
Use better implementation instead of using reflect for classes
Modified:
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAOImpl.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImpl.java
Modified: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAOImpl.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAOImpl.java 2010-12-29 16:18:26 UTC (rev 446)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAOImpl.java 2010-12-29 16:32:38 UTC (rev 447)
@@ -3,7 +3,6 @@
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
-import java.lang.reflect.ParameterizedType;
import java.util.List;
import org.apache.commons.logging.Log;
@@ -75,24 +74,17 @@
/**
* Constructor to be called by siblings.
+ *
+ * @param interfaceClass Class of the entity interface
+ * @param entityClass Class of the entity
+ *
*/
- public BaseDAOImpl() {
- initClasses();
+ protected BaseDAOImpl(Class<C> interfaceClass, Class<E> entityClass) {
+ this.interfaceClass = interfaceClass;
+ this.entityClass = entityClass;
saveStrategy = SaveStrategy.DEFAULT;
}
- @SuppressWarnings({"unchecked"})
- private void initClasses() throws ClassCastException {
- ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
- entityClass = (Class<E>) genericSuperclass.getActualTypeArguments()[1];
- interfaceClass = (Class<C>) genericSuperclass.getActualTypeArguments()[0];
- if (logger.isTraceEnabled()) {
- logger.trace("Initialize classes for DAO " + getClass().getName() +
- " :: entityClass = " + entityClass.getName() +
- " _ interfaceClass = " + interfaceClass.getName());
- }
- }
-
public EntityManager getEntityManager() {
return entityManager;
}
Modified: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImpl.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImpl.java 2010-12-29 16:18:26 UTC (rev 446)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImpl.java 2010-12-29 16:32:38 UTC (rev 447)
@@ -17,6 +17,10 @@
@Repository
public class CustomerDAOImpl extends BaseDAOImpl<Customer, CustomerImpl> implements CustomerDAO {
+ public CustomerDAOImpl() {
+ super(Customer.class, CustomerImpl.class);
+ }
+
@Override
public Address newInstanceAddress() {
return new AddressImpl();
1
0
r446 - in jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2: sample test
by fdesbois@users.nuiton.org 29 Dec '10
by fdesbois@users.nuiton.org 29 Dec '10
29 Dec '10
Author: fdesbois
Date: 2010-12-29 17:18:26 +0100 (Wed, 29 Dec 2010)
New Revision: 446
Url: http://nuiton.org/repositories/revision/sandbox/446
Log:
Missing new classes
Added:
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/sample/DataProviderLimit.java
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/sample/UseDataProvider.java
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/RandomFunction.java
Added: jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/sample/DataProviderLimit.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/sample/DataProviderLimit.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/sample/DataProviderLimit.java 2010-12-29 16:18:26 UTC (rev 446)
@@ -0,0 +1,43 @@
+package org.nuiton.sandbox.jsr317.jpa2.sample;
+
+/**
+ * Limit creation in {@link DataSampleProvider} avoiding too many insertion on each usage.
+ * <p/>
+ * Created on 29 nov. 2010
+ *
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id: DataProviderLimit.java 52484 2010-12-27 14:52:28Z fdesbois $
+ */
+public enum DataProviderLimit {
+
+ /**
+ * Location objets only (Town, Department, Region, Country)
+ */
+ LOCATIONS_ONLY,
+
+ /**
+ * ClassifiedAd objects only inluding Locations (Attorney, ClassifiedAd, RealEstate, RealEstateAgency,
+ * RealEstateNetwork, RealEstatePartner).
+ */
+ CLASSIFIED_ADS_ONLY,
+
+ /**
+ * VideoPartners objects only inluding Locations (Video, VideoPartner, VideoLocation, VideoPartnerLocation,
+ * Category, EntryPoint).
+ */
+ VIDEOS_ONLY,
+
+ /**
+ * All model objects
+ */
+ ALL;
+
+ boolean hasVideos() {
+ return VIDEOS_ONLY.equals(this) || ALL.equals(this);
+ }
+
+ boolean hasClassifiedAds() {
+ return CLASSIFIED_ADS_ONLY.equals(this) || ALL.equals(this);
+ }
+
+}
Added: jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/sample/UseDataProvider.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/sample/UseDataProvider.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/sample/UseDataProvider.java 2010-12-29 16:18:26 UTC (rev 446)
@@ -0,0 +1,27 @@
+package org.nuiton.sandbox.jsr317.jpa2.sample;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import static org.nuiton.sandbox.jsr317.jpa2.sample.DataProviderLimit.ALL;
+
+/**
+ * Created on 15 nov. 2010
+ *
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id$
+ */
+(a)Target({ElementType.METHOD, ElementType.TYPE})
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface UseDataProvider {
+
+ boolean value() default true;
+
+ /**
+ * @return Limit the insertions to a part of the model defined by {@link DataProviderLimit}
+ */
+ DataProviderLimit limit() default ALL;
+
+}
Added: jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/RandomFunction.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/RandomFunction.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/RandomFunction.java 2010-12-29 16:18:26 UTC (rev 446)
@@ -0,0 +1,24 @@
+package org.nuiton.sandbox.jsr317.jpa2.test;
+
+import javax.persistence.criteria.CriteriaBuilder;
+
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.expression.function.BasicFunctionExpression;
+
+/**
+ * Extension of {@link BasicFunctionExpression} from Hibernate used to execute rand function in orderBy.
+ * <p/>
+ * Created on 17 nov. 2010
+ *
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id: RandomFunction.java 48848 2010-11-18 09:48:00Z fdesbois $
+ */
+public class RandomFunction extends BasicFunctionExpression<Object> {
+
+ public static final String NAME = "rand";
+
+ public RandomFunction(CriteriaBuilder criteriaBuilder) {
+ super((CriteriaBuilderImpl) criteriaBuilder, Object.class, NAME);
+ }
+
+}
1
0
Author: fdesbois
Date: 2010-12-29 17:15:42 +0100 (Wed, 29 Dec 2010)
New Revision: 445
Url: http://nuiton.org/repositories/revision/sandbox/445
Log:
Update jpa tests :
- Add QueryWrapper
- Add OrderBy
- Update DAO
- Add PaginationData
- Move DataProvider, use inheritance between tests
Added:
jpa2-validation/trunk/jsr303-validation/src/test/java/org/nuiton/sandbox/jsr303/validation/test/BaseValidationTest.java
jpa2-validation/trunk/jsr303-validation/src/test/resources/test-validation-spring-context.xml
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/CountQueryWrapper.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/EntityQueryWrapper.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderBy.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderByAsc.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderByDesc.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderByRandom.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/PaginationData.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/QueryWrapper.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/Search.java
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/query/
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/query/PaginationDataTest.java
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/sample/
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/BaseJpaTest.java
jpa2-validation/trunk/jsr317-jpa2/src/test/resources/test-jpa-spring-context.xml
Removed:
jpa2-validation/trunk/jsr303-validation/src/test/java/org/nuiton/sandbox/jsr303/validation/test/BaseTest.java
jpa2-validation/trunk/jsr303-validation/src/test/resources/META-INF/persistence.xml
jpa2-validation/trunk/jsr303-validation/src/test/resources/test-spring-context.xml
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/Search.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/SearchImpl.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/sample/
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/BaseTest.java
jpa2-validation/trunk/jsr317-jpa2/src/test/resources/test-context.xml
Modified:
jpa2-validation/trunk/jsr303-validation/pom.xml
jpa2-validation/trunk/jsr303-validation/src/test/java/org/nuiton/sandbox/jsr303/validation/CustomerValidationTest.java
jpa2-validation/trunk/jsr317-jpa2/pom.xml
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/config/UpdateTechnicalFieldListener.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAO.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAOImpl.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImpl.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/ModelContext.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/ModelContextImpl.java
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/entity/EntityManagerTest.java
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/entity/MetaModelTest.java
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAOImplTest.java
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImplTest.java
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/sample/DataSampleProvider.java
jpa2-validation/trunk/pom.xml
Modified: jpa2-validation/trunk/jsr303-validation/pom.xml
===================================================================
--- jpa2-validation/trunk/jsr303-validation/pom.xml 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr303-validation/pom.xml 2010-12-29 16:15:42 UTC (rev 445)
@@ -69,7 +69,15 @@
</dependency>
<!-- TESTS -->
+
<dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>jsr317-jpa2</artifactId>
+ <version>${project.version}</version>
+ <classifier>tests</classifier>
+ </dependency>
+
+ <dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
Modified: jpa2-validation/trunk/jsr303-validation/src/test/java/org/nuiton/sandbox/jsr303/validation/CustomerValidationTest.java
===================================================================
--- jpa2-validation/trunk/jsr303-validation/src/test/java/org/nuiton/sandbox/jsr303/validation/CustomerValidationTest.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr303-validation/src/test/java/org/nuiton/sandbox/jsr303/validation/CustomerValidationTest.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -9,7 +9,7 @@
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Test;
-import org.nuiton.sandbox.jsr303.validation.test.BaseTest;
+import org.nuiton.sandbox.jsr303.validation.test.BaseValidationTest;
import org.nuiton.sandbox.jsr317.jpa2.entity.Customer;
import org.nuiton.sandbox.jsr317.jpa2.persistence.CustomerDAO;
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,7 +21,7 @@
* @author fdesbois <florian.desbois(a)wiztivi.com>
* @version $Id: CustomerValidationTest.java 48934 2010-11-18 16:17:46Z fdesbois $
*/
-public class CustomerValidationTest extends BaseTest {
+public class CustomerValidationTest extends BaseValidationTest {
private static final Log log = LogFactory.getLog(CustomerValidationTest.class);
@@ -39,6 +39,8 @@
try {
// ---- EXECUTE ---- //
userDAO.save(user);
+ // Need manual flush because test have @Transactional annotation
+ modelContext.flushSession();
Assert.fail();
} catch (ConstraintViolationException ex) {
@@ -72,6 +74,8 @@
try {
log.info("test 2 : update the same user with fake email : throw ConstraintViolationException");
user = userDAO.update(user);
+ // Need manual flush because test have @Transactional annotation
+ modelContext.flushSession();
Assert.fail();
} catch (ConstraintViolationException ex) {
Deleted: jpa2-validation/trunk/jsr303-validation/src/test/java/org/nuiton/sandbox/jsr303/validation/test/BaseTest.java
===================================================================
--- jpa2-validation/trunk/jsr303-validation/src/test/java/org/nuiton/sandbox/jsr303/validation/test/BaseTest.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr303-validation/src/test/java/org/nuiton/sandbox/jsr303/validation/test/BaseTest.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -1,115 +0,0 @@
-package org.nuiton.sandbox.jsr303.validation.test;
-
-import javax.validation.ConstraintViolation;
-import javax.validation.ConstraintViolationException;
-import javax.validation.Validator;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.rules.TestName;
-import org.junit.runner.RunWith;
-import org.junit.runners.model.FrameworkMethod;
-import org.nuiton.sandbox.jsr317.jpa2.persistence.BaseDAOImpl.SaveStrategy;
-import org.nuiton.sandbox.jsr317.jpa2.persistence.ModelContext;
-import org.nuiton.sandbox.jsr317.jpa2.sample.DataSampleProvider;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-/**
- * Created on 26 oct. 2010
- *
- * @author fdesbois <florian.desbois(a)wiztivi.com>
- * @version $Id: BaseTest.java 48934 2010-11-18 16:17:46Z fdesbois $
- */
-(a)RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = {"/test-spring-context.xml"})
-public abstract class BaseTest {
-
- private static final Log logger = LogFactory.getLog(BaseTest.class);
-
- @Autowired
- protected ModelContext modelContext;
-
- @Autowired
- protected DataSampleProvider dataProvider;
-
- @Autowired
- protected Validator validator;
-
- @Rule
- public TestName rule = new TestName() {
-
- @Override
- public void starting(FrameworkMethod method) {
- super.starting(method);
-
- // Apply persist flush saveStrategy for all tests, this will effectively keep instance in session and flush
- // it after each {@link BaseDAO#save()} call
- modelContext.setSaveStrategy(SaveStrategy.PERSIST_FLUSH);
-
- // Use DataProvider depends on annotation declaration in tests
-// useDataProvider(method.getAnnotation(UseDataProvider.class));
- }
-
-// protected void useDataProvider(UseDataProvider useDataProvider) {
-// boolean useData = DataSampleProvider.isUseDataProviderFromMethod(BaseTest.this.getClass(), useDataProvider);
-//
-// if (useData) {
-// try {
-// dataProvider.createAllData();
-// } catch (ConstraintViolationException ex) {
-// logger.error(ex);
-// if (logger.isInfoEnabled()) {
-// for (ConstraintViolation<?> constraint : ex.getConstraintViolations()) {
-// logger.info("constraint.getRootBeanClass = " + constraint.getRootBeanClass());
-// logger.info("constraint.getPropertyPath = " + constraint.getPropertyPath());
-// logger.info("constraint.getMessageTemplate = " + constraint.getMessageTemplate());
-// logger.info("constraint.getInvalidValue = " + constraint.getInvalidValue());
-// }
-// }
-// throw new TivimmoRuntimeException("Error while creating all data", ex);
-// } catch (Exception ex) {
-// logger.error(ex.getClass().getSimpleName(), ex);
-// throw new TivimmoRuntimeException("Error while creating all data", ex);
-// }
-// }
-// }
- };
-
- protected interface ConstraintChecker {
-
- void execute();
- }
-
- protected void assertConstraintViolationException(ConstraintChecker checker, String field, Class<?> annotationClass) {
-
- try {
- checker.execute();
- Assert.fail();
-
- } catch (ConstraintViolationException ex) {
-
- if (logger.isDebugEnabled()) {
- logger.debug("Expected error", ex);
- }
-
- ConstraintViolation<?> constraint = ex.getConstraintViolations().iterator().next();
- Assert.assertEquals(field, constraint.getPropertyPath().toString());
- Assert.assertTrue(constraint.getMessageTemplate().contains(annotationClass.getSimpleName()));
-
- if (logger.isDebugEnabled()) {
- logger.debug("constraint.getMessageTemplate = " + constraint.getMessageTemplate());
- logger.debug("constraint.getMessage = " + constraint.getMessage());
- logger.debug("constraint.getInvalidValue = " + constraint.getInvalidValue());
- logger.debug("constraint.getLeafBean = " + constraint.getLeafBean());
- logger.debug("constraint.getPropertyPath = " + constraint.getPropertyPath());
- logger.debug("constraint.getRootBean = " + constraint.getRootBean());
- logger.debug("constraint.getRootBeanClass = " + constraint.getRootBeanClass());
- }
-
- }
- }
-}
Copied: jpa2-validation/trunk/jsr303-validation/src/test/java/org/nuiton/sandbox/jsr303/validation/test/BaseValidationTest.java (from rev 444, jpa2-validation/trunk/jsr303-validation/src/test/java/org/nuiton/sandbox/jsr303/validation/test/BaseTest.java)
===================================================================
--- jpa2-validation/trunk/jsr303-validation/src/test/java/org/nuiton/sandbox/jsr303/validation/test/BaseValidationTest.java (rev 0)
+++ jpa2-validation/trunk/jsr303-validation/src/test/java/org/nuiton/sandbox/jsr303/validation/test/BaseValidationTest.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -0,0 +1,113 @@
+package org.nuiton.sandbox.jsr303.validation.test;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.ConstraintViolationException;
+import javax.validation.Validator;
+import java.lang.annotation.Annotation;
+
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.rules.TestWatchman;
+import org.nuiton.sandbox.jsr317.jpa2.persistence.ModelContext;
+import org.nuiton.sandbox.jsr317.jpa2.sample.DataProviderLimit;
+import org.nuiton.sandbox.jsr317.jpa2.test.BaseJpaTest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * Created on 26 oct. 2010
+ *
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id: BaseValidationTest.java 48934 2010-11-18 16:17:46Z fdesbois $
+ */
+@ContextConfiguration(locations = { "/test-validation-spring-context.xml" })
+public abstract class BaseValidationTest extends BaseJpaTest {
+
+ @Autowired
+ protected ModelContext modelContext;
+
+ @Autowired
+ protected Validator validator;
+
+ protected class ValidationTestRule extends JpaTestRule {
+
+ @Override
+ protected void createData(DataProviderLimit limit) {
+ try {
+ dataProvider.createData(limit);
+ modelContext.flushSession();
+ } catch (ConstraintViolationException ex) {
+ logger.error(ex);
+ if (logger.isInfoEnabled()) {
+ for (ConstraintViolation<?> constraint : ex.getConstraintViolations()) {
+ logger.info("constraint.getRootBeanClass = " + constraint.getRootBeanClass());
+ logger.info("constraint.getPropertyPath = " + constraint.getPropertyPath());
+ logger.info("constraint.getMessageTemplate = " + constraint.getMessageTemplate());
+ logger.info("constraint.getInvalidValue = " + constraint.getInvalidValue());
+ }
+ }
+ throw new RuntimeException("Error while creating all data", ex);
+ } catch (Exception ex) {
+ logger.error(ex.getClass().getSimpleName(), ex);
+ throw new RuntimeException("Error while creating all data", ex);
+ }
+ }
+ }
+
+ protected interface ConstraintChecker {
+
+ void execute() throws Exception;
+ }
+
+ @Rule
+ public TestWatchman rule = new ValidationTestRule();
+
+ protected void assertConstraintViolationException(ConstraintChecker checker, String expectedField,
+ Class<?> expectedAnnotation) throws Exception {
+
+ try {
+ checker.execute();
+ Assert.fail("No ConstraintViolationException was thrown");
+ } catch (ConstraintViolationException ex) {
+
+ boolean constraintFound = false;
+ for (ConstraintViolation<?> constraintViolation : ex.getConstraintViolations()) {
+ ConstraintViolation<?> constraint = constraintViolation;
+
+ String propertyPath = getConstraintPropertyPath(constraint);
+ Class<? extends Annotation> annotationType = getConstraintAnnotationType(constraint);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Constraint error " + annotationType.getSimpleName() + " on property " + propertyPath
+ + " from bean " + constraint.getRootBeanClass().getSimpleName());
+ }
+
+ if (logger.isTraceEnabled()) {
+ logger.trace("constraint.getMessageTemplate = " + constraint.getMessageTemplate());
+ logger.trace("constraint.getMessage = " + constraint.getMessage());
+ logger.trace("constraint.getInvalidValue = " + constraint.getInvalidValue());
+ logger.trace("constraint.getLeafBean = " + constraint.getLeafBean());
+ logger.trace("constraint.getPropertyPath = " + constraint.getPropertyPath());
+ logger.trace("constraint.getRootBean = " + constraint.getRootBean());
+ logger.trace("constraint.getRootBeanClass = " + constraint.getRootBeanClass());
+ }
+
+ if (propertyPath.equals(expectedField) && annotationType.equals(expectedAnnotation)) {
+ constraintFound = true;
+ }
+ }
+
+ Assert.assertTrue("No constraint typed by '" + expectedAnnotation.getSimpleName() + "' was found"
+ + " for field '" + expectedField + "'", constraintFound);
+ }
+ }
+
+ protected Class<? extends Annotation> getConstraintAnnotationType(ConstraintViolation<?> constraint) {
+ return constraint.getConstraintDescriptor().getAnnotation().annotationType();
+ }
+
+ protected String getConstraintPropertyPath(ConstraintViolation<?> constraint) {
+ return constraint.getPropertyPath().toString();
+ }
+
+}
Deleted: jpa2-validation/trunk/jsr303-validation/src/test/resources/META-INF/persistence.xml
===================================================================
--- jpa2-validation/trunk/jsr303-validation/src/test/resources/META-INF/persistence.xml 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr303-validation/src/test/resources/META-INF/persistence.xml 2010-12-29 16:15:42 UTC (rev 445)
@@ -1,12 +0,0 @@
-<persistence xmlns="http://java.sun.com/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
- version="2.0">
-
- <persistence-unit name="jsr303-test" transaction-type="RESOURCE_LOCAL">
- <class>org.nuiton.sandbox.jsr317.jpa2.entity.CustomerImpl</class>
- <class>org.nuiton.sandbox.jsr317.jpa2.entity.CountryImpl</class>
- <!--<validation-mode>NONE</validation-mode>-->
- </persistence-unit>
-
-</persistence>
\ No newline at end of file
Deleted: jpa2-validation/trunk/jsr303-validation/src/test/resources/test-spring-context.xml
===================================================================
--- jpa2-validation/trunk/jsr303-validation/src/test/resources/test-spring-context.xml 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr303-validation/src/test/resources/test-spring-context.xml 2010-12-29 16:15:42 UTC (rev 445)
@@ -1,51 +0,0 @@
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
-
- <!-- TEST CONFIGURATION :: sample used to fill database -->
- <context:component-scan base-package="org.nuiton.sandbox.jsr317.jpa2.sample"/>
-
- <!-- SERVICES CONFIGURATION -->
- <import resource="classpath:/jsr303-spring-context.xml"/>
-
- <!-- MODEL INJECTION and JPA CONFIGURATION -->
- <import resource="classpath:/jsr317-spring-context.xml"/>
-
- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property name="url"
- value="jdbc:h2:file:./target/surefire-data/jsr303"/>
- <property name="username" value="sa"/>
- <property name="password" value=""/>
- </bean>
-
- <bean id="transactionManager"
- class="org.springframework.orm.jpa.JpaTransactionManager">
- <property name="entityManagerFactory" ref="entityManagerFactory"/>
- </bean>
-
- <bean id="entityManagerFactory"
- class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
- <property name="dataSource" ref="dataSource"/>
- <property name="jpaVendorAdapter">
- <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
- <property name="showSql" value="false"/>
- <property name="generateDdl" value="true"/>
- <property name="databasePlatform" value="org.hibernate.dialect.H2Dialect"/>
- </bean>
- </property>
- <property name="jpaProperties">
- <props>
- <prop key="hibernate.hbm2ddl.auto">create</prop>
- <!-- IdGenerator Strategy : one unique number for each row for all database -->
- <prop key="hibernate.id.new_generator_mappings">true</prop>
- </props>
- </property>
- <property name="loadTimeWeaver">
- <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
- </property>
- </bean>
-
-</beans>
\ No newline at end of file
Copied: jpa2-validation/trunk/jsr303-validation/src/test/resources/test-validation-spring-context.xml (from rev 444, jpa2-validation/trunk/jsr303-validation/src/test/resources/test-spring-context.xml)
===================================================================
--- jpa2-validation/trunk/jsr303-validation/src/test/resources/test-validation-spring-context.xml (rev 0)
+++ jpa2-validation/trunk/jsr303-validation/src/test/resources/test-validation-spring-context.xml 2010-12-29 16:15:42 UTC (rev 445)
@@ -0,0 +1,56 @@
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
+
+ <!-- TEST CONFIGURATION :: sample used to fill database -->
+ <context:component-scan base-package="org.nuiton.sandbox.jsr317.jpa2.sample"/>
+
+ <!-- SERVICES CONFIGURATION -->
+ <import resource="classpath:/jsr303-spring-context.xml"/>
+
+ <!-- MODEL INJECTION and JPA CONFIGURATION -->
+ <import resource="classpath:/jsr317-spring-context.xml"/>
+
+ <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="url"
+ value="jdbc:h2:file:./target/surefire-data/jsr303"/>
+ <property name="username" value="sa"/>
+ <property name="password" value=""/>
+ </bean>
+
+ <!-- For @Transactional annotations -->
+ <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
+
+ <bean id="transactionManager"
+ class="org.springframework.orm.jpa.JpaTransactionManager">
+ <property name="entityManagerFactory" ref="entityManagerFactory"/>
+ </bean>
+
+ <bean id="entityManagerFactory"
+ class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <property name="dataSource" ref="dataSource"/>
+ <property name="jpaVendorAdapter">
+ <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
+ <property name="showSql" value="false"/>
+ <property name="generateDdl" value="true"/>
+ <property name="databasePlatform" value="org.hibernate.dialect.H2Dialect"/>
+ </bean>
+ </property>
+ <property name="jpaProperties">
+ <props>
+ <prop key="hibernate.hbm2ddl.auto">create</prop>
+ <!-- IdGenerator Strategy : one unique number for each row for all database -->
+ <prop key="hibernate.id.new_generator_mappings">true</prop>
+ </props>
+ </property>
+ <property name="loadTimeWeaver">
+ <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
+ </property>
+ </bean>
+
+</beans>
\ No newline at end of file
Modified: jpa2-validation/trunk/jsr317-jpa2/pom.xml
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/pom.xml 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/pom.xml 2010-12-29 16:15:42 UTC (rev 445)
@@ -24,6 +24,11 @@
<!--<version>1.4.2</version>-->
<!--</dependency>-->
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
+
<!-- SPRING -->
<dependency>
<groupId>org.springframework</groupId>
@@ -169,6 +174,17 @@
</executions>
</plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
</plugins>
</build>
Modified: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/config/UpdateTechnicalFieldListener.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/config/UpdateTechnicalFieldListener.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/config/UpdateTechnicalFieldListener.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -51,6 +51,7 @@
Date createDate = new Date();
entity.setCreateDate(createDate);
+ entity.setUpdateDate(createDate);
if (log.isTraceEnabled()) {
log.trace("PrePersist :: " + entity + " _ createDate = " + createDate);
Modified: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAO.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAO.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAO.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -22,7 +22,8 @@
E newInstance();
/**
- * Create the {@code element}, i.e, persist it. The {@code element} need to be instantiated using {@link #newInstance()}.
+ * Create the {@code element}, i.e, persist it. The {@code element} need to be instantiated using {@link
+ * #newInstance()}.
*
* @param element the object to create.
* @see EntityManager#persist(Object)
@@ -30,8 +31,8 @@
void create(E element);
/**
- * Update the {@code element}. If element is not present in session, it will be retrieved from database and attached to it. The update
- * is directly executed (flushed) to have proper data in resulting object.
+ * Update the {@code element}. If element is not present in session, it will be retrieved from database and attached
+ * to it. The update is directly executed (flushed) to have proper data in resulting object.
*
* @param element the object to update
* @return the object updated attached to the session
@@ -40,15 +41,17 @@
E update(E element);
/**
- * Save the {@code element} will create it if no id is defined or update it otherwise. Updated or created element will be returned as result.
+ * Save the {@code element} will create it if no id is defined or update it otherwise. Updated or created element
+ * will be returned as result.
*
- * @param element Element to save
- * @return the element saved this way
+ * @param element Element to save
+ * @return the element saved this way
*/
E save(E element);
-
+
/**
- * Remove the {@code element}. The reference is still available after removal but the next read will return a null value using the element id.
+ * Remove the {@code element}. The reference is still available after removal but the next read will return a null
+ * value using the element id.
*
* @param element the object to remove
*/
@@ -57,7 +60,7 @@
/**
* Read an element using it's {@code id}.
*
- * @param id Id of the element to read
+ * @param id Id of the element to read
* @return the element if found or null otherwise
*/
E read(K id);
@@ -72,21 +75,11 @@
/**
* Return the number of existing elements.
*
- * @return the number of existing elements
+ * @return the number of existing elements
*/
int count();
/**
- * Clear the current session. Needed after some error occurs.
- */
- void clearSession();
-
- /**
- * Flush the current session. Needed to manually commit the session.
- */
- void flushSession();
-
- /**
* Delete all existing elements of E type
*/
void deleteAll();
Modified: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAOImpl.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAOImpl.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAOImpl.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -1,18 +1,18 @@
package org.nuiton.sandbox.jsr317.jpa2.persistence;
import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
-import javax.persistence.NonUniqueResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Path;
-import javax.persistence.criteria.Root;
-import java.io.Serializable;
+import java.lang.reflect.ParameterizedType;
import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.nuiton.sandbox.jsr317.jpa2.entity.BaseEntity;
import org.nuiton.sandbox.jsr317.jpa2.entity.BaseEntityImpl;
+import org.nuiton.sandbox.jsr317.jpa2.query.CountQueryWrapper;
+import org.nuiton.sandbox.jsr317.jpa2.query.EntityQueryWrapper;
+import org.nuiton.sandbox.jsr317.jpa2.query.QueryWrapper;
/**
* This class provides basic CRUD mechanism.
@@ -22,11 +22,18 @@
* @param <C> the Entity contract (interface)
* @param <E> the Entity class for JPA
*/
-public abstract class BaseDAOImpl<C extends BaseEntity, E extends BaseEntityImpl, K extends Serializable> implements BaseDAO<C, K> {
+public abstract class BaseDAOImpl<C extends BaseEntity, E extends BaseEntityImpl> implements BaseDAO<C, Long> {
+ protected final Log logger = LogFactory.getLog(getClass());
+
public enum SaveStrategy {
- PERSIST(true, false), PERSIST_FLUSH(true, true), MERGE(false, false), MERGE_FLUSH(false, true);
+ DEFAULT(false, false),
+ PERSIST(true, false),
+ PERSIST_FLUSH(true, true),
+ MERGE(false, false),
+ MERGE_FLUSH(false, true);
+
boolean flush;
boolean persist;
@@ -45,125 +52,21 @@
}
}
- protected abstract class QueryWrapper<E extends BaseEntity, R> {
+ /**
+ * EntityManager used as persistence context to manage entities.
+ */
+ @PersistenceContext
+ protected EntityManager entityManager;
- protected CriteriaBuilder builder;
-
- protected CriteriaQuery<R> criteria;
-
- protected Root<E> root;
-
- protected TypedQuery<R> query;
-
- public Root<E> root() {
- if (root == null) {
- root = criteria().from(entityClass());
- }
- return root;
- }
-
- public CriteriaQuery<R> criteria() {
- if (criteria == null) {
- criteria = builder().createQuery(resultClass());
- }
- return criteria;
- }
-
- public CriteriaBuilder builder() {
- if (builder == null) {
- builder = em.getCriteriaBuilder();
- }
- return builder;
- }
-
- public TypedQuery<R> computeCriteria() {
- return em.createQuery(criteria);
- }
-
- public TypedQuery<R> query() {
- if (query == null) {
- query = computeCriteria();
- }
- return query;
- }
-
- public <T> void whereEqual(Path<? extends T> propertyPath, T value) {
- criteria().where(
- builder().equal(
- propertyPath,
- value
- )
- );
- }
-
- public <T> void whereEqual(String property, T value) {
- whereEqual(root().<T>get(property), value);
- }
-
- @SuppressWarnings({"unchecked"})
- protected Class<E> entityClass() {
- // Use entityClass defined in DAO
- return (Class<E>) getEntityClass();
- }
-
- protected abstract Class<R> resultClass();
-
- }
-
- protected class BaseQueryWrapper<C extends BaseEntity, E extends BaseEntityImpl> extends QueryWrapper<E, E> {
-
- @Override
- protected Class<E> resultClass() {
- return entityClass();
- }
-
- @SuppressWarnings({"unchecked"})
- public List<C> listResult() {
- List<E> results = query().getResultList();
- return (List<C>) results;
- }
-
- @SuppressWarnings({"unchecked"})
- public C singleResult() throws NonUniqueResultException, NoResultException {
- E result = query().getSingleResult();
- return (C) result;
- }
- }
-
- protected class CountQueryWrapper<E extends BaseEntity> extends QueryWrapper<E, Long> {
-
- public int count() {
- criteria().select(builder.count(root()));
- return executeCount();
- }
-
- public int countDistinct() {
- criteria().select(builder.countDistinct(root()));
- return executeCount();
- }
-
- protected int executeCount() {
- // Create the query and retrieve the single result corresponding to the count value
- TypedQuery<Long> query = computeCriteria();
- return query.getSingleResult().intValue();
- }
-
- @Override
- protected Class<Long> resultClass() {
- return Long.class;
- }
- }
-
/**
- * Memorizes the Entity Class.
+ * Class of the interface
*/
- private Class<E> entityClass;
+ protected Class<C> interfaceClass;
/**
- * Private EntityManager through Hibernate implementation.
+ * Class of the entity implementation
*/
- @PersistenceContext
- protected EntityManager em;
+ protected Class<E> entityClass;
/**
* The SaveStrategy defined how the save method should be executed, look at {@link #save(BaseEntity)} implementation
@@ -174,10 +77,34 @@
* Constructor to be called by siblings.
*/
public BaseDAOImpl() {
- entityClass = getEntityClass();
- saveStrategy = SaveStrategy.PERSIST;
+ initClasses();
+ saveStrategy = SaveStrategy.DEFAULT;
}
+ @SuppressWarnings({"unchecked"})
+ private void initClasses() throws ClassCastException {
+ ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
+ entityClass = (Class<E>) genericSuperclass.getActualTypeArguments()[1];
+ interfaceClass = (Class<C>) genericSuperclass.getActualTypeArguments()[0];
+ if (logger.isTraceEnabled()) {
+ logger.trace("Initialize classes for DAO " + getClass().getName() +
+ " :: entityClass = " + entityClass.getName() +
+ " _ interfaceClass = " + interfaceClass.getName());
+ }
+ }
+
+ public EntityManager getEntityManager() {
+ return entityManager;
+ }
+
+ public Class<E> getEntityClass() {
+ return entityClass;
+ }
+
+ public Class<C> getInterfaceClass() {
+ return interfaceClass;
+ }
+
public SaveStrategy getSaveStrategy() {
return saveStrategy;
}
@@ -186,21 +113,41 @@
this.saveStrategy = saveStrategy;
}
+ @SuppressWarnings({"unchecked"})
+ @Override
+ public C newInstance() {
+ C result;
+ try {
+ // unchecked because entityClass implements interfaceClass (BaseDAOImpl implements BaseDAO)
+ result = (C) entityClass.newInstance();
+ } catch (InstantiationException ex) {
+ throw new Error(ex);
+ } catch (IllegalAccessException ex) {
+ throw new Error(ex);
+ }
+ return result;
+ }
+
/**
* {@inheritDoc}
*/
@Override
public void create(C element) {
- em.persist(element);
+ if (logger.isTraceEnabled()) {
+ logger.trace("Persist element type : " + element.getClass().getName());
+ }
+ entityManager.persist(element);
}
/**
* {@inheritDoc}
*/
@Override
- public C update(C entity) {
- C result = em.merge(entity);
- em.flush();
+ public C update(C element) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Merge element type : " + element.getClass().getName() + " (ID = " + element.getId() + ")");
+ }
+ C result = entityManager.merge(element);
return result;
}
@@ -212,16 +159,32 @@
// Keep instance by default
C result = element;
- // Type of save, if persist the element need to be in session for an update
- if (saveStrategy.isPersist()) {
- em.persist(element);
- } else {
- result = em.merge(element);
+ if (logger.isTraceEnabled()) {
+ logger.trace("SaveStrategy :: " + saveStrategy);
}
- // Explicit flush
- if (saveStrategy.isFlush()) {
- em.flush();
+ // Default strategy use create and update methods
+ if (SaveStrategy.DEFAULT.equals(saveStrategy)) {
+
+ if (element.getCreateDate() == null) {
+ create(element);
+ } else {
+ result = update(element);
+ }
+
+ } else {
+
+ // Type of save, if persist the element need to be in session for an update
+ if (saveStrategy.isPersist()) {
+ entityManager.persist(element);
+ } else {
+ result = entityManager.merge(element);
+ }
+
+ // Explicit flush
+ if (saveStrategy.isFlush()) {
+ entityManager.flush();
+ }
}
return result;
@@ -232,9 +195,7 @@
*/
@Override
public void delete(final C entity) {
- if (entity != null) {
- em.remove(entity);
- }
+ entityManager.remove(entity);
}
/**
@@ -242,11 +203,11 @@
*/
@SuppressWarnings({"unchecked"})
@Override
- public C read(final K id) {
+ public C read(final Long id) {
if (id == null) {
return null;
}
- return (C) em.find(entityClass, id);
+ return (C) entityManager.find(entityClass, id);
}
/**
@@ -255,7 +216,7 @@
@Override
public List<C> readAll() {
- BaseQueryWrapper<C, E> query = new BaseQueryWrapper<C, E>();
+ EntityQueryWrapper<C, E> query = newQueryWrapper();
query.criteria().select(query.root());
@@ -266,9 +227,9 @@
protected List<C> readAllByProperty(String property, Object value) {
- BaseQueryWrapper<C, E> query = new BaseQueryWrapper<C, E>();
+ EntityQueryWrapper<C, E> query = newQueryWrapper();
- query.whereEqual(property, value);
+ query.addEqual(property, value);
List<C> results = query.listResult();
@@ -286,7 +247,7 @@
*/
@Override
public int count() {
- CountQueryWrapper<E> query = new CountQueryWrapper<E>();
+ CountQueryWrapper<E> query = newCountQueryWrapper();
return query.count();
}
@@ -307,16 +268,6 @@
}
@Override
- public void clearSession() {
- em.clear();
- }
-
- @Override
- public void flushSession() {
- em.flush();
- }
-
- @Override
public void deleteAll() {
List<C> elements = readAll();
for (C element : elements) {
@@ -324,33 +275,16 @@
}
}
- /**
- * Set the limit of the {@code query} depends on {@code search} parameters.
- *
- * @param query Query to add limit parameters
- * @param search Search containing limit parameters
- */
- protected void setSearchLimit(TypedQuery<?> query, Search search) {
- int start = 0;
- if (search.getStartIndex() != null) {
- start = search.getStartIndex();
- query.setFirstResult(start);
- }
+ public EntityQueryWrapper<C, E> newQueryWrapper() {
+ return new EntityQueryWrapper<C, E>(entityManager, entityClass);
+ }
- if (search.getEndIndex() != null) {
- query.setMaxResults(search.getEndIndex() - start + 1);
- }
+ public <R> QueryWrapper<E, R> newCustomQueryWrapper(Class<R> resultClass) {
+ return new QueryWrapper<E, R>(entityManager, entityClass, resultClass);
}
- /**
- * {@inheritDoc}
- */
- @Override
- public abstract C newInstance();
+ public CountQueryWrapper<E> newCountQueryWrapper() {
+ return new CountQueryWrapper<E>(entityManager, entityClass);
+ }
- /**
- * @return the entityClass to manipulate as persistent object (defined in mapping).
- */
- protected abstract Class<E> getEntityClass();
-
}
Modified: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImpl.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImpl.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImpl.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -15,19 +15,9 @@
* @version $Id$
*/
@Repository
-public class CustomerDAOImpl extends BaseDAOImpl<Customer, CustomerImpl, Long> implements CustomerDAO {
+public class CustomerDAOImpl extends BaseDAOImpl<Customer, CustomerImpl> implements CustomerDAO {
@Override
- public Customer newInstance() {
- return new CustomerImpl();
- }
-
- @Override
- protected Class<CustomerImpl> getEntityClass() {
- return CustomerImpl.class;
- }
-
- @Override
public Address newInstanceAddress() {
return new AddressImpl();
}
@@ -36,4 +26,5 @@
public AccessCode newInstanceAccessCode() {
return new AccessCodeImpl();
}
+
}
Modified: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/ModelContext.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/ModelContext.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/ModelContext.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -1,5 +1,6 @@
package org.nuiton.sandbox.jsr317.jpa2.persistence;
+import org.nuiton.sandbox.jsr317.jpa2.entity.BaseEntity;
import org.nuiton.sandbox.jsr317.jpa2.persistence.BaseDAOImpl.SaveStrategy;
/**
@@ -25,4 +26,25 @@
*/
void flushSession();
+ /**
+ * Create a new instance based on {@code pojoClass} to encapsulate given {@code id} into a proper persistent object
+ * needed in queries.
+ *
+ * @param entityClass Class of the pojo to instantiate
+ * @param id Id of this pojo
+ * @param <P> Type of the pojo
+ * @return a new instance of pojo
+ */
+ <P extends BaseEntity> P newInstance(Class<P> entityClass, Long id);
+
+ /**
+ * Retrieve the DAO corresponding to given {@code pojoClass}.
+ *
+ * @param entityClass The Class to retrieve DAO
+ * @param <P> Type of Pojo
+ * @param <D> Type of DAO
+ * @return the DAO corresponding
+ */
+ <P extends BaseEntity, D extends BaseDAO<P, Long>> D getDAO(Class<P> entityClass);
+
}
Modified: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/ModelContextImpl.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/ModelContextImpl.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/ModelContextImpl.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -2,8 +2,10 @@
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
+import java.util.HashMap;
import java.util.Map;
+import org.nuiton.sandbox.jsr317.jpa2.entity.BaseEntity;
import org.nuiton.sandbox.jsr317.jpa2.persistence.BaseDAOImpl.SaveStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
@@ -24,16 +26,20 @@
@PersistenceContext
protected EntityManager entityManager;
- protected Map<String, BaseDAOImpl> daos;
+ protected Map<Class<? extends BaseEntity>, BaseDAOImpl> daos;
/**
* Retrieve daos from Spring applicationContext if needed.
*
* @return the registered DAOs
*/
- public Map<String, BaseDAOImpl> getDAOs() {
+ @SuppressWarnings({"unchecked"})
+ public Map<Class<? extends BaseEntity>, BaseDAOImpl> getDAOs() {
if (daos == null) {
- daos = context.getBeansOfType(BaseDAOImpl.class);
+ daos = new HashMap<Class<? extends BaseEntity>, BaseDAOImpl>();
+ for (BaseDAOImpl dao : context.getBeansOfType(BaseDAOImpl.class).values()) {
+ daos.put(dao.getInterfaceClass(), dao);
+ }
}
return daos;
}
@@ -50,4 +56,19 @@
entityManager.flush();
}
+ @SuppressWarnings({"unchecked"})
+ @Override
+ public <P extends BaseEntity> P newInstance(Class<P> interfaceClass, Long id) {
+ BaseDAOImpl dao = getDAOs().get(interfaceClass);
+ BaseEntity pojo = dao.newInstance();
+ pojo.setId(id);
+ return (P) pojo;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ @Override
+ public <P extends BaseEntity, D extends BaseDAO<P, Long>> D getDAO(Class<P> interfaceClass) {
+ return (D) getDAOs().get(interfaceClass);
+ }
+
}
Deleted: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/Search.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/Search.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/Search.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -1,26 +0,0 @@
-package org.nuiton.sandbox.jsr317.jpa2.persistence;
-
-import java.io.Serializable;
-
-/**
- * Created on 2 nov. 2010
- *
- * @author fdesbois <fdesbois(a)codelutin.com>
- * @version $Id$
- */
-public interface Search extends Serializable {
-
- String getOrderBy();
-
- void setOrderBy(String orderBy);
-
- Integer getStartIndex();
-
- void setStartIndex(Integer startIndex);
-
- Integer getEndIndex();
-
- /** @deprecated FIXME-fdesbois-2010-11-09 : criteria api need maxResults param so nbElementsByPage in PaginatedSearch */
- @Deprecated
- void setEndIndex(Integer endIndex);
-}
Deleted: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/SearchImpl.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/SearchImpl.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/persistence/SearchImpl.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -1,48 +0,0 @@
-package org.nuiton.sandbox.jsr317.jpa2.persistence;
-
-/**
- * Created on 2 nov. 2010
- *
- * @author fdesbois <fdesbois(a)codelutin.com>
- * @version $Id$
- */
-public class SearchImpl implements Search {
-
- public static final long serialVersionUID = 1L;
-
- private String orderBy;
-
- private Integer startIndex;
-
- private Integer endIndex;
-
- @Override
- public String getOrderBy() {
- return orderBy;
- }
-
- @Override
- public void setOrderBy(String orderBy) {
- this.orderBy = orderBy;
- }
-
- @Override
- public Integer getStartIndex() {
- return startIndex;
- }
-
- @Override
- public void setStartIndex(Integer startIndex) {
- this.startIndex = startIndex;
- }
-
- @Override
- public Integer getEndIndex() {
- return endIndex;
- }
-
- @Override
- public void setEndIndex(Integer endIndex) {
- this.endIndex = endIndex;
- }
-}
Added: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/CountQueryWrapper.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/CountQueryWrapper.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/CountQueryWrapper.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -0,0 +1,69 @@
+package org.nuiton.sandbox.jsr317.jpa2.query;
+
+import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
+
+import org.nuiton.sandbox.jsr317.jpa2.entity.BaseEntityImpl;
+
+/**
+ * Implementation of {@link QueryWrapper} with Long result class type used for counting. Ex :
+ * <pre>
+ * CountQueryWrapper<CustomerImpl> wrapper = new CountQueryWrapper<CustomerImpl>(entityManager,
+ * CustomerImpl.class);
+ * <p/>
+ * // Will retrieve all customers starting by toto
+ * wrapper.addPredicate(
+ * wrapper.builder().like(
+ * wrapper.root().get(Customer.PROPERTY_FIRST_NAME, "toto%")
+ * )
+ * );
+ * <p/>
+ * // Will retrieve the number of customers starting by toto
+ * int nbCustomers = wrapper.count();
+ * </pre>
+ * <p/>
+ * Created on 18 nov. 2010
+ *
+ * @param <E> Entity type
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id: CountQueryWrapper.java 52639 2010-12-29 14:24:20Z fdesbois $
+ */
+public class CountQueryWrapper<E extends BaseEntityImpl> extends QueryWrapper<E, Long> {
+
+ public CountQueryWrapper(EntityManager entityManager, Class<E> entityClass) {
+ super(entityManager, entityClass, Long.class);
+ }
+
+ /**
+ * Count the number of result for current criteria.
+ *
+ * @return the number of result
+ */
+ public int count() {
+ criteria().select(builder.count(root()));
+ return executeCount();
+ }
+
+ /**
+ * Count the number of distinct result for current criteria.
+ *
+ * @return the number of distinct result
+ */
+ public int countDistinct() {
+ criteria().select(builder.countDistinct(root()));
+ return executeCount();
+ }
+
+ /**
+ * Create the query using {@link #computeCriteria()} and execute it as single result. The Long result type is
+ * converted as Integer. COUNT constraint must be defined in SELECT to execute properly the counting.
+ *
+ * @return the count result for current criteria
+ */
+ protected int executeCount() {
+ // Create the query and retrieve the single result corresponding to the count value
+ TypedQuery<Long> query = computeCriteria();
+ return query.getSingleResult().intValue();
+ }
+
+}
Added: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/EntityQueryWrapper.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/EntityQueryWrapper.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/EntityQueryWrapper.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -0,0 +1,162 @@
+package org.nuiton.sandbox.jsr317.jpa2.query;
+
+import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
+import javax.persistence.NonUniqueResultException;
+import javax.persistence.TypedQuery;
+import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.Order;
+import javax.persistence.criteria.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.sandbox.jsr317.jpa2.entity.BaseEntity;
+import org.nuiton.sandbox.jsr317.jpa2.entity.BaseEntityImpl;
+
+/**
+ * EntityQueryWrapper is an extension of QueryWrapper using the entityClass as resultClass. This wrapper also provide
+ * safe typed method to return results with interface type and not implementation one. Ex :
+ * <pre>
+ * EntityQueryWrapper<Customer, CustomerImpl> wrapper = new EntityQueryWrapper<Customer,
+ * CustomerImpl>(entityManager,
+ * CustomerImpl.class);
+ * <p/>
+ * // Will retrieve all customers starting by toto
+ * wrapper.addPredicate(
+ * wrapper.builder().like(
+ * wrapper.root().get(Customer.PROPERTY_FIRST_NAME, "toto%")
+ * )
+ * );
+ * <p/>
+ * // Will retrieve the result list from the current query, calling the first time will compute the criteria
+ * List<Customer> customers = wrapper.listResult();
+ * </pre>
+ * It's also possible to limit result using {@link #listResult(Integer, Integer)}
+ * <p/>
+ * Created on 18 nov. 2010
+ *
+ * @param <C> Interface of the entity
+ * @param <E> Implementation of the entity
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id: EntityQueryWrapper.java 52639 2010-12-29 14:24:20Z fdesbois $
+ */
+public class EntityQueryWrapper<C extends BaseEntity, E extends BaseEntityImpl> extends QueryWrapper<E, E> {
+
+ private static final Log logger = LogFactory.getLog(EntityQueryWrapper.class);
+
+ // TODO-fdesbois-2010-12-29 : test if it's possible to have interfaceClass as resultClass, avoiding cast in listResult and singleResult
+ public EntityQueryWrapper(EntityManager entityManager, Class<E> entityClass) {
+ super(entityManager, entityClass, entityClass);
+ }
+
+ /**
+ * Set the OrderBy in the query from an {@code orderByList}. Nothing will be done if the list is null. OrderBy can
+ * also define a referenceClass from {@link OrderBy#getReferenceClass()}, in this case, the path will be retrieved
+ * from the query, you must register query references using {@link #registerPath(Class, Path)} for different object
+ * supported.
+ *
+ * @param orderByList List of OrderBy to set
+ * @see OrderBy
+ * @see #registerPath(Class, Path)
+ */
+ public void setOrderBy(OrderBy... orderByList) {
+
+ if (orderByList == null) {
+ return;
+ }
+
+ // List to add in the criteria
+ List<Order> orders = new ArrayList<Order>();
+
+ for (OrderBy orderBy : orderByList) {
+
+ // Retrieve orderByPath from context using path() method if orderBy defined any referenceClass, otherwise
+ // the query root will be considered as orderByPath.
+ Path<?> orderByPath;
+ if (orderBy.getReferenceClass() != null) {
+ orderByPath = path(orderBy.getReferenceClass());
+ } else {
+ orderByPath = root();
+ }
+
+ if (orderByPath == null) {
+ String msg = "Unknown path for OrderBy reference = " + orderBy.getReferenceClass() + ".";
+ if (paths != null) {
+ msg += " Available references are : [" + StringUtils.join(paths.keySet(), ";") + "]";
+ }
+ throw new IllegalStateException(msg);
+ }
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("OrderBy based on rootPath type = " + orderByPath.getJavaType());
+ }
+
+ // Expression constructed for each orderBy, depends on the implementation
+ Expression<?> orderExpression = orderBy.getExpression(builder(), orderByPath);
+
+ Order order;
+ if (orderBy.isAscending()) {
+ order = builder().asc(orderExpression);
+ } else {
+ order = builder().desc(orderExpression);
+ }
+ orders.add(order);
+ }
+
+ criteria().orderBy(orders);
+
+ }
+
+ /**
+ * Return a result list from the current query.
+ *
+ * @return a List of results with entity interface type.
+ * @see TypedQuery#getResultList()
+ */
+ @SuppressWarnings({"unchecked"})
+ public List<C> listResult() {
+ List<E> results = query().getResultList();
+ return (List<C>) results;
+ }
+
+ /**
+ * Limit the result list with {@code startIndex} and {@code endIndex}. Values can be null.
+ *
+ * @param startIndex Index to start the result limitation
+ * @param endIndex Index to end the result limitation
+ * @return a List of limited results
+ * @see #listResult()
+ */
+ public List<C> listResult(Integer startIndex, Integer endIndex) {
+
+ int start = 0;
+ if (startIndex != null) {
+ start = startIndex;
+ query().setFirstResult(start);
+ }
+
+ if (endIndex != null) {
+ query().setMaxResults(endIndex - start + 1);
+ }
+
+ return listResult();
+ }
+
+ /**
+ * Return a single result from the current query.
+ *
+ * @return a single result with entity interface type
+ * @throws NonUniqueResultException for multiple results error
+ * @throws NoResultException for no result error
+ * @see TypedQuery#getSingleResult()
+ */
+ @SuppressWarnings({"unchecked"})
+ public C singleResult() throws NonUniqueResultException, NoResultException {
+ E result = query().getSingleResult();
+ return (C) result;
+ }
+
+}
Added: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderBy.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderBy.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderBy.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -0,0 +1,42 @@
+package org.nuiton.sandbox.jsr317.jpa2.query;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.Path;
+
+/**
+ * Api used to defined ordering in {@link Search} context. You can use different implementations : <ul> <li>{@link
+ * OrderByAsc} : simple ascending order</li> <li>{@link OrderByDesc} : simple descending order</li> <li>{@link
+ * OrderByRandom} : random order</li> </ul>
+ * <p/>
+ * Created on 17 nov. 2010
+ *
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id: OrderBy.java 49443 2010-11-24 17:16:59Z fdesbois $
+ */
+public interface OrderBy {
+
+ /**
+ * Retrieve expression for criteria api based on {@code rootPath}.
+ *
+ * @param criteriaBuilder Criteria builder could be useful to create the expression
+ * @param rootPath Root path needed to retrieve expression
+ * @return the expression to use in criteria api
+ */
+ Expression<?> getExpression(CriteriaBuilder criteriaBuilder, Path<?> rootPath);
+
+ /**
+ * Flag used to check order type (ascending or descending)
+ *
+ * @return true if ascending order is defined, false for descending order
+ */
+ boolean isAscending();
+
+ /**
+ * Reference class of the orderBy properties
+ *
+ * @return the base class for orderBy properties
+ */
+ Class<?> getReferenceClass();
+
+}
Added: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderByAsc.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderByAsc.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderByAsc.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -0,0 +1,90 @@
+package org.nuiton.sandbox.jsr317.jpa2.query;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.Path;
+import java.util.Arrays;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Ascending OrderBy.
+ * <p/>
+ * Created on 17 nov. 2010
+ *
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id: OrderByAsc.java 51603 2010-12-15 15:09:17Z fdesbois $
+ */
+public class OrderByAsc implements OrderBy {
+
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ protected String[] properties;
+
+ protected boolean ascending;
+
+ protected Class<?> referenceClass;
+
+ /**
+ * Create OrderByAsc creating propertyPath by concatenation of all {@code properties}. Ex : new
+ * OrderByAsc("classifiedAd", "realEstate") will result as : rootPath.get("classifiedAd").get("realEstate")
+ *
+ * @param properties String to concatenate creating the ordering property for query. It's better to use property
+ * constants defined in each Pojo interface.
+ */
+ public OrderByAsc(String... properties) {
+ this.properties = properties;
+ ascending = true;
+ }
+
+ /**
+ * Create OrderByAsc creating propertyPath by concatenation of all {@code properties} based on {@code
+ * referenceClass} pojo. Ex : new OrderByAsc(VideoPartnerLocation.class, "highlighted") will result as :
+ * videoPartnerLocationPath.get("highlighted"). This case is specific, so dao method need to check referenceClass to
+ * ensure the path when {@link #getExpression(CriteriaBuilder, Path)} method is used.
+ *
+ * @param referenceClass Class reference for properties otherwise the default one from DAO will be used.
+ * @param properties String to concatenate creating the ordering property for query. It's better to use property
+ * constants defined in each Pojo interface.
+ */
+ public OrderByAsc(Class<?> referenceClass, String... properties) {
+ this(properties);
+ this.referenceClass = referenceClass;
+ }
+
+ @Override
+ public Class<?> getReferenceClass() {
+ return referenceClass;
+ }
+
+ @Override
+ public Expression<?> getExpression(CriteriaBuilder criteriaBuilder, Path<?> rootPath) {
+ Path<?> path = rootPath;
+ for (String property : properties) {
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("OrderBy property = " + property);
+ }
+
+ path = path.get(property);
+ }
+ return path;
+ }
+
+ @Override
+ public boolean isAscending() {
+ return ascending;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder("[OrderBy").
+ append(ascending ? "Asc" : "Desc").
+ append("] properties = ").
+ append(Arrays.toString(properties)).
+ append(" _ referenceClass = ").
+ append(referenceClass);
+ return builder.toString();
+ }
+}
Added: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderByDesc.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderByDesc.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderByDesc.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -0,0 +1,28 @@
+package org.nuiton.sandbox.jsr317.jpa2.query;
+
+/**
+ * Descending OrderBy.
+ * <p/>
+ * Created on 17 nov. 2010
+ *
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id: OrderByDesc.java 49443 2010-11-24 17:16:59Z fdesbois $
+ */
+public class OrderByDesc extends OrderByAsc {
+
+ /**
+ * {@inheritDoc} for Desc ordering
+ */
+ public OrderByDesc(String... properties) {
+ super(properties);
+ ascending = false;
+ }
+
+ /**
+ * {@inheritDoc} for Desc ordering
+ */
+ public OrderByDesc(Class<?> referenceClass, String... properties) {
+ super(referenceClass, properties);
+ ascending = false;
+ }
+}
Added: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderByRandom.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderByRandom.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/OrderByRandom.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -0,0 +1,52 @@
+package org.nuiton.sandbox.jsr317.jpa2.query;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.Path;
+
+import org.nuiton.sandbox.jsr317.jpa2.entity.BaseEntity;
+
+/**
+ * Random OrderBy. This OrderBy use a specific expression to calculate random based on a randomKey.
+ * <p/>
+ * Created on 17 nov. 2010
+ *
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id: OrderByRandom.java 51603 2010-12-15 15:09:17Z fdesbois $
+ */
+public class OrderByRandom implements OrderBy {
+
+ private long randomKey;
+
+ public OrderByRandom(long randomKey) {
+ this.randomKey = randomKey;
+ }
+
+ @Override
+ public Expression<?> getExpression(CriteriaBuilder criteriaBuilder, Path<?> rootPath) {
+ // product = id * randomKey
+ Expression<Long> product = criteriaBuilder.prod(rootPath.<Long>get(BaseEntity.PROPERTY_ID), randomKey);
+ // modulo = product % 97
+ Expression<Integer> modulo = criteriaBuilder.mod(criteriaBuilder.toInteger(product), 97);
+ // (id * randomKey) % 97
+ return modulo;
+ }
+
+ @Override
+ public boolean isAscending() {
+ // No ascending definition is needed for random
+ return true;
+ }
+
+ @Override
+ public Class<?> getReferenceClass() {
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder("[OrderByRandom] key = ").append(randomKey);
+ return builder.toString();
+ }
+
+}
Added: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/PaginationData.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/PaginationData.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/PaginationData.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -0,0 +1,209 @@
+package org.nuiton.sandbox.jsr317.jpa2.query;
+
+import java.io.Serializable;
+
+/**
+ * Simple bean to transport pagination data. Those data is necessary for any pagination. Generally, the {@link
+ * #PaginationData(int, int, int)} is used to set {@code nbElementsByPage}, {@code currentPage} and {@code
+ * nbPagesToRetrieve}, then {@code nbPages}, {@code nbElements}, {@code startIndex} and {@code endIndex} will be
+ * calculated from {@link #compute(int)} with given nbResults.
+ * <p/>
+ * Created on 15/12/10
+ *
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id: PaginationData.java 52218 2010-12-22 14:37:02Z fdesbois $
+ */
+public class PaginationData implements Serializable {
+
+ public static final long serialVersionUID = 1L;
+
+ private int currentPage = 1;
+
+ private int nbPagesToRetrieve = 1;
+
+ private int nbElementsByPage;
+
+ private int nbResults;
+
+ private int nbPages;
+
+ private int maxAvailablePages;
+
+ private int nbElements;
+
+ private Integer startIndex;
+
+ private Integer endIndex;
+
+ /**
+ * Constructor of PaginationData, can't be initialized without giving {@code nbElementsByPage}, otherwise, this data
+ * can't be used. Default currentPage is 1 and nbPagesToRetrieve is 1 to retrieve first page results.
+ *
+ * @param nbElementsByPage Number of elements to display on each page.
+ */
+ public PaginationData(int nbElementsByPage) {
+ this.nbElementsByPage = nbElementsByPage;
+ }
+
+ /**
+ * Constructor of PaginationData with necessary {@code nbElementsByPage}. {@code currentPage} and {@code
+ * nbPagesToRetrieve} is also set to initialize properly the data at a given point and not from the beginning by
+ * default (currentPage = 1 and nbPagesToRetrieve = 1).
+ *
+ * @param nbElementsByPage Number of elements to display on each page.
+ * @param currentPage Current page to start
+ * @param nbPagesToRetrieve Number of pages to retrieve
+ * @see #PaginationData(int)
+ */
+ public PaginationData(int nbElementsByPage, int currentPage, int nbPagesToRetrieve) {
+ this(nbElementsByPage);
+ this.currentPage = currentPage;
+ this.nbPagesToRetrieve = nbPagesToRetrieve;
+ }
+
+ /**
+ * @return Current page to use : could be set in constructor {@link #PaginationData(int, int, int)}, default will be
+ * 1
+ */
+ public int getCurrentPage() {
+ return currentPage;
+ }
+
+ /**
+ * @return Number of pages to retrieve : could be set in constructor {@link #PaginationData(int, int, int)}, default
+ * will be 1
+ */
+ public int getNbPagesToRetrieve() {
+ return nbPagesToRetrieve;
+ }
+
+ /**
+ * @return Number of elements to display on each page : need to be set in one of the constructor
+ */
+ public int getNbElementsByPage() {
+ return nbElementsByPage;
+ }
+
+ /**
+ * @return Number of total existing results : need to be set using {@link #compute(int)}
+ */
+ public int getNbResults() {
+ return nbResults;
+ }
+
+ /**
+ * @return Number of total pages calculated on {@link #compute(int)} call (nbResults / nbElementsByPage)
+ */
+ public int getNbPages() {
+ return nbPages;
+ }
+
+ /**
+ * @return Number of available pages from current one calculated on {@link #compute(int)} call (nbPages -
+ * currentPage + 1)
+ */
+ public int getMaxAvailablePages() {
+ return maxAvailablePages;
+ }
+
+ /**
+ * @return Number of current elements calculated on {@link #compute(int)} call (nbPagesToRetrieve *
+ * nbElementsByPage)
+ */
+ public int getNbElements() {
+ return nbElements;
+ }
+
+ /**
+ * @return Start index of elements calculated on {@link #compute(int)} call (0 is the minimum, could be null)
+ */
+ public Integer getStartIndex() {
+ return startIndex;
+ }
+
+ /**
+ * @return End index of elements calculated on {@link #compute(int)} call (nbResults - 1 is the maximum, could be
+ * null)
+ */
+ public Integer getEndIndex() {
+ return endIndex;
+ }
+
+ /**
+ * Compute the data validating needed nbResults and nbElementsByPage for pagination and ensure bounds for
+ * currentPage and nbPagesToRetrieve. nbPages and maxAvailablePages will be updated.
+ *
+ * @param nbResults Number of results to compute the data
+ * @throws IllegalArgumentException if nbResults or nbElementsByPage can't be used (not positive)
+ */
+ public void compute(int nbResults) throws IllegalArgumentException {
+
+ if (nbResults < 0) {
+ throw new IllegalArgumentException("Pagination can't be computed if nbResults is not positive");
+ }
+
+ this.nbResults = nbResults;
+
+ if (nbElementsByPage < 1) {
+ throw new IllegalArgumentException("Pagination can't be computed if nbElementsByPage is not positive");
+ }
+
+ // First step : calculate nbPages
+ Double computedValue = Math.ceil((double) nbResults / (double) nbElementsByPage);
+ nbPages = computedValue.intValue();
+
+ // Second step : update currentPage to avoid outOfBounds
+ if (currentPage > nbPages) {
+ currentPage = nbPages;
+ }
+ if (currentPage < 1) {
+ currentPage = 1;
+ }
+
+ // Third step : calculate nbPagesToRetrieve depends on maxAvailablePages
+ maxAvailablePages = nbPages == 0 ? 0 : nbPages - currentPage + 1;
+
+ if (nbPagesToRetrieve > maxAvailablePages) {
+ nbPagesToRetrieve = maxAvailablePages;
+ }
+ if (nbPagesToRetrieve < 1) {
+ nbPagesToRetrieve = 1;
+ }
+
+ // Fourth step : calculate indexes
+
+ // Number of elements to retrieve
+ if (nbResults != 0) {
+ nbElements = nbPagesToRetrieve * nbElementsByPage;
+ // Index to begin
+ startIndex = (currentPage - 1) * nbElementsByPage;
+ // Index to end
+ endIndex = startIndex + nbElements - 1;
+
+ // UpperBound available
+ if (endIndex > nbResults) {
+ endIndex = nbResults;
+ }
+
+ } else {
+ nbElements = 0;
+ startIndex = null;
+ endIndex = null;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "PaginationData{" +
+ "currentPage=" + currentPage +
+ ", nbPagesToRetrieve=" + nbPagesToRetrieve +
+ ", nbElementsByPage=" + nbElementsByPage +
+ ", nbResults=" + nbResults +
+ ", nbPages=" + nbPages +
+ ", maxAvailablePages=" + maxAvailablePages +
+ ", nbElements=" + nbElements +
+ ", startIndex=" + startIndex +
+ ", endIndex=" + endIndex +
+ '}';
+ }
+}
Added: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/QueryWrapper.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/QueryWrapper.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/QueryWrapper.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -0,0 +1,316 @@
+package org.nuiton.sandbox.jsr317.jpa2.query;
+
+import javax.persistence.Entity;
+import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
+import javax.persistence.criteria.AbstractQuery;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.From;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+import javax.persistence.criteria.Subquery;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.sandbox.jsr317.jpa2.entity.BaseEntityImpl;
+
+/**
+ * QueryWrapper is used to contain instances used to create a query with Criteria Api. {@link #base()} is the main
+ * element where QL statements are called (WHERE, FROM, ORDER_BY, ...), then you need {@link #builder()} to create
+ * predicate expressions to use in criteria. The {@link #root()} element is also available depends on E type which
+ * extend the {@link BaseEntityImpl} type. Then you can retrieve {@link TypedQuery} based on criteria created using
+ * {@link #computeCriteria()} method or {@link #query()} if already defined.
+ * <p/>
+ * The simple way to use this wrapper is to add predicates using {@link #addPredicate(Predicate)} method and then
+ * execute the query retrieved using {@link #computeCriteria()}. Each predicate could be created using {@link
+ * #builder()} and {@link #root()} to create property paths. Ex :
+ * <pre>
+ * QueryWrapper<Customer, Customer> wrapper = new QueryWrapper<Customer, Customer>(entityManager,
+ * Customer.class,
+ * Customer.class);
+ * <p/>
+ * // Will retrieve all customers starting by toto
+ * wrapper.addPredicate(
+ * wrapper.builder().like(
+ * wrapper.root().get(Customer.PROPERTY_FIRST_NAME, "toto%")
+ * )
+ * );
+ * <p/>
+ * // Calling query() the first time will compute the criteria, each next calling will keep the same query
+ * List<Customer> customers = wrapper.query().getResultList();
+ * </pre>
+ * <p/>
+ * Created on 18 nov. 2010
+ *
+ * @param <E> EntityClass defined in DAO
+ * @param <R> ResultClass for TypedQuery
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id: QueryWrapper.java 52639 2010-12-29 14:24:20Z fdesbois $
+ * @see EntityQueryWrapper
+ * @see CountQueryWrapper
+ */
+public class QueryWrapper<E extends BaseEntityImpl, R> {
+
+ private static final Log logger = LogFactory.getLog(QueryWrapper.class);
+
+ /**
+ * {@link EntityManager} to retrieve {@link CriteriaBuilder} and construct the resulting {@link TypedQuery}
+ */
+ protected EntityManager entityManager;
+
+ /**
+ * {@link Entity} class where the query is based on ({@link Root} element as first {@link From})
+ */
+ protected Class<E> entityClass;
+
+ /**
+ * Result class for {@link CriteriaQuery} and resulting {@link TypedQuery}
+ */
+ protected Class<R> resultClass;
+
+ /**
+ * Builder used to add constraints in the query
+ */
+ protected CriteriaBuilder builder;
+
+ /**
+ * Criteria where clauses are added (FROM, WHERE, SELECT, ...)
+ */
+ protected CriteriaQuery<R> criteria;
+
+ protected AbstractQuery<R> base;
+
+ /**
+ * Root element based on {@link Entity} class
+ */
+ protected From<?, E> root;
+
+ protected Map<Class<?>, Path<?>> paths;
+
+ /**
+ * Resulting query to execute based on result class
+ */
+ protected TypedQuery<R> query;
+
+ /**
+ * List of current predicates to add to the query (on {@link #computeCriteria()} )
+ */
+ protected List<Predicate> predicates;
+
+ public QueryWrapper(EntityManager entityManager, Class<E> entityClass, Class<R> resultClass) {
+ this.entityManager = entityManager;
+ this.entityClass = entityClass;
+ this.resultClass = resultClass;
+ }
+
+ /**
+ * CriteriaBuilder element used to create predicate expression for criteria.
+ *
+ * @return the CriteriaBuilder
+ */
+ public CriteriaBuilder builder() {
+ if (builder == null) {
+ builder = entityManager.getCriteriaBuilder();
+ }
+ return builder;
+ }
+
+ /**
+ * CriteriaQuery element used to apply QL clauses (WHERE, FROM, ...). It's better to use {@link #base()} method if
+ * you don't need specific treatment on {@link CriteriaQuery} type.
+ *
+ * @return the Criteria based on resultClass
+ * @see #base()
+ */
+ public CriteriaQuery<R> criteria() {
+ if (criteria == null) {
+ criteria = builder().createQuery(resultClass);
+ }
+ return criteria;
+ }
+
+ /**
+ * Retrieve base {@link AbstractQuery} of the wrapper, could be a {@link CriteriaQuery} or a {@link Subquery}. If
+ * not manually defined using {@link #setBase(AbstractQuery)}, the default criteria will be created using {@link
+ * #criteria()}. It seems better to use this method as far as possible instead of {@link #criteria()} to manage also
+ * subqueries if needed.
+ *
+ * @return the {@link AbstractQuery} base of the wrapper
+ * @see #criteria()
+ * @see #setBase(AbstractQuery)
+ */
+ public AbstractQuery<R> base() {
+ if (base == null) {
+ base = criteria();
+ }
+ return base;
+ }
+
+ /**
+ * Set the base asbtractQuery to use it for all operations (from, where, ...). You can set a {@link Subquery} as
+ * base element to manipulate in into the wrapper. All methods on predicates and path will be available but if you
+ * need a criteria you have to retrieve it from the main query otherwise it occurs some errors on {@link
+ * #computeCriteria()} method or {@link #query()}. If you use {@link #addPredicate(Predicate)} method you need to
+ * manually compute all predicates at the end of the treatment using {@link #computePredicates()}.
+ *
+ * @param base Base {@link AbstractQuery} to set, generally a {@link Subquery}
+ */
+ public void setBase(AbstractQuery<R> base) {
+ this.base = base;
+ }
+
+ /**
+ * Root element which is the main From entity based on {@code entityClass}.
+ *
+ * @return the Root typed as entityClass
+ */
+ public From<?, E> root() {
+ if (root == null) {
+ root = base().from(entityClass);
+ }
+ return root;
+ }
+
+ /**
+ * Set manually the root element of the query.
+ *
+ * @param root From element used as main root
+ */
+ public void setRoot(From<?, E> root) {
+ this.root = root;
+ }
+
+ /**
+ * Register a {@code path} for the {@code referenceClass}. This could be useful to keep getPath context during all
+ * the query creation. Retrieve getPath using {@link #path(Class)} method.
+ *
+ * @param referenceClass Class to associate the specified getPath
+ * @param path Path corresponding to the referenceClass
+ */
+ public void registerPath(Class<?> referenceClass, Path<?> path) {
+ if (paths == null) {
+ paths = new HashMap<Class<?>, Path<?>>();
+ }
+ paths.put(referenceClass, path);
+ }
+
+ /**
+ * Retrieve a path for the {@code referenceClass}. This will return null if referenceClass is not previously
+ * registered using {@link #registerPath(Class, Path)}. Root path could simply be retrieved using {@link #root()}.
+ *
+ * @param referenceClass Reference Class to retrieve the corresponding path
+ * @return the Path corresponding to the reference class
+ */
+ public Path<?> path(Class<?> referenceClass) {
+ return paths != null ? paths.get(referenceClass) : null;
+ }
+
+ /**
+ * Add all registered predicates to the {@link #base()} query in WHERE clause.
+ *
+ * @see #addPredicate(Predicate)
+ */
+ public void computePredicates() {
+ if (predicates != null) {
+ base().where(predicates.toArray(new Predicate[predicates.size()]));
+ }
+ }
+
+ /**
+ * Create a TypedQuery from the current criteria. Predicate list will be added to the where of the query. You can
+ * also call {@link #query()} to avoid computing criteria each time and so retrieve the current query.
+ *
+ * @return a TypedQuery
+ * @throws NullPointerException if criteria is null, must use {@link #criteria()} method before compute it.
+ */
+ public TypedQuery<R> computeCriteria() {
+ computePredicates();
+ query = entityManager.createQuery(criteria);
+ return query;
+ }
+
+ /**
+ * Retrieve the current TypedQuery. The query will be computed once based on current criteria if it's not manually
+ * done using {@link #computeCriteria()}.
+ *
+ * @return the current TypedQuery
+ * @see #computeCriteria()
+ */
+ public TypedQuery<R> query() {
+ if (query == null) {
+ computeCriteria();
+ }
+ return query;
+ }
+
+ /**
+ * Add a predicate to the current list. This predicate will be add to the where clause of the query on {@link
+ * #computePredicates()}. The computing will be automatically done on query execution with {@link #query()} or
+ * {@link #computeCriteria()}.
+ *
+ * @param predicate New predicate to add to the query
+ * @see #query()
+ */
+ public void addPredicate(Predicate predicate) {
+ if (predicates == null) {
+ predicates = new ArrayList<Predicate>();
+ }
+ predicates.add(predicate);
+ }
+
+ /**
+ * Add an equal predicate to the query : {@code propertyPath} = {@code value}. If value is null, the isNull
+ * predicate will be added for the {@code propertyPath}.
+ *
+ * @param propertyPath Path to access the property
+ * @param value Value of this property in the query
+ * @param <T> Type of the property
+ * @return Predicate constructed this way (already added to the query)
+ */
+ public <T> Predicate addEqual(Path<? extends T> propertyPath, T value) {
+
+ Predicate equalPredicate;
+
+ if (value == null) {
+ equalPredicate = builder().isNull(propertyPath);
+ } else {
+ equalPredicate = builder().equal(propertyPath, value);
+ }
+
+ addPredicate(equalPredicate);
+
+ return equalPredicate;
+ }
+
+ /**
+ * Add an equal predicate to the query : {@code property} = {@code value}. If value is null, the isNull predicate
+ * will be added for the {@code property}.
+ *
+ * @param property Attribute name of the root entity to apply the constraint
+ * @param value Value of this property in the query
+ * @param <T> Type of the property
+ * @return Predicate constructed this way (already added to the query)
+ */
+ public <T> Predicate addEqual(String property, T value) {
+ return addEqual(root().<T>get(property), value);
+ }
+
+ /**
+ * Add or predicate to the query : predicate1 OR predicate2 OR ...
+ *
+ * @param predicates List of predicate to add as OR predicate
+ * @return Predicate constructed this way (already added to the query)
+ */
+ public Predicate addOr(List<Predicate> predicates) {
+ Predicate orPredicate = builder().or(predicates.toArray(new Predicate[predicates.size()]));
+ addPredicate(orPredicate);
+ return orPredicate;
+ }
+
+}
Added: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/Search.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/Search.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/query/Search.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -0,0 +1,49 @@
+package org.nuiton.sandbox.jsr317.jpa2.query;
+
+import java.util.List;
+
+/**
+ * Created on 2 nov. 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id: Search.java 433 2010-11-12 17:53:20Z fdesbois $
+ */
+public class Search {
+
+ public static final long serialVersionUID = 1L;
+
+ private OrderBy[] orderBy;
+
+ private Integer startIndex;
+
+ private Integer endIndex;
+
+ public OrderBy[] getOrderBy() {
+ return orderBy;
+ }
+
+ public void setOrderBy(OrderBy... orderBy) {
+ this.orderBy = orderBy;
+ }
+
+ public void setOrderBy(List<OrderBy> orderBys) {
+ setOrderBy(orderBys.toArray(new OrderBy[orderBys.size()]));
+ }
+
+ public Integer getStartIndex() {
+ return startIndex;
+ }
+
+ public void setStartIndex(Integer startIndex) {
+ this.startIndex = startIndex;
+ }
+
+ public Integer getEndIndex() {
+ return endIndex;
+ }
+
+ public void setEndIndex(Integer endIndex) {
+ this.endIndex = endIndex;
+ }
+
+}
Modified: jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/entity/EntityManagerTest.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/entity/EntityManagerTest.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/entity/EntityManagerTest.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -2,12 +2,13 @@
import javax.persistence.PersistenceException;
import javax.persistence.Query;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
-import org.nuiton.sandbox.jsr317.jpa2.test.BaseTest;
+import org.nuiton.sandbox.jsr317.jpa2.test.BaseJpaTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Transactional;
@@ -17,7 +18,7 @@
* @author fdesbois <florian.desbois(a)wiztivi.com>
* @version $Id$
*/
-public class EntityManagerTest extends BaseTest {
+public class EntityManagerTest extends BaseJpaTest {
private static final Log log = LogFactory.getLog(EntityManagerTest.class);
@@ -40,42 +41,42 @@
user.setLastName("lastName");
user.setFirstName("firstName");
- em.persist(user);
+ entityManager.persist(user);
long userId = user.getId();
log.debug("Created entity with id " + userId + " at " + user.getCreateDate());
// Entity is still in the EntityManager
- Assert.assertTrue(em.contains(user));
+ Assert.assertTrue(entityManager.contains(user));
// Flush session to insert the entity before detach it
- em.flush();
+ entityManager.flush();
// Detach the entity to find it from database
- em.detach(user);
- Assert.assertFalse(em.contains(user));
+ entityManager.detach(user);
+ Assert.assertFalse(entityManager.contains(user));
// Object not attached to the entityManager, a query will be called
- Customer userFound = em.find(CustomerImpl.class, userId);
+ Customer userFound = entityManager.find(CustomerImpl.class, userId);
// Check data
Assert.assertNotNull(userFound);
Assert.assertNotNull(userFound.getId());
Assert.assertEquals(0, userFound.getVersion());
Assert.assertNotNull(userFound.getCreateDate());
- Assert.assertNull(userFound.getUpdateDate());
+ Assert.assertNotNull(userFound.getUpdateDate());
Assert.assertEquals("lastName", userFound.getLastName());
Assert.assertEquals("firstName", userFound.getFirstName());
// Update name, check version changed
userFound.setLastName("nameChanged");
- em.merge(userFound);
+ entityManager.merge(userFound);
// Version not changed before commit (or manual flush)
- userFound = em.find(CustomerImpl.class, userId);
+ userFound = entityManager.find(CustomerImpl.class, userId);
Assert.assertEquals(0, userFound.getVersion());
Assert.assertEquals("nameChanged", userFound.getLastName());
- em.flush();
+ entityManager.flush();
// Version is updated
Assert.assertEquals(1, userFound.getVersion());
@@ -91,27 +92,27 @@
user1.setLastName("lastName1");
user1.setFirstName("firstName1");
- em.persist(user1);
+ entityManager.persist(user1);
Customer user2 = new CustomerImpl();
user2.setLastName("lastName2");
user2.setFirstName("firstName2");
- em.persist(user2);
+ entityManager.persist(user2);
// ---- EXECUTE ---- //
String readAllCustomersQuery = new StringBuilder("FROM ").append(CustomerImpl.class.getSimpleName()).toString();
// Create named query to check all existing accounts
- Query query = em.createQuery(readAllCustomersQuery);
+ Query query = entityManager.createQuery(readAllCustomersQuery);
Assert.assertEquals(2, query.getResultList().size());
// Delete all data from AccountImpl
userDAO.deleteAll();
// Create named query to check all existing accounts
- query = em.createQuery(readAllCustomersQuery);
+ query = entityManager.createQuery(readAllCustomersQuery);
Assert.assertEquals(0, query.getResultList().size());
}
@@ -123,11 +124,11 @@
user.setLastName("lastName");
user.setFirstName("firstName");
- em.persist(user);
+ entityManager.persist(user);
- em.detach(user);
+ entityManager.detach(user);
- em.persist(user);
+ entityManager.persist(user);
}
@Test
@@ -138,14 +139,14 @@
user.setLastName("lastName");
user.setFirstName("firstName");
- em.persist(user);
+ entityManager.persist(user);
// Flush session to insert the entity before detach it
- em.flush();
+ entityManager.flush();
- em.detach(user);
+ entityManager.detach(user);
- em.merge(user);
+ entityManager.merge(user);
}
@Test
@@ -156,14 +157,14 @@
user.setLastName("lastName");
user.setFirstName("firstName");
- Customer userCreated = em.merge(user);
+ Customer userCreated = entityManager.merge(user);
// Flush session to insert the entity before detach it
- em.flush();
+ entityManager.flush();
- em.detach(userCreated);
+ entityManager.detach(userCreated);
- em.merge(userCreated);
+ entityManager.merge(userCreated);
}
@Test
@@ -175,14 +176,14 @@
user.setFirstName("firstName");
// Persist the user
- em.persist(user);
+ entityManager.persist(user);
// Create a new bean with existing id
Customer userToUpdate = new CustomerImpl();
userToUpdate.setId(user.getId());
userToUpdate.setLastName("newLastName");
- Customer userUpdated = em.merge(userToUpdate);
+ Customer userUpdated = entityManager.merge(userToUpdate);
// All data are updated, so firstName becomes NULL
Assert.assertNull(userUpdated.getFirstName());
Assert.assertEquals("newLastName", userUpdated.getLastName());
Modified: jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/entity/MetaModelTest.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/entity/MetaModelTest.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/entity/MetaModelTest.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -2,7 +2,7 @@
import org.junit.Assert;
import org.junit.Test;
-import org.nuiton.sandbox.jsr317.jpa2.test.BaseTest;
+import org.nuiton.sandbox.jsr317.jpa2.test.BaseJpaTest;
/**
* Created on 26 nov. 2010
@@ -10,7 +10,7 @@
* @author fdesbois <florian.desbois(a)wiztivi.com>
* @version $Id$
*/
-public class MetaModelTest extends BaseTest {
+public class MetaModelTest extends BaseJpaTest {
@Test
public void testEmbeddableSingularAttribute() {
@@ -19,8 +19,8 @@
Assert.assertNotNull(AccessCodeImpl_.password);
// Broken with Hibernate 3.6 and MetamodelGenerator 1.1
- Assert.assertNotNull(AddressImpl_.town);
- Assert.assertNotNull(AddressImpl_.country);
+// Assert.assertNotNull(AddressImpl_.town);
+// Assert.assertNotNull(AddressImpl_.country);
}
}
Modified: jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAOImplTest.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAOImplTest.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/persistence/BaseDAOImplTest.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -1,14 +1,15 @@
package org.nuiton.sandbox.jsr317.jpa2.persistence;
import java.util.List;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+
+import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.nuiton.sandbox.jsr317.jpa2.entity.Customer;
import org.nuiton.sandbox.jsr317.jpa2.entity.CustomerImpl;
import org.nuiton.sandbox.jsr317.jpa2.persistence.BaseDAOImpl.SaveStrategy;
-import org.nuiton.sandbox.jsr317.jpa2.test.BaseTest;
+import org.nuiton.sandbox.jsr317.jpa2.test.BaseJpaTest;
+import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Transactional;
/**
@@ -19,13 +20,13 @@
* @author fdesbois <florian.desbois(a)codelutin.com>
* @version $Id$
*/
-public class BaseDAOImplTest extends BaseTest {
+public class BaseDAOImplTest extends BaseJpaTest {
- private static final Log log = LogFactory.getLog(BaseDAOImplTest.class);
-
- @Override
- protected boolean autoDataEnabled() {
- return true;
+ @After
+ @Transactional
+ @Rollback(false)
+ public void tearDown() throws Exception {
+ userDAO.deleteAll();
}
@Test
@@ -38,17 +39,17 @@
user.setFirstName("createFirstName");
// ---- EXECUTE ---- //
- log.info("CREATE user " + user);
+ logger.info("CREATE user " + user);
userDAO.create(user);
- log.debug("AFTER CREATE user " + user);
+ logger.debug("AFTER CREATE user " + user);
// ---- CHECK DATA ---- //
Assert.assertNotNull(user.getId());
Assert.assertNotNull(user.getCreateDate());
- Assert.assertNull(user.getUpdateDate());
+ Assert.assertNotNull(user.getUpdateDate());
Assert.assertEquals(0, user.getVersion());
- Customer userFound = em.find(CustomerImpl.class, user.getId());
+ Customer userFound = entityManager.find(CustomerImpl.class, user.getId());
Assert.assertNotNull(userFound);
Assert.assertEquals("createLastName", userFound.getLastName());
Assert.assertEquals("createFirstName", userFound.getFirstName());
@@ -63,20 +64,21 @@
user.setLastName("updateLastName");
user.setFirstName("updateFirstName");
- em.persist(user);
- em.flush();
- em.detach(user);
+ entityManager.persist(user);
+ entityManager.flush();
+ entityManager.detach(user);
// ---- EXECUTE ---- //
user.setLastName("nameUpdated");
- log.info("UPDATE user " + user);
+ logger.info("UPDATE user " + user);
Customer userUpdated = userDAO.update(user);
- log.debug("AFTER UPDATE user " + userUpdated);
+ logger.debug("AFTER UPDATE user " + userUpdated);
// ---- CHECK DATA ---- //
- Assert.assertFalse(em.contains(user));
- Assert.assertTrue(em.contains(userUpdated));
+ Assert.assertFalse(entityManager.contains(user));
+ Assert.assertTrue(entityManager.contains(userUpdated));
+ entityManager.flush();
Assert.assertNotNull(userUpdated.getUpdateDate());
Assert.assertEquals(1, userUpdated.getVersion());
Assert.assertEquals("nameUpdated", userUpdated.getLastName());
@@ -100,7 +102,7 @@
// ## CREATE ## //
Customer userCreated = userDAO.save(user);
- if (!strategy.isPersist()) {
+ if (strategy != SaveStrategy.DEFAULT && !strategy.isPersist()) {
// Same as a create instead of returning the instance instead of modifying the input one
Assert.assertNotSame(user, userCreated);
} else {
@@ -109,7 +111,7 @@
Assert.assertNotNull(userCreated.getId());
Assert.assertNotNull(userCreated.getCreateDate());
- Assert.assertNull(userCreated.getUpdateDate());
+ Assert.assertNotNull(userCreated.getUpdateDate());
Assert.assertEquals(0, userCreated.getVersion());
// ## UPDATE ## //
@@ -123,10 +125,10 @@
Assert.assertEquals(1, userUpdated.getVersion());
} else {
- Assert.assertNull(userUpdated.getUpdateDate());
+ Assert.assertNotNull(userUpdated.getUpdateDate());
Assert.assertEquals(0, userUpdated.getVersion());
// need explicit Flush
- userDAO.flushSession();
+ entityManager.flush();
}
// Other update no change, no version increment
@@ -134,7 +136,6 @@
Assert.assertEquals(1, userUpdatedTwice.getVersion());
}
-
@Test
@Transactional
public void testDelete() throws Exception {
@@ -144,15 +145,15 @@
user.setLastName("deleteLastName");
user.setFirstName("deleteFirstName");
- em.persist(user);
+ entityManager.persist(user);
// ---- EXECUTE ---- //
- log.info("DELETE account " + user);
+ logger.info("DELETE account " + user);
userDAO.delete(user);
- log.debug("AFTER DELETE account " + user);
+ logger.debug("AFTER DELETE account " + user);
// ---- CHECK DATA ---- //
- Customer accountFound = em.find(CustomerImpl.class, user.getId());
+ Customer accountFound = entityManager.find(CustomerImpl.class, user.getId());
Assert.assertNull(accountFound);
}
@@ -165,10 +166,10 @@
account.setLastName("readLastName");
account.setFirstName("readFirstName");
- em.persist(account);
+ entityManager.persist(account);
// ---- EXECUTE ---- //
- log.info("READ account " + account);
+ logger.info("READ account " + account);
Customer accountFound = userDAO.read(account.getId());
// ---- CHECK DATA ---- //
@@ -185,16 +186,16 @@
user1.setLastName("readAllLastName1");
user1.setFirstName("readAllFirstName1");
- em.persist(user1);
+ entityManager.persist(user1);
Customer user2 = new CustomerImpl();
user2.setLastName("readAllLastName2");
user2.setFirstName("readAllFirstName2");
- em.persist(user2);
+ entityManager.persist(user2);
// ---- EXECUTE ---- //
- log.info("READ_ALL accounts");
+ logger.info("READ_ALL accounts");
List<Customer> users = userDAO.readAll();
// ---- CHECK DATA ---- //
@@ -212,16 +213,16 @@
user1.setLastName("readAllLastName1");
user1.setFirstName("readAllFirstName1");
- em.persist(user1);
+ entityManager.persist(user1);
Customer user2 = new CustomerImpl();
user2.setLastName("readAllLastName2");
user2.setFirstName("readAllFirstName2");
- em.persist(user2);
+ entityManager.persist(user2);
// ---- EXECUTE ---- //
- log.info("COUNT accounts");
+ logger.info("COUNT accounts");
int count = userDAO.count();
// ---- CHECK DATA ---- //
@@ -233,11 +234,12 @@
public void testNewInstance() throws Exception {
// ---- EXECUTE ---- //
- log.info("NEW_INSTANCE account");
+ logger.info("NEW_INSTANCE account");
Customer user = userDAO.newInstance();
// ---- CHECK DATA ---- //
Assert.assertNotNull(user);
Assert.assertEquals(CustomerImpl.class, user.getClass());
}
+
}
Modified: jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImplTest.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImplTest.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImplTest.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -9,8 +9,9 @@
import org.nuiton.sandbox.jsr317.jpa2.config.JpaHelper;
import org.nuiton.sandbox.jsr317.jpa2.entity.Address;
import org.nuiton.sandbox.jsr317.jpa2.entity.Customer;
+import org.nuiton.sandbox.jsr317.jpa2.sample.UseDataProvider;
import org.nuiton.sandbox.jsr317.jpa2.test.AddressFake;
-import org.nuiton.sandbox.jsr317.jpa2.test.BaseTest;
+import org.nuiton.sandbox.jsr317.jpa2.test.BaseJpaTest;
import org.springframework.transaction.annotation.Transactional;
/**
@@ -19,13 +20,9 @@
* @author fdesbois <florian.desbois(a)codelutin.com>
* @version $Id$
*/
-public class CustomerDAOImplTest extends BaseTest {
+@UseDataProvider
+public class CustomerDAOImplTest extends BaseJpaTest {
- @Override
- protected boolean autoDataEnabled() {
- return true;
- }
-
@Test
@Transactional
public void testCreateCustomerWithAddress() {
Added: jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/query/PaginationDataTest.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/query/PaginationDataTest.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/query/PaginationDataTest.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -0,0 +1,112 @@
+package org.nuiton.sandbox.jsr317.jpa2.query;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Created on 4 nov. 2010
+ *
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id: PaginationDataTest.java 51940 2010-12-17 17:22:32Z fdesbois $
+ */
+public class PaginationDataTest {
+
+ private static final Log logger = LogFactory.getLog(PaginationDataTest.class);
+
+ protected PaginationData pagination;
+
+ @Test
+ public void testCompute() {
+
+ pagination = new PaginationData(20);
+
+ pagination.compute(150);
+
+ Assert.assertEquals(1, pagination.getCurrentPage());
+ Assert.assertEquals(1, pagination.getNbPagesToRetrieve());
+ Assert.assertEquals(20, pagination.getNbElementsByPage());
+ Assert.assertEquals(150, pagination.getNbResults());
+ Assert.assertEquals(8, pagination.getNbPages());
+ Assert.assertEquals(8, pagination.getMaxAvailablePages());
+ Assert.assertEquals(20, pagination.getNbElements());
+ Assert.assertEquals((Integer) 0, pagination.getStartIndex());
+ Assert.assertEquals((Integer) 19, pagination.getEndIndex());
+ }
+
+ @Test
+ public void testSetCurrentPageSuccess() {
+
+ pagination = new PaginationData(20, 3, 1);
+
+ pagination.compute(150);
+
+ // Indexes are updated
+ Assert.assertEquals(20, pagination.getNbElements());
+ Assert.assertEquals((Integer) 40, pagination.getStartIndex());
+ Assert.assertEquals((Integer) 59, pagination.getEndIndex());
+ }
+
+ @Test
+ public void testSetCurrentPageUpdated() {
+
+ pagination = new PaginationData(20, 9, 1);
+
+ pagination.compute(150);
+
+ Assert.assertEquals(8, pagination.getCurrentPage());
+ }
+
+ @Test
+ public void testSetNbPagesToRetrieve() {
+
+ pagination = new PaginationData(20, 3, 2);
+
+ pagination.compute(150);
+
+ // Indexes are updated
+ Assert.assertEquals(40, pagination.getNbElements());
+ Assert.assertEquals((Integer) 40, pagination.getStartIndex());
+ Assert.assertEquals((Integer) 79, pagination.getEndIndex());
+ }
+
+ @Test
+ public void testSetNbPagesToRetrieveOutOfBounds() {
+
+ // 18 is out of bounds, all pages from page 3 will be retrieved, i.e : 3, 4, 5, 6, 7, 8, 9
+ pagination = new PaginationData(20, 3, 18);
+
+ pagination.compute(180);
+
+ logger.debug(pagination);
+
+ Assert.assertEquals(9, pagination.getNbPages());
+ Assert.assertEquals(7, pagination.getNbPagesToRetrieve());
+ // Indexes are updated
+ Assert.assertEquals(140, pagination.getNbElements());
+ Assert.assertEquals((Integer) 40, pagination.getStartIndex());
+ Assert.assertEquals((Integer) 179, pagination.getEndIndex());
+ }
+
+ @Test
+ public void testNoResults() {
+
+ pagination = new PaginationData(20, 1, 1);
+
+ pagination.compute(0);
+
+ logger.debug(pagination);
+
+ Assert.assertEquals(1, pagination.getCurrentPage());
+ Assert.assertEquals(1, pagination.getNbPagesToRetrieve());
+ Assert.assertEquals(20, pagination.getNbElementsByPage());
+ Assert.assertEquals(0, pagination.getNbResults());
+ Assert.assertEquals(0, pagination.getNbPages());
+ Assert.assertEquals(0, pagination.getMaxAvailablePages());
+ Assert.assertEquals(0, pagination.getNbElements());
+ Assert.assertNull(pagination.getStartIndex());
+ Assert.assertNull(pagination.getEndIndex());
+ }
+
+}
Modified: jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/sample/DataSampleProvider.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/sample/DataSampleProvider.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/sample/DataSampleProvider.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -1,10 +1,11 @@
package org.nuiton.sandbox.jsr317.jpa2.sample;
-import java.util.LinkedHashMap;
-import java.util.Map;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.sandbox.jsr317.jpa2.entity.BaseEntity;
import org.nuiton.sandbox.jsr317.jpa2.entity.Customer;
import org.nuiton.sandbox.jsr317.jpa2.persistence.CustomerDAO;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,44 +25,15 @@
private static final Log logger = LogFactory.getLog(DataSampleProvider.class);
- /**
- * Extension of {@link LinkedHashMap} with getter on index. Use {@link #get(int)} method to retrieve element at provided index.
- *
- * @param <K> Key type of the Map
- * @param <O> Object type of the Map
- */
- protected class IndexedMap<K, O extends BaseEntity> extends LinkedHashMap<K, O> {
-
- public O get(int index) {
- int i = 0;
- for (O o : values()) {
- if (i == index) {
- return o;
- }
- i++;
- }
- return null;
- }
-
- @Override
- public O put(K key, O value) {
- if (logger.isTraceEnabled()) {
- logger.trace("Add " + value.getClass().getSimpleName() + " with id = " + value.getId() +
- " _ @" + Integer.toHexString(value.hashCode()));
- }
- return super.put(key, value);
- }
- }
-
@Autowired
protected CustomerDAO customerDAO;
- protected IndexedMap<Long, Customer> customers = new IndexedMap<Long, Customer>();
+ protected List<Customer> customers = new ArrayList<Customer>();
- public void createAllData() {
+ public void createData(DataProviderLimit limit) {
if (logger.isDebugEnabled()) {
- logger.debug("#### SAMPLE INSERT START ####");
+ logger.debug("#### SAMPLE INSERT START :: " + limit + " ####");
}
createCustomers();
@@ -102,7 +74,38 @@
return customers.get(index);
}
- public Map<Long, Customer> getCustomers() {
+ public List<Customer> getCustomers() {
return customers;
}
+
+ protected <T> List<T> subList(List<T> list, int from, int to) {
+ // subList exclude by default the "to" index, in most of cases, we want also the "to" element
+ int toInclude = to + 1;
+ // it's important to check the max case to avoid IndexOutOfBoundsException, the last element will be also part
+ // of the resulting list.
+ if (toInclude > list.size()) {
+ toInclude = to;
+ }
+ return list.subList(from, toInclude);
+ }
+
+ /**
+ * Simple method to retrieve annotation linked with {@code method}. If defined on the method, the annotation will
+ * directly be used, otherwise the one on the class is returned (could be null). So if the annotation is defined on
+ * the method, parameters from class will be ignored (no inheritance is done).
+ *
+ * @param method Method where annotation is retrieved
+ * @return the UseDataProvider annotation linked to this method or null if no annotation is found
+ */
+ public static UseDataProvider getUseDataProviderAnnotation(Method method) {
+
+ UseDataProvider useDataProvider = method.getAnnotation(UseDataProvider.class);
+
+ if (useDataProvider == null) {
+ useDataProvider = method.getDeclaringClass().getAnnotation(UseDataProvider.class);
+ }
+
+ return useDataProvider;
+ }
+
}
Copied: jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/BaseJpaTest.java (from rev 444, jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/BaseTest.java)
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/BaseJpaTest.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/BaseJpaTest.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -0,0 +1,78 @@
+package org.nuiton.sandbox.jsr317.jpa2.test;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Rule;
+import org.junit.rules.TestWatchman;
+import org.junit.runner.RunWith;
+import org.junit.runners.model.FrameworkMethod;
+import org.nuiton.sandbox.jsr317.jpa2.persistence.CustomerDAO;
+import org.nuiton.sandbox.jsr317.jpa2.sample.DataProviderLimit;
+import org.nuiton.sandbox.jsr317.jpa2.sample.DataSampleProvider;
+import org.nuiton.sandbox.jsr317.jpa2.sample.UseDataProvider;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * Created on 18 oct. 2010
+ *
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ * @version $Id$
+ */
+(a)RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"/test-jpa-spring-context.xml"})
+public abstract class BaseJpaTest {
+
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ @Autowired
+ protected ApplicationContext context;
+
+ @PersistenceContext
+ protected EntityManager entityManager;
+
+ @Autowired
+ protected DataSampleProvider dataProvider;
+
+ @Autowired
+ protected CustomerDAO userDAO;
+
+ protected class JpaTestRule extends TestWatchman {
+
+ @Override
+ public void starting(FrameworkMethod method) {
+ super.starting(method);
+
+ // Use DataProvider depends on annotation declaration in tests
+ useDataProvider(DataSampleProvider.getUseDataProviderAnnotation(method.getMethod()));
+ }
+
+ protected void useDataProvider(UseDataProvider useDataProvider) {
+ if (useDataProvider != null && useDataProvider.value()) {
+ createData(useDataProvider.limit());
+ }
+ }
+
+ protected void createData(DataProviderLimit limit) {
+ try {
+ dataProvider.createData(limit);
+ } catch (Exception ex) {
+ logger.error(ex.getMessage(), ex);
+ }
+ }
+
+ }
+
+ @Rule
+ public TestWatchman rule = new JpaTestRule();
+
+ protected RandomFunction getRandomExpression() {
+ return new RandomFunction(entityManager.getCriteriaBuilder());
+ }
+
+}
Property changes on: jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/BaseJpaTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Deleted: jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/BaseTest.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/BaseTest.java 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/BaseTest.java 2010-12-29 16:15:42 UTC (rev 445)
@@ -1,76 +0,0 @@
-package org.nuiton.sandbox.jsr317.jpa2.test;
-
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Rule;
-import org.junit.rules.TestName;
-import org.junit.runner.RunWith;
-import org.junit.runners.model.FrameworkMethod;
-import org.nuiton.sandbox.jsr317.jpa2.persistence.CustomerDAO;
-import org.nuiton.sandbox.jsr317.jpa2.sample.DataSampleProvider;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.annotation.Rollback;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-/**
- * Created on 18 oct. 2010
- *
- * @author fdesbois <fdesbois(a)codelutin.com>
- * @version $Id$
- */
-(a)RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = {"/test-context.xml"})
-public abstract class BaseTest {
-
- private static final Log logger = LogFactory.getLog(BaseTest.class);
-
- @PersistenceContext
- protected EntityManager em;
-
- @Autowired
- protected DataSampleProvider dataProvider;
-
- @Autowired
- protected CustomerDAO userDAO;
-
- @Rule
- public TestName rule = new TestName() {
-
- @Override
- public void starting(FrameworkMethod method) {
- super.starting(method);
- if (autoDataEnabled()) {
- try {
- dataProvider.createAllData();
- } catch (Exception eee) {
- logger.error(eee.getClass().getSimpleName(), eee);
- }
- }
- }
-
- @Override
- public void finished(FrameworkMethod method) {
- if (autoDataEnabled()) {
-
- Rollback rollback = method.getAnnotation(Rollback.class);
-
- if (rollback == null || rollback.value()) {
- dataProvider.deleteAllData();
- }
- }
- super.finished(method);
- }
-
- public BaseTest getTest() {
- return BaseTest.this;
- }
- };
-
- protected boolean autoDataEnabled() {
- return false;
- }
-
-}
Deleted: jpa2-validation/trunk/jsr317-jpa2/src/test/resources/test-context.xml
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/resources/test-context.xml 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/resources/test-context.xml 2010-12-29 16:15:42 UTC (rev 445)
@@ -1,16 +0,0 @@
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
-
- <!--<import resource="classpath:META-INF/jsr317-spring-context.xml"/>-->
-
- <!-- Load Spring Configuration from Java file -->
- <bean class="org.nuiton.sandbox.jsr317.jpa2.test.SpringTestConfig" />
-
- <!-- Scan sample -->
- <context:component-scan base-package="org.nuiton.sandbox.jsr317.jpa2.sample" />
-
-</beans>
\ No newline at end of file
Copied: jpa2-validation/trunk/jsr317-jpa2/src/test/resources/test-jpa-spring-context.xml (from rev 444, jpa2-validation/trunk/jsr317-jpa2/src/test/resources/test-context.xml)
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/resources/test-jpa-spring-context.xml (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/resources/test-jpa-spring-context.xml 2010-12-29 16:15:42 UTC (rev 445)
@@ -0,0 +1,16 @@
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+ <!--<import resource="classpath:META-INF/jsr317-spring-context.xml"/>-->
+
+ <!-- Load Spring Configuration from Java file -->
+ <bean class="org.nuiton.sandbox.jsr317.jpa2.test.SpringTestConfig" />
+
+ <!-- Scan sample -->
+ <context:component-scan base-package="org.nuiton.sandbox.jsr317.jpa2.sample" />
+
+</beans>
\ No newline at end of file
Property changes on: jpa2-validation/trunk/jsr317-jpa2/src/test/resources/test-jpa-spring-context.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: jpa2-validation/trunk/pom.xml
===================================================================
--- jpa2-validation/trunk/pom.xml 2010-12-15 08:21:32 UTC (rev 444)
+++ jpa2-validation/trunk/pom.xml 2010-12-29 16:15:42 UTC (rev 445)
@@ -34,6 +34,12 @@
<version>1.4.2</version>
</dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.5</version>
+ </dependency>
+
<!-- SPRING -->
<dependency>
<groupId>org.springframework</groupId>
1
0
Author: tchemit
Date: 2010-12-15 09:21:32 +0100 (Wed, 15 Dec 2010)
New Revision: 444
Url: http://nuiton.org/repositories/revision/sandbox/444
Log:
test commit
Modified:
javabeans/trunk/pom.xml
Modified: javabeans/trunk/pom.xml
===================================================================
--- javabeans/trunk/pom.xml 2010-12-15 08:19:26 UTC (rev 443)
+++ javabeans/trunk/pom.xml 2010-12-15 08:21:32 UTC (rev 444)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom</artifactId>
- <version>2.0.5</version>
+ <version>2.4.1</version>
</parent>
<artifactId>javabeans</artifactId>
1
0
Author: sletellier
Date: 2010-12-15 09:19:26 +0100 (Wed, 15 Dec 2010)
New Revision: 443
Url: http://nuiton.org/repositories/revision/sandbox/443
Log:
Test svn
Modified:
javabeans/trunk/README.txt
Modified: javabeans/trunk/README.txt
===================================================================
--- javabeans/trunk/README.txt 2010-11-26 15:21:55 UTC (rev 442)
+++ javabeans/trunk/README.txt 2010-12-15 08:19:26 UTC (rev 443)
@@ -1,2 +1,3 @@
Lutin Matrix
-============
\ No newline at end of file
+============
+
1
0
Author: jcouteau
Date: 2010-12-01 11:01:29 +0100 (Wed, 01 Dec 2010)
New Revision: 22
Url: http://chorem.org/repositories/revision/incubator/22
Log:
First huge, real commit
First admin screen : Frequencies
Added:
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/AdminCati.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/AdminCati.ui.xml
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/CatiForm.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/CatiForm.ui.xml
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/AdminFrequencies.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/AdminFrequencies.ui.xml
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/FrequenciesForm.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/FrequenciesForm.ui.xml
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/AdminSkills.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/AdminSkills.ui.xml
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/SkillForm.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/SkillForm.ui.xml
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/TreeItemCallback.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/TreeRootCallback.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/AdminUsers.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/AdminUsers.ui.xml
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/UserForm.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/UserForm.ui.xml
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Form.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Form.ui.xml
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/FormContent.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/StorageService.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/StorageServiceAsync.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/StorageServiceImpl.java
refComp/skills-client/src/main/resources/skills.properties
refComp/skills-entities/src/main/xmi/refcomp.zargo
refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/AlreadyExistingException.java
refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/ServiceFactory.java
refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsConfiguration.java
refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsConfigurationHelper.java
refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsException.java
refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsSession.java
refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/StorageService.java
refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/StorageServiceImpl.java
refComp/skills-services/src/main/resources/log4j.properties
Removed:
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/AdminUsers.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/AdminUsers.ui.xml
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/Level.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/LoginService.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/LoginServiceAsync.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/SearchService.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/SearchServiceAsync.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/Skill.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/UserService.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/UserServiceAsync.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/LoginServiceImpl.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/SearchServiceImpl.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/UserServiceImpl.java
refComp/skills-entities/src/main/xmi/UseCaseINRA-RefComp.zargo
Modified:
refComp/pom.xml
refComp/skills-client/pom.xml
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/RefComp.gwt.xml
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/Login.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/MySkills.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/Search.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/SearchResults.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/SkillEditionRow.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Footer.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Header.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Menu.java
refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Menu.ui.xml
refComp/skills-client/src/main/webapp/WEB-INF/web.xml
refComp/skills-entities/pom.xml
refComp/skills-entities/src/main/java/org/chorem/bonzoms/skills/Entities.gwt.xml
refComp/skills-services/pom.xml
Modified: refComp/pom.xml
===================================================================
--- refComp/pom.xml 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/pom.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -68,7 +68,8 @@
<!-- libraries version -->
<gwtVersion>2.1.0</gwtVersion>
<wikittyVersion>3.0-SNAPSHOT</wikittyVersion>
- <generatorPluginVersion>2.2</generatorPluginVersion>
+ <generatorPluginVersion>2.3-SNAPSHOT</generatorPluginVersion>
+ <slf4jVersion>1.6.1</slf4jVersion>
</properties>
<dependencyManagement>
@@ -97,6 +98,11 @@
</dependency>
<dependency>
<groupId>org.nuiton.wikitty</groupId>
+ <artifactId>wikitty-dto</artifactId>
+ <version>${wikittyVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.nuiton.wikitty</groupId>
<artifactId>wikitty-jdbc-impl</artifactId>
<version>${wikittyVersion}</version>
</dependency>
@@ -136,6 +142,28 @@
<version>1.5.3</version>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4jVersion}</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${slf4jVersion}</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+
+
<!-- Comment, not maven packaged -->
<!--dependency>
<groupId>com.spiral</groupId>
@@ -185,7 +213,7 @@
</executions>
<configuration>
<hostedWebapp>src/main/webapp</hostedWebapp>
- <runTarget>org.chorem.bonzoms.skills.client.RefComp/RefComp.html</runTarget>
+ <runTarget>org.chorem.bonzoms.skills.RefComp/RefComp.html</runTarget>
<noServer>false</noServer>
</configuration>
</plugin>
@@ -220,6 +248,11 @@
<artifactId>wikitty-generators</artifactId>
<version>${wikittyVersion}</version>
</dependency>
+ <dependency>
+ <groupId>org.nuiton.wikitty</groupId>
+ <artifactId>wikitty-dto</artifactId>
+ <version>${wikittyVersion}</version>
+ </dependency>
</dependencies>
</plugin>
Modified: refComp/skills-client/pom.xml
===================================================================
--- refComp/skills-client/pom.xml 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/pom.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -45,40 +45,53 @@
</dependency>
<dependency>
+ <groupId>org.chorem.bonzoms.skills</groupId>
+ <artifactId>skills-services</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.nuiton.wikitty</groupId>
<artifactId>wikitty-api</artifactId>
<version>${wikittyVersion}</version>
<classifier>sources</classifier>
</dependency>
- <dependency>
- <groupId>com.google.code.gwtx</groupId>
- <artifactId>gwtx</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.nuiton.wikitty</groupId>
+ <artifactId>wikitty-api</artifactId>
+ </dependency>
- <!-- Not maven packaged -->
<!--dependency>
- <groupId>com.spiral</groupId>
- <artifactId>gwt-calendar</artifactId>
+ <groupId>org.nuiton.wikitty</groupId>
+ <artifactId>wikitty-dto</artifactId>
+ <version>${wikittyVersion}</version>
+ <classifier>sources</classifier>
</dependency-->
- <!-- Useless tries -->
- <!--dependency>
- <groupId>com.smartgwt</groupId>
- <artifactId>smartgwt</artifactId>
+ <dependency>
+ <groupId>org.nuiton.wikitty</groupId>
+ <artifactId>wikitty-dto</artifactId>
</dependency>
<dependency>
- <groupId>org.gwtwidget</groupId>
- <artifactId>gwt-widget</artifactId>
- <type>war</type>
+ <groupId>com.google.code.gwtx</groupId>
+ <artifactId>gwtx</artifactId>
</dependency>
<dependency>
- <groupId>pl.rmalinowski</groupId>
- <artifactId>gwtreflect</artifactId>
- </dependency-->
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ <version>20090211</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>1.0.0.GA</version>
+ </dependency>
+
+
</dependencies>
<!-- ************************************************************* -->
Modified: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/RefComp.gwt.xml
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/RefComp.gwt.xml 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/RefComp.gwt.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -6,26 +6,24 @@
<inherits name='com.google.gwt.user.User'/>
<inherits name="com.google.gwt.uibinder.UiBinder"/>
<inherits name="org.chorem.bonzoms.skills.Entities"/>
+ <inherits name="org.chorem.bonzoms.skills.SkillsService"/>
<!--Wikitty dependency-->
<inherits name="org.nuiton.WikittyAPI"/>
+ <!--inherits name="org.nuiton.WikittyDTO"/-->
<!--gwtx dependency-->
<inherits name="com.googlecode.gwtx.Java"/>
- <!--gwt-calendar dependancy-->
- <inherits name='com.spiral.gwt-calendar'/>
-
- <!--inherits name="com.smartgwt.SmartGwt"/-->
-
<!-- inherit css based theme -->
- <inherits name='com.google.gwt.user.theme.standard.Standard'/>
+ <!--inherits name='com.google.gwt.user.theme.standard.Standard'/-->
<!-- Specify the app entry point class. -->
<entry-point class='org.chorem.bonzoms.skills.client.RefComp'/>
+ <stylesheet src='refcomp.css'/>
+
<source path="client"/>
- <source path="service"/>
<public path="public"/>
<public path="client"/>
Deleted: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/AdminUsers.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/AdminUsers.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/AdminUsers.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -1,55 +0,0 @@
-package org.chorem.bonzoms.skills.client;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.uibinder.client.UiBinder;
-import com.google.gwt.uibinder.client.UiField;
-import com.google.gwt.uibinder.client.UiTemplate;
-import com.google.gwt.user.client.Window;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.Panel;
-import org.chorem.bonzoms.skills.client.services.UserService;
-import org.chorem.bonzoms.skills.client.services.UserServiceAsync;
-import org.chorem.bonzoms.skills.entities.User;
-import org.chorem.bonzoms.skills.entities.UserImpl;
-
-/**
- * User: couteau
- * Date: 5 nov. 2010
- */
-public class AdminUsers extends Composite {
-
- /**private final UserServiceAsync userService = GWT
- .create(UserService.class);**/
-
- @UiTemplate("AdminUsers.ui.xml")
- interface MyUiBinder extends UiBinder<Panel, AdminUsers> {
- }
-
- @UiField
- Label userName;
-
- private static final MyUiBinder binder = GWT.create(MyUiBinder.class);
-
- public AdminUsers() {
- initWidget(binder.createAndBindUi(this));
-
- User toto = new UserImpl();
- toto.setNom("Toto");
-
- //userName.setText(toto.getNom());
-
- /*userService.getUser(new AsyncCallback<User>() {
- @Override
- public void onFailure(Throwable caught) {
- Window.alert("Server communication error");
- }
-
- @Override
- public void onSuccess(User result) {
- userName.setText(result.getNom());
- }
- });*/
- }
-}
Deleted: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/AdminUsers.ui.xml
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/AdminUsers.ui.xml 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/AdminUsers.ui.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -1,13 +0,0 @@
-<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
- xmlns:gwt='urn:import:com.google.gwt.user.client.ui'>
-
- <ui:style src="refcomp.css"/>
-
- <gwt:HTMLPanel>
- <div align="center">
- <gwt:HorizontalPanel verticalAlignment="ALIGN_MIDDLE">
- <gwt:Label ui:field="userName" styleName="{style.greyText}"/>
- </gwt:HorizontalPanel>
- </div>
- </gwt:HTMLPanel>
-</ui:UiBinder>
\ No newline at end of file
Modified: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/Login.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/Login.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/Login.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -15,10 +15,9 @@
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
-import org.chorem.bonzoms.skills.client.constants.Header;
import org.chorem.bonzoms.skills.client.constants.Menu;
-import org.chorem.bonzoms.skills.client.services.LoginService;
-import org.chorem.bonzoms.skills.client.services.LoginServiceAsync;
+import org.chorem.bonzoms.skills.client.services.StorageService;
+import org.chorem.bonzoms.skills.client.services.StorageServiceAsync;
/**
* User: couteau
@@ -26,8 +25,8 @@
*/
public class Login extends Composite {
- private final LoginServiceAsync loginService = GWT
- .create(LoginService.class);
+ private final StorageServiceAsync service = GWT
+ .create(StorageService.class);
@UiTemplate("Login.ui.xml")
interface MyUiBinder extends UiBinder<Panel, Login> {
@@ -56,7 +55,7 @@
@UiHandler("buttonSubmit")
void doClickSubmit(ClickEvent event) {
if (tooShort) {
- loginService.login(loginBox.getValue(), passwordBox.getValue(),
+ service.login(loginBox.getValue(), passwordBox.getValue(),
new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {
Modified: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/MySkills.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/MySkills.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/MySkills.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -13,10 +13,10 @@
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;
-import org.chorem.bonzoms.skills.client.services.Skill;
-import org.chorem.bonzoms.skills.client.services.SearchServiceAsync;
-import org.chorem.bonzoms.skills.client.services.SearchService;
import java.util.List;
+import org.chorem.bonzoms.skills.client.services.StorageService;
+import org.chorem.bonzoms.skills.client.services.StorageServiceAsync;
+import org.chorem.bonzoms.skills.entities.Skill;
/**
* User: couteau
@@ -24,8 +24,8 @@
*/
public class MySkills extends Composite {
- private final SearchServiceAsync searchService = GWT
- .create(SearchService.class);
+ private final StorageServiceAsync searchService = GWT
+ .create(StorageService.class);
@UiTemplate("MySkills.ui.xml")
interface MyUiBinder extends UiBinder<Panel, MySkills> {
@@ -42,7 +42,7 @@
//Use here the searchService that return a skill. Replace this with
//a real server.
- searchService.search("toto",
+ /*searchService.search("toto",
new AsyncCallback<List<Skill>>() {
@Override
public void onFailure(Throwable caught) {
@@ -76,7 +76,7 @@
skillsList.add(skillPanel);
}
}
- });
+ });*/
}
Modified: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/Search.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/Search.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/Search.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -12,10 +12,10 @@
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
-import org.chorem.bonzoms.skills.client.services.SearchService;
-import org.chorem.bonzoms.skills.client.services.SearchServiceAsync;
-import org.chorem.bonzoms.skills.client.services.Skill;
import java.util.List;
+import org.chorem.bonzoms.skills.client.services.StorageService;
+import org.chorem.bonzoms.skills.client.services.StorageServiceAsync;
+import org.chorem.bonzoms.skills.entities.Skill;
/**
* User: couteau
@@ -23,8 +23,8 @@
*/
public class Search extends Composite {
- private final SearchServiceAsync searchService = GWT
- .create(SearchService.class);
+ private final StorageServiceAsync searchService = GWT
+ .create(StorageService.class);
@UiTemplate("Search.ui.xml")
interface MyUiBinder extends UiBinder<Panel, Search> {
@@ -41,7 +41,7 @@
@UiHandler("buttonSearch")
void doClickSubmit(ClickEvent event) {
- searchService.search(searchBox.getValue(),
+ /*searchService.search(searchBox.getValue(),
new AsyncCallback<List<Skill>>() {
@Override
public void onFailure(Throwable caught) {
@@ -60,7 +60,7 @@
resultPanel.setResults(result);
}
- });
+ });*/
}
Modified: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/SearchResults.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/SearchResults.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/SearchResults.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -7,8 +7,8 @@
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Panel;
-import org.chorem.bonzoms.skills.client.services.Skill;
import java.util.List;
+import org.chorem.bonzoms.skills.entities.Skill;
/**
* User: couteau
@@ -49,10 +49,6 @@
resultsGrid.setText(i+1,0,skill.getName());
resultsGrid.setText(i+1,1,skill.getSkill());
- resultsGrid.setText(i+1,2,skill.getLinkedSkill());
- resultsGrid.setText(i+1,3,skill.getLevel());
- resultsGrid.setText(i+1,4,skill.getComment());
- resultsGrid.setText(i+1,5,skill.getRight());
}
Modified: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/SkillEditionRow.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/SkillEditionRow.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/SkillEditionRow.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -9,10 +9,10 @@
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.TextBox;
-import org.chorem.bonzoms.skills.client.services.Level;
-import org.chorem.bonzoms.skills.client.services.Skill;
import java.util.ArrayList;
import java.util.List;
+import java.util.logging.Level;
+import org.chorem.bonzoms.skills.entities.Skill;
/**
* User: couteau
@@ -28,7 +28,7 @@
private static final MyUiBinder binder = GWT.create(MyUiBinder.class);
- private Skill editedSkill;
+ protected Skill editedSkill;
@UiField
Label skill;
@@ -64,20 +64,11 @@
editedSkill = skill;
this.skill.setText(editedSkill.getSkill());
- this.linkedSkill.setText(editedSkill.getLinkedSkill());
- this.levelListBox.setSelectedIndex(levels.indexOf(editedSkill.getLevel()));
- this.commentBox.setText(editedSkill.getComment());
- this.rightLabel.setText(editedSkill.getRight());
-
+
}
protected void populateLevelList(){
levels = new ArrayList<String>();
- for (Level level: Level.values()){
- levels.add(level.getLabel());
- levelListBox.addItem(level.getLabel());
- }
-
}
}
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/AdminCati.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/AdminCati.java (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/AdminCati.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,107 @@
+package org.chorem.bonzoms.skills.client.admin.cati;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.ChangeEvent;
+import com.google.gwt.event.dom.client.ChangeHandler;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.uibinder.client.UiHandler;
+import com.google.gwt.uibinder.client.UiTemplate;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.ListBox;
+import com.google.gwt.user.client.ui.Panel;
+import java.util.List;
+import org.chorem.bonzoms.skills.client.admin.frequencies.FrequenciesForm;
+import org.chorem.bonzoms.skills.client.constants.Form;
+import org.chorem.bonzoms.skills.client.services.StorageService;
+import org.chorem.bonzoms.skills.client.services.StorageServiceAsync;
+import org.chorem.bonzoms.skills.entities.Cati;
+
+/**
+ * User: couteau
+ * Date: 29 nov. 2010
+ */
+public class AdminCati extends Composite {
+
+ private final StorageServiceAsync service = GWT
+ .create(StorageService.class);
+
+ @UiTemplate("AdminCati.ui.xml")
+ interface MyUiBinder extends UiBinder<Panel, AdminCati> {
+ }
+
+ private static final MyUiBinder binder = GWT.create(MyUiBinder.class);
+
+ @UiField
+ ListBox catiList;
+
+ @UiField
+ Form form;
+
+ @UiHandler("addButton")
+ void doClickAdd(ClickEvent event) {
+ service.createCati(new AsyncCallback<Cati>() {
+ @Override
+ public void onSuccess(Cati result) {
+ editedBean = result;
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("Server communication error");
+ }
+ });
+
+ form.setContent(editedBean, true);
+ }
+
+ Cati editedBean;
+
+ public AdminCati() {
+ initWidget(binder.createAndBindUi(this));
+
+ service.getCatis(new AsyncCallback<List<Cati>>() {
+ @Override
+ public void onSuccess(List<Cati> result) {
+ for (Cati cati : result) {
+ catiList.addItem(cati.getName(),
+ cati.getWikittyId());
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("Server communication error");
+ }
+ });
+
+ FrequenciesForm freqForm = new FrequenciesForm();
+
+ form.setContentPanel(freqForm);
+
+ catiList.addChangeHandler(new ChangeHandler() {
+ @Override
+ public void onChange(ChangeEvent event) {
+
+ String beanId = catiList.getValue(catiList.getSelectedIndex());
+
+ service.getCati(beanId, new AsyncCallback<Cati>() {
+ @Override
+ public void onSuccess(Cati result) {
+ editedBean = result;
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("Server communication error");
+ }
+ });
+
+ form.setContent(editedBean, false);
+ }
+ });
+ }
+}
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/AdminCati.ui.xml
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/AdminCati.ui.xml (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/AdminCati.ui.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,15 @@
+<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
+ xmlns:gwt='urn:import:com.google.gwt.user.client.ui'
+ xmlns:sk='urn:import:org.chorem.bonzoms.skills.client.constants'
+ >
+
+ <gwt:HTMLPanel>
+ <div>
+ <gwt:ListBox ui:field="catiList"/>
+ <gwt:Button ui:field="addButton">Add</gwt:Button>
+ </div>
+ <div>
+ <sk:Form ui:field="form"/>
+ </div>
+ </gwt:HTMLPanel>
+</ui:UiBinder>
\ No newline at end of file
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/CatiForm.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/CatiForm.java (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/CatiForm.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,131 @@
+package org.chorem.bonzoms.skills.client.admin.cati;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.uibinder.client.UiTemplate;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.Panel;
+import com.google.gwt.user.client.ui.TextBox;
+import org.chorem.bonzoms.skills.client.constants.FormContent;
+import org.chorem.bonzoms.skills.client.services.StorageService;
+import org.chorem.bonzoms.skills.client.services.StorageServiceAsync;
+import org.chorem.bonzoms.skills.entities.Cati;
+import org.chorem.bonzoms.skills.services.AlreadyExistingException;
+import org.nuiton.wikitty.entities.BusinessEntity;
+
+/**
+ * User: couteau
+ * Date: 29 nov. 2010
+ */
+public class CatiForm extends Composite implements FormContent {
+
+ private final StorageServiceAsync service = GWT
+ .create(StorageService.class);
+
+ @UiTemplate("FrequenciesForm.ui.xml")
+ interface MyUiBinder extends UiBinder<Panel, CatiForm> {
+ }
+
+ private static final MyUiBinder binder = GWT.create(MyUiBinder.class);
+
+ @UiField
+ Label catiLabel;
+
+ @UiField
+ TextBox nameBox;
+
+ Cati bean;
+
+ public CatiForm() {
+ initWidget(binder.createAndBindUi(this));
+ }
+
+ @Override
+ public void setContent(BusinessEntity bean) {
+
+ if ((bean != null) && (bean instanceof Cati)) {
+ this.bean = (Cati) bean;
+ catiLabel.setText(this.bean.getName());
+ nameBox.setText(this.bean.getName());
+ }
+
+ }
+
+ @Override
+ public void clearContent() {
+ bean = null;
+ catiLabel.setText("");
+ nameBox.setText("");
+ }
+
+ @Override
+ public BusinessEntity getContent() {
+ if (bean != null) {
+ bean.setName(nameBox.getText());
+ }
+
+ return bean;
+ }
+
+ @Override
+ public void saveContent() {
+
+ Boolean validate = Window.confirm("Are you sure ?");
+
+ if (validate) {
+
+ try {
+ service.saveCati((Cati) getContent(),
+ new AsyncCallback<Cati>() {
+ @Override
+ public void onSuccess(Cati result) {
+ clearContent();
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("Server communication error");
+ }
+ });
+ } catch (AlreadyExistingException eee) {
+ Window.alert("A frequency with the same name already exist");
+ }
+ }
+ }
+
+ @Override
+ public void cancelContent() {
+
+ Boolean validate = Window.confirm("Are you sure ?");
+
+ if (validate) {
+ clearContent();
+ }
+
+ }
+
+ @Override
+ public void deleteContent() {
+ Boolean validate = Window.confirm("Are you sure ?");
+
+ if (validate) {
+
+ service.deleteCati((Cati) getContent(),
+ new AsyncCallback<Void>() {
+ @Override
+ public void onSuccess(Void result) {
+ clearContent();
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("Server communication error");
+ }
+ });
+ }
+ }
+}
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/CatiForm.ui.xml
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/CatiForm.ui.xml (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/cati/CatiForm.ui.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,9 @@
+<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
+ xmlns:gwt='urn:import:com.google.gwt.user.client.ui'>
+
+ <gwt:HTMLPanel>
+ <gwt:Label ui:field="catiLabel"/>
+ <p>Name :</p>
+ <gwt:TextBox ui:field="nameBox"/>
+ </gwt:HTMLPanel>
+</ui:UiBinder>
\ No newline at end of file
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/AdminFrequencies.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/AdminFrequencies.java (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/AdminFrequencies.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,106 @@
+package org.chorem.bonzoms.skills.client.admin.frequencies;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.ChangeEvent;
+import com.google.gwt.event.dom.client.ChangeHandler;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.uibinder.client.UiHandler;
+import com.google.gwt.uibinder.client.UiTemplate;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.ListBox;
+import com.google.gwt.user.client.ui.Panel;
+import java.util.List;
+import org.chorem.bonzoms.skills.client.constants.Form;
+import org.chorem.bonzoms.skills.client.services.StorageService;
+import org.chorem.bonzoms.skills.client.services.StorageServiceAsync;
+import org.chorem.bonzoms.skills.entities.Frequency;
+
+/**
+ * User: couteau
+ * Date: 26 nov. 2010
+ */
+public class AdminFrequencies extends Composite {
+
+ protected static final StorageServiceAsync service = GWT
+ .create(StorageService.class);
+
+ @UiTemplate("AdminFrequencies.ui.xml")
+ interface MyUiBinder extends UiBinder<Panel, AdminFrequencies> {
+ }
+
+ private static final MyUiBinder binder = GWT.create(MyUiBinder.class);
+
+ @UiField
+ static ListBox frequenciesList;
+
+ @UiField
+ Form form;
+
+ @UiHandler("addButton")
+ void doClickAdd(ClickEvent event) {
+ service.createFrequency(new AsyncCallback<Frequency>() {
+ @Override
+ public void onSuccess(Frequency result) {
+ form.setContent(result, true);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("Server communication error");
+ }
+ });
+ }
+
+ public AdminFrequencies() {
+ initWidget(binder.createAndBindUi(this));
+
+ refresh();
+
+ FrequenciesForm freqForm = new FrequenciesForm();
+
+ form.setContentPanel(freqForm);
+
+ frequenciesList.addChangeHandler(new ChangeHandler(){
+ @Override
+ public void onChange(ChangeEvent event){
+
+ String beanId = frequenciesList.getValue(frequenciesList.getSelectedIndex());
+
+ service.getFrequency(beanId, new AsyncCallback<Frequency>() {
+ @Override
+ public void onSuccess(Frequency result) {
+ form.setContent(result, false);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("Server communication error");
+ }
+ });
+
+ }
+ });
+ }
+
+ public static void refresh(){
+ service.getFrequencies(new AsyncCallback<List<Frequency>>() {
+ @Override
+ public void onSuccess(List<Frequency> result) {
+ frequenciesList.clear();
+ for (Frequency frequency : result) {
+ frequenciesList.addItem(frequency.getName(),
+ frequency.getWikittyId());
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("Server communication error");
+ }
+ });
+ }
+}
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/AdminFrequencies.ui.xml
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/AdminFrequencies.ui.xml (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/AdminFrequencies.ui.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,16 @@
+<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
+ xmlns:gwt='urn:import:com.google.gwt.user.client.ui'
+ xmlns:sk='urn:import:org.chorem.bonzoms.skills.client.constants'
+ >
+
+ <gwt:HTMLPanel>
+ <div>
+ <gwt:ListBox ui:field="frequenciesList"
+ visibleItemCount="10"/>
+ <gwt:Button ui:field="addButton">Add</gwt:Button>
+ </div>
+ <div>
+ <sk:Form ui:field="form"/>
+ </div>
+ </gwt:HTMLPanel>
+</ui:UiBinder>
\ No newline at end of file
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/FrequenciesForm.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/FrequenciesForm.java (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/FrequenciesForm.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,144 @@
+package org.chorem.bonzoms.skills.client.admin.frequencies;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.KeyDownEvent;
+import com.google.gwt.event.dom.client.KeyPressEvent;
+import com.google.gwt.event.dom.client.KeyUpEvent;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.uibinder.client.UiHandler;
+import com.google.gwt.uibinder.client.UiTemplate;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.Panel;
+import com.google.gwt.user.client.ui.TextBox;
+import org.chorem.bonzoms.skills.client.constants.FormContent;
+import org.chorem.bonzoms.skills.client.services.StorageService;
+import org.chorem.bonzoms.skills.client.services.StorageServiceAsync;
+import org.chorem.bonzoms.skills.entities.Frequency;
+import org.chorem.bonzoms.skills.services.AlreadyExistingException;
+import org.nuiton.wikitty.entities.BusinessEntity;
+
+/**
+ * User: couteau
+ * Date: 27 nov. 2010
+ */
+public class FrequenciesForm extends Composite implements FormContent {
+
+ private final StorageServiceAsync service = GWT
+ .create(StorageService.class);
+
+ @UiTemplate("FrequenciesForm.ui.xml")
+ interface MyUiBinder extends UiBinder<Panel, FrequenciesForm> {
+ }
+
+ private static final MyUiBinder binder = GWT.create(MyUiBinder.class);
+
+ @UiField
+ Label frequencyLabel;
+
+ @UiField
+ TextBox nameBox;
+
+ @UiHandler("nameBox")
+ void nameBoxValueChanged(KeyUpEvent event) {
+ frequencyLabel.setText(nameBox.getText());
+ }
+
+ Frequency bean;
+
+ public FrequenciesForm() {
+ initWidget(binder.createAndBindUi(this));
+ nameBox.setEnabled(false);
+ }
+
+ @Override
+ public void setContent(BusinessEntity bean) {
+ if (bean instanceof Frequency) {
+ this.bean = (Frequency)bean;
+ frequencyLabel.setText(this.bean.getName());
+ nameBox.setText(this.bean.getName());
+ nameBox.setEnabled(true);
+ } else {
+ frequencyLabel.setText("Error");
+ }
+ }
+
+ @Override
+ public void clearContent() {
+ bean = null;
+ frequencyLabel.setText("");
+ nameBox.setText("");
+ nameBox.setEnabled(false);
+ }
+
+ @Override
+ public BusinessEntity getContent() {
+ if (bean != null){
+ bean.setName(nameBox.getText());
+ }
+ return bean;
+ }
+
+ @Override
+ public void saveContent() {
+
+ Boolean validate = Window.confirm("Are you sure ?");
+
+ if (validate){
+
+ try {
+ service.saveFrequency((Frequency)getContent(),
+ new AsyncCallback<Frequency>() {
+ @Override
+ public void onSuccess(Frequency result) {
+ clearContent();
+ AdminFrequencies.refresh();
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("Server communication error");
+ }
+ });
+ } catch (AlreadyExistingException eee){
+ Window.alert("A frequency with the same name already exist");
+ }
+ }
+ }
+
+ @Override
+ public void cancelContent() {
+
+ Boolean validate = Window.confirm("Are you sure ?");
+
+ if (validate){
+ clearContent();
+ }
+
+ }
+
+ @Override
+ public void deleteContent() {
+ Boolean validate = Window.confirm("Are you sure ?");
+
+ if (validate) {
+
+ service.deleteFrequency((Frequency) getContent(),
+ new AsyncCallback<Void>() {
+ @Override
+ public void onSuccess(Void result) {
+ clearContent();
+ AdminFrequencies.refresh();
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("Server communication error");
+ }
+ });
+ }
+ }
+}
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/FrequenciesForm.ui.xml
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/FrequenciesForm.ui.xml (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/frequencies/FrequenciesForm.ui.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,9 @@
+<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
+ xmlns:gwt='urn:import:com.google.gwt.user.client.ui'>
+
+ <gwt:HTMLPanel>
+ <gwt:Label ui:field="frequencyLabel"/>
+ <p>Name : </p>
+ <gwt:TextBox ui:field="nameBox"/>
+ </gwt:HTMLPanel>
+</ui:UiBinder>
\ No newline at end of file
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/AdminSkills.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/AdminSkills.java (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/AdminSkills.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,73 @@
+package org.chorem.bonzoms.skills.client.admin.skills;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.logical.shared.OpenEvent;
+import com.google.gwt.event.logical.shared.OpenHandler;
+import com.google.gwt.event.logical.shared.SelectionEvent;
+import com.google.gwt.event.logical.shared.SelectionHandler;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.uibinder.client.UiTemplate;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.Panel;
+import com.google.gwt.user.client.ui.Tree;
+import com.google.gwt.user.client.ui.TreeItem;
+import org.chorem.bonzoms.skills.client.constants.Form;
+import org.chorem.bonzoms.skills.client.services.StorageService;
+import org.chorem.bonzoms.skills.client.services.StorageServiceAsync;
+import org.chorem.bonzoms.skills.entities.Skill;
+
+/**
+ * User: couteau
+ * Date: 30 nov. 2010
+ */
+public class AdminSkills extends Composite {
+
+ private final StorageServiceAsync service = GWT
+ .create(StorageService.class);
+
+ @UiTemplate("AdminSkills.ui.xml")
+ interface MyUiBinder extends UiBinder<Panel, AdminSkills> {
+ }
+
+ private static final MyUiBinder binder = GWT.create(MyUiBinder.class);
+
+ @UiField
+ Tree skillsTree;
+
+ @UiField
+ Form form;
+
+ Skill editedBean;
+
+ public AdminSkills() {
+ initWidget(binder.createAndBindUi(this));
+
+ //Tree loading at display
+ TreeItem root = new TreeItem("Loading...");
+ skillsTree.addItem(root);
+ service.getChildrenSkill(null, new TreeRootCallback(skillsTree));
+ skillsTree.addOpenHandler(new OpenHandler<TreeItem>() {
+ public void onOpen(OpenEvent event) {
+ if (needsLoading((TreeItem)event.getTarget())) {
+ service.getChildrenSkill(((TreeItem)event.getTarget()).getText(),
+ new TreeItemCallback((TreeItem)event.getTarget()));
+ }
+ }
+
+ });
+
+ skillsTree.addSelectionHandler(new SelectionHandler<TreeItem>(){
+ public void onSelection(SelectionEvent<TreeItem> event) {
+ editedBean = (Skill)skillsTree.getSelectedItem().getUserObject();
+
+ form.setContent(editedBean, false);
+ }
+ });
+ }
+
+ protected boolean needsLoading(TreeItem item) {
+ return item.getChildCount() == 1
+ && "Loading...".equals(item.getChild(0).getText());
+ }
+}
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/AdminSkills.ui.xml
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/AdminSkills.ui.xml (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/AdminSkills.ui.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,16 @@
+<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
+ xmlns:gwt='urn:import:com.google.gwt.user.client.ui'
+ xmlns:sk='urn:import:org.chorem.bonzoms.skills.client.constants'
+ >
+
+ <gwt:HTMLPanel>
+ <div>
+ <gwt:Tree ui:field="skillsTree"/>
+ <gwt:Button ui:field="addButton">Add</gwt:Button>
+ <gwt:Button ui:field="addChildButton">Add child</gwt:Button>
+ </div>
+ <div>
+ <sk:Form ui:field="form"/>
+ </div>
+ </gwt:HTMLPanel>
+</ui:UiBinder>
\ No newline at end of file
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/SkillForm.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/SkillForm.java (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/SkillForm.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,128 @@
+package org.chorem.bonzoms.skills.client.admin.skills;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.uibinder.client.UiTemplate;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.Panel;
+import com.google.gwt.user.client.ui.TextBox;
+import org.chorem.bonzoms.skills.client.constants.FormContent;
+import org.chorem.bonzoms.skills.client.services.StorageService;
+import org.chorem.bonzoms.skills.client.services.StorageServiceAsync;
+import org.chorem.bonzoms.skills.entities.Skill;
+import org.chorem.bonzoms.skills.services.AlreadyExistingException;
+import org.nuiton.wikitty.entities.BusinessEntity;
+
+/**
+ * User: couteau
+ * Date: 30 nov. 2010
+ */
+public class SkillForm extends Composite implements FormContent {
+
+ private final StorageServiceAsync service = GWT
+ .create(StorageService.class);
+
+ @UiTemplate("SkillForm.ui.xml")
+ interface MyUiBinder extends UiBinder<Panel, SkillForm> {
+ }
+
+ private static final MyUiBinder binder = GWT.create(MyUiBinder.class);
+
+ @UiField
+ Label skillLabel;
+
+ @UiField
+ TextBox skillBox;
+
+ Skill bean;
+
+ public SkillForm() {
+ initWidget(binder.createAndBindUi(this));
+ }
+
+ @Override
+ public void setContent(BusinessEntity bean) {
+ if ((bean != null) && (bean instanceof Skill)) {
+ this.bean = (Skill) bean;
+
+ skillLabel.setText(this.bean.getName());
+ skillBox.setText(this.bean.getName());
+ }
+ }
+
+ @Override
+ public void clearContent() {
+ bean = null;
+
+ skillLabel.setText("");
+ skillBox.setText("");
+ }
+
+ @Override
+ public BusinessEntity getContent() {
+ bean.setName(skillBox.getText());
+ return bean;
+ }
+
+ @Override
+ public void saveContent() {
+
+
+ Boolean validate = Window.confirm("Are you sure ?");
+
+ if (validate) {
+
+ try {
+ service.saveSkill((Skill) getContent(),
+ new AsyncCallback<Skill>() {
+ @Override
+ public void onSuccess(Skill result) {
+ clearContent();
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("Server communication error");
+ }
+ });
+ } catch (AlreadyExistingException eee) {
+ Window.alert("A frequency with the same name already exist");
+ }
+ }
+ }
+
+ @Override
+ public void cancelContent() {
+
+ Boolean validate = Window.confirm("Are you sure ?");
+
+ if (validate) {
+ clearContent();
+ }
+ }
+
+ @Override
+ public void deleteContent() {
+ Boolean validate = Window.confirm("Are you sure ?");
+
+ if (validate) {
+
+ service.deleteSkill((Skill) getContent(),
+ new AsyncCallback<Void>() {
+ @Override
+ public void onSuccess(Void result) {
+ clearContent();
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("Server communication error");
+ }
+ });
+ }
+ }
+}
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/SkillForm.ui.xml
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/SkillForm.ui.xml (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/SkillForm.ui.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,9 @@
+<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
+ xmlns:gwt='urn:import:com.google.gwt.user.client.ui'>
+
+ <gwt:HTMLPanel>
+ <gwt:Label ui:field="skillLabel"/>
+ <p>Name :</p>
+ <gwt:TextBox ui:field="skillBox"/>
+ </gwt:HTMLPanel>
+</ui:UiBinder>
\ No newline at end of file
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/TreeItemCallback.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/TreeItemCallback.java (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/TreeItemCallback.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,34 @@
+package org.chorem.bonzoms.skills.client.admin.skills;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.TreeItem;
+import java.util.ArrayList;
+import java.util.List;
+import org.chorem.bonzoms.skills.entities.Skill;
+
+/**
+ * User: couteau
+ * Date: 30 nov. 2010
+ */
+public class TreeItemCallback implements AsyncCallback<List<Skill>> {
+ protected TreeItem treeItem;
+
+ public TreeItemCallback(TreeItem treeItem) {
+ super();
+ this.treeItem = treeItem;
+ }
+
+ public void onFailure(Throwable caught) {
+ caught.printStackTrace();
+ }
+
+ public void onSuccess(List<Skill> skills) {
+ treeItem.removeItems();
+ for (Skill skill : skills) {
+ TreeItem ti = new TreeItem(skill.getName());
+ ti.setUserObject(skill);
+ ti.addItem("Loading...");
+ treeItem.addItem(ti);
+ }
+ }
+}
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/TreeRootCallback.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/TreeRootCallback.java (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/skills/TreeRootCallback.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,36 @@
+package org.chorem.bonzoms.skills.client.admin.skills;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.Tree;
+import com.google.gwt.user.client.ui.TreeItem;
+import java.util.ArrayList;
+import java.util.List;
+import org.chorem.bonzoms.skills.entities.Skill;
+
+/**
+ * User: couteau
+ * Date: 30 nov. 2010
+ */
+public class TreeRootCallback implements AsyncCallback<List<Skill>> {
+
+ protected Tree browseTree;
+
+ public TreeRootCallback(Tree browseTree) {
+ super();
+ this.browseTree = browseTree;
+ }
+
+ public void onFailure(Throwable caught) {
+ caught.printStackTrace();
+ }
+
+ public void onSuccess(List<Skill> skills) {
+ browseTree.removeItems();
+ for (Skill skill : skills) {
+ TreeItem ti = new TreeItem(skill.getName());
+ ti.setUserObject(skill);
+ ti.addItem("Loading...");
+ browseTree.addItem(ti);
+ }
+ }
+}
Copied: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/AdminUsers.java (from rev 20, refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/AdminUsers.java)
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/AdminUsers.java (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/AdminUsers.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,106 @@
+package org.chorem.bonzoms.skills.client.admin.users;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.ChangeEvent;
+import com.google.gwt.event.dom.client.ChangeHandler;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.uibinder.client.UiHandler;
+import com.google.gwt.uibinder.client.UiTemplate;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.ListBox;
+import com.google.gwt.user.client.ui.Panel;
+import java.util.List;
+import org.chorem.bonzoms.skills.client.constants.Form;
+import org.chorem.bonzoms.skills.client.services.StorageService;
+import org.chorem.bonzoms.skills.client.services.StorageServiceAsync;
+import org.chorem.bonzoms.skills.entities.User;
+
+/**
+ * User: couteau
+ * Date: 5 nov. 2010
+ */
+public class AdminUsers extends Composite {
+
+ private final StorageServiceAsync service = GWT
+ .create(StorageService.class);
+
+ @UiTemplate("AdminUsers.ui.xml")
+ interface MyUiBinder extends UiBinder<Panel, AdminUsers> {
+ }
+
+ @UiField
+ ListBox usersList;
+
+ @UiField
+ Form form;
+
+ private static final MyUiBinder binder = GWT.create(MyUiBinder.class);
+
+ @UiHandler("addButton")
+ void doClickAdd(ClickEvent event) {
+ service.createUser(new AsyncCallback<User>() {
+ @Override
+ public void onSuccess(User result) {
+ editedBean = result;
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("Server communication error");
+ }
+ });
+
+ form.setContent(editedBean, true);
+ }
+
+ User editedBean;
+
+ public AdminUsers() {
+ initWidget(binder.createAndBindUi(this));
+
+ service.getUsers(new AsyncCallback<List<User>>() {
+ @Override
+ public void onSuccess(List<User> result) {
+ for (User user : result) {
+ usersList.addItem(user.getFirstName() + user.getLastName(),
+ user.getWikittyId());
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("Server communication error");
+ }
+ });
+
+ UserForm userForm = new UserForm();
+
+ form.setContentPanel(userForm);
+
+ usersList.addChangeHandler(new ChangeHandler() {
+ @Override
+ public void onChange(ChangeEvent event) {
+
+ String beanId = usersList.getValue(usersList.getSelectedIndex());
+
+ service.getUser(beanId, new AsyncCallback<User>() {
+ @Override
+ public void onSuccess(User result) {
+ editedBean = result;
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert("Server communication error");
+ }
+ });
+
+ form.setContent(editedBean, false);
+ }
+ });
+ }
+}
Copied: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/AdminUsers.ui.xml (from rev 17, refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/AdminUsers.ui.xml)
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/AdminUsers.ui.xml (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/AdminUsers.ui.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,15 @@
+<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
+ xmlns:gwt='urn:import:com.google.gwt.user.client.ui'
+ xmlns:sk='urn:import:org.chorem.bonzoms.skills.client.constants'
+ >
+
+ <gwt:HTMLPanel>
+ <div>
+ <gwt:ListBox ui:field="usersList"/>
+ <gwt:Button ui:field="addButton">Add</gwt:Button>
+ </div>
+ <div>
+ <sk:Form ui:field="form"/>
+ </div>
+ </gwt:HTMLPanel>
+</ui:UiBinder>
\ No newline at end of file
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/UserForm.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/UserForm.java (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/UserForm.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,120 @@
+package org.chorem.bonzoms.skills.client.admin.users;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.uibinder.client.UiTemplate;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.ListBox;
+import com.google.gwt.user.client.ui.Panel;
+import com.google.gwt.user.client.ui.PasswordTextBox;
+import com.google.gwt.user.client.ui.TextBox;
+import org.chorem.bonzoms.skills.client.constants.FormContent;
+import org.chorem.bonzoms.skills.client.services.StorageService;
+import org.chorem.bonzoms.skills.client.services.StorageServiceAsync;
+import org.chorem.bonzoms.skills.entities.User;
+import org.nuiton.wikitty.entities.BusinessEntity;
+
+/**
+ * User: couteau
+ * Date: 29 nov. 2010
+ */
+public class UserForm extends Composite implements FormContent {
+
+ private final StorageServiceAsync storageService = GWT
+ .create(StorageService.class);
+
+ @UiTemplate("UserForm.ui.xml")
+ interface MyUiBinder extends UiBinder<Panel, UserForm> {
+ }
+
+ private static final MyUiBinder binder = GWT.create(MyUiBinder.class);
+
+ @UiField
+ Label userLabel;
+
+ @UiField
+ TextBox lastNameBox;
+
+ @UiField
+ TextBox firstNameBox;
+
+ @UiField
+ TextBox loginBox;
+
+ @UiField
+ PasswordTextBox passwordBox;
+
+ @UiField
+ ListBox catiBox;
+
+ @UiField
+ ListBox serviceBox;
+
+ User bean;
+
+ public UserForm() {
+ initWidget(binder.createAndBindUi(this));
+ }
+
+ @Override
+ public void setContent(BusinessEntity bean) {
+ if ((bean != null) && (bean instanceof User)) {
+ this.bean = (User) bean;
+
+ populateCatiBox();
+ populateServiceBox();
+
+ userLabel.setText(this.bean.getFirstName() + " " +
+ this.bean.getLastName());
+ lastNameBox.setText(this.bean.getLastName());
+ firstNameBox.setText(this.bean.getFirstName());
+ loginBox.setText(this.bean.getLogin());
+ passwordBox.setText(this.bean.getPassword());
+ //selectCatiItem(this.bean.getCati());
+ //selectServiceItem(this.bean.getService());
+
+ }
+ }
+
+ @Override
+ public void clearContent() {
+ }
+
+ @Override
+ public BusinessEntity getContent() {
+ return null;
+ }
+
+ @Override
+ public void saveContent() {
+ }
+
+ @Override
+ public void cancelContent() {
+ }
+
+ @Override
+ public void deleteContent() {
+ }
+
+ protected void populateCatiBox(){}
+
+ protected void populateServiceBox(){}
+
+ protected void selectCatiItem(String cati){
+ for (int i=0;i<catiBox.getItemCount();i++){
+ if (cati.equals(catiBox.getItemText(i))){
+ catiBox.setSelectedIndex(i);
+ }
+ }
+ }
+
+ protected void selectServiceItem(String service){
+ for (int i=0;i<serviceBox.getItemCount();i++){
+ if (service.equals(serviceBox.getItemText(i))){
+ serviceBox.setSelectedIndex(i);
+ }
+ }}
+}
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/UserForm.ui.xml
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/UserForm.ui.xml (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/admin/users/UserForm.ui.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,19 @@
+<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
+ xmlns:gwt='urn:import:com.google.gwt.user.client.ui'>
+
+ <gwt:HTMLPanel>
+ <gwt:Label ui:field="userLabel"/>
+ <p>Last Name :</p>
+ <gwt:TextBox ui:field="lastNameBox"/>
+ <p>First Name :</p>
+ <gwt:TextBox ui:field="firstNameBox"/>
+ <p>Login :</p>
+ <gwt:TextBox ui:field="loginBox"/>
+ <p>Password :</p>
+ <gwt:PasswordTextBox ui:field="passwordBox"/>
+ <p>Cati :</p>
+ <gwt:ListBox ui:field="catiBox"/>
+ <p>Service :</p>
+ <gwt:ListBox ui:field="serviceBox"/>
+ </gwt:HTMLPanel>
+</ui:UiBinder>
\ No newline at end of file
Modified: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Footer.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Footer.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Footer.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -1,9 +1,7 @@
package org.chorem.bonzoms.skills.client.constants;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.dom.client.StyleInjector;
import com.google.gwt.uibinder.client.UiBinder;
-import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Panel;
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Form.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Form.java (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Form.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,72 @@
+package org.chorem.bonzoms.skills.client.constants;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.uibinder.client.UiHandler;
+import com.google.gwt.uibinder.client.UiTemplate;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.Panel;
+import org.nuiton.wikitty.entities.BusinessEntity;
+
+/**
+ * User: couteau
+ * Date: 26 nov. 2010
+ */
+public class Form extends Composite {
+
+ @UiTemplate("Form.ui.xml")
+ interface MyUiBinder extends UiBinder<Panel, Form> {
+ }
+
+ private static final MyUiBinder binder = GWT.create(MyUiBinder.class);
+
+ @UiField
+ protected FlowPanel contentPanel;
+
+ protected FormContent content;
+
+ protected Boolean creation;
+
+ public Form() {
+ initWidget(binder.createAndBindUi(this));
+ }
+
+ public Form(FormContent contentPanel){
+ this();
+ setContentPanel(contentPanel);
+ }
+
+ public void setContent(BusinessEntity bean, boolean creation){
+ this.creation = creation;
+ content.setContent(bean);
+ }
+
+ public void clearContent(){
+ content.clearContent();
+ }
+
+ public void setContentPanel(FormContent contentPanel){
+ this.contentPanel.clear();
+ content = contentPanel;
+ this.contentPanel.add(content);
+ }
+
+ @UiHandler("okButton")
+ void doClickOk(ClickEvent event) {
+ content.saveContent();
+ }
+
+ @UiHandler("cancelButton")
+ void doClickCancel(ClickEvent event) {
+ content.cancelContent();
+ }
+
+ @UiHandler("deleteButton")
+ void doClickDelete(ClickEvent event) {
+ content.deleteContent();
+ }
+
+}
\ No newline at end of file
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Form.ui.xml
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Form.ui.xml (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Form.ui.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,12 @@
+<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
+ xmlns:gwt='urn:import:com.google.gwt.user.client.ui'>
+
+ <gwt:HTMLPanel>
+ <gwt:FlowPanel ui:field="contentPanel"/>
+ <div>
+ <gwt:Button ui:field="okButton">Ok</gwt:Button>
+ <gwt:Button ui:field="cancelButton">Cancel</gwt:Button>
+ <gwt:Button ui:field="deleteButton">Delete</gwt:Button>
+ </div>
+ </gwt:HTMLPanel>
+</ui:UiBinder>
\ No newline at end of file
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/FormContent.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/FormContent.java (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/FormContent.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,26 @@
+package org.chorem.bonzoms.skills.client.constants;
+
+import com.google.gwt.user.client.ui.IsWidget;
+import org.nuiton.wikitty.entities.BusinessEntity;
+
+/**
+ *
+ * Interface for all DefaultForm content.
+ *
+ * User: couteau
+ * Date: 27 nov. 2010
+ */
+public interface FormContent extends IsWidget {
+
+ void setContent(BusinessEntity bean);
+
+ void clearContent();
+
+ BusinessEntity getContent();
+
+ void saveContent();
+
+ void cancelContent();
+
+ void deleteContent();
+}
Modified: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Header.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Header.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Header.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -1,17 +1,10 @@
package org.chorem.bonzoms.skills.client.constants;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
-import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.uibinder.client.UiTemplate;
-import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Panel;
-import com.google.gwt.user.client.ui.RootPanel;
-import org.chorem.bonzoms.skills.client.AdminUsers;
-import org.chorem.bonzoms.skills.client.Login;
-import org.chorem.bonzoms.skills.client.MySkills;
/**
* User: couteau
Modified: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Menu.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Menu.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Menu.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -12,11 +12,12 @@
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;
-import org.chorem.bonzoms.skills.client.AdminUsers;
+import org.chorem.bonzoms.skills.client.admin.users.AdminUsers;
import org.chorem.bonzoms.skills.client.Home;
import org.chorem.bonzoms.skills.client.Login;
import org.chorem.bonzoms.skills.client.MySkills;
import org.chorem.bonzoms.skills.client.RefComp;
+import org.chorem.bonzoms.skills.client.admin.frequencies.AdminFrequencies;
/**
* User: couteau
@@ -77,6 +78,17 @@
History.newItem("mySkills");
}
+ @UiHandler("adminFrequencies")
+ void doClickAdminFrequencies(ClickEvent event) {
+
+ RootPanel content = RootPanel.get("content");
+
+ content.clear();
+
+ content.add(new AdminFrequencies());
+ History.newItem("adminFrequencies");
+ }
+
@UiHandler("adminSkills")
void doClickAdminSkills(ClickEvent event) {
Modified: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Menu.ui.xml
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Menu.ui.xml 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/constants/Menu.ui.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -7,6 +7,7 @@
<li><gwt:Anchor ui:field="login" text="Login"/></li>
<li><gwt:Anchor ui:field="mySkills" text="My Skills"/></li>
<li><gwt:Anchor ui:field="adminSkills" text="Admin. Skills"/></li>
+ <li><gwt:Anchor ui:field="adminFrequencies" text="Admin. Frequencies"/></li>
<li><gwt:Anchor ui:field="adminCati" text="Admin. Cati"/></li>
<li><gwt:Anchor ui:field="adminServices" text="Admin. Services"/></li>
<li><gwt:Anchor ui:field="adminUsers" text="Admin. Users"/></li>
Deleted: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/Level.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/Level.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/Level.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -1,22 +0,0 @@
-package org.chorem.bonzoms.skills.client.services;
-
-/**
- * User: couteau
- * Date: 4 nov. 2010
- */
-public enum Level {
- HELP("I need help"),
- ALONE("I can be alone"),
- CANHELP("I can help"),
- CANFORM("I can teach others");
-
- private final String label;
-
- Level(String label){
- this.label=label;
- }
-
- public String getLabel(){
- return label;
- }
-}
Deleted: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/LoginService.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/LoginService.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/LoginService.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -1,15 +0,0 @@
-package org.chorem.bonzoms.skills.client.services;
-
-import com.google.gwt.user.client.rpc.RemoteService;
-import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
-
-/**
- * User: couteau
- * Date: 4 nov. 2010
- */
-@RemoteServiceRelativePath("login")
-public interface LoginService extends RemoteService {
-
- Boolean login(String login, String password);
-}
-
Deleted: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/LoginServiceAsync.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/LoginServiceAsync.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/LoginServiceAsync.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -1,12 +0,0 @@
-package org.chorem.bonzoms.skills.client.services;
-
-import com.google.gwt.user.client.rpc.AsyncCallback;
-
-/**
- * User: couteau
- * Date: 4 nov. 2010
- */
-public interface LoginServiceAsync {
- void login(String login, String password, AsyncCallback<Boolean> callback);
-}
-
Deleted: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/SearchService.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/SearchService.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/SearchService.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -1,15 +0,0 @@
-package org.chorem.bonzoms.skills.client.services;
-
-import com.google.gwt.user.client.rpc.RemoteService;
-import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
-import java.util.List;
-
-/**
- * User: couteau
- * Date: 4 nov. 2010
- */
-@RemoteServiceRelativePath("search")
-public interface SearchService extends RemoteService {
-
- List<Skill> search(String searchSentence);
-}
Deleted: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/SearchServiceAsync.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/SearchServiceAsync.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/SearchServiceAsync.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -1,12 +0,0 @@
-package org.chorem.bonzoms.skills.client.services;
-
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import java.util.List;
-
-/**
- * User: couteau
- * Date: 4 nov. 2010
- */
-public interface SearchServiceAsync {
- void search(String searchSentence, AsyncCallback<List<Skill>> callback);
-}
Deleted: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/Skill.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/Skill.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/Skill.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -1,77 +0,0 @@
-package org.chorem.bonzoms.skills.client.services;
-
-import java.io.Serializable;
-
-/**
- * User: couteau
- * Date: 3 nov. 2010
- */
-public class Skill implements Serializable {
-
- public Skill(){}
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getLevel() {
- return level;
- }
-
- public void setLevel(String level) {
- this.level = level;
- }
-
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
- this.comment = comment;
- }
-
- public String getLinkedSkill() {
- return linkedSkill;
- }
-
- public void setLinkedSkill(String linkedSkill) {
- this.linkedSkill = linkedSkill;
- }
-
- public String getRight() {
- return right;
- }
-
- public void setRight(String right) {
- this.right = right;
- }
-
- protected String name;
-
- public String getSkill() {
- return skill;
- }
-
- public void setSkill(String skill) {
- this.skill = skill;
- }
-
- protected String skill;
- protected String level;
- protected String comment;
- protected String linkedSkill;
- protected String right;
-
- public Skill(String name, String skill, String level, String comment, String linkedSkill, String right){
- this.skill=skill;
- this.name=name;
- this.level=level;
- this.comment=comment;
- this.linkedSkill=linkedSkill;
- this.right=right;
- }
-}
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/StorageService.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/StorageService.java (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/StorageService.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,60 @@
+package org.chorem.bonzoms.skills.client.services;
+
+import com.google.gwt.user.client.rpc.RemoteService;
+import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
+import java.util.List;
+import org.chorem.bonzoms.skills.entities.Cati;
+import org.chorem.bonzoms.skills.entities.Frequency;
+import org.chorem.bonzoms.skills.entities.Skill;
+import org.chorem.bonzoms.skills.entities.User;
+import org.chorem.bonzoms.skills.services.AlreadyExistingException;
+
+/**
+ * User: couteau
+ * Date: 30 nov. 2010
+ */
+@RemoteServiceRelativePath("storage")
+public interface StorageService extends RemoteService{
+
+ List<Cati> getCatis();
+
+ Cati saveCati(Cati cati) throws AlreadyExistingException;
+
+ Cati createCati();
+
+ Cati getCati(String id);
+
+ void deleteCati(Cati cati);
+
+ List<Frequency> getFrequencies();
+
+ Frequency saveFrequency(Frequency frequency) throws AlreadyExistingException;
+
+ Frequency createFrequency();
+
+ Frequency getFrequency(String id);
+
+ void deleteFrequency(Frequency frequency);
+
+ List<User> getUsers();
+
+ User saveUser(User user) throws AlreadyExistingException;
+
+ User createUser();
+
+ User getUser(String id);
+
+ void deleteUser(User user);
+
+ Boolean login(String login, String password);
+
+ List<Skill> getChildrenSkill(String id);
+
+ Skill saveSkill(Skill skill) throws AlreadyExistingException;
+
+ Skill createSkill();
+
+ Skill getSkill(String id);
+
+ void deleteSkill(Skill skill);
+}
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/StorageServiceAsync.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/StorageServiceAsync.java (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/StorageServiceAsync.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,62 @@
+package org.chorem.bonzoms.skills.client.services;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import java.util.List;
+import org.chorem.bonzoms.skills.entities.Cati;
+import org.chorem.bonzoms.skills.entities.Frequency;
+import org.chorem.bonzoms.skills.entities.Skill;
+import org.chorem.bonzoms.skills.entities.User;
+import org.chorem.bonzoms.skills.services.AlreadyExistingException;
+
+/**
+ * User: couteau
+ * Date: 30 nov. 2010
+ */
+public interface StorageServiceAsync {
+
+ void login(String login, String password, AsyncCallback<Boolean> callback);
+
+ void getUsers(AsyncCallback<List<User>> callback);
+
+ void saveUser(User user, AsyncCallback<User> callback)
+ throws AlreadyExistingException;
+
+ void createUser(AsyncCallback<User> callback);
+
+ void getUser(String id, AsyncCallback<User> callback);
+
+ void deleteUser(User user, AsyncCallback<Void> callback);
+
+ void getFrequencies(AsyncCallback<List<Frequency>> callback);
+
+ void saveFrequency(Frequency frequency, AsyncCallback<Frequency> callback)
+ throws AlreadyExistingException;
+
+ void createFrequency(AsyncCallback<Frequency> callback);
+
+ void getFrequency(String id, AsyncCallback<Frequency> callback);
+
+ void deleteFrequency(Frequency frequency, AsyncCallback<Void> callback);
+
+ void getCatis(AsyncCallback<List<Cati>> callback);
+
+ void saveCati(Cati cati, AsyncCallback<Cati> callback)
+ throws AlreadyExistingException;
+
+ void createCati(AsyncCallback<Cati> callback);
+
+ void getCati(String id, AsyncCallback<Cati> callback);
+
+ void deleteCati(Cati cati, AsyncCallback<Void> callback);
+
+ void getChildrenSkill(String id, AsyncCallback<List<Skill>> callback);
+
+ void saveSkill(Skill skill, AsyncCallback<Skill> callback)
+ throws AlreadyExistingException;
+
+ void createSkill(AsyncCallback<Skill> callback);
+
+ void getSkill(String id, AsyncCallback<Skill> callback);
+
+ void deleteSkill(Skill skill, AsyncCallback<Void> callback);
+}
Deleted: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/UserService.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/UserService.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/UserService.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -1,13 +0,0 @@
-package org.chorem.bonzoms.skills.client.services;
-
-import com.google.gwt.user.client.rpc.RemoteService;
-import org.chorem.bonzoms.skills.entities.User;
-
-/**
- * User: couteau
- * Date: 5 nov. 2010
- */
-public interface UserService extends RemoteService {
-
- User getUser();
-}
Deleted: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/UserServiceAsync.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/UserServiceAsync.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/client/services/UserServiceAsync.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -1,14 +0,0 @@
-package org.chorem.bonzoms.skills.client.services;
-
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import org.chorem.bonzoms.skills.entities.User;
-
-/**
- * User: couteau
- * Date: 5 nov. 2010
- */
-public interface UserServiceAsync {
-
- void getUser(AsyncCallback<User> user);
-
-}
Deleted: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/LoginServiceImpl.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/LoginServiceImpl.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/LoginServiceImpl.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -1,20 +0,0 @@
-package org.chorem.bonzoms.skills.server;
-
-import com.google.gwt.user.server.rpc.RemoteServiceServlet;
-import org.chorem.bonzoms.skills.client.services.LoginService;
-
-/**
- * User: couteau
- * Date: 4 nov. 2010
- */
-public class LoginServiceImpl extends RemoteServiceServlet implements
- LoginService {
-
- public Boolean login(String login, String password) {
- if (login.equals("admin") && password.equals("admin"))
- return true;
- else
- return false;
- }
-}
-
Deleted: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/SearchServiceImpl.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/SearchServiceImpl.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/SearchServiceImpl.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -1,29 +0,0 @@
-package org.chorem.bonzoms.skills.server;
-
-import com.google.gwt.user.server.rpc.RemoteServiceServlet;
-import org.chorem.bonzoms.skills.client.services.Level;
-import org.chorem.bonzoms.skills.client.services.SearchService;
-import org.chorem.bonzoms.skills.client.services.Skill;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * User: couteau
- * Date: 4 nov. 2010
- */
-public class SearchServiceImpl extends RemoteServiceServlet implements
- SearchService {
-
- List<Skill> searchResults;
-
- public List<Skill> search(String searchSentence) {
-
- searchResults = new ArrayList<Skill>();
-
- searchResults.add(new Skill("Hervé Richard", "Java", Level.CANFORM.getLabel(), "Enfin pas trop quand même", "R", "CIAM"));
-
- return searchResults;
- }
-
-
-}
\ No newline at end of file
Added: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/StorageServiceImpl.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/StorageServiceImpl.java (rev 0)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/StorageServiceImpl.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,108 @@
+package org.chorem.bonzoms.skills.server;
+
+import com.google.gwt.user.server.rpc.RemoteServiceServlet;
+import java.util.List;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import org.chorem.bonzoms.skills.client.services.StorageService;
+import org.chorem.bonzoms.skills.entities.Cati;
+import org.chorem.bonzoms.skills.entities.Frequency;
+import org.chorem.bonzoms.skills.entities.Skill;
+import org.chorem.bonzoms.skills.entities.User;
+import org.chorem.bonzoms.skills.services.AlreadyExistingException;
+import org.chorem.bonzoms.skills.services.ServiceFactory;
+import org.chorem.bonzoms.skills.services.SkillsSession;
+
+/**
+ * User: couteau
+ * Date: 30 nov. 2010
+ */
+public class StorageServiceImpl extends RemoteServiceServlet implements
+ StorageService {
+
+ public List<User> getUsers() {
+ return ServiceFactory.getStorageService(getSession()).getUsers();
+ }
+
+ public User saveUser(User user) throws AlreadyExistingException {
+ return ServiceFactory.getStorageService(getSession()).saveUser(user);
+ }
+
+ public User createUser() {
+ return ServiceFactory.getStorageService(getSession()).createUser();
+ }
+
+ public void deleteUser(User user) {
+ ServiceFactory.getStorageService(getSession()).deleteUser(user);
+ }
+
+ public User getUser(String id) {
+ return ServiceFactory.getStorageService(getSession()).getUser(id);
+ }
+
+ public Boolean login(String login, String password) {
+ return login.equals("admin") && password.equals("admin");
+ }
+
+ public List<Frequency> getFrequencies() {
+ return ServiceFactory.getStorageService(getSession()).getFrequencies();
+ }
+
+ public Frequency saveFrequency(Frequency frequency) throws AlreadyExistingException {
+ return ServiceFactory.getStorageService(getSession()).saveFrequency(frequency);
+ }
+
+ public Frequency createFrequency() {
+ return ServiceFactory.getStorageService(getSession()).createFrequency();
+ }
+
+ public void deleteFrequency(Frequency frequency) {
+ ServiceFactory.getStorageService(getSession()).deleteFrequency(frequency);
+ }
+
+ public Frequency getFrequency(String id) {
+ return ServiceFactory.getStorageService(getSession()).getFrequency(id);
+ }
+
+ public List<Cati> getCatis() {
+ return ServiceFactory.getStorageService(getSession()).getCatis();
+ }
+
+ public Cati saveCati(Cati cati) throws AlreadyExistingException {
+ return ServiceFactory.getStorageService(getSession()).saveCati(cati);
+ }
+
+ public Cati createCati() {
+ return ServiceFactory.getStorageService(getSession()).createCati();
+ }
+
+ public void deleteCati(Cati cati) {
+ ServiceFactory.getStorageService(getSession()).deleteCati(cati);
+ }
+
+ public Cati getCati(String id) {
+ return ServiceFactory.getStorageService(getSession()).getCati(id);
+ }
+
+ public List<Skill> getChildrenSkill(String id) {
+ return ServiceFactory.getStorageService(getSession()).getChildrenSkill(id);
+ }
+
+ /**
+ * Get the SkillsSession from the user session
+ *
+ * @return the user's session
+ */
+ protected SkillsSession getSession(){
+ HttpServletRequest request = this.getThreadLocalRequest();
+ HttpSession session = request.getSession();
+
+ // If the session does not contain the session object, create a new SkillsSession
+ if (session.getAttribute("session") == null) {
+ session.setAttribute("session", new SkillsSession());
+ }
+
+ // Return the SkillsSession
+ return (SkillsSession) session.getAttribute("session");
+ }
+}
Deleted: refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/UserServiceImpl.java
===================================================================
--- refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/UserServiceImpl.java 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/java/org/chorem/bonzoms/skills/server/UserServiceImpl.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -1,22 +0,0 @@
-package org.chorem.bonzoms.skills.server;
-
-import com.google.gwt.user.server.rpc.RemoteServiceServlet;
-import org.chorem.bonzoms.skills.client.services.UserService;
-import org.chorem.bonzoms.skills.entities.User;
-import org.chorem.bonzoms.skills.entities.UserImpl;
-
-/**
- * User: couteau
- * Date: 5 nov. 2010
- */
-public class UserServiceImpl extends RemoteServiceServlet implements UserService{
-
- public User getUser(){
- User testUser = new UserImpl();
-
- testUser.setNom("Couteau");
- testUser.setPrenom("Jean");
-
- return testUser;
- }
-}
Added: refComp/skills-client/src/main/resources/skills.properties
===================================================================
--- refComp/skills-client/src/main/resources/skills.properties (rev 0)
+++ refComp/skills-client/src/main/resources/skills.properties 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,24 @@
+#wikitty.storage.jdbc.queryfile=wikitty-jdbc-query.properties
+#wikitty.storage.jdbc.driver=org.h2.Driver
+wikitty.storage.jdbc.host=jdbc:h2:file:/tmp/skills/data/db
+#wikitty.storage.jdbc.login=sa
+#wikitty.storage.jdbc.password=
+#wikitty.storage.jdbc.xadatasource=org.h2.jdbcx.JdbcDataSource
+#wikitty.storage.jdbc.xadatasource.org.h2.jdbcx.JdbcDataSource.URL=${wikitty.storage.jdbc.host}
+#wikitty.storage.jdbc.xadatasource.org.h2.jdbcx.JdbcDataSource.user=${wikitty.storage.jdbc.login}
+#wikitty.storage.jdbc.xadatasource.org.h2.jdbcx.JdbcDataSource.password=${wikitty.storage.jdbc.password}
+#wikitty.searchengine.solr.directory.factory=solr.RAMDirectoryFactory
+#wikitty.WikittyService.components=org.nuiton.wikitty.services.WikittyServiceStorage,\
+#org.nuiton.wikitty.services.WikittyServiceCached,
+#org.nuiton.wikitty.services.WikittyServiceSecurity
+#wikitty.WikittyServiceStorage.components=org.nuiton.wikitty.jdbc.WikittyExtensionStorageJDBC,\
+#org.nuiton.wikitty.jdbc.WikittyStorageJDBC,
+#org.nuiton.wikitty.solr.WikittySearchEnginSolr
+#wikitty.addon.export.threadnumber=1
+#wikitty.addon.export.directory=/tmp/wikitty
+#wikitty.addon.export.publicurl=file:///tmp/wikitty/
+#wikitty.service.cache.allwaysRestoreCopies=false
+#wikitty.service.event.propagate=false
+#wikitty.service.event.listen=false
+solr.data.dir=/tmp/skills/solr
+skills.objectStore.dir=/tmp/skills/data
\ No newline at end of file
Modified: refComp/skills-client/src/main/webapp/WEB-INF/web.xml
===================================================================
--- refComp/skills-client/src/main/webapp/WEB-INF/web.xml 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-client/src/main/webapp/WEB-INF/web.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -10,23 +10,13 @@
</welcome-file-list>
<servlet>
- <servlet-name>LoginService</servlet-name>
- <servlet-class>org.chorem.bonzoms.skills.server.LoginServiceImpl
+ <servlet-name>StorageService</servlet-name>
+ <servlet-class>org.chorem.bonzoms.skills.server.StorageServiceImpl
</servlet-class>
</servlet>
<servlet-mapping>
- <servlet-name>LoginService</servlet-name>
- <url-pattern>/org.chorem.bonzoms.skills.RefComp/login</url-pattern>
+ <servlet-name>StorageService</servlet-name>
+ <url-pattern>/org.chorem.bonzoms.skills.RefComp/storage</url-pattern>
</servlet-mapping>
-
- <servlet>
- <servlet-name>SearchService</servlet-name>
- <servlet-class>org.chorem.bonzoms.skills.server.SearchServiceImpl
- </servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>SearchService</servlet-name>
- <url-pattern>/org.chorem.bonzoms.skills.RefComp/search</url-pattern>
- </servlet-mapping>
</web-app>
Modified: refComp/skills-entities/pom.xml
===================================================================
--- refComp/skills-entities/pom.xml 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-entities/pom.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -48,10 +48,6 @@
<executions>
<execution>
<id>api generator</id>
- <!--
- do not use the phase generate-XXX because it can be excecuted
- several times...
- -->
<phase>process-sources</phase>
<configuration>
<inputs>
@@ -67,7 +63,8 @@
<generatedPackages>org.chorem.bonzoms.skills.entities
</generatedPackages>
<templates>
- org.nuiton.wikitty.generator.WikittyMetaGenerator
+ org.nuiton.wikitty.generator.WikittyMetaGenerator,
+ org.nuiton.wikitty.generator.WikittyDTOGenerator
</templates>
</configuration>
<goals>
Modified: refComp/skills-entities/src/main/java/org/chorem/bonzoms/skills/Entities.gwt.xml
===================================================================
--- refComp/skills-entities/src/main/java/org/chorem/bonzoms/skills/Entities.gwt.xml 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-entities/src/main/java/org/chorem/bonzoms/skills/Entities.gwt.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -2,8 +2,9 @@
"http://google-web-toolkit.googlecode.com/svn/tags/1.6.2/distro-source/core/…">
<module>
- <!-- Inherit the core Web Toolkit stuff. -->
- <inherits name='com.google.gwt.user.User'/>
-
- <source path="entities"/>
+ <source path="entities">
+ <exclude name="*Impl.java"/>
+ <exclude name="*Abstract.java"/>
+ <exclude name="*Helper.java"/>
+ </source>
</module>
\ No newline at end of file
Deleted: refComp/skills-entities/src/main/xmi/UseCaseINRA-RefComp.zargo
===================================================================
(Binary files differ)
Added: refComp/skills-entities/src/main/xmi/refcomp.zargo
===================================================================
(Binary files differ)
Property changes on: refComp/skills-entities/src/main/xmi/refcomp.zargo
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: refComp/skills-services/pom.xml
===================================================================
--- refComp/skills-services/pom.xml 2010-11-18 13:56:42 UTC (rev 21)
+++ refComp/skills-services/pom.xml 2010-12-01 10:01:29 UTC (rev 22)
@@ -20,12 +20,43 @@
<dependencies>
- <!-- GWT -->
- <dependency>
- <groupId>com.google.gwt</groupId>
- <artifactId>gwt-user</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.chorem.bonzoms.skills</groupId>
+ <artifactId>skills-entities</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.nuiton.wikitty</groupId>
+ <artifactId>wikitty-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.nuiton.wikitty</groupId>
+ <artifactId>wikitty-dto</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.nuiton.wikitty</groupId>
+ <artifactId>wikitty-jdbc-impl</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.nuiton.wikitty</groupId>
+ <artifactId>wikitty-solr-impl</artifactId>
+ </dependency>
+
+ <!-- databases dependencies -->
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
+
</dependencies>
<!-- ************************************************************* -->
Added: refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/AlreadyExistingException.java
===================================================================
--- refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/AlreadyExistingException.java (rev 0)
+++ refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/AlreadyExistingException.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,36 @@
+package org.chorem.bonzoms.skills.services;
+
+/**
+ *
+ * Exception to be thrown when an entity already exist in database and that only
+ * one of those entities is allowed.
+ *
+ * User: couteau
+ * Date: 26 nov. 2010
+ */
+public class AlreadyExistingException extends SkillsException {
+
+ public AlreadyExistingException() {
+ super();
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message.
+ *
+ * @param message message
+ */
+ public AlreadyExistingException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and cause.
+ *
+ * @param message
+ * @param cause
+ */
+ public AlreadyExistingException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
Added: refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/ServiceFactory.java
===================================================================
--- refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/ServiceFactory.java (rev 0)
+++ refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/ServiceFactory.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,98 @@
+package org.chorem.bonzoms.skills.services;
+
+import java.util.Locale;
+import org.apache.commons.beanutils.ConvertUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.i18n.I18n;
+import org.nuiton.util.LocaleConverter;
+import org.nuiton.util.converter.ConverterUtil;
+import org.nuiton.wikitty.WikittyProxy;
+import org.nuiton.wikitty.WikittyService;
+import org.nuiton.wikitty.WikittyServiceFactory;
+
+/**
+ * User: couteau
+ * Date: 26 nov. 2010
+ */
+public class ServiceFactory {
+
+ /**
+ * Log.
+ */
+ private static final Log log = LogFactory.getLog(ServiceFactory.class);
+
+ /**
+ * Wikitty service (cached version) for remote access.
+ */
+ protected static WikittyService wikittyService;
+
+ /**
+ * Single instance of frequency service.
+ */
+ protected static StorageService storageService;
+
+ protected static SkillsConfiguration config;
+
+ static {
+ // TODO JC 26/11/2010 Gotten from vradi, maybe better way to do it
+ // Dans un block static pour definition des variables
+ // d'environnement solr et jbossts
+ // A voir pourquoi, les converters s'initialise mal durant les tests
+ try {
+
+ ConverterUtil.initConverters();
+ ConvertUtils.register(new LocaleConverter(), Locale.class);
+ config = SkillsConfiguration.getInstance();
+ I18n.init(SkillsConfigurationHelper.getLocale(config));
+ } catch (Exception eee) {
+ log.error("Cant initialize Service factory : ", eee);
+ }
+ }
+
+ public static synchronized StorageService getStorageService(SkillsSession session) {
+ if (storageService == null) {
+ storageService = new StorageServiceImpl(getProxy(session));
+ }
+ return storageService;
+ }
+
+ /**
+ * Creates wikitty service (cached).
+ * <p/>
+ * Constructor added for UI embedded mode, with custom configuration.
+ *
+ * @return a unique instance of WikittyService
+ */
+ public static WikittyService getWikittyService() {
+ if (wikittyService == null) {
+ synchronized (ServiceFactory.class) {
+ if(wikittyService == null) {
+ wikittyService = WikittyServiceFactory.buildWikittyService(config);
+ }
+ }
+ }
+
+ return wikittyService;
+ }
+
+ /**
+ * Creates wikitty proxy.
+ *
+ * @return a unique instance of WikittyProxy.
+ */
+ public static WikittyProxy getProxy(SkillsSession session) {
+ WikittyProxy proxy = session.getProxy();
+ if (proxy == null) {
+ WikittyService service = getWikittyService();
+
+ // init proxy on cached service
+ proxy = new WikittyProxy(service);
+ session.setProxy(proxy);
+
+ }
+
+ return proxy;
+ }
+
+}
Added: refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsConfiguration.java
===================================================================
--- refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsConfiguration.java (rev 0)
+++ refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsConfiguration.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,181 @@
+package org.chorem.bonzoms.skills.services;
+
+import java.io.File;
+import java.util.Locale;
+import org.apache.commons.lang.UnhandledException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.wikitty.WikittyConfig;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * User: couteau
+ * Date: 26 nov. 2010
+ */
+public class SkillsConfiguration extends ApplicationConfig {
+
+ /**
+ * log.
+ */
+ private static final Log log = LogFactory.getLog(SkillsConfiguration.class);
+
+ /**
+ * After init step.
+ */
+ public static final int STEP_AFTER_INIT = 0;
+
+ /**
+ * Singleton instance.
+ */
+ protected static SkillsConfiguration instance = null;
+
+ public static final String DATA_DEFAULT_DIR = "${user.home}" + File.separator + ".skills" +
+ File.separator + "skills-${application.version}";
+
+ protected SkillsConfiguration() {
+ super();
+
+ // Load defaults wikitty options
+ loadDefaultOptions(WikittyConfig.WikittyOption.class);
+
+ // Load defaults vradi options
+ loadDefaultOptions(SkillsOption.class);
+
+ }
+
+ public static synchronized SkillsConfiguration getInstance(String... args) {
+ if (instance == null) {
+ try {
+ instance = new SkillsConfiguration();
+ instance.parse(args);
+ // was done in parse before (but not good for tests)
+ instance.setSystemDefaultProps();
+ } catch (Exception ex) {
+ if (log.isErrorEnabled()) {
+ log.error("Can't intitialize configuration", ex);
+ }
+ throw new UnhandledException(ex);
+ }
+ }
+ return instance;
+ }
+
+ /**
+ * Set {@code solr} and {@code jms} system configuration.
+ * <p/>
+ * This is the "only" way to configure embedded solr.
+ */
+ protected void setSystemDefaultProps() {
+ String[] datadirs = new String[]{"solr.data.dir", "skills.objectStore.dir"};
+
+ for (String datadir : datadirs) {
+ String value = System.getProperty(datadir, null);
+ if (value == null) {
+ value = getOption(datadir);
+ if (log.isInfoEnabled()) {
+ log.info("Setting system property " + datadir + " : " + value);
+ }
+ if (value != null) {
+ System.setProperty(datadir, value);
+ env.put(datadir, value);
+ }
+ }
+ }
+ }
+
+ /**
+ * Vradi option definition.
+ */
+ public static enum SkillsOption implements OptionDef {
+
+ CONFIG_FILE(
+ CONFIG_FILE_NAME,
+ _("skills.config.configFileName.description"),
+ "skills.properties",
+ String.class, true, true),
+
+ APPLICATION_VERSION(
+ "application.version",
+ _("skills.config.application.version.description"),
+ null, String.class, false, false),
+
+ DATA_DIR(
+ "skills.data.dir",
+ _("skills.config.data.dir.description"),
+ DATA_DEFAULT_DIR,
+ String.class, false, false),
+
+ LOCALE(
+ "skills.locale",
+ _("skills.config.ui.locale.description"),
+ Locale.FRANCE.toString(), Locale.class, false, false);
+
+ public String key;
+ public String description;
+ public String defaultValue;
+ public Class<?> type;
+ public boolean isTransient;
+ public boolean isFinal;
+
+ private SkillsOption(String key, String description, String defaultValue,
+ Class<?> type, boolean isTransient, boolean isFinal) {
+ this.key = key;
+ this.description = description;
+ this.defaultValue = defaultValue;
+ this.type = type;
+ this.isFinal = isFinal;
+ this.isTransient = isTransient;
+ }
+
+ @Override
+ public String getKey() {
+ return key;
+ }
+
+ @Override
+ public Class<?> getType() {
+ return type;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ @Override
+ public boolean isTransient() {
+ return isTransient;
+ }
+
+ @Override
+ public boolean isFinal() {
+ return isFinal;
+ }
+
+ @Override
+ public void setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ @Override
+ public void setTransient(boolean isTransient) {
+ this.isTransient = isTransient;
+ }
+
+ @Override
+ public void setFinal(boolean isFinal) {
+ this.isFinal = isFinal;
+ }
+
+ private static String getDefaultDir(String dirName) {
+ return DATA_DEFAULT_DIR + File.separator + dirName;
+ }
+ }
+}
\ No newline at end of file
Added: refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsConfigurationHelper.java
===================================================================
--- refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsConfigurationHelper.java (rev 0)
+++ refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsConfigurationHelper.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,42 @@
+package org.chorem.bonzoms.skills.services;
+
+import java.io.File;
+import java.util.Locale;
+import java.util.Set;
+import org.nuiton.util.ApplicationConfig;
+
+/**
+ * User: couteau
+ * Date: 26 nov. 2010
+ */
+public class SkillsConfigurationHelper {
+
+ /**
+ * Get current application version as string.
+ *
+ * @param config vradi service configuration
+ * @return version
+ */
+ public static String getApplicationVersion(ApplicationConfig config) {
+ return config.getOption(SkillsConfiguration.SkillsOption.APPLICATION_VERSION.key);
+ }
+
+ public static String getDataDir(ApplicationConfig config) {
+ String option = config.getOption(SkillsConfiguration.SkillsOption.DATA_DIR.key);
+ return option;
+ }
+
+ public static File getDataDirAsFile(ApplicationConfig config) {
+ File option = config.getOptionAsFile(SkillsConfiguration.SkillsOption.DATA_DIR.key);
+ return option;
+ }
+
+ public static Locale getLocale(ApplicationConfig config) {
+ Locale result = config.getOption(Locale.class, SkillsConfiguration.SkillsOption.LOCALE.key);
+ return result;
+ }
+
+ public static void setLocale(ApplicationConfig config, Locale locale) {
+ config.setOption(SkillsConfiguration.SkillsOption.LOCALE.key, locale.toString());
+ }
+}
Added: refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsException.java
===================================================================
--- refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsException.java (rev 0)
+++ refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsException.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,32 @@
+package org.chorem.bonzoms.skills.services;
+
+/**
+ * User: couteau
+ * Date: 26 nov. 2010
+ */
+public class SkillsException extends Exception {
+
+ public SkillsException() {
+ super();
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message.
+ *
+ * @param message message
+ */
+ public SkillsException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and cause.
+ *
+ * @param message
+ * @param cause
+ */
+ public SkillsException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
Added: refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsSession.java
===================================================================
--- refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsSession.java (rev 0)
+++ refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/SkillsSession.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,21 @@
+package org.chorem.bonzoms.skills.services;
+
+import org.nuiton.wikitty.WikittyProxy;
+
+/**
+ * User: couteau
+ * Date: 30 nov. 2010
+ */
+public class SkillsSession {
+
+
+ WikittyProxy proxy;
+
+ public WikittyProxy getProxy() {
+ return proxy;
+ }
+
+ public void setProxy(WikittyProxy proxy) {
+ this.proxy = proxy;
+ }
+}
Added: refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/StorageService.java
===================================================================
--- refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/StorageService.java (rev 0)
+++ refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/StorageService.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,177 @@
+package org.chorem.bonzoms.skills.services;
+
+import java.util.List;
+import org.chorem.bonzoms.skills.entities.Cati;
+import org.chorem.bonzoms.skills.entities.Frequency;
+import org.chorem.bonzoms.skills.entities.Skill;
+import org.chorem.bonzoms.skills.entities.User;
+
+/**
+ * User: couteau
+ * Date: 30 nov. 2010
+ */
+public interface StorageService {
+
+ /**
+ * Get all the catis.
+ *
+ * @return a list containing all the catis.
+ */
+ List<Cati> getCatis();
+
+ /**
+ * Save a cati in database.
+ *
+ * @param cati the cati to save
+ * @return the save cati
+ * @throws AlreadyExistingException if a cati with the same name already
+ * exist in database
+ */
+ Cati saveCati(Cati cati) throws AlreadyExistingException;
+
+ /**
+ * Return a new cati created in database.
+ *
+ * @return the new cati
+ */
+ Cati createCati();
+
+ /**
+ * Delete a cati
+ *
+ * @param cati the cati to delete
+ */
+ void deleteCati(Cati cati);
+
+ /**
+ * Get a cati with its id
+ *
+ * @param id the cati to get's id
+ * @return the cati
+ */
+ Cati getCati(String id);
+
+ /**
+ * Get all the frequencies.
+ *
+ * @return a list containing all the frequencies.
+ */
+ List<Frequency> getFrequencies();
+
+ /**
+ * Save a frequency in database.
+ *
+ * @param frequency the frequency to save
+ * @return the save frequency
+ * @throws AlreadyExistingException if a frequency with the same name already
+ * exist in database
+ */
+ Frequency saveFrequency(Frequency frequency) throws AlreadyExistingException;
+
+ /**
+ * Return a new frequency created in database.
+ *
+ * @return the new frequency
+ */
+ Frequency createFrequency();
+
+ /**
+ * Delete a frequency
+ *
+ * @param frequency the frequency to delete
+ */
+ void deleteFrequency(Frequency frequency);
+
+ /**
+ * Get a frequency with its id
+ *
+ * @param id the frequency to get's id
+ * @return the frequency
+ */
+ Frequency getFrequency(String id);
+
+ /**
+ * Get all the users.
+ *
+ * @return a list containing all the users.
+ */
+ List<User> getUsers();
+
+ /**
+ * Save a user in database.
+ *
+ * @param user the user to save
+ * @return the saved user
+ * @throws AlreadyExistingException if a user with the same name already
+ * exist in database
+ */
+ User saveUser(User user) throws AlreadyExistingException;
+
+ /**
+ * Return a new user created in database.
+ *
+ * @return the new user
+ */
+ User createUser();
+
+ /**
+ * Delete a user
+ *
+ * @param user the user to delete
+ */
+ void deleteUser(User user);
+
+ /**
+ * Get a user with its id
+ *
+ * @param id the user to get's id
+ * @return the user
+ */
+ User getUser(String id);
+
+ /**
+ * Save a skill in database.
+ *
+ * @param skill the skill to save
+ * @return the saved user
+ * @throws AlreadyExistingException if a user with the same name already
+ * exist in database
+ */
+ Skill saveSkill(Skill skill) throws AlreadyExistingException;
+
+ /**
+ * Return a new user created in database.
+ *
+ * @return the new user
+ */
+ Skill createSkill();
+
+ /**
+ * Delete a skill
+ *
+ * @param skill the skill to delete
+ */
+ void deleteSkill(Skill skill);
+
+ /**
+ * Get a skill with its id
+ *
+ * @param id the skill to get's id
+ * @return the skill
+ */
+ Skill getSkill(String id);
+
+ List<Skill> getChildrenSkill(String id);
+
+ /**
+ * Log the user in
+ * @param login the user login
+ * @param password the user password
+ * @return true if logged in, false otherwise
+ */
+ Boolean login(String login, String password);
+
+ /*Boolean logout(String login);
+
+ Boolean isLoggedIn();*/
+}
Added: refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/StorageServiceImpl.java
===================================================================
--- refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/StorageServiceImpl.java (rev 0)
+++ refComp/skills-services/src/main/java/org/chorem/bonzoms/skills/services/StorageServiceImpl.java 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,435 @@
+package org.chorem.bonzoms.skills.services;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.bonzoms.skills.entities.Cati;
+import org.chorem.bonzoms.skills.entities.CatiImpl;
+import org.chorem.bonzoms.skills.entities.Frequency;
+import org.chorem.bonzoms.skills.entities.FrequencyImpl;
+import org.chorem.bonzoms.skills.entities.Skill;
+import org.chorem.bonzoms.skills.entities.SkillImpl;
+import org.chorem.bonzoms.skills.entities.User;
+import org.chorem.bonzoms.skills.entities.UserImpl;
+import org.nuiton.wikitty.WikittyProxy;
+import org.nuiton.wikitty.search.Criteria;
+import org.nuiton.wikitty.search.PagedResult;
+import org.nuiton.wikitty.search.Search;
+import org.nuiton.wikitty.search.operators.Element;
+import org.nuiton.wikitty.dto.DTOHelper;
+
+/**
+ * User: couteau
+ * Date: 30 nov. 2010
+ */
+public class StorageServiceImpl implements StorageService{
+
+ /**
+ * log.
+ */
+ private static final Log log = LogFactory.getLog(StorageServiceImpl.class);
+
+ WikittyProxy proxy;
+
+ StorageServiceImpl(WikittyProxy proxy) {
+ this.proxy = proxy;
+ }
+
+ /**
+ * Get all the catis.
+ *
+ * @return a list containing all the catis.
+ */
+ public List<Cati> getCatis() {
+
+ //Create criteria : everything that got the cati extension
+ Search search = Search.query().eq(Element.ELT_EXTENSION, Cati.EXT_CATI);
+ Criteria criteria = search.criteria();
+ criteria.addSortAscending(Cati.FIELD_CATI_NAME);
+
+ //get results
+ PagedResult<Cati> catiPagedResult = proxy.findAllByCriteria(Cati.class, criteria);
+
+ List<Cati> catis = new ArrayList<Cati>();
+
+ if (catiPagedResult != null) {
+ for (Cati cati:catiPagedResult.getAll()){
+ catis.add(DTOHelper.toDto(cati));
+ }
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Catis list : " + catis);
+ }
+ return catis;
+ }
+
+ /**
+ * Save a cati in database.
+ *
+ * @param cati the cati to save
+ * @return the saved cati
+ * @throws AlreadyExistingException if a cati with the same name already
+ * exist in database
+ */
+ public Cati saveCati(Cati cati) throws AlreadyExistingException {
+
+ if (exist(cati)) {
+ throw new AlreadyExistingException("Cati with name " +
+ cati.getName() + " already exist in database");
+ }
+
+ Cati entity = DTOHelper.fromDto(proxy, Cati.class, cati);
+ Cati dto = DTOHelper.toDto(proxy.store(entity));
+
+ return dto;
+ }
+
+ /**
+ * Return a new cati created in database.
+ *
+ * @return the new cati
+ */
+ public Cati createCati() {
+ Cati cati = new CatiImpl();
+ cati = DTOHelper.toDto(proxy.store(cati));
+ return cati;
+ }
+
+ /**
+ * Delete a cati
+ */
+ public void deleteCati(Cati cati) {
+ proxy.delete(cati.getWikittyId());
+ }
+
+ /**
+ * Check if a cati is already present in database
+ *
+ * @param cati the cati to check
+ * @return true is exist, false otherwise
+ */
+ protected boolean exist(Cati cati) {
+ boolean returnValue = false;
+
+ if (cati != null) {
+ List<Cati> catis = getCatis();
+ for (Cati cat : catis) {
+ if (cat.getName().equals(cat.getName())) {
+ returnValue = true;
+ }
+ }
+ }
+
+ return returnValue;
+ }
+
+ /**
+ * Get a cati from its id
+ *
+ * @param id the cati id
+ * @return the cati
+ */
+ public Cati getCati(String id) {
+
+ Cati cati = proxy.restore(Cati.class, id);
+
+ return DTOHelper.toDto(cati);
+ }
+
+ /**
+ * Get all the frequencies.
+ *
+ * @return a list containing all the frequencies.
+ */
+ public List<Frequency> getFrequencies() {
+
+ //Create criteria : everything that got frequency extension
+ Search search = Search.query().eq(Element.ELT_EXTENSION, Frequency.EXT_FREQUENCY);
+ Criteria criteria = search.criteria();
+
+ //get results
+ PagedResult<Frequency> frequenciesResult = proxy.findAllByCriteria(Frequency.class, criteria);
+
+ List<Frequency> frequencies = new ArrayList<Frequency>();
+
+ //Fill in frequencies with dtos
+ if (frequenciesResult != null) {
+ log.debug("Frequencies size : " + frequenciesResult.size());
+ for (Frequency frequency:frequenciesResult.getAll()){
+ log.debug("adding a frequency to the list");
+ frequencies.add(DTOHelper.toDto(frequency));
+ }
+ }
+
+ log.debug("Frequencies size : " + frequencies.size());
+
+ if (log.isDebugEnabled()) {
+ log.debug("Frequencies list : " + frequencies);
+ }
+ return frequencies;
+ }
+
+ /**
+ * Save a frequency in database.
+ *
+ * @param frequency the frequency to save
+ * @return the saved frequency
+ * @throws AlreadyExistingException if a frequency with the same name already
+ * exist in database
+ */
+ public Frequency saveFrequency(Frequency frequency) throws AlreadyExistingException {
+
+ if (exist(frequency)) {
+ throw new AlreadyExistingException("Frequency with name " +
+ frequency.getName() + " already exist in database");
+ }
+
+ if (log.isDebugEnabled()){
+ log.debug("Try to save frequency : " + frequency);
+ }
+
+ Frequency returnFrequency = null;
+
+ if (frequency !=null ){
+ Frequency toSaveFrequency = DTOHelper.fromDto(proxy, Frequency.class,frequency);
+ if(log.isDebugEnabled()){
+ log.debug("Try to save frequency : " + toSaveFrequency);
+ }
+
+ Frequency storedFrequency = proxy.store(toSaveFrequency);
+
+ if(log.isDebugEnabled()){
+ log.debug("Saved frequency : " + storedFrequency);
+ }
+
+ returnFrequency = DTOHelper.toDto(storedFrequency);
+ }
+
+ return returnFrequency;
+ }
+
+ /**
+ * Return a new frequency created in database.
+ *
+ * @return the new frequency
+ */
+ public Frequency createFrequency() {
+ Frequency frequency = new FrequencyImpl();
+ frequency = proxy.store(frequency);
+
+ Frequency frequency1 = DTOHelper.toDto(frequency);
+
+ if (log.isDebugEnabled()){
+ log.debug("Frequency " + frequency1 +" created");
+ }
+
+ return frequency1;
+ }
+
+ /**
+ * Delete a frequency
+ */
+ public void deleteFrequency(Frequency frequency) {
+ proxy.delete(frequency.getWikittyId());
+ }
+
+ /**
+ * Get a frequency from its id
+ *
+ * @param id the frequency id
+ * @return the frequency
+ */
+ public Frequency getFrequency(String id) {
+ Frequency frequencyResult = proxy.restore(Frequency.class, id);
+ return DTOHelper.toDto(frequencyResult);
+ }
+
+ /**
+ * Get all the users.
+ *
+ * @return a list containing all the users.
+ */
+ public List<User> getUsers() {
+
+ //Create criteria : everything that got frequency extension
+ Search search = Search.query().eq(Element.ELT_EXTENSION, User.EXT_USER);
+ Criteria criteria = search.criteria();
+ criteria.addSortAscending(User.FIELD_USER_FIRSTNAME);
+
+ //get results
+ PagedResult<User> userPagedResult = proxy.findAllByCriteria(User.class, criteria);
+
+ List<User> users = new ArrayList<User>();
+
+ if (userPagedResult != null) {
+ for (User user:userPagedResult.getAll()){
+ users.add(DTOHelper.toDto(user));
+ }
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Users list : " + users);
+ }
+ return users;
+ }
+
+ /**
+ * Save a user in database.
+ *
+ * @param user the user to save
+ * @return the saved user
+ * @throws AlreadyExistingException if a user with the same name already
+ * exist in database
+ */
+ public User saveUser(User user) throws AlreadyExistingException {
+
+ if (exist(user)) {
+ throw new AlreadyExistingException("User with login " +
+ user.getLogin() + " already exist in database");
+ }
+
+ User entity = DTOHelper.fromDto(proxy, User.class, user);
+ User dto = DTOHelper.toDto(proxy.store(entity));
+
+ return dto;
+ }
+
+ /**
+ * Return a new user created in database.
+ *
+ * @return the new user
+ */
+ public User createUser() {
+ User user = new UserImpl();
+ user = proxy.store(user);
+ return DTOHelper.toDto(user);
+ }
+
+ /**
+ * Delete a user
+ */
+ public void deleteUser(User user) {
+ proxy.delete(user.getWikittyId());
+ }
+
+ /**
+ * Check if a user is already present in database
+ *
+ * @param user the user to check
+ * @return true is exist, false otherwise
+ */
+ protected boolean exist(User user) {
+ boolean returnValue = false;
+
+ if (user != null) {
+ List<User> users = getUsers();
+ for (User user2 : users) {
+ if (user2.getLogin().equals(user2.getLogin())) {
+ returnValue = true;
+ }
+ }
+ }
+
+ return returnValue;
+ }
+
+ /**
+ * Get a user from its id
+ *
+ * @param id the user id
+ * @return the user
+ */
+ public User getUser(String id) {
+ User user = proxy.restore(User.class, id);
+ return DTOHelper.toDto(user);
+ }
+
+ @Override
+ public Skill saveSkill(Skill skill) throws AlreadyExistingException {
+
+ if (exist(skill)) {
+ throw new AlreadyExistingException("Skill named " +
+ skill.getName() + " already exist in database");
+ }
+
+ Skill entity = DTOHelper.fromDto(proxy, Skill.class, skill);
+ Skill dto = DTOHelper.toDto(proxy.store(entity));
+
+ return dto;
+ }
+
+ @Override
+ public Skill createSkill() {
+ Skill skill = new SkillImpl();
+ skill = proxy.store(skill);
+ return DTOHelper.toDto(skill);
+ }
+
+ @Override
+ public void deleteSkill(Skill skill) {
+ proxy.delete(skill.getWikittyId());
+ }
+
+ @Override
+ public Skill getSkill(String id) {
+ Skill skill = proxy.restore(Skill.class, id);
+ return DTOHelper.toDto(skill);
+ }
+
+ protected Boolean exist(Skill skill){
+ //TODO JC 2010/11/30 use this method in all exist methods. Group all exist methods in same place.
+ //Create criteria
+ Search search = Search.query().eq(Element.ELT_EXTENSION, Skill.EXT_SKILL)
+ .eq(Skill.FQ_FIELD_WIKITTYTREENODE_NAME,skill.getName());
+ Criteria criteria = search.criteria();
+
+ //get results
+ PagedResult<Skill> skillPagedResult = proxy.findAllByCriteria(Skill.class, criteria);
+
+ return (skillPagedResult.size()>0);
+ }
+
+ protected Boolean exist(Frequency frequency) {
+ //Create criteria
+ Search search = Search.query().eq(Element.ELT_EXTENSION, Frequency.EXT_FREQUENCY)
+ .eq(Frequency.FQ_FIELD_FREQUENCY_NAME, frequency.getName());
+ Criteria criteria = search.criteria();
+
+ //get results
+ PagedResult<Frequency> frequencyPagedResult = proxy.findAllByCriteria(Frequency.class, criteria);
+
+ return (frequencyPagedResult.size() > 0);
+ }
+
+ public Boolean login(String login, String password){
+ proxy.login(login, password);
+ return true;
+ }
+
+ public List<Skill> getChildrenSkill(String id) {
+
+ //Create criteria : everything that got frequency extension
+ Search search = Search.query().eq(Element.ELT_EXTENSION, Skill.EXT_SKILL)
+ .eq(Skill.FQ_FIELD_WIKITTYTREENODE_PARENT,id);
+ Criteria criteria = search.criteria();
+ criteria.addSortAscending(Skill.FQ_FIELD_WIKITTYTREENODE_NAME);
+
+ //get results
+ PagedResult<Skill> skillPagedResult = proxy.findAllByCriteria(Skill.class, criteria);
+
+ List<Skill> skills = new ArrayList<Skill>();
+
+ if (skillPagedResult != null) {
+ for (Skill skill:skillPagedResult.getAll()){
+ skills.add(skill);
+ }
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Skills list : " + skills);
+ }
+ return skills;
+ }
+}
Added: refComp/skills-services/src/main/resources/log4j.properties
===================================================================
--- refComp/skills-services/src/main/resources/log4j.properties (rev 0)
+++ refComp/skills-services/src/main/resources/log4j.properties 2010-12-01 10:01:29 UTC (rev 22)
@@ -0,0 +1,22 @@
+# Global logging configuration
+log4j.rootLogger=ERROR, stdout, file
+
+# Console output
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
+
+log4j.appender.file=org.apache.log4j.RollingFileAppender
+log4j.appender.file.file=refcomp.log
+log4j.appender.file.MaxFileSize=10MB
+log4j.appender.file.MaxBackupIndex=4
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %5p [%t] %c - %m%n
+
+# Vradi
+log4j.logger.org.chorem.bonzoms.skills=DEBUG
+
+# Wikitty
+log4j.logger.org.nuiton.wikitty=DEBUG
+
+log4j.logger.org.picocontainer=DEBUG
\ No newline at end of file
1
0
26 Nov '10
Author: fdesbois
Date: 2010-11-26 16:21:55 +0100 (Fri, 26 Nov 2010)
New Revision: 442
Url: http://nuiton.org/repositories/revision/sandbox/442
Log:
Keep useful debug logger (commented) to display criteria query as HQL
Modified:
jpa2-validation/trunk/jsr317-jpa2/src/test/resources/log4j.properties
Modified: jpa2-validation/trunk/jsr317-jpa2/src/test/resources/log4j.properties
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/resources/log4j.properties 2010-11-26 14:17:17 UTC (rev 441)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/resources/log4j.properties 2010-11-26 15:21:55 UTC (rev 442)
@@ -9,3 +9,4 @@
log4j.appender.A1.layout.ConversionPattern=%d [%p] (%c:%L) %m%n
log4j.logger.org.nuiton.sandbox.jsr317.jpa2=info
+#log4j.logger.org.hibernate.ejb.criteria=debug
1
0
26 Nov '10
Author: fdesbois
Date: 2010-11-26 15:17:17 +0100 (Fri, 26 Nov 2010)
New Revision: 441
Url: http://nuiton.org/repositories/revision/sandbox/441
Log:
Add test with metatemodel usage, error in hibernate 3.6 with ElementCollection
Added:
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/Country.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/CountryImpl.java
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/entity/MetaModelTest.java
Modified:
jpa2-validation/trunk/jsr303-validation/src/test/resources/META-INF/persistence.xml
jpa2-validation/trunk/jsr317-jpa2/pom.xml
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/Address.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/AddressImpl.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/Customer.java
jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/CustomerImpl.java
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImplTest.java
jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/AddressFake.java
jpa2-validation/trunk/jsr317-jpa2/src/test/resources/META-INF/persistence.xml
jpa2-validation/trunk/pom.xml
Modified: jpa2-validation/trunk/jsr303-validation/src/test/resources/META-INF/persistence.xml
===================================================================
--- jpa2-validation/trunk/jsr303-validation/src/test/resources/META-INF/persistence.xml 2010-11-22 14:13:30 UTC (rev 440)
+++ jpa2-validation/trunk/jsr303-validation/src/test/resources/META-INF/persistence.xml 2010-11-26 14:17:17 UTC (rev 441)
@@ -5,6 +5,7 @@
<persistence-unit name="jsr303-test" transaction-type="RESOURCE_LOCAL">
<class>org.nuiton.sandbox.jsr317.jpa2.entity.CustomerImpl</class>
+ <class>org.nuiton.sandbox.jsr317.jpa2.entity.CountryImpl</class>
<!--<validation-mode>NONE</validation-mode>-->
</persistence-unit>
Modified: jpa2-validation/trunk/jsr317-jpa2/pom.xml
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/pom.xml 2010-11-22 14:13:30 UTC (rev 440)
+++ jpa2-validation/trunk/jsr317-jpa2/pom.xml 2010-11-26 14:17:17 UTC (rev 441)
@@ -2,217 +2,189 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.0.0</modelVersion>
- <!-- ************************************************************* -->
- <!-- *** POM Relationships *************************************** -->
- <!-- ************************************************************* -->
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
- <parent>
- <groupId>org.nuiton.sandbox</groupId>
- <artifactId>jsr-tests</artifactId>
- <version>0.1-SNAPSHOT</version>
- </parent>
+ <parent>
+ <groupId>org.nuiton.sandbox</groupId>
+ <artifactId>jsr-tests</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </parent>
- <artifactId>jsr317-jpa2</artifactId>
+ <artifactId>jsr317-jpa2</artifactId>
- <dependencies>
+ <dependencies>
- <!--<dependency>-->
- <!--<groupId>org.nuiton</groupId>-->
- <!--<artifactId>nuiton-utils</artifactId>-->
- <!--<version>1.4.2</version>-->
- <!--</dependency>-->
+ <!--<dependency>-->
+ <!--<groupId>org.nuiton</groupId>-->
+ <!--<artifactId>nuiton-utils</artifactId>-->
+ <!--<version>1.4.2</version>-->
+ <!--</dependency>-->
- <!-- SPRING -->
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-orm</artifactId>
- </dependency>
+ <!-- SPRING -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-orm</artifactId>
+ </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-jdbc</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-beans</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-tx</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ </dependency>
- <!-- JPA : JSR-317- -->
- <dependency>
- <groupId>org.hibernate.javax.persistence</groupId>
- <artifactId>hibernate-jpa-2.0-api</artifactId>
- </dependency>
+ <!-- JPA : JSR-317- -->
+ <dependency>
+ <groupId>org.hibernate.javax.persistence</groupId>
+ <artifactId>hibernate-jpa-2.0-api</artifactId>
+ </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-jpamodelgen</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-jpamodelgen</artifactId>
+ </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ </dependency>
- <!-- LOGGING -->
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </dependency>
-
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </dependency>
+ <!-- LOGGING -->
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
- <!-- TESTS -->
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
- <!-- Hibernate implementation used for tests -->
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-entitymanager</artifactId>
- </dependency>
+ <!-- TESTS -->
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
+ <!-- Hibernate implementation used for tests -->
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
- <!-- Testing -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- </dependency>
+ <!-- Testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
- </dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ </dependency>
- <!-- ************************************************************* -->
- <!-- *** Project Information ************************************* -->
- <!-- ************************************************************* -->
+ </dependencies>
- <name>JSR Tests :: JSR-317 JPA2</name>
- <description>JPA2 tests</description>
- <inceptionYear>2010</inceptionYear>
- <url>http://maven-site.nuiton.org/${project.artifactId}</url>
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
- <!-- ************************************************************* -->
- <!-- *** Build Settings ****************************************** -->
- <!-- ************************************************************* -->
+ <name>JSR Tests :: JSR-317 JPA2</name>
+ <description>JPA2 tests</description>
+ <inceptionYear>2010</inceptionYear>
+ <url>http://maven-site.nuiton.org/${project.artifactId}</url>
- <packaging>jar</packaging>
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
- <build>
+ <packaging>jar</packaging>
- <resources>
- <resource>
- <directory>src/main/resources</directory>
- <includes>
- <include>**/*</include>
- </includes>
- <filtering>true</filtering>
- </resource>
- </resources>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
- <!-- Configuration to generate metamodel : ref = http://docs.jboss.org/hibernate/jpamodelgen/1.0/reference/en-US/html_single… -->
- <plugins>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <!--<compilerArguments>-->
- <!--<!– Generate Jpa MetaModel –>-->
- <!--<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>-->
- <!--</compilerArguments>-->
- <compilerArgument>-proc:none</compilerArgument>
- </configuration>
- </plugin>
+ <!-- Configuration to generate metamodel : ref = http://docs.jboss.org/hibernate/jpamodelgen/1.0/reference/en-US/html_single… -->
+ <plugins>
- <plugin>
- <groupId>org.bsc.maven</groupId>
- <artifactId>maven-processor-plugin</artifactId>
- <executions>
- <execution>
- <id>process</id>
- <goals>
- <goal>process</goal>
- </goals>
- <phase>generate-sources</phase>
- <configuration>
- <compilerArguments>-Adebug=TRUE</compilerArguments>
- <!-- source output directory -->
- <outputDirectory>${maven.gen.dir}/java</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <compilerArgument>-proc:none</compilerArgument>
+ </configuration>
+ </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>add-source</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>add-source</goal>
- </goals>
- <configuration>
- <sources>
- <source>${maven.gen.dir}/java</source>
- </sources>
- </configuration>
- </execution>
- </executions>
- </plugin>
+ <plugin>
+ <groupId>org.bsc.maven</groupId>
+ <artifactId>maven-processor-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>process</id>
+ <phase>process-sources</phase>
+ <goals>
+ <goal>process</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
- </plugins>
+ </plugins>
- </build>
+ </build>
- <!-- Source control management. -->
- <scm>
- <connection>
- scm:svn:http://svn.nuiton.org/svn/sandbox/jpa2-validation/trunk/jsr317-jpa2
- </connection>
- <developerConnection>
- scm:svn:http://svn.nuiton.org/svn/sandbox/jpa2-validation/trunk/jsr317-jpa2
- </developerConnection>
- <url>
- http://www.nuiton.org/repositories/browse/sandbox/jpa2-validation/trunk/jsr…
- </url>
- </scm>
+ <!-- Source control management. -->
+ <scm>
+ <connection>
+ scm:svn:http://svn.nuiton.org/svn/sandbox/jpa2-validation/trunk/jsr317-jpa2
+ </connection>
+ <developerConnection>
+ scm:svn:http://svn.nuiton.org/svn/sandbox/jpa2-validation/trunk/jsr317-jpa2
+ </developerConnection>
+ <url>
+ http://www.nuiton.org/repositories/browse/sandbox/jpa2-validation/trunk/jsr…
+ </url>
+ </scm>
</project>
Modified: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/Address.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/Address.java 2010-11-22 14:13:30 UTC (rev 440)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/Address.java 2010-11-26 14:17:17 UTC (rev 441)
@@ -64,11 +64,11 @@
/**
* @return the country
*/
- public String getCountry();
+ public Country getCountry();
/**
* @param country the country to set
*/
- public void setCountry(String country);
+ public void setCountry(Country country);
}
Modified: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/AddressImpl.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/AddressImpl.java 2010-11-22 14:13:30 UTC (rev 440)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/AddressImpl.java 2010-11-26 14:17:17 UTC (rev 441)
@@ -1,9 +1,10 @@
/**
- *
+ *
*/
package org.nuiton.sandbox.jsr317.jpa2.entity;
import javax.persistence.Embeddable;
+import javax.persistence.ManyToOne;
/**
* @author fdesbois <fdesbois(a)codelutin.com>
@@ -11,118 +12,119 @@
*/
@Embeddable
public class AddressImpl implements Address {
-
- public static final long serialVersionUID = 1L;
-
- /**
- * the street
- */
- private String street;
-
- /**
- * the street complement
- */
- private String street2;
-
- /**
- * the zip code
- */
- private String zipCode;
-
- /**
- * the town
- */
- private String town;
-
- /**
- * the country
- */
- private String country;
-
- /**
- * Default constructor: constructs an empty address
- */
- public AddressImpl(){
- }
- /**
- * @return the street
- */
- @Override
- public String getStreet() {
- return street;
- }
+ public static final long serialVersionUID = 1L;
- /**
- * @param street the street to set
- */
- @Override
- public void setStreet(String street) {
- this.street = street;
- }
+ /**
+ * the street
+ */
+ private String street;
- /**
- * @return the street2
- */
- @Override
- public String getStreet2() {
- return street2;
- }
+ /**
+ * the street complement
+ */
+ private String street2;
- /**
- * @param street2 the street2 to set
- */
- @Override
- public void setStreet2(String street2) {
- this.street2 = street2;
- }
+ /**
+ * the zip code
+ */
+ private String zipCode;
- /**
- * @return the zipCode
- */
- @Override
- public String getZipCode() {
- return zipCode;
- }
+ /**
+ * the town
+ */
+ private String town;
- /**
- * @param zipCode the zipCode to set
- */
- @Override
- public void setZipCode(String zipCode) {
- this.zipCode = zipCode;
- }
+ /**
+ * the country
+ */
+ private Country country;
- /**
- * @return the town
- */
- @Override
- public String getTown() {
- return town;
- }
+ /**
+ * Default constructor: constructs an empty address
+ */
+ public AddressImpl() {
+ }
- /**
- * @param town the town to set
- */
- @Override
- public void setTown(String town) {
- this.town = town;
- }
+ /**
+ * @return the street
+ */
+ @Override
+ public String getStreet() {
+ return street;
+ }
- /**
- * @return the country
- */
- @Override
- public String getCountry() {
- return country;
- }
+ /**
+ * @param street the street to set
+ */
+ @Override
+ public void setStreet(String street) {
+ this.street = street;
+ }
- /**
- * @param country the country to set
- */
- @Override
- public void setCountry(String country) {
- this.country = country;
- }
+ /**
+ * @return the street2
+ */
+ @Override
+ public String getStreet2() {
+ return street2;
+ }
+ /**
+ * @param street2 the street2 to set
+ */
+ @Override
+ public void setStreet2(String street2) {
+ this.street2 = street2;
+ }
+
+ /**
+ * @return the zipCode
+ */
+ @Override
+ public String getZipCode() {
+ return zipCode;
+ }
+
+ /**
+ * @param zipCode the zipCode to set
+ */
+ @Override
+ public void setZipCode(String zipCode) {
+ this.zipCode = zipCode;
+ }
+
+ /**
+ * @return the town
+ */
+ @Override
+ public String getTown() {
+ return town;
+ }
+
+ /**
+ * @param town the town to set
+ */
+ @Override
+ public void setTown(String town) {
+ this.town = town;
+ }
+
+ /**
+ * @return the country
+ */
+ @Override
+ @ManyToOne(targetEntity = CountryImpl.class)
+ public Country getCountry() {
+ return country;
+ }
+
+ /**
+ * @param country the country to set
+ */
+ @Override
+ public void setCountry(Country country) {
+ this.country = country;
+ }
+
}
Added: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/Country.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/Country.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/Country.java 2010-11-26 14:17:17 UTC (rev 441)
@@ -0,0 +1,18 @@
+package org.nuiton.sandbox.jsr317.jpa2.entity;
+
+/**
+ * Created on 26 nov. 2010
+ *
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id$
+ */
+public interface Country extends BaseEntity {
+
+ String getCode();
+
+ void setCode(String code);
+
+ String getName();
+
+ void setName(String name);
+}
Added: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/CountryImpl.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/CountryImpl.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/CountryImpl.java 2010-11-26 14:17:17 UTC (rev 441)
@@ -0,0 +1,43 @@
+package org.nuiton.sandbox.jsr317.jpa2.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+/**
+ * Created on 26 nov. 2010
+ *
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id$
+ */
+@Entity
+@Table(name = CountryImpl.TABLE_NAME)
+public class CountryImpl extends BaseEntityImpl implements Country {
+
+ public static final long serialVersionUID = 1L;
+
+ public static final String TABLE_NAME = "COUNTRY";
+
+ private String code;
+
+ private String name;
+
+ @Override
+ public String getCode() {
+ return code;
+ }
+
+ @Override
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Modified: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/Customer.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/Customer.java 2010-11-22 14:13:30 UTC (rev 440)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/Customer.java 2010-11-26 14:17:17 UTC (rev 441)
@@ -1,8 +1,10 @@
/**
- *
+ *
*/
package org.nuiton.sandbox.jsr317.jpa2.entity;
+import java.util.List;
+
/**
* @author fdesbois <fdesbois(a)codelutin.com>
* @version $Id$
@@ -23,73 +25,73 @@
String PROPERTY_ACCESS_CODE = "accessCode";
- /**
- * @return the firstName
- */
- public String getFirstName() ;
+ /**
+ * @return the firstName
+ */
+ String getFirstName();
- /**
- * @param firstName the firstName to set
- */
- public void setFirstName(String firstName);
+ /**
+ * @param firstName the firstName to set
+ */
+ void setFirstName(String firstName);
- /**
- * @return the lastName
- */
- public String getLastName();
+ /**
+ * @return the lastName
+ */
+ String getLastName();
- /**
- * @param lastName the lastName to set
- */
- public void setLastName(String lastName);
+ /**
+ * @param lastName the lastName to set
+ */
+ void setLastName(String lastName);
- /**
- * @return the address
- */
- public Address getAddress();
+ /**
+ * @return the addresses
+ */
+ List<Address> getAddresses();
- /**
- * @param address the address to set
- */
- public void setAddress(Address address);
+ /**
+ * @param addresses the addresses to set
+ */
+ void setAddresses(List<Address> addresses);
- /**
- * @return the phone
- */
- public String getPhone() ;
+ /**
+ * @return the phone
+ */
+ String getPhone();
- /**
- * @param phone the phone to set
- */
- public void setPhone(String phone) ;
-
- /**
- * @return the cellphone
- */
- public String getCellphone() ;
+ /**
+ * @param phone the phone to set
+ */
+ void setPhone(String phone);
- /**
- * @param cellphone the cellphone to set
- */
- public void setCellphone(String cellphone) ;
+ /**
+ * @return the cellphone
+ */
+ String getCellphone();
- /**
- * @return the email
- */
- public String getEmail();
+ /**
+ * @param cellphone the cellphone to set
+ */
+ void setCellphone(String cellphone);
- /**
- * @param email the email to set
- */
- public void setEmail(String email) ;
+ /**
+ * @return the email
+ */
+ String getEmail();
- /**
- * @return the accessCode
- */
- public AccessCode getAccessCode();
+ /**
+ * @param email the email to set
+ */
+ void setEmail(String email);
- /**
- * @param accessCode the accessCode to set
- */
- public void setAccessCode(AccessCode accessCode) ;
+ /**
+ * @return the accessCode
+ */
+ AccessCode getAccessCode();
+
+ /**
+ * @param accessCode the accessCode to set
+ */
+ void setAccessCode(AccessCode accessCode);
}
Modified: jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/CustomerImpl.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/CustomerImpl.java 2010-11-22 14:13:30 UTC (rev 440)
+++ jpa2-validation/trunk/jsr317-jpa2/src/main/java/org/nuiton/sandbox/jsr317/jpa2/entity/CustomerImpl.java 2010-11-26 14:17:17 UTC (rev 441)
@@ -3,9 +3,13 @@
*/
package org.nuiton.sandbox.jsr317.jpa2.entity;
+import javax.persistence.CollectionTable;
+import javax.persistence.ElementCollection;
import javax.persistence.Embedded;
import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
import javax.persistence.Table;
+import java.util.List;
import org.nuiton.sandbox.jsr317.jpa2.config.JpaHelper;
@@ -14,11 +18,17 @@
* @version $Id$
*/
@Entity
-@Table(name = "CUSTOMER")
+@Table(name = CustomerImpl.TABLE_NAME)
public class CustomerImpl extends BaseEntityImpl implements Customer {
public static final long serialVersionUID = 1L;
+ public static final String TABLE_NAME = "CUSTOMER";
+
+ public static final String FOREIGN_KEY_COLUMN_NAME = "customer_id";
+
+ public static final String CUSTOMER_ADDRESS_TABLE_NAME = "CUSTOMER_ADDRESS";
+
/**
* the firstName
*/
@@ -32,7 +42,7 @@
/**
* the address
*/
- private Address address;
+ private List<Address> addresses;
/**
* the phone number
@@ -95,18 +105,21 @@
/**
* @return the address
*/
- @Embedded
@Override
- public AddressImpl getAddress() {
- return JpaHelper.safeEmbeddableCast(address, AddressImpl.class);
+ @ElementCollection(targetClass = AddressImpl.class)
+ @CollectionTable(name = CUSTOMER_ADDRESS_TABLE_NAME, joinColumns =
+ @JoinColumn(name = FOREIGN_KEY_COLUMN_NAME, referencedColumnName = PROPERTY_ID)
+ )
+ public List<Address> getAddresses() {
+ return addresses;
}
/**
- * @param address the address to set
+ * @param addresses the address to set
*/
@Override
- public void setAddress(Address address) {
- this.address = address;
+ public void setAddresses(List<Address> addresses) {
+ this.addresses = addresses;
}
/**
Added: jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/entity/MetaModelTest.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/entity/MetaModelTest.java (rev 0)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/entity/MetaModelTest.java 2010-11-26 14:17:17 UTC (rev 441)
@@ -0,0 +1,26 @@
+package org.nuiton.sandbox.jsr317.jpa2.entity;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.nuiton.sandbox.jsr317.jpa2.test.BaseTest;
+
+/**
+ * Created on 26 nov. 2010
+ *
+ * @author fdesbois <florian.desbois(a)wiztivi.com>
+ * @version $Id$
+ */
+public class MetaModelTest extends BaseTest {
+
+ @Test
+ public void testEmbeddableSingularAttribute() {
+
+ Assert.assertNotNull(AccessCodeImpl_.login);
+ Assert.assertNotNull(AccessCodeImpl_.password);
+
+ // Broken with Hibernate 3.6 and MetamodelGenerator 1.1
+ Assert.assertNotNull(AddressImpl_.town);
+ Assert.assertNotNull(AddressImpl_.country);
+ }
+
+}
Modified: jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImplTest.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImplTest.java 2010-11-22 14:13:30 UTC (rev 440)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/persistence/CustomerDAOImplTest.java 2010-11-26 14:17:17 UTC (rev 441)
@@ -1,9 +1,11 @@
package org.nuiton.sandbox.jsr317.jpa2.persistence;
import javax.persistence.PersistenceException;
+import java.util.Arrays;
import org.junit.Assert;
import org.junit.Test;
+import org.junit.matchers.JUnitMatchers;
import org.nuiton.sandbox.jsr317.jpa2.config.JpaHelper;
import org.nuiton.sandbox.jsr317.jpa2.entity.Address;
import org.nuiton.sandbox.jsr317.jpa2.entity.Customer;
@@ -36,10 +38,11 @@
address.setStreet("createStreet");
address.setZipCode("40000");
- user.setAddress(address);
+ user.setAddresses(Arrays.asList(address));
- Assert.assertNotNull(user.getAddress());
- Assert.assertEquals("createStreet", user.getAddress().getStreet());
+ Assert.assertNotNull(user.getAddresses());
+ Assert.assertThat(user.getAddresses(), JUnitMatchers.hasItem(address));
+ Assert.assertEquals("createStreet", user.getAddresses().get(0).getStreet());
}
/**
@@ -59,7 +62,7 @@
address.setStreet("fakeStreet");
address.setZipCode("40000");
- user.setAddress(address);
+ user.setAddresses(Arrays.asList(address));
userDAO.save(user);
}
Modified: jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/AddressFake.java
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/AddressFake.java 2010-11-22 14:13:30 UTC (rev 440)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/java/org/nuiton/sandbox/jsr317/jpa2/test/AddressFake.java 2010-11-26 14:17:17 UTC (rev 441)
@@ -2,6 +2,7 @@
import org.nuiton.sandbox.jsr317.jpa2.config.JpaHelper;
import org.nuiton.sandbox.jsr317.jpa2.entity.Address;
+import org.nuiton.sandbox.jsr317.jpa2.entity.Country;
/**
* Fake implementation of address to test Embeddable target management (need explicit cast provided by {@link
@@ -51,11 +52,11 @@
}
@Override
- public String getCountry() {
+ public Country getCountry() {
return null;
}
@Override
- public void setCountry(String country) {
+ public void setCountry(Country country) {
}
}
Modified: jpa2-validation/trunk/jsr317-jpa2/src/test/resources/META-INF/persistence.xml
===================================================================
--- jpa2-validation/trunk/jsr317-jpa2/src/test/resources/META-INF/persistence.xml 2010-11-22 14:13:30 UTC (rev 440)
+++ jpa2-validation/trunk/jsr317-jpa2/src/test/resources/META-INF/persistence.xml 2010-11-26 14:17:17 UTC (rev 441)
@@ -5,6 +5,7 @@
<persistence-unit name="jsr317-test" transaction-type="RESOURCE_LOCAL">
<class>org.nuiton.sandbox.jsr317.jpa2.entity.CustomerImpl</class>
+ <class>org.nuiton.sandbox.jsr317.jpa2.entity.CountryImpl</class>
</persistence-unit>
</persistence>
\ No newline at end of file
Modified: jpa2-validation/trunk/pom.xml
===================================================================
--- jpa2-validation/trunk/pom.xml 2010-11-22 14:13:30 UTC (rev 440)
+++ jpa2-validation/trunk/pom.xml 2010-11-26 14:17:17 UTC (rev 441)
@@ -81,7 +81,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
- <version>${jpa2ApiVersion}</version>
+ <version>${hibernateMetamodelGeneratorVersion}</version>
<scope>provided</scope>
</dependency>
@@ -173,13 +173,14 @@
<properties>
<!-- Dependencies versions -->
- <springVersion>3.0.4.RELEASE</springVersion>
+ <springVersion>3.0.5.RELEASE</springVersion>
<jpa2ApiVersion>1.0.0.Final</jpa2ApiVersion>
<validationApiVersion>1.0.0.GA</validationApiVersion>
<!-- For test only : Hibernate implementation for JSR used -->
- <hibernateVersion>3.5.6-Final</hibernateVersion>
- <hibernateValidatorVersion>4.0.2.GA</hibernateValidatorVersion>
+ <hibernateVersion>3.6.0.Final</hibernateVersion>
+ <hibernateValidatorVersion>4.1.0.Final</hibernateValidatorVersion>
+ <hibernateMetamodelGeneratorVersion>1.1.0.Final</hibernateMetamodelGeneratorVersion>
<slf4jVersion>1.6.1</slf4jVersion>
</properties>
@@ -194,17 +195,19 @@
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>1.3.7</version>
- </plugin>
+ <configuration>
+ <!-- source output directory -->
+ <outputDirectory>${maven.gen.dir}/annotations</outputDirectory>
+ </configuration>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <version>1.3</version>
- </plugin>
+ <!--<dependencies>-->
+ <!--<dependency>-->
+ <!--<groupId>org.hibernate</groupId>-->
+ <!--<artifactId>hibernate-jpamodelgen</artifactId>-->
+ <!--<version>${hibernateMetamodelGeneratorVersion}</version>-->
+ <!--</dependency>-->
+ <!--</dependencies>-->
- <plugin>
- <artifactId>maven-invoker-plugin</artifactId>
- <version>1.5</version>
</plugin>
</plugins>
1
0
r440 - in jpa2-validation/trunk/jsr303-validation/src: it/hibernate it/hibernate/src/main/java/org/nuiton/sandbox/jsr303/validation/hibernate it/hibernate/src/main/resources it/hibernate/src/main/resources/META-INF main/java/org/nuiton/sandbox/jsr303/validation/services
by fdesbois@users.nuiton.org 22 Nov '10
by fdesbois@users.nuiton.org 22 Nov '10
22 Nov '10
Author: fdesbois
Date: 2010-11-22 15:13:30 +0100 (Mon, 22 Nov 2010)
New Revision: 440
Url: http://nuiton.org/repositories/revision/sandbox/440
Log:
- Repair compilation issues
- Add missing configuration for transactionManager
- Use properties file for configuration options
Added:
jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/resources/application.properties
jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/resources/hibernate-spring-context.xml
Removed:
jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/resources/spring/
Modified:
jpa2-validation/trunk/jsr303-validation/src/it/hibernate/pom.xml
jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/java/org/nuiton/sandbox/jsr303/validation/hibernate/TransactionTest.java
jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/resources/META-INF/persistence.xml
jpa2-validation/trunk/jsr303-validation/src/main/java/org/nuiton/sandbox/jsr303/validation/services/BaseService.java
Modified: jpa2-validation/trunk/jsr303-validation/src/it/hibernate/pom.xml
===================================================================
--- jpa2-validation/trunk/jsr303-validation/src/it/hibernate/pom.xml 2010-11-22 11:16:07 UTC (rev 439)
+++ jpa2-validation/trunk/jsr303-validation/src/it/hibernate/pom.xml 2010-11-22 14:13:30 UTC (rev 440)
@@ -17,17 +17,17 @@
<dependencies>
- <!--<dependency>-->
- <!--<groupId>${project.groupId}</groupId>-->
- <!--<artifactId>tivimmo-services</artifactId>-->
- <!--<version>${project.version}</version>-->
- <!--</dependency>-->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>jsr317-jpa2</artifactId>
+ <version>${project.version}</version>
+ </dependency>
- <!--<dependency>-->
- <!--<groupId>${project.groupId}</groupId>-->
- <!--<artifactId>tivimmo-model</artifactId>-->
- <!--<version>${project.version}</version>-->
- <!--</dependency>-->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>jsr303-validation</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.springframework</groupId>
@@ -56,36 +56,48 @@
<artifactId>commons-logging</artifactId>
</dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>compile</scope>
+ </dependency>
+
<!-- RUNTIME scope for implementations -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
- <scope>runtime</scope>
+ <scope>compile</scope>
</dependency>
<!-- Hibernate implementation used in tests -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
- <scope>runtime</scope>
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
- <scope>runtime</scope>
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
- <scope>runtime</scope>
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
- <scope>runtime</scope>
+ <scope>compile</scope>
</dependency>
<!--<dependency>-->
Modified: jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/java/org/nuiton/sandbox/jsr303/validation/hibernate/TransactionTest.java
===================================================================
--- jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/java/org/nuiton/sandbox/jsr303/validation/hibernate/TransactionTest.java 2010-11-22 11:16:07 UTC (rev 439)
+++ jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/java/org/nuiton/sandbox/jsr303/validation/hibernate/TransactionTest.java 2010-11-22 14:13:30 UTC (rev 440)
@@ -36,10 +36,13 @@
Customer customerOk = serviceCustomer.newCustomer();
customerOk.setFirstName("FIRST_NAME");
- customerOk.setFirstName("LAST_NAME");
+ customerOk.setLastName("LAST_NAME");
serviceCustomer.saveCustomer(customerOk);
+ // Check number of customer in safe transaction
+ logger.info("CountCustomers = " + countCustomers(customerDAO));
+
Customer customerKo = serviceCustomer.newCustomer();
// Will throw an ConstraintViolationException and rollback, but first agency is still in database
@@ -51,13 +54,13 @@
logger.info("ConstraintViolationException", ex);
} finally {
- // Check number of agency in safe transaction
+ // Check number of customer in safe transaction
logger.info("CountCustomers = " + countCustomers(customerDAO));
}
}
@Transactional
- protected static int countCustomers(CustomerDAO customerDAO) {
+ public int countCustomers(CustomerDAO customerDAO) {
return customerDAO.count();
}
Modified: jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/resources/META-INF/persistence.xml
===================================================================
--- jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/resources/META-INF/persistence.xml 2010-11-22 11:16:07 UTC (rev 439)
+++ jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/resources/META-INF/persistence.xml 2010-11-22 14:13:30 UTC (rev 440)
@@ -3,7 +3,7 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
- <persistence-unit name="tivimmo" transaction-type="RESOURCE_LOCAL">
+ <persistence-unit name="jsr317" transaction-type="RESOURCE_LOCAL">
<class>org.nuiton.sandbox.jsr317.jpa2.entity.CustomerImpl</class>
<!--<validation-mode>NONE</validation-mode>-->
</persistence-unit>
Added: jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/resources/application.properties
===================================================================
--- jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/resources/application.properties (rev 0)
+++ jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/resources/application.properties 2010-11-22 14:13:30 UTC (rev 440)
@@ -0,0 +1,15 @@
+# JDBC configuration
+jdbc.url=jdbc:h2:file:./target/surefire-data/hibernate
+jdbc.username=sa
+jdbc.password=
+
+# Dialect to use
+database.dialect=org.hibernate.dialect.H2Dialect
+option.showSql=true
+option.generateDdl=true
+
+# Option to generate the schema
+option.hbm2ddl.auto=create
+# Option to genate unique ids in all database (@GeneratedValue)
+option.id.new_generator_mappings=true
+
\ No newline at end of file
Copied: jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/resources/hibernate-spring-context.xml (from rev 436, jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/resources/spring/hibernate-spring-context.xml)
===================================================================
--- jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/resources/hibernate-spring-context.xml (rev 0)
+++ jpa2-validation/trunk/jsr303-validation/src/it/hibernate/src/main/resources/hibernate-spring-context.xml 2010-11-22 14:13:30 UTC (rev 440)
@@ -0,0 +1,55 @@
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
+
+ <!-- SERVICES CONFIGURATION -->
+ <import resource="classpath:/jsr303-spring-context.xml"/>
+
+ <!-- MODEL INJECTION and JPA CONFIGURATION -->
+ <import resource="classpath:/jsr317-spring-context.xml"/>
+
+ <!-- Read properties file to inject properties using ${} -->
+ <context:property-placeholder location="application.properties"/>
+
+ <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="url" value="${jdbc.url}"/>
+ <property name="username" value="${jdbc.username}"/>
+ <property name="password" value="${jdbc.password}"/>
+ </bean>
+
+ <!-- Activate transactionManager using @Transactional annotations -->
+ <tx:annotation-driven transaction-manager="transactionManager"/>
+
+ <bean id="transactionManager"
+ class="org.springframework.orm.jpa.JpaTransactionManager">
+ <property name="entityManagerFactory" ref="entityManagerFactory"/>
+ </bean>
+
+ <bean id="entityManagerFactory"
+ class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <property name="dataSource" ref="dataSource"/>
+ <property name="jpaVendorAdapter">
+ <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
+ <property name="showSql" value="${option.showSql}"/>
+ <property name="generateDdl" value="${option.generateDdl}"/>
+ <property name="databasePlatform" value="${database.dialect}"/>
+ </bean>
+ </property>
+ <property name="jpaProperties">
+ <props>
+ <prop key="hibernate.hbm2ddl.auto">${option.hbm2ddl.auto}</prop>
+ <!-- IdGenerator Strategy : one unique number for each row for all database -->
+ <prop key="hibernate.id.new_generator_mappings">${option.id.new_generator_mappings}</prop>
+ </props>
+ </property>
+ <property name="loadTimeWeaver">
+ <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
+ </property>
+ </bean>
+
+</beans>
\ No newline at end of file
Modified: jpa2-validation/trunk/jsr303-validation/src/main/java/org/nuiton/sandbox/jsr303/validation/services/BaseService.java
===================================================================
--- jpa2-validation/trunk/jsr303-validation/src/main/java/org/nuiton/sandbox/jsr303/validation/services/BaseService.java 2010-11-22 11:16:07 UTC (rev 439)
+++ jpa2-validation/trunk/jsr303-validation/src/main/java/org/nuiton/sandbox/jsr303/validation/services/BaseService.java 2010-11-22 14:13:30 UTC (rev 440)
@@ -32,15 +32,15 @@
if (!errors.isEmpty()) {
- if (logger.isTraceEnabled()) {
+ if (logger.isDebugEnabled()) {
for (ConstraintViolation<T> constraint : errors) {
- logger.trace("constraint.getMessageTemplate = " + constraint.getMessageTemplate());
- logger.trace("constraint.getMessage = " + constraint.getMessage());
- logger.trace("constraint.getInvalidValue = " + constraint.getInvalidValue());
- logger.trace("constraint.getLeafBean = " + constraint.getLeafBean());
- logger.trace("constraint.getPropertyPath = " + constraint.getPropertyPath());
- logger.trace("constraint.getRootBean = " + constraint.getRootBean());
- logger.trace("constraint.getRootBeanClass = " + constraint.getRootBeanClass());
+ logger.debug("constraint.getMessageTemplate = " + constraint.getMessageTemplate());
+ logger.debug("constraint.getMessage = " + constraint.getMessage());
+ logger.debug("constraint.getInvalidValue = " + constraint.getInvalidValue());
+ logger.debug("constraint.getLeafBean = " + constraint.getLeafBean());
+ logger.debug("constraint.getPropertyPath = " + constraint.getPropertyPath());
+ logger.debug("constraint.getRootBean = " + constraint.getRootBean());
+ logger.debug("constraint.getRootBeanClass = " + constraint.getRootBeanClass());
}
}
1
0
r439 - jpa2-validation/trunk/jsr303-validation/src/it/hibernate
by tchemit@users.nuiton.org 22 Nov '10
by tchemit@users.nuiton.org 22 Nov '10
22 Nov '10
Author: tchemit
Date: 2010-11-22 12:16:07 +0100 (Mon, 22 Nov 2010)
New Revision: 439
Url: http://nuiton.org/repositories/revision/sandbox/439
Log:
make it works
Added:
jpa2-validation/trunk/jsr303-validation/src/it/hibernate/LICENSE.txt
jpa2-validation/trunk/jsr303-validation/src/it/hibernate/README.txt
jpa2-validation/trunk/jsr303-validation/src/it/hibernate/changelog.txt
Modified:
jpa2-validation/trunk/jsr303-validation/src/it/hibernate/invoker.properties
Property changes on: jpa2-validation/trunk/jsr303-validation/src/it/hibernate/LICENSE.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Property changes on: jpa2-validation/trunk/jsr303-validation/src/it/hibernate/README.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Property changes on: jpa2-validation/trunk/jsr303-validation/src/it/hibernate/changelog.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: jpa2-validation/trunk/jsr303-validation/src/it/hibernate/invoker.properties
===================================================================
--- jpa2-validation/trunk/jsr303-validation/src/it/hibernate/invoker.properties 2010-11-22 11:06:39 UTC (rev 438)
+++ jpa2-validation/trunk/jsr303-validation/src/it/hibernate/invoker.properties 2010-11-22 11:16:07 UTC (rev 439)
@@ -1,7 +1,7 @@
# A comma or space separated list of goals/phases to execute, may
# specify an empty list to execute the default goal of the IT project
-invoker.goals=clean exec:java -Dexec.mainClass="org.nuiton.sandbox.jsr303.validation.hibernate.Launcher"
+invoker.goals=clean compile exec:java -Dexec.mainClass="org.nuiton.sandbox.jsr303.validation.hibernate.Launcher"
# Optionally, a list of goals to run during further invocations of Maven
#invoker.goals.2=${project.groupId}:${project.artifactId}:${project.version}:run
1
0