Package org.hibernate.test.legacy

Examples of org.hibernate.test.legacy.Simple


    Iterator iter = s.createQuery( "select max(s.count) from Simple s" ).iterate();

    if ( getDialect() instanceof MySQLDialect ) assertTrue( iter.hasNext() && iter.next()==null );

    Simple simple = new Simple();
    simple.setName("Simple Dialect Function Test");
    simple.setAddress("Simple Address");
    simple.setPay(new Float(45.8));
    simple.setCount(2);
    s.save(simple, new Long(10) );

    // Test to make sure allocating an specified object operates correctly.
    assertTrue(
        s.createQuery( "select new org.hibernate.test.legacy.S(s.count, s.address) from Simple s" ).list().size() == 1
    );

    // Quick check the base dialect functions operate correctly
    assertTrue(
        s.createQuery( "select max(s.count) from Simple s" ).list().size() == 1
    );
    assertTrue(
        s.createQuery( "select count(*) from Simple s" ).list().size() == 1
    );

    if ( getDialect() instanceof Cache71Dialect) {
      // Check Oracle Dialect mix of dialect functions - no args (no parenthesis and single arg functions
      List rset = s.createQuery( "select s.name, sysdate, floor(s.pay), round(s.pay,0) from Simple s" ).list();
      assertNotNull("Name string should have been returned",(((Object[])rset.get(0))[0]));
      assertNotNull("Todays Date should have been returned",(((Object[])rset.get(0))[1]));
      assertEquals("floor(45.8) result was incorrect ", new Integer(45), ( (Object[]) rset.get(0) )[2] );
      assertEquals("round(45.8) result was incorrect ", new Float(46), ( (Object[]) rset.get(0) )[3] );

      simple.setPay(new Float(-45.8));
      s.update(simple);

      // Test type conversions while using nested functions (Float to Int).
      rset = s.createQuery( "select abs(round(s.pay,0)) from Simple s" ).list();
      assertEquals("abs(round(-45.8)) result was incorrect ", new Float(46), rset.get(0));

      // Test a larger depth 3 function example - Not a useful combo other than for testing
      assertTrue(
          s.createQuery( "select floor(round(sysdate,1)) from Simple s" ).list().size() == 1
      );

      // Test the oracle standard NVL funtion as a test of multi-param functions...
      simple.setPay(null);
      s.update(simple);
      Double value = (Double) s.createQuery("select mod( nvl(s.pay, 5000), 2 ) from Simple as s where s.id = 10").list().get(0);
      assertTrue( 0 == value.intValue() );
    }

View Full Code Here


  }

  public void testSetProperties() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Simple simple = new Simple();
    simple.setName("Simple 1");
    s.save(simple, new Long(10) );
    Query q = s.createQuery("from Simple s where s.name=:name and s.count=:count");
    q.setProperties(simple);
    assertTrue( q.list().get(0)==simple );
    //misuse of "Single" as a propertyobject, but it was the first testclass i found with a collection ;)
View Full Code Here

  }

  public void testNothinToUpdate() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Simple simple = new Simple();
    simple.setName("Simple 1");
    s.save( simple, new Long(10) );
    t.commit();
    s.close();

    s = openSession();
View Full Code Here

  }

  public void testCachedQuery() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Simple simple = new Simple();
    simple.setName("Simple 1");
    s.save( simple, new Long(10) );
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    Query q = s.createQuery("from Simple s where s.name=?");
    q.setCacheable(true);
    q.setString(0, "Simple 1");
    assertTrue( q.list().size()==1 );
    assertTrue( q.list().size()==1 );
    assertTrue( q.list().size()==1 );
    q = s.createQuery("from Simple s where s.name=:name");
    q.setCacheable(true);
    q.setString("name", "Simple 1");
    assertTrue( q.list().size()==1 );
    simple = (Simple) q.list().get(0);

    q.setString("name", "Simple 2");
    assertTrue( q.list().size()==0 );
    assertTrue( q.list().size()==0 );
    simple.setName("Simple 2");
    assertTrue( q.list().size()==1 );
    assertTrue( q.list().size()==1 );
    t.commit();
    s.close();
View Full Code Here

  }

  public void testCachedQueryRegion() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Simple simple = new Simple();
    simple.setName("Simple 1");
    s.save( simple, new Long(10) );
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    Query q = s.createQuery("from Simple s where s.name=?");
    q.setCacheRegion("foo");
    q.setCacheable(true);
    q.setString(0, "Simple 1");
    assertTrue( q.list().size()==1 );
    assertTrue( q.list().size()==1 );
    assertTrue( q.list().size()==1 );
    q = s.createQuery("from Simple s where s.name=:name");
    q.setCacheRegion("foo");
    q.setCacheable(true);
    q.setString("name", "Simple 1");
    assertTrue( q.list().size()==1 );
    simple = (Simple) q.list().get(0);

    q.setString("name", "Simple 2");
    assertTrue( q.list().size()==0 );
    assertTrue( q.list().size()==0 );
    simple.setName("Simple 2");
    assertTrue( q.list().size()==1 );
    assertTrue( q.list().size()==1 );
    t.commit();
    s.close();
View Full Code Here

  }

  public void testSQLFunctions() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Simple simple = new Simple();
    simple.setName("Simple 1");
    s.save(simple, new Long(10) );

    if ( getDialect() instanceof Cache71Dialect) {
      s.createQuery( "from Simple s where repeat('foo', 3) = 'foofoofoo'" ).list();
      s.createQuery( "from Simple s where repeat(s.name, 3) = 'foofoofoo'" ).list();
      s.createQuery( "from Simple s where repeat( lower(s.name), (3 + (1-1)) / 2) = 'foofoofoo'" ).list();
    }

    assertTrue(
        s.createQuery( "from Simple s where upper( s.name ) ='SIMPLE 1'" ).list().size()==1
    );
    if ( !(getDialect() instanceof HSQLDialect) ) {
      assertTrue(
          s.createQuery(
              "from Simple s where not( upper( s.name ) ='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar' )"
          ).list()
              .size()==1
      );
    }
    if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof SybaseDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof InterbaseDialect) && !(getDialect() instanceof TimesTenDialect) ) { //My SQL has a funny concatenation operator
      assertTrue(
          s.createQuery( "from Simple s where lower( s.name || ' foo' ) ='simple 1 foo'" ).list().size()==1
      );
    }
        /* + is not concat in Cache
        if ( (getDialect() instanceof Cache71Dialect) ) {
      assertTrue(
        s.find("from Simple s where lower( cons.name ' foo' ) ='simple 1 foo'").size()==1
      );
    }
    */
    if ( (getDialect() instanceof Cache71Dialect) ) {
      assertTrue(
          s.createQuery( "from Simple s where lower( concat(s.name, ' foo') ) ='simple 1 foo'" ).list().size()==1
      );
    }

    Simple other = new Simple();
    other.setName("Simple 2");
    other.setCount(12);
    simple.setOther(other);
    s.save( other, new Long(20) );
    //s.find("from Simple s where s.name ## 'cat|rat|bag'");
    assertTrue(
        s.createQuery( "from Simple s where upper( s.other.name ) ='SIMPLE 2'" ).list().size()==1
    );
    assertTrue(
        s.createQuery( "from Simple s where not ( upper( s.other.name ) ='SIMPLE 2' )" ).list().size()==0
    );
    assertTrue(
        s.createQuery(
            "select distinct s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2"
        ).list()
            .size()==1
    );
    assertTrue(
        s.createQuery(
            "select s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2 order by s.other.count"
        ).list()
            .size()==1
    );
    Simple min = new Simple();
    min.setCount(-1);
    s.save(min, new Long(30) );
    if ( ! (getDialect() instanceof MySQLDialect) && ! (getDialect() instanceof HSQLDialect) ) { //My SQL has no subqueries
      assertTrue(
          s.createQuery( "from Simple s where s.count > ( select min(sim.count) from Simple sim )" )
              .list()
View Full Code Here

    log.info("Using function named [" + functionName + "] for 'function as alias' test");
    String query = "select " + functionName + " from Simple as " + functionName + " where " + functionName + ".id = 10";

    Session s = openSession();
    Transaction t = s.beginTransaction();
    Simple simple = new Simple();
    simple.setName("Simple 1");
    s.save( simple, new Long(10) );
    t.commit();
    s.close();

    s = openSession();
View Full Code Here

  }

  public void testCachedQueryOnInsert() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Simple simple = new Simple();
    simple.setName("Simple 1");
    s.save( simple, new Long(10) );
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    Query q = s.createQuery("from Simple s");
    List list = q.setCacheable(true).list();
    assertTrue( list.size()==1 );
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    q = s.createQuery("from Simple s");
    list = q.setCacheable(true).list();
    assertTrue( list.size()==1 );
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    Simple simple2 = new Simple();
    simple2.setCount(133);
    s.save( simple2, new Long(12) );
    t.commit();
    s.close();

    s = openSession();
View Full Code Here

      s.delete("from Simple");
      s.flush();
      Simple[] simples = new Simple[n];
      Serializable[] ids = new Serializable[n];
      for ( int i=0; i<n; i++ ) {
        simples[i] = new Simple();
        simples[i].init();
        simples[i].setCount(i);
        ids[i] = new Long(i);
        s.save(simples[i], ids[i]);
      }
View Full Code Here

      s.delete("from Simple");
      s.flush();
      Simple[] simples = new Simple[n];
      Serializable[] ids = new Serializable[n];
      for ( int i=0; i<n; i++ ) {
        simples[i] = new Simple();
        simples[i].init();
        simples[i].setCount(i);
        ids[i] = new Long(i);
        s.save(simples[i], ids[i]);
      }
View Full Code Here

TOP

Related Classes of org.hibernate.test.legacy.Simple

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.