| 1 | |
package org.apache.ojb.broker.accesslayer.sql; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
import org.apache.ojb.broker.OJBRuntimeException; |
| 19 | |
import org.apache.ojb.broker.metadata.ClassDescriptor; |
| 20 | |
import org.apache.ojb.broker.metadata.FieldDescriptor; |
| 21 | |
import org.apache.ojb.broker.util.logging.Logger; |
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
public class SqlExistStatement extends SqlPkStatement |
| 31 | |
{ |
| 32 | |
private static final String SELECT = "SELECT "; |
| 33 | |
private static final String FROM = " FROM "; |
| 34 | |
|
| 35 | |
private String sql; |
| 36 | |
|
| 37 | |
public SqlExistStatement(ClassDescriptor aCld, Logger aLogger) |
| 38 | |
{ |
| 39 | |
super(aCld, aLogger); |
| 40 | |
} |
| 41 | |
|
| 42 | |
|
| 43 | |
public String getStatement() |
| 44 | |
{ |
| 45 | |
if(sql == null) |
| 46 | |
{ |
| 47 | |
StringBuffer stmt = new StringBuffer(128); |
| 48 | |
ClassDescriptor cld = getClassDescriptor(); |
| 49 | |
|
| 50 | |
FieldDescriptor[] fieldDescriptors = cld.getPkFields(); |
| 51 | |
if(fieldDescriptors == null || fieldDescriptors.length == 0) |
| 52 | |
{ |
| 53 | |
throw new OJBRuntimeException("No PK fields defined in metadata for " + cld.getClassNameOfObject()); |
| 54 | |
} |
| 55 | |
FieldDescriptor field = fieldDescriptors[0]; |
| 56 | |
|
| 57 | |
stmt.append(SELECT); |
| 58 | |
stmt.append(field.getColumnName()); |
| 59 | |
stmt.append(FROM); |
| 60 | |
stmt.append(cld.getFullTableName()); |
| 61 | |
appendWhereClause(cld, false, stmt); |
| 62 | |
|
| 63 | |
sql = stmt.toString(); |
| 64 | |
} |
| 65 | |
return sql; |
| 66 | |
} |
| 67 | |
} |