org.apache.openjpa.jdbc.sql
Interface BooleanRepresentation<REPRESENTATION_TYPE>

Type Parameters:
REPRESENTATION_TYPE - the java type which is used to store the Boolean in the database, e.g. String or Integer
All Known Implementing Classes:
BooleanRepresentationFactory.BooleanBooleanRepresentation, BooleanRepresentationFactory.Int10BooleanRepresentation, BooleanRepresentationFactory.StringBooleanRepresentation

public interface BooleanRepresentation<REPRESENTATION_TYPE>

Defines how a Boolean or boolean value gets stored in the database by default.

The DBDictionary defines a default representation for Boolean and boolean fields in JPA entities. The OracleDictionary for example uses a NUMBER(1) with the values (int) 1 and (int) 0 by 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 a CHAR(1) field with "T" and "F" values then you might configure the DBDictionary to 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 the BitTypeName and/or BooleanTypeName (depending on your database) to the desired type in the database.

The following BooleanRepresentation configuration options are possible:

If a single column uses a different representation then they still can tweak this for those columns with the org.apache.openjpa.persistence.ExternalValues annotation.


Method Summary
 boolean getBoolean(ResultSet rs, int columnIndex)
          Read the boolean from the given ResultSet
 REPRESENTATION_TYPE getRepresentation(boolean bool)
           
 void setBoolean(PreparedStatement stmnt, int columnIndex, boolean val)
          Set the boolean value into the statement
 

Method Detail

setBoolean

void setBoolean(PreparedStatement stmnt,
                int columnIndex,
                boolean val)
                throws SQLException
Set the boolean value into the statement

Throws:
SQLException

getBoolean

boolean getBoolean(ResultSet rs,
                   int columnIndex)
                   throws SQLException
Read the boolean from the given ResultSet

Throws:
SQLException

getRepresentation

REPRESENTATION_TYPE getRepresentation(boolean bool)
Returns:
return the representation for true and false


Copyright © 2006–2015 Apache Software Foundation. All rights reserved.