This is an automated email from the git hooks/post-receive script. New commit to branch feature/7470_mise_en_place_de_la_date_de_derniere_mise_a_jour in repository tutti. See http://git.codelutin.com/tutti.git commit f9c2470d6a7255d15537049b35d38d80c6700dd1 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Dec 30 16:58:24 2015 +0100 Ajout méthode pour compter le nombre d'éléments d'une table --- .../observe/ObserveTopiaPersistenceContext.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/observe-entities/src/main/java/fr/ird/observe/ObserveTopiaPersistenceContext.java b/observe-entities/src/main/java/fr/ird/observe/ObserveTopiaPersistenceContext.java index 841e2e0..7e2cf3c 100644 --- a/observe-entities/src/main/java/fr/ird/observe/ObserveTopiaPersistenceContext.java +++ b/observe-entities/src/main/java/fr/ird/observe/ObserveTopiaPersistenceContext.java @@ -30,7 +30,12 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaDao; import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContextConstructorParameter; +import org.nuiton.topia.persistence.support.TopiaSqlQuery; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.Date; public class ObserveTopiaPersistenceContext extends AbstractObserveTopiaPersistenceContext { @@ -91,4 +96,34 @@ public class ObserveTopiaPersistenceContext extends AbstractObserveTopiaPersiste public <E extends ObserveEntity> TopiaDao<E> getDao(E entity) { return getDao(getType(entity)); } + + public long countTable(String fullyTableName) { + + CountTableSqlWork countQuery = new CountTableSqlWork(fullyTableName); + Long count = getSqlSupport().findSingleResult(countQuery); + return count; + + } + + protected class CountTableSqlWork extends TopiaSqlQuery<Long> { + + private final String fullyTableName; + + public CountTableSqlWork(String fullyTableName) { + this.fullyTableName = fullyTableName; + } + + @Override + public PreparedStatement prepareQuery(Connection connection) throws SQLException { + String sql = "SELECT count(*) FROM " + fullyTableName; + PreparedStatement statement = connection.prepareStatement(sql); + + return statement; + } + + @Override + public Long prepareResult(ResultSet set) throws SQLException { + return set.getLong(1); + } + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.