Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 344805

Summary: [DB] Add new type mapping: Boolean from VARCHAR
Product: [Modeling] EMF Reporter: Erdal Karaca <erdal.karaca.de>
Component: cdo.net4j.dbAssignee: Eike Stepper <stepper>
Status: CLOSED WONTFIX QA Contact: Eike Stepper <stepper>
Severity: enhancement    
Priority: P3 CC: sraul.martins
Version: 4.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Added support for VARCHAR to Boolean stepper: iplog+

Description Erdal Karaca CLA 2011-05-05 04:34:18 EDT
Some DBMS do not have a boolean type.
You will then have somethin other to convert it from/to.

Currently, there is support for INT to Boolean in CDO.
We have to add support for VARCHAR to Boolean, as well.
Comment 1 Erdal Karaca CLA 2011-05-05 04:35:06 EDT
Created attachment 194804 [details]
Added support for VARCHAR to Boolean
Comment 2 Eike Stepper CLA 2011-06-23 03:56:44 EDT
Moving all open enhancement requests to 4.1
Comment 3 Eike Stepper CLA 2011-08-05 12:20:46 EDT
Stefan, can you review this small contribution first?
Comment 4 Stefan Winkler CLA 2011-08-15 07:24:57 EDT
Erdal,

thank you for your contribution.
The management/initialization code seems ok so far, did you test it? (in the best case, please provide a TestCase for the DB test suite)

I am currently unsure whether mapping/unmapping of the types work (do the JDBC drivers support get and set for Java type Boolean and DB type VARCHAR out of the box? If so, the code should work. If not, then you should implement a separate type mapping instead of reusing the existing one and do the conversion Boolean <-> String explicitly yourself.
Comment 5 Eike Stepper CLA 2012-08-14 22:50:18 EDT
Moving all open issues to 4.2. Open bugs can be ported to 4.1 maintenance after they've been fixed in master.
Comment 6 Eike Stepper CLA 2012-11-07 23:08:29 EST
The JavaDoc for ResultSet.getBoolean() says:

If the designated column has a datatype of CHAR or VARCHAR and contains a "0" [...] a value of false is returned.
If the designated column has a datatype of CHAR or VARCHAR and contains a "1" [...] a value of true is returned.

commit 2d90f84ddaaa0ec6dec264a5fa80ce516d96800c
Comment 7 Eike Stepper CLA 2012-11-07 23:15:18 EST
I still think that Boolean should be mapped to a some number. I was about to write something up but I couldn't test it on Oracle. Does someone want to submit a respective (tested) patch? I suggest to submit a separate bugzilla for this undertaking.
Comment 8 Silvestre Martins CLA 2012-11-08 07:01:39 EST
From the tests I did, this is not enough to make this work. It would also be needed to map the EBoolean to VARCHAR (not only the EBooleanObject):

CoreTypeMappings:
public static final Factory FACTORY_VARCHAR = new Factory(TypeMappingUtil.createDescriptor(ID_PREFIX
        + ".Boolean_VARCHAR", EcorePackage.eINSTANCE.getEBoolean(), DBType.VARCHAR));

TypeMappingRegistry:
container.registerFactory(CoreTypeMappings.TMBoolean.FACTORY_VARCHAR);

However, we still have a problem with this approach: when CDO is creating the columns for the ecore types, it will create a column with type VARCHAR2(4000) for a boolean attribute, because the OracleAdapter is "adapting" the dbType BOOLEAN to VARCHAR. 
And after all, CDO still stores 0 and 1 for the boolean (not 'false' or 'true').
So, I would definitely use the SMALLINT rather than VARCHAR.

Should I create a new bugzilla for this so I can attach a patch?
Comment 9 Eike Stepper CLA 2012-11-08 13:43:11 EST
> So, I would definitely use the SMALLINT rather than VARCHAR.
> 
> Should I create a new bugzilla for this so I can attach a patch?

Yes, please! ;-)
Comment 10 Eike Stepper CLA 2012-11-08 13:43:48 EST
Maybe you can add the "EBoolean to VARCHAR" mapping at the same time?
Comment 11 Silvestre Martins CLA 2012-11-08 14:42:05 EST
(In reply to comment #10)
> Maybe you can add the "EBoolean to VARCHAR" mapping at the same time?

Created bugzilla for the Boolean to NUMBER mapping:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=393917

Regarding the missing mapping for VARCHAR, do we really need it? If we decide to change the mapping from Boolean to NUMBER, then we could simply revert the changes from this commit. 

@Erdal, @Eike, what do you think?
Comment 12 Erdal Karaca CLA 2012-11-08 14:51:57 EST
(In reply to comment #11)
> (In reply to comment #10)
> > Maybe you can add the "EBoolean to VARCHAR" mapping at the same time?
> 
> Created bugzilla for the Boolean to NUMBER mapping:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=393917
> 
> Regarding the missing mapping for VARCHAR, do we really need it? If we
> decide to change the mapping from Boolean to NUMBER, then we could simply
> revert the changes from this commit. 
> 
> @Erdal, @Eike, what do you think?

Sure, I dont see any problems.
Existing apps would have to somehow migrate their column definitions to use the new mapping (NUMBER(1)/SMALLINT instead of VARCHAR(5)).
Comment 13 Silvestre Martins CLA 2012-11-08 15:03:02 EST
(In reply to comment #12)
> (In reply to comment #11)
> > (In reply to comment #10)
> > > Maybe you can add the "EBoolean to VARCHAR" mapping at the same time?
> > 
> > Created bugzilla for the Boolean to NUMBER mapping:
> > https://bugs.eclipse.org/bugs/show_bug.cgi?id=393917
> > 
> > Regarding the missing mapping for VARCHAR, do we really need it? If we
> > decide to change the mapping from Boolean to NUMBER, then we could simply
> > revert the changes from this commit. 
> > 
> > @Erdal, @Eike, what do you think?
> 
> Sure, I dont see any problems.
> Existing apps would have to somehow migrate their column definitions to use
> the new mapping (NUMBER(1)/SMALLINT instead of VARCHAR(5)).

The only way that existing apps managed to work in Oracle was by using the patches and local changes. So, in such cases, people either migrate the columns or continue to use local changes on the OracleAdapter.
Comment 14 Eike Stepper CLA 2012-11-08 23:06:14 EST
Agreed. I've reverted the commit:

commit 776874bc9b9431ed0972c66da1094ef19ab023bb
Comment 15 Eike Stepper CLA 2013-06-27 04:00:31 EDT
Closing