Search in sources :

Example 1 with Oracle8iDialect

use of org.hibernate.dialect.Oracle8iDialect in project hibernate-orm by hibernate.

the class ReadWriteExpressionChange method shouldRespectWriteExpression.

@Test
public void shouldRespectWriteExpression() {
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    List resultList = em.createNativeQuery("select size_in_cm from t_staff_AUD where id =" + id).getResultList();
    Assert.assertEquals(1, resultList.size());
    Double sizeInCm = null;
    if (getDialect() instanceof Oracle8iDialect) {
        sizeInCm = ((BigDecimal) resultList.get(0)).doubleValue();
    } else {
        sizeInCm = (Double) resultList.get(0);
    }
    em.getTransaction().commit();
    Assert.assertEquals(HEIGHT_CENTIMETERS, sizeInCm.doubleValue(), 0.00000001);
}
Also used : EntityManager(javax.persistence.EntityManager) List(java.util.List) Oracle8iDialect(org.hibernate.dialect.Oracle8iDialect) Test(org.junit.Test)

Example 2 with Oracle8iDialect

use of org.hibernate.dialect.Oracle8iDialect in project hibernate-orm by hibernate.

the class StandardDialectResolver method resolveDialect.

@Override
public Dialect resolveDialect(DialectResolutionInfo info) {
    final String databaseName = info.getDatabaseName();
    if ("CUBRID".equalsIgnoreCase(databaseName)) {
        return new CUBRIDDialect();
    }
    if ("HSQL Database Engine".equals(databaseName)) {
        return new HSQLDialect();
    }
    if ("H2".equals(databaseName)) {
        return new H2Dialect();
    }
    if ("MySQL".equals(databaseName)) {
        final int majorVersion = info.getDatabaseMajorVersion();
        if (majorVersion >= 5) {
            return new MySQL5Dialect();
        }
        return new MySQLDialect();
    }
    if ("PostgreSQL".equals(databaseName)) {
        final int majorVersion = info.getDatabaseMajorVersion();
        final int minorVersion = info.getDatabaseMinorVersion();
        if (majorVersion == 9) {
            if (minorVersion >= 4) {
                return new PostgreSQL94Dialect();
            } else if (minorVersion >= 2) {
                return new PostgreSQL92Dialect();
            }
            return new PostgreSQL9Dialect();
        }
        if (majorVersion == 8 && minorVersion >= 2) {
            return new PostgreSQL82Dialect();
        }
        return new PostgreSQL81Dialect();
    }
    if ("EnterpriseDB".equals(databaseName)) {
        return new PostgresPlusDialect();
    }
    if ("Apache Derby".equals(databaseName)) {
        final int majorVersion = info.getDatabaseMajorVersion();
        final int minorVersion = info.getDatabaseMinorVersion();
        if (majorVersion > 10 || (majorVersion == 10 && minorVersion >= 7)) {
            return new DerbyTenSevenDialect();
        } else if (majorVersion == 10 && minorVersion == 6) {
            return new DerbyTenSixDialect();
        } else if (majorVersion == 10 && minorVersion == 5) {
            return new DerbyTenFiveDialect();
        } else {
            return new DerbyDialect();
        }
    }
    if ("ingres".equalsIgnoreCase(databaseName)) {
        final int majorVersion = info.getDatabaseMajorVersion();
        final int minorVersion = info.getDatabaseMinorVersion();
        switch(majorVersion) {
            case 9:
                if (minorVersion > 2) {
                    return new Ingres9Dialect();
                }
                return new IngresDialect();
            case 10:
                return new Ingres10Dialect();
            default:
                LOG.unknownIngresVersion(majorVersion);
        }
        return new IngresDialect();
    }
    if (databaseName.startsWith("Microsoft SQL Server")) {
        final int majorVersion = info.getDatabaseMajorVersion();
        switch(majorVersion) {
            case 8:
                {
                    return new SQLServerDialect();
                }
            case 9:
                {
                    return new SQLServer2005Dialect();
                }
            case 10:
                {
                    return new SQLServer2008Dialect();
                }
            case 11:
            case 12:
            case 13:
                {
                    return new SQLServer2012Dialect();
                }
            default:
                {
                    if (majorVersion < 8) {
                        LOG.unknownSqlServerVersion(majorVersion, SQLServerDialect.class);
                        return new SQLServerDialect();
                    } else {
                        // assume `majorVersion > 13`
                        LOG.unknownSqlServerVersion(majorVersion, SQLServer2012Dialect.class);
                        return new SQLServer2012Dialect();
                    }
                }
        }
    }
    if ("Sybase SQL Server".equals(databaseName) || "Adaptive Server Enterprise".equals(databaseName)) {
        return new SybaseASE15Dialect();
    }
    if (databaseName.startsWith("Adaptive Server Anywhere")) {
        return new SybaseAnywhereDialect();
    }
    if ("Informix Dynamic Server".equals(databaseName)) {
        return new InformixDialect();
    }
    if ("DB2 UDB for AS/400".equals(databaseName)) {
        return new DB2400Dialect();
    }
    if (databaseName.startsWith("DB2/")) {
        return new DB2Dialect();
    }
    if ("Oracle".equals(databaseName)) {
        final int majorVersion = info.getDatabaseMajorVersion();
        switch(majorVersion) {
            case 12:
                return new Oracle12cDialect();
            case 11:
            // fall through
            case 10:
                return new Oracle10gDialect();
            case 9:
                return new Oracle9iDialect();
            case 8:
                return new Oracle8iDialect();
            default:
                LOG.unknownOracleVersion(majorVersion);
        }
        return new Oracle8iDialect();
    }
    if ("HDB".equals(databaseName)) {
        // SAP recommends defaulting to column store.
        return new HANAColumnStoreDialect();
    }
    if (databaseName.startsWith("Firebird")) {
        return new FirebirdDialect();
    }
    return null;
}
Also used : MySQL5Dialect(org.hibernate.dialect.MySQL5Dialect) SybaseASE15Dialect(org.hibernate.dialect.SybaseASE15Dialect) H2Dialect(org.hibernate.dialect.H2Dialect) PostgreSQL92Dialect(org.hibernate.dialect.PostgreSQL92Dialect) IngresDialect(org.hibernate.dialect.IngresDialect) DerbyTenSixDialect(org.hibernate.dialect.DerbyTenSixDialect) Oracle10gDialect(org.hibernate.dialect.Oracle10gDialect) PostgreSQL94Dialect(org.hibernate.dialect.PostgreSQL94Dialect) FirebirdDialect(org.hibernate.dialect.FirebirdDialect) PostgreSQL82Dialect(org.hibernate.dialect.PostgreSQL82Dialect) PostgreSQL81Dialect(org.hibernate.dialect.PostgreSQL81Dialect) MySQLDialect(org.hibernate.dialect.MySQLDialect) PostgreSQL9Dialect(org.hibernate.dialect.PostgreSQL9Dialect) SybaseAnywhereDialect(org.hibernate.dialect.SybaseAnywhereDialect) DerbyTenSevenDialect(org.hibernate.dialect.DerbyTenSevenDialect) DB2400Dialect(org.hibernate.dialect.DB2400Dialect) Ingres9Dialect(org.hibernate.dialect.Ingres9Dialect) HSQLDialect(org.hibernate.dialect.HSQLDialect) HANAColumnStoreDialect(org.hibernate.dialect.HANAColumnStoreDialect) PostgresPlusDialect(org.hibernate.dialect.PostgresPlusDialect) DerbyDialect(org.hibernate.dialect.DerbyDialect) SQLServerDialect(org.hibernate.dialect.SQLServerDialect) Oracle9iDialect(org.hibernate.dialect.Oracle9iDialect) DerbyTenFiveDialect(org.hibernate.dialect.DerbyTenFiveDialect) DB2Dialect(org.hibernate.dialect.DB2Dialect) Oracle8iDialect(org.hibernate.dialect.Oracle8iDialect) Ingres10Dialect(org.hibernate.dialect.Ingres10Dialect) SQLServer2012Dialect(org.hibernate.dialect.SQLServer2012Dialect) Oracle12cDialect(org.hibernate.dialect.Oracle12cDialect) SQLServer2005Dialect(org.hibernate.dialect.SQLServer2005Dialect) InformixDialect(org.hibernate.dialect.InformixDialect) CUBRIDDialect(org.hibernate.dialect.CUBRIDDialect) SQLServer2008Dialect(org.hibernate.dialect.SQLServer2008Dialect)

Example 3 with Oracle8iDialect

use of org.hibernate.dialect.Oracle8iDialect in project hibernate-orm by hibernate.

the class CriteriaQueryTest method testSubselect.

@Test
@SkipForDialect(value = SybaseASE15Dialect.class, strictMatching = true, jiraKey = "HHH-3032", comment = "I was told this is fixed in Sybase ASE 15.7")
public void testSubselect() {
    Session session = openSession();
    Transaction t = session.beginTransaction();
    Course course = new Course();
    course.setCourseCode("HIB");
    course.setDescription("Hibernate Training");
    session.persist(course);
    Student gavin = new Student();
    gavin.setName("Gavin King");
    gavin.setStudentNumber(232);
    session.persist(gavin);
    Enrolment enrolment2 = new Enrolment();
    enrolment2.setCourse(course);
    enrolment2.setCourseCode(course.getCourseCode());
    enrolment2.setSemester((short) 3);
    enrolment2.setYear((short) 1998);
    enrolment2.setStudent(gavin);
    enrolment2.setStudentNumber(gavin.getStudentNumber());
    gavin.getEnrolments().add(enrolment2);
    session.persist(enrolment2);
    DetachedCriteria dc = DetachedCriteria.forClass(Student.class).add(Property.forName("studentNumber").eq(new Long(232))).setProjection(Property.forName("name"));
    session.createCriteria(Student.class).add(Subqueries.propertyEqAll("name", dc)).list();
    session.createCriteria(Student.class).add(Subqueries.exists(dc)).list();
    session.createCriteria(Student.class).add(Property.forName("name").eqAll(dc)).list();
    session.createCriteria(Student.class).add(Subqueries.in("Gavin King", dc)).list();
    DetachedCriteria dc2 = DetachedCriteria.forClass(Student.class, "st").add(Property.forName("st.studentNumber").eqProperty("e.studentNumber")).setProjection(Property.forName("name"));
    session.createCriteria(Enrolment.class, "e").add(Subqueries.eq("Gavin King", dc2)).list();
    DetachedCriteria dc3 = DetachedCriteria.forClass(Student.class, "st").createCriteria("enrolments").createCriteria("course").add(Property.forName("description").eq("Hibernate Training")).setProjection(Property.forName("st.name"));
    session.createCriteria(Enrolment.class, "e").add(Subqueries.eq("Gavin King", dc3)).list();
    DetachedCriteria dc4 = DetachedCriteria.forClass(Student.class, "st").setProjection(Property.forName("name").as("stname"));
    dc4.getExecutableCriteria(session).list();
    // SQL Server and Oracle doesn't normally support ORDER BY in subqueries...
    if (!(getDialect() instanceof SQLServerDialect) && !(getDialect() instanceof Oracle8iDialect)) {
        dc4.getExecutableCriteria(session).addOrder(Order.asc("stname")).list();
    }
    session.createCriteria(Enrolment.class, "e").add(Subqueries.eq("Gavin King", dc4)).list();
    session.delete(enrolment2);
    session.delete(gavin);
    session.delete(course);
    t.commit();
    session.close();
}
Also used : SQLServerDialect(org.hibernate.dialect.SQLServerDialect) Transaction(org.hibernate.Transaction) DetachedCriteria(org.hibernate.criterion.DetachedCriteria) Session(org.hibernate.Session) Oracle8iDialect(org.hibernate.dialect.Oracle8iDialect) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 4 with Oracle8iDialect

use of org.hibernate.dialect.Oracle8iDialect in project hibernate-orm by hibernate.

the class ASTParserLoadingTest method testStr.

@Test
public void testStr() {
    Session session = openSession();
    Transaction txn = session.beginTransaction();
    Animal an = new Animal();
    an.setBodyWeight(123.45f);
    session.persist(an);
    String str = (String) session.createQuery("select str(an.bodyWeight) from Animal an where str(an.bodyWeight) like '%1%'").uniqueResult();
    if ((getDialect() instanceof DB2Dialect || getDialect() instanceof TeradataDialect) && !(getDialect() instanceof DerbyDialect)) {
        assertTrue(str.startsWith("1.234"));
    } else //noinspection deprecation
    if (getDialect() instanceof SybaseDialect || getDialect() instanceof Sybase11Dialect || getDialect() instanceof SybaseASE15Dialect || getDialect() instanceof SybaseAnywhereDialect || getDialect() instanceof SQLServerDialect) {
        // str(val) on sybase assumes a default of 10 characters with no decimal point or decimal values
        // str(val) on sybase result is right-justified
        assertEquals(str.length(), 10);
        assertTrue(str.endsWith("123"));
        str = (String) session.createQuery("select str(an.bodyWeight, 8, 3) from Animal an where str(an.bodyWeight, 8, 3) like '%1%'").uniqueResult();
        assertEquals(str.length(), 8);
        assertTrue(str.endsWith("123.450"));
    } else {
        assertTrue(str.startsWith("123.4"));
    }
    //noinspection deprecation
    if (!(getDialect() instanceof SybaseDialect) && !(getDialect() instanceof Sybase11Dialect) && !(getDialect() instanceof SybaseASE15Dialect) && !(getDialect() instanceof SybaseAnywhereDialect) && !(getDialect() instanceof SQLServerDialect || getDialect() instanceof TeradataDialect)) {
        // In TransactSQL (the variant spoken by Sybase and SQLServer), the str() function
        // is explicitly intended for numeric values only...
        String dateStr1 = (String) session.createQuery("select str(current_date) from Animal").uniqueResult();
        String dateStr2 = (String) session.createQuery("select str(year(current_date))||'-'||str(month(current_date))||'-'||str(day(current_date)) from Animal").uniqueResult();
        System.out.println(dateStr1 + '=' + dateStr2);
        if (!(getDialect() instanceof Oracle8iDialect)) {
            //Oracle renders the name of the month :(
            String[] dp1 = StringHelper.split("-", dateStr1);
            String[] dp2 = StringHelper.split("-", dateStr2);
            for (int i = 0; i < 3; i++) {
                if (dp1[i].startsWith("0")) {
                    dp1[i] = dp1[i].substring(1);
                }
                assertEquals(dp1[i], dp2[i]);
            }
        }
    }
    session.delete(an);
    txn.commit();
    session.close();
}
Also used : DerbyDialect(org.hibernate.dialect.DerbyDialect) SybaseASE15Dialect(org.hibernate.dialect.SybaseASE15Dialect) SQLServerDialect(org.hibernate.dialect.SQLServerDialect) SybaseDialect(org.hibernate.dialect.SybaseDialect) DB2Dialect(org.hibernate.dialect.DB2Dialect) Oracle8iDialect(org.hibernate.dialect.Oracle8iDialect) SybaseAnywhereDialect(org.hibernate.dialect.SybaseAnywhereDialect) Transaction(org.hibernate.Transaction) TeradataDialect(org.hibernate.dialect.TeradataDialect) Sybase11Dialect(org.hibernate.dialect.Sybase11Dialect) Session(org.hibernate.Session) Test(org.junit.Test)

Example 5 with Oracle8iDialect

use of org.hibernate.dialect.Oracle8iDialect in project hibernate-orm by hibernate.

the class FooBarTest method testScrollableIterator.

@Test
public void testScrollableIterator() throws Exception {
    // skip if not one of these named dialects
    boolean match = getDialect() instanceof DB2Dialect || getDialect() instanceof SybaseDialect || getDialect() instanceof HSQLDialect || // 9i/10g too because of inheritence...
    getDialect() instanceof Oracle8iDialect;
    if (!match) {
        return;
    }
    Session s = openSession();
    Transaction txn = s.beginTransaction();
    s.save(new Foo());
    s.save(new Foo());
    s.save(new Foo());
    s.save(new Bar());
    Query query = s.createQuery("select f, f.integer from Foo f");
    assertTrue(query.getReturnTypes().length == 2);
    ScrollableResults iter = query.scroll();
    assertTrue(iter.next());
    assertTrue(iter.scroll(1));
    FooProxy f2 = (FooProxy) iter.get()[0];
    assertTrue(f2 != null);
    assertTrue(iter.scroll(-1));
    Object f1 = iter.get(0);
    iter.next();
    assertTrue(f1 != null && iter.get(0) == f2);
    iter.getInteger(1);
    assertTrue(!iter.scroll(100));
    assertTrue(iter.first());
    assertTrue(iter.scroll(3));
    Object f4 = iter.get(0);
    assertTrue(f4 != null);
    assertTrue(!iter.next());
    assertTrue(iter.first());
    assertTrue(iter.get(0) == f1);
    assertTrue(iter.last());
    assertTrue(iter.get(0) == f4);
    assertTrue(iter.previous());
    txn.commit();
    s.close();
    s = openSession();
    txn = s.beginTransaction();
    query = s.createQuery("select f, f.integer from Foo f");
    assertTrue(query.getReturnTypes().length == 2);
    iter = query.scroll();
    assertTrue(iter.next());
    assertTrue(iter.scroll(1));
    f2 = (FooProxy) iter.get()[0];
    assertTrue(f2 != null);
    assertTrue(f2.getString() != null && f2.getComponent().getImportantDates().length > 0);
    assertTrue(iter.scroll(-1));
    f1 = iter.get(0);
    iter.next();
    assertTrue(f1 != null && iter.get(0) == f2);
    iter.getInteger(1);
    assertTrue(!iter.scroll(100));
    assertTrue(iter.first());
    assertTrue(iter.scroll(3));
    f4 = iter.get(0);
    assertTrue(f4 != null);
    assertTrue(!iter.next());
    assertTrue(iter.first());
    assertTrue(iter.get(0) == f1);
    assertTrue(iter.last());
    assertTrue(iter.get(0) == f4);
    assertTrue(iter.previous());
    int i = 0;
    for (Object entity : s.createQuery("from Foo").list()) {
        i++;
        s.delete(entity);
    }
    assertEquals(4, i);
    s.flush();
    assertTrue(s.createQuery("from java.lang.Object").list().size() == 0);
    txn.commit();
    s.close();
}
Also used : HSQLDialect(org.hibernate.dialect.HSQLDialect) Query(org.hibernate.Query) SybaseDialect(org.hibernate.dialect.SybaseDialect) DB2Dialect(org.hibernate.dialect.DB2Dialect) Oracle8iDialect(org.hibernate.dialect.Oracle8iDialect) Transaction(org.hibernate.Transaction) ScrollableResults(org.hibernate.ScrollableResults) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

Oracle8iDialect (org.hibernate.dialect.Oracle8iDialect)6 Test (org.junit.Test)5 Session (org.hibernate.Session)4 Transaction (org.hibernate.Transaction)4 DB2Dialect (org.hibernate.dialect.DB2Dialect)4 HSQLDialect (org.hibernate.dialect.HSQLDialect)3 SQLServerDialect (org.hibernate.dialect.SQLServerDialect)3 SybaseASE15Dialect (org.hibernate.dialect.SybaseASE15Dialect)3 SybaseDialect (org.hibernate.dialect.SybaseDialect)3 List (java.util.List)2 DerbyDialect (org.hibernate.dialect.DerbyDialect)2 MySQLDialect (org.hibernate.dialect.MySQLDialect)2 PostgreSQL81Dialect (org.hibernate.dialect.PostgreSQL81Dialect)2 SybaseAnywhereDialect (org.hibernate.dialect.SybaseAnywhereDialect)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 EntityManager (javax.persistence.EntityManager)1 Query (org.hibernate.Query)1 ScrollableResults (org.hibernate.ScrollableResults)1 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)1