| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
package net.wotonomy.access; |
| 19 |
|
|
| 20 |
|
import java.lang.reflect.Constructor; |
| 21 |
|
|
| 22 |
|
import net.wotonomy.control.EOFetchSpecification; |
| 23 |
|
import net.wotonomy.control.EOQualifier; |
| 24 |
|
import net.wotonomy.foundation.NSArray; |
| 25 |
|
import net.wotonomy.foundation.NSDictionary; |
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
public class EOSQLExpressionFactory { |
| 34 |
|
|
| 35 |
|
protected EOAdaptor _adaptor; |
| 36 |
|
protected Class _expressionClass; |
| 37 |
|
private Constructor _instantiator; |
| 38 |
|
|
| 39 |
|
public EOSQLExpressionFactory(EOAdaptor adaptor) { |
| 40 |
0 |
super(); |
| 41 |
0 |
_adaptor = adaptor; |
| 42 |
0 |
_expressionClass = _adaptor.expressionClass(); |
| 43 |
0 |
if (_expressionClass == null) |
| 44 |
0 |
throw new IllegalStateException("EOAdaptor " + _adaptor.name() + " returned null for expressionClass()"); |
| 45 |
0 |
} |
| 46 |
|
|
| 47 |
|
public EOAdaptor adaptor() { |
| 48 |
0 |
return _adaptor; |
| 49 |
|
} |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
public EOSQLExpression createExpression(EOEntity entity) { |
| 58 |
0 |
EOSQLExpression expr = null; |
| 59 |
0 |
if (_instantiator == null) { |
| 60 |
|
try { |
| 61 |
0 |
_instantiator = _expressionClass.getConstructor(new Class[]{ EOEntity.class }); |
| 62 |
0 |
} catch (Exception ex) { |
| 63 |
0 |
throw new IllegalArgumentException("The expression class " + _expressionClass.getName() + " has no constructor with an entity parameter."); |
| 64 |
0 |
} |
| 65 |
|
} |
| 66 |
|
try { |
| 67 |
0 |
expr = (EOSQLExpression)_instantiator.newInstance(new Object[]{ entity }); |
| 68 |
0 |
} catch (Exception ex) { |
| 69 |
0 |
throw new IllegalArgumentException("Cannot create new expression of class " + _expressionClass.getName()); |
| 70 |
0 |
} |
| 71 |
0 |
return expr; |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
public EOSQLExpression expressionForEntity(EOEntity entity) { |
| 75 |
0 |
return createExpression(entity); |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
public EOSQLExpression deleteStatementWithQualifier(EOQualifier qualifier, EOEntity entity) { |
| 79 |
0 |
EOSQLExpression expr = createExpression(entity); |
| 80 |
0 |
expr.prepareDeleteExpressionForQualifier(qualifier); |
| 81 |
0 |
return expr; |
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
public EOSQLExpression insertStatementForRow(NSDictionary row, EOEntity entity) { |
| 85 |
0 |
EOSQLExpression expr = createExpression(entity); |
| 86 |
0 |
expr.prepareInsertExpressionWithRow(row); |
| 87 |
0 |
return expr; |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
public EOSQLExpression selectStatementForAttributes(NSArray atts, boolean lock, EOFetchSpecification fspec, EOEntity entity) { |
| 91 |
0 |
EOSQLExpression expr = createExpression(entity); |
| 92 |
0 |
expr.prepareSelectExpressionWithAttributes(atts, lock, fspec); |
| 93 |
0 |
return expr; |
| 94 |
|
} |
| 95 |
|
|
| 96 |
|
public EOSQLExpression updateStatementForRow(NSDictionary row, EOQualifier qualifier, EOEntity entity) { |
| 97 |
0 |
EOSQLExpression expr = createExpression(entity); |
| 98 |
0 |
expr.prepareUpdateExpressionWithRow(row, qualifier); |
| 99 |
0 |
return expr; |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
public EOSQLExpression expressionForString(String sql) { |
| 103 |
0 |
EOSQLExpression expr = null; |
| 104 |
|
try { |
| 105 |
0 |
expr = (EOSQLExpression)_expressionClass.newInstance(); |
| 106 |
0 |
} catch (Exception e) { |
| 107 |
0 |
return null; |
| 108 |
0 |
} |
| 109 |
0 |
expr.setStatement(sql); |
| 110 |
0 |
return expr; |
| 111 |
|
} |
| 112 |
|
|
| 113 |
|
public Class expressionClass() { |
| 114 |
0 |
return _expressionClass; |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
|
|
| 130 |
|
|
| 131 |
|
|