1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.transport.jdbc.sqlstrategy; |
8 | |
|
9 | |
public class DefaultSqlStatementStrategyFactory implements SqlStatementStrategyFactory |
10 | |
{ |
11 | |
protected SimpleUpdateSqlStatementStrategy simpleUpdateSQLStrategy; |
12 | |
protected SelectSqlStatementStrategy selectSQLStrategy; |
13 | |
protected CallableSqlStatementStrategy callableSQLStrategy; |
14 | |
|
15 | |
public DefaultSqlStatementStrategyFactory() |
16 | 0 | { |
17 | 0 | simpleUpdateSQLStrategy = new SimpleUpdateSqlStatementStrategy(); |
18 | 0 | selectSQLStrategy = new SelectSqlStatementStrategy(); |
19 | 0 | callableSQLStrategy = new CallableSqlStatementStrategy(); |
20 | 0 | } |
21 | |
|
22 | |
public SqlStatementStrategy create(String sql, Object payload) |
23 | |
throws Exception |
24 | |
{ |
25 | 0 | String sqlLowerCase = sql.toLowerCase(); |
26 | |
|
27 | 0 | if( sqlLowerCase.startsWith("insert") || |
28 | |
sqlLowerCase.startsWith("update") || |
29 | |
sqlLowerCase.startsWith("delete") || |
30 | |
sqlLowerCase.startsWith("merge")) |
31 | |
{ |
32 | 0 | return simpleUpdateSQLStrategy; |
33 | |
} |
34 | |
|
35 | 0 | if (sqlLowerCase.startsWith("select")) |
36 | |
{ |
37 | 0 | return selectSQLStrategy; |
38 | |
} |
39 | |
|
40 | 0 | if (sqlLowerCase.startsWith("call")) |
41 | |
{ |
42 | 0 | return callableSQLStrategy; |
43 | |
} |
44 | |
|
45 | 0 | throw new IllegalArgumentException("No SQL Strategy found for SQL statement: " + sql); |
46 | |
} |
47 | |
|
48 | |
} |