Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OGM-717 Adding support for @type(type = "numeric_boolean")
- Loading branch information
1 parent
a69174c
commit 25c4f44
Showing
6 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...src/main/java/org/hibernate/ogm/type/descriptor/impl/IntegerMappedGridTypeDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Hibernate OGM, Domain model persistence for NoSQL datastores | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.ogm.type.descriptor.impl; | ||
|
||
import org.hibernate.ogm.model.spi.Tuple; | ||
import org.hibernate.type.descriptor.WrapperOptions; | ||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; | ||
|
||
/** | ||
* Maps a field to an {@link Integer} value. | ||
* | ||
* @author Gunnar Morling | ||
*/ | ||
public class IntegerMappedGridTypeDescriptor implements GridTypeDescriptor { | ||
|
||
public static final IntegerMappedGridTypeDescriptor INSTANCE = new IntegerMappedGridTypeDescriptor(); | ||
|
||
@Override | ||
public <X> GridValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { | ||
return new BasicGridBinder<X>(javaTypeDescriptor, this) { | ||
@Override | ||
protected void doBind(Tuple resultset, X value, String[] names, WrapperOptions options) { | ||
resultset.put( names[0], javaTypeDescriptor.unwrap( value, Integer.class, options ) ); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public <X> GridValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor) { | ||
return new BasicGridExtractor<X>( javaTypeDescriptor, true ); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
core/src/main/java/org/hibernate/ogm/type/impl/NumericBooleanType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Hibernate OGM, Domain model persistence for NoSQL datastores | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.ogm.type.impl; | ||
|
||
import org.hibernate.MappingException; | ||
import org.hibernate.engine.spi.Mapping; | ||
import org.hibernate.ogm.type.descriptor.impl.IntegerMappedGridTypeDescriptor; | ||
|
||
/** | ||
* Maps {@link Boolean} to ints {@code 1} or {@code 0}. | ||
* | ||
* @author Gunnar Morling | ||
*/ | ||
public class NumericBooleanType extends AbstractGenericBasicType<Boolean> { | ||
|
||
public static final NumericBooleanType INSTANCE = new NumericBooleanType(); | ||
|
||
public NumericBooleanType() { | ||
super( IntegerMappedGridTypeDescriptor.INSTANCE, org.hibernate.type.NumericBooleanType.INSTANCE.getJavaTypeDescriptor() ); | ||
} | ||
|
||
@Override | ||
public int getColumnSpan(Mapping mapping) throws MappingException { | ||
return 1; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "numeric_boolean"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters