Topia-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
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- 4806 discussions
r3132 - in trunk: topia-it/src/test/java/org/nuiton/topia/persistence/internal topia-persistence/src/main/java/org/nuiton/topia/persistence/internal
by athimel@users.nuiton.org 23 May '14
by athimel@users.nuiton.org 23 May '14
23 May '14
Author: athimel
Date: 2014-05-23 12:29:45 +0200 (Fri, 23 May 2014)
New Revision: 3132
Url: http://forge.nuiton.org/projects/topia/repository/revisions/3132
Log:
refs #3208 Prevent exception when using findAllLazy together with a SELECT clause
Modified:
trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java
Modified: trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java
===================================================================
--- trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java 2014-05-23 08:28:43 UTC (rev 3131)
+++ trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java 2014-05-23 10:29:45 UTC (rev 3132)
@@ -181,8 +181,27 @@
}
@Test
- public void iterateOnTopiaDAO() throws TopiaException {
+ public void findAllLazyWithSelect() throws TopiaException {
+ Assert.assertEquals(dao.count(), 0);
+
+ createPersons(25);
+
+ Map<String, Object> emptyArgs = Maps.newHashMap();
+
+ dao.setBatchSize(10);
+
+ String hql = "SELECT DISTINCT(" + Person.PROPERTY_NAME + ") " +
+ "FROM " + dao.getTopiaEntityEnum().getImplementationFQN() + " " +
+ "ORDER BY " + Person.PROPERTY_NAME;
+ Iterable<String> allByLazy = dao.findAllLazy(hql, emptyArgs);
+
+ Assert.assertEquals(25, Iterables.size(allByLazy));
+ }
+
+ @Test
+ public void iterateOnTopiaDao() throws TopiaException {
+
createPersons(1999);
List<Person> excepted = dao.findAll();
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java 2014-05-23 08:28:43 UTC (rev 3131)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java 2014-05-23 10:29:45 UTC (rev 3132)
@@ -209,12 +209,17 @@
PaginationParameter firstPage = PaginationParameter.of(0, pageSize);
if (hqlContainsOrderBy(hql)) {
-
// must remove the order by clause, otherwise some sql queries won't work.
hql = hql.substring(0, hql.toLowerCase().indexOf("order by"));
}
+
+ if (hqlStartsWithSelect(hql)) {
+ // must remove the select, otherwise some sql queries won't work.
+ hql = hql.substring(hql.toLowerCase().indexOf("from"));
+ }
+
long count = count("SELECT COUNT(*) " + hql, params);
- List<E> emptyList = Lists.newArrayList(); // XXX AThimel 22/05/14 To keep the old behavior, we do not load the elements. Is it correct ?
+ List<E> emptyList = Lists.newArrayList(); // AThimel 22/05/14 To keep the old behavior, we do not load the elements
PaginationResult<E> result = PaginationResult.of(emptyList, count, firstPage);
return result;
}
@@ -686,6 +691,10 @@
return hql.toLowerCase().contains("order by");
}
+ protected boolean hqlStartsWithSelect(String hql) {
+ return hql.toLowerCase().trim().startsWith("select ");
+ }
+
protected boolean hqlContainsCount(String hql) {
return hql.toLowerCase().contains("count(");
}
@@ -1077,7 +1086,7 @@
@Override
public Iterable<E> findAllLazy() {
- return topiaDAO.findAllLazy(hql +(fromHql?"":" ORDER BY id") , hqlParameters);
+ return topiaDAO.findAllLazy(hql + (fromHql ? "" : " ORDER BY id"), hqlParameters);
}
@Override
1
0
r3131 - in trunk: topia-it/src/test/java/org/nuiton/topia/persistence/internal topia-persistence/src/main/java/org/nuiton/topia/persistence topia-persistence/src/main/java/org/nuiton/topia/persistence/internal topia-persistence/src/test/java/org/nuiton/topia/persistence
by athimel@users.nuiton.org 23 May '14
by athimel@users.nuiton.org 23 May '14
23 May '14
Author: athimel
Date: 2014-05-23 10:28:43 +0200 (Fri, 23 May 2014)
New Revision: 3131
Url: http://forge.nuiton.org/projects/topia/repository/revisions/3131
Log:
refs-80 #3208 Introduce findPage(...) methods
Removed:
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/
Modified:
trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java
Modified: trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java
===================================================================
--- trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java 2014-05-23 07:31:13 UTC (rev 3130)
+++ trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java 2014-05-23 08:28:43 UTC (rev 3131)
@@ -42,6 +42,7 @@
import org.nuiton.topia.persistence.TopiaEntities;
import org.nuiton.topia.persistence.TopiaException;
import org.nuiton.util.pagination.PaginationParameter;
+import org.nuiton.util.pagination.PaginationResult;
import com.google.common.base.Function;
import com.google.common.base.Strings;
@@ -208,9 +209,7 @@
@Test
public void iterateOnEmptyTopiaDAO() throws TopiaException {
- for (Person person : dao) {
- Assert.fail("No person has been created");
- }
+ Assert.assertFalse("No person has been created, hasNext should return false", dao.iterator().hasNext());
}
protected void createPersons(int number) throws TopiaException {
@@ -339,4 +338,78 @@
Assert.assertTrue(intersection.contains("toto07"));
}
+ @Test
+ public void testFindPage() throws TopiaException {
+
+ createPersons(19);
+
+ String hql = dao.newFromClause("p") + " WHERE p." + Person.PROPERTY_NAME + " LIKE 'toto%' ";
+ PaginationResult<Person> page = dao.forHql(hql).findPage(PaginationParameter.of(0, 5));
+
+ Assert.assertEquals(5, page.getElements().size());
+ Assert.assertEquals(0, page.getCurrentPage().getStartIndex());
+ Assert.assertEquals(4, page.getCurrentPage().getEndIndex());
+ Assert.assertEquals(19, page.getCount());
+ Assert.assertEquals(4, page.getPageCount());
+
+ while (page.hasNextPage()) {
+ PaginationParameter nextPage = page.getNextPage();
+ page = dao.forHql(hql).findPage(nextPage);
+
+ if (page.hasNextPage()) {
+ Assert.assertEquals(5, page.getElements().size());
+ } else {
+ // last page only has 4 elements
+ Assert.assertEquals(4, page.getElements().size());
+ }
+ Assert.assertEquals(19, page.getCount());
+ Assert.assertEquals(4, page.getPageCount());
+ }
+ }
+
+ @Test
+ public void testFindPageWithOrder() throws TopiaException {
+
+ createPersons(19);
+
+ String hql = dao.newFromClause("p") + " WHERE p." + Person.PROPERTY_NAME + " LIKE 'toto%' ";
+ PaginationResult<Person> page = dao.forHql(hql).findPage(PaginationParameter.of(0, 7, Person.PROPERTY_NAME, true));
+
+ Assert.assertEquals(7, page.getElements().size());
+ Assert.assertEquals(0, page.getCurrentPage().getStartIndex());
+ Assert.assertEquals(6, page.getCurrentPage().getEndIndex());
+ Assert.assertEquals(19, page.getCount());
+ Assert.assertEquals(3, page.getPageCount());
+
+ Assert.assertEquals("toto18", page.getElements().iterator().next().getName());
+ Assert.assertEquals("toto12", Iterables.getLast(page.getElements()).getName());
+
+ PaginationParameter lastPage = page.getLastPage();
+ page = dao.forHql(hql).findPage(lastPage);
+
+ Assert.assertEquals(5, page.getElements().size());
+ Assert.assertEquals(14, page.getCurrentPage().getStartIndex());
+ Assert.assertEquals(20, page.getCurrentPage().getEndIndex());
+ Assert.assertEquals(19, page.getCount());
+ Assert.assertEquals(3, page.getPageCount());
+ Assert.assertFalse(page.hasNextPage());
+
+ Assert.assertEquals("toto04", page.getElements().iterator().next().getName());
+ Assert.assertEquals("toto00", Iterables.getLast(page.getElements()).getName());
+
+ }
+
+ @Test
+ public void testFindPageNoData() throws TopiaException {
+
+ String hql = dao.newFromClause("p");
+ PaginationResult<Person> page = dao.forHql(hql).findPage(PaginationParameter.of(0, 5));
+
+ Assert.assertEquals(0, page.getElements().size());
+ Assert.assertEquals(0, page.getCount());
+ Assert.assertEquals(0, page.getPageCount());
+ Assert.assertFalse(page.hasNextPage());
+
+ }
+
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java 2014-05-23 07:31:13 UTC (rev 3130)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java 2014-05-23 08:28:43 UTC (rev 3131)
@@ -82,7 +82,9 @@
* @param pageSize size of a page
* @return the initialized pager.
* @since 3.0
+ * @deprecated This method has to be replaced by another clearer method
*/
+ @Deprecated
PaginationResult<E> newPager(int pageSize);
/**
@@ -97,7 +99,9 @@
* @param pageSize size of a page
* @return the initialized pager.
* @since 3.0
+ * @deprecated This method has to be replaced by another clearer method
*/
+ @Deprecated
PaginationResult<E> newPager(String hql, Map<String, Object> params, int pageSize);
/**
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java 2014-05-23 07:31:13 UTC (rev 3130)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java 2014-05-23 08:28:43 UTC (rev 3131)
@@ -27,6 +27,7 @@
import java.util.List;
import org.nuiton.util.pagination.PaginationParameter;
+import org.nuiton.util.pagination.PaginationResult;
import com.google.common.base.Optional;
@@ -121,10 +122,14 @@
List<E> find(PaginationParameter page);
+ PaginationResult<E> findPage(PaginationParameter page);
+
List<String> findAllIds();
List<String> findIds(int startIndex, int endIndex);
List<String> findIds(PaginationParameter page);
+ PaginationResult<String> findIdsPage(PaginationParameter page);
+
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java 2014-05-23 07:31:13 UTC (rev 3130)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java 2014-05-23 08:28:43 UTC (rev 3131)
@@ -946,6 +946,11 @@
}
@Override
+ public PaginationResult<E> findPage(PaginationParameter page) {
+ return getNextStep().findPage(page);
+ }
+
+ @Override
public Iterable<E> findAllLazy() {
return getNextStep().findAllLazy();
}
@@ -971,6 +976,11 @@
}
@Override
+ public PaginationResult<String> findIdsPage(PaginationParameter page) {
+ return getNextStep().findIdsPage(page);
+ }
+
+ @Override
public List<String> findAllIds() {
return getNextStep().findAllIds();
}
@@ -1086,6 +1096,14 @@
}
@Override
+ public PaginationResult<E> findPage(PaginationParameter page) {
+ List<E> elements = find(page);
+ long count = count();
+ PaginationResult<E> result = PaginationResult.of(elements, count, page);
+ return result;
+ }
+
+ @Override
public List<String> findAllIds() {
String hqlWithSelectClause = "select topiaId " + hql;
return topiaDAO.findAll(hqlWithSelectClause, hqlParameters);
@@ -1102,6 +1120,15 @@
String hqlWithSelectClause = "select topiaId " + hql;
return topiaDAO.find(hqlWithSelectClause, hqlParameters, page);
}
+
+ @Override
+ public PaginationResult<String> findIdsPage(PaginationParameter page) {
+ List<String> elements = findIds(page);
+ long count = count();
+ PaginationResult<String> result = PaginationResult.of(elements, count, page);
+ return result;
+ }
+
}
}
1
0
r3130 - in trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence: . internal
by athimel@users.nuiton.org 23 May '14
by athimel@users.nuiton.org 23 May '14
23 May '14
Author: athimel
Date: 2014-05-23 09:31:13 +0200 (Fri, 23 May 2014)
New Revision: 3130
Url: http://forge.nuiton.org/projects/topia/repository/revisions/3130
Log:
refs #3208 fix generic used
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java 2014-05-22 15:24:46 UTC (rev 3129)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java 2014-05-23 07:31:13 UTC (rev 3130)
@@ -83,7 +83,7 @@
* @return the initialized pager.
* @since 3.0
*/
- <K> PaginationResult<K> newPager(int pageSize);
+ PaginationResult<E> newPager(int pageSize);
/**
* Creates a new pager initialized for the first page of data of the given
@@ -98,7 +98,7 @@
* @return the initialized pager.
* @since 3.0
*/
- <K> PaginationResult<K> newPager(String hql, Map<String, Object> params, int pageSize);
+ PaginationResult<E> newPager(String hql, Map<String, Object> params, int pageSize);
/**
* Creates an entity not created without the DAO using any of the others
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java 2014-05-22 15:24:46 UTC (rev 3129)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java 2014-05-23 07:31:13 UTC (rev 3130)
@@ -199,13 +199,13 @@
}
@Override
- public <K> PaginationResult<K> newPager(int pageSize) {
- PaginationResult<K> result = newPager(newFromClause(), null, pageSize);
+ public PaginationResult<E> newPager(int pageSize) {
+ PaginationResult<E> result = newPager(newFromClause(), null, pageSize);
return result;
}
@Override
- public <K> PaginationResult<K> newPager(String hql, Map<String, Object> params, int pageSize) {
+ public PaginationResult<E> newPager(String hql, Map<String, Object> params, int pageSize) {
PaginationParameter firstPage = PaginationParameter.of(0, pageSize);
if (hqlContainsOrderBy(hql)) {
@@ -214,8 +214,8 @@
hql = hql.substring(0, hql.toLowerCase().indexOf("order by"));
}
long count = count("SELECT COUNT(*) " + hql, params);
- List<K> emptyList = Lists.newArrayList(); // XXX AThimel 22/05/14 To keep the old behavior, we do not load the elements. Is it correct ?
- PaginationResult<K> result = PaginationResult.of(emptyList, count, firstPage);
+ List<E> emptyList = Lists.newArrayList(); // XXX AThimel 22/05/14 To keep the old behavior, we do not load the elements. Is it correct ?
+ PaginationResult<E> result = PaginationResult.of(emptyList, count, firstPage);
return result;
}
@@ -716,7 +716,7 @@
protected final Map<String, Object> params;
- protected PaginationResult<K> pager;
+ protected PaginationResult<E> pager;
protected boolean firstPageLoaded;
1
0
r3129 - trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal
by athimel@users.nuiton.org 22 May '14
by athimel@users.nuiton.org 22 May '14
22 May '14
Author: athimel
Date: 2014-05-22 17:24:46 +0200 (Thu, 22 May 2014)
New Revision: 3129
Url: http://forge.nuiton.org/projects/topia/repository/revisions/3129
Log:
refs #3208 Add tests on PaginationParameter interpretation by ToPIA
Modified:
trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java
Modified: trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java
===================================================================
--- trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java 2014-05-22 14:53:11 UTC (rev 3128)
+++ trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java 2014-05-22 15:24:46 UTC (rev 3129)
@@ -24,8 +24,10 @@
* #L%
*/
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
@@ -36,12 +38,17 @@
import org.nuiton.topia.it.legacy.TopiaItLegacyTopiaPersistenceContext;
import org.nuiton.topia.it.legacy.test.entities.Person;
import org.nuiton.topia.it.legacy.test.entities.PersonTopiaDao;
+import org.nuiton.topia.persistence.TopiaDao;
+import org.nuiton.topia.persistence.TopiaEntities;
+import org.nuiton.topia.persistence.TopiaException;
+import org.nuiton.util.pagination.PaginationParameter;
+import com.google.common.base.Function;
import com.google.common.base.Strings;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import org.nuiton.topia.persistence.TopiaDao;
-import org.nuiton.topia.persistence.TopiaException;
+import com.google.common.collect.Sets;
/**
* Test on {@link TopiaDao}.
@@ -103,7 +110,7 @@
createPersons(1);
- Iterable<Person> persons = dao.forNameEquals("toto0").findAllLazy();
+ Iterable<Person> persons = dao.forNameEquals("toto00").findAllLazy();
Assert.assertTrue(persons.iterator().hasNext());
}
@@ -208,7 +215,8 @@
protected void createPersons(int number) throws TopiaException {
for (int i = 0; i < number; i++) {
- createPerson("toto" + i);
+ String name = "toto" + Strings.padStart(String.valueOf(i), 2, '0');
+ createPerson(name);
}
context.commit();
@@ -232,4 +240,103 @@
Assert.assertTrue(!Strings.isNullOrEmpty(person.getTopiaId()));
}
+ @Test
+ public void testFindUsingPagination() throws TopiaException {
+
+ createPersons(17);
+
+ List<Person> excepted = dao.findAll();
+ Assert.assertEquals(17, excepted.size());
+
+ {
+ PaginationParameter page = PaginationParameter.of(0, -1);
+ List<Person> list = dao.find(dao.newFromClause(), new HashMap<String, Object>(), page);
+ Assert.assertEquals(17, list.size());
+ }
+
+ Set<String> alreadyLoaded = Sets.newHashSet();
+ {
+ PaginationParameter page = PaginationParameter.of(0, 6);
+ List<Person> list = dao.find(dao.newFromClause(), new HashMap<String, Object>(), page);
+ Assert.assertEquals(6, list.size());
+
+ // Now make sure that a same entity is not in several pages
+ Set<String> newlyLoaded = Sets.newHashSet(Iterables.transform(list, TopiaEntities.getTopiaIdFunction()));
+ Assert.assertTrue(Sets.intersection(alreadyLoaded, newlyLoaded).isEmpty());
+ alreadyLoaded.addAll(newlyLoaded);
+ }
+
+ {
+ PaginationParameter page = PaginationParameter.of(1, 6);
+ List<Person> list = dao.find(dao.newFromClause(), new HashMap<String, Object>(), page);
+ Assert.assertEquals(6, list.size());
+
+ // Now make sure that a same entity is not in several pages
+ Set<String> newlyLoaded = Sets.newHashSet(Iterables.transform(list, TopiaEntities.getTopiaIdFunction()));
+ Assert.assertTrue(Sets.intersection(alreadyLoaded, newlyLoaded).isEmpty());
+ alreadyLoaded.addAll(newlyLoaded);
+ }
+
+ {
+ PaginationParameter page = PaginationParameter.of(2, 6);
+ List<Person> list = dao.find(dao.newFromClause(), new HashMap<String, Object>(), page);
+ Assert.assertEquals(5, list.size());
+
+ // Now make sure that a same entity is not in several pages
+ Set<String> newlyLoaded = Sets.newHashSet(Iterables.transform(list, TopiaEntities.getTopiaIdFunction()));
+ Assert.assertTrue(Sets.intersection(alreadyLoaded, newlyLoaded).isEmpty());
+ alreadyLoaded.addAll(newlyLoaded);
+ }
+
+ Assert.assertEquals(17, alreadyLoaded.size());
+
+ }
+
+ @Test
+ public void testFindUsingPaginationOrderClauses() throws TopiaException {
+
+ createPersons(15);
+
+ List<Person> excepted = dao.findAll();
+ Assert.assertEquals(15, excepted.size());
+
+ Set<String> setAsc = Sets.newHashSet();
+ Set<String> setDesc = Sets.newHashSet();
+
+ Function<Person, String> getNameFunction = new Function<Person, String>() {
+ @Override
+ public String apply(Person input) {
+ return input.getName();
+ }
+ };
+
+ {
+ PaginationParameter page = PaginationParameter.of(0, 8, Person.PROPERTY_NAME, false);
+ List<Person> list = dao.find(dao.newFromClause(), new HashMap<String, Object>(), page);
+ Assert.assertEquals(8, list.size());
+
+ Set<String> newlyLoaded = Sets.newHashSet(Iterables.transform(list, getNameFunction));
+ setAsc.addAll(newlyLoaded);
+ }
+
+ {
+ PaginationParameter page = PaginationParameter.of(0, 8, Person.PROPERTY_NAME, true);
+ List<Person> list = dao.find(dao.newFromClause(), new HashMap<String, Object>(), page);
+ Assert.assertEquals(8, list.size());
+
+ Set<String> newlyLoaded = Sets.newHashSet(Iterables.transform(list, getNameFunction));
+ setDesc.addAll(newlyLoaded);
+ }
+
+ Sets.SetView<String> intersection = Sets.intersection(setAsc, setDesc);
+
+ // Sorting a list of 15 elements asc and desc by 8-elements pages, intersection will be the middle one (toto7)
+ // <---------ASC-page-0----------><-------ASC-page-1---------->
+ // 00 01 02 03 04 05 06 |7| 8 9 10 11 12 13 14
+ // <---------DESC-page-1--------><--------DESC-page-0-------->
+
+ Assert.assertEquals(1, intersection.size());
+ Assert.assertTrue(intersection.contains("toto07"));
+ }
+
}
1
0
r3128 - in trunk: topia-it/src/test/java/org/nuiton/topia/persistence/internal topia-persistence/src/main/java/org/nuiton/topia/persistence topia-persistence/src/main/java/org/nuiton/topia/persistence/internal
by athimel@users.nuiton.org 22 May '14
by athimel@users.nuiton.org 22 May '14
22 May '14
Author: athimel
Date: 2014-05-22 16:53:11 +0200 (Thu, 22 May 2014)
New Revision: 3128
Url: http://forge.nuiton.org/projects/topia/repository/revisions/3128
Log:
refs-50 #3208 use nuiton-utils refactored pagination classes
Modified:
trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java
Modified: trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java
===================================================================
--- trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java 2014-05-22 08:43:16 UTC (rev 3127)
+++ trunk/topia-it/src/test/java/org/nuiton/topia/persistence/internal/TopiaDaoTest.java 2014-05-22 14:53:11 UTC (rev 3128)
@@ -199,6 +199,13 @@
}
+ @Test
+ public void iterateOnEmptyTopiaDAO() throws TopiaException {
+ for (Person person : dao) {
+ Assert.fail("No person has been created");
+ }
+ }
+
protected void createPersons(int number) throws TopiaException {
for (int i = 0; i < number; i++) {
createPerson("toto" + i);
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java 2014-05-22 08:43:16 UTC (rev 3127)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDao.java 2014-05-22 14:53:11 UTC (rev 3128)
@@ -27,7 +27,7 @@
import com.google.common.base.Optional;
import org.nuiton.topia.persistence.event.TopiaEntityListener;
import org.nuiton.topia.persistence.event.TopiaEntityVetoable;
-import org.nuiton.topia.persistence.pager.TopiaPagerBean;
+import org.nuiton.util.pagination.PaginationResult;
import java.util.Collection;
import java.util.List;
@@ -83,7 +83,7 @@
* @return the initialized pager.
* @since 3.0
*/
- TopiaPagerBean newPager(int pageSize);
+ <K> PaginationResult<K> newPager(int pageSize);
/**
* Creates a new pager initialized for the first page of data of the given
@@ -98,7 +98,7 @@
* @return the initialized pager.
* @since 3.0
*/
- TopiaPagerBean newPager(String hql, Map<String, Object> params, int pageSize);
+ <K> PaginationResult<K> newPager(String hql, Map<String, Object> params, int pageSize);
/**
* Creates an entity not created without the DAO using any of the others
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java 2014-05-22 08:43:16 UTC (rev 3127)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaQueryBuilderRunQueryStep.java 2014-05-22 14:53:11 UTC (rev 3128)
@@ -26,7 +26,7 @@
import java.util.List;
-import org.nuiton.topia.persistence.pager.TopiaPagerBean;
+import org.nuiton.util.pagination.PaginationParameter;
import com.google.common.base.Optional;
@@ -119,12 +119,12 @@
List<E> find(int startIndex, int endIndex);
- List<E> find(TopiaPagerBean pager);
+ List<E> find(PaginationParameter page);
List<String> findAllIds();
List<String> findIds(int startIndex, int endIndex);
- List<String> findIds(TopiaPagerBean pager);
+ List<String> findIds(PaginationParameter page);
}
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java 2014-05-22 08:43:16 UTC (rev 3127)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaDao.java 2014-05-22 14:53:11 UTC (rev 3128)
@@ -24,10 +24,14 @@
* #L%
*/
+import com.google.common.base.Function;
+import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
+import com.google.common.collect.Lists;
+
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
@@ -55,8 +59,9 @@
import org.nuiton.topia.persistence.event.TopiaEntityVetoable;
import org.nuiton.topia.persistence.internal.support.TopiaFiresSupport;
import org.nuiton.topia.persistence.util.TopiaUtil;
-import org.nuiton.topia.persistence.pager.TopiaPagerBean;
-import org.nuiton.util.PagerBeanUtil;
+import org.nuiton.util.pagination.PaginationOrder;
+import org.nuiton.util.pagination.PaginationParameter;
+import org.nuiton.util.pagination.PaginationResult;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
@@ -85,6 +90,15 @@
private static Log log = LogFactory.getLog(AbstractTopiaDao.class);
+
+ protected static final Function<PaginationOrder, String> PAGINATION_ORDER_TO_HQL = new Function<PaginationOrder, String>() {
+ @Override
+ public String apply(PaginationOrder input) {
+ String result = String.format("%s %s", input.getClause(), input.isDesc() ? "DESC" : "ASC");
+ return result;
+ }
+ };
+
/**
* Default batch size used to iterate on data.
*
@@ -185,14 +199,14 @@
}
@Override
- public TopiaPagerBean newPager(int pageSize) {
- TopiaPagerBean pager = newPager(newFromClause(), null, pageSize);
- return pager;
+ public <K> PaginationResult<K> newPager(int pageSize) {
+ PaginationResult<K> result = newPager(newFromClause(), null, pageSize);
+ return result;
}
@Override
- public TopiaPagerBean newPager(String hql, Map<String, Object> params, int pageSize) {
- TopiaPagerBean pager = new TopiaPagerBean();
+ public <K> PaginationResult<K> newPager(String hql, Map<String, Object> params, int pageSize) {
+ PaginationParameter firstPage = PaginationParameter.of(0, pageSize);
if (hqlContainsOrderBy(hql)) {
@@ -200,10 +214,9 @@
hql = hql.substring(0, hql.toLowerCase().indexOf("order by"));
}
long count = count("SELECT COUNT(*) " + hql, params);
- pager.setRecords(count);
- pager.setPageSize(pageSize);
- PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager);
- return pager;
+ List<K> emptyList = Lists.newArrayList(); // XXX AThimel 22/05/14 To keep the old behavior, we do not load the elements. Is it correct ?
+ PaginationResult<K> result = PaginationResult.of(emptyList, count, firstPage);
+ return result;
}
@Override
@@ -537,28 +550,27 @@
return result;
}
- protected <K> List<K> find(String hql, Map<String, Object> hqlParameters, TopiaPagerBean pager) {
+ protected <K> List<K> find(String hql, Map<String, Object> hqlParameters, PaginationParameter page) {
Preconditions.checkNotNull(hql);
Preconditions.checkNotNull(hqlParameters);
- Preconditions.checkNotNull(pager);
+ Preconditions.checkNotNull(page);
- if (StringUtils.isNotBlank(pager.getSortColumn())) {
+ if (!page.getOrderClauses().isEmpty()) {
// can't have a order by clause in hql query
Preconditions.checkState(
!hqlContainsOrderBy(hql),
"An 'order by' clause was already found in hql, can't use the order of the pager");
- hql += " order by " + pager.getSortColumn();
- if (!pager.isSortAscendant()) {
- hql += " desc";
- }
+ hql += " ORDER BY ";
+ Iterable<String> orderClauses = Iterables.transform(page.getOrderClauses(), PAGINATION_ORDER_TO_HQL);
+ hql += Joiner.on(", ").join(orderClauses);
}
List<K> result = topiaJpaSupport.find(
hql,
- (int) pager.getRecordStartIndex(),
- (int) pager.getRecordEndIndex() - 1,
+ (int) page.getStartIndex(),
+ (int) page.getEndIndex(),
hqlParameters);
return result;
@@ -652,7 +664,7 @@
@Override
public Iterable<E> findAllLazy() {
- String hql = "from " + getTopiaEntityEnum().getImplementationFQN() + " order by id";
+ String hql = " FROM " + getTopiaEntityEnum().getImplementationFQN() + " ORDER BY id ";
Map<String, Object> hqlParameters = Collections.emptyMap();
Iterable<E> result = findAllLazy(hql, hqlParameters);
return result;
@@ -704,8 +716,10 @@
protected final Map<String, Object> params;
- protected final TopiaPagerBean pager;
+ protected PaginationResult<K> pager;
+ protected boolean firstPageLoaded;
+
public FindAllIterator(AbstractTopiaDao<E> dao,
int batchSize,
String hql,
@@ -722,16 +736,16 @@
// empty iterator (will be changed at first next call)
data = Iterators.emptyIterator();
+ firstPageLoaded = false;
}
-
public boolean hasNext() {
boolean result = data.hasNext() || // no more data
- pager.getPageIndex() < pager.getPagesNumber();
+ (!firstPageLoaded && pager.getCount() > 0) || // first page not yet loaded and there is data to load
+ (firstPageLoaded && pager.hasNextPage()); // the first page has been loaded and there is another page
return result;
}
-
public K next() {
if (!hasNext()) {
throw new NoSuchElementException();
@@ -741,14 +755,21 @@
// must load iterator
- // increments page index
- pager.setPageIndex(pager.getPageIndex() + 1);
- PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager);
+ PaginationParameter pageToLoad;
+ if (firstPageLoaded) {
+ pageToLoad = pager.getNextPage();
+ } else {
+ pageToLoad = pager.getCurrentPage();
+ firstPageLoaded = true;
+ }
// load new window of data
- List<K> values = dao.find(hql, params, pager);
+ List<K> values = dao.find(hql, params, pageToLoad);
data = values.iterator();
+ // Create a new pager on the next page
+ pager = PaginationResult.of(pager.getElements(), pager.getCount(), pageToLoad);
+
}
K next = data.next();
@@ -920,8 +941,8 @@
}
@Override
- public List<E> find(TopiaPagerBean pager) {
- return getNextStep().find(pager);
+ public List<E> find(PaginationParameter page) {
+ return getNextStep().find(page);
}
@Override
@@ -945,8 +966,8 @@
}
@Override
- public List<String> findIds(TopiaPagerBean pager) {
- return getNextStep().findIds(pager);
+ public List<String> findIds(PaginationParameter page) {
+ return getNextStep().findIds(page);
}
@Override
@@ -1060,8 +1081,8 @@
}
@Override
- public List<E> find(TopiaPagerBean pager) {
- return topiaDAO.find(hql, hqlParameters, pager);
+ public List<E> find(PaginationParameter page) {
+ return topiaDAO.find(hql, hqlParameters, page);
}
@Override
@@ -1077,9 +1098,9 @@
}
@Override
- public List<String> findIds(TopiaPagerBean pager) {
+ public List<String> findIds(PaginationParameter page) {
String hqlWithSelectClause = "select topiaId " + hql;
- return topiaDAO.find(hqlWithSelectClause, hqlParameters, pager);
+ return topiaDAO.find(hqlWithSelectClause, hqlParameters, page);
}
}
1
0
r3127 - in trunk: . topia-persistence/src/main/java/org/nuiton/topia/persistence/pager topia-persistence/src/test/java/org/nuiton/topia/persistence/pager
by athimel@users.nuiton.org 22 May '14
by athimel@users.nuiton.org 22 May '14
22 May '14
Author: athimel
Date: 2014-05-22 10:43:16 +0200 (Thu, 22 May 2014)
New Revision: 3127
Url: http://forge.nuiton.org/projects/topia/repository/revisions/3127
Log:
refs #3208 Pagination* classes moved to nuiton-utils
Removed:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationOrder.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationParameter.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationResult.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationParameterTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationResultTest.java
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-05-21 22:10:11 UTC (rev 3126)
+++ trunk/pom.xml 2014-05-22 08:43:16 UTC (rev 3127)
@@ -240,7 +240,7 @@
<!-- libs version -->
<eugeneVersion>2.9</eugeneVersion>
- <nuitonUtilsVersion>3.0-rc-2</nuitonUtilsVersion>
+ <nuitonUtilsVersion>3.0-SNAPSHOT</nuitonUtilsVersion>
<nuitonCsvVersion>3.0-rc-1</nuitonCsvVersion>
<nuitonDecoratorVersion>3.0-alpha-3</nuitonDecoratorVersion>
<nuitonI18nVersion>3.0</nuitonI18nVersion>
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationOrder.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationOrder.java 2014-05-21 22:10:11 UTC (rev 3126)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationOrder.java 2014-05-22 08:43:16 UTC (rev 3127)
@@ -1,63 +0,0 @@
-package org.nuiton.topia.persistence.pager;
-
-/*
- * #%L
- * ToPIA :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2014 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-import java.io.Serializable;
-
-/**
- * This class represents an 'order' information : order clause and asc/desc
- *
- * @author Arnaud Thimel (Code Lutin)
- * @since 3.0
- */
-public class PaginationOrder implements Serializable {
-
- private static final long serialVersionUID = -1222944258030026951L;
-
- protected String clause;
- protected boolean desc;
-
- public PaginationOrder(String clause, boolean desc) {
- this.clause = clause;
- this.desc = desc;
- }
-
- public String getClause() {
- return clause;
- }
-
- public void setClause(String clause) {
- this.clause = clause;
- }
-
- public boolean isDesc() {
- return desc;
- }
-
- public void setDesc(boolean desc) {
- this.desc = desc;
- }
-
-}
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationParameter.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationParameter.java 2014-05-21 22:10:11 UTC (rev 3126)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationParameter.java 2014-05-22 08:43:16 UTC (rev 3127)
@@ -1,182 +0,0 @@
-package org.nuiton.topia.persistence.pager;
-
-/*
- * #%L
- * ToPIA :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2014 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-import java.io.Serializable;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-/**
- * This class represents the necessary information to do pagination (page number, size, ...).
- *
- * @author Arnaud Thimel (Code Lutin)
- * @since 3.0
- */
-public class PaginationParameter implements Serializable {
-
- private static final long serialVersionUID = -2564463476779099397L;
-
- protected int pageNumber;
- protected int pageSize;
- protected List<PaginationOrder> orderClauses;
-
- private PaginationParameter(int pageNumber, int pageSize) {
- this(pageNumber, pageSize, new LinkedList<PaginationOrder>());
- }
-
- private PaginationParameter(int pageNumber, int pageSize, List<PaginationOrder> orderClauses) {
- this.pageNumber = pageNumber;
- this.pageSize = pageSize;
- this.orderClauses = Collections.unmodifiableList(orderClauses);
- }
-
- public static PaginationParameter of(int pageNumber, int pageSize) {
- PaginationParameter result = new PaginationParameter(pageNumber, pageSize);
- return result;
- }
-
- public static PaginationParameter of(int pageNumber, int pageSize,
- String orderClause1, boolean orderDesc1) {
- return builder(pageNumber, pageSize)
- .addOrder(orderClause1, orderDesc1)
- .build();
- }
-
- public static PaginationParameter of(int pageNumber, int pageSize,
- String orderClause1, boolean orderDesc1,
- String orderClause2, boolean orderDesc2) {
- return builder(pageNumber, pageSize)
- .addOrder(orderClause1, orderDesc1)
- .addOrder(orderClause2, orderDesc2)
- .build();
- }
-
- public static PaginationParameter of(int pageNumber, int pageSize,
- String orderClause1, boolean orderDesc1,
- String orderClause2, boolean orderDesc2,
- String orderClause3, boolean orderDesc3) {
- return builder(pageNumber, pageSize)
- .addOrder(orderClause1, orderDesc1)
- .addOrder(orderClause2, orderDesc2)
- .addOrder(orderClause3, orderDesc3)
- .build();
- }
-
- public static PaginationParameter.Builder builder(int pageNumber, int pageSize) {
- Builder result = new Builder(pageNumber, pageSize);
- return result;
- }
-
- public int getPageNumber() {
- return pageNumber;
- }
-
- public int getPageSize() {
- return pageSize;
- }
-
- public List<PaginationOrder> getOrderClauses() {
- return orderClauses;
- }
-
- public int getStartIndex() {
- if (pageNumber != 0) {
- Preconditions.checkState(pageSize != -1, "This is non-sense to have pageNumber>1 if pageSize==-1");
- }
- int startIndex = pageNumber * pageSize;
- return startIndex;
- }
-
- public int getEndIndex() {
- int endIndex = Integer.MAX_VALUE;
- if (pageSize != -1) {
- endIndex = getStartIndex() + pageSize - 1;
- }
- return endIndex;
- }
-
- /**
- * Class used to build an instance of PaginationParameter
- */
- public static class Builder {
-
- protected int pageNumber;
- protected int pageSize;
- protected List<PaginationOrder> orderClauses;
-
- public Builder(int pageNumber, int pageSize) {
- this.pageNumber = pageNumber;
- this.pageSize = pageSize;
- }
-
- public Builder addOrder(String clause, boolean desc) {
- if (orderClauses == null) {
- orderClauses = Lists.newLinkedList();
- }
- PaginationOrder paginationOrder = new PaginationOrder(clause, desc);
- orderClauses.add(paginationOrder);
- return this;
- }
-
- public Builder addAscOrder(String clause) {
- return addOrder(clause, false);
- }
-
- public Builder addDescOrder(String clause) {
- return addOrder(clause, true);
- }
-
- public Builder addOrder(String clause) {
- boolean desc = false;
- String cleanedClause = clause;
- int spaceIndex = clause.indexOf(' ');
- if (spaceIndex != -1) {
- cleanedClause = clause.substring(0, spaceIndex).trim();
- desc = "desc".equalsIgnoreCase(clause.substring(spaceIndex + 1).trim());
- }
- return addOrder(cleanedClause, desc);
- }
-
- public Builder addOrderClauses(Iterable<PaginationOrder> clauses) {
- if (orderClauses == null) {
- orderClauses = Lists.newLinkedList();
- }
- if (clauses != null) {
- Iterables.addAll(orderClauses, clauses);
- }
- return this;
- }
-
- public PaginationParameter build() {
- PaginationParameter result = new PaginationParameter(pageNumber, pageSize, orderClauses);
- return result;
- }
- }
-}
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationResult.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationResult.java 2014-05-21 22:10:11 UTC (rev 3126)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationResult.java 2014-05-22 08:43:16 UTC (rev 3127)
@@ -1,127 +0,0 @@
-package org.nuiton.topia.persistence.pager;
-
-/*
- * #%L
- * ToPIA :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2014 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-import java.io.Serializable;
-import java.util.List;
-
-import com.google.common.base.Preconditions;
-
-/**
- * Represents the result of a pagination request. It contains the result elements together with the
- * {code}PaginationParameter{/code} used to compute it.
- *
- * @author Arnaud Thimel (Code Lutin)
- * @since 3.0
- */
-public class PaginationResult<K> implements Serializable {
-
- private static final long serialVersionUID = -8794603203860852003L;
-
- protected List<K> elements;
- protected long count;
- protected PaginationParameter currentPage;
-
- private PaginationResult(List<K> elements, long count, PaginationParameter currentPage) {
- this.elements = elements;
- this.count = count;
- this.currentPage = currentPage;
- }
-
- public static <E> PaginationResult<E> of(List<E> elements, long count, PaginationParameter currentPage) {
- PaginationResult<E> result = new PaginationResult<E>(elements, count, currentPage);
- return result;
- }
-
- public List<K> getElements() {
- return elements;
- }
-
- public long getCount() {
- return count;
- }
-
- public PaginationParameter getCurrentPage() {
- return currentPage;
- }
-
- public PaginationParameter getNextPage() {
- int nextPageNumber = currentPage.getPageNumber() + 1;
- int pageSize = currentPage.getPageSize();
- List<PaginationOrder> orderClauses = currentPage.getOrderClauses();
- PaginationParameter result = PaginationParameter.
- builder(nextPageNumber, pageSize).
- addOrderClauses(orderClauses).
- build();
- return result;
- }
-
- public PaginationParameter getPreviousPage() {
- // XXX AThimel 21/05/14 Maybe, do not fail, just return the first page ?
- Preconditions.checkState(currentPage.getPageNumber() > 0, "You cannot get a previous page to the first one");
- int previousPageNumber = currentPage.getPageNumber() - 1;
- int pageSize = currentPage.getPageSize();
- List<PaginationOrder> orderClauses = currentPage.getOrderClauses();
- PaginationParameter result = PaginationParameter.
- builder(previousPageNumber, pageSize).
- addOrderClauses(orderClauses).
- build();
- return result;
- }
-
- public PaginationParameter getFirstPage() {
- int firstPageNumber = 0;
- int pageSize = currentPage.getPageSize();
- List<PaginationOrder> orderClauses = currentPage.getOrderClauses();
- PaginationParameter result = PaginationParameter.
- builder(firstPageNumber, pageSize).
- addOrderClauses(orderClauses).
- build();
- return result;
- }
-
- public PaginationParameter getLastPage() {
- int lastPageNumber = getPageCount() - 1;
- int pageSize = currentPage.getPageSize();
- List<PaginationOrder> orderClauses = currentPage.getOrderClauses();
- PaginationParameter result = PaginationParameter.
- builder(lastPageNumber, pageSize).
- addOrderClauses(orderClauses).
- build();
- return result;
- }
-
- public int getPageCount() {
- int pageCount = 1;
- int pageSize = currentPage.getPageSize();
- if (pageSize > 1) {
- double countDouble = Long.valueOf(count).doubleValue();
- double pageSizeDouble = Integer.valueOf(pageSize).doubleValue();
- double pageNumberDouble = Math.ceil(countDouble / pageSizeDouble);
- pageCount = Double.valueOf(pageNumberDouble).intValue();
- }
- return pageCount;
- }
-}
Deleted: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationParameterTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationParameterTest.java 2014-05-21 22:10:11 UTC (rev 3126)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationParameterTest.java 2014-05-22 08:43:16 UTC (rev 3127)
@@ -1,75 +0,0 @@
-package org.nuiton.topia.persistence.pager;
-
-/*
- * #%L
- * ToPIA :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2014 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * @author Arnaud Thimel (Code Lutin)
- */
-public class PaginationParameterTest {
-
- @Test
- public void testIndexes() {
- {
- PaginationParameter paginationParameter = PaginationParameter.of(0, 50);
- Assert.assertEquals(0, paginationParameter.getStartIndex());
- Assert.assertEquals(49, paginationParameter.getEndIndex());
- }
- {
- PaginationParameter paginationParameter = PaginationParameter.of(2, 50);
- Assert.assertEquals(100, paginationParameter.getStartIndex());
- Assert.assertEquals(149, paginationParameter.getEndIndex());
- }
- {
- PaginationParameter paginationParameter = PaginationParameter.of(0, -1);
- Assert.assertEquals(0, paginationParameter.getStartIndex());
- Assert.assertEquals(Integer.MAX_VALUE, paginationParameter.getEndIndex());
- }
- {
- PaginationParameter paginationParameter = PaginationParameter.of(0, 19);
- Assert.assertEquals(0, paginationParameter.getStartIndex());
- Assert.assertEquals(18, paginationParameter.getEndIndex());
- }
- {
- PaginationParameter paginationParameter = PaginationParameter.of(1, 19);
- Assert.assertEquals(19, paginationParameter.getStartIndex());
- Assert.assertEquals(37, paginationParameter.getEndIndex());
- }
- {
- PaginationParameter paginationParameter = PaginationParameter.of(2, 19);
- Assert.assertEquals(38, paginationParameter.getStartIndex());
- Assert.assertEquals(56, paginationParameter.getEndIndex());
- }
- }
-
- @Test(expected = IllegalStateException.class)
- public void testInvalidIndex() {
- PaginationParameter paginationParameter = PaginationParameter.of(2, -1);
- paginationParameter.getStartIndex();
- }
-
-}
Deleted: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationResultTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationResultTest.java 2014-05-21 22:10:11 UTC (rev 3126)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationResultTest.java 2014-05-22 08:43:16 UTC (rev 3127)
@@ -1,90 +0,0 @@
-package org.nuiton.topia.persistence.pager;
-
-/*
- * #%L
- * ToPIA :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2014 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-import java.util.List;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.common.collect.Lists;
-
-/**
- * @author Arnaud Thimel (Code Lutin)
- */
-public class PaginationResultTest {
-
- protected PaginationResult<Object> paginationResult;
-
- @Before
- public void init() {
- List<Object> elements = Lists.newArrayList();
- PaginationParameter page = PaginationParameter.of(2, 50);
- paginationResult = PaginationResult.of(elements, 204, page);
- }
-
- @Test
- public void testGetFirstPage() {
- Assert.assertEquals(0, paginationResult.getFirstPage().getPageNumber());
- Assert.assertEquals(50, paginationResult.getFirstPage().getPageSize());
- Assert.assertEquals(0, paginationResult.getFirstPage().getStartIndex());
- Assert.assertEquals(49, paginationResult.getFirstPage().getEndIndex());
- }
-
- @Test
- public void testGetPreviousPage() {
- Assert.assertEquals(1, paginationResult.getPreviousPage().getPageNumber());
- Assert.assertEquals(50, paginationResult.getPreviousPage().getPageSize());
- Assert.assertEquals(50, paginationResult.getPreviousPage().getStartIndex());
- Assert.assertEquals(99, paginationResult.getPreviousPage().getEndIndex());
- }
-
- @Test
- public void testCurrentPage() {
- Assert.assertEquals(5, paginationResult.getPageCount());
- Assert.assertEquals(2, paginationResult.getCurrentPage().getPageNumber());
- Assert.assertEquals(50, paginationResult.getCurrentPage().getPageSize());
- Assert.assertEquals(100, paginationResult.getCurrentPage().getStartIndex());
- Assert.assertEquals(149, paginationResult.getCurrentPage().getEndIndex());
- }
-
- @Test
- public void testGeNextPage() {
- Assert.assertEquals(3, paginationResult.getNextPage().getPageNumber());
- Assert.assertEquals(50, paginationResult.getNextPage().getPageSize());
- Assert.assertEquals(150, paginationResult.getNextPage().getStartIndex());
- Assert.assertEquals(199, paginationResult.getNextPage().getEndIndex());
- }
-
- @Test
- public void testGetLastPage() {
- Assert.assertEquals(4, paginationResult.getLastPage().getPageNumber());
- Assert.assertEquals(50, paginationResult.getLastPage().getPageSize());
- Assert.assertEquals(200, paginationResult.getLastPage().getStartIndex());
- Assert.assertEquals(249, paginationResult.getLastPage().getEndIndex());
- }
-
-}
1
0
r3125 - in trunk/topia-persistence/src: main/java/org/nuiton/topia/persistence/pager test/java/org/nuiton/topia/persistence test/java/org/nuiton/topia/persistence/pager
by athimel@users.nuiton.org 22 May '14
by athimel@users.nuiton.org 22 May '14
22 May '14
Author: athimel
Date: 2014-05-21 23:56:15 +0200 (Wed, 21 May 2014)
New Revision: 3125
Url: http://forge.nuiton.org/projects/topia/repository/revisions/3125
Log:
refs #3208 Introduce new pagination classes
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationOrder.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationParameter.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationResult.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationParameterTest.java
trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationResultTest.java
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationOrder.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationOrder.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationOrder.java 2014-05-21 21:56:15 UTC (rev 3125)
@@ -0,0 +1,63 @@
+package org.nuiton.topia.persistence.pager;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2014 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import java.io.Serializable;
+
+/**
+ * This class represents an 'order' information : order clause and asc/desc
+ *
+ * @author Arnaud Thimel (Code Lutin)
+ * @since 3.0
+ */
+public class PaginationOrder implements Serializable {
+
+ private static final long serialVersionUID = -1222944258030026951L;
+
+ protected String clause;
+ protected boolean desc;
+
+ public PaginationOrder(String clause, boolean desc) {
+ this.clause = clause;
+ this.desc = desc;
+ }
+
+ public String getClause() {
+ return clause;
+ }
+
+ public void setClause(String clause) {
+ this.clause = clause;
+ }
+
+ public boolean isDesc() {
+ return desc;
+ }
+
+ public void setDesc(boolean desc) {
+ this.desc = desc;
+ }
+
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationOrder.java
___________________________________________________________________
Added: svn:eol-style
+ native
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationParameter.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationParameter.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationParameter.java 2014-05-21 21:56:15 UTC (rev 3125)
@@ -0,0 +1,185 @@
+package org.nuiton.topia.persistence.pager;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2014 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
+/**
+ * This class represents the necessary information to do pagination (page number, size, ...).
+ *
+ * @author Arnaud Thimel (Code Lutin)
+ * @since 3.0
+ */
+public class PaginationParameter implements Serializable {
+
+ private static final long serialVersionUID = -2564463476779099397L;
+
+ protected int pageNumber;
+ protected int pageSize;
+ protected List<PaginationOrder> orderClauses;
+
+ private PaginationParameter(int pageNumber, int pageSize) {
+ this(pageNumber, pageSize, new ArrayList<PaginationOrder>());
+ }
+
+ private PaginationParameter(int pageNumber, int pageSize, List<PaginationOrder> orderClauses) {
+ this.pageNumber = pageNumber;
+ this.pageSize = pageSize;
+ this.orderClauses = Collections.unmodifiableList(orderClauses);
+ }
+
+ public static PaginationParameter of(int pageNumber, int pageSize) {
+ PaginationParameter result = new PaginationParameter(pageNumber, pageSize);
+ return result;
+ }
+
+ public static PaginationParameter of(int pageNumber, int pageSize,
+ String orderClause1, boolean orderDesc1) {
+ List<PaginationOrder> orderClauses = Lists.newArrayListWithCapacity(3);
+ orderClauses.add(new PaginationOrder(orderClause1, orderDesc1));
+ PaginationParameter result = new PaginationParameter(pageNumber, pageSize, orderClauses);
+ return result;
+ }
+
+ public static PaginationParameter of(int pageNumber, int pageSize,
+ String orderClause1, boolean orderDesc1,
+ String orderClause2, boolean orderDesc2) {
+ List<PaginationOrder> orderClauses = Lists.newArrayListWithCapacity(3);
+ orderClauses.add(new PaginationOrder(orderClause1, orderDesc1));
+ orderClauses.add(new PaginationOrder(orderClause2, orderDesc2));
+ PaginationParameter result = new PaginationParameter(pageNumber, pageSize, orderClauses);
+ return result;
+ }
+
+ public static PaginationParameter of(int pageNumber, int pageSize,
+ String orderClause1, boolean orderDesc1,
+ String orderClause2, boolean orderDesc2,
+ String orderClause3, boolean orderDesc3) {
+ List<PaginationOrder> orderClauses = Lists.newArrayListWithCapacity(3);
+ orderClauses.add(new PaginationOrder(orderClause1, orderDesc1));
+ orderClauses.add(new PaginationOrder(orderClause2, orderDesc2));
+ orderClauses.add(new PaginationOrder(orderClause3, orderDesc3));
+ PaginationParameter result = new PaginationParameter(pageNumber, pageSize, orderClauses);
+ return result;
+ }
+
+ public static PaginationParameter.Builder builder(int pageNumber, int pageSize) {
+ Builder result = new Builder(pageNumber, pageSize);
+ return result;
+ }
+
+ public int getPageNumber() {
+ return pageNumber;
+ }
+
+ public int getPageSize() {
+ return pageSize;
+ }
+
+ public List<PaginationOrder> getOrderClauses() {
+ return orderClauses;
+ }
+
+ public int getStartIndex() {
+ if (pageNumber != 0) {
+ Preconditions.checkState(pageSize != -1, "This is non-sense to have pageNumber>1 if pageSize==-1");
+ }
+ int startIndex = pageNumber * pageSize;
+ return startIndex;
+ }
+
+ public int getEndIndex() {
+ int endIndex = Integer.MAX_VALUE;
+ if (pageSize != -1) {
+ endIndex = getStartIndex() + pageSize - 1;
+ }
+ return endIndex;
+ }
+
+ /**
+ * Class used to build an instance of PaginationParameter
+ */
+ public static class Builder {
+
+ protected int pageNumber;
+ protected int pageSize;
+ protected List<PaginationOrder> orderClauses;
+
+ public Builder(int pageNumber, int pageSize) {
+ this.pageNumber = pageNumber;
+ this.pageSize = pageSize;
+ }
+
+ public Builder addOrder(String clause, boolean desc) {
+ if (orderClauses == null) {
+ orderClauses = Lists.newArrayList();
+ }
+ PaginationOrder paginationOrder = new PaginationOrder(clause, desc);
+ orderClauses.add(paginationOrder);
+ return this;
+ }
+
+ public Builder addAscOrder(String clause) {
+ return addOrder(clause, false);
+ }
+
+ public Builder addDescOrder(String clause) {
+ return addOrder(clause, true);
+ }
+
+ public Builder addOrder(String clause) {
+ boolean desc = false;
+ String cleanedClause = clause;
+ int spaceIndex = clause.indexOf(' ');
+ if (spaceIndex != -1) {
+ cleanedClause = clause.substring(0, spaceIndex).trim();
+ desc = "desc".equalsIgnoreCase(clause.substring(spaceIndex + 1).trim());
+ }
+ return addOrder(cleanedClause, desc);
+ }
+
+ public Builder addOrderClauses(Iterable<PaginationOrder> clauses) {
+ if (orderClauses == null) {
+ orderClauses = Lists.newArrayList();
+ }
+ if (clauses != null) {
+ Iterables.addAll(orderClauses, clauses);
+ }
+ return this;
+ }
+
+ public PaginationParameter build() {
+ PaginationParameter result = new PaginationParameter(pageNumber, pageSize, orderClauses);
+ return result;
+ }
+ }
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationParameter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationResult.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationResult.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationResult.java 2014-05-21 21:56:15 UTC (rev 3125)
@@ -0,0 +1,127 @@
+package org.nuiton.topia.persistence.pager;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2014 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import java.io.Serializable;
+import java.util.List;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Represents the result of a pagination request. It contains the result elements together with the
+ * {code}PaginationParameter{/code} used to compute it.
+ *
+ * @author Arnaud Thimel (Code Lutin)
+ * @since 3.0
+ */
+public class PaginationResult<K> implements Serializable {
+
+ private static final long serialVersionUID = -8794603203860852003L;
+
+ protected List<K> elements;
+ protected long count;
+ protected PaginationParameter currentPage;
+
+ private PaginationResult(List<K> elements, long count, PaginationParameter currentPage) {
+ this.elements = elements;
+ this.count = count;
+ this.currentPage = currentPage;
+ }
+
+ public static <E> PaginationResult<E> of(List<E> elements, long count, PaginationParameter currentPage) {
+ PaginationResult<E> result = new PaginationResult<E>(elements, count, currentPage);
+ return result;
+ }
+
+ public List<K> getElements() {
+ return elements;
+ }
+
+ public long getCount() {
+ return count;
+ }
+
+ public PaginationParameter getCurrentPage() {
+ return currentPage;
+ }
+
+ public PaginationParameter getNextPage() {
+ int nextPageNumber = currentPage.getPageNumber() + 1;
+ int pageSize = currentPage.getPageSize();
+ List<PaginationOrder> orderClauses = currentPage.getOrderClauses();
+ PaginationParameter result = PaginationParameter.
+ builder(nextPageNumber, pageSize).
+ addOrderClauses(orderClauses).
+ build();
+ return result;
+ }
+
+ public PaginationParameter getPreviousPage() {
+ // XXX AThimel 21/05/14 Maybe, do not fail, just return the first page ?
+ Preconditions.checkState(currentPage.getPageNumber() > 0, "You cannot get a previous page to the first one");
+ int previousPageNumber = currentPage.getPageNumber() - 1;
+ int pageSize = currentPage.getPageSize();
+ List<PaginationOrder> orderClauses = currentPage.getOrderClauses();
+ PaginationParameter result = PaginationParameter.
+ builder(previousPageNumber, pageSize).
+ addOrderClauses(orderClauses).
+ build();
+ return result;
+ }
+
+ public PaginationParameter getFirstPage() {
+ int firstPageNumber = 0;
+ int pageSize = currentPage.getPageSize();
+ List<PaginationOrder> orderClauses = currentPage.getOrderClauses();
+ PaginationParameter result = PaginationParameter.
+ builder(firstPageNumber, pageSize).
+ addOrderClauses(orderClauses).
+ build();
+ return result;
+ }
+
+ public PaginationParameter getLastPage() {
+ int lastPageNumber = getPageCount() - 1;
+ int pageSize = currentPage.getPageSize();
+ List<PaginationOrder> orderClauses = currentPage.getOrderClauses();
+ PaginationParameter result = PaginationParameter.
+ builder(lastPageNumber, pageSize).
+ addOrderClauses(orderClauses).
+ build();
+ return result;
+ }
+
+ public int getPageCount() {
+ int pageCount = 1;
+ int pageSize = currentPage.getPageSize();
+ if (pageSize > 1) {
+ double countDouble = Long.valueOf(count).doubleValue();
+ double pageSizeDouble = Integer.valueOf(pageSize).doubleValue();
+ double pageNumberDouble = Math.ceil(countDouble / pageSizeDouble);
+ pageCount = Double.valueOf(pageNumberDouble).intValue();
+ }
+ return pageCount;
+ }
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationResult.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationParameterTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationParameterTest.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationParameterTest.java 2014-05-21 21:56:15 UTC (rev 3125)
@@ -0,0 +1,75 @@
+package org.nuiton.topia.persistence.pager;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2014 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Arnaud Thimel (Code Lutin)
+ */
+public class PaginationParameterTest {
+
+ @Test
+ public void testIndexes() {
+ {
+ PaginationParameter paginationParameter = PaginationParameter.of(0, 50);
+ Assert.assertEquals(0, paginationParameter.getStartIndex());
+ Assert.assertEquals(49, paginationParameter.getEndIndex());
+ }
+ {
+ PaginationParameter paginationParameter = PaginationParameter.of(2, 50);
+ Assert.assertEquals(100, paginationParameter.getStartIndex());
+ Assert.assertEquals(149, paginationParameter.getEndIndex());
+ }
+ {
+ PaginationParameter paginationParameter = PaginationParameter.of(0, -1);
+ Assert.assertEquals(0, paginationParameter.getStartIndex());
+ Assert.assertEquals(Integer.MAX_VALUE, paginationParameter.getEndIndex());
+ }
+ {
+ PaginationParameter paginationParameter = PaginationParameter.of(0, 19);
+ Assert.assertEquals(0, paginationParameter.getStartIndex());
+ Assert.assertEquals(18, paginationParameter.getEndIndex());
+ }
+ {
+ PaginationParameter paginationParameter = PaginationParameter.of(1, 19);
+ Assert.assertEquals(19, paginationParameter.getStartIndex());
+ Assert.assertEquals(37, paginationParameter.getEndIndex());
+ }
+ {
+ PaginationParameter paginationParameter = PaginationParameter.of(2, 19);
+ Assert.assertEquals(38, paginationParameter.getStartIndex());
+ Assert.assertEquals(56, paginationParameter.getEndIndex());
+ }
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testInvalidIndex() {
+ PaginationParameter paginationParameter = PaginationParameter.of(2, -1);
+ paginationParameter.getStartIndex();
+ }
+
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationParameterTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationResultTest.java
===================================================================
--- trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationResultTest.java (rev 0)
+++ trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationResultTest.java 2014-05-21 21:56:15 UTC (rev 3125)
@@ -0,0 +1,90 @@
+package org.nuiton.topia.persistence.pager;
+
+/*
+ * #%L
+ * ToPIA :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2014 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+
+/**
+ * @author Arnaud Thimel (Code Lutin)
+ */
+public class PaginationResultTest {
+
+ protected PaginationResult<Object> paginationResult;
+
+ @Before
+ public void init() {
+ List<Object> elements = Lists.newArrayList();
+ PaginationParameter page = PaginationParameter.of(2, 50);
+ paginationResult = PaginationResult.of(elements, 204, page);
+ }
+
+ @Test
+ public void testGetFirstPage() {
+ Assert.assertEquals(0, paginationResult.getFirstPage().getPageNumber());
+ Assert.assertEquals(50, paginationResult.getFirstPage().getPageSize());
+ Assert.assertEquals(0, paginationResult.getFirstPage().getStartIndex());
+ Assert.assertEquals(49, paginationResult.getFirstPage().getEndIndex());
+ }
+
+ @Test
+ public void testGetPreviousPage() {
+ Assert.assertEquals(1, paginationResult.getPreviousPage().getPageNumber());
+ Assert.assertEquals(50, paginationResult.getPreviousPage().getPageSize());
+ Assert.assertEquals(50, paginationResult.getPreviousPage().getStartIndex());
+ Assert.assertEquals(99, paginationResult.getPreviousPage().getEndIndex());
+ }
+
+ @Test
+ public void testCurrentPage() {
+ Assert.assertEquals(5, paginationResult.getPageCount());
+ Assert.assertEquals(2, paginationResult.getCurrentPage().getPageNumber());
+ Assert.assertEquals(50, paginationResult.getCurrentPage().getPageSize());
+ Assert.assertEquals(100, paginationResult.getCurrentPage().getStartIndex());
+ Assert.assertEquals(149, paginationResult.getCurrentPage().getEndIndex());
+ }
+
+ @Test
+ public void testGeNextPage() {
+ Assert.assertEquals(3, paginationResult.getNextPage().getPageNumber());
+ Assert.assertEquals(50, paginationResult.getNextPage().getPageSize());
+ Assert.assertEquals(150, paginationResult.getNextPage().getStartIndex());
+ Assert.assertEquals(199, paginationResult.getNextPage().getEndIndex());
+ }
+
+ @Test
+ public void testGetLastPage() {
+ Assert.assertEquals(4, paginationResult.getLastPage().getPageNumber());
+ Assert.assertEquals(50, paginationResult.getLastPage().getPageSize());
+ Assert.assertEquals(200, paginationResult.getLastPage().getStartIndex());
+ Assert.assertEquals(249, paginationResult.getLastPage().getEndIndex());
+ }
+
+}
Property changes on: trunk/topia-persistence/src/test/java/org/nuiton/topia/persistence/pager/PaginationResultTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
2
1
21 May '14
See <http://ci.nuiton.org/jenkins/job/topia-nightly/42/changes>
Changes:
[bleny] refs #3204 make liquibase service create schema if needed
[bleny] fixes #3204 introduce topia-service-liquibase module
[bleny] remove useless section of pom
------------------------------------------
Started by an SCM change
Building in workspace <http://ci.nuiton.org/jenkins/job/topia-nightly/ws/>
Reverting <http://ci.nuiton.org/jenkins/job/topia-nightly/ws/trunk> to depth infinity with ignoreExternals: false
Updating https://svn.nuiton.org/topia/trunk at revision '2014-05-21T00:44:50.704 +0200'
U pom.xml
U topia-service-flyway/pom.xml
A topia-service-liquibase
AU topia-service-liquibase/LICENSE.txt
A topia-service-liquibase/src
A topia-service-liquibase/src/main
A topia-service-liquibase/src/main/java
A topia-service-liquibase/src/main/java/org
A topia-service-liquibase/src/main/java/org/nuiton
A topia-service-liquibase/src/main/java/org/nuiton/topia
A topia-service-liquibase/src/main/java/org/nuiton/topia/liquibase
A topia-service-liquibase/src/main/java/org/nuiton/topia/liquibase/TopiaLiquibaseService.java
A topia-service-liquibase/src/main/java/org/nuiton/topia/liquibase/TopiaLiquibaseServiceImpl.java
AU topia-service-liquibase/pom.xml
A topia-service-liquibase/README.txt
At revision 3115
Parsing POMs
Downloaded artifact http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/nuiton/mav…
Downloaded artifact http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/nuiton/mav…
Downloaded artifact http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/nuiton/mav…
Discovered a new module org.nuiton.topia:topia-service-liquibase ToPIA :: Liquibase integration service
Modules changed, recalculating dependency graph
[trunk] $ /opt/jdk7/bin/java -Dsettings.security=/var/local/forge/data/nuiton.org/maven/settings-security.xml -Djava.awt.headless=true -cp /var/local/forge/data/nuiton.org/jenkins/plugins/maven-plugin/WEB-INF/lib/maven31-agent-1.5.jar:/opt/maven3/boot/plexus-classworlds-2.5.1.jar:/opt/maven3/conf/logging jenkins.maven3.agent.Maven31Main /opt/maven3 /var/local/forge/exec/tomcat-nuiton.org/webapps/jenkins/WEB-INF/lib/remoting-2.39.jar /var/local/forge/data/nuiton.org/jenkins/plugins/maven-plugin/WEB-INF/lib/maven31-interceptor-1.5.jar /var/local/forge/data/nuiton.org/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.5.jar 40462
<===[JENKINS REMOTING CAPACITY]===> channel started
Executing Maven: -B -f <http://ci.nuiton.org/jenkins/job/topia-nightly/ws/trunk/pom.xml> -s /var/local/forge/data/nuiton.org/maven/settings.xml -e -U clean install -DperformRelease
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/nuiton/mav…
[INFO] Downloaded: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/nuiton/mav… (613 B at 6.7 KB/sec)
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/nuiton/mav…
[INFO] Downloaded: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/nuiton/mav… (603 B at 25.6 KB/sec)
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/nuiton/mav…
[INFO] Downloaded: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/nuiton/mav… (595 B at 25.3 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] ToPIA
[INFO] ToPIA :: Persistence
[INFO] ToPIA :: JUnit
[INFO] ToPIA :: Templates
[INFO] ToPIA :: IT
[INFO] ToPIA :: Service Replication
[INFO] ToPIA :: Service Migration
[INFO] ToPIA :: Flyway integration service
[INFO] ToPIA :: Liquibase integration service
[INFO] ToPIA :: Service CSV
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ToPIA 3.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ topia ---
[INFO] Deleting <http://ci.nuiton.org/jenkins/job/topia-nightly/ws/trunk/target>
[INFO]
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (ensure-no-container-api) @ topia ---
[INFO]
[INFO] --- helper-maven-plugin:2.1:check-auto-container (check-central-safe) @ topia ---
[INFO] Will use repository http://repo1.maven.org/maven2/
[INFO] Will use repository http://maven.nuiton.org/central-releases
[INFO] 14 dependencies to check.
[INFO] 14 artifact(s) resolved by repository http://repo1.maven.org/maven2/ in 2.106s
[INFO] All dependencies are safe.
[INFO]
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (check-project-files) @ topia ---
[INFO]
[INFO] --- helper-maven-plugin:2.1:share-server-secret (get-redmine-login) @ topia ---
[INFO] Exporting server [redmine-forge.nuiton.org] privateKey in ${redmine.apiKey}
[INFO]
[INFO] --- license-maven-plugin:1.7:update-project-license (attach-licenses) @ topia ---
[INFO] Will create or update license file [lgpl_v3] to <http://ci.nuiton.org/jenkins/job/topia-nightly/ws/trunk/LICENSE.txt>
[INFO]
[INFO] --- license-maven-plugin:1.7:add-third-party (attach-licenses) @ topia ---
[WARNING] The goal is skip due to packaging 'pom'
[INFO]
[INFO] --- license-maven-plugin:1.7:update-file-header (update-file-header) @ topia ---
[WARNING] The extension xsl is already accepted for comment style xml
[INFO] Will search files to update from root <http://ci.nuiton.org/jenkins/job/topia-nightly/ws/trunk/src>
[INFO] Scan 21 files header done in 108.501ms.
[INFO]
* uptodate header on 19 files.
* add header on 2 files.
[INFO]
[INFO] --- animal-sniffer-maven-plugin:1.10:check (default) @ topia ---
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java16:1.1
[INFO]
[INFO] --- jredmine-maven-plugin:1.8.1:generate-changes (jredmine-generate-changes) @ topia ---
[ERROR] (RedmineClient:491) - Error = <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<title>Redmine 500 error</title>
<style>
body{
font-family: Trebuchet MS,Georgia,"Times New Roman",serif;
color:#303030;
margin:10px;
}
h1{
font-size:1.5em;
}
p{
font-size:0.8em;
}
</style>
<body>
<h1>Internal error</h1>
<p>An error occurred on the page you were trying to access.<br />
If you continue to experience problems please contact your Redmine administrator for assistance.</p>
<p>If you are the Redmine administrator, check your log files for details about the error.</p>
<p><a href="javascript:history.back()">Back</a></p>
</body>
</html>
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] ToPIA ............................................. FAILURE [ 9.502 s]
[INFO] ToPIA :: Persistence .............................. SKIPPED
[INFO] ToPIA :: JUnit .................................... SKIPPED
[INFO] ToPIA :: Templates ................................ SKIPPED
[INFO] ToPIA :: IT ....................................... SKIPPED
[INFO] ToPIA :: Service Replication ...................... SKIPPED
[INFO] ToPIA :: Service Migration ........................ SKIPPED
[INFO] ToPIA :: Flyway integration service ............... SKIPPED
[INFO] ToPIA :: Liquibase integration service ............ SKIPPED
[INFO] ToPIA :: Service CSV .............................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.360 s
[INFO] Finished at: 2014-05-21T00:45:09+01:00
[INFO] Final Memory: 30M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.nuiton.jredmine:jredmine-maven-plugin:1.8.1:generate-changes (jredmine-generate-changes) on project topia: could not init goal GenerateChangesMojo for reason : could not init service for reason Got error code <500:Internal Server Error> on http://forge.nuiton.org/jredmine/ping -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.nuiton.jredmine:jredmine-maven-plugin:1.8.1:generate-changes (jredmine-generate-changes) on project topia: could not init goal GenerateChangesMojo for reason : could not init service for reason Got error code <500:Internal Server Error> on http://forge.nuiton.org/jredmine/ping
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.jvnet.hudson.maven3.launcher.Maven31Launcher.main(Maven31Launcher.java:132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:330)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:238)
at jenkins.maven3.agent.Maven31Main.launch(Maven31Main.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at hudson.maven.Maven3Builder.call(Maven3Builder.java:134)
at hudson.maven.Maven3Builder.call(Maven3Builder.java:69)
at hudson.remoting.UserRequest.perform(UserRequest.java:118)
at hudson.remoting.UserRequest.perform(UserRequest.java:48)
at hudson.remoting.Request$2.run(Request.java:328)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.maven.plugin.MojoExecutionException: could not init goal GenerateChangesMojo for reason : could not init service for reason Got error code <500:Internal Server Error> on http://forge.nuiton.org/jredmine/ping
at org.nuiton.plugin.AbstractPlugin.execute(AbstractPlugin.java:113)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 30 more
Caused by: org.nuiton.jredmine.service.RedmineServiceException: could not init service for reason Got error code <500:Internal Server Error> on http://forge.nuiton.org/jredmine/ping
at org.nuiton.jredmine.service.AbstractRedmineService.init(AbstractRedmineService.java:60)
at org.nuiton.jredmine.service.DefaultRedmineService.init(DefaultRedmineService.java:78)
at org.nuiton.jredmine.plugin.AbstractRedmineMojo.init(AbstractRedmineMojo.java:290)
at org.nuiton.jredmine.plugin.AbstractRedmineMojoWithProject.init(AbstractRedmineMojoWithProject.java:92)
at org.nuiton.jredmine.plugin.AbstractRedmineMojoWithProjectAndVersion.init(AbstractRedmineMojoWithProjectAndVersion.java:101)
at org.nuiton.jredmine.plugin.GenerateChangesMojo.init(GenerateChangesMojo.java:336)
at org.nuiton.plugin.AbstractPlugin.execute(AbstractPlugin.java:106)
... 32 more
Caused by: java.io.IOException: Got error code <500:Internal Server Error> on http://forge.nuiton.org/jredmine/ping
at org.nuiton.jredmine.client.RedmineClient$AbstractRedmineResponseHandler.checkResponse(RedmineClient.java:492)
at org.nuiton.jredmine.client.RedmineClient$RedmineSimpleResponseHandler.handleResponse(RedmineClient.java:509)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:218)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:160)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:136)
at org.nuiton.jredmine.client.RedmineClient.executeRequest(RedmineClient.java:183)
at org.nuiton.jredmine.client.RedmineClient.open(RedmineClient.java:148)
at org.nuiton.jredmine.service.AbstractRedmineService.init(AbstractRedmineService.java:58)
... 38 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Sending e-mails to: topia-commits(a)list.nuiton.org leny(a)codelutin.com
channel stopped
Skipping sonar analysis due to bad build status FAILURE
1
1
21 May '14
See <http://ci.nuiton.org/jenkins/job/topia-nightly/org.nuiton$topia/42/changes>
Changes:
[bleny] fixes #3204 introduce topia-service-liquibase module
------------------------------------------
<===[JENKINS REMOTING CAPACITY]===> channel started
Executing Maven: -B -f <http://ci.nuiton.org/jenkins/job/topia-nightly/org.nuiton$topia/ws/pom.xml> -s /var/local/forge/data/nuiton.org/maven/settings.xml -e -U clean install -DperformRelease
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/nuiton/mav…
[INFO] Downloaded: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/nuiton/mav… (613 B at 6.7 KB/sec)
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/nuiton/mav…
[INFO] Downloaded: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/nuiton/mav… (603 B at 25.6 KB/sec)
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/nuiton/mav…
[INFO] Downloaded: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/nuiton/mav… (595 B at 25.3 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] ToPIA
[INFO] ToPIA :: Persistence
[INFO] ToPIA :: JUnit
[INFO] ToPIA :: Templates
[INFO] ToPIA :: IT
[INFO] ToPIA :: Service Replication
[INFO] ToPIA :: Service Migration
[INFO] ToPIA :: Flyway integration service
[INFO] ToPIA :: Liquibase integration service
[INFO] ToPIA :: Service CSV
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ToPIA 3.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ topia ---
[INFO] Deleting <http://ci.nuiton.org/jenkins/job/topia-nightly/org.nuiton$topia/ws/target>
[INFO]
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (ensure-no-container-api) @ topia ---
[INFO]
[INFO] --- helper-maven-plugin:2.1:check-auto-container (check-central-safe) @ topia ---
[INFO] Will use repository http://repo1.maven.org/maven2/
[INFO] Will use repository http://maven.nuiton.org/central-releases
[INFO] 14 dependencies to check.
[INFO] 14 artifact(s) resolved by repository http://repo1.maven.org/maven2/ in 2.106s
[INFO] All dependencies are safe.
[INFO]
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (check-project-files) @ topia ---
[INFO]
[INFO] --- helper-maven-plugin:2.1:share-server-secret (get-redmine-login) @ topia ---
[INFO] Exporting server [redmine-forge.nuiton.org] privateKey in ${redmine.apiKey}
[INFO]
[INFO] --- license-maven-plugin:1.7:update-project-license (attach-licenses) @ topia ---
[INFO] Will create or update license file [lgpl_v3] to <http://ci.nuiton.org/jenkins/job/topia-nightly/org.nuiton$topia/ws/LICENSE.…>
[INFO]
[INFO] --- license-maven-plugin:1.7:add-third-party (attach-licenses) @ topia ---
[WARNING] The goal is skip due to packaging 'pom'
[INFO]
[INFO] --- license-maven-plugin:1.7:update-file-header (update-file-header) @ topia ---
[WARNING] The extension xsl is already accepted for comment style xml
[INFO] Will search files to update from root <http://ci.nuiton.org/jenkins/job/topia-nightly/org.nuiton$topia/ws/src>
[INFO] Scan 21 files header done in 108.501ms.
[INFO]
* uptodate header on 19 files.
* add header on 2 files.
[INFO]
[INFO] --- animal-sniffer-maven-plugin:1.10:check (default) @ topia ---
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java16:1.1
[INFO]
[INFO] --- jredmine-maven-plugin:1.8.1:generate-changes (jredmine-generate-changes) @ topia ---
[ERROR] (RedmineClient:491) - Error = <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<title>Redmine 500 error</title>
<style>
body{
font-family: Trebuchet MS,Georgia,"Times New Roman",serif;
color:#303030;
margin:10px;
}
h1{
font-size:1.5em;
}
p{
font-size:0.8em;
}
</style>
<body>
<h1>Internal error</h1>
<p>An error occurred on the page you were trying to access.<br />
If you continue to experience problems please contact your Redmine administrator for assistance.</p>
<p>If you are the Redmine administrator, check your log files for details about the error.</p>
<p><a href="javascript:history.back()">Back</a></p>
</body>
</html>
[JENKINS] Archiving disabled
1
1
r3126 - trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager
by athimel@users.nuiton.org 21 May '14
by athimel@users.nuiton.org 21 May '14
21 May '14
Author: athimel
Date: 2014-05-22 00:10:11 +0200 (Thu, 22 May 2014)
New Revision: 3126
Url: http://forge.nuiton.org/projects/topia/repository/revisions/3126
Log:
refs #3208 PaginationParameter : use builder internaly
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationParameter.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationParameter.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationParameter.java 2014-05-21 21:56:15 UTC (rev 3125)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/PaginationParameter.java 2014-05-21 22:10:11 UTC (rev 3126)
@@ -25,8 +25,8 @@
*/
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.Collections;
+import java.util.LinkedList;
import java.util.List;
import com.google.common.base.Preconditions;
@@ -48,7 +48,7 @@
protected List<PaginationOrder> orderClauses;
private PaginationParameter(int pageNumber, int pageSize) {
- this(pageNumber, pageSize, new ArrayList<PaginationOrder>());
+ this(pageNumber, pageSize, new LinkedList<PaginationOrder>());
}
private PaginationParameter(int pageNumber, int pageSize, List<PaginationOrder> orderClauses) {
@@ -64,32 +64,29 @@
public static PaginationParameter of(int pageNumber, int pageSize,
String orderClause1, boolean orderDesc1) {
- List<PaginationOrder> orderClauses = Lists.newArrayListWithCapacity(3);
- orderClauses.add(new PaginationOrder(orderClause1, orderDesc1));
- PaginationParameter result = new PaginationParameter(pageNumber, pageSize, orderClauses);
- return result;
+ return builder(pageNumber, pageSize)
+ .addOrder(orderClause1, orderDesc1)
+ .build();
}
public static PaginationParameter of(int pageNumber, int pageSize,
String orderClause1, boolean orderDesc1,
String orderClause2, boolean orderDesc2) {
- List<PaginationOrder> orderClauses = Lists.newArrayListWithCapacity(3);
- orderClauses.add(new PaginationOrder(orderClause1, orderDesc1));
- orderClauses.add(new PaginationOrder(orderClause2, orderDesc2));
- PaginationParameter result = new PaginationParameter(pageNumber, pageSize, orderClauses);
- return result;
+ return builder(pageNumber, pageSize)
+ .addOrder(orderClause1, orderDesc1)
+ .addOrder(orderClause2, orderDesc2)
+ .build();
}
public static PaginationParameter of(int pageNumber, int pageSize,
String orderClause1, boolean orderDesc1,
String orderClause2, boolean orderDesc2,
String orderClause3, boolean orderDesc3) {
- List<PaginationOrder> orderClauses = Lists.newArrayListWithCapacity(3);
- orderClauses.add(new PaginationOrder(orderClause1, orderDesc1));
- orderClauses.add(new PaginationOrder(orderClause2, orderDesc2));
- orderClauses.add(new PaginationOrder(orderClause3, orderDesc3));
- PaginationParameter result = new PaginationParameter(pageNumber, pageSize, orderClauses);
- return result;
+ return builder(pageNumber, pageSize)
+ .addOrder(orderClause1, orderDesc1)
+ .addOrder(orderClause2, orderDesc2)
+ .addOrder(orderClause3, orderDesc3)
+ .build();
}
public static PaginationParameter.Builder builder(int pageNumber, int pageSize) {
@@ -141,7 +138,7 @@
public Builder addOrder(String clause, boolean desc) {
if (orderClauses == null) {
- orderClauses = Lists.newArrayList();
+ orderClauses = Lists.newLinkedList();
}
PaginationOrder paginationOrder = new PaginationOrder(clause, desc);
orderClauses.add(paginationOrder);
@@ -169,7 +166,7 @@
public Builder addOrderClauses(Iterable<PaginationOrder> clauses) {
if (orderClauses == null) {
- orderClauses = Lists.newArrayList();
+ orderClauses = Lists.newLinkedList();
}
if (clauses != null) {
Iterables.addAll(orderClauses, clauses);
1
0