1 17 package org.apache.ws.jaxme.sqls.oracle; 18 19 import org.apache.ws.jaxme.sqls.ColumnReference; 20 import org.apache.ws.jaxme.sqls.DeleteStatement; 21 import org.apache.ws.jaxme.sqls.InsertStatement; 22 import org.apache.ws.jaxme.sqls.JoinReference; 23 import org.apache.ws.jaxme.sqls.SelectStatement; 24 import org.apache.ws.jaxme.sqls.SelectTableReference; 25 import org.apache.ws.jaxme.sqls.UpdateStatement; 26 import org.apache.ws.jaxme.sqls.impl.SQLGeneratorImpl; 27 import org.apache.ws.jaxme.sqls.impl.StatementMetaData; 28 29 30 33 public class OraSQLGeneratorImpl extends SQLGeneratorImpl implements OraSQLGenerator { 34 private boolean isOracle8Compatibility; 35 36 protected boolean isTableAliasUsingAs() { return false; } 37 38 40 public void setOracle8Compatibility(boolean pOracle8Compatibility) { 41 isOracle8Compatibility = pOracle8Compatibility; 42 } 43 44 46 public boolean isOracle8Compatibility() { 47 return isOracle8Compatibility; 48 } 49 50 protected StatementMetaData newStatementMetaData(SelectStatement pQuery) { 51 return new OraStatementMetaData(pQuery); 52 } 53 54 protected StatementMetaData newStatementMetaData(DeleteStatement pQuery) { 55 return new OraStatementMetaData(pQuery); 56 } 57 58 protected StatementMetaData newStatementMetaData(UpdateStatement pQuery, ColumnReference[] pColumns) { 59 return new OraStatementMetaData(pQuery, pColumns); 60 } 61 62 protected StatementMetaData newStatementMetaData(InsertStatement pQuery, ColumnReference[] pColumns) { 63 return new OraStatementMetaData(pQuery, pColumns); 64 } 65 66 protected String getSelectQueryFromClause(SelectStatement pQuery, StatementMetaData pData) { 67 if (isOracle8Compatibility()) { 68 SelectTableReference tableReference = pQuery.getSelectTableReference(); 69 if (tableReference == null) { 70 return super.getSelectQueryFromClause(pQuery, pData); 71 } 72 StringBuffer sb = new StringBuffer (" FROM "); 73 sb.append(getTableAlias(pData, tableReference)); 74 for (JoinReference joinReference = tableReference.getRightJoinedTableReference(); 75 joinReference != null; 76 joinReference = joinReference.getRightJoinedTableReference()) { 77 sb.append(", "); 78 sb.append(getTableAlias(pData, joinReference)); 79 } 80 return sb.toString(); 81 } else { 82 return super.getSelectQueryFromClause(pQuery, pData); 83 } 84 } 85 86 protected String getSelectQueryConstraints(SelectStatement pQuery, StatementMetaData pData, 87 StatementMetaData.LocalData pLocalData) { 88 String result; 89 if (isOracle8Compatibility()) { 90 SelectTableReference tableReference = pQuery.getSelectTableReference(); 91 if (tableReference == null) { 92 result = super.getSelectQuery(pQuery, pData); 93 } else { 94 StringBuffer sb = new StringBuffer (); 95 for (JoinReference joinReference = tableReference.getRightJoinedTableReference(); 96 joinReference != null; 97 joinReference = joinReference.getRightJoinedTableReference()) { 98 OraJoinReferenceImpl oraJoin = null; 99 if (joinReference instanceof OraJoinReferenceImpl) { 100 oraJoin = (OraJoinReferenceImpl) joinReference; 101 } 102 String onClause; 103 if (oraJoin == null) { 104 onClause = getWhereClause(pData, joinReference.getOn()); 105 } else { 106 oraJoin.setIsOracle8LeftOuterJoin(true); 107 onClause = getWhereClause(pData, joinReference.getOn()); 108 oraJoin.setIsOracle8LeftOuterJoin(false); 109 } 110 if (onClause != null && onClause.length() > 0) { 111 if (pLocalData.hasWhereClause()) { 112 sb.append(" AND "); 113 } else { 114 pLocalData.setWhereClause(true); 115 } 116 sb.append(onClause); 117 } 118 } 119 String whereClause = getWhereClause(pData, pQuery.getWhere()); 120 if (whereClause != null && whereClause.length() > 0) { 121 if (pLocalData.hasWhereClause()) { 122 sb.append(" AND "); 123 } else { 124 pLocalData.setWhereClause(true); 125 } 126 sb.append(whereClause); 127 } 128 result = sb.toString(); 129 } 130 } else { 131 result = super.getSelectQueryConstraints(pQuery, pData, pLocalData); 132 } 133 134 if (pQuery instanceof OraSelectStatement) { 135 OraSelectStatement oraStatement = (OraSelectStatement) pQuery; 136 String s = getWhereClause(pData, oraStatement.getStartWith()); 137 if (s != null && s.length() > 0) { 138 result += " START WITH " + s; 139 } 140 s = getWhereClause(pData, oraStatement.getConnectBy()); 141 if (s != null && s.length() > 0) { 142 result += " CONNECT BY " + s; 143 } 144 } 145 146 return result; 147 } 148 149 protected String getColumnAlias(StatementMetaData pData, ColumnReference pColumn) { 150 String s = super.getColumnAlias(pData, pColumn); 151 if (pColumn.getTableReference() instanceof OraJoinReferenceImpl) { 152 OraJoinReferenceImpl oraJoin = (OraJoinReferenceImpl) pColumn.getTableReference(); 153 if (oraJoin.isOracle8LeftOuterJoin()) { 154 s = s + "(+)"; 155 } 156 } 157 if (pColumn instanceof OraColumnReference) { 158 OraColumnReference oraRef = (OraColumnReference) pColumn; 159 if (oraRef.isPrior()) { 160 s = "PRIOR " + s; 161 } 162 } 163 return s; 164 } 165 166 protected String getOrderColumn(StatementMetaData pData, SelectStatement.OrderColumn pColumn) { 167 String s = super.getOrderColumn(pData, pColumn); 168 if (pColumn instanceof OraSelectStatement.OraOrderColumn) { 169 OraSelectStatement.OraOrderColumn ooc = (OraSelectStatement.OraOrderColumn) pColumn; 170 if (ooc.isNullsFirst()) { 171 s += " NULLS FIRST"; 172 } 173 } 174 return s; 175 } 176 } 177 | Popular Tags |