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

Bug 331619

Summary: Support cross-referencing (XRef) for abstract classes and class hierarchies
Product: [Modeling] EMF Reporter: Lothar Werzinger <lothar>
Component: cdo.dbAssignee: Stefan Winkler <stefan>
Status: CLOSED FIXED QA Contact: Eike Stepper <stepper>
Severity: enhancement    
Priority: P3 CC: jon, saulius.tvarijonas, stepper
Version: 4.0Keywords: noteworthy
Target Milestone: ---Flags: stepper: review+
Hardware: All   
OS: All   
Whiteboard: Power to the People
Bug Depends on: 332912    
Bug Blocks:    
Attachments:
Description Flags
Patch-v1-wo-cache
none
Patch v2
none
Patch-v3 none

Description Lothar Werzinger CLA 2010-12-01 18:08:30 EST
Build Identifier: 

We have a model where an abstract model class contains a reference to another class (call it X) and several classes that derive from the abstract class.

When we try to do a queryXRefs for X it fails, as the mapping does not create tables for abstract classes.

This was tested against CDO4 from Hudson (2010-12-01)
CDO Model Repository Site - https://hudson.eclipse.org/hudson/job/emf-cdo-integration/lastSuccessfulBuild/artifact/result/site.p2/


Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'ts_marketplace1.ParameterBasedChoiceListConstraint' doesn't exist
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
	at com.mysql.jdbc.Util.getInstance(Util.java:381)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2477)
	at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1422)
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.AbstractHorizontalClassMapping.queryScalarXRefs(AbstractHorizontalClassMapping.java:834)
	... 11 more


Reproducible: Always

Steps to Reproduce:
1. call queryXRefs
Comment 1 Lothar Werzinger CLA 2010-12-01 19:15:18 EST
Here's the relevant part of the cdo-server.xml that we are using:

   <repository name="marketplace1">
     <property name="supportingAudits" value="true"/>
     <property name="supportingRevisionDeltas" value="true"/>
     <property name="supportingBranches" value="true"/>
     <property name="verifyingRevisions" value="false"/>
     <property name="currentLRUCapacity" value="10000"/>
     <property name="revisedLRUCapacity" value="100"/>
     
     <store type="db">
       <!-- type: horizontal | horizontalAuditWithRanges | horizontalBranchingWithRanges | vertical | <any user-contributed type>-->
       <mappingStrategy type="horizontalBranchingWithRanges">
         <!-- ONE_TABLE_PER_REFERENCE | ONE_TABLE_PER_CLASS | ONE_TABLE_PER_PACKAGE | ONE_TABLE_PER_REPOSITORY | LIKE_ATTRIBUTES -->
         <property name="toManyReferences" value="ONE_TABLE_PER_REFERENCE"/>
 
         <!-- LIKE_ATTRIBUTES | LIKE_TO_MANY_REFERENCES-->
         <property name="toOneReferences" value="LIKE_ATTRIBUTES"/>
         
         <!-- MODEL | STRATEGY-->
         <property name="mappingPrecedence" value="MODEL"/>
       </mappingStrategy>
       
       <dbAdapter name="mysql"/>
       <dataSource class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
         url="jdbc:mysql://localhost/ts_marketplace1"
         user="cdo"
         password="cdo"/>
     </store>
   </repository>
Comment 2 Stefan Winkler CLA 2010-12-18 14:14:57 EST
Created attachment 185482 [details]
Patch-v1-wo-cache

Fixes the basic issue for the bug. 

Yet, a caching mechanism to speed up the performance of the search for all subclasses is missing.

Eike, before I implement the cache, can you have a look at the basic implementation and double-check, if this is what we want (as discussed last week)?

I have also included a test-case to reproduce the basic issue and the case for which the subclasses are needed in the first place.
Comment 3 Eike Stepper CLA 2010-12-19 04:08:17 EST
I believe in your code in CDOModelUtil has two bugs:

1) packageRegistry.values() is always dangerous. Better keySet() + getEPackage()
2) We should use getE *All* SuperTypes()

I'll attach a new patch...

As a preparation for the caching of descendent classes I'd prefer to pass a CDOPackageRegistry into the static collectXYZ() methods. Using the StoreThreadLocal is to be limited as much as possible. Note that you can make use of IQueryContext.getView().getSession().getManager().getRepository()
Comment 4 Eike Stepper CLA 2010-12-19 04:09:24 EST
Created attachment 185491 [details]
Patch v2
Comment 5 Stefan Winkler CLA 2010-12-20 08:45:00 EST
Created attachment 185535 [details]
Patch-v3

As discussed on Skype, cache implementation is in Bug 332912.
Therefore, this patch needs the patch of Bug 332912 in the workspace as well to compile.
Comment 6 Stefan Winkler CLA 2010-12-21 03:01:12 EST
Committed to HEAD
Comment 7 Eike Stepper CLA 2011-06-23 03:38:06 EDT
Available in R20110608-1407