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 _over; 12 String _fromAlias = null; 13 String _toAlias = null; 14 boolean _reversed; 15 16 public JoinDefinition(DjExtent from, DjExtent to, String 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 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 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 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 alias) 70 { 71 _fromAlias = alias.toLowerCase(); 72 } 73 74 public void setToAlias(String 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 createUniqueAlias(String 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 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 |