Interface BooleanRepresentation<REPRESENTATION_TYPE>
-
- Type Parameters:
REPRESENTATION_TYPE- the java type which is used to store the Boolean in the database, e.g.StringorInteger
- All Known Implementing Classes:
BooleanRepresentationFactory.BooleanBooleanRepresentation,BooleanRepresentationFactory.Int10BooleanRepresentation,BooleanRepresentationFactory.StringBooleanRepresentation
public interface BooleanRepresentation<REPRESENTATION_TYPE>Defines how a
Booleanorbooleanvalue gets stored in the database by default.The
DBDictionarydefines a default representation forBooleanandbooleanfields in JPA entities. TheOracleDictionaryfor example uses aNUMBER(1)with the values(int) 1and(int) 0by default. However, sometimes you like to use a different default representation for Boolean values in your database. If your application likes to store boolean values in aCHAR(1)field with"T"and"F"values then you might configure theDBDictionaryto use the"STRING_TF"BooleanRepresentation:<property name="openjpa.jdbc.DBDictionary" value="(BitTypeName=CHAR(1),BooleanTypeName=CHAR(1),BooleanRepresentation=STRING_10)"/>Please note that you still need to adopt the mapping separately by setting theBitTypeNameand/orBooleanTypeName(depending on your database) to the desired type in the database.The following
BooleanRepresentationconfiguration options are possible:- One of the values of
BooleanRepresentationFactory.BUILTIN_BOOLEAN_REPRESENTATIONS, e.g.:<property name="openjpa.jdbc.DBDictionary" value="(BooleanRepresentation=STRING_YN)"/> -
Two slash (
'/') separated true/false value strings:<property name="openjpa.jdbc.DBDictionary" value="(BooleanRepresentation=oui/non)"/> -
A fully qualified class name of your own
BooleanRepresentationimplementation, e.g.:<property name="openjpa.jdbc.DBDictionary" value="(BooleanRepresentation=com.mycompany.MyOwnBoolRepresentation)"/>
If a single column uses a different representation then they still can tweak this for those columns with the
org.apache.openjpa.persistence.ExternalValuesannotation.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleangetBoolean(java.sql.ResultSet rs, int columnIndex)Read the boolean from the given ResultSetREPRESENTATION_TYPEgetRepresentation(boolean bool)voidsetBoolean(java.sql.PreparedStatement stmnt, int columnIndex, boolean val)Set the boolean value into the statement
-
-
-
Method Detail
-
setBoolean
void setBoolean(java.sql.PreparedStatement stmnt, int columnIndex, boolean val) throws java.sql.SQLExceptionSet the boolean value into the statement- Throws:
java.sql.SQLException
-
getBoolean
boolean getBoolean(java.sql.ResultSet rs, int columnIndex) throws java.sql.SQLExceptionRead the boolean from the given ResultSet- Throws:
java.sql.SQLException
-
getRepresentation
REPRESENTATION_TYPE getRepresentation(boolean bool)
- Returns:
- return the representation for
trueandfalse
-
-