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

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


    }

    public KiWiCacheEntry constructCacheEntry(ResultSet row) throws SQLException {
        Long id = row.getLong("id");

        KiWiCacheEntry cached = entryIdCache.get(id);

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

        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")));
        entry.setTripleCount(row.getInt("triple_count"));

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

        return entry;
    }
View Full Code Here


     *         is no entry for this resource
     * @throws SQLException
     */
    public KiWiCacheEntry getCacheEntry(String uri) throws SQLException {

        KiWiCacheEntry cached = entryResourceCache.get(uri);

        // lookup element in cache first, so we can avoid reconstructing it if it is already there
        if(cached != null) {
            return cached;
        }
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());
            kEntry.setTripleCount(entry.getTripleCount());
        }

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

        // needed before the entry can be inserted
        connection.flushBatch();

        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.setInt(6, kEntry.getTripleCount());
        insertEntry.executeUpdate();

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

    }
View Full Code Here

        PreparedStatement deleteEntry = connection.getPreparedStatement("delete.entry_by_uri");
        deleteEntry.setString(1,uri);
        deleteEntry.executeUpdate();

        KiWiCacheEntry cached = entryResourceCache.get(uri);

        if(cached != null) {
            entryResourceCache.remove(uri);
            entryIdCache.remove(cached.getId());
        }
    }
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);
            entry1.setTripleCount(1);
            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);
            entry2.setTripleCount(1);
            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);
            entry1.setTripleCount(1);
            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);
            entry2.setTripleCount(1);
            connection.storeCacheEntry(entry2);

            connection.commit();

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

        // 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")));
        entry.setTripleCount(row.getInt("triple_count"));

        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());
            kEntry.setTripleCount(entry.getTripleCount());
        }

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

        // needed before the entry can be inserted
        connection.flushBatch();

        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.setInt(6, kEntry.getTripleCount());
        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);
            entry1.setTripleCount(1);
            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);
            entry2.setTripleCount(1);
            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);
            entry1.setTripleCount(1);
            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);
            entry2.setTripleCount(1);
            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.