Skip to content

Commit

Permalink
OGM-717 [CASSANDRA] Add classes to convert YesNoType and TrueFalseType
Browse files Browse the repository at this point in the history
  OGM uses these types to convert a Boolean into a Character.
  Cassandra does not support the Character type. These new classes will
  save the values as String.
  • Loading branch information
DavideD committed May 15, 2015
1 parent a4a9c6d commit f3d5cdf
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
@@ -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.datastore.cassandra.type.impl;

import org.hibernate.MappingException;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.ogm.type.descriptor.impl.StringMappedGridTypeDescriptor;
import org.hibernate.ogm.type.impl.AbstractGenericBasicType;

/**
* Maps {@link Boolean} to {@code T} or {@code F} strings.
*
* @author Davide D'Alto
*/
public class CassandraTrueFalseType extends AbstractGenericBasicType<Boolean> {

public static final CassandraTrueFalseType INSTANCE = new CassandraTrueFalseType();

public CassandraTrueFalseType() {
super( StringMappedGridTypeDescriptor.INSTANCE, org.hibernate.type.TrueFalseType.INSTANCE.getJavaTypeDescriptor() );
}

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

@Override
public String getName() {
return "true_false";
}
}
@@ -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.datastore.cassandra.type.impl;

import org.hibernate.MappingException;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.ogm.type.descriptor.impl.StringMappedGridTypeDescriptor;
import org.hibernate.ogm.type.impl.AbstractGenericBasicType;

/**
* Maps {@link Boolean} to {@code Y} or {@code N} strings.
*
* @author Davide D'Alto
*/
public class CassandraYesNoType extends AbstractGenericBasicType<Boolean> {

public static final CassandraYesNoType INSTANCE = new CassandraYesNoType();

public CassandraYesNoType() {
super( StringMappedGridTypeDescriptor.INSTANCE, org.hibernate.type.YesNoType.INSTANCE.getJavaTypeDescriptor() );
}

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

@Override
public String getName() {
return "yes_no";
}
}

0 comments on commit f3d5cdf

Please sign in to comment.