org.eigenbase.oj.util
Class OJClassMap

java.lang.Object
  extended by org.eigenbase.oj.util.OJClassMap

public class OJClassMap
extends Object

An OJClassMap is ...

Since:
Jun 5, 2002
Version:
$Id: //open/dev/farrago/src/org/eigenbase/oj/util/OJClassMap.java#14 $
Author:
jhyde

Field Summary
private  boolean defineValueConstructors
          Do generated classes need value constructors? This can blow the Java virtual machine's limit on number of parameters per method, and in Farrago we don't actually use anything but the default constructor.
private  int id
          Sequence generator for generated class names.
private  Hashtable<String,OJSyntheticClass> mapKey2SyntheticClass
          Map a HashableArray (which is just a wrapper around an array of classes and names to the OJSyntheticClass which implements that array of types.
private  Class syntheticSuperClass
          Class from which synthetic classes should be subclassed.
private static Logger tracer
           
 
Constructor Summary
OJClassMap(Class<SyntheticObject> syntheticSuperClass)
           
OJClassMap(Class syntheticSuperClass, boolean defineValueConstructors)
           
 
Method Summary
private static void addAtomicClasses(Vector<OJClass> classesVector, OJClass clazz)
           
private  OJClass create(OJClass declarer, OJClass[] classes, String[] fieldNames, boolean isJoin)
           
 OJClass createJoin(OJClass declarer, OJClass[] classes)
          Creates a OJSyntheticClass, or if there is already one with the same number and type of fields, returns that.
 OJClass createProject(OJClass declarer, OJClass[] classes, String[] fieldNames)
          Creates a OJSyntheticClass with named fields.
private  ClassDeclaration makeDeclaration(String className, OJClass[] classes, String[] fieldNames)
           
 OJClass makeJoinType(OJClass declarer, OJClass left, OJClass right)
          Makes the type of a join.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tracer

private static final Logger tracer

mapKey2SyntheticClass

private Hashtable<String,OJSyntheticClass> mapKey2SyntheticClass
Map a HashableArray (which is just a wrapper around an array of classes and names to the OJSyntheticClass which implements that array of types.


syntheticSuperClass

private Class syntheticSuperClass
Class from which synthetic classes should be subclassed.


id

private int id
Sequence generator for generated class names.


defineValueConstructors

private final boolean defineValueConstructors
Do generated classes need value constructors? This can blow the Java virtual machine's limit on number of parameters per method, and in Farrago we don't actually use anything but the default constructor.

Constructor Detail

OJClassMap

public OJClassMap(Class<SyntheticObject> syntheticSuperClass)

OJClassMap

public OJClassMap(Class syntheticSuperClass,
                  boolean defineValueConstructors)
Method Detail

createProject

public OJClass createProject(OJClass declarer,
                             OJClass[] classes,
                             String[] fieldNames)
Creates a OJSyntheticClass with named fields. We don't check whether there is an equivalent class -- all classes with named fields are different.


create

private OJClass create(OJClass declarer,
                       OJClass[] classes,
                       String[] fieldNames,
                       boolean isJoin)

makeDeclaration

private ClassDeclaration makeDeclaration(String className,
                                         OJClass[] classes,
                                         String[] fieldNames)

createJoin

public OJClass createJoin(OJClass declarer,
                          OJClass[] classes)
Creates a OJSyntheticClass, or if there is already one with the same number and type of fields, returns that.


makeJoinType

public OJClass makeJoinType(OJClass declarer,
                            OJClass left,
                            OJClass right)

Makes the type of a join. There are two kinds of classes. A real class exists in the developer's environment. A synthetic class is constructed by the system to describe the intermediate and final results of a query. We are at liberty to modify synthetic classes.

If we join class C1 to class C2, the result is a synthetic class:

 class SC1 {
     C1 $f0;
     C2 $f1;
 }
 
Suppose that we now join class C3 to this; you would expect the result type to be a new synthetic class:
 class SC2 {
     class SC1 {
         C1 $f0;
         C2 $f1;
     } $f0;
     class C3 $f1;
 }
 
Now imagine the type resulting from a 6-way join. It will be very difficult to unpick the nesting in order to reference fields or to permute the join order. Therefore when one or both of the inputs to a join are synthetic, we break them apart and re-construct them. Type of synthetic class SC1 joined to class C3 above is
 class SC3 {
     C1 $f0;
     C2 $f1;
     C3 $f2;
 }
 

There are also row classes, which are synthetic classes arising from projections. The type of

select from (select deptno from dept)
   join emp
   join (select loc.nation, loc.zipcode from loc)
is
 class SC {
     int $f0;
     Emp $f1;
     class RC {
         String nation;
         int zipcode;
     } $f2;
 }
 

This deals with nesting; we still need to deal with the field permutations which occur when we re-order joins. A permutation operator moves fields back to their original positions, so that join transforms preserve type.


addAtomicClasses

private static void addAtomicClasses(Vector<OJClass> classesVector,
                                     OJClass clazz)