Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OGM-717 [CASSANDRA] Add classes to convert YesNoType and TrueFalseType
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
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...src/main/java/org/hibernate/ogm/datastore/cassandra/type/impl/CassandraTrueFalseType.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.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"; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...dra/src/main/java/org/hibernate/ogm/datastore/cassandra/type/impl/CassandraYesNoType.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.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"; | ||
} | ||
} |