private Session newSession(Locale locale) { this.locale = locale; session = sessionFactory.openSession(); return session; }
@Override public <T> T execute(SessionCallback<T> cb) { if (sessionContext.getCurrentSession() != null) { return cb.doInSession(sessionContext.getCurrentSession()); } else { Session session = openSession(); try { return cb.doInSession(session); } finally { session.close(); } } }
public void export() { SessionFactoryImpl sessionFactory = new SessionFactoryImpl(); sessionFactory.setConfiguration(new DefaultConfiguration(RDFSClass.class.getPackage(), OWLClass.class.getPackage())); sessionFactory.setRepository(repository); sessionFactory.initialize(); Session session = sessionFactory.openSession(); if (ontology != null) { Ontology ont = new Ontology(new UID(ontology)); if (ontologyImports != null) { for (String oimport : ontologyImports) { ont.addImport(new Ontology(new UID(oimport))); } } session.save(ont); } Map<UID, RDFSResource> resources = new HashMap<UID, RDFSResource>(); resources.put(RDF.List, new RDFSClass<RDFSResource>(RDF.List)); resources.put(RDF.first, new RDFProperty(RDF.first)); resources.put(RDF.rest, new RDFProperty(RDF.rest)); resources.put(RDF.type, new RDFProperty(RDF.type)); resources.put(RDFS.label, new RDFProperty(RDFS.label)); resources.put(RDFS.comment, new RDFProperty(RDFS.comment)); resources.put(RDFS.Resource, new RDFSClass<Object>(RDFS.Resource)); // process classes for (MappedClass mappedClass : configuration.getMappedClasses()) { processClass(session, mappedClass.getJavaClass(), resources); } // save resources session.saveAll(resources.values().toArray()); }
public static Session openSession(Repository repository, Iterable<Locale> locales, Configuration configuration) { SessionFactoryImpl sessionFactory = new SessionFactoryImpl(locales); sessionFactory.setConfiguration(configuration); sessionFactory.setRepository(repository); sessionFactory.initialize(); return sessionFactory.openSession(); }
session = sessionFactory.openSession(); project = session.get(Project.class, _project); Person person = session.get(Person.class, _person);
@Before public void setUp() { Configuration configuration = new DefaultConfiguration(TEST.NS, Entity.class); Repository repository = new MiniRepository(); sessionFactory = new SessionFactoryImpl(); sessionFactory.setConfiguration(configuration); sessionFactory.setRepository(repository); sessionFactory.initialize(); Session session = sessionFactory.openSession(); for (int i = 0; i < 10; i++) { session.save(new Entity()); } session.close(); }
@Before public void setUp() { Configuration configuration = new DefaultConfiguration(TEST.NS, Entity.class); Repository repository = new MiniRepository(); sessionFactory = new SessionFactoryImpl(); sessionFactory.setConfiguration(configuration); sessionFactory.setRepository(repository); sessionFactory.initialize(); Session session = sessionFactory.openSession(); for (int i = 0; i < 10; i++) { session.save(new Entity()); } session.close(); }
@Before public void setUp() throws IOException { sessionFactory = new SessionFactoryImpl(); sessionFactory.setConfiguration(new DefaultConfiguration(User.class)); sessionFactory.setRepository(new MiniRepository()); sessionFactory.initialize(); Session session = sessionFactory.openSession(); session.save(new User("Anton", "Bruxner")); session.save(new User("John", "Smith")); session.save(new User("Zoe", "Ark")); session.save(new User("Chris", "Rock")); session.save(new User("Bernard", "Shaw")); session.close(); }
@Before public void setUp() { repository = new MiniRepository(); configuration = new DefaultConfiguration(TEST.NS, Project.class, Person.class); sessionFactory = new SessionFactoryImpl(); sessionFactory.setRepository(repository); sessionFactory.setConfiguration(configuration); sessionFactory.initialize(); repository.add( new STMT(_project, RDF.type, new UID(TEST.NS, "Project")), new STMT(_project, _name, new LIT("TestProject")), new STMT(_project, _created, new LIT(CREATED.toString(), XSD.date)), new STMT(_person, RDF.type, new UID(TEST.NS, "Person")), new STMT(_person, _name, new LIT("Foo Bar")) ); session = sessionFactory.openSession(); }