Index: SQLBuilder.java
===================================================================
--- SQLBuilder.java	(revision 44197)
+++ SQLBuilder.java	(revision 44198)
@@ -3,14 +3,18 @@
 import java.util.List;
 import org.cresques.cts.IProjection;
 import org.gvsig.expressionevaluator.ExpressionBuilder;
-import org.gvsig.expressionevaluator.ExpressionBuilder.Config;
-import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import org.gvsig.expressionevaluator.ExpressionBuilder.GeometrySupportType;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Parameter;
 import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
-import org.gvsig.expressionevaluator.ExpressionBuilder.Visitable;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Variable;
+import org.gvsig.expressionevaluator.Formatter;
 import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
+import org.gvsig.fmap.dal.feature.FeatureType;
 
-public interface SQLBuilder extends ExpressionBuilder {
-    
+public interface SQLBuilder {
+
+    public static final String FEATURE_ATTRIBUTE_DESCRIPTOR = "FeatureAttributeDescriptor";
+
     public enum Privilege {
         SELECT,
         INSERT,
@@ -22,336 +26,429 @@
         ALL
     };
 
-    public interface Statement extends Visitable {
-        
-    }
-    
-    public interface SQLConfig extends Config {
-        public final static String default_schema = "default_schema";
-        
-        public final static String allowAutomaticValues = "allowAutomaticValues";
-        
-        public final static String Find_SRID = "Find_SRID";
-        public final static String ST_ExtentAggregate = "ST_ExtentAggregate";
-        public final static String ST_UnionAggregate = "ST_UnionAggregate";
-        public final static String count = "count";
-        public final static String count_distinct = "count_distinct";
+    public interface ColumnDescriptor {
 
-        public final static String type_boolean = "type_boolean";
-        public final static String type_byte = "type_byte";
-        public final static String type_bytearray = "type_bytearray";
-        public final static String type_geometry = "type_geometry";
-        public final static String type_char = "type_char";
-        public final static String type_date = "type_date";
-        public final static String type_double = "type_double";
-        public final static String type_numeric_p = "type_numeric_p";
-        public final static String type_numeric_ps = "type_numeric_ps";
-        public final static String type_bigdecimal = "type_bigdecimal";
-        public final static String type_float = "type_float";
-        public final static String type_int = "type_int";
-        public final static String type_long = "type_long";
-        public final static String type_string = "type_string";
-        public final static String type_string_p = "type_string_p";
-        public final static String type_time = "type_time";
-        public final static String type_timestamp = "type_timestamp";
-        public final static String type_version = "type_version";
-        public final static String type_URI = "type_URI";
-        public final static String type_URL = "type_URL";
-        public final static String type_FILE = "type_FILE";
-        public final static String type_FOLDER = "type_FOLDER";
-     
-        public final static String DELETE_FROM_table_WHERE_expresion = "DELETE_FROM_table_WHERE_expresion";
-        public final static String DELETE_FROM_table = "DELETE_FROM_table";
-        public final static String INSERT_INTO_table_columns_VALUES_values = "INSERT_INTO_table_columns_VALUES_values";
-        public final static String UPDATE_TABLE_STATISTICS_table = "UPDATE_TABLE_STATISTICS_table";        
-        public final static String DROP_TABLE_table = "DROP_TABLE_table";
-        public final static String DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table = "DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table";
-        public final static String DELETE_GEOMETRY_COLUMN_FROM_TABLE_table = "DELETE_GEOMETRY_COLUMN_FROM_TABLE_table";
-        public final static String UPDATE_table_SET_columnsAndValues_WHERE_expresion = "UPDATE_table_SET_columnsAndValues_WHERE_expresion";
-        public final static String UPDATE_table_SET_columnsAndValues = "UPDATE_table_SET_columnsAndValues";
-        public final static String GRANT_privileges_ON_table_TO_role = "GRANT_privileges_ON_table_TO_role";
-//        public final static String CREATE_INDEX_name_ON_table_column = "CREATE_INDEX_name_ON_table_column";
-//        public final static String CREATE_INDEX_name_ON_table_USING_GIST_column = "CREATE_INDEX_name_ON_table_USING_GIST_column";
-   
-    }
-    
-    public interface ColumnDescriptor {
         public String getName();
+
         public int getType();
+
         public int getSize();
+
         public int getPrecision();
+
         public boolean isPrimaryKey();
+
         public boolean isIndexed();
+
         public boolean isAutomatic();
+
         boolean allowNulls();
+
         public Object getDefaultValue();
+
         public int getGeometryType();
+
         public int getGeometrySubtype();
+
         public Object getGeometrySRSId();
+
         public boolean isGeometry();
-        
+
         public DataStoreParameters getStoreParameters();
-        
+
         public void setName(String name);
+
         public void setType(int type);
+
         public void setSize(int size);
+
         public void setPrecision(int precision);
+
         public void setIsPrimaryKey(boolean isPk);
+
         public void setIsAutomatic(boolean isAutomatic);
+
         public void setAllowNulls(boolean allowNulls);
+
         public void setDefaultValue(Object defaultValue);
+
         public void setGeometryType(int geom_type);
+
         public void setGeometrySubtype(int geom_subtype);
+
         public void setGeometrySRSId(Object geom_srsid);
     }
-    
-    public interface Column extends Variable {
-        public ColumnDescriptor getDescriptor();
+
+//    public interface ColumnDescriptorBuilder {
+//        public String getName();
+//        public int getType();
+//        public int getSize();
+//        public int getPrecision();
+//        public boolean isPrimaryKey();
+//        public boolean isIndexed();
+//        public boolean isAutomatic();
+//        boolean allowNulls();
+//        public Object getDefaultValue();
+//        public int getGeometryType();
+//        public int getGeometrySubtype();
+//        public Object getGeometrySRSId();
+//        public boolean isGeometry();
+//        
+//        public void setName(String name);
+//        public void setType(int type);
+//        public void setSize(int size);
+//        public void setPrecision(int precision);
+//        public void setIsPrimaryKey(boolean isPk);
+//        public void setIsAutomatic(boolean isAutomatic);
+//        public void setAllowNulls(boolean allowNulls);
+//        public void setDefaultValue(Object defaultValue);
+//        public void setGeometryType(int geom_type);
+//        public void setGeometrySubtype(int geom_subtype);
+//        public void setGeometrySRSId(Object geom_srsid);
+//    }
+//
+//    public interface Column extends Variable {
+//        public ColumnDescriptor getDescriptor();
+//    }
+    public interface StatementPart extends Value {
+
     }
-    
-    public interface TableNameBuilder extends Visitable {
+
+    public interface Statement extends StatementPart {
+
+    }
+
+    public interface TableNameBuilder extends StatementPart {
+
         public TableNameBuilder database(String name);
+
         public TableNameBuilder schema(String name);
+
         public TableNameBuilder name(String name);
+
         public String getDatabase();
+
         public String getSchema();
+
         public String getName();
+
         public boolean has_database();
+
         public boolean has_schema();
     }
-    
-    public interface ColumnDescriptorBuilder {
-        public String getName();
-        public int getType();
-        public int getSize();
-        public int getPrecision();
-        public boolean isPrimaryKey();
-        public boolean isIndexed();
-        public boolean isAutomatic();
-        boolean allowNulls();
-        public Object getDefaultValue();
-        public int getGeometryType();
-        public int getGeometrySubtype();
-        public Object getGeometrySRSId();
-        public boolean isGeometry();
-        
-        public void setName(String name);
-        public void setType(int type);
-        public void setSize(int size);
-        public void setPrecision(int precision);
-        public void setIsPrimaryKey(boolean isPk);
-        public void setIsAutomatic(boolean isAutomatic);
-        public void setAllowNulls(boolean allowNulls);
-        public void setDefaultValue(Object defaultValue);
-        public void setGeometryType(int geom_type);
-        public void setGeometrySubtype(int geom_subtype);
-        public void setGeometrySRSId(Object geom_srsid);
-    }
 
-    public interface CountBuilder extends Value {
+    public interface CountBuilder extends StatementPart {
+
         public CountBuilder all();
+
         public CountBuilder column(Value value);
+
         public CountBuilder distinct();
     }
-    
-    public interface SelectColumnBuilder extends Visitable {
+
+    public interface SelectColumnBuilder extends StatementPart {
+
         public SelectColumnBuilder name(String name);
+
         public SelectColumnBuilder value(Value value);
+
         public SelectColumnBuilder as(String alias);
+
         public SelectColumnBuilder as_geometry();
+
         public SelectColumnBuilder all();
+
         public String getName();
+
         public String getAlias();
+
         public String getValue();
     }
-    
-    public interface InsertColumnBuilder extends Visitable {
+
+    public interface InsertColumnBuilder extends StatementPart {
+
         public InsertColumnBuilder name(String name);
+
         public InsertColumnBuilder with_value(Value value);
+
         public String getName();
+
         public Value getValue();
     }
-    
+
     public interface UpdateColumnBuilder extends InsertColumnBuilder {
+
         @Override
         public UpdateColumnBuilder name(String name);
+
         @Override
         public UpdateColumnBuilder with_value(Value value);
+
         @Override
         public String getName();
+
         @Override
         public Value getValue();
     }
-        
-    public interface FromBuilder extends Visitable {
+
+    public interface FromBuilder extends StatementPart {
+
         public TableNameBuilder table();
+
         public FromBuilder subquery(String subquery);
+
         public FromBuilder custom(String passthrough);
     }
 
-    public interface OrderByBuilder extends Visitable {
+    public interface OrderByBuilder extends StatementPart {
+
         public OrderByBuilder column(String name);
+
         public OrderByBuilder ascending(boolean asc);
+
         public OrderByBuilder ascending();
+
         public OrderByBuilder descending();
+
         public OrderByBuilder custom(String order);
     }
-    
+
     public interface SelectBuilder extends Statement {
+
         public SelectColumnBuilder column();
+
         public FromBuilder from();
+
         public ExpressionBuilder where();
+
         public OrderByBuilder order_by();
+
         public SelectBuilder distinct();
+
         public SelectBuilder limit(long limit);
+
         public SelectBuilder limit(Long limit);
-        
+
         /**
-         * Specifies an offset to be applied to the SQL statement.
-         * Only an offset can be applied if an order has been specified. 
-         * Otherwise an IllegalStateException exception will be thrown when 
-         * constructing the SQL statement invoking the toString method.
-         * 
+         * Specifies an offset to be applied to the SQL statement. Only an
+         * offset can be applied if an order has been specified. Otherwise an
+         * IllegalStateException exception will be thrown when constructing the
+         * SQL statement invoking the toString method.
+         *
          * @param offset
          * @return this SelectBuilder
          */
         public SelectBuilder offset(long offset);
-        
+
         public boolean has_column(String name);
+
         public boolean has_where();
+
         public boolean has_from();
+
         public boolean has_order_by();
+
         public boolean has_limit();
+
         public boolean has_offset();
 
         /**
-         * Constructs the SQL statement.
-         * If the values associated with the SQL statement are not valid 
-         * an IllegalStateException exception is thrown.
-         * 
+         * Constructs the SQL statement. If the values associated with the SQL
+         * statement are not valid an IllegalStateException exception is thrown.
+         *
          * @return the SQL select statement.
-         * @throws IllegalStateException if the values of select statement are not valids.
+         * @throws IllegalStateException if the values of select statement are
+         * not valids.
          */
         @Override
         public String toString();
-        
+
     }
-    
+
     public interface UpdateBuilder extends Statement {
+
         public TableNameBuilder table();
+
         public UpdateColumnBuilder column();
+
         public ExpressionBuilder where();
+
         public boolean has_where();
     }
-    
+
     public interface InsertBuilder extends Statement {
+
         public TableNameBuilder table();
+
         public InsertColumnBuilder column();
     }
-    
+
     public interface DeleteBuilder extends Statement {
+
         public TableNameBuilder table();
+
         public ExpressionBuilder where();
+
         public boolean has_where();
     }
-    
+
     public interface AlterTableBuilder extends Statement {
+
         public TableNameBuilder table();
+
         public AlterTableBuilder drop_column(String columnName);
+
         public AlterTableBuilder add_column(FeatureAttributeDescriptor fad);
-        public AlterTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue);    
+
+        public AlterTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue);
+
         public AlterTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls);
+
         public AlterTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls);
+
         public AlterTableBuilder alter_column(FeatureAttributeDescriptor fad);
+
         public AlterTableBuilder alter_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue);
+
         public AlterTableBuilder alter_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls);
+
         public AlterTableBuilder alter_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls);
+
         public AlterTableBuilder rename_column(String source, String target);
+
         public boolean isEmpty();
+
         public List<String> toStrings();
+
+        public List<String> toStrings(Formatter formatter);
     }
-    
+
     public interface CreateTableBuilder extends Statement {
+
         public TableNameBuilder table();
+
         public CreateTableBuilder add_column(FeatureAttributeDescriptor fad);
+
         public CreateTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue);
+
         public CreateTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls);
+
         public CreateTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls);
+
         public ColumnDescriptor getColumnDescriptor(String columnName);
+
         public List<String> toStrings();
+
+        public List<String> toStrings(Formatter formatter);
     }
-    
+
     public interface UpdateTableStatisticsBuilder extends Statement {
+
         public TableNameBuilder table();
+
         public List<String> toStrings();
+
+        public List<String> toStrings(Formatter formatter);
     }
-        
-    public interface GrantRoleBuilder {
+
+    public interface GrantRoleBuilder extends StatementPart {
+
         public GrantRoleBuilder privilege(Privilege privilege);
+
         public GrantRoleBuilder select();
+
         public GrantRoleBuilder insert();
+
         public GrantRoleBuilder delete();
+
         public GrantRoleBuilder truncate();
+
         public GrantRoleBuilder reference();
+
         public GrantRoleBuilder update();
+
         public GrantRoleBuilder trigger();
+
         public GrantRoleBuilder all();
     }
-    
+
     public interface GrantBuilder extends Statement {
+
         public TableNameBuilder table();
-        public GrantRoleBuilder role(String name);        
+
+        public GrantRoleBuilder role(String name);
+
         public List<String> toStrings();
+
+        public List<String> toStrings(Formatter formatter);
     }
-        
+
     public interface DropTableBuilder extends Statement {
+
         public TableNameBuilder table();
+
         public List<String> toStrings();
+
+        public List<String> toStrings(Formatter formatter);
     }
-    
+
     public interface CreateIndexBuilder extends Statement {
+
         public CreateIndexBuilder if_not_exist();
+
         public CreateIndexBuilder unique();
+
         public CreateIndexBuilder name(String name);
+
         public CreateIndexBuilder spatial();
+
         public CreateIndexBuilder column(String name);
+
         public TableNameBuilder table();
+
         public List<String> toStrings();
+
+        public List<String> toStrings(Formatter formatter);
     }
 
-    @Override
-    public Column column(String name); 
+    public String default_schema();
 
-    public Column column(FeatureAttributeDescriptor fad); 
+    public boolean support_schemas();
 
-    @Override
-    public List<Variable> getVariables();
-    
-    public String default_schema();
-    
-    public boolean supportSchemas();
+    public boolean has_spatial_functions();
 
-    @Deprecated
-    public String sqltype(int dataType, int p, int s);
-    
+    public GeometrySupportType geometry_support_type();
+
     public String sqltype(int dataType, int p, int s, int geomType, int geomSubtype);
-    
+
     public Object sqlgeometrytype(int type, int subtype);
 
     public Object sqlgeometrydimension(int type, int subtype);
-    
+
+    public Object srs_id(IProjection projection);
+
+    public String toString(Formatter formatter);
+
+    public List<Variable> variables();
+
+    public List<String> variables_names();
+
+    public List<Parameter> parameters();
+
+    public List<String> parameters_names();
+
     public SelectBuilder select();
-    
+
     public UpdateBuilder update();
 
     public InsertBuilder insert();
-    
+
     public DeleteBuilder delete();
-    
+
     public AlterTableBuilder alter_table();
 
     public CreateTableBuilder create_table();
-    
+
     public CreateIndexBuilder create_index();
 
     public GrantBuilder grant();
@@ -361,12 +458,21 @@
     public UpdateTableStatisticsBuilder update_table_statistics();
 
     public CountBuilder count();
-    
-    public Function ST_ExtentAggregate(Value geom);
 
-    public Function ST_UnionAggregate(Value geom);
+    public ExpressionBuilder expression();
 
-    public Function Find_SRID(Value schema, Value table, Value column);
-    
-    
+    public String as_identifier(String id);
+
+    public String as_string(String s);
+
+    public String as_string(byte[] s);
+
+    public String as_string(boolean value);
+
+    public String as_string(Number value);
+
+    public String as_string(Object value);
+
+    public void setProperties(Class classToApply, Object... values);
+
 }
