cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Reading boolean values stored in a database as chars
Date Thu, 08 Oct 2015 20:43:50 GMT
> 
> If you are using 3.1, we appear to be missing the documentation for
> ExtendedTypes at the bottom of this page:
> 
> http://cayenne.apache.org/docs/3.1/cayenne-guide/customizing-cayenne-runtime.html


Unfortunately we are. But luckily it is pretty easy. In your own DI module do this:

public class CayenneJava8Module implements Module {

    @Override
    public void configure(Binder binder) {
        binder.bindList(Constants.SERVER_DEFAULT_TYPES_LIST)
                .add(new MyType1())
                .add(new MyType2()); 
    }
}

Andrus



> On Oct 8, 2015, at 9:05 AM, Michael Gentry <mgentry@masslight.net> wrote:
> 
> Hi Hugi,
> 
> If you are using 3.1, we appear to be missing the documentation for
> ExtendedTypes at the bottom of this page:
> 
> http://cayenne.apache.org/docs/3.1/cayenne-guide/customizing-cayenne-runtime.html
> 
> If you are using 3.0 (and it may be the same in 3.1, I've just not done it
> there yet):
> 
> http://cayenne.apache.org/docs/3.0/extended-types.html
> 
> Once your extended type is registered, you specify it in the Cayenne Model
> as the Java type (that field/column is editable by you -- you aren't
> restricted to the types in the pulldown).
> 
> 
> On Thu, Oct 8, 2015 at 5:19 AM, Hugi Thordarson <hugi@karlmenn.is> wrote:
> 
>> Thanks for the advice everyone. I think this is the correct way, writing
>> cover methods won't really cut it in my case since I’m going to perform
>> queries using the fields in question.
>> The DB mixes different types for booleans in the database (some are
>> strings, others are proper booleans) but It looks like I can check for the
>> type of the field in the type adaptor before performing my operations, so I
>> should be able to handle this correctly.
>> 
>> Do you know how I register my own type adaptor for BooleanType?
>> 
>> Cheers,
>> - hugi
>> 
>> 
>> 
>>> On 7. okt. 2015, at 19:08, John Huss <johnthuss@gmail.com <mailto:
>> johnthuss@gmail.com>> wrote:
>>> 
>>> Check out the code for org.apache.cayenne.access.types.BooleanType and
>> it's
>>> subclasses.  I think you need to create your own extended type to handle
>>> it.  Not sure if you can have multiple different BooleanTypes in the same
>>> runtime, but you could have one that detects and switches
>>> behavior dynamically I guess.
>>> 
>>> On Wed, Oct 7, 2015 at 12:19 PM Hugi Thordarson <hugi@karlmenn.is
>> <mailto:hugi@karlmenn.is>> wrote:
>>> 
>>>> Hi all.
>>>> 
>>>> Oh the joys of working with legacy databases… :) I’m now using a
>> database
>>>> that sometimes stores boolean values as a char field with the value ’t’
>> or
>>>> ‘f’ (true or false). Can Cayenne help me map these fields to actual
>>>> booleans in my entities so I don’t have to think about this in my logic?
>>>> 
>>>> Cheers,
>>>> - hugi
>> 
>> 


Mime
View raw message