Permalink
Browse files

HHH-6682 add support for oracle "bitand" function to Oracle Dialect

  • Loading branch information...
1 parent 9f7f572 commit 6a5bd555dec6af11e0a3aab013dff4d25bb799c0 brmeyer committed Sep 17, 2012
@@ -123,6 +123,7 @@ protected void registerFunctions() {
registerFunction( "acos", new StandardSQLFunction("acos", StandardBasicTypes.DOUBLE) );
registerFunction( "asin", new StandardSQLFunction("asin", StandardBasicTypes.DOUBLE) );
registerFunction( "atan", new StandardSQLFunction("atan", StandardBasicTypes.DOUBLE) );
+ registerFunction( "bitand", new StandardSQLFunction("bitand") );
registerFunction( "cos", new StandardSQLFunction("cos", StandardBasicTypes.DOUBLE) );
registerFunction( "cosh", new StandardSQLFunction("cosh", StandardBasicTypes.DOUBLE) );
registerFunction( "exp", new StandardSQLFunction("exp", StandardBasicTypes.DOUBLE) );
@@ -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>
@@ -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;
+ }
+
+}
@@ -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.