Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Version 1.5
Revision History..................................................................................................................1
Problem................................................................................................................................2
Required Functionality........................................................................................................2
DAL Core Enhancements....................................................................................................3
1.Applications/DAOs with General JOIN.......................................................................3
2. Com.ebay.integ.dal.JoinedDo.java..............................................................................5
2.1 JoinedDo Constructors & APIs..............................................................................5
3. com.ebay.integ.dal.map.JoinedMap.............................................................................6
3.1 Constructor & APIs................................................................................................6
4. QueryEngine APIs.......................................................................................................7
5. Table Touples/DDR......................................................................................................7
6. ContainedFieldMapping.Java & AttributeToken.java................................................8
Some Requirements for DEDE............................................................................................8
Design Review Minutes (11/13/2007).................................................................................9
Testing..................................................................................................................................9
Revision History
Revision
1.0
1.1
1.2
1.3
1.4
Author
George
GJ
GJ
GJ
GJ
1.5
GJ
date
11/6/2007
11/8/2007
11/13/2007
12/06/2007
12/13/2007
Comment
A draft version
Added SELF-JOIN handling
Added Design Review Minutes
Updated after coding done
Added how to pass joined hints to query/QEAPI
12/20/2007 Minor updates
Problem
Though the existing SQL JOIN support in DAL suffices to meet eBay Marketplaces
needs so far, it seems not adequate and flexible enough for eBox users who may need
general SQL JOIN capabilities.
Currently, there are a few mechanisms that DAL employs when multiple tables are
involved in a Query. However they all have certain limitations:
Independent sub-objects are other Java entities that have a loose association with
the 'parent' DO/DAO. Elements from independent sub-objects are lazily loaded
(at the time that the getXXX() method is called, rather than at the time the parent
DAO finder method is called.
Limitation: the JOIN was performed at application side (in DAO), not on
database server side. i.e. 2 or more trips to DB server are required.
Contained sub-objects are Java entities that are tightly bound to the parent
DO/DAO. SELECTs will contain a JOIN to retrieve from the contained object's
table (iff the read-set includes one or more columns from that contained subobject).
Limitation:
1> it requires that all objects that participate in the JOIN have read-sets that
are in sync. (That is, READSET_COMPACT must have the same integer
identity in each table involved. otherwise queries that use this read-set will
return unexpected results).
2>The container and sub-objects have the same life cycle.
Required Functionality
This document mainly focuses on removing those limitations mentioned above.
The general JOIN functionality must meet the following functional requirements:
Allow join of two or more tables located on the same data source
Do not require synchronization of read sets among the joined objects
Allow participated objects to be independent each other (i.e.
Do not require to create a new DO Class for JOIN.)
Emp_name
Mark
Alex
John
Martin
emp_age
28
35
41
32
Name
Lab
marketing
Support
mgr_id
1
1
1
dept_no
1
2
2
3
location
Dallas
Houston
LA
/* 1> create two contributing proto DOs for the JOIN and the JoinedMap */
EmpDoImpl protoEmpDO = new EmpDoImpl(EmpDAO.getInstance(),EmpMap.getInstance());
DeptDoImpl protoDeptDO = new DeptDoImpl(DeptDAO.getInstance(), DeptMap.getInstance());
TableJoin[] tableJoins ={
new TableJoin(m_joinMap.getTableDefs(), e.DEPT_ID=d.DEPT_ID(+)",null)};
joinMap.setTableJoins(tableJoins);
/* 3> create queries
Query queries[] ={
new SelectQuery(FIND_EMP_NAME_DEPT_LOATION, m_ourDDRHints,
new SelectStatement[] {
new SelectStatement(
BaseMap2.SET_MATCHANY, "SELECT /*<CALCOMMENT/>*/
"FROM <TABLES/> " +
"WHERE (<JOIN/>) "),} ),
new SelectQuery(JOIN_WITH_BINDING, m_ourDDRHints,
new SelectStatement[] {
new SelectStatement(
BaseMap2.SET_MATCHANY, "SELECT /*<CALCOMMENT/>*/
"FROM <TABLES/> " +
"WHERE e.id > :emp1.m_id
= :dept2.m_deptid and
.
joinMap.setQueries(queries);
<SELECTFIELDS/> " +
<SELECTFIELDS/> " +
and d.dept_id
(<JOIN/>) "),
}),
/* 4> create field mapping: the attr name must be unique. if it is used for binding then the
names must be matched with the the ones on the binding line:
":emp1.m_id" on where clause, then we have to use "emp1" here */
FieldMapping[] fieldMappings = {
new ContainedFieldMapping("emp1", EmpMap.getInstance(), EmpDoImpl.class, jd),
new ContainedFieldMapping("dept2", DeptMap.getInstance(), DeptDoImpl.class, jd) };
joinMap.setFieldMappings(fieldMappings);
/* 5> set the read setid for each involved DO/table
* <set1, set2> can be one of all available combinations.
* it is not necessary that set1==set2.
* the set id determines which fields are used in the query/SQL
* DeptMap.READSET_GET_LOCATION_ONLY: only location
*/
is requested.
2. Com.ebay.integ.dal.JoinedDo.java
For table A, B (or even Table C, D) and their corresponding DOs:
DO0, DO1 (subclass of BaseDo2)we introduce a new class called JoinedDo
class (extending BaseDo2 ) to loosely hold DO0, DO1... as you saw in the example
above.
A protoDO (passed to QE APIs) of the type JoinedDo should be a validated one (see
constructors below). The validated JoinedDo object should have following properties:
a> The participated DO0, DO1 must NOT be instances of JoinedDo.
b> each participated DO should have different Classes.
c> each participated DO should have a non-null map object
The general join utilizes the existing concept of contained DO. In addition to
eliminating the set id sync requirement, with the general join, you do NOT need to
define a Class to contain a few sub-DOs, instead, you just need to instantiate an
object of the class JoinedDo as discussed below.
When table A JOINs B, the result set should contain zero to many JoinedDo objects.
To get individual DO from a result JoinedDo object, call:
DO = (DOClass) JoinedDo.getDO(Class DOClass);
DO = (DOClass) JoinedDo.getDO(int DOIndex);
For example:
EmpDoImpl emp = (EmpDoImpl) JoinedDo.getDO(EmpDoImpl.class);
EmpDoImpl emp = (EmpDoImpl) JoinedDo.getDO(0);
3. com.ebay.integ.dal.map.JoinedMap
QueryEngine needs a map object for a protoDO to figure out the <SELECTFIELDS/>,
<TABLES/> and SQL statement (parsed token), hints/TouplProvider/table touples,
and even CAL logging .
4. QueryEngine APIs
Here are a few possible new QE APIs (overloading ones), but not limited to.
/* do not know if there is any use case that we need to read fist record
from a JOIN. But we list the API here
*/
public JoinedDo readJoinSingle(
JoinedMap
map
JoinedDo
protoJoinedDO,
String
queryName, //search for the query in the map
Int
readsetId,
MappingIncludesAttribute[][] overrideQueryDefaultDDRHints);
/* likely used by most applications */
public void readJoinMultiple(
List<JoinedDo> results,
JoinedMap map,
JoinedDo protoJoinedDO,
String queryName,
int readSetId) throws FinderException
5. Table Touples/DDR
For a protoJoinedDO, QueryEngine will figure out table touples for each participated
DO separately with each DOs own hints & touple provider. For each protoDO, QE will
throw a RuntimeException if it detects that the data source is different among the table
touples at each position/try (see DDRToupleSetManager.verifyDataSources()) to
guarantee that all physical tables involved in JOIN are on the same db host for each try.
Application developers should make sure that the corresponding touple providers & hints
of the participated DOs will generate the same number of table touples for each DO
during run time AND the same data source for each touple across the DOs in the same
try. For example:
if tables Emp and Dept, each has two table touples during run time:
Emp: <emp1, datasource1> and <emp2, datasource2>
Dept: <dept, datasource1> and <dept, datasource2>
QE will be fine.
Testing
Unit test code for this feature is in
KernelDALTests/src/com/ebay/integ/dal/generaljointests
There are a few directories in this directory. Each focuses on
a certain category of testing. See README.txt there for
9
details.
10