Revision 44853

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/DataManager.java
80 80
    public static final String FUNCTION_CURRENT_ROW = "CURRENT_ROW";
81 81
    public static final String FUNCTION_CURRENT_STORE = "CURRENT_STORE";
82 82
    public static final String FUNCTION_ISSELECTED_CURRENT_ROW = "ISSELECTED_CURRENT_ROW";
83
    public static final String FUNCTION_GEOMETRY = "GEOMETRY";
83 84
    
84 85
    public static final String DAL_PREFERRED_COLUMNS = "DAL.Preferred.Columns";
85 86
    
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/dataaccess/GeometryFunction.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.expressionevaluator.impl.function.dataaccess;
25

  
26
import org.apache.commons.lang3.Range;
27
import org.gvsig.expressionevaluator.Interpreter;
28
import org.gvsig.expressionevaluator.impl.DALFunctions;
29
import static org.gvsig.fmap.dal.DataManager.FUNCTION_GEOMETRY;
30
import org.gvsig.fmap.dal.feature.Feature;
31
import org.gvsig.fmap.geom.Geometry;
32

  
33
/**
34
 *
35
 * @author jjdelcerro
36
 */
37
public class GeometryFunction extends AbstractFeatureFunction {
38

  
39
  public GeometryFunction() {
40
    super(
41
            DALFunctions.GROUP_DATA_ACCESS,
42
            FUNCTION_GEOMETRY,
43
            Range.is(0),
44
            "Returns the value of the field that stores the default geometry " +
45
              "of the current row or feature.",
46
            FUNCTION_GEOMETRY + "()",
47
            null,
48
            "Geometry",
49
            false
50
    );
51
  }
52

  
53
  @Override
54
  public boolean allowConstantFolding() {
55
    return false;
56
  }
57

  
58
  @Override
59
  public Object call(Interpreter interpreter, Object[] args) throws Exception {
60
    Feature feature = this.current_row(interpreter);
61
    Geometry geom = feature.getDefaultGeometry();
62
    return geom;
63
  }
64

  
65
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/dataaccess/AbstractFeatureFunction.java
1
package org.gvsig.expressionevaluator.impl.function.dataaccess;
2

  
3
import org.apache.commons.lang3.Range;
4
import org.gvsig.expressionevaluator.Interpreter;
5
import org.gvsig.expressionevaluator.spi.AbstractFunction;
6
import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_ROW;
7
import org.gvsig.fmap.dal.feature.Feature;
8

  
9
/**
10
 *
11
 * @author jjdelcerro
12
 */
13
public abstract class AbstractFeatureFunction extends AbstractFunction {
14

  
15
  protected AbstractFeatureFunction(String group, String name, Range argc, String description, String template, String[] descriptionArgs, String returnType, boolean sqlCompatible) {
16
    super(group, name, argc, description, template, descriptionArgs, returnType, sqlCompatible);
17
  }
18
  
19
  protected AbstractFeatureFunction(String group, String name, Range argc, String description, String template, String[] descriptionArgs, String returnType) {
20
    super(group, name, argc, description, template, descriptionArgs, returnType);
21
  }
22

  
23
  public Feature current_row(Interpreter interpreter) {
24
    try {
25
      Feature f = (Feature) interpreter.call(FUNCTION_CURRENT_ROW);
26
      return f;
27
    } catch (Exception ex) {
28
      return null;
29
    }
30
  }
31
  
32
  
33
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/dataaccess/CurrentStoreFunction.java
26 26
import org.apache.commons.lang3.Range;
27 27
import org.gvsig.expressionevaluator.Interpreter;
28 28
import org.gvsig.expressionevaluator.impl.DALFunctions;
29
import org.gvsig.expressionevaluator.spi.AbstractFunction;
30
import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_ROW;
31 29
import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_STORE;
32 30
import org.gvsig.fmap.dal.feature.Feature;
33 31

  
......
35 33
 *
36 34
 * @author jjdelcerro
37 35
 */
38
public class CurrentStoreFunction extends AbstractFunction {
36
public class CurrentStoreFunction extends AbstractFeatureFunction {
39 37

  
40 38
  public CurrentStoreFunction() {
41 39
    super(
......
51 49
    );
52 50
  }
53 51

  
54
  private Feature current_row(Interpreter interpreter) {
55
    try {
56
      Feature f = (Feature) interpreter.call(FUNCTION_CURRENT_ROW);
57
      return f;
58
    } catch (Exception ex) {
59
      return null;
60
    }
61
  }
62

  
63 52
  @Override
64 53
  public Object call(Interpreter interpreter, Object[] args) throws Exception {
65 54
    Feature feature = this.current_row(interpreter);
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/dataaccess/ExistsFunction.java
29 29
import org.gvsig.expressionevaluator.ExpressionRuntimeException;
30 30
import org.gvsig.expressionevaluator.Interpreter;
31 31
import org.gvsig.expressionevaluator.impl.DALFunctions;
32
import org.gvsig.expressionevaluator.spi.AbstractFunction;
33 32
import static org.gvsig.fmap.dal.DataManager.FUNCTION_EXISTS;
34 33
import org.gvsig.tools.util.UnmodifiableBasicCollection;
35 34
import org.gvsig.tools.util.UnmodifiableBasicCollection64;
......
38 37
 *
39 38
 * @author jjdelcerro
40 39
 */
41
public class ExistsFunction extends AbstractFunction {
40
public class ExistsFunction extends AbstractFeatureFunction {
42 41

  
43 42
  public static final String NAME = "EXISTS";
44 43

  
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/dataaccess/IsSelectedCurrentRowFunction.java
26 26
import org.apache.commons.lang3.Range;
27 27
import org.gvsig.expressionevaluator.Interpreter;
28 28
import org.gvsig.expressionevaluator.impl.DALFunctions;
29
import org.gvsig.expressionevaluator.spi.AbstractFunction;
30
import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_ROW;
31 29
import static org.gvsig.fmap.dal.DataManager.FUNCTION_ISSELECTED_CURRENT_ROW;
32 30
import org.gvsig.fmap.dal.feature.Feature;
33 31
import org.gvsig.fmap.dal.feature.FeatureSelection;
......
37 35
 *
38 36
 * @author jjdelcerro
39 37
 */
40
public class IsSelectedCurrentRowFunction extends AbstractFunction {
38
public class IsSelectedCurrentRowFunction extends AbstractFeatureFunction {
41 39
  
42 40
  public IsSelectedCurrentRowFunction() {
43 41
    super(
......
53 51
    );
54 52
  }
55 53

  
56
  private Feature current_row(Interpreter interpreter) {
57
    try {
58
      Feature f = (Feature) interpreter.call(FUNCTION_CURRENT_ROW);
59
      return f;
60
    } catch (Exception ex) {
61
      return null;
62
    }
63
  }
64

  
65 54
  @Override
66 55
  public Object call(Interpreter interpreter, Object[] args) throws Exception {
67
    Feature feature = current_row(interpreter);
56
    Feature feature = this.current_row(interpreter);
68 57
    if (feature == null) {
69 58
      return false;
70 59
    }
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/dataaccess/SelectFunction.java
41 41
import org.gvsig.expressionevaluator.Optimizer;
42 42
import org.gvsig.expressionevaluator.SymbolTable;
43 43
import org.gvsig.expressionevaluator.impl.DALFunctions;
44
import org.gvsig.expressionevaluator.spi.AbstractFunction;
45 44
import org.gvsig.fmap.dal.DALLocator;
46 45
import org.gvsig.fmap.dal.DataManager;
47 46
import static org.gvsig.fmap.dal.DataManager.FUNCTION_SELECT;
......
62 61
 * @author jjdelcerro
63 62
 */
64 63
public class SelectFunction 
65
        extends AbstractFunction 
64
        extends AbstractFeatureFunction 
66 65
        implements Optimizer.FunctionOptimizer
67 66
  {
68 67

  
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/dataaccess/ForeingValueFunction.java
30 30
import org.gvsig.expressionevaluator.ExpressionRuntimeException;
31 31
import org.gvsig.expressionevaluator.Interpreter;
32 32
import org.gvsig.expressionevaluator.impl.DALFunctions;
33
import org.gvsig.expressionevaluator.spi.AbstractFunction;
34 33
import org.gvsig.fmap.dal.DataManager;
35
import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_ROW;
36 34
import static org.gvsig.fmap.dal.DataManager.FUNCTION_FOREING_VALUE;
37 35
import org.gvsig.fmap.dal.feature.Feature;
38 36
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
......
41 39
import org.gvsig.tools.util.UnmodifiableBasicListAdapter;
42 40
import org.gvsig.tools.util.UnmodifiableBasicListArrayAdapter;
43 41

  
44
public class ForeingValueFunction extends AbstractFunction {
42
public class ForeingValueFunction extends AbstractFeatureFunction {
45 43

  
46 44
  public ForeingValueFunction() {
47 45
    super(
......
57 55
    );
58 56
  }
59 57

  
60
  private Feature current_row(Interpreter interpreter) {
61
    try {
62
      Feature f = (Feature) interpreter.call(FUNCTION_CURRENT_ROW);
63
      return f;
64
    } catch (Exception ex) {
65
      return null;
66
    }
67
  }
68
  
69 58
  @Override
70 59
  public Object call(Interpreter interpreter, Object[] args) throws Exception {
71 60
    UnmodifiableBasicList<String> fieldNames;
72 61
    switch( args.length) {
73 62
      case 1:
74 63
        Object fields_o = getObject(args, 0);
64
        if( fields_o == null ) {
65
          throw new ExpressionRuntimeException("Problems calling '" + DataManager.FUNCTION_FOREING_VALUE + "' function, type of parameter 'null' not supported, use string or list.");
66
        }
75 67
        if (fields_o instanceof String[]) {
76 68
          fieldNames = new UnmodifiableBasicListArrayAdapter<>((String[]) fields_o);
77 69
        } else if (fields_o instanceof List) {
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/dataaccess/SelectCountFunction.java
29 29
import org.gvsig.expressionevaluator.ExpressionRuntimeException;
30 30
import org.gvsig.expressionevaluator.Interpreter;
31 31
import org.gvsig.expressionevaluator.impl.DALFunctions;
32
import org.gvsig.expressionevaluator.spi.AbstractFunction;
33 32
import org.gvsig.fmap.dal.DALLocator;
34 33
import org.gvsig.fmap.dal.DataManager;
35 34
import static org.gvsig.fmap.dal.DataManager.FUNCTION_SELECT_COUNT;
......
44 43
 * @author jjdelcerro
45 44
 */
46 45
@SuppressWarnings("UseSpecificCatch")
47
public class SelectCountFunction extends AbstractFunction {
46
public class SelectCountFunction extends AbstractFeatureFunction {
48 47

  
49 48
  public SelectCountFunction() {
50 49
    super(DALFunctions.GROUP_DATA_ACCESS,
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/dataaccess/CurrentRowFunction.java
33 33
 *
34 34
 * @author jjdelcerro
35 35
 */
36
public class CurrentRowFunction extends AbstractFunction {
36
public class CurrentRowFunction extends AbstractFeatureFunction {
37 37

  
38 38
  public CurrentRowFunction() {
39 39
    super(
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/expressionevaluator/impl/symboltable/DALSymbolTable.java
28 28
import org.gvsig.expressionevaluator.impl.function.dataaccess.CurrentStoreFunction;
29 29
import org.gvsig.expressionevaluator.impl.function.dataaccess.ExistsFunction;
30 30
import org.gvsig.expressionevaluator.impl.function.dataaccess.ForeingValueFunction;
31
import org.gvsig.expressionevaluator.impl.function.dataaccess.GeometryFunction;
31 32
import org.gvsig.expressionevaluator.impl.function.dataaccess.IsSelectedCurrentRowFunction;
32 33
import org.gvsig.expressionevaluator.impl.function.dataaccess.SelectCountFunction;
33 34
import org.gvsig.expressionevaluator.impl.function.dataaccess.SelectFunction;
......
55 56
        this.addFunction(new ForeingValueFunction());
56 57
        this.addFunction(new IsSelectedCurrentRowFunction());
57 58
        this.addFunction(new ForeingValueFunction());
59
        this.addFunction(new GeometryFunction());
58 60
    }    
59 61
}

Also available in: Unified diff