Package org.openrdf.sail

Examples of org.openrdf.sail.SailConnection


        try {
            TweetStore store = new TweetStore(sail);
            store.initialize();
            try {
                final SailConnection sc = sail.getConnection();
                try {
                    final TweetPersister p = new TweetPersister(store, null);

                    Handler<Tweet> h = new Handler<Tweet>() {
                        public boolean isOpen() {
                            return p.isOpen();
                        }

                        public void handle(final Tweet tweet) throws HandlerException {
                            try {
                                sc.clear();
                                sc.commit();
                                sc.begin();
                            } catch (SailException e) {
                                throw new HandlerException(e);
                            }
                            p.handle(tweet);
                        }
                    };

                    stressTest(h, 1000);
                } finally {
                    sc.close();
                }
            } finally {
                store.shutDown();
            }
        } finally {
View Full Code Here


        try {
            TweetStore store = new TweetStore(sail);
            store.initialize();
            try {
                final SailConnection sc = baseSail.getConnection();
                try {
                    final TweetPersister p = new TweetPersister(store, null);

                    Handler<Tweet> h = new Handler<Tweet>() {
                        public boolean isOpen() {
                            return p.isOpen();
                        }

                        public void handle(final Tweet tweet) throws HandlerException {
                            try {
                                sc.clear();
                                sc.commit();
                                sc.begin();
                            } catch (SailException e) {
                                throw new HandlerException(e);
                            }
                            p.handle(tweet);
                        }
                    };

                    stressTest(h, 1000);
                } finally {
                    sc.close();
                }
            } finally {
                store.shutDown();
            }
        } finally {
View Full Code Here

                        TweetStore store = new TweetStore(sail);
                        store.doNotRefreshCoreMetadata();
                        store.initialize();
                        try {
                            final SailConnection tc = tSail.getConnection();
                            try {
                                final TweetPersister p = new TweetPersister(store, null);

                                Handler<Tweet> h = new Handler<Tweet>() {
                                    public boolean isOpen() {
                                        return p.isOpen();
                                    }

                                    public void handle(final Tweet tweet) throws HandlerException {
                                        try {
                                            tc.clear();
                                            tc.commit();
                                            tc.begin();
                                        } catch (SailException e) {
                                            throw new HandlerException(e);
                                        }

                                        p.handle(tweet);
                                    }
                                };

                                stressTest(h, 100);
                            } finally {
                                tc.close();
                            }
                        } finally {
                            store.shutDown();
                        }
                    } finally {
View Full Code Here

            try {
                TweetStore store = new TweetStore(sail);
                store.initialize();

                try {
                    final SailConnection tc = transientSail.getConnection();

                    try {
                        tc.begin();
                        final TweetPersister p = new TweetPersister(store, null);

                        Handler<Tweet> h = new Handler<Tweet>() {
                            public boolean isOpen() {
                                return p.isOpen();
                            }

                            public void handle(final Tweet tweet) throws HandlerException {
                                try {
                                    tc.clear();
                                    tc.commit();
                                    tc.begin();
                                } catch (SailException e) {
                                    throw new HandlerException(e);
                                }
                                p.handle(tweet);
                            }
                        };

                        stressTest(h, 1000);
                    } finally {
                        tc.rollback();
                        tc.close();
                    }
                } finally {
                    store.shutDown();
                }
            } finally {
View Full Code Here

                store.doNotRefreshCoreMetadata();
                store.initialize();

                try {
                    // A connection with which to repeatedly clear the working store
                    final SailConnection c = workingSail.getConnection();

                    try {
                        // Offline persister
                        final TweetPersister p = new TweetPersister(store, null);

                        try {
                            Handler<Tweet> h = new Handler<Tweet>() {
                                public boolean isOpen() {
                                    return p.isOpen();
                                }

                                public void handle(final Tweet tweet) throws HandlerException {
                                    try {
                                        c.clear();
                                        c.commit();
                                        c.begin();
                                    } catch (SailException e) {
                                        throw new HandlerException(e);
                                    }

                                    p.handle(tweet);
                                }
                            };

                            stressTest(h, 1000);
                        } finally {
                            p.close();
                        }
                    } finally {
                        c.close();
                    }
                } finally {
                    store.shutDown();
                }
            } finally {
View Full Code Here

        if (null != p) {
            LOGGER.fine("deleting tweet " + tweet.getId());

            try {
                SailConnection c = storeConnection.getSailConnection();
                try {
                    c.begin();
                    // TODO: remove only from the authoritative graph
                    c.removeStatements(uriOf(p), null, null);

                    Graph g = p.getEmbedsKnowledge();
                    if (null != g) {
                        c.removeStatements(null, null, null, uriOf(g));
                    }

                    c.commit();
                } finally {
                    c.rollback();
                    c.close();
                }
            } catch (SailException e) {
                throw new HandlerException(e);
            }
        }
View Full Code Here

    public void preprocessingHook() throws Exception {
        TweetStore store = TweetStore.getInstance();
        TweetStoreConnection c = store.createConnection();
        try {
            ValueFactory vf = store.getSail().getValueFactory();
            SailConnection sc = c.getSailConnection();

            long id = Long.valueOf(selfURI.substring(selfURI.lastIndexOf('/') + 1, selfURI.lastIndexOf('.')));
            User user = new User(id);
            URI personURI = vf.createURI(PersistenceContext.uriOf(new Person(user)));

            // check timestamp
            long lastUpdate = -1;
            CloseableIteration<? extends Statement, SailException> iter
                    = sc.getStatements(personURI, TwitlogicVocabulary.lastUpdatedAt, null, false);
            try {
                if (iter.hasNext()) {
                    lastUpdate = ((Literal) iter.next().getObject()).calendarValue().toGregorianCalendar().getTime().getTime();
                }
            } finally {
                iter.close();
            }

            long now = System.currentTimeMillis();
            if (-1 == lastUpdate || (expireTime > 0 && now - lastUpdate > expireTime)) {
                LOGGER.info((0 == lastUpdate ? "setting" : "updating") + " followees of " + personURI);

                // fetch followees
                TwitterClient client = store.getTwitterClient();
                List<User> followees = client.getFollowees(user, followeeLimit);

                URI foafKnows = vf.createURI(FOAF.KNOWS);

                // persist self and foaf:knows edges
                sc.removeStatements(personURI, foafKnows, null);
                for (User f : followees) {
                    sc.addStatement(personURI, foafKnows, vf.createURI(PersistenceContext.uriOf(new Person(f))));
                }

                // update timestamp
                GregorianCalendar cal = new GregorianCalendar();
                cal.setTime(new Date(now));
                Literal obj = sail.getValueFactory().createLiteral(
                        DATATYPE_FACTORY.newXMLGregorianCalendar(cal));
                sc.removeStatements(personURI, TwitlogicVocabulary.lastUpdatedAt, null);
                sc.addStatement(personURI, TwitlogicVocabulary.lastUpdatedAt, obj);

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

    @Before
    public void setUp() throws Exception {
        modelConnection = getTestModel().createConnection();
        comparator = modelConnection.getComparator();

        SailConnection sc = getTestSail().getConnection();

        try {
            sc.begin();
            sc.clear();
            sc.commit();
        } finally {
            sc.close();
        }
    }
View Full Code Here

            sail = new MemoryStore();

            try {
                sail.initialize();

                SailConnection sc = sail.getConnection();
                try {
                    sc.begin();
                    // Define some common namespaces
                    sc.setNamespace("rdf", RDF.NAMESPACE);
                    sc.setNamespace("rdfs", RDFS.NAMESPACE);
                    sc.setNamespace("xsd", XMLSchema.NAMESPACE);
                    sc.commit();
                } finally {
                    sc.close();
                }
            } catch (SailException e) {
                throw new RippleException(e);
            }
        }
View Full Code Here

            add(sail, is, "", RDFFormat.TURTLE);
        } catch (Exception e) {
        }
        is.close();

        SailConnection sc = sail.getConnection();
        try {
            sc.begin();
            int count = countStatements(sc, null);
            assertEquals(1, count);
        } finally {
            sc.rollback();
            sc.close();
        }
    }
View Full Code Here

TOP

Related Classes of org.openrdf.sail.SailConnection

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.