1 28 29 package com.caucho.ejb.cfg; 30 31 import com.caucho.amber.field.AbstractField; 32 import com.caucho.config.ConfigException; 33 import com.caucho.util.L10N; 34 35 import javax.annotation.PostConstruct; 36 import java.util.Collection ; 37 38 41 public class CmpRelationRole { 42 private static L10N L = new L10N(CmpRelationRole.class); 43 44 private CmpRelation _relation; 45 private CmpRelationRole _target; 46 47 private String _location; 48 49 private String _ejbName; 50 private String _fieldName; 51 52 private boolean _cascadeDelete; 53 private String _multiplicity; 54 55 private SqlRelation []_sqlColumns = new SqlRelation[0]; 56 private String _orderBy; 57 58 private AbstractField _amberField; 59 private Class _javaType; 60 61 private boolean _isImplicit; 62 63 66 public CmpRelationRole(CmpRelation relation) 67 { 68 _relation = relation; 69 } 70 71 74 public void setDescription(String description) 75 { 76 } 77 78 81 public CmpRelation getRelation() 82 { 83 return _relation; 84 } 85 86 89 public CmpRelationRole getTarget() 90 { 91 return _target; 92 } 93 94 97 public void setTarget(CmpRelationRole target) 98 { 99 _target = target; 100 } 101 102 105 public void setConfigLocation(String filename, int line) 106 { 107 _location = filename + ":" + line + ": "; 108 } 109 110 113 public String getLocation() 114 { 115 return _location; 116 } 117 118 121 public void setEjbRelationshipRoleName(String name) 122 { 123 } 124 125 128 public String getEJBName() 129 { 130 return _ejbName; 131 } 132 133 136 public void setEJBName(String ejbName) 137 { 138 _ejbName = ejbName; 139 } 140 141 144 public String getFieldName() 145 { 146 return _fieldName; 147 } 148 149 152 public void setFieldName(String fieldName) 153 { 154 _fieldName = fieldName; 155 } 156 157 160 public boolean getCascadeDelete() 161 { 162 return _cascadeDelete; 163 } 164 165 168 public void setCascadeDelete(boolean cascadeDelete) 169 { 170 _cascadeDelete = cascadeDelete; 171 } 172 173 176 public String getMultiplicity() 177 { 178 return _multiplicity; 179 } 180 181 184 public void setMultiplicity(String multiplicity) 185 throws ConfigException 186 { 187 _multiplicity = multiplicity; 188 189 if (multiplicity == null || 190 ! multiplicity.equals("One") && 191 ! multiplicity.equals("Many")) 192 throw new ConfigException(L.l("`{0}' is an unknown multiplicity. `One' and `Many' are the only allowed values.", multiplicity)); 193 } 194 195 198 public SqlRelation []getSQLColumns() 199 { 200 return _sqlColumns; 201 } 202 203 206 public void addSQLColumn(String sqlColumn, String references) 207 { 208 SqlRelation relation = new SqlRelation(_fieldName); 209 210 relation.setSQLColumn(sqlColumn); 211 relation.setReferences(references); 212 213 if (_sqlColumns == null) 214 _sqlColumns = new SqlRelation[] { relation }; 215 else { 216 SqlRelation []newColumns = new SqlRelation[_sqlColumns.length + 1]; 217 System.arraycopy(_sqlColumns, 0, newColumns, 0, _sqlColumns.length); 218 219 newColumns[_sqlColumns.length] = relation; 220 _sqlColumns = newColumns; 221 } 222 } 223 224 public SqlColumn createSqlColumn() 225 { 226 return new SqlColumn(); 227 } 228 229 232 public String getOrderBy() 233 { 234 return _orderBy; 235 } 236 237 240 public void setOrderBy(String orderBy) 241 { 242 _orderBy = orderBy; 243 } 244 245 248 public boolean isImplicit() 249 { 250 return _isImplicit; 251 } 252 253 256 public void setImplicit(boolean isImplicit) 257 { 258 _isImplicit = isImplicit; 259 } 260 261 264 public void setJavaType(Class cl) 265 { 266 _javaType = cl; 267 } 268 269 272 public void setAmberField(AbstractField field) 273 { 274 _amberField = field; 275 } 276 277 280 public AbstractField getAmberField() 281 { 282 return _amberField; 283 } 284 285 288 public boolean isCollection() 289 { 290 return _javaType != null && Collection .class.isAssignableFrom(_javaType); 291 } 292 293 296 public void merge(CmpRelationRole newRole) 297 { 298 if (_sqlColumns.length == 0) 299 _sqlColumns = newRole.getSQLColumns(); 300 } 301 302 304 307 public RoleSource createRelationshipRoleSource() 308 { 309 return new RoleSource(); 310 } 311 312 315 public CmrField createCmrField() 316 { 317 return new CmrField(); 318 } 319 320 323 public boolean equals(Object o) 324 { 325 if (! (o instanceof CmpRelationRole)) 326 return false; 327 328 CmpRelationRole role = (CmpRelationRole) o; 329 330 if (! _ejbName.equals(role._ejbName)) 331 return false; 332 333 if (_fieldName == null || role._fieldName == null) 334 return _fieldName == role._fieldName; 335 336 if (! _fieldName.equals(role._fieldName)) 337 return false; 338 339 return true; 340 } 341 342 public class RoleSource { 343 public void setEJBName(String name) 344 { 345 CmpRelationRole.this.setEJBName(name); 346 } 347 } 348 349 public class CmrField { 350 public void setCmrFieldName(String name) 351 { 352 CmpRelationRole.this.setFieldName(name); 353 } 354 355 public void setCmrFieldType(String name) 356 { 357 } 359 360 public SqlColumn createSqlColumn() 361 { 362 return new SqlColumn(); 363 } 364 } 365 366 public class SqlColumn { 367 private String _value; 368 private String _references; 369 370 public void setReferences(String references) 371 { 372 _references = references; 373 } 374 375 public void setValue(String value) 376 { 377 _value = value; 378 } 379 380 public void addText(String value) 381 { 382 _value = value; 383 } 384 385 @PostConstruct 386 public void init() 387 { 388 CmpRelationRole.this.addSQLColumn(_value, _references); 389 } 390 } 391 } 392 | Popular Tags |