org.homiefund.api.dao.impl.TransactionPreviewDAOImpl.java Source code

Java tutorial

Introduction

Here is the source code for org.homiefund.api.dao.impl.TransactionPreviewDAOImpl.java

Source

/**
 * Copyright  2016 REPLACE ME OWNER (REPLACE ME YEAR)
 *
 * 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 org.homiefund.api.dao.impl;

import org.homiefund.api.dao.TransactionPreviewDAO;
import org.homiefund.api.dao.domain.Home;
import org.homiefund.api.dao.domain.TransactionPreview;
import org.homiefund.api.dao.domain.User;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

/**
 * Created by Dominik Szalai - emptulik at gmail.com on 4.10.2016.
 */
@Repository
public class TransactionPreviewDAOImpl extends AbstractDAO<TransactionPreview, Long>
        implements TransactionPreviewDAO {
    @Override
    public Long create(TransactionPreview entity) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void update(TransactionPreview entity) {
        throw new UnsupportedOperationException();
    }

    @Override
    public TransactionPreview getById(Long id) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void delete(Long id) {
        throw new UnsupportedOperationException();
    }

    @Override
    public List<TransactionPreview> getAll() {
        throw new UnsupportedOperationException();
    }

    @Override
    public Collection<TransactionPreview> getTransactions(int firstResult, int pageSize, Home home,
            User participant) {
        return getEntityManager()
                .createQuery(
                        "SELECT tl FROM transactionlist tl WHERE tl.home = :home AND tl.participant = :participant",
                        getClassType())
                .setParameter("home", home.getId()).setParameter("participant", participant.getId())
                .setFirstResult(firstResult).setMaxResults(pageSize).getResultList();
    }

    @Override
    public Long totalTransactions(Home home, User participant) {
        return getEntityManager().createQuery(
                "SELECT COUNT(tl.id) FROM transactionlist tl WHERE tl.home = :home AND tl.participant = :participant",
                Long.class).setParameter("home", home.getId()).setParameter("participant", participant.getId())
                .getSingleResult();
    }

    @Override
    public Class<TransactionPreview> getClassType() {
        return TransactionPreview.class;
    }
}