com.formkiq.server.dao.AbstractDaoImpl Maven / Gradle / Ivy
package com.formkiq.server.dao;
import java.sql.Blob;
import java.sql.SQLException;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.springframework.util.StringUtils;
import com.formkiq.server.domain.type.PaginationDTO;
import com.formkiq.server.domain.type.SyncDTO;
import com.formkiq.server.domain.type.SyncListDTO;
import com.formkiq.server.domain.type.SyncType;
import com.formkiq.server.util.Strings;
/**
* AbstractDao.
*
*/
public abstract class AbstractDaoImpl implements AbstractDao {
/** Default MAX Results. */
protected static final int DEFAULT_MAX_RESULTS = 10;
/** EntityManager. */
@PersistenceContext
private EntityManager entityManager;
@Override
public Blob convertToBlob(final byte[] data) {
Session session = getEntityManager().unwrap(Session.class);
Blob blob = Hibernate.getLobCreator(session).createBlob(data);
return blob;
}
/**
* Converts Query to Sync List DTO.
* @param query {@link org.hibernate.Query}
* @param lastNextToken {@link String}
* @param maxRecords int
* @return {@link SyncListDTO}
*/
@SuppressWarnings("unchecked")
protected SyncListDTO convertToSyncList(final org.hibernate.Query query,
final int lastNextToken,
final int maxRecords) {
List