<commit_before>/**
 * Licensed to Jasig under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Jasig licenses this file to you 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.jasig.portal.concurrency.locking;

import java.util.List;
import java.util.concurrent.TimeUnit;

import javax.persistence.LockModeType;
import javax.persistence.LockTimeoutException;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Root;

import org.hibernate.PessimisticLockException;
import org.jasig.portal.jpa.BasePortalJpaDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.ImmutableMap;

/**
 * DB based locking DAO using JPA2 locking APIs
 * 
 * @author <NAME>
 * @version $Revision$
 */
@Repository
public class JpaClusterLockDao extends BasePortalJpaDao implements IClusterLockDao {
    protected final Logger logger = LoggerFactory.getLogger(getClass());
    
    private ParameterExpression<String> nameParameter;
    private CriteriaQuery<ClusterMutex> clusterLockByNameQuery;

    /* (non-Javadoc)
     * @see org.jasig.portal.jpa.BaseJpaDao#buildCriteriaQueries(javax.persistence.criteria.CriteriaBuilder)
     */
    @Override
    protected void buildCriteriaQueries(CriteriaBuilder criteriaBuilder) {
        this.nameParameter = criteriaBuilder.parameter(String.class, "name");
        
        this.clusterLockByNameQuery = buildGetClusterLockByNameQuery(criteriaBuilder);
    }

    protected CriteriaQuery<ClusterMutex> buildGetClusterLockByNameQuery(CriteriaBuilder criteriaBuilder) {
        final CriteriaQuery<ClusterMutex> criteriaQuery = criteriaBuilder.createQuery(ClusterMutex.class);
        final Root<ClusterMutex> definitionRoot = criteriaQuery.from(ClusterMutex.class);
        criteriaQuery.select(definitionRoot);
        criteriaQuery.where(
            criteriaBuilder.equal(definitionRoot.get(ClusterMutex_.name), this.nameParameter)
        );<commit_msg>UP-3231 fix base jpa dao usage<commit_after>/**
 * Licensed to Jasig under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Jasig licenses this file to you 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.jasig.portal.concurrency.locking;

import java.util.List;
import java.util.concurrent.TimeUnit;

import javax.persistence.EntityManager;
import javax.persistence.LockModeType;
import javax.persistence.LockTimeoutException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Root;

import org.hibernate.PessimisticLockException;
import org.jasig.portal.jpa.BaseJpaDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.ImmutableMap;

/**
 * DB based locking DAO using JPA2 locking APIs
 * 
 * @author <NAME>
 * @version $Revision$
 */
@Repository
public class JpaClusterLockDao extends BaseJpaDao implements IClusterLockDao {
    protected final Logger logger = LoggerFactory.getLogger(getClass());
    
    private ParameterExpression<String> nameParameter;
    private CriteriaQuery<ClusterMutex> clusterLockByNameQuery;
    private EntityManager entityManager;

    @PersistenceContext(unitName = "uPortalPersistence")
    public final void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }
    
    /* (non-Javadoc)
     * @see org.jasig.portal.jpa.BaseJpaDao#getEntityManager()
     */
    @Override
    protected EntityManager getEntityManager() {
        return this.entityManager;
    }

    /* (non-Javadoc)
     * @see org.jasig.portal.jpa.BaseJpaDao#buildCriteriaQueries(javax.persistence.criteria.CriteriaBuilder)
     */
    @Override
    protected void buildCriteriaQueries(CriteriaBuilder criteriaBuilder) {
        this.nameParameter = criteriaBuilder.parameter(String.class, "name");
        
        this.clusterLockByNameQuery = buildGetClusterLockByNameQuery(criteriaBuilder);
    }

    protected CriteriaQuery<ClusterMutex> buildGetClusterLockByNameQuery(CriteriaBuilder criteriaBuilder) {
        final CriteriaQuery<ClusterMutex> criteriaQuery = criteriaBuilder.createQuery(ClusterMutex.class);
        final Root<ClusterMutex> definitionRoot = criteriaQuery.from(ClusterMutex.class);
        criteriaQuery.select(definitionRoot);
        criteriaQuery.where(
            criteriaBuilder.equal(definitionRoot.get(ClusterMutex_.name), this.nameParameter)
        );
{'fraction_non_alphanumeric': 0.07927762473217019, 'fraction_numerical': 0.0027548209366391185, 'mean_word_length': 4.84525939177102, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1468224', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1728, 'n_words': 446}