Created
June 8, 2021 20:33
-
-
Save CarlosPanarello/408c8147ddbb8a7d48ba13dd999d310b to your computer and use it in GitHub Desktop.
SimNaoType para hibernate
This file contains hidden or 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
import java.io.Serializable; | |
import org.hibernate.annotations.TypeDef; | |
import org.hibernate.annotations.TypeDefs; | |
import org.hibernate.dialect.Dialect; | |
import org.hibernate.type.AbstractSingleColumnStandardBasicType; | |
import org.hibernate.type.DiscriminatorType; | |
import org.hibernate.type.PrimitiveType; | |
import org.hibernate.type.StringType; | |
import org.hibernate.type.descriptor.java.BooleanTypeDescriptor; | |
import org.hibernate.type.descriptor.sql.CharTypeDescriptor; | |
// Para usar colocar essa anotacao na entity | |
//@TypeDefs({@TypeDef(name = "sim_nao", typeClass = SimNaoType.class) }) | |
public class SimNaoType extends AbstractSingleColumnStandardBasicType<Boolean> implements | |
PrimitiveType<Boolean>, DiscriminatorType<Boolean> { | |
public static final SimNaoType INSTANCE = new SimNaoType(); | |
public SimNaoType() { | |
super(CharTypeDescriptor.INSTANCE, new BooleanTypeDescriptor('S', 'N')); | |
} | |
public String getName() { | |
return "sim_nao"; | |
} | |
public Class getPrimitiveClass() { | |
return Boolean.TYPE; | |
} | |
public Boolean stringToObject(String xml) throws Exception { | |
return (Boolean)this.fromString(xml); | |
} | |
public Serializable getDefaultValue() { | |
return Boolean.FALSE; | |
} | |
public String objectToSQLString(Boolean value, Dialect dialect) throws Exception { | |
return StringType.INSTANCE.objectToSQLString(value ? "S" : "N", dialect); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment