1 28 29 package com.caucho.ejb.cfg; 30 31 import com.caucho.config.ConfigException; 32 import com.caucho.util.L10N; 33 34 import javax.annotation.PostConstruct; 35 36 39 public class CmpRelation { 40 private static final L10N L = new L10N(CmpRelation.class); 41 42 private EjbConfig _config; 43 44 private String _location = ""; 45 46 private String _name; 47 private String _sqlTable; 48 49 private CmpRelationRole _sourceRole; 50 private CmpRelationRole _targetRole; 51 52 private int _roleCount; 53 54 57 public CmpRelation(EjbConfig config) 58 { 59 _config = config; 60 _sourceRole = new CmpRelationRole(this); 61 _targetRole = new CmpRelationRole(this); 62 63 _sourceRole.setTarget(_targetRole); 64 _targetRole.setTarget(_sourceRole); 65 } 66 67 70 public CmpRelation() 71 { 72 _sourceRole = new CmpRelationRole(this); 73 _targetRole = new CmpRelationRole(this); 74 75 _sourceRole.setTarget(_targetRole); 76 _targetRole.setTarget(_sourceRole); 77 } 78 79 82 public void setConfigLocation(String filename, int line) 83 { 84 _location = filename + ":" + line + ": "; 85 } 86 87 90 public String getLocation() 91 { 92 return _location; 93 } 94 95 98 public String getName() 99 { 100 return _name; 101 } 102 103 106 public void setName(String name) 107 { 108 _name = name; 109 } 110 111 114 public void setEJBRelationName(String name) 115 { 116 _name = name; 117 } 118 119 122 public String getSQLTable() 123 { 124 return _sqlTable; 125 } 126 127 130 public void setSQLTable(String sqlTable) 131 { 132 _sqlTable = sqlTable; 133 } 134 135 138 public CmpRelationRole getSourceRole() 139 { 140 if (_sourceRole.getFieldName() == null && 141 _targetRole.getFieldName() != null) 142 return _targetRole; 143 else 144 return _sourceRole; 145 } 146 147 150 public CmpRelationRole getTargetRole() 151 { 152 if (_sourceRole.getFieldName() == null && 153 _targetRole.getFieldName() != null) 154 return _sourceRole; 155 else 156 return _targetRole; 157 } 158 159 162 public String getSourceEJB() 163 { 164 return getSourceRole().getEJBName(); 165 } 166 167 170 public void setSourceEJB(String sourceEJB) 171 { 172 _sourceRole.setEJBName(sourceEJB); 173 } 174 175 178 public String getSourceField() 179 { 180 return getSourceRole().getFieldName(); 181 } 182 183 186 public void setSourceField(String sourceField) 187 { 188 _sourceRole.setFieldName(sourceField); 189 } 190 191 194 public boolean getSourceCascadeDelete() 195 { 196 return getSourceRole().getCascadeDelete(); 197 } 198 199 202 public void setSourceCascadeDelete(boolean sourceCascadeDelete) 203 { 204 _sourceRole.setCascadeDelete(sourceCascadeDelete); 205 } 206 207 210 public String getSourceMultiplicity() 211 { 212 return getSourceRole().getMultiplicity(); 213 } 214 215 218 public void setSourceMultiplicity(String sourceMultiplicity) 219 throws ConfigException 220 { 221 _sourceRole.setMultiplicity(sourceMultiplicity); 222 } 223 224 227 public SqlRelation []getSourceSQLColumns() 228 { 229 return getSourceRole().getSQLColumns(); 230 } 231 232 235 public void addSourceSQLColumn(String sqlColumn, String references) 236 { 237 _sourceRole.addSQLColumn(sqlColumn, references); 238 } 239 240 243 public CmpRelationRole.SqlColumn createSourceSqlColumn() 244 { 245 return _sourceRole.createSqlColumn(); 246 } 247 248 251 public String getSourceOrderBy() 252 { 253 return getSourceRole().getOrderBy(); 254 } 255 256 259 public void setSourceOrderBy(String sourceOrderBy) 260 { 261 _sourceRole.setOrderBy(sourceOrderBy); 262 } 263 264 267 public String getTargetEJB() 268 { 269 return getTargetRole().getEJBName(); 270 } 271 272 275 public void setTargetEJB(String targetEJB) 276 { 277 _targetRole.setEJBName(targetEJB); 278 } 279 280 283 public String getTargetField() 284 { 285 return getTargetRole().getFieldName(); 286 } 287 288 291 public void setTargetField(String targetField) 292 { 293 _targetRole.setFieldName(targetField); 294 } 295 296 299 public boolean getTargetCascadeDelete() 300 { 301 return getTargetRole().getCascadeDelete(); 302 } 303 304 307 public void setTargetCascadeDelete(boolean targetCascadeDelete) 308 { 309 _targetRole.setCascadeDelete(targetCascadeDelete); 310 } 311 312 315 public String getTargetMultiplicity() 316 { 317 return getTargetRole().getMultiplicity(); 318 } 319 320 323 public void setTargetMultiplicity(String targetMultiplicity) 324 throws ConfigException 325 { 326 _targetRole.setMultiplicity(targetMultiplicity); 327 } 328 329 332 public SqlRelation []getTargetSQLColumns() 333 { 334 return getTargetRole().getSQLColumns(); 335 } 336 337 340 public void addTargetSQLColumn(String sqlColumn, String references) 341 { 342 _targetRole.addSQLColumn(sqlColumn, references); 343 } 344 345 348 public CmpRelationRole.SqlColumn createTargetSqlColumn() 349 { 350 return _targetRole.createSqlColumn(); 351 } 352 353 356 public String getTargetOrderBy() 357 { 358 return getTargetRole().getOrderBy(); 359 } 360 361 364 public void setTargetOrderBy(String targetOrderBy) 365 { 366 _targetRole.setOrderBy(targetOrderBy); 367 } 368 369 372 public CmpRelationRole createEjbRelationshipRole() 373 throws ConfigException 374 { 375 _roleCount++; 376 377 if (_roleCount == 1) 378 return _sourceRole; 379 else if (_roleCount == 2) 380 return _targetRole; 381 else 382 throw new ConfigException(L.l("ejb-relation requires two ejb-relationship-role elements")); 383 } 384 385 388 public void merge(CmpRelation newRel) 389 throws ConfigException 390 { 391 if (_sqlTable == null) 392 _sqlTable = newRel.getSQLTable(); 393 394 _sourceRole.merge(newRel.getSourceRole()); 395 _targetRole.merge(newRel.getTargetRole()); 396 } 397 398 401 @PostConstruct 402 public void init() 403 throws ConfigException 404 { 405 if (getSourceEJB() == null) 406 throw new ConfigException(L.l("ejb-relation needs a source EJB.")); 407 408 if (getTargetEJB() == null) 409 throw new ConfigException(L.l("ejb-relation needs a target EJB.")); 410 411 if (getSourceField() == null) 412 throw new ConfigException(L.l("ejb-relation needs a source field.")); 413 } 414 415 418 public boolean equals(Object o) 419 { 420 if (! (o instanceof CmpRelation)) 421 return false; 422 423 CmpRelation relation = (CmpRelation) o; 424 425 return _sourceRole.equals(relation._sourceRole); 426 } 427 } 428 | Popular Tags |