KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > repository > oql > core > util > JoinDefinition


1 package com.genimen.djeneric.repository.oql.core.util;
2
3 import com.genimen.djeneric.repository.DjExtent;
4 import com.genimen.djeneric.repository.exceptions.ObjectNotDefinedException;
5 import com.genimen.djeneric.util.DjLogger;
6
7 public class JoinDefinition
8 {
9   DjExtent _from;
10   DjExtent _to;
11   String JavaDoc _over;
12   String JavaDoc _fromAlias = null;
13   String JavaDoc _toAlias = null;
14   boolean _reversed;
15
16   public JoinDefinition(DjExtent from, DjExtent to, String JavaDoc over, boolean reversed)
17   {
18     _from = from;
19     _to = to;
20     _over = over;
21     _reversed = reversed;
22   }
23
24   public boolean isToAliasSet()
25   {
26     return _toAlias != null;
27   }
28
29   public boolean aliassesSet()
30   {
31     return _fromAlias != null && _toAlias != null;
32   }
33
34   public String JavaDoc toString()
35   {
36     try
37     {
38       return getJoin();
39     }
40     catch (ObjectNotDefinedException e)
41     {
42       DjLogger.log(e);
43       return e.getMessage();
44     }
45   }
46
47   public String JavaDoc getJoin() throws ObjectNotDefinedException
48   {
49     if (_reversed) return getAlias() + "." + _from.getIdProperty().getName() + " = " + getToAlias() + "." + _over;
50     else return getAlias() + "." + _over + " = " + getToAlias() + "." + _to.getIdProperty().getName();
51   }
52
53   public DjExtent getExtent()
54   {
55     return _from;
56   }
57
58   public String JavaDoc getAlias()
59   {
60     if (_fromAlias == null) return _from.getAlias();
61     return _fromAlias;
62   }
63
64   public DjExtent getToExtent()
65   {
66     return _to;
67   }
68
69   public void setFromAlias(String JavaDoc alias)
70   {
71     _fromAlias = alias.toLowerCase();
72   }
73
74   public void setToAlias(String JavaDoc alias)
75   {
76     _toAlias = alias.toLowerCase();
77   }
78
79   public void setFromAlias(int uid)
80   {
81     _fromAlias = createUniqueAlias(_from.getAlias(), uid);
82   }
83
84   private String JavaDoc createUniqueAlias(String JavaDoc alias, int uid)
85   {
86     if (alias.length() > 4) alias = alias.substring(0, 4);
87     return (alias + uid).toLowerCase();
88   }
89
90   public void setToAlias(int uid)
91   {
92     _toAlias = createUniqueAlias(_to.getAlias(), uid);
93   }
94
95   public String JavaDoc getToAlias()
96   {
97     if (_toAlias == null) return _to.getAlias();
98     return _toAlias;
99   }
100
101   public boolean isFromAliasSet()
102   {
103     return _fromAlias != null;
104   }
105
106   public boolean isReversed()
107   {
108     return _reversed;
109   }
110 }
Popular Tags