Index: 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/test/java/org/gvsig/fmap/dal/store/jdbc2/ExpressionBuilderTest.java
===================================================================
--- 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/test/java/org/gvsig/fmap/dal/store/jdbc2/ExpressionBuilderTest.java	(revision 0)
+++ 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/test/java/org/gvsig/fmap/dal/store/jdbc2/ExpressionBuilderTest.java	(revision 43114)
@@ -0,0 +1,209 @@
+package org.gvsig.fmap.dal.store.jdbc2;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.lang3.ArrayUtils;
+import org.cresques.cts.IProjection;
+import org.gvsig.fmap.crs.CRSFactory;
+import org.gvsig.fmap.dal.ExpressionBuilder;
+import org.gvsig.fmap.dal.ExpressionBuilder.Config;
+import org.gvsig.fmap.dal.ExpressionBuilder.GeometrySupportType;
+import org.gvsig.fmap.dal.ExpressionBuilder.Parameter;
+import static org.gvsig.fmap.dal.ExpressionBuilder.ParameterType.Constant;
+import org.gvsig.fmap.dal.ExpressionBuilder.Variable;
+import org.gvsig.fmap.dal.feature.spi.ExpressionBuilderBase;
+import org.gvsig.fmap.geom.Geometry;
+import org.gvsig.fmap.geom.GeometryLocator;
+import org.gvsig.fmap.geom.GeometryManager;
+import org.gvsig.fmap.geom.exception.CreateGeometryException;
+import org.gvsig.fmap.geom.primitive.Point;
+import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
+
+public class ExpressionBuilderTest extends AbstractLibraryAutoInitTestCase {
+    
+    @Override
+    protected void doSetUp() throws Exception {
+
+    }
+    
+    List<String> getVariableNames(ExpressionBuilder builder) {
+        List<String> vars = new ArrayList<>();
+        for (Variable var : builder.getVariables()) {
+            vars.add(var.getName());
+        }
+        return vars;
+    }
+    
+    List<String> getParameterNames(ExpressionBuilder builder) {
+        List<String> params = new ArrayList<>();
+        for (Parameter param : builder.getParameters()) {
+            String s;
+            switch(param.getType()) {
+                case Constant:
+                    Object value = param.getValue();
+                    if( value==null ) {
+                        s = "null";
+                    } else if( value instanceof String ) {
+                        s = "'" + (String)value + "'";
+                    } else {
+                        s = value.toString();
+                    }    
+                    break;
+                case Geometry:
+                case Variable:
+                default:
+                    s = "\"" + param.getName() + "\"";
+            }
+            params.add(s);
+        }
+        return params;
+    }
+    
+    public void test2() {
+        ExpressionBuilder builder = new ExpressionBuilderBase();
+        
+        builder.and(
+          builder.eq(
+            builder.lcase(builder.variable("colum_name_c")),
+            builder.parameter("colum_name_p")
+          )
+        );
+        builder.and(
+            builder.group(
+                builder.or(
+                    builder.like(
+                        builder.lcase( builder.variable("uno")),
+                        builder.constant("%10")
+                    ),
+                    builder.lt(
+                        builder.variable("dos"),
+                        builder.constant(-3.5)
+                    )
+                )
+            )
+        );
+        builder.and(
+                builder.ST_Intersects(
+                    builder.variable("geom1"), 
+                    builder.ST_Envelope(
+                        builder.ST_GeomFromWKB(
+                                builder.parameter("geom2"), 
+                                builder.parameter().value(4326).as_constant()
+                        )
+                    )
+                )
+        );
+        builder.and(
+            builder.gt(
+                builder.variable("tres"),
+                builder.constant(123456789)
+            )
+        );
+        assertEquals(
+                "( (LCASE(\"colum_name_c\")) = (?) ) AND ( ( (LCASE(\"uno\")) LIKE ('%10') ) OR ( (\"dos\") < (-3.5) ) ) AND ST_Intersects((\"geom1\"), (ST_Envelope(ST_GeomFromWKB((?), (?))))) AND ( (\"tres\") > (123456789) )",
+                builder.toString()
+        );
+        assertEquals(
+                "[colum_name_c, dos, geom1, tres, uno]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "[\"colum_name_p\", \"geom2\", 4326]",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+    
+    public void test3() throws CreateGeometryException {
+        ExpressionBuilder builder = new ExpressionBuilderBase();
+                
+        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+        
+        Point point = geometryManager.createPoint(10, 20, Geometry.SUBTYPES.GEOM2D);
+        builder.set(        
+            builder.ST_Intersects(
+              builder.geometry(point,proj),
+              builder.variable("the_geom")
+            )
+        );
+        builder.getConfig().set(Config.geometry_type_support, GeometrySupportType.WKT);
+        System.out.println(builder.toString());
+        assertEquals(
+                "ST_Intersects((ST_GeomFromText('POINT (10 20)', (4326))), (\"the_geom\"))",
+                builder.toString()
+        );
+        builder.getConfig().set(Config.geometry_type_support, GeometrySupportType.WKB);
+        System.out.println(builder.toString());
+        assertEquals(
+                "ST_Intersects((ST_GeomFromWKB((0x000000000140240000000000004034000000000000), (4326))), (\"the_geom\"))",
+                builder.toString()
+        );
+        assertEquals(
+                "[the_geom]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+    
+    public void test4() throws CreateGeometryException {
+        ExpressionBuilder builder = new ExpressionBuilderBase();
+                
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+        
+        builder.and(
+                builder.ST_Intersects(
+                    builder.variable("geom1"), 
+                    builder.ST_Envelope(
+                        builder.ST_GeomFromWKB(
+                                builder.parameter("geom2"), 
+                                builder.parameter().value(proj).as_constant()
+                        )
+                    )
+                )
+        );
+        
+        System.out.println(builder.toString());
+        assertEquals(
+                "ST_Intersects((\"geom1\"), (ST_Envelope(ST_GeomFromWKB((?), (?)))))",
+                builder.toString()
+        );
+        assertEquals(
+                "[geom1]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "[\"geom2\", 4326]",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+        
+    public void test5() throws CreateGeometryException {
+        ExpressionBuilder builder = new ExpressionBuilderBase();
+                
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+        
+        builder.and(
+                builder.eq(
+                        builder.ST_SRID( builder.variable("geom") ),
+                        builder.srs(proj)
+                )
+        );
+        
+        System.out.println(builder.toString());
+        assertEquals(
+                "( (ST_SRID(\"geom\")) = (4326) )",
+                builder.toString()
+        );
+        assertEquals(
+                "[geom]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+}
Index: 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/test/java/org/gvsig/fmap/dal/store/jdbc2/SQLBuilderTest.java
===================================================================
--- 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/test/java/org/gvsig/fmap/dal/store/jdbc2/SQLBuilderTest.java	(revision 0)
+++ 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/test/java/org/gvsig/fmap/dal/store/jdbc2/SQLBuilderTest.java	(revision 43114)
@@ -0,0 +1,486 @@
+package org.gvsig.fmap.dal.store.jdbc2;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.lang3.ArrayUtils;
+import org.cresques.cts.IProjection;
+import org.gvsig.fmap.crs.CRSFactory;
+import org.gvsig.fmap.dal.ExpressionBuilder;
+import org.gvsig.fmap.dal.ExpressionBuilder.Constant;
+import org.gvsig.fmap.dal.ExpressionBuilder.Parameter;
+import org.gvsig.fmap.dal.ExpressionBuilder.Variable;
+import org.gvsig.fmap.dal.SQLBuilder;
+import org.gvsig.fmap.dal.SQLBuilder.Privilege;
+import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase;
+import org.gvsig.fmap.geom.DataTypes;
+import org.gvsig.fmap.geom.Geometry;
+import org.gvsig.fmap.geom.GeometryLocator;
+import org.gvsig.fmap.geom.GeometryManager;
+import org.gvsig.fmap.geom.primitive.Polygon;
+import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
+
+public class SQLBuilderTest extends AbstractLibraryAutoInitTestCase {
+    
+    @Override
+    protected void doSetUp() throws Exception {
+
+    }
+    
+    List<String> getVariableNames(ExpressionBuilder builder) {
+        List<String> vars = new ArrayList<>();
+        for (Variable var : builder.getVariables()) {
+            vars.add(var.getName());
+        }
+        return vars;
+    }
+    
+    List<String> getParameterNames(ExpressionBuilder builder) {
+        List<String> params = new ArrayList<>();
+        for (Parameter param : builder.getParameters()) {
+            String s;
+            switch(param.getType()) {
+                case Constant:
+                    Object value = param.getValue();
+                    if( value==null ) {
+                        s = "null";
+                    } else if( value instanceof String ) {
+                        s = "'" + (String)value + "'";
+                    } else {
+                        s = value.toString();
+                    }    
+                    break;
+                case Geometry:
+                case Variable:
+                default:
+                    s = "\"" + param.getName() + "\"";
+            }
+            params.add(s);
+        }
+        return params;
+    }
+    
+ 
+    public void testCalulateEnvelope() throws Exception {
+        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+        
+        Polygon limit = geometryManager.createPolygon(Geometry.SUBTYPES.GEOM2D);
+        limit.addVertex(0, 0);
+        limit.addVertex(0, 100);
+        limit.addVertex(100, 100);
+        limit.addVertex(100, 0);
+        limit.addVertex(0, 0);
+        
+        SQLBuilder builder = new SQLBuilderBase();
+        
+        builder.select().column().value(
+            builder.getAsGeometry(
+              builder.ST_ExtentAggregate(
+                builder.column("the_geom")
+              )
+            )
+        ).as("envelope");
+        builder.select().from().table().database("master").schema("dbo").name("test1");
+        builder.select().where().set(
+            builder.ST_Intersects(
+                builder.ST_Envelope(
+                    builder.column("the_geom")
+                ),
+                builder.geometry(limit, proj)
+            )
+        );
+        builder.select().where().and(
+                builder.custom("x = 27")
+        );
+        
+        // SELECT ST_AsBinary(ST_Extent("the_geom")) AS "envelope" FROM "master"."dbo"."test1" WHERE ST_Intersects((ST_Envelope("the_geom")), (ST_GeomFromText('POLYGON ((0 0, 0 100, 100 100, 100 0, 0 0))', (4326)))) AND x = 27
+        
+        System.out.println("# Test:: testCalulateEnvelope");
+        System.out.println("# SQL:: " + builder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+        assertEquals(
+                "SELECT ST_AsBinary(ST_Extent(\"the_geom\")) AS \"envelope\" FROM \"master\".\"dbo\".\"test1\" WHERE ST_Intersects((ST_Envelope(\"the_geom\")), (ST_GeomFromText('POLYGON ((0 0, 0 100, 100 100, 100 0, 0 0))', (4326)))) AND x = 27",
+                builder.toString()
+        );
+        assertEquals(
+                "[the_geom]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+
+    public void testCount() throws Exception {
+        SQLBuilder builder = new SQLBuilderBase();
+        
+        builder.select().column().value(builder.count().all());
+        builder.select().from().table().database("master").schema("dbo").name("test1");
+        builder.select().from().subquery(null);
+        builder.select().where().set( builder.custom("pp = 200"));
+
+        System.out.println("# Test:: testCount");
+        System.out.println("# SQL:: " + builder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+
+        //# Test:: testCount
+        //# SQL:: SELECT COUNT(*) FROM "master"."dbo"."test1" WHERE pp = 200
+        //# Variables:: []
+        //# Parametros:: []
+
+        assertEquals(
+                "SELECT COUNT(*) FROM \"master\".\"dbo\".\"test1\" WHERE pp = 200",
+                builder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+    
+    public void testCreateTable() throws Exception {
+        SQLBuilder builder = new SQLBuilderBase();
+
+        builder.create_table().table().database("master").schema("dbo").name("test1");
+        builder.create_table().add_column(
+                "name",
+                DataTypes.STRING,
+                45,
+                0,
+                false,
+                true,
+                false,
+                null
+        );
+        builder.create_table().add_column(
+                "id",
+                DataTypes.INT,
+                0,
+                0,
+                true,
+                false,
+                true,
+                0
+        );
+        builder.create_table().add_column(
+                "geom",
+                DataTypes.GEOMETRY,
+                0,
+                0,
+                false,
+                true,
+                false,
+                null
+        );
+
+        
+        // CREATE TABLE "master"."dbo"."test1" ("name" VARCHAR(45) DEFAULT NULL NULL, "id" SERIAL DEFAULT '0' NOT NULL PRIMARY KEY, "geom" TEXT DEFAULT NULL NULL )
+        System.out.println("# Test:: testCreateTable");
+        System.out.println("# SQL:: " + builder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+        assertEquals(
+                "CREATE TABLE \"master\".\"dbo\".\"test1\" (\"name\" VARCHAR(45) DEFAULT NULL NULL, \"id\" SERIAL DEFAULT '0' NOT NULL PRIMARY KEY, \"geom\" TEXT DEFAULT NULL NULL )",
+                builder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+
+    public void testDropTable() throws Exception {
+        SQLBuilder builder = new SQLBuilderBase();
+        
+        builder.drop_table().table().database("master").schema("dbo").name("test1");
+
+        // DROP TABLE "master"."dbo"."test1"; DELETE FROM GEOMETRY_COLUMNS WHERE f_table_schema = 'dbo' AND f_table_name = 'test1'
+        
+        System.out.println("# Test:: testDropTable");
+        System.out.println("# SQL:: " + builder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+        assertEquals(
+                "DROP TABLE \"master\".\"dbo\".\"test1\"; DELETE FROM GEOMETRY_COLUMNS WHERE f_table_schema = 'dbo' AND f_table_name = 'test1'",
+                builder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+    
+    public void testFetchFeatureProviderByReference() throws Exception {
+        SQLBuilder builder = new SQLBuilderBase();
+        
+        String value = "yoyo";
+        builder.select().column().name("name");
+        builder.select().column().name("id");
+        builder.select().column().name("geom").as_geometry();
+        builder.select().from().table().database("master").schema("dbo").name("test1");
+        builder.select().where().set(
+            builder.eq(
+                builder.column("name"),
+                builder.parameter(value).as_constant()
+            )
+        );
+        builder.select().limit(1);
+
+        // SELECT "name", "id", ST_AsBinary("geom") FROM "master"."dbo"."test1" WHERE ( ("name") = (?) ) LIMIT 1
+
+        System.out.println("# Test:: testFetchFeatureProviderByReference");
+        System.out.println("# SQL:: " + builder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+        assertEquals(
+                "SELECT \"name\", \"id\", ST_AsBinary(\"geom\") FROM \"master\".\"dbo\".\"test1\" WHERE ( (\"name\") = (?) ) LIMIT 1",
+                builder.toString()
+        );
+        assertEquals(
+                "[geom, id, name]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "['yoyo']",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+    
+    public void testFetchFeatureType() throws Exception {
+        SQLBuilder builder = new SQLBuilderBase();
+
+        builder.select().column().all();
+        builder.select().from().table().database("master").schema("dbo").name("test1");
+        builder.select().limit(1);
+
+        System.out.println("# Test:: testFetchFeatureType");
+        System.out.println("# SQL:: " + builder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+        
+        //# Test:: testFetchFeatureType
+        //# SQL:: SELECT * FROM [master].[dbo].[test1] LIMMIT 1
+        //# Variables:: []
+        //# Parametros:: []        
+        
+        assertEquals(
+                "SELECT * FROM \"master\".\"dbo\".\"test1\" LIMIT 1",
+                builder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+        
+    public void testPerformDeletes() throws Exception {
+        SQLBuilder builder = new SQLBuilderBase();
+
+        builder.delete().table().database("master").schema("dbo").name("test1");
+        builder.delete().where().and(
+            builder.eq( 
+                builder.column("id1"),
+                builder.parameter("id1").as_variable()
+            )
+        );
+        builder.delete().where().and(
+            builder.eq( 
+                builder.column("id2"),
+                builder.parameter("id2").as_variable()
+            )
+        );
+
+        // DELETE FROM "master"."dbo"."test1" WHERE ( ("id1") = (?) ) AND ( ("id2") = (?) )
+
+        System.out.println("# Test:: testPerformDeletes");
+        System.out.println("# SQL:: " + builder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+        assertEquals(
+                "DELETE FROM \"master\".\"dbo\".\"test1\" WHERE ( (\"id1\") = (?) ) AND ( (\"id2\") = (?) )",
+                builder.toString()
+        );
+        assertEquals(
+                "[id1, id2]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "[\"id1\", \"id2\"]",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+
+    public void testPerformInserts1() throws Exception {
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+
+        SQLBuilder builder = new SQLBuilderBase();
+
+        builder.insert().table().database("master").schema("dbo").name("test1");
+        builder.insert().column().name("id").with_value(builder.parameter("id"));
+        builder.insert().column().name("name").with_value(builder.parameter("name"));
+        builder.insert().column().name("geom").with_value(builder.parameter("geom").as_geometry_variable().srs(proj));
+        
+        // INSERT INTO "master"."dbo"."test1" ( "id", "name", "geom" ) VALUES ( ?, ?, ST_GeomFromText(?, (4326)) )
+        
+        System.out.println("# Test:: testPerformInserts1");
+        System.out.println("# SQL:: " + builder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+        assertEquals(
+                "INSERT INTO \"master\".\"dbo\".\"test1\" ( \"id\", \"name\", \"geom\" ) VALUES ( ?, ?, ST_GeomFromText(?, (4326)) )",
+                builder.toString()
+        );
+        assertEquals(
+                "[geom, id, name]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "[\"id\", \"name\", \"geom\"]",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+
+    public void testPerformInserts2() throws Exception {
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+
+        SQLBuilder builder = new SQLBuilderBase();
+
+        builder.insert().table().database("master").schema("dbo").name("test1");
+        builder.insert().column().name("id").with_value(builder.parameter("id"));
+        builder.insert().column().name("name").with_value(builder.parameter("name"));
+        builder.insert().column().name("geom").with_value(builder.parameter("geom").as_geometry_variable().srs(proj));
+        
+        // INSERT INTO "master"."dbo"."test1" ( "id", "name", "geom" ) VALUES ( ?, ?, ST_GeomFromText(?, (?)) )
+        
+        System.out.println("# Test:: testPerformInserts2");
+        System.out.println("# SQL:: " + builder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+        assertEquals(
+                "INSERT INTO \"master\".\"dbo\".\"test1\" ( \"id\", \"name\", \"geom\" ) VALUES ( ?, ?, ST_GeomFromText(?, (?)) )",
+                builder.toString()
+        );
+        assertEquals(
+                "[geom, id, name]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "[\"id\", \"name\", \"geom\", 4326]",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+
+    public void testPerformUpdates() throws Exception {
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+
+        SQLBuilder builder = new SQLBuilderBase();
+
+        builder.update().table().database("master").schema("dbo").name("test1");
+        builder.update().where().and(
+            builder.eq(
+                builder.column("id"), 
+                builder.parameter("id").as_variable()
+            )
+        );
+        builder.update().column().name("name").with_value(builder.parameter("name"));
+        builder.update().column().name("geom").with_value(
+                builder.parameter("geom").as_geometry_variable().srs(proj) 
+        );
+
+        // UPDATE "master"."dbo"."test1" SET "name" = ?, "geom" = ST_GeomFromText(?, (?)) WHERE ( ("id") = (?) )
+
+        System.out.println("# Test:: testPerformUpdates");
+        System.out.println("# SQL:: " + builder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+        assertEquals(
+                "UPDATE \"master\".\"dbo\".\"test1\" SET \"name\" = ?, \"geom\" = ST_GeomFromText(?, (?)) WHERE ( (\"id\") = (?) )",
+                builder.toString()
+        );
+        assertEquals(
+                "[geom, id, name]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "[\"name\", \"geom\", 4326, \"id\"]",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+
+    public void testGrant1() throws Exception {
+
+        SQLBuilder builder = new SQLBuilderBase();
+
+        builder.grant().table().database("master").schema("dbo").name("test1");
+        builder.grant().role("prueba").select().insert().update();
+        builder.grant().role("gis").all();
+                
+        
+        System.out.println("# Test:: testGrant1");
+        System.out.println("# SQL:: " + builder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+        assertEquals(
+                "",
+                builder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+
+    public void testGrant2() throws Exception {
+
+        SQLBuilder builder = new SQLBuilderBase();
+
+        builder.grant().table().database("master").schema("dbo").name("test1");
+        builder.grant().role("prueba").privilege(Privilege.SELECT)
+                .privilege(Privilege.INSERT)
+                .privilege(Privilege.UPDATE);
+        builder.grant().role("gis").privilege(Privilege.ALL);
+                
+        
+        System.out.println("# Test:: testGrant2");
+        System.out.println("# SQL:: " + builder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+        assertEquals(
+                "",
+                builder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(getVariableNames(builder))
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(getParameterNames(builder))
+        );
+    }
+
+
+}
Index: 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/AbstractConnectionOperation.java
===================================================================
--- 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/AbstractConnectionOperation.java	(revision 43113)
+++ 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/AbstractConnectionOperation.java	(revision 43114)
@@ -17,6 +17,8 @@
     final static protected Logger logger = LoggerFactory.getLogger(AbstractConnectionOperation.class);
 
     final protected JDBCHelper helper;
+    
+    private Connection conn = null;
 
     public AbstractConnectionOperation(JDBCHelper helper) {
         this.helper = helper;
@@ -47,9 +49,12 @@
         }
     }
 
+    protected Connection getConnection() {
+        return this.conn;
+    }
+    
     public Object perform_operation() throws Exception {
             Object result = null;
-        Connection conn = null;
         try {
             logger.debug("preparing execution of "+this.getClass().getSimpleName()+".");
             conn = helper.getConnection();
@@ -76,6 +81,7 @@
             return result;
         } finally {
             helper.closeConnection(conn);
+            conn = null;
         }
     }
 //
Index: 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/FetchFeatureTypeOperation.java
===================================================================
--- 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/FetchFeatureTypeOperation.java	(revision 43113)
+++ 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/FetchFeatureTypeOperation.java	(revision 43114)
@@ -65,6 +65,18 @@
         return true;
     }
     
+    protected String getDatabase() {
+        return this.dbname;
+    }
+    
+    protected String getSchema() {
+        return this.schema;
+    }
+    
+    protected String getTablename() {
+        return this.table;
+    }
+    
     public void fetch(
             EditableFeatureType featureType,
             Connection conn,
@@ -106,7 +118,7 @@
             boolean firstGeometryAttrFound = false;
             for (i = 1; i <= rsMetadata.getColumnCount(); i++) {
                 attr = getAttributeFromMetadata(featureType, conn, rsMetadata, i);
-                if (pks != null && pks.contains(attr.getName())) {
+                if ( isInPrimaryKeys(pks,attr) ) {
                     attr.setIsPrimaryKey(true);
                 }
                 if (attr.getType() == DataTypes.GEOMETRY) {
@@ -122,10 +134,6 @@
 
             }
 
-            if (geometriesColumns > 0) {
-                fetch_CRS_and_shapeType(conn, rsMetadata, featureType, schema, table);
-            }
-
             if (defaultGeometryColumn == null && geometriesColumns == 1) {
                 featureType.setDefaultGeometryAttributeName(lastGeometry);
             }
@@ -142,6 +150,10 @@
         }
     }
 
+    protected boolean isInPrimaryKeys(List<String> pks, EditableFeatureAttributeDescriptor attr) {
+        return pks != null && pks.contains(attr.getName());
+    }
+    
     protected List<String> getPrimaryKeysFromMetadata(
             Connection conn,
             String catalog,
@@ -286,28 +298,12 @@
                 );
                 break;
             case DataTypes.GEOMETRY:
-                this.fetchGeometryType(attr, rsMetadata, colIndex);
+                this.fetchGeometryTypeAndSRS(attr, rsMetadata, colIndex);
                 break;
         }
         return attr;
     }
 
-    protected void fetchGeometryType(
-            EditableFeatureAttributeDescriptor attr,
-            ResultSetMetaData rsMetadata,
-            int colIndex
-        ) {
-        try {
-            GeometryType geomType = GeometryLocator.getGeometryManager().getGeometryType(
-                    Geometry.TYPES.GEOMETRY,
-                    Geometry.SUBTYPES.GEOM2D
-            );
-            attr.setGeometryType(geomType);
-        } catch (Exception ex) {
-            logger.warn("Can't get default geometry type.",ex);
-        }
-    }
-    
     protected int getDataTypeFromMetadata(
             ResultSetMetaData rsMetadata,
             int colIndex
@@ -369,15 +365,31 @@
         }
     }
 
-    protected void fetch_CRS_and_shapeType(
-            Connection conn,
+    /**
+     * Inicializa el tipo, subtipo y SRS del attributo de tipo geometria.
+     * 
+     * @param attr
+     * @param rsMetadata
+     * @param colIndex 
+     */
+    protected void fetchGeometryTypeAndSRS(
+            EditableFeatureAttributeDescriptor attr,
             ResultSetMetaData rsMetadata,
-            EditableFeatureType featureType,
-            String schema,
-            String table
-        ) throws SQLException {
-
-        // Nothing to do
+            int colIndex
+        ) {
+        if( attr.getType()!=DataTypes.GEOMETRY ) {
+            return;
+        }
+        try {
+            GeometryType geomType = GeometryLocator.getGeometryManager().getGeometryType(
+                    Geometry.TYPES.GEOMETRY,
+                    Geometry.SUBTYPES.GEOM2D
+            );
+            attr.setGeometryType(geomType);
+            attr.setSRS(null);
+        } catch (Exception ex) {
+            logger.warn("Can't get default geometry type.",ex);
+        }
     }
-
+    
 }
Index: 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/CreateTableOperation.java
===================================================================
--- 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/CreateTableOperation.java	(revision 43113)
+++ 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/CreateTableOperation.java	(revision 43114)
@@ -13,6 +13,7 @@
 import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
 import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException;
 import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
+import org.gvsig.fmap.geom.DataTypes;
 
 public class CreateTableOperation extends AbstractConnectionOperation {
 
@@ -65,16 +66,26 @@
         JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
         sqlbuilder.create_table().table().database(dbName).schema(schemaName).name(tableName);
         for (FeatureAttributeDescriptor attr : type) {
-            sqlbuilder.create_table().add_column(
-                    attr.getName(),
-                    attr.getType(),
-                    attr.getSize(),
-                    attr.getPrecision(),
-                    attr.isPrimaryKey(),
-                    attr.allowNull(),
-                    attr.isAutomatic(),
-                    attr.getDefaultValue()
-            );
+            if( attr.getType()==DataTypes.GEOMETRY ) {
+                sqlbuilder.create_table().add_geometry_column(
+                        attr.getName(),
+                        attr.getGeomType().getType(),
+                        attr.getGeomType().getSubType(),
+                        attr.getSRS(),
+                        attr.allowNull()
+                );
+            } else {
+                sqlbuilder.create_table().add_column(
+                        attr.getName(),
+                        attr.getType(),
+                        attr.getSize(),
+                        attr.getPrecision(),
+                        attr.isPrimaryKey(),
+                        attr.allowNull(),
+                        attr.isAutomatic(),
+                        attr.getDefaultValue()
+                );
+            }
         }
         for (Pair<String, SQLBuilder.Privilege> roleAndPrivilege : rolesAndPrivileges) {
             sqlbuilder.grant().role(roleAndPrivilege.getLeft()).privilege(roleAndPrivilege.getRight());
Index: 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/JDBCHelperBase.java
===================================================================
--- 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/JDBCHelperBase.java	(revision 43113)
+++ 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/JDBCHelperBase.java	(revision 43114)
@@ -6,6 +6,7 @@
 import java.sql.ResultSet;
 import org.apache.commons.lang3.StringUtils;
 import org.cresques.cts.IProjection;
+import org.gvsig.fmap.crs.CRSFactory;
 import org.gvsig.fmap.dal.DataTypes;
 import org.gvsig.fmap.dal.exception.DataException;
 import org.gvsig.fmap.dal.exception.InitializeException;
@@ -334,6 +335,16 @@
         int id = Integer.parseInt(ss[1]);
         return id;
     }
+
+    @Override
+    public IProjection getProjectionFromSRSId(int srsid) {
+        // Dumb implementation
+        if( srsid < 2000 ) {
+            return null;
+        }
+        IProjection proj = CRSFactory.getCRS("EPSG:"+srsid);
+        return proj;
+    }
     
     @Override
     public JDBCStoreProvider createProvider(
Index: 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/JDBCHelper.java
===================================================================
--- 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/JDBCHelper.java	(revision 43113)
+++ 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/JDBCHelper.java	(revision 43114)
@@ -159,6 +159,8 @@
     ) throws InitializeException;
 
     public int getSRSCode(IProjection crs);
+    
+    public IProjection getProjectionFromSRSId(int srsid);
 
     public JDBCNewStoreParameters createNewStoreParameters();
 
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/pom.xml
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/pom.xml	(revision 43113)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/pom.xml	(revision 43114)
@@ -50,8 +50,13 @@
         <type>test-jar</type>
         <scope>test</scope>
     </dependency>
-    
     <dependency>
+        <groupId>org.gvsig</groupId>
+        <artifactId>org.gvsig.tools.lib</artifactId>
+        <type>test-jar</type>
+        <scope>test</scope>
+    </dependency>    
+    <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
         <scope>test</scope>
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/jdbc/DefaultJDBCConnectionPanelView.xml
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/jdbc/DefaultJDBCConnectionPanelView.xml	(revision 43113)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/jdbc/DefaultJDBCConnectionPanelView.xml	(revision 43114)
@@ -24,7 +24,7 @@
     </at>
     <at name="componentclass">com.jeta.forms.gui.form.FormComponent</at>
    </super>
-   <at name="id">/home/jjdelcerro/datos/devel/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/jdbc/DefaultJDBCConnectionPanelView.java.xml</at>
+   <at name="id">/home/jjdelcerro/data/devel/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/jdbc/DefaultJDBCConnectionPanelView.xml</at>
    <at name="rowspecs">CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE</at>
    <at name="colspecs">FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE</at>
    <at name="components">
@@ -53,15 +53,6 @@
           <at name="classname">com.jeta.forms.components.label.JETALabel</at>
           <at name="properties">
            <object classname="com.jeta.forms.store.support.PropertyMap">
-            <at name="text">Nombre de la conexion</at>
-            <at name="height">14</at>
-            <at name="width">131</at>
-            <at name="name">lblConnectionName</at>
-            <at name="fill">
-             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
-              <at name="name">fill</at>
-             </object>
-            </at>
             <at name="border">
              <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
               <super classname="com.jeta.forms.store.properties.BorderProperty">
@@ -82,6 +73,15 @@
               </at>
              </object>
             </at>
+            <at name="name">lblConnectionName</at>
+            <at name="width">131</at>
+            <at name="text">Nombre de la conexion</at>
+            <at name="fill">
+             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
+              <at name="name">fill</at>
+             </object>
+            </at>
+            <at name="height">14</at>
            </object>
           </at>
          </object>
@@ -113,15 +113,6 @@
           <at name="classname">com.jeta.forms.components.label.JETALabel</at>
           <at name="properties">
            <object classname="com.jeta.forms.store.support.PropertyMap">
-            <at name="text">Conector</at>
-            <at name="height">14</at>
-            <at name="width">131</at>
-            <at name="name">lblConnector</at>
-            <at name="fill">
-             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
-              <at name="name">fill</at>
-             </object>
-            </at>
             <at name="border">
              <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
               <super classname="com.jeta.forms.store.properties.BorderProperty">
@@ -142,6 +133,15 @@
               </at>
              </object>
             </at>
+            <at name="name">lblConnector</at>
+            <at name="width">131</at>
+            <at name="text">Conector</at>
+            <at name="fill">
+             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
+              <at name="name">fill</at>
+             </object>
+            </at>
+            <at name="height">14</at>
            </object>
           </at>
          </object>
@@ -173,15 +173,6 @@
           <at name="classname">com.jeta.forms.components.label.JETALabel</at>
           <at name="properties">
            <object classname="com.jeta.forms.store.support.PropertyMap">
-            <at name="text">Servidor</at>
-            <at name="height">14</at>
-            <at name="width">131</at>
-            <at name="name">lblServer</at>
-            <at name="fill">
-             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
-              <at name="name">fill</at>
-             </object>
-            </at>
             <at name="border">
              <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
               <super classname="com.jeta.forms.store.properties.BorderProperty">
@@ -202,6 +193,15 @@
               </at>
              </object>
             </at>
+            <at name="name">lblServer</at>
+            <at name="width">131</at>
+            <at name="text">Servidor</at>
+            <at name="fill">
+             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
+              <at name="name">fill</at>
+             </object>
+            </at>
+            <at name="height">14</at>
            </object>
           </at>
          </object>
@@ -233,15 +233,6 @@
           <at name="classname">com.jeta.forms.components.label.JETALabel</at>
           <at name="properties">
            <object classname="com.jeta.forms.store.support.PropertyMap">
-            <at name="text">Puerto</at>
-            <at name="height">14</at>
-            <at name="width">131</at>
-            <at name="name">lblPort</at>
-            <at name="fill">
-             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
-              <at name="name">fill</at>
-             </object>
-            </at>
             <at name="border">
              <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
               <super classname="com.jeta.forms.store.properties.BorderProperty">
@@ -262,6 +253,15 @@
               </at>
              </object>
             </at>
+            <at name="name">lblPort</at>
+            <at name="width">131</at>
+            <at name="text">Puerto</at>
+            <at name="fill">
+             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
+              <at name="name">fill</at>
+             </object>
+            </at>
+            <at name="height">14</at>
            </object>
           </at>
          </object>
@@ -293,15 +293,6 @@
           <at name="classname">com.jeta.forms.components.label.JETALabel</at>
           <at name="properties">
            <object classname="com.jeta.forms.store.support.PropertyMap">
-            <at name="text">Base de datos</at>
-            <at name="height">14</at>
-            <at name="width">131</at>
-            <at name="name">lblDataBase</at>
-            <at name="fill">
-             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
-              <at name="name">fill</at>
-             </object>
-            </at>
             <at name="border">
              <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
               <super classname="com.jeta.forms.store.properties.BorderProperty">
@@ -322,6 +313,15 @@
               </at>
              </object>
             </at>
+            <at name="name">lblDataBase</at>
+            <at name="width">131</at>
+            <at name="text">Base de datos</at>
+            <at name="fill">
+             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
+              <at name="name">fill</at>
+             </object>
+            </at>
+            <at name="height">14</at>
            </object>
           </at>
          </object>
@@ -353,15 +353,6 @@
           <at name="classname">com.jeta.forms.components.label.JETALabel</at>
           <at name="properties">
            <object classname="com.jeta.forms.store.support.PropertyMap">
-            <at name="text">Usuario</at>
-            <at name="height">14</at>
-            <at name="width">131</at>
-            <at name="name">lblUsername</at>
-            <at name="fill">
-             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
-              <at name="name">fill</at>
-             </object>
-            </at>
             <at name="border">
              <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
               <super classname="com.jeta.forms.store.properties.BorderProperty">
@@ -382,6 +373,15 @@
               </at>
              </object>
             </at>
+            <at name="name">lblUsername</at>
+            <at name="width">131</at>
+            <at name="text">Usuario</at>
+            <at name="fill">
+             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
+              <at name="name">fill</at>
+             </object>
+            </at>
+            <at name="height">14</at>
            </object>
           </at>
          </object>
@@ -413,15 +413,6 @@
           <at name="classname">com.jeta.forms.components.label.JETALabel</at>
           <at name="properties">
            <object classname="com.jeta.forms.store.support.PropertyMap">
-            <at name="text">Clave</at>
-            <at name="height">14</at>
-            <at name="width">131</at>
-            <at name="name">lblPassword</at>
-            <at name="fill">
-             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
-              <at name="name">fill</at>
-             </object>
-            </at>
             <at name="border">
              <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
               <super classname="com.jeta.forms.store.properties.BorderProperty">
@@ -442,6 +433,15 @@
               </at>
              </object>
             </at>
+            <at name="name">lblPassword</at>
+            <at name="width">131</at>
+            <at name="text">Clave</at>
+            <at name="fill">
+             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
+              <at name="name">fill</at>
+             </object>
+            </at>
+            <at name="height">14</at>
            </object>
           </at>
          </object>
@@ -473,16 +473,6 @@
           <at name="classname">javax.swing.JComboBox</at>
           <at name="properties">
            <object classname="com.jeta.forms.store.support.PropertyMap">
-            <at name="height">20</at>
-            <at name="requestFocusEnabled">false</at>
-            <at name="items">
-             <object classname="com.jeta.forms.store.properties.ItemsProperty">
-              <at name="name">items</at>
-             </object>
-            </at>
-            <at name="componentCount">3</at>
-            <at name="width">244</at>
-            <at name="name">cboConnections</at>
             <at name="border">
              <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
               <super classname="com.jeta.forms.store.properties.BorderProperty">
@@ -503,7 +493,17 @@
               </at>
              </object>
             </at>
+            <at name="componentCount">3</at>
             <at name="editable">true</at>
+            <at name="requestFocusEnabled">false</at>
+            <at name="name">cboConnections</at>
+            <at name="width">760</at>
+            <at name="items">
+             <object classname="com.jeta.forms.store.properties.ItemsProperty">
+              <at name="name">items</at>
+             </object>
+            </at>
+            <at name="height">20</at>
            </object>
           </at>
          </object>
@@ -535,14 +535,6 @@
           <at name="classname">javax.swing.JComboBox</at>
           <at name="properties">
            <object classname="com.jeta.forms.store.support.PropertyMap">
-            <at name="height">20</at>
-            <at name="items">
-             <object classname="com.jeta.forms.store.properties.ItemsProperty">
-              <at name="name">items</at>
-             </object>
-            </at>
-            <at name="width">244</at>
-            <at name="name">cboConnectors</at>
             <at name="border">
              <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
               <super classname="com.jeta.forms.store.properties.BorderProperty">
@@ -563,6 +555,14 @@
               </at>
              </object>
             </at>
+            <at name="name">cboConnectors</at>
+            <at name="width">760</at>
+            <at name="items">
+             <object classname="com.jeta.forms.store.properties.ItemsProperty">
+              <at name="name">items</at>
+             </object>
+            </at>
+            <at name="height">20</at>
            </object>
           </at>
          </object>
@@ -594,9 +594,6 @@
           <at name="classname">javax.swing.JTextField</at>
           <at name="properties">
            <object classname="com.jeta.forms.store.support.PropertyMap">
-            <at name="height">20</at>
-            <at name="width">244</at>
-            <at name="name">txtServer</at>
             <at name="border">
              <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
               <super classname="com.jeta.forms.store.properties.BorderProperty">
@@ -617,6 +614,9 @@
               </at>
              </object>
             </at>
+            <at name="name">txtServer</at>
+            <at name="width">760</at>
+            <at name="height">20</at>
            </object>
           </at>
          </object>
@@ -648,9 +648,6 @@
           <at name="classname">javax.swing.JTextField</at>
           <at name="properties">
            <object classname="com.jeta.forms.store.support.PropertyMap">
-            <at name="height">20</at>
-            <at name="width">244</at>
-            <at name="name">txtPort</at>
             <at name="border">
              <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
               <super classname="com.jeta.forms.store.properties.BorderProperty">
@@ -671,60 +668,9 @@
               </at>
              </object>
             </at>
-           </object>
-          </at>
-         </object>
-        </at>
-       </object>
-      </at>
-     </item>
-     <item >
-      <at name="value">
-       <object classname="com.jeta.forms.store.memento.BeanMemento">
-        <super classname="com.jeta.forms.store.memento.ComponentMemento">
-         <at name="cellconstraints">
-          <object classname="com.jeta.forms.store.memento.CellConstraintsMemento">
-           <at name="column">4</at>
-           <at name="row">10</at>
-           <at name="colspan">1</at>
-           <at name="rowspan">1</at>
-           <at name="halign">default</at>
-           <at name="valign">default</at>
-           <at name="insets" object="insets">0,0,0,0</at>
-          </object>
-         </at>
-         <at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at>
-        </super>
-        <at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at>
-        <at name="beanclass">javax.swing.JTextField</at>
-        <at name="beanproperties">
-         <object classname="com.jeta.forms.store.memento.PropertiesMemento">
-          <at name="classname">javax.swing.JTextField</at>
-          <at name="properties">
-           <object classname="com.jeta.forms.store.support.PropertyMap">
+            <at name="name">txtPort</at>
+            <at name="width">760</at>
             <at name="height">20</at>
-            <at name="width">244</at>
-            <at name="name">txtDataBase</at>
-            <at name="border">
-             <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
-              <super classname="com.jeta.forms.store.properties.BorderProperty">
-               <at name="name">border</at>
-              </super>
-              <at name="borders">
-               <object classname="java.util.LinkedList">
-                <item >
-                 <at name="value">
-                  <object classname="com.jeta.forms.store.properties.DefaultBorderProperty">
-                   <super classname="com.jeta.forms.store.properties.BorderProperty">
-                    <at name="name">border</at>
-                   </super>
-                  </object>
-                 </at>
-                </item>
-               </object>
-              </at>
-             </object>
-            </at>
            </object>
           </at>
          </object>
@@ -756,9 +702,6 @@
           <at name="classname">javax.swing.JTextField</at>
           <at name="properties">
            <object classname="com.jeta.forms.store.support.PropertyMap">
-            <at name="height">20</at>
-            <at name="width">244</at>
-            <at name="name">txtUsername</at>
             <at name="border">
              <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
               <super classname="com.jeta.forms.store.properties.BorderProperty">
@@ -779,6 +722,9 @@
               </at>
              </object>
             </at>
+            <at name="name">txtUsername</at>
+            <at name="width">760</at>
+            <at name="height">20</at>
            </object>
           </at>
          </object>
@@ -810,9 +756,6 @@
           <at name="classname">javax.swing.JTextField</at>
           <at name="properties">
            <object classname="com.jeta.forms.store.support.PropertyMap">
-            <at name="height">20</at>
-            <at name="width">244</at>
-            <at name="name">txtPassword</at>
             <at name="border">
              <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
               <super classname="com.jeta.forms.store.properties.BorderProperty">
@@ -833,6 +776,9 @@
               </at>
              </object>
             </at>
+            <at name="name">txtPassword</at>
+            <at name="width">760</at>
+            <at name="height">20</at>
            </object>
           </at>
          </object>
@@ -857,7 +803,7 @@
          </at>
          <at name="componentclass">com.jeta.forms.gui.form.FormComponent</at>
         </super>
-        <at name="id">embedded.1913631561</at>
+        <at name="id">embedded.186663118</at>
         <at name="rowspecs">CENTER:DEFAULT:NONE</at>
         <at name="colspecs">RIGHT:12DLU:GROW(1.0)</at>
         <at name="components">
@@ -886,15 +832,6 @@
                <at name="classname">com.jeta.forms.components.label.JETALabel</at>
                <at name="properties">
                 <object classname="com.jeta.forms.store.support.PropertyMap">
-                 <at name="text">&lt;html&gt; Tenga en cuenta que el nombre de usuario y la  contraseña deben coincidir en mayusculas y minusculas con el registrado en la base de dato. &lt;html&gt;</at>
-                 <at name="height">42</at>
-                 <at name="width">390</at>
-                 <at name="name">lblFoother</at>
-                 <at name="fill">
-                  <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
-                   <at name="name">fill</at>
-                  </object>
-                 </at>
                  <at name="border">
                   <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
                    <super classname="com.jeta.forms.store.properties.BorderProperty">
@@ -915,6 +852,15 @@
                    </at>
                   </object>
                  </at>
+                 <at name="name">lblFoother</at>
+                 <at name="width">814</at>
+                 <at name="text">&lt;html&gt; Tenga en cuenta que el nombre de usuario y la  contraseña deben coincidir en mayusculas y minusculas con el registrado en la base de dato. &lt;html&gt;</at>
+                 <at name="fill">
+                  <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
+                   <at name="name">fill</at>
+                  </object>
+                 </at>
+                 <at name="height">14</at>
                 </object>
                </at>
               </object>
@@ -929,7 +875,17 @@
           <at name="classname">com.jeta.forms.gui.form.GridView</at>
           <at name="properties">
            <object classname="com.jeta.forms.store.support.PropertyMap">
-            <at name="name"></at>
+            <at name="border">
+             <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
+              <super classname="com.jeta.forms.store.properties.BorderProperty">
+               <at name="name">border</at>
+              </super>
+              <at name="borders">
+               <object classname="java.util.LinkedList"/>
+              </at>
+             </object>
+            </at>
+            <at name="name"/>
             <at name="fill">
              <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
               <at name="name">fill</at>
@@ -962,6 +918,177 @@
               </at>
              </object>
             </at>
+           </object>
+          </at>
+         </object>
+        </at>
+        <at name="cellpainters">
+         <object classname="com.jeta.forms.store.support.Matrix">
+          <at name="rows">
+           <object classname="[Ljava.lang.Object;" size="1">
+            <at name="item" index="0">
+             <object classname="[Ljava.lang.Object;" size="1"/>
+            </at>
+           </object>
+          </at>
+         </object>
+        </at>
+        <at name="rowgroups">
+         <object classname="com.jeta.forms.store.memento.FormGroupSet">
+          <at name="groups">
+           <object classname="java.util.HashMap"/>
+          </at>
+         </object>
+        </at>
+        <at name="colgroups">
+         <object classname="com.jeta.forms.store.memento.FormGroupSet">
+          <at name="groups">
+           <object classname="java.util.HashMap"/>
+          </at>
+         </object>
+        </at>
+       </object>
+      </at>
+     </item>
+     <item >
+      <at name="value">
+       <object classname="com.jeta.forms.store.memento.FormMemento">
+        <super classname="com.jeta.forms.store.memento.ComponentMemento">
+         <at name="cellconstraints">
+          <object classname="com.jeta.forms.store.memento.CellConstraintsMemento">
+           <at name="column">4</at>
+           <at name="row">10</at>
+           <at name="colspan">1</at>
+           <at name="rowspan">1</at>
+           <at name="halign">default</at>
+           <at name="valign">default</at>
+           <at name="insets" object="insets">0,0,0,0</at>
+          </object>
+         </at>
+         <at name="componentclass">com.jeta.forms.gui.form.FormComponent</at>
+        </super>
+        <at name="id">embedded.D62a6c86R15a7a6771e8EJ7fff</at>
+        <at name="rowspecs">CENTER:DEFAULT:NONE</at>
+        <at name="colspecs">FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE</at>
+        <at name="components">
+         <object classname="java.util.LinkedList">
+          <item >
+           <at name="value">
+            <object classname="com.jeta.forms.store.memento.BeanMemento">
+             <super classname="com.jeta.forms.store.memento.ComponentMemento">
+              <at name="cellconstraints">
+               <object classname="com.jeta.forms.store.memento.CellConstraintsMemento">
+                <at name="column">1</at>
+                <at name="row">1</at>
+                <at name="colspan">1</at>
+                <at name="rowspan">1</at>
+                <at name="halign">default</at>
+                <at name="valign">default</at>
+                <at name="insets" object="insets">0,0,0,0</at>
+               </object>
+              </at>
+              <at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at>
+             </super>
+             <at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at>
+             <at name="beanclass">javax.swing.JTextField</at>
+             <at name="beanproperties">
+              <object classname="com.jeta.forms.store.memento.PropertiesMemento">
+               <at name="classname">javax.swing.JTextField</at>
+               <at name="properties">
+                <object classname="com.jeta.forms.store.support.PropertyMap">
+                 <at name="border">
+                  <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
+                   <super classname="com.jeta.forms.store.properties.BorderProperty">
+                    <at name="name">border</at>
+                   </super>
+                   <at name="borders">
+                    <object classname="java.util.LinkedList">
+                     <item >
+                      <at name="value">
+                       <object classname="com.jeta.forms.store.properties.DefaultBorderProperty">
+                        <super classname="com.jeta.forms.store.properties.BorderProperty">
+                         <at name="name">border</at>
+                        </super>
+                       </object>
+                      </at>
+                     </item>
+                    </object>
+                   </at>
+                  </object>
+                 </at>
+                 <at name="name">txtDataBase</at>
+                 <at name="width">707</at>
+                 <at name="height">20</at>
+                </object>
+               </at>
+              </object>
+             </at>
+            </object>
+           </at>
+          </item>
+          <item >
+           <at name="value">
+            <object classname="com.jeta.forms.store.memento.BeanMemento">
+             <super classname="com.jeta.forms.store.memento.ComponentMemento">
+              <at name="cellconstraints">
+               <object classname="com.jeta.forms.store.memento.CellConstraintsMemento">
+                <at name="column">2</at>
+                <at name="row">1</at>
+                <at name="colspan">1</at>
+                <at name="rowspan">1</at>
+                <at name="halign">default</at>
+                <at name="valign">default</at>
+                <at name="insets" object="insets">0,0,0,0</at>
+               </object>
+              </at>
+              <at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at>
+             </super>
+             <at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at>
+             <at name="beanclass">javax.swing.JButton</at>
+             <at name="beanproperties">
+              <object classname="com.jeta.forms.store.memento.PropertiesMemento">
+               <at name="classname">javax.swing.JButton</at>
+               <at name="properties">
+                <object classname="com.jeta.forms.store.support.PropertyMap">
+                 <at name="border">
+                  <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
+                   <super classname="com.jeta.forms.store.properties.BorderProperty">
+                    <at name="name">border</at>
+                   </super>
+                   <at name="borders">
+                    <object classname="java.util.LinkedList">
+                     <item >
+                      <at name="value">
+                       <object classname="com.jeta.forms.store.properties.DefaultBorderProperty">
+                        <super classname="com.jeta.forms.store.properties.BorderProperty">
+                         <at name="name">border</at>
+                        </super>
+                       </object>
+                      </at>
+                     </item>
+                    </object>
+                   </at>
+                  </object>
+                 </at>
+                 <at name="actionCommand">...</at>
+                 <at name="name">btnDataBaseBrowser</at>
+                 <at name="width">44</at>
+                 <at name="text">...</at>
+                 <at name="height">22</at>
+                </object>
+               </at>
+              </object>
+             </at>
+            </object>
+           </at>
+          </item>
+         </object>
+        </at>
+        <at name="properties">
+         <object classname="com.jeta.forms.store.memento.PropertiesMemento">
+          <at name="classname">com.jeta.forms.gui.form.GridView</at>
+          <at name="properties">
+           <object classname="com.jeta.forms.store.support.PropertyMap">
             <at name="border">
              <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
               <super classname="com.jeta.forms.store.properties.BorderProperty">
@@ -972,6 +1099,19 @@
               </at>
              </object>
             </at>
+            <at name="name"></at>
+            <at name="fill">
+             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
+              <at name="name">fill</at>
+             </object>
+            </at>
+            <at name="scollBars">
+             <object classname="com.jeta.forms.store.properties.ScrollBarsProperty">
+              <at name="name">scollBars</at>
+              <at name="verticalpolicy">21</at>
+              <at name="horizontalpolicy">31</at>
+             </object>
+            </at>
            </object>
           </at>
          </object>
@@ -981,7 +1121,7 @@
           <at name="rows">
            <object classname="[Ljava.lang.Object;" size="1">
             <at name="item" index="0">
-             <object classname="[Ljava.lang.Object;" size="1"/>
+             <object classname="[Ljava.lang.Object;" size="2"/>
             </at>
            </object>
           </at>
@@ -1011,6 +1151,16 @@
      <at name="classname">com.jeta.forms.gui.form.GridView</at>
      <at name="properties">
       <object classname="com.jeta.forms.store.support.PropertyMap">
+       <at name="border">
+        <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
+         <super classname="com.jeta.forms.store.properties.BorderProperty">
+          <at name="name">border</at>
+         </super>
+         <at name="borders">
+          <object classname="java.util.LinkedList"/>
+         </at>
+        </object>
+       </at>
        <at name="name"></at>
        <at name="fill">
         <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
@@ -1044,16 +1194,6 @@
          </at>
         </object>
        </at>
-       <at name="border">
-        <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
-         <super classname="com.jeta.forms.store.properties.BorderProperty">
-          <at name="name">border</at>
-         </super>
-         <at name="borders">
-          <object classname="java.util.LinkedList"/>
-         </at>
-        </object>
-       </at>
       </object>
      </at>
     </object>
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/jdbc/DefaultJDBCConnectionPanelView.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/jdbc/DefaultJDBCConnectionPanelView.java	(revision 43113)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/jdbc/DefaultJDBCConnectionPanelView.java	(revision 43114)
@@ -9,6 +9,7 @@
 import java.awt.Dimension;
 import javax.swing.Box;
 import javax.swing.ImageIcon;
+import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
@@ -29,10 +30,11 @@
    JComboBox cboConnectors = new JComboBox();
    JTextField txtServer = new JTextField();
    JTextField txtPort = new JTextField();
-   JTextField txtDataBase = new JTextField();
    JTextField txtUsername = new JTextField();
    JTextField txtPassword = new JTextField();
    JLabel lblFoother = new JLabel();
+   JTextField txtDataBase = new JTextField();
+   JButton btnDataBaseBrowser = new JButton();
 
    /**
     * Default constructor
@@ -170,9 +172,6 @@
       txtPort.setName("txtPort");
       jpanel1.add(txtPort,cc.xy(4,8));
 
-      txtDataBase.setName("txtDataBase");
-      jpanel1.add(txtDataBase,cc.xy(4,10));
-
       txtUsername.setName("txtUsername");
       jpanel1.add(txtUsername,cc.xy(4,12));
 
@@ -180,6 +179,7 @@
       jpanel1.add(txtPassword,cc.xy(4,14));
 
       jpanel1.add(createPanel1(),cc.xywh(2,16,3,1));
+      jpanel1.add(createPanel2(),cc.xy(4,10));
       addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 });
       return jpanel1;
    }
@@ -199,6 +199,25 @@
       return jpanel1;
    }
 
+   public JPanel createPanel2()
+   {
+      JPanel jpanel1 = new JPanel();
+      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
+      CellConstraints cc = new CellConstraints();
+      jpanel1.setLayout(formlayout1);
+
+      txtDataBase.setName("txtDataBase");
+      jpanel1.add(txtDataBase,cc.xy(1,1));
+
+      btnDataBaseBrowser.setActionCommand("...");
+      btnDataBaseBrowser.setName("btnDataBaseBrowser");
+      btnDataBaseBrowser.setText("...");
+      jpanel1.add(btnDataBaseBrowser,cc.xy(2,1));
+
+      addFillComponents(jpanel1,new int[0],new int[0]);
+      return jpanel1;
+   }
+
    /**
     * Initializer
     */
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/jdbc/DefaultJDBCConnectionPanel.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/jdbc/DefaultJDBCConnectionPanel.java	(revision 43113)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/jdbc/DefaultJDBCConnectionPanel.java	(revision 43114)
@@ -6,16 +6,21 @@
 package org.gvsig.fmap.dal.swing.impl.jdbc;
 
 import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
+import java.io.File;
 import java.util.Iterator;
 import java.util.List;
 import javax.swing.ComboBoxModel;
 import javax.swing.JComponent;
 import javax.swing.JLabel;
 import javax.swing.JTextField;
+import javax.swing.SwingUtilities;
 import javax.swing.plaf.basic.BasicHTML;
 import javax.swing.text.View;
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.gvsig.fmap.dal.DALLocator;
 import org.gvsig.fmap.dal.DataFactory;
@@ -24,10 +29,15 @@
 import org.gvsig.fmap.dal.DataServerExplorerPool;
 import org.gvsig.fmap.dal.DataServerExplorerPoolEntry;
 import org.gvsig.fmap.dal.exception.DataException;
+import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
 import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
 import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionPanel;
 import org.gvsig.tools.ToolsLocator;
+import org.gvsig.tools.dynobject.DynClass;
+import org.gvsig.tools.dynobject.DynField;
 import org.gvsig.tools.i18n.I18nManager;
+import org.gvsig.tools.swing.api.ToolsSwingLocator;
+import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -81,13 +91,29 @@
         this.cboConnections.addItemListener(new ItemListener() {
             @Override
             public void itemStateChanged(ItemEvent e) {
-                onChangeConnection();
+                // Lo hago asi para evitar cuelgues durante la depuracion
+                // al poner puntos de ruptura en un evento de un combo.
+                SwingUtilities.invokeLater(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        onChangeConnection();
+                    }
+                });
             }
         });
         this.cboConnectors.addItemListener(new ItemListener() {
             @Override
             public void itemStateChanged(ItemEvent e) {
-                onChangeConnector();
+                // Lo hago asi para evitar cuelgues durante la depuracion
+                // al poner puntos de ruptura en un evento de un combo.
+                SwingUtilities.invokeLater(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        onChangeConnector();
+                    }
+                });
             }
         });
         try {
@@ -98,6 +124,13 @@
             logger.warn("Can't fill combos",th);
         }
         this.translate();
+        this.btnDataBaseBrowser.addActionListener(new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                onBrowseDatabase();
+            }
+        });
         adjustPreferedHeight(this.lblFoother,300);
     }
 
@@ -147,6 +180,20 @@
         this.txtDataBase.setText(parameters.getDBName());
         this.txtUsername.setText(parameters.getUser());
         this.txtPassword.setText(parameters.getPassword());
+        
+        DynClass definition = parameters.getDynClass();
+        
+        DynField field = definition.getDynField(JDBCServerExplorerParameters.HOST_PARAMTER_NAME);
+        this.txtServer.setEnabled( !( field.isReadOnly() || field.isHidden() ));
+        field = definition.getDynField(JDBCServerExplorerParameters.PORT_PARAMTER_NAME);
+        this.txtPort.setEnabled( !( field.isReadOnly() || field.isHidden() ));
+        field = definition.getDynField(JDBCServerExplorerParameters.DBNAME_PARAMTER_NAME);
+        this.txtDataBase.setEnabled( !( field.isReadOnly() || field.isHidden() ));
+        field = definition.getDynField(JDBCServerExplorerParameters.USER_PARAMTER_NAME);
+        this.txtUsername.setEnabled( !( field.isReadOnly() || field.isHidden() ));
+        field = definition.getDynField(JDBCServerExplorerParameters.PASSWORD_PARAMTER_NAME);
+        this.txtPassword.setEnabled( !( field.isReadOnly() || field.isHidden() ));
+        this.btnDataBaseBrowser.setVisible(parameters instanceof FilesystemStoreParameters);
     }
 
     @Override
@@ -351,4 +398,21 @@
         this.txtUsername.setText("");
         this.txtPassword.setText("");
     }
+    
+    private void onBrowseDatabase() {
+        if( this.forcedParameters==null ) {
+            return;
+        }
+        ThreadSafeDialogsManager dlgmanager = ToolsSwingLocator.getThreadSafeDialogsManager();
+        I18nManager i18nManager = ToolsLocator.getI18nManager();
+        File[] files = dlgmanager.showOpenFileDialog(
+                i18nManager.getTranslation("_Select_database"), 
+                null
+        );
+        if( ArrayUtils.isEmpty(files) ) {
+            return;
+        }
+        ((FilesystemStoreParameters)this.forcedParameters).setFile(files[0]);
+        this.txtDataBase.setText(this.forcedParameters.getDBName());
+    }
 }
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/pom.xml
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/pom.xml	(revision 43113)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/pom.xml	(revision 43114)
@@ -30,6 +30,11 @@
         </dependency>
         <dependency>
             <groupId>org.gvsig</groupId>
+            <artifactId>org.gvsig.fmap.dal.file.lib</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.gvsig</groupId>
             <artifactId>org.gvsig.fmap.dal.swing.api</artifactId>
             <scope>compile</scope>
         </dependency>   
Index: 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/SQLBuilder.java
===================================================================
--- 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/SQLBuilder.java	(revision 43113)
+++ 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/SQLBuilder.java	(revision 43114)
@@ -1,6 +1,7 @@
 package org.gvsig.fmap.dal;
 
 import java.util.List;
+import org.cresques.cts.IProjection;
 
 public interface SQLBuilder extends ExpressionBuilder {
     
@@ -75,6 +76,33 @@
         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 isAutomatic();
+        boolean allowNulls();
+        public Object getDefaultValue();
+        public int getGeometryType();
+        public int getGeometrySubtype();
+        public int 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(int geom_srsid);
+    }
 
     public interface CountBuilder extends Value {
         public CountBuilder all();
@@ -194,6 +222,8 @@
     public interface CreateTableBuilder extends Statement {
         public TableNameBuilder table();
         public CreateTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean allowNulls, boolean isAutomatic, Object defaultValue);
+        public CreateTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean allowNulls);
+        public ColumnDescriptorBuilder getColumnDescriptor(String columnName);
         public List<String> toStrings();
     }
     
@@ -228,7 +258,11 @@
     public String default_schema();
 
     public String sqltype(int dataType, int p, int s);
+    
+    public Object sqlgeometrytype(int type, int subtype);
 
+    public Object sqlgeometrydimension(int type, int subtype);
+    
     public SelectBuilder select();
     
     public UpdateBuilder update();
Index: trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/SQLBuilderBase.java
===================================================================
--- trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/SQLBuilderBase.java	(revision 43113)
+++ trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/SQLBuilderBase.java	(revision 43114)
@@ -10,6 +10,7 @@
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
+import org.cresques.cts.IProjection;
 import org.gvsig.fmap.dal.DataTypes;
 import org.gvsig.fmap.dal.ExpressionBuilder;
 import org.gvsig.fmap.dal.SQLBuilder;
@@ -30,6 +31,10 @@
 import org.gvsig.fmap.dal.SQLBuilder.UpdateBuilder;
 import org.gvsig.fmap.dal.SQLBuilder.UpdateColumnBuilder;
 import org.gvsig.fmap.dal.SQLBuilder.UpdateTableStatisticsBuilder;
+import org.gvsig.fmap.geom.Geometry;
+import org.gvsig.fmap.geom.GeometryLocator;
+import org.gvsig.fmap.geom.GeometryManager;
+import org.gvsig.fmap.geom.type.GeometryType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -48,39 +53,178 @@
     protected UpdateTableStatisticsBuilder update_table_statistics;
     protected List<Parameter> parameters;
 
-    protected class ColumnInfo {
+    protected class ColumnDescriptorBuilderBase implements ColumnDescriptorBuilder {
 
-        public String name;
-        public int type;
-        public int type_p;
-        public int type_s;
-        public boolean isPk;
-        public boolean allowNulls;
-        public boolean isAutomatic;
-        public Object defaultValue;
+        private String name;
+        private int type;
+        private int type_p;
+        private int type_s;
+        private boolean isPk;
+        private boolean _allowNulls;
+        private boolean _isAutomatic;
+        private Object defaultValue;
+        private int geom_type;
+        private int geom_subtype;
+        private int geom_srsid;
 
-        public ColumnInfo(String name, int type, Object defaultValue) {
+        public ColumnDescriptorBuilderBase(String name, int type, Object defaultValue) {
             this.name = name;
             this.type = type;
             this.type_p = -1;
             this.type_s = -1;
             this.isPk = false;
-            this.allowNulls = true;
-            this.isAutomatic = false;
+            this._allowNulls = true;
+            this._isAutomatic = false;
             this.defaultValue = defaultValue;
+            this.geom_type = Geometry.TYPES.GEOMETRY;
+            this.geom_subtype = Geometry.SUBTYPES.GEOM2D;
+            this.geom_srsid = -1;
         }
 
-        public ColumnInfo(String name, int type, int type_p, int type_s, boolean isPk, boolean allowNulls, boolean isAutomatic, Object defaultValue) {
+        public ColumnDescriptorBuilderBase(String name, int type, int type_p, int type_s, boolean isPk, boolean allowNulls, boolean isAutomatic, Object defaultValue) {
             this.name = name;
             this.type = type;
             this.type_p = type_p;
             this.type_s = type_s;
             this.isPk = isPk;
-            this.allowNulls = allowNulls;
-            this.isAutomatic = isAutomatic;
+            this._allowNulls = allowNulls;
+            this._isAutomatic = isAutomatic;
             this.defaultValue = defaultValue;
+            this.geom_type = Geometry.TYPES.GEOMETRY;
+            this.geom_subtype = Geometry.SUBTYPES.GEOM2D;
+            this.geom_srsid = -1;
         }
+        
+        public ColumnDescriptorBuilderBase(String name, int geom_type, int geom_subtype, IProjection proj, boolean allowNulls) {
+            this.name = name;
+            this.type_p = 0;
+            this.type_s = 0;
+            this.isPk = false;
+            this._allowNulls = allowNulls;
+            this._isAutomatic = false;
+            this.defaultValue = null;
+            this.geom_type = geom_type;
+            this.geom_subtype = geom_subtype;
+            this.geom_srsid = getSRSId(proj);
+        }
+        
+        @Override
+        public String getName() {
+            return this.name;
+        }
+        
+        @Override
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        @Override
+        public int getType() {
+            return this.type;
+        }
+
+        @Override
+        public void setType(int type) {
+            this.type = type;
+        }
+
+        @Override
+        public int getPrecision() {
+            return type_p;
+        }
+
+        @Override
+        public void setPrecision(int precision) {
+            this.type_p = precision;
+        }
+
+        @Override
+        public int getSize() {
+            return type_s;
+        }
+
+        @Override
+        public void setSize(int size) {
+            this.type_s = size;
+        }
+
+        @Override
+        public boolean isPrimaryKey() {
+            return isPk;
+        }
+
+        @Override
+        public void setIsPrimaryKey(boolean isPk) {
+            this.isPk = isPk;
+        }
+
+        @Override
+        public boolean allowNulls() {
+            return _allowNulls;
+        }
+
+        @Override
+        public void setAllowNulls(boolean allowNulls) {
+            this._allowNulls = allowNulls;
+        }
+
+        @Override
+        public boolean isAutomatic() {
+            return _isAutomatic;
+        }
+
+        @Override
+        public void setIsAutomatic(boolean isAutomatic) {
+            this._isAutomatic = isAutomatic;
+        }
+
+        @Override
+        public Object getDefaultValue() {
+            return defaultValue;
+        }
+
+        @Override
+        public void setDefaultValue(Object defaultValue) {
+            this.defaultValue = defaultValue;
+        }
+
+        @Override
+        public int getGeometryType() {
+            return geom_type;
+        }
+
+        @Override
+        public void setGeometryType(int geom_type) {
+            this.geom_type = geom_type;
+        }
+
+        @Override
+        public int getGeometrySubtype() {
+            return geom_subtype;
+        }
+
+        @Override
+        public void setGeometrySubtype(int geom_subtype) {
+            this.geom_subtype = geom_subtype;
+        }
+
+        @Override
+        public int getGeometrySRSId() {
+            return geom_srsid;
+        }
+
+        @Override
+        public void setGeometrySRSId(int geom_srsid) {
+            this.geom_srsid = geom_srsid;
+        }        
+
+        @Override
+        public boolean isGeometry() {
+            return this.type == DataTypes.GEOMETRY;
+        }
+                
     }
+    
 
     public class TableNameBuilderBase implements TableNameBuilder {
 
@@ -222,7 +366,7 @@
         @Override
         public TableNameBuilder table() {
             if( tableName == null ) {
-                this.tableName = new TableNameBuilderBase();
+                this.tableName = createTableNameBuilder();
             }
             return this.tableName;
         }
@@ -363,7 +507,7 @@
         protected boolean ascending;
         
         public OrderByBuilderBase() {
-            
+            this.ascending = true;
         }
 
         @Override
@@ -620,7 +764,7 @@
         @Override
         public TableNameBuilder table() {
             if( table == null ) {
-                table = new TableNameBuilderBase();
+                table = createTableNameBuilder();
             }
             return table;
         }
@@ -804,7 +948,7 @@
         @Override
         public TableNameBuilder table() {
             if( table == null ) {
-                table = new TableNameBuilderBase();
+                table = createTableNameBuilder();
             }
             return table;
         }
@@ -912,7 +1056,7 @@
         @Override
         public TableNameBuilder table() {
             if( table == null ) {
-                table = new TableNameBuilderBase();
+                table = createTableNameBuilder();
             }
             return table;
         }
@@ -1002,7 +1146,7 @@
         @Override
         public TableNameBuilder table() {
             if( table == null ) {
-                table = new TableNameBuilderBase();
+                table = createTableNameBuilder();
             }
             return table;
         }
@@ -1039,8 +1183,8 @@
 
         protected TableNameBuilder table;
         protected List<String> drops;
-        protected List<ColumnInfo> adds;
-        protected List<ColumnInfo> alters;
+        protected List<ColumnDescriptorBuilderBase> adds;
+        protected List<ColumnDescriptorBuilderBase> alters;
         protected List<Pair> renames;
 
         public AlterTableBuilderBase() {
@@ -1063,7 +1207,7 @@
         @Override
         public TableNameBuilder table() {
             if( table == null ) {
-                table = new TableNameBuilderBase();
+                table = createTableNameBuilder();
             }
             return table;
         }
@@ -1079,7 +1223,7 @@
             if (isPk || isAutomatic) {
                 allowNulls = false;
             }
-            this.adds.add(new ColumnInfo(columnName, type, type_p, type_s, isPk, allowNulls, isAutomatic, defaultValue));
+            this.adds.add(new ColumnDescriptorBuilderBase(columnName, type, type_p, type_s, isPk, allowNulls, isAutomatic, defaultValue));
             return this;
         }
 
@@ -1088,7 +1232,7 @@
             if (isPk || isAutomatic) {
                 allowNulls = false;
             }
-            this.alters.add(new ColumnInfo(columnName, type, type_p, type_s, isPk, allowNulls, isAutomatic, defaultValue));
+            this.alters.add(new ColumnDescriptorBuilderBase(columnName, type, type_p, type_s, isPk, allowNulls, isAutomatic, defaultValue));
             return this;
         }
 
@@ -1189,69 +1333,69 @@
                 builder.append(column);
             }
             first = drops.isEmpty();
-            for (ColumnInfo column : adds) {
+            for (ColumnDescriptorBuilderBase column : adds) {
                 if (first) {
                     first = false;
                 } else {
                     builder.append(", ");
                 }
                 builder.append("ADD COLUMN ");
-                builder.append(column.name);
+                builder.append(column.getName());
                 builder.append(" ");
-                if( column.type == DataTypes.INT && column.isAutomatic ) {
+                if( column.getType() == DataTypes.INT && column.isAutomatic() ) {
                     builder.append(" SERIAL");
                 } else {
-                    builder.append(sqltype(column.type, column.type_p, column.type_s));
+                    builder.append(sqltype(column.getType(), column.getPrecision(), column.getSize()));
                 }
-                if (column.defaultValue == null) {
-                    if (column.allowNulls) {
+                if (column.getDefaultValue() == null) {
+                    if (column.allowNulls()) {
                         builder.append(" DEFAULT NULL");
                     }
                 } else {
                     builder.append(" DEFAULT '");
-                    builder.append(column.defaultValue.toString());
+                    builder.append(column.getDefaultValue().toString());
                     builder.append("'");
                 }
-                if (column.allowNulls) {
+                if (column.allowNulls()) {
                     builder.append(" NULL");
                 } else {
                     builder.append(" NOT NULL");
                 }
-                if (column.isPk) {
+                if (column.isPrimaryKey()) {
                     builder.append(" PRIMARY KEY");
                 }
             }
             first = drops.isEmpty() && adds.isEmpty();
-            for (ColumnInfo column : alters) {
+            for (ColumnDescriptorBuilderBase column : alters) {
                 if (first) {
                     first = false;
                 } else {
                     builder.append(", ");
                 }
                 builder.append("ALTER COLUMN ");
-                builder.append(column.name);
+                builder.append(column.getName());
                 builder.append("SET DATA TYPE ");
-                if( column.type == DataTypes.INT && column.isAutomatic ) {
+                if( column.getType() == DataTypes.INT && column.isAutomatic() ) {
                     builder.append(" SERIAL");
                 } else {
-                    builder.append(sqltype(column.type, column.type_p, column.type_s));
+                    builder.append(sqltype(column.getType(), column.getPrecision(), column.getSize()));
                 }
                 builder.append(", ");
-                if (column.defaultValue == null) {
-                    if (column.allowNulls) {
+                if (column.getDefaultValue() == null) {
+                    if (column.allowNulls()) {
                         builder.append("ALTER COLUMN ");
-                        builder.append(column.name);
+                        builder.append(column.getName());
                         builder.append(" SET DEFAULT NULL");
                     } else {
                         builder.append("ALTER COLUMN ");
-                        builder.append(column.name);
+                        builder.append(column.getName());
                         builder.append(" DROP DEFAULT");
                     }
                 } else {
                     builder.append("ALTER COLUMN ");
-                    builder.append(column.name);
+                    builder.append(column.getName());
                     builder.append(" SET DEFAULT '");
-                    builder.append(column.defaultValue.toString());
+                    builder.append(column.getDefaultValue().toString());
                     builder.append("'");
                 }
             }
@@ -1277,7 +1421,7 @@
     public class CreateTableBuilderBase implements CreateTableBuilder {
 
         protected TableNameBuilder table;
-        protected List<ColumnInfo> columns;
+        protected List<ColumnDescriptorBuilderBase> columns;
 
         public CreateTableBuilderBase() {
             this.columns = new ArrayList<>();
@@ -1296,21 +1440,46 @@
         @Override
         public TableNameBuilder table() {
             if( table == null ) {
-                table = new TableNameBuilderBase();
+                table = createTableNameBuilder();
             }
             return table;
         }
 
         @Override
         public CreateTableBuilderBase add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean allowNulls, boolean isAutomatic, Object defaultValue) {
+            if( StringUtils.isEmpty(columnName) ) {
+                throw new IllegalArgumentException("Argument 'columnName' can't be empty.");
+            }
             if (isPk || isAutomatic) {
                 allowNulls = false;
             }
-            this.columns.add(new ColumnInfo(columnName, type, type_p, type_s, isPk, allowNulls, isAutomatic, defaultValue));
+            this.columns.add(new ColumnDescriptorBuilderBase(columnName, type, type_p, type_s, isPk, allowNulls, isAutomatic, defaultValue));
             return this;
         }
 
         @Override
+        public CreateTableBuilder add_geometry_column(String columnName, int type, int subtype, IProjection proj, boolean allowNulls) {
+            if( StringUtils.isEmpty(columnName) ) {
+                throw new IllegalArgumentException("Argument 'columnName' can't be empty.");
+            }
+            this.columns.add(new ColumnDescriptorBuilderBase(columnName, type, subtype, proj, allowNulls));
+            return this;
+        }
+
+        @Override
+        public ColumnDescriptorBuilder getColumnDescriptor(String columnName) {
+            if( StringUtils.isEmpty(columnName) ) {
+                return null;
+            }
+            for (ColumnDescriptorBuilderBase column : columns) {
+                if( columnName.equals(column.getName()) ) {
+                    return column;
+                }
+            }
+            return null;
+        }
+                
+        @Override
         public String toString() {
             StringBuilder builder = new StringBuilder();
             boolean first = true;
@@ -1362,36 +1531,36 @@
             builder.append(this.table.toString());
             builder.append(" (");
             boolean first = true;
-            for (ColumnInfo column : columns) {
+            for (ColumnDescriptorBuilderBase column : columns) {
                 if (first) {
                     first = false;
                 } else {
                     builder.append(", ");
                 }
-                builder.append(identifier(column.name));
+                builder.append(identifier(column.getName()));
                 builder.append(" ");
-                if( column.isAutomatic && column.type == DataTypes.INT ) {
+                if( column.isAutomatic() && column.getType() == DataTypes.INT ) {
                     builder.append("SERIAL");
-                } else if( column.isAutomatic && column.type == DataTypes.LONG ) {
+                } else if( column.isAutomatic() && column.getType() == DataTypes.LONG ) {
                     builder.append("BIGSERIAL");
                 } else {
-                    builder.append(sqltype(column.type, column.type_p, column.type_s));
+                    builder.append(sqltype(column.getType(), column.getPrecision(), column.getSize()));
                 }
-                if (column.defaultValue == null) {
-                    if (column.allowNulls) {
+                if (column.getDefaultValue() == null) {
+                    if (column.allowNulls()) {
                         builder.append(" DEFAULT NULL");
                     }
                 } else {
                     builder.append(" DEFAULT '");
-                    builder.append(column.defaultValue.toString());
+                    builder.append(column.getDefaultValue().toString());
                     builder.append("'");
                 }
-                if (column.allowNulls) {
+                if (column.allowNulls()) {
                     builder.append(" NULL");
                 } else {
                     builder.append(" NOT NULL");
                 }
-                if (column.isPk) {
+                if (column.isPrimaryKey()) {
                     builder.append(" PRIMARY KEY");
                 }
             }
@@ -1475,7 +1644,7 @@
         @Override
         public TableNameBuilder table() {
             if( table == null ) {
-                table = new TableNameBuilderBase();
+                table = createTableNameBuilder();
             }
             return table;
         }
@@ -1544,7 +1713,7 @@
         @Override
         public TableNameBuilder table() {
             if( table == null ) {
-                table = new TableNameBuilderBase();
+                table = createTableNameBuilder();
             }
             return table;
         }
@@ -1704,6 +1873,75 @@
         }
     }
 
+    private static Map<Pair<Integer,Integer>,String> sqlgeometrytypes = null;
+    
+    @Override
+    public Object sqlgeometrytype(int type, int subtype) {
+        // Devuelve un Object por que algunos gestores de BBDD utilizan
+        // identificadores numericos para el tipo y otros strings.
+        // Por defecto vamos a devolver strings.
+        if( sqlgeometrytypes==null ) {
+            sqlgeometrytypes = new HashMap<>();
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM2D), "POINT");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM3D), "POINTZ");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM2DM), "POINTM");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM3DM), "POINTZM");
+
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM2D), "LINESTRING");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM3D), "LINESTRINGZ");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM2DM), "LINESTRINGM");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM3DM), "LINESTRINGZM");
+
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM2D), "POLYGON");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM3D), "POLYGONZ");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM2DM), "POLYGONM");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM3DM), "POLYGONZM");
+
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM2D), "MULTIPOINT");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM3D), "MULTIPOINTZ");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM2DM), "MULTIPOINTM");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM3DM), "MULTIPOINTZM");
+
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM2D), "MULTILINESTRING");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM3D), "MULTILINESTRINGZ");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM2DM), "MULTILINESTRINGM");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM3DM), "MULTILINESTRINGZM");
+
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM2D), "MULTIPOLYGON");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM3D), "MULTIPOLYGONZ");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM2DM), "MULTIPOLYGONM");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM3DM), "MULTIPOLYGONZM");
+
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM2D), "GEOMETRY");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM3D), "GEOMETRYZ");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM2DM), "GEOMETRYM");
+            sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM3DM), "GEOMETRYZM");
+        }
+        return sqlgeometrytypes.get(new ImmutablePair<>(type,subtype));
+    }
+
+    @Override
+    public Object sqlgeometrydimension(int type, int subtype) {
+        // Devuelve un Object por que algunos gestortes de BBDD utilizan
+        // identificadores numericos para las dimensiones y otros strings.
+        // Por defecto vamos a devolver enteros.
+        switch(subtype) {
+            case Geometry.SUBTYPES.GEOM3D:
+                return 3;
+            case Geometry.SUBTYPES.GEOM2DM:
+                return 3;
+            case Geometry.SUBTYPES.GEOM3DM:
+                return 4;
+            case Geometry.SUBTYPES.GEOM2D:
+            default:
+                return 2;
+        }
+    }
+    
+    protected TableNameBuilder createTableNameBuilder() {
+        return new TableNameBuilderBase();
+    }
+    
     protected SelectColumnBuilder createSelectColumnBuilder() {
         return new SelectColumnBuilderBase();
     }
