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 {
17 simpleUpdateSQLStrategy = new SimpleUpdateSqlStatementStrategy();
18 selectSQLStrategy = new SelectSqlStatementStrategy();
19 callableSQLStrategy = new CallableSqlStatementStrategy();
20 }
21
22 public SqlStatementStrategy create(String sql, Object payload)
23 throws Exception
24 {
25 String sqlLowerCase = sql.toLowerCase();
26
27 if( sqlLowerCase.startsWith("insert") ||
28 sqlLowerCase.startsWith("update") ||
29 sqlLowerCase.startsWith("delete") ||
30 sqlLowerCase.startsWith("merge"))
31 {
32 return simpleUpdateSQLStrategy;
33 }
34
35 if (sqlLowerCase.startsWith("select"))
36 {
37 return selectSQLStrategy;
38 }
39
40 if (sqlLowerCase.startsWith("call"))
41 {
42 return callableSQLStrategy;
43 }
44
45 throw new IllegalArgumentException("No SQL Strategy found for SQL statement: " + sql);
46 }
47
48 }