cz.muni.fi.editor.database.dao.CmisObjectDAOImpl.java Source code

Java tutorial

Introduction

Here is the source code for cz.muni.fi.editor.database.dao.CmisObjectDAOImpl.java

Source

/*
*Copyright  2016 Dominik Szalai (emptulik@gmail.com)
*
*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.
*/
/*
 * Copyright  2016 Dominik Szalai (emptulik@gmail.com)
 *
 * 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 cz.muni.fi.editor.database.dao;

import cz.muni.fi.editor.database.domain.CmisObjectDB;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Repository;

import java.util.Optional;

/**
 * Created by Dominik Szalai - emptulik at gmail.com on 7/21/16.
 */
@Repository
@Log4j2
public class CmisObjectDAOImpl extends AbstractDAO<CmisObjectDB, Long> implements CmisObjectDAO {
    @Override
    public Class<CmisObjectDB> getClassType() {
        return CmisObjectDB.class;
    }

    @Override
    public Optional<CmisObjectDB> getByCmisID(String objectID) {
        return getSafe(() -> getEntityManager()
                .createQuery("SELECT c FROM cmisobject c WHERE c.objectID = :cmisID", getClassType())
                .setParameter("cmisID", objectID).getSingleResult());
    }

    @Override
    public void deleteByCmisID(String objectID) {
        Optional<CmisObjectDB> result = getByCmisID(objectID);
        if (result.isPresent()) {
            getEntityManager().remove(result.get());
        }
    }
}