com.formkiq.server.dao.AbstractDaoImpl Maven / Gradle / Ivy
/*
* Copyright (C) 2016 FormKiQ Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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