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

Examples of org.apache.marmotta.ldcache.backend.kiwi.persistence.LDCachingKiWiPersistenceConnection


     * @return true in case the resource is a cached resource
     */
    @Override
    public boolean isCached(String resource) throws RepositoryException {
        try {
            LDCachingKiWiPersistenceConnection con = persistence.getConnection();
            try {
                CacheEntry entry = con.getCacheEntry(resource);
                return  entry != null && entry.getTripleCount() > 0;
            } finally {
                con.commit();
                con.close();
            }
        } catch (SQLException e) {
            throw new RepositoryException(e);
        }
    }
View Full Code Here


    };

    @Test
    public void testTablesCreateDrop() throws Exception {
        // test if database exists and has a version
        LDCachingKiWiPersistenceConnection connection = vpersistence.getConnection();
        try {
            Assert.assertThat(connection.getDatabaseTables(), hasItems("ldcache_entries"));
            Assert.assertEquals(2, connection.getDatabaseVersion());

            connection.commit();
        } finally {
            connection.close();
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testCreateListEntries() throws Exception {
        LDCachingKiWiPersistenceConnection connection = vpersistence.getConnection();
        try {
            KiWiUriResource subject1  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
            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());

            connection.commit();

        } finally {
            connection.close();
        }

    }
View Full Code Here

    }


    @Test
    public void testCreateListExpired() throws Exception {
        LDCachingKiWiPersistenceConnection connection = vpersistence.getConnection();
        try {
            KiWiUriResource subject1  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
            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());
            Assert.assertEquals(1,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);

            connection.commit();

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

            connection.commit();

        } finally {
            connection.close();
        }

    }
View Full Code Here

    public LDCachingKiWiSailConnection(KiWiSailConnection wrappedCon) throws SailException {
        super(wrappedCon);

        this.wrapped = wrappedCon;
        try {
            this.persistence = new LDCachingKiWiPersistenceConnection(wrappedCon.getDatabaseConnection());
        } catch (SQLException e) {
            throw new SailException(e);
        }
    }
View Full Code Here

    };

    @Test
    public void testTablesCreateDrop() throws Exception {
        // test if database exists and has a version
        LDCachingKiWiPersistenceConnection connection = vpersistence.getConnection();
        try {
            Assert.assertThat(connection.getDatabaseTables(), hasItems("ldcache_entries"));
            Assert.assertEquals(3, connection.getDatabaseVersion());

            connection.commit();
        } finally {
            connection.close();
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testCreateListEntries() throws Exception {
        LDCachingKiWiPersistenceConnection connection = vpersistence.getConnection();
        try {
            KiWiUriResource subject1  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
            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());

            connection.commit();

        } finally {
            connection.close();
        }

    }
View Full Code Here

    }


    @Test
    public void testCreateListExpired() throws Exception {
        LDCachingKiWiPersistenceConnection connection = vpersistence.getConnection();
        try {
            KiWiUriResource subject1  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
            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());
            Assert.assertEquals(1,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);

            connection.commit();

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

            connection.commit();

        } finally {
            connection.close();
        }

    }
View Full Code Here

    }


    @Test
    public void testCreateListExpired() throws Exception {
        LDCachingKiWiPersistenceConnection connection = vpersistence.getConnection();
        try {
            KiWiUriResource subject1  = new KiWiUriResource("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
            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());
            Assert.assertEquals(1,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);

            connection.commit();

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

            connection.commit();

        } finally {
            connection.close();
        }

    }
View Full Code Here

    };

    @Test
    public void testTablesCreateDrop() throws Exception {
        // test if database exists and has a version
        LDCachingKiWiPersistenceConnection connection = vpersistence.getConnection();
        try {
            Assert.assertThat(connection.getDatabaseTables(), hasItems("ldcache_entries"));
            Assert.assertEquals(1, connection.getDatabaseVersion());

            connection.commit();
        } finally {
            connection.close();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.marmotta.ldcache.backend.kiwi.persistence.LDCachingKiWiPersistenceConnection

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.