1 /*
2 * Replica is published under the terms
3 * of the Apache Software License.
4 */
5 package replica.database.commands.plsql;
6
7 import java.io.StringReader;
8 import java.sql.SQLException;
9 import java.util.logging.Level;
10
11 import org.springframework.jdbc.datasource.DriverManagerDataSource;
12
13 import mobisnap.mobile_trx.MobisnapInterpreter;
14 import replica.database.commands.DatabaseCommand;
15 import replica.database.commands.DatabaseCommandVO;
16 import replica.server.commands.PrintCommand;
17
18 /***
19 *
20 * @author Pedro Costa
21 * @author Helder Silva
22 * @since 30/Jan/2004
23 */
24 public class PlsqlDbCommand extends DatabaseCommand {
25
26 MobisnapInterpreter mobisnapInterpreter;
27 DriverManagerDataSource dataSource;
28
29 /***
30 *
31 */
32 public PlsqlDbCommand() {
33 super();
34 }
35
36 public void init(){
37 try{
38 mobisnapInterpreter = new MobisnapInterpreter(dataSource.getDriverClassName(),
39 dataSource.getUrl(), dataSource.getUsername(), dataSource.getPassword());
40 }
41 catch(SQLException e){
42 throw new RuntimeException(e);
43 }
44 }
45
46 /* (non-Javadoc)
47 * @see replica.database.commands.DatabaseCommand#execute(replica.database.commands.DatabaseCommandVO)
48 */
49 protected Object execute(DatabaseCommandVO c) {
50 if( mobisnapInterpreter == null )
51 init();
52
53 try{
54 return PrintCommand.NAME + " " + mobisnapInterpreter.processMSQLTrx(new StringReader(c.getCommand()));
55 }
56 catch(Exception e){
57 getLogger().log(Level.SEVERE, e.getMessage(), e);
58 return PrintCommand.NAME + " " + e.getMessage();
59 }
60 }
61
62 /***
63 * @return
64 */
65 public DriverManagerDataSource getDataSource() {
66 return dataSource;
67 }
68
69 /***
70 * @param source
71 */
72 public void setDataSource(DriverManagerDataSource source) {
73 dataSource = source;
74 }
75
76 }
This page was automatically generated by Maven