Skip to content

Commit

Permalink
OGM-640 Add support for Character type
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajay Bhat authored and gunnarmorling committed Jan 9, 2015
1 parent d8b01fb commit 2cd4292
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
41 changes: 41 additions & 0 deletions core/src/main/java/org/hibernate/ogm/type/impl/CharacterType.java
@@ -0,0 +1,41 @@
/*
* 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.WrappedGridTypeDescriptor;
import org.hibernate.type.descriptor.java.CharacterTypeDescriptor;

/**
* Represents a Character type
*
* @author Ajay Bhat
*/
public class CharacterType extends AbstractGenericBasicType<Character> {
public static CharacterType INSTANCE = new CharacterType();

public CharacterType() {
super( WrappedGridTypeDescriptor.INSTANCE, CharacterTypeDescriptor.INSTANCE );
}

@Override
public String[] getRegistrationKeys() {
return new String[] {getName(), char.class.getName(), Character.class.getName()};
}

@Override
public int getColumnSpan(Mapping mapping) throws MappingException {
return 1;
}

@Override
public String getName() {
return "char";
}
}
Expand Up @@ -26,6 +26,7 @@
import org.hibernate.type.descriptor.java.ByteTypeDescriptor;
import org.hibernate.type.descriptor.java.CalendarDateTypeDescriptor;
import org.hibernate.type.descriptor.java.CalendarTypeDescriptor;
import org.hibernate.type.descriptor.java.CharacterTypeDescriptor;
import org.hibernate.type.descriptor.java.ClassTypeDescriptor;
import org.hibernate.type.descriptor.java.DoubleTypeDescriptor;
import org.hibernate.type.descriptor.java.FloatTypeDescriptor;
Expand Down Expand Up @@ -56,13 +57,14 @@ public class TypeTranslatorImpl implements TypeTranslator {
public TypeTranslatorImpl(GridDialect dialect) {
this.dialect = dialect;

Map<JavaTypeDescriptor<?>, GridType> tmpMap = newHashMap( 17 );
Map<JavaTypeDescriptor<?>, GridType> tmpMap = newHashMap( 20 );
tmpMap.put( ClassTypeDescriptor.INSTANCE, ClassType.INSTANCE );
tmpMap.put( LongTypeDescriptor.INSTANCE, LongType.INSTANCE );
tmpMap.put( IntegerTypeDescriptor.INSTANCE, IntegerType.INSTANCE );
tmpMap.put( DoubleTypeDescriptor.INSTANCE, DoubleType.INSTANCE );
tmpMap.put( FloatTypeDescriptor.INSTANCE, FloatType.INSTANCE );
tmpMap.put( ShortTypeDescriptor.INSTANCE, ShortType.INSTANCE );
tmpMap.put( CharacterTypeDescriptor.INSTANCE, CharacterType.INSTANCE );
tmpMap.put( StringTypeDescriptor.INSTANCE, StringType.INSTANCE );
tmpMap.put( UrlTypeDescriptor.INSTANCE, UrlType.INSTANCE );
tmpMap.put( BigDecimalTypeDescriptor.INSTANCE, BigDecimalType.INSTANCE );
Expand Down
Expand Up @@ -56,6 +56,7 @@ public enum Classifier {
private Classifier classifierAsOrdinal;
private Float visitRatio;
private Short urlPort;
private Character delimiter;

@Id
public String getId() {
Expand Down Expand Up @@ -255,4 +256,12 @@ public Short getUrlPort() {
public void setUrlPort(Short urlPort) {
this.urlPort = urlPort;
}

public Character getDelimiter() {
return delimiter;
}

public void setDelimiter(Character delimiter) {
this.delimiter = delimiter;
}
}
Expand Up @@ -103,6 +103,8 @@ public void testTypesSupport() throws Exception {
b.setUrlPort( urlPort );
final Float visitRatio = Float.valueOf( (float) 10.4 );
b.setVisitRatio( visitRatio );
final Character delimiter = Character.valueOf( '/' );
b.setDelimiter( delimiter );
b.setType( BookmarkType.URL );
b.setTaxPercentage( 12.34d );
session.persist( b );
Expand All @@ -123,6 +125,7 @@ public void testTypesSupport() throws Exception {
assertEquals( "stock count incorrect", stockCount, b.getStockCount() );
assertEquals( "url port incorrect", urlPort, b.getUrlPort() );
assertEquals( "visit ratio incorrect", visitRatio, b.getVisitRatio() );
assertEquals( "delimieter incorrect", delimiter, b.getDelimiter() );
assertEquals( "Tax percentage as double inscorrect", 0, b.getTaxPercentage().compareTo( 12.34d ) );
assertEquals( "Classifier as enum string is incorrect", Classifier.HOME, b.getClassifier() );
assertEquals( "Classifier stored as enum ordinal is incorrect", Classifier.WORK, b.getClassifierAsOrdinal() );
Expand Down Expand Up @@ -192,6 +195,8 @@ public void testStringMappedTypeSerialisation() throws Exception {
b.setUrlPort( urlPort );
final Float visitRatio = Float.valueOf( (float) 10.4 );
b.setVisitRatio( visitRatio );
final Character delimiter = Character.valueOf( '/' );
b.setDelimiter( delimiter );

session.persist( b );
transaction.commit();
Expand Down

0 comments on commit 2cd4292

Please sign in to comment.