Package org.apache.marmotta.ldcache.backend.kiwi.model

Examples of org.apache.marmotta.ldcache.backend.kiwi.model.KiWiCacheEntry


        // lookup element in cache first, so we can avoid reconstructing it if it is already there
        if(cached != null) {
            return (KiWiCacheEntry)cached.getObjectValue();
        }

        KiWiCacheEntry entry = new KiWiCacheEntry();
        entry.setId(id);
        entry.setLastRetrieved(new Date(row.getTimestamp("retrieved_at").getTime()));
        entry.setExpiryDate(new Date(row.getTimestamp("expires_at").getTime()));
        entry.setUpdateCount(row.getInt("update_count"));
        entry.setResource((URI) connection.loadNodeById(row.getLong("resource_id")));

        entryIdCache.put(new Element(id,entry));
        entryResourceCache.put(new Element(entry.getResource().stringValue(),entry));

        return entry;
    }
View Full Code Here


     *
     * @param entry the cache entry to store
     * @throws SQLException
     */
    public void storeCacheEntry(CacheEntry entry) throws SQLException {
        KiWiCacheEntry kEntry;
        if(entry instanceof KiWiCacheEntry) {
            kEntry = (KiWiCacheEntry) entry;
        } else {
            kEntry = new KiWiCacheEntry();
            kEntry.setExpiryDate(entry.getExpiryDate());
            kEntry.setLastRetrieved(entry.getLastRetrieved());
            kEntry.setUpdateCount(entry.getUpdateCount());
            kEntry.setResource(entry.getResource());
        }

        if(! (entry.getResource() instanceof KiWiResource) || ((KiWiResource) entry.getResource()).getId() == null) {
            throw new IllegalStateException("the resource contained in the cache entry is not a KiWiResource!");
        }

        kEntry.setId(connection.getNextSequence("seq.ldcache"));

        PreparedStatement insertEntry = connection.getPreparedStatement("store.entry");
        insertEntry.setLong(1, kEntry.getId());
        insertEntry.setTimestamp(2, new Timestamp(kEntry.getLastRetrieved().getTime()));
        insertEntry.setTimestamp(3,new Timestamp(kEntry.getExpiryDate().getTime()));
        insertEntry.setLong(4,((KiWiNode)kEntry.getResource()).getId());
        insertEntry.setInt(5, kEntry.getUpdateCount());
        insertEntry.executeUpdate();

        log.debug("persisted ld-cache entry with id {}", kEntry.getId());
       
        entryIdCache.put(new Element(kEntry.getId(),kEntry));
        entryResourceCache.put(new Element(kEntry.getResource().stringValue(),kEntry));

    }
View Full Code Here

            KiWiUriResource subject2  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));

            connection.storeNode(subject1);
            connection.storeNode(subject2);

            KiWiCacheEntry entry1 = new KiWiCacheEntry();
            entry1.setExpiryDate(new Date(System.currentTimeMillis()+1000*60));
            entry1.setLastRetrieved(new Date());
            entry1.setUpdateCount(1);
            entry1.setResource(subject1);
            connection.storeCacheEntry(entry1);

            connection.commit();

            Assert.assertEquals(1,asList(connection.listAll()).size());
            Assert.assertEquals(0,asList(connection.listExpired()).size());

            KiWiCacheEntry entry2 = new KiWiCacheEntry();
            entry2.setExpiryDate(new Date(System.currentTimeMillis() + 1000 * 60));
            entry2.setLastRetrieved(new Date());
            entry2.setUpdateCount(1);
            entry2.setResource(subject2);
            connection.storeCacheEntry(entry2);

            connection.commit();

            Assert.assertEquals(2,asList(connection.listAll()).size());
            Assert.assertEquals(0,asList(connection.listExpired()).size());

            connection.commit();

            connection.removeCacheEntry(entry1);

            connection.commit();

            Assert.assertEquals(1,asList(connection.listAll()).size());
            Assert.assertEquals(0, asList(connection.listExpired()).size());

            connection.removeCacheEntry(entry2.getResource().stringValue());

            connection.commit();

            Assert.assertEquals(0,asList(connection.listAll()).size());
            Assert.assertEquals(0,asList(connection.listExpired()).size());
View Full Code Here

            KiWiUriResource subject2  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));

            connection.storeNode(subject1);
            connection.storeNode(subject2);

            KiWiCacheEntry entry1 = new KiWiCacheEntry();
            entry1.setExpiryDate(new Date(System.currentTimeMillis() - 1000*60));
            entry1.setLastRetrieved(new Date());
            entry1.setUpdateCount(1);
            entry1.setResource(subject1);
            connection.storeCacheEntry(entry1);

            KiWiCacheEntry entry2 = new KiWiCacheEntry();
            entry2.setExpiryDate(new Date(System.currentTimeMillis() + 1000 * 60));
            entry2.setLastRetrieved(new Date());
            entry2.setUpdateCount(1);
            entry2.setResource(subject2);
            connection.storeCacheEntry(entry2);

            connection.commit();

            Assert.assertEquals(2,asList(connection.listAll()).size());
View Full Code Here

TOP

Related Classes of org.apache.marmotta.ldcache.backend.kiwi.model.KiWiCacheEntry

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.