Skip to content

Commit

Permalink
HHH-6682 add support for oracle "bitand" function to Oracle Dialect
Browse files Browse the repository at this point in the history
  • Loading branch information
brmeyer committed Sep 17, 2012
1 parent 9f7f572 commit 6a5bd55
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 0 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ protected void registerFunctions() {
registerFunction( "acos", new StandardSQLFunction("acos", StandardBasicTypes.DOUBLE) ); registerFunction( "acos", new StandardSQLFunction("acos", StandardBasicTypes.DOUBLE) );
registerFunction( "asin", new StandardSQLFunction("asin", StandardBasicTypes.DOUBLE) ); registerFunction( "asin", new StandardSQLFunction("asin", StandardBasicTypes.DOUBLE) );
registerFunction( "atan", new StandardSQLFunction("atan", StandardBasicTypes.DOUBLE) ); registerFunction( "atan", new StandardSQLFunction("atan", StandardBasicTypes.DOUBLE) );
registerFunction( "bitand", new StandardSQLFunction("bitand") );
registerFunction( "cos", new StandardSQLFunction("cos", StandardBasicTypes.DOUBLE) ); registerFunction( "cos", new StandardSQLFunction("cos", StandardBasicTypes.DOUBLE) );
registerFunction( "cosh", new StandardSQLFunction("cosh", StandardBasicTypes.DOUBLE) ); registerFunction( "cosh", new StandardSQLFunction("cosh", StandardBasicTypes.DOUBLE) );
registerFunction( "exp", new StandardSQLFunction("exp", StandardBasicTypes.DOUBLE) ); registerFunction( "exp", new StandardSQLFunction("exp", StandardBasicTypes.DOUBLE) );
Expand Down
21 changes: 21 additions & 0 deletions hibernate-core/src/test/java/org/hibernate/test/math/Math.hbm.xml
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">


<hibernate-mapping package="org.hibernate.test.math">

<class name="MathEntity" table="MathEntity">
<id name="id">
<generator class="native"/>
</id>


<property name="value">
<column name="value" not-null="true" />
</property>
</class>

</hibernate-mapping>
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.hibernate.test.math;

/**
* @author Brett Meyer
*/
public class MathEntity {

private Long id;

private int value;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public int getValue() {
return value;
}

public void setValue(int value) {
this.value = value;
}

}
67 changes: 67 additions & 0 deletions hibernate-core/src/test/java/org/hibernate/test/math/MathTest.java
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.hibernate.test.math;

import static org.junit.Assert.assertEquals;

import org.hibernate.Session;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.Oracle8iDialect;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;

/**
* @author Brett Meyer
*/
@RequiresDialect( value = { Oracle8iDialect.class, H2Dialect.class } )
public class MathTest extends BaseCoreFunctionalTestCase {

@Override
public String[] getMappings() {
return new String[]{"math/Math.hbm.xml"};
}

@Test
public void testBitAnd() {
MathEntity me = new MathEntity();
me.setValue( 5 );

Session s = openSession();
s.beginTransaction();
Long id = (Long) s.save( me );
s.getTransaction().commit();
s.close();

s = openSession();
s.beginTransaction();
int value1 = (int)s.createQuery( "select bitand(m.value,0) from MathEntity m where m.id=" + id ).uniqueResult();
int value2 = (int)s.createQuery( "select bitand(m.value,2) from MathEntity m where m.id=" + id ).uniqueResult();
int value3 = (int)s.createQuery( "select bitand(m.value,3) from MathEntity m where m.id=" + id ).uniqueResult();
s.getTransaction().commit();
s.close();

assertEquals(value1, 0);
assertEquals(value2, 0);
assertEquals(value3, 1);
}

}

0 comments on commit 6a5bd55

Please sign in to comment.