Package org.apache.marmotta.ldcache.api

Examples of org.apache.marmotta.ldcache.api.LDCachingConnection


     *
     * @throws Exception
     */
    @Test
    public void testStoreEntries() throws Exception {
        LDCachingConnection con = backend.getCacheConnection("http://localhost/resource/1");
        try {
            con.begin();

            URI subject1     = con.getValueFactory().createURI("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
            URI subject2     = con.getValueFactory().createURI("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
            Literal object1  = con.getValueFactory().createLiteral(RandomStringUtils.random(64));
            Literal object2  = con.getValueFactory().createLiteral(RandomStringUtils.random(64));
            URI predicate    = con.getValueFactory().createURI("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));

            Statement stmt1 = con.getValueFactory().createStatement(subject1,predicate,object1);
            Statement stmt2 = con.getValueFactory().createStatement(subject2,predicate,object2);

            con.add(stmt1);
            con.add(stmt2);

            con.commit();

            con.begin();
            CacheEntry entry1 = new CacheEntry();
            entry1.setExpiryDate(new Date(System.currentTimeMillis()+1000*60));
            entry1.setLastRetrieved(new Date());
            entry1.setUpdateCount(1);
            entry1.setResource(subject1);
            con.addCacheEntry(subject1, entry1);
            con.commit();

            Assert.assertEquals(1,asList(backend.listCacheEntries()).size());
            Assert.assertEquals(0,asList(backend.listExpiredEntries()).size());

            con.begin();
            CacheEntry entry2 = new CacheEntry();
            entry2.setExpiryDate(new Date(System.currentTimeMillis() - 1000 * 60));
            entry2.setLastRetrieved(new Date());
            entry2.setUpdateCount(1);
            entry2.setResource(subject2);
            con.addCacheEntry(subject2,entry2);

            con.commit();

            Assert.assertEquals(2,asList(backend.listCacheEntries()).size());
            Assert.assertEquals(1,asList(backend.listExpiredEntries()).size());

            con.begin();
            con.removeCacheEntry(subject1);
            con.commit();

            Assert.assertEquals(1,asList(backend.listCacheEntries()).size());
            Assert.assertEquals(1,asList(backend.listExpiredEntries()).size());
        } catch(RepositoryException ex) {
            con.rollback();
        } finally {
            con.close();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.marmotta.ldcache.api.LDCachingConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.