org.hibernate.cfg.Configuration.addInputStream()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(197)

本文整理了Java中org.hibernate.cfg.Configuration.addInputStream()方法的一些代码示例,展示了Configuration.addInputStream()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.addInputStream()方法的具体详情如下:
包路径:org.hibernate.cfg.Configuration
类名称:Configuration
方法名:addInputStream

Configuration.addInputStream介绍

[英]Read mappings from an java.io.InputStream.
[中]从java应用程序读取映射。木卫一。输入流。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

for ( String xmlFile : xmlFiles ) {
  try ( InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile ) ) {
    configuration.addInputStream( is );

代码示例来源:origin: hibernate/hibernate-orm

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();
}

代码示例来源:origin: hibernate/hibernate-orm

@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();
}

代码示例来源:origin: hibernate/hibernate-orm

cfg.addInputStream( ConfigHelper.getResourceAsStream( resourceName ) );
fail();

代码示例来源:origin: hibernate/hibernate-orm

cfg.addInputStream( new ByteArrayInputStream( new byte[0] ) );
fail();

代码示例来源:origin: babyfish-ct/babyfish

@Override
public Configuration addInputStream(InputStream xmlInputStream)
    throws MappingException {
  super.addInputStream(xmlInputStream);
  return this;
}

代码示例来源:origin: org.sakaiproject.metaobj/sakai-metaobj-tool-lib

public void processConfig(Configuration config) throws IOException, MappingException {
   for (int i = 0; i < this.mappingLocations.length; i++) {
     config.addInputStream(this.mappingLocations[i].getInputStream());
   }
  }
}

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.ejb

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 );
  }
}

代码示例来源:origin: hibernate/hibernate

/**
 * 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;
}

代码示例来源:origin: hibernate/hibernate

/**
 * 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;
}

代码示例来源:origin: hibernate/hibernate

/**
 * 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 );
  }
}

代码示例来源:origin: hibernate/hibernate

/**
 * 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 );
  }
}

代码示例来源:origin: hibernate/hibernate

/**
 * 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 );
  }
}

代码示例来源:origin: hibernate/hibernate

log.info( "Found mapping documents in jar: " + ze.getName() );
try {
  addInputStream( jarFile.getInputStream( ze ) );

代码示例来源:origin: com.xpn.xwiki.platform/xwiki-core

/**
 * {@inheritDoc}
 * @see Initializable#initialize()
 */
public void initialize() throws InitializationException
{
  this.sessionFactory.getConfiguration().addInputStream(Util.getResourceAsStream(this.mappingPath));
}

代码示例来源:origin: org.ikasan/ikasan-connector-basefiletransfer

/**
 * 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;
}

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.core

LOG.foundMappingDocument( ze.getName() );
try {
  addInputStream( jarFile.getInputStream( ze ) );

代码示例来源:origin: org.beangle.commons/beangle-commons-orm

for (String mapping : this.mappingResources) {
 Resource resource = new ClassPathResource(mapping.trim(), this.beanClassLoader);
 configuration.addInputStream(resource.getInputStream());

代码示例来源:origin: hibernate/hibernate-search

cfgs[sfIndex].addInputStream( is );

代码示例来源:origin: com.atlassian.hibernate/hibernate.adapter

config.addInputStream(transpile(new ByteArrayInputStream(is)));

相关文章

Configuration类方法