alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (AbstractReadOnlyAccessTestCase.java)

This example Hibernate source code file (AbstractReadOnlyAccessTestCase.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

call, exception, exception, integer, integer, key, key_base, object, override, override, string, test, test, value1

The Hibernate AbstractReadOnlyAccessTestCase.java source code

/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * Copyright (c) 2007, Red Hat, Inc. and/or it's affiliates or third-party contributors as
 * indicated by the @author tags or express copyright attribution
 * statements applied by the authors.  All third-party contributions are
 * distributed under license by Red Hat, Inc. and/or it's affiliates.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.hibernate.test.cache.infinispan.entity;

import org.infinispan.transaction.tm.BatchModeTransactionManager;

import org.hibernate.cache.spi.access.AccessType;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

/**
 * Base class for tests of TRANSACTIONAL access.
 * 
 * @author Galder Zamarreño
 * @since 3.5
 */
public abstract class AbstractReadOnlyAccessTestCase extends AbstractEntityRegionAccessStrategyTestCase {
    @Override
    protected AccessType getAccessType() {
        return AccessType.READ_ONLY;
    }   

	@Test
    @Override
    public void testPutFromLoad() throws Exception {
        putFromLoadTest(false);
    }

	@Test
    @Override
    public void testPutFromLoadMinimal() throws Exception {
        putFromLoadTest(true);
    }
    
    private void putFromLoadTest(boolean minimal) throws Exception {
       
        final String KEY = KEY_BASE + testCount++;
        
        long txTimestamp = System.currentTimeMillis();
        BatchModeTransactionManager.getInstance().begin();
        assertNull(localAccessStrategy.get(KEY, System.currentTimeMillis()));
        if (minimal)
            localAccessStrategy.putFromLoad(KEY, VALUE1, txTimestamp, new Integer(1), true);
        else
            localAccessStrategy.putFromLoad(KEY, VALUE1, txTimestamp, new Integer(1));
        
        sleep(250);
        Object expected = isUsingInvalidation() ? null : VALUE1;
        assertEquals(expected, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
        
        BatchModeTransactionManager.getInstance().commit();
        assertEquals(VALUE1, localAccessStrategy.get(KEY, System.currentTimeMillis()));
        assertEquals(expected, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));
    }

	@Test
    @Override
    public void testUpdate() throws Exception {
       
        final String KEY = KEY_BASE + testCount++;
        
        try {
            localAccessStrategy.update(KEY, VALUE2, new Integer(2), new Integer(1));
            fail("Call to update did not throw exception");
        }
        catch (UnsupportedOperationException good) {}
    }

}

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate AbstractReadOnlyAccessTestCase.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.