fr.ird.observe.entities.AbstractObserveTopiaDao Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-persistence Show documentation
Show all versions of common-persistence Show documentation
ObServe Toolkit Common Persistence module
package fr.ird.observe.entities;
/*-
* #%L
* ObServe Toolkit :: Common Persistence
* %%
* Copyright (C) 2017 - 2020 IRD, Ultreia.io
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* .
* #L%
*/
import org.nuiton.topia.persistence.internal.AbstractTopiaDao;
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.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Map;
public abstract class AbstractObserveTopiaDao extends AbstractTopiaDao {
private final GetLastUpdateDateSqlQuery getLastUpdateDateSqlQuery;
protected AbstractObserveTopiaDao() {
String schemaName = getTopiaEntityEnum().dbSchemaName();
String tableName = getTopiaEntityEnum().dbTableName();
getLastUpdateDateSqlQuery = new GetLastUpdateDateSqlQuery(schemaName, tableName);
}
public Date getLastUpdateDate() {
return topiaSqlSupport.findSingleResult(getLastUpdateDateSqlQuery);
}
public List findAllFromHql(String hql, Map hqlParameters) {
return findAll(hql, hqlParameters);
}
private static class GetLastUpdateDateSqlQuery extends TopiaSqlQuery {
protected final String sql;
private GetLastUpdateDateSqlQuery(String schemaName, String tableName) {
this.sql = "SELECT max(" + Entity.PROPERTY_LAST_UPDATE_DATE + ") FROM " + schemaName + "." + tableName;
}
@Override
public PreparedStatement prepareQuery(Connection connection) throws SQLException {
return connection.prepareStatement(sql);
}
@Override
public Timestamp prepareResult(ResultSet set) throws SQLException {
return set.getTimestamp(1);
}
}
}