View Javadoc

1   /*
2    * $Id: DefaultSqlStatementStrategyFactory.java 20319 2010-11-24 14:53:41Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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  }