Revision 45606

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/ExecuteOperation.java
25 25

  
26 26
import java.sql.Connection;
27 27
import java.sql.ResultSet;
28
import java.sql.SQLException;
29 28
import java.sql.Statement;
30 29
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCTransactionRollbackException;
32 30
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
33 31
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
34
import static org.gvsig.fmap.dal.store.jdbc2.spi.operations.AbstractConnectionOperation.LOGGER;
35 32

  
36 33
public class ExecuteOperation extends AbstractConnectionOperation {
37 34

  
......
77 74
                JDBCUtils.closeQuietly(st);
78 75
                return null;
79 76
            }
80
            if(rs.getMetaData().getColumnCount() > 0) {
77
            if(rs.getMetaData().getColumnCount() > 1) {
81 78
                return rs;
82 79
            }
83 80
            if(!rs.next()){
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/impl/expressionevaluator/JDBCSymbolTable.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.store.jdbc2.impl.expressionevaluator;
25

  
26
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable;
27
import static org.gvsig.fmap.dal.store.jdbc2.impl.expressionevaluator.JDBCSymbolTableFactory.SYMBOLTABLE_NAME;
28

  
29
/**
30
 *
31
 * @author jjdelcerro
32
 */
33
public class JDBCSymbolTable 
34
        extends AbstractSymbolTable
35
    {   
36

  
37
    public JDBCSymbolTable() {
38
        super(SYMBOLTABLE_NAME);
39
        this.initFunctions();
40
    }
41
    
42
    private void initFunctions() {
43
        this.addFunction(new ExecuteSQLFunction());
44
        
45
    }    
46
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/impl/expressionevaluator/ExecuteSQLFunction.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.store.jdbc2.impl.expressionevaluator;
25

  
26
import org.apache.commons.lang3.Range;
27
import org.gvsig.expressionevaluator.Interpreter;
28
import org.gvsig.expressionevaluator.spi.AbstractFunction;
29
import org.gvsig.fmap.dal.DALLocator;
30
import org.gvsig.fmap.dal.DataManager;
31
import org.gvsig.fmap.dal.DataServerExplorerParameters;
32
import org.gvsig.fmap.dal.DataServerExplorerPoolEntry;
33
import org.gvsig.fmap.dal.feature.FeatureStore;
34
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
35
import static org.gvsig.fmap.dal.store.jdbc2.impl.expressionevaluator.JDBCSymbolTableFactory.GROUP_JDBC;
36

  
37
/**
38
 *
39
 * @author jjdelcerro
40
 */
41
public class ExecuteSQLFunction extends AbstractFunction {
42

  
43
  public static final String FUNCTION_EXECUTESQL = "EXECUTESQL";
44

  
45
  public ExecuteSQLFunction() {
46
    super(  GROUP_JDBC,
47
            FUNCTION_EXECUTESQL,
48
            Range.between(1,2),
49
            "Receive a connection and SQL string as argument.",
50
            FUNCTION_EXECUTESQL + "({{connection}}, sql)",
51
            new String[]{
52
              "connection - conextion string (optional)",
53
              "sql - sql string"
54
            },
55
            "Object",
56
            false
57
    );
58
  }
59

  
60
  @Override
61
  public boolean allowConstantFolding() {
62
    return false;
63
  }
64

  
65
  @Override
66
  public boolean useArgumentsInsteadObjects() {
67
    return false;
68
  }
69

  
70
  @Override
71
  public Object call(Interpreter interpreter, Object[] args) throws Exception {
72
      String connectionName;
73
      String sql;
74
      JDBCServerExplorer explorer;
75
      if (args.length==1) {
76
          sql = this.getStr(args, 0);
77
          FeatureStore store = (FeatureStore) interpreter.getSymbolTable().function(DataManager.FUNCTION_CURRENT_STORE).call(interpreter,(Object[]) null);
78
          explorer = (JDBCServerExplorer) store.getExplorer();
79
      } else {
80
        connectionName = this.getStr(args, 0);
81
        sql = this.getStr(args, 1);
82
        if (this.getObject(args, 0) instanceof JDBCServerExplorer) {
83
            explorer = (JDBCServerExplorer) this.getObject(args, 0);
84
        } else if (this.getObject(args, 0) instanceof FeatureStore) {
85
            explorer = (JDBCServerExplorer) ((FeatureStore) this.getObject(args, 0)).getExplorer();
86
        } else {
87
            DataManager dalManager = DALLocator.getManager();
88
            DataServerExplorerPoolEntry poolEntry = dalManager.getDataServerExplorerPool().get(connectionName);
89
            DataServerExplorerParameters explorerParameters = poolEntry.getExplorerParameters();
90
            explorer = (JDBCServerExplorer) dalManager.openServerExplorer(explorerParameters.getProviderName(), explorerParameters);
91
        }
92
      }
93
      Object result = explorer.execute(sql);
94
      return result;
95
      
96
  }
97

  
98
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/impl/expressionevaluator/JDBCSymbolTableFactory.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.store.jdbc2.impl.expressionevaluator;
25

  
26
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
27
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
28
import org.gvsig.expressionevaluator.SymbolTable;
29
import org.gvsig.expressionevaluator.spi.AbstractSymbolTableFactory;
30

  
31
/**
32
 *
33
 * @author jjdelcerro
34
 */
35
public class JDBCSymbolTableFactory extends AbstractSymbolTableFactory {
36

  
37
    private SymbolTable symbolTable;
38
    public static final String SYMBOLTABLE_NAME = "JDBC";
39
    public static final String GROUP_JDBC = "Data access";
40
    
41
    public JDBCSymbolTableFactory() {
42
        super(SYMBOLTABLE_NAME, true);
43
    }
44
    
45
    @Override
46
    public SymbolTable create(Object... args) {
47
        if( this.symbolTable==null ) {
48
            this.symbolTable = new JDBCSymbolTable();
49
        }
50
        return this.symbolTable;
51
    }
52
    
53
    public static final void selfRegister() {
54
        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
55
        
56
        manager.registerSymbolTable(new JDBCSymbolTableFactory());
57
    }
58
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/JDBCLibrary.java
32 32
import org.gvsig.fmap.dal.store.jdbc.JDBCResourceParameters;
33 33
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
34 34
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
35
import org.gvsig.fmap.dal.store.jdbc2.impl.expressionevaluator.JDBCSymbolTableFactory;
35 36
import org.gvsig.metadata.exceptions.MetadataException;
36 37
import org.gvsig.tools.library.AbstractLibrary;
37 38
import org.gvsig.tools.library.LibraryException;
......
114 115
//            dataman.registerServerExplorerFactory(new JDBCServerExplorerFactory());
115 116
//        }
116 117

  
118
        JDBCSymbolTableFactory.selfRegister();
119

  
117 120
        if (ex != null) {
118 121
            throw ex;
119 122
        }

Also available in: Unified diff