public static SessionFactory buildSessionFactory( Configuration configuration, Repository repository, Map<String, ObjectRepository> objectRepositories) { SessionFactoryImpl sessionFactory = new SessionFactoryImpl(); sessionFactory.setObjectRepositories(objectRepositories); sessionFactory.setConfiguration(configuration); sessionFactory.setRepository(repository); sessionFactory.initialize(); return sessionFactory; }
@Override public void run() { sessionFactory.close(); } });
private Session newSession(Locale locale) { this.locale = locale; session = sessionFactory.openSession(); return session; }
@Before public void init() { Company company = new Company(); company.name = "Example"; company.description = "In English"; Employee employee = new Employee(); employee.age = 30; employee.name = "John Doe"; employee.company = company; repository = new MiniRepository(); sessionFactory = new SessionFactoryImpl() { @Override public Iterable<Locale> getLocales() { return new LocaleIterable(locale, false); } }; sessionFactory.setRepository(repository); DefaultConfiguration configuration = new DefaultConfiguration(TEST.NS, Employee.class, Company.class, EmployeeInfo.class); // configuration.setFetchStrategies(Collections.<FetchStrategy>emptyList()); sessionFactory.setConfiguration(configuration); sessionFactory.initialize(); ids = newSession().saveAll(employee, company); }
public SessionFactoryImpl(Locale locale) { this(Collections.singleton(locale)); setSessionContext(new EmptySessionContext()); }
/** * Create a new RDFBeanTransactionManager instance. */ public RDFBeanTransactionManager(SessionFactoryImpl sessionFactory) { this.sessionContext = new SimpleSessionContext(sessionFactory); sessionFactory.setSessionContext(sessionContext); setRollbackOnCommitFailure(false); }
@Provides @Singleton public SessionFactory createSessionFactory(Configuration configuration, Repository repository) { // TODO : locale handling final SessionFactoryImpl sessionFactory = new SessionFactoryImpl(); sessionFactory.setConfiguration(configuration); sessionFactory.setRepository(repository); sessionFactory.initialize(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { sessionFactory.close(); } }); return sessionFactory; }
@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(); } } }
@After public void tearDown() { sessionFactory.close(); }
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() { sessionFactory = new SessionFactoryImpl(); sessionFactory.setConfiguration(new DefaultConfiguration()); sessionFactory.setRepository(new MiniRepository()); sessionFactory.initialize(); sessionContext = new SimpleSessionContext(sessionFactory); }
@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(); }
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()); }
@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(); }