File: TreatAsExpression.java

package info (click to toggle)
eclipselink 2.6.9-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 44,528 kB
  • sloc: java: 475,126; xml: 72; makefile: 21; sh: 10
file content (624 lines) | stat: -rw-r--r-- 25,925 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
/*******************************************************************************
 * Copyright (c) 2013 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the 
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
 * which accompanies this distribution. 
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at 
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * Contributors:
 *     11/06/2013-2.5.1 Chris Delahunt  
 *       - 374771 : TREAT support
 ******************************************************************************/  
package org.eclipse.persistence.internal.expressions;

import java.io.BufferedWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.descriptors.InheritancePolicy;
import org.eclipse.persistence.exceptions.QueryException;
import org.eclipse.persistence.expressions.Expression;
import org.eclipse.persistence.internal.helper.DatabaseTable;
import org.eclipse.persistence.internal.sessions.AbstractRecord;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.mappings.DatabaseMapping;
import org.eclipse.persistence.queries.DatabaseQuery;

/**
 * @author cdelahun
 *
 */
public class TreatAsExpression extends QueryKeyExpression {
    protected ObjectExpression typeExpressionBase;
    protected Expression typeExpression;
    
    protected Boolean isDowncast;//we only need a type expression if this is a downcast.  

    public Expression convertToUseOuterJoin() {
        typeExpressionBase.convertToUseOuterJoin();
        return this;
    }

    public String descriptionOfNodeType() {
        return "Treat";
    }

    public boolean equals(Object object) {
        if (!super.equals(object)) {
            return false;
        }
        TreatAsExpression expression = (TreatAsExpression) object;        
        return getCastClass().equals(expression.getCastClass());
    }

    public Vector getFields() {
        return typeExpressionBase.getFields();
    }

    public Object getFieldValue(Object objectValue, AbstractSession session) {
        return typeExpressionBase.getFieldValue(objectValue, session);
    }

    /**
     * This owns (can access) the child's extra tables as well as its parent's tables
     * so we should pull these from super (which gets them from the current descriptor)
     */
    public List<DatabaseTable> getOwnedTables() {
        return super.getOwnedTables();
    }

    public Expression getAlias(Expression subSelect) {
        return typeExpressionBase.getAlias(subSelect);
    }

    /**
     * Calculate the relation table for based on the various QueryKeyExpression
     * usages (join query keys, custom defined query keys, or query keys for
     * mappings).
     * Does not apply to Treat
     * 
     * Called from {@link SQLSelectStatement#appendFromClauseForOuterJoin}.
     * 
     * @return DatabaseTable
     */    
    public DatabaseTable getRelationTable() {
        return null;
    }

    public TableAliasLookup getTableAliases() {
        return typeExpressionBase.getTableAliases();
    }

    public boolean hasAsOfClause() {
        return typeExpressionBase.hasAsOfClause();
    }

    /**
     * INTERNAL:
     */
    public boolean isDowncast() {
        if (this.isDowncast == null) {
            this.getDescriptor();//initializes isDowncast
        }
        return this.isDowncast;
    }

    /**
     * INTERNAL:
     */
    public boolean isTreatExpression() {
        return true;
    }

    public void printSQL(ExpressionSQLPrinter printer) {
        typeExpressionBase.printSQL(printer);
    }

    public boolean selectIfOrderedBy() {
        return typeExpressionBase.selectIfOrderedBy();
    }

    public Expression twistedForBaseAndContext(Expression newBase,
            Expression context, Expression oldBase) {
        if (oldBase == null || this.typeExpressionBase == oldBase) {
            Expression twistedBase = this.typeExpressionBase.twistedForBaseAndContext(newBase, context, oldBase);
            TreatAsExpression result = (TreatAsExpression)twistedBase.treat(this.castClass);
            if (shouldUseOuterJoin) {
                result.doUseOuterJoin();
            }
            if (shouldQueryToManyRelationship) {
                result.doQueryToManyRelationship();
            }
            return result;
        }

        return this;
    }

    public void validateNode() {
        typeExpressionBase.validateNode();
        //getDescriptor currently checks if the descriptor can be found for the castclass.
        //We may want to check that this is a downcast in future
        getDescriptor();
    }

    public Object valueFromObject(Object object, AbstractSession session,
            AbstractRecord translationRow, int valueHolderPolicy,
            boolean isObjectUnregistered) {
        return typeExpressionBase.valueFromObject(object, session,
                translationRow, valueHolderPolicy, isObjectUnregistered);
    }

    public Object valueFromObject(Object object, AbstractSession session,
            AbstractRecord translationRow, int valueHolderPolicy) {
        return typeExpressionBase.valueFromObject(object, session,
                translationRow, valueHolderPolicy);
    }

    public void writeDescriptionOn(BufferedWriter writer) throws IOException {
        if (castClass != null){
            writer.write(" AS "+ castClass.getName());
        }
    }

    public void writeFields(ExpressionSQLPrinter printer, Vector newFields,
            SQLSelectStatement statement) {
        typeExpressionBase.writeFields(printer, newFields, statement);
    }

    public void writeSubexpressionsTo(BufferedWriter writer, int indent)
            throws IOException {
        if (this.typeExpressionBase != null) {
            this.typeExpressionBase.toString(writer, indent);
        } else {
            super.writeSubexpressionsTo(writer, indent);
        }
    }

    public ClassDescriptor getLeafDescriptor(DatabaseQuery query,
            ClassDescriptor rootDescriptor, AbstractSession session) {
        return session.getDescriptor(castClass);
    }

    public DatabaseMapping getLeafMapping(DatabaseQuery query,
            ClassDescriptor rootDescriptor, AbstractSession session) {
        return typeExpressionBase
                .getLeafMapping(query, rootDescriptor, session);
    }

    @Override
    public DatabaseTable aliasForTable(DatabaseTable table) {
        return typeExpressionBase.aliasForTable(table);
    }

    /**
     * INTERNAL:
     * This expression is built on a different base than the one we want. Rebuild it and
     * return the root of the new tree
     */
    public Expression rebuildOn(Expression newBase) {
        Expression newLocalBase = this.typeExpressionBase.rebuildOn(newBase);
        return newLocalBase.treat(castClass);
    }

    public ClassDescriptor getDescriptor() {
        if (isAttribute()) {
            //TODO: add support for treat on attributes
            throw QueryException.couldNotFindCastDescriptor(castClass, getBaseExpression());
        }
        if (descriptor == null) {
            ClassDescriptor rootDescriptor = typeExpressionBase.getDescriptor();
            descriptor = convertToCastDescriptor(rootDescriptor, getSession());
        }
        return descriptor;
    }

    /**
     * INTERNAL - 
     * Return the descriptor which contains this query key, look in the inheritance hierarchy 
     * of rootDescriptor for the descriptor.  Does not set the descriptor, only returns it.
     */
    public ClassDescriptor convertToCastDescriptor(ClassDescriptor rootDescriptor, AbstractSession session) {
        isDowncast = Boolean.FALSE;
        if (castClass == null || rootDescriptor == null || rootDescriptor.getJavaClass() == castClass) {
            return rootDescriptor;
        }

        ClassDescriptor castDescriptor = session.getClassDescriptor(castClass);

        if (castDescriptor == null){
            throw QueryException.couldNotFindCastDescriptor(castClass, getBaseExpression());
        }
        if (!castDescriptor.hasInheritance()){
            throw QueryException.castMustUseInheritance(getBaseExpression());
        }
        ClassDescriptor parentDescriptor = castDescriptor.getInheritancePolicy().getParentDescriptor();
        while (parentDescriptor != null){
            if (parentDescriptor == rootDescriptor){
                isDowncast = Boolean.TRUE;
                return castDescriptor;
            }
            parentDescriptor = parentDescriptor.getInheritancePolicy().getParentDescriptor();
        }
        //is there value casting an emp to person in a query?
        ClassDescriptor childDescriptor = rootDescriptor;
        while (childDescriptor != null){
            if (childDescriptor == castDescriptor){
                return rootDescriptor;
            }
            childDescriptor = childDescriptor.getInheritancePolicy().getParentDescriptor();
        }

        throw QueryException.couldNotFindCastDescriptor(castClass, getBaseExpression());
    }

    public Expression getTypeClause() {
        if (typeExpression == null) { 
            if (getDescriptor() !=null && isDowncast()) {
                InheritancePolicy ip = this.getDescriptor().getInheritancePolicy();
                if (ip.isChildDescriptor()) {//or use the isDowncast flag.  Don't need to do anything if its not a downcast
                    //equivalent to typeExpressionBase.type().in(this.getDescriptor().getInheritancePolicy().getChildClasses())
                    typeExpression = ip.getWithAllSubclassesExpression();
                    if (typeExpression == null ) {
                        typeExpression = typeExpressionBase.type().equal(this.getDescriptor().getJavaClass());
                    } else {
                        typeExpression = this.typeExpressionBase.twist(typeExpression, typeExpressionBase);
                    }

                }
            } else {
                typeExpression = this.getBuilder();//equivalent to an empty expression.
            }
                
        }
        return typeExpression;
    }

    @Override
    protected void postCopyIn(Map alreadyDone) {
        super.postCopyIn(alreadyDone);
        this.typeExpressionBase = (ObjectExpression)typeExpressionBase.copiedVersionFrom(alreadyDone);
    }

    public TreatAsExpression(Class castClass, ObjectExpression baseExpression) {
        super();
        this.name = "Treat as "+castClass;
        this.typeExpressionBase = baseExpression;
        if (baseExpression.isExpressionBuilder()){     
            this.baseExpression = baseExpression;

            shouldQueryToManyRelationship = false;
            hasQueryKey = false;
            hasMapping = false;
        } else {
            this.baseExpression = baseExpression.getBaseExpression();
        }
        shouldUseOuterJoin = true;//this uses outerjoins to the cast class' tables by default.
        this.castClass = castClass;
    }

    /**
     * INTERNAL:
     * Print java for project class generation
     */
    @Override
    public void printJava(ExpressionJavaPrinter printer) {
        this.typeExpressionBase.printJava(printer);
        if (castClass != null){
            printer.printString(".treat(" + castClass.getName() + ".class)");
        }
    }

    /**
     * INTERNAL:
     * Alias a particular table within this node
     */
    protected void assignAlias(DatabaseTable alias, DatabaseTable table) {
        if (tableAliases == null) {
            if (this.typeExpressionBase!=null) {
                if (this.typeExpressionBase.getTableAliases()==null) {
                    typeExpressionBase.setTableAliases(new TableAliasLookup());
                }
                tableAliases = typeExpressionBase.getTableAliases();
            } else {
                tableAliases = new TableAliasLookup();
            }
        }
        tableAliases.put(alias, table);
    }

    /**
     * INTERNAL:
     * Assign aliases to any tables which I own. Start with t(initialValue),
     * and return the new value of  the counter , i.e. if initialValue is one
     * and I have tables ADDRESS and EMPLOYEE I will assign them t1 and t2 respectively, and return 3.
     */
    public int assignTableAliasesStartingAt(int initialValue) {
        //This assumes that the typeExpressionBase will alias its own tables, so we only need to handle
        //the extra's caused by this treat expression.
        if (hasBeenAliased()) {
            return initialValue;
        }
        int counter = initialValue;
        if (this.typeExpressionBase != null) {
            counter = this.typeExpressionBase.assignTableAliasesStartingAt(counter);
        }
        //Only difference between this and ObjectExpression's assignTableAliasesStartingAt is this uses getOwnedSubTables
        // instead of getOwnedTables which returns everything.
        List<DatabaseTable> ownedTables = getOwnedSubTables();
        if (ownedTables != null) {
            for (DatabaseTable table : ownedTables) {
                assignAlias("t" + counter, table);
                counter++;
            }
        }
        this.hasBeenAliased = true;
        return counter;
    }

    /**
     * INTERNAL: 
     * much like getOwnedTables(), this gets the tables represented from the descriptor.  Difference is this only returns local tables
     * for the child casted descriptor, and excludes tables owned by the parent descriptor
     */
    public List<DatabaseTable> getOwnedSubTables() {
        ClassDescriptor parentDescriptor = this.typeExpressionBase.getDescriptor();
        Vector<DatabaseTable> childTables = new Vector(2);
        if (parentDescriptor.hasInheritance() && parentDescriptor.getInheritancePolicy().hasMultipleTableChild() ) {
            List parentTables = typeExpressionBase.getOwnedTables();
            //All tables for this child, including parent tables
            Vector<DatabaseTable> tables = getDescriptor().getTables();
            for (DatabaseTable table : tables) {
                if (!parentTables.contains(table)) {
                    childTables.add(table);
                }
            }
        }

        return childTables;
    }


    @Override
    public List<DatabaseTable> getAdditionalTables() {
        //called from ObjectExpression's getOwnedTables but not relevant to treat.
        return null;
    }

    /*
     * INTERNAL:
     * If this query key represents a foreign reference answer the
     * base expression -> foreign reference join criteria.
     * This shouldn't be used on Treat
     */
    public Expression mappingCriteria(Expression base) {
        if (typeExpressionBase.isQueryKeyExpression()) {
            return ((QueryKeyExpression)typeExpressionBase).mappingCriteria(base);
        }
        return null;
    }

    /**
     * INTERNAL:
     * Used in case outer joins should be printed in FROM clause.
     * Each of the additional tables mapped to expressions that joins it.
     */
    public Map additionalTreatExpressionCriteriaMap() {
        if (getDescriptor() == null) {
            return null;
        }
        int tableSize = 0;
        HashMap tablesJoinExpressions = new HashMap();

        ClassDescriptor parentDescriptor = this.typeExpressionBase.getDescriptor();

        //outerjoin our parent->child tables
        if (parentDescriptor.hasInheritance() &&
                parentDescriptor.getInheritancePolicy().hasMultipleTableChild() ) {
            Vector tables = getDescriptor().getTables();//All this child's tables
            tableSize = tables.size();
            //look up the joins from the parent descriptor to our tables.  
            for (int i=0; i < tableSize; i++) {
                DatabaseTable table = (DatabaseTable)tables.elementAt(i);
                Expression joinExpression = parentDescriptor.getInheritancePolicy().getChildrenTablesJoinExpressions().get(table);
                //Some of our tables might be the in our parent as well, so ignore the lack of a joinExpression
                if (joinExpression != null) {
                    joinExpression = this.baseExpression.twist(joinExpression, this);
                    tablesJoinExpressions.put(table, joinExpression);
                }
            }
        }

        if (isUsingOuterJoinForMultitableInheritance()) {
            List childrenTables = getDescriptor().getInheritancePolicy().getChildrenTables();
            tableSize = childrenTables.size();
            for (int i=0; i < tableSize; i++) {
                DatabaseTable table = (DatabaseTable)childrenTables.get(i);
                Expression joinExpression = getDescriptor().getInheritancePolicy().getChildrenTablesJoinExpressions().get(table);
                joinExpression = this.baseExpression.twist(joinExpression, this);
                tablesJoinExpressions.put(table, joinExpression);
            }
        }

        return tablesJoinExpressions;
    }

    /**
     * INTERNAL:
     * this returns a single expression to represent the join from the main table to all child descriptor tables
     * Only if outer joins should be printed in the where clause
     * @return Expression
     */
    public Expression getTreatCriteria() {
        if (getDescriptor() == null) {
            return null;
        }
        //need to build this using just the multiple tables on this descriptor not included in the parent's join expression
        Expression criteria = null;
        if(getSession().getPlatform().shouldPrintOuterJoinInWhereClause()) {
            Vector tables = getDescriptor().getTables();//This child's tables
            ClassDescriptor parentDescriptor = this.typeExpressionBase.getDescriptor();
            int tablesSize = tables.size();
            if (parentDescriptor.hasInheritance() &&
                    parentDescriptor.getInheritancePolicy().hasMultipleTableChild() ) {
                //look up the joins from the parent descriptor to our tables.  
                for (int i=0; i < tablesSize; i++) {
                    DatabaseTable table = (DatabaseTable)tables.elementAt(i);
                    Expression joinExpression = parentDescriptor.getInheritancePolicy().getChildrenTablesJoinExpressions().get(table);
                    //Some of our tables might be the in our parent as well, so ignore the lack of a joinExpression
                    if (joinExpression != null) {
                        joinExpression = this.baseExpression.twist(joinExpression, this);
                        if (shouldUseOuterJoin()) {
                            joinExpression = joinExpression.convertToUseOuterJoin();
                        }
                        criteria = joinExpression.and(criteria);
                    }
                }
            }
        }
        return criteria;
    }

    /**
     * INTERNAL:
     * Return the expression to join the main table of this node to any auxiliary tables.
     */
    public Expression additionalTreatExpressionCriteria() {
        if (getDescriptor() == null) {
            return null;
        }
        //need to build this using just the multiple tables on this descriptor not included in the parent's join expression
        Expression criteria = null;
        if(getSession().getPlatform().shouldPrintOuterJoinInWhereClause()) {
            if(isUsingOuterJoinForMultitableInheritance()) {
                criteria = getDescriptor().getInheritancePolicy().getChildrenJoinExpression();
                criteria = this.baseExpression.twist(criteria, this);
                criteria.convertToUseOuterJoin();
            }
        }
        return criteria;
    }

    
    public DatabaseTable getSourceTable() {
        //not used currently, but should return the baseExpressionType table if used in the future
        return null;
    }

    public DatabaseTable getReferenceTable() {
        //not used currently, but should return the treat subclass first table if used in the future
        return null;
    }

    public Expression normalize(ExpressionNormalizer normalizer, Expression base, List<Expression> foreignKeyJoinPointer) {
        //need to determine what type this is, as it may need to change the expression its based off slightly
        if (this.hasBeenNormalized) {
            return this;
        }
        this.hasBeenNormalized = true;
        
        Expression typeExpression = getTypeClause();
        typeExpression.normalize(normalizer);

        if (this.baseExpression != null) {//should never be null
            // First normalize the base.
            setBaseExpression(this.baseExpression.normalize(normalizer));
            if (getAsOfClause() == null) {
                asOf(this.baseExpression.getAsOfClause());
            }
        }

        //This class has no validation but we should still make the method call for consistency
        //bug # 2956674
        //validation is moved into normalize to ensure that expressions are valid before we attempt to work with them
        validateNode();
        //the following is based on QueryKey.normalize

        SQLSelectStatement statement = normalizer.getStatement();
        //no longer directly normalize the typeExpressionBase, or find a way to use it
        this.typeExpressionBase = (ObjectExpression)this.typeExpressionBase.normalize(normalizer);


        // Normalize the ON clause if present.  Need to use rebuild, not twist as parameters are real parameters.
        if (this.onClause != null) {//not sure this is needed/valid
            this.onClause = this.onClause.normalize(normalizer);
        }

        ClassDescriptor parentDescriptor = this.typeExpressionBase.getDescriptor();
        boolean isSTI =  getOwnedSubTables().isEmpty();
        //only really valid if it has inheritance, but better this code than skipping it into the joins

        if (isSTI) {
            if (foreignKeyJoinPointer != null) {
                // If this expression is right side of an objExp.equal(objExp), one
                // need not add additionalExpressionCriteria twice.
                // Also the join will replace the original objExp.equal(objExp).
                // For CR#2456.
                foreignKeyJoinPointer.add(typeExpression.and(this.onClause));
            } else {
                //this just and's in the entire expression to the normalizer's expression.  
                //Need to use this for TYPE and none-outerjoin components
                normalizer.addAdditionalLocalExpression(typeExpression.and(this.onClause));
            }
            return this;
        }

        //if shouldPrintOuterJoinInWhereClause is true, this is this child's tables joined together in one expression
        Expression treatJoinTableExpressions = getTreatCriteria();

        boolean parentUsingOuterJoinForMultitableInheritance = typeExpressionBase.isUsingOuterJoinForMultitableInheritance();

        if (treatJoinTableExpressions != null) {
            treatJoinTableExpressions = treatJoinTableExpressions.normalize(normalizer);
        }
        Integer postition = typeExpressionBase.getOuterJoinExpIndex();
        if (postition!=null ) {
            if (parentUsingOuterJoinForMultitableInheritance) {
                //outer join was done, so our class' tables would have been included 
                return this;
            }

            if (getSession().getPlatform().isInformixOuterJoin()) {
                normalizer.addAdditionalLocalExpression(typeExpression.and(additionalTreatExpressionCriteria()).and(this.onClause));
                return this;
            } else if (((!getSession().getPlatform().shouldPrintOuterJoinInWhereClause())) 
                    || (!getSession().getPlatform().shouldPrintInnerJoinInWhereClause())) {

                //Adds the left joins from treat to the base QKE joins.
                Map<DatabaseTable, Expression> map = statement.getOuterJoinExpressionsHolders().get(postition).outerJoinedAdditionalJoinCriteria;
                if (map !=null) {
                    map.putAll(additionalTreatExpressionCriteriaMap());
                } else {
                    statement.getOuterJoinExpressionsHolders().get(postition).outerJoinedAdditionalJoinCriteria = additionalTreatExpressionCriteriaMap();
                }
                return this;
            }
        } else if (!getSession().getPlatform().shouldPrintOuterJoinInWhereClause()
                || (!getSession().getPlatform().shouldPrintInnerJoinInWhereClause())) {
            //the base is not using an outer join, so we add a new one for this class' tables.  
            Map additionalExpMap = additionalTreatExpressionCriteriaMap();
            if (additionalExpMap!=null && !additionalExpMap.isEmpty()) {
                statement.addOuterJoinExpressionsHolders(additionalExpMap, parentDescriptor);
            }
        }
        typeExpression = typeExpression.normalize(normalizer);

        if (foreignKeyJoinPointer != null) {
            // If this expression is right side of an objExp.equal(objExp), one
            // need not add additionalExpressionCriteria twice.
            // Also the join will replace the original objExp.equal(objExp).
            // For CR#2456.
            foreignKeyJoinPointer.add(typeExpression.and(this.onClause));
        } else {
            //this just and's in the entire expression to the normalizer's expression.  Need to use this for TYPE and non-outerjoin components
            normalizer.addAdditionalLocalExpression(typeExpression.and(additionalTreatExpressionCriteria()).and(this.onClause));
        }
        return this;
    }
}