Search in sources :

Example 1 with ReaderInputStream

use of org.hibernate.engine.jdbc.ReaderInputStream in project hibernate-orm by hibernate.

the class QueryReturnTest method testQueryReturn.

@Test
public void testQueryReturn() {
    StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder().applySetting("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    StandardServiceRegistry standardServiceRegistry = serviceRegistryBuilder.build();
    MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
    try {
        metadataSources.addInputStream(new ReaderInputStream(new StringReader(QUERY_RETURN_HBM_XML)));
        Metadata metadata = metadataSources.buildMetadata();
        NamedSQLQueryDefinition myQuery = metadata.getNamedNativeQueryDefinition("myQuery");
        Assert.assertNotNull(myQuery);
        NativeSQLQueryReturn[] myQueryReturns = myQuery.getQueryReturns();
        Assert.assertNotNull(myQueryReturns);
        Assert.assertEquals(1, myQueryReturns.length);
        Assert.assertTrue(NativeSQLQueryRootReturn.class.isInstance(myQueryReturns[0]));
        NativeSQLQueryRootReturn myQueryRootReturn = (NativeSQLQueryRootReturn) myQueryReturns[0];
        Assert.assertEquals("e", myQueryRootReturn.getAlias());
        Assert.assertEquals("org.hibernate.test.hbm.query.QueryReturnTest$Bar", myQueryRootReturn.getReturnEntityName());
    } finally {
        if (standardServiceRegistry instanceof StandardServiceRegistryImpl) {
            ((StandardServiceRegistryImpl) standardServiceRegistry).destroy();
        }
    }
}
Also used : ReaderInputStream(org.hibernate.engine.jdbc.ReaderInputStream) NamedSQLQueryDefinition(org.hibernate.engine.spi.NamedSQLQueryDefinition) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) NativeSQLQueryReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn) MetadataSources(org.hibernate.boot.MetadataSources) StringReader(java.io.StringReader) Metadata(org.hibernate.boot.Metadata) NativeSQLQueryRootReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 2 with ReaderInputStream

use of org.hibernate.engine.jdbc.ReaderInputStream in project hibernate-orm by hibernate.

the class ClassCommentTest method testClassComment.

@Test
public void testClassComment() {
    StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder().applySetting("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    MetadataSources metadataSources = new MetadataSources(serviceRegistryBuilder.build());
    metadataSources.addInputStream(new ReaderInputStream(new StringReader(CLASS_COMMENT_HBM_XML)));
    Metadata metadata = metadataSources.buildMetadata();
    PersistentClass pc = metadata.getEntityBinding("org.hibernate.test.hbm.Foo");
    Assert.assertNotNull(pc);
    Table table = pc.getTable();
    Assert.assertNotNull(table);
    Assert.assertEquals("This is class 'Foo' with property 'bar'.", table.getComment());
}
Also used : ReaderInputStream(org.hibernate.engine.jdbc.ReaderInputStream) Table(org.hibernate.mapping.Table) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) StringReader(java.io.StringReader) Metadata(org.hibernate.boot.Metadata) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 3 with ReaderInputStream

use of org.hibernate.engine.jdbc.ReaderInputStream in project hibernate-orm by hibernate.

the class NamedQueryTest method testQuery.

@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();
}
Also used : SessionFactory(org.hibernate.SessionFactory) ReaderInputStream(org.hibernate.engine.jdbc.ReaderInputStream) Configuration(org.hibernate.cfg.Configuration) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

StringReader (java.io.StringReader)3 ReaderInputStream (org.hibernate.engine.jdbc.ReaderInputStream)3 Test (org.junit.Test)3 Metadata (org.hibernate.boot.Metadata)2 MetadataSources (org.hibernate.boot.MetadataSources)2 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)2 SessionFactory (org.hibernate.SessionFactory)1 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)1 StandardServiceRegistryImpl (org.hibernate.boot.registry.internal.StandardServiceRegistryImpl)1 Configuration (org.hibernate.cfg.Configuration)1 NativeSQLQueryReturn (org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn)1 NativeSQLQueryRootReturn (org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn)1 NamedSQLQueryDefinition (org.hibernate.engine.spi.NamedSQLQueryDefinition)1 PersistentClass (org.hibernate.mapping.PersistentClass)1 Table (org.hibernate.mapping.Table)1