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