for ( String xmlFile : xmlFiles ) { try ( InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile ) ) { configuration.addInputStream( is );
private SessionFactoryImplementor buildSessionFactory(List<Class<?>> classesUnderTest, List<String> configFiles) { assert classesUnderTest != null; assert configFiles != null; Configuration cfg = new Configuration(); for ( Class<?> clazz : classesUnderTest ) { cfg.addAnnotatedClass( clazz ); } for ( String configFile : configFiles ) { try ( InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( configFile ) ) { cfg.addInputStream( is ); } catch (IOException e) { throw new IllegalArgumentException( e ); } } return ( SessionFactoryImplementor ) cfg.buildSessionFactory(); }
@Test public void testQuery() { Configuration cfg = new Configuration(); cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); cfg.addInputStream(new ReaderInputStream(new StringReader(NAMED_QUERY_HBM_XML))); SessionFactory sessionFactory = cfg.buildSessionFactory(); sessionFactory.close(); }
cfg.addInputStream( ConfigHelper.getResourceAsStream( resourceName ) ); fail();
cfg.addInputStream( new ByteArrayInputStream( new byte[0] ) ); fail();
@Override public Configuration addInputStream(InputStream xmlInputStream) throws MappingException { super.addInputStream(xmlInputStream); return this; }
public void processConfig(Configuration config) throws IOException, MappingException { for (int i = 0; i < this.mappingLocations.length; i++) { config.addInputStream(this.mappingLocations[i].getInputStream()); } } }
public Ejb3Configuration addInputStream(InputStream xmlInputStream) throws MappingException { Thread thread = null; ClassLoader contextClassLoader = null; if (overridenClassLoader != null) { thread = Thread.currentThread(); contextClassLoader = thread.getContextClassLoader(); thread.setContextClassLoader( overridenClassLoader ); } try { cfg.addInputStream( xmlInputStream ); return this; } finally { if (thread != null) thread.setContextClassLoader( contextClassLoader ); } }
/** * Read mappings from a <tt>URL</tt> * * @param url */ public Configuration addURL(URL url) throws MappingException { if ( log.isDebugEnabled() ) log.debug( "Mapping URL:\n" + url ); try { addInputStream( url.openStream() ); } catch ( Exception e ) { log.error( "Could not configure datastore from URL: " + url , e ); throw new MappingException( "Could not configure datastore from URL: " + url, e ); } return this; }
/** * Read mappings from a particular XML file * * @param xmlFile a path to a file */ public Configuration addFile(File xmlFile) throws MappingException { log.info( "Mapping file: " + xmlFile.getPath() ); try { addInputStream( new FileInputStream( xmlFile ) ); } catch ( Exception e ) { log.error( "Could not configure datastore from file: " + xmlFile.getPath(), e ); throw new MappingException( "Could not configure datastore from file: " + xmlFile.getPath(), e ); } return this; }
/** * Read mappings from an application resource trying different classloaders. * This method will try to load the resource first from the thread context * classloader and then from the classloader that loaded Hibernate. */ public Configuration addResource(String path) throws MappingException { log.info( "Mapping resource: " + path ); InputStream rsrc = Thread.currentThread().getContextClassLoader().getResourceAsStream( path ); if ( rsrc == null ) rsrc = Environment.class.getClassLoader().getResourceAsStream( path ); if ( rsrc == null ) throw new MappingException( "Resource: " + path + " not found" ); try { return addInputStream( rsrc ); } catch ( MappingException me ) { throw new MappingException( "Error reading resource: " + path, me ); } }
/** * Read a mapping from an application resource, using a convention. * The class <tt>foo.bar.Foo</tt> is mapped by the file <tt>foo/bar/Foo.hbm.xml</tt>. * * @param persistentClass the mapped class */ public Configuration addClass(Class persistentClass) throws MappingException { String fileName = persistentClass.getName().replace( '.', '/' ) + ".hbm.xml"; log.info( "Mapping resource: " + fileName ); InputStream rsrc = persistentClass.getClassLoader().getResourceAsStream( fileName ); if ( rsrc == null ) throw new MappingException( "Resource: " + fileName + " not found" ); try { return addInputStream( rsrc ); } catch ( MappingException me ) { throw new MappingException( "Error reading resource: " + fileName, me ); } }
/** * Read mappings from an application resource * * @param path a resource * @param classLoader a <tt>ClassLoader</tt> to use */ public Configuration addResource(String path, ClassLoader classLoader) throws MappingException { log.info( "Mapping resource: " + path ); InputStream rsrc = classLoader.getResourceAsStream( path ); if ( rsrc == null ) throw new MappingException( "Resource: " + path + " not found" ); try { return addInputStream( rsrc ); } catch ( MappingException me ) { throw new MappingException( "Error reading resource: " + path, me ); } }
log.info( "Found mapping documents in jar: " + ze.getName() ); try { addInputStream( jarFile.getInputStream( ze ) );
/** * {@inheritDoc} * @see Initializable#initialize() */ public void initialize() throws InitializationException { this.sessionFactory.getConfiguration().addInputStream(Util.getResourceAsStream(this.mappingPath)); }
/** * static accessor for singleton TransactionalResourceCommandDAO * * @return singleton instance of TransactionalResourceCommandDAO */ public static TransactionalResourceCommandDAO getTransactionalResourceCommandDAO() { if (transactionalResourceCommandDAO == null) { InputStream transactionalResourceCommandMappings = Thread .currentThread() .getContextClassLoader() .getResourceAsStream("TransactionalResourceCommand.hbm.xml"); InputStream xidImplMappings = Thread.currentThread() .getContextClassLoader().getResourceAsStream( "XidImpl.hbm.xml"); Configuration cfg = generateConfiguration(); cfg.setProperty(Environment.DATASOURCE, "java:/datasource/ikasan/ds"); cfg.addInputStream(transactionalResourceCommandMappings); cfg.addInputStream(xidImplMappings); transactionalResourceCommandDAO = new HibernateTransactionalResourceCommandDAO( cfg.buildSessionFactory()); } return transactionalResourceCommandDAO; }
LOG.foundMappingDocument( ze.getName() ); try { addInputStream( jarFile.getInputStream( ze ) );
for (String mapping : this.mappingResources) { Resource resource = new ClassPathResource(mapping.trim(), this.beanClassLoader); configuration.addInputStream(resource.getInputStream());
cfgs[sfIndex].addInputStream( is );
config.addInputStream(transpile(new ByteArrayInputStream(is)));