Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/pom.xml
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/pom.xml	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/pom.xml	(revision 928)
@@ -0,0 +1,214 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>org.gvsig.postgresql.provider</artifactId>
+  <packaging>jar</packaging>
+  <name>${project.artifactId}</name>
+  <description>DAL provider for PostgeSQL files</description>
+  <parent>
+    <groupId>org.gvsig</groupId>
+    <artifactId>org.gvsig.postgresql</artifactId>
+    <version>2.0.182</version>
+  </parent>
+  <dependencies>
+    <dependency>
+      <groupId>com.googlecode.log4jdbc</groupId>
+      <artifactId>log4jdbc</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.tools.lib</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.projection.api</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.fmap.dal.api</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.fmap.dal.db.jdbc</artifactId>
+      <scope>compile</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.fmap.dal.db.lib</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.fmap.dal.spi</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.fmap.geometry.api</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <!--
+    <dependency>
+        <groupId>org.gvsig</groupId>
+        <artifactId>org.gvsig.fmap.geometry.operation</artifactId>
+        <scope>compile</scope>
+    </dependency>
+    -->
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.timesupport.lib.api</artifactId>
+      <scope>compile</scope>
+    </dependency>  
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.utils</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.postgresql</groupId>
+      <artifactId>postgresql</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.commons</groupId>
+        <artifactId>commons-dbcp2</artifactId>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.commons</groupId>
+        <artifactId>commons-pool2</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+      <scope>compile</scope>
+    </dependency>
+
+
+    <!-- TESTS -->
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.tools.lib</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.compat.se</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.fmap.dal.impl</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.fmap.dal.file.csv</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.tools.util.impl</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.tools.swing.impl</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>${org.gvsig.fmap.geometry.impl}</artifactId>
+      <scope>test</scope>
+    </dependency>    
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.expressionevaluator.geometry.lib.impl</artifactId>
+      <scope>test</scope>
+    </dependency>    
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>${org.gvsig.proj.lib.impl}</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.projection.cresques.impl</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.timesupport.lib.impl</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.metadata.lib.basic.impl</artifactId>
+      <scope>test</scope>
+    </dependency>      
+    
+    
+    <dependency>
+      <artifactId>junit</artifactId>
+      <groupId>junit</groupId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+
+      <!-- Skip test execution ? -->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <skipTests>false</skipTests>
+        </configuration>
+      </plugin>
+        
+      <!-- Skip test compilation ? -->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>default-testCompile</id>
+            <phase>process-test-sources</phase>
+            <goals>
+              <goal>testCompile</goal>
+            </goals>
+            <configuration>
+              <skip>false</skip>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+      <!-- Ignore test execution failure ? -->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <testFailureIgnore>false</testFailureIgnore>
+        </configuration>
+      </plugin>
+
+    </plugins>
+  </build>
+
+</project>
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/updateTableStatistics.sql
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/updateTableStatistics.sql	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/updateTableStatistics.sql	(revision 928)
@@ -0,0 +1,3 @@
+
+-- UpdateTableStatistics SQL
+ANALYZE "public"."test";
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/append.sql
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/append.sql	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/append.sql	(revision 928)
@@ -0,0 +1,14 @@
+
+-- Previous SQLs
+
+-- Inser SQL
+
+INSERT INTO "dbtest"."public"."test" ( 
+    "ID", "Byte", "Bool1", "Long", "Timestamp", "Date", "Time", 
+    "Bool2", "String", "Bool3", "Double", "Bool4", "Float", "Bool5", 
+    "Decimal", "Geometry" 
+  ) VALUES ( 
+      ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ST_GeomFromWKB((?), (?)) 
+  );
+
+-- Post SQLs
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/fetchFeatureType.sql
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/fetchFeatureType.sql	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/fetchFeatureType.sql	(revision 928)
@@ -0,0 +1,17 @@
+
+-- FetchFeatureType first row SQL
+SELECT * FROM "dbtest"."public"."test" LIMIT 1;
+
+-- FetchFeatureType get primery keys SQL
+SELECT 
+    "COLUMN_NAME", "CONSTRAINT_TYPE" 
+  FROM INFORMATION_SCHEMA.table_constraints t_cons 
+    inner join INFORMATION_SCHEMA.key_column_usage c 
+      on c.constraint_catalog = t_cons.constraint_catalog and 
+        c.table_schema = t_cons.table_schema and 
+        c.table_name = t_cons.table_name and 
+        c.constraint_name = t_cons.constraint_name  
+  WHERE ((( (c.TABLE_NAME) LIKE ('test') ) AND 
+    ( (c.TABLE_SCHEMA) LIKE ('public') )) AND 
+    ( ("CONSTRAINT_TYPE") = ('PRIMARY KEY') )
+  );
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/count.sql
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/count.sql	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/count.sql	(revision 928)
@@ -0,0 +1,3 @@
+
+-- Count SQL
+SELECT COUNT(*) FROM "dbtest"."public"."test";
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/resultSetForSetProvider.sql
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/resultSetForSetProvider.sql	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/resultSetForSetProvider.sql	(revision 928)
@@ -0,0 +1,7 @@
+
+-- ResultSetForSetProvider SQL
+SELECT 
+    "ID", "Byte", "Bool1", "Long", "Timestamp", "Date", "Time", 
+    "Bool2", "String", "Bool3", "Double", "Bool4", "Float", "Bool5", "Decimal", 
+    ST_AsBinary("Geometry") 
+  FROM "dbtest"."public"."test" ORDER BY "ID" ASC;
\ No newline at end of file
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/fetchFeatureProviderByReference.sql
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/fetchFeatureProviderByReference.sql	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/fetchFeatureProviderByReference.sql	(revision 928)
@@ -0,0 +1,9 @@
+
+-- FetchFeatureProviderByReference SQL
+
+SELECT 
+    "ID", "Byte", "Bool1", "Long", "Timestamp", "Date", "Time", "Bool2", 
+    "String", "Bool3", "Double", "Bool4", "Float", "Bool5", "Decimal", 
+    ST_AsBinary("Geometry") 
+  FROM "dbtest"."public"."test" 
+  WHERE ( ("ID") = (?) ) LIMIT 1;
\ No newline at end of file
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/calculateEnvelope.sql
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/calculateEnvelope.sql	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/calculateEnvelope.sql	(revision 928)
@@ -0,0 +1,7 @@
+
+-- Count SQL
+
+SELECT 
+  ST_AsBinary(ST_Extent("Geometry")) 
+  FROM "dbtest"."public"."test" 
+  WHERE ( ("Geometry") IS NOT NULL );
\ No newline at end of file
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/createTable.sql
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/createTable.sql	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/createTable.sql	(revision 928)
@@ -0,0 +1,23 @@
+
+-- Se usa en TestCreateTable.
+-- Se corresponde con el fichero CSV "testCreateSource1.csv".
+
+CREATE TABLE "dbtest"."public"."test" (
+    "ID" INT NOT NULL PRIMARY KEY, 
+    "Byte" TINYINT DEFAULT NULL NULL, 
+    "Bool1" BOOLEAN DEFAULT NULL NULL, 
+    "Long" BIGINT DEFAULT NULL NULL, 
+    "Timestamp" TIMESTAMP DEFAULT NULL NULL, 
+    "Date" DATE DEFAULT NULL NULL, 
+    "Time" TIME DEFAULT NULL NULL, 
+    "Bool2" BOOLEAN DEFAULT NULL NULL, 
+    "String" VARCHAR(30) DEFAULT NULL NULL, 
+    "Bool3" BOOLEAN DEFAULT NULL NULL, 
+    "Double" DOUBLE PRECISION DEFAULT NULL NULL, 
+    "Bool4" BOOLEAN DEFAULT NULL NULL, 
+    "Float" REAL DEFAULT NULL NULL, 
+    "Bool5" BOOLEAN DEFAULT NULL NULL, 
+    "Decimal" NUMERIC(6,3) DEFAULT NULL NULL 
+);
+
+SELECT AddGeometryColumn('public' , 'test' , 'Geometry', 4326 , 'POINT' , 2, TRUE);
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/dropTable.sql
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/dropTable.sql	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/dropTable.sql	(revision 928)
@@ -0,0 +1,3 @@
+
+-- Count SQL
+DROP TABLE "dbtest"."public"."test";
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/testCreateSource1.csv
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/testCreateSource1.csv	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/testCreateSource1.csv	(revision 928)
@@ -0,0 +1,20 @@
+ID/Integer/set/pk=true;Byte/Byte;Bool1/Boolean;Long/Long;Timestamp/TimeStamp;Date/Date;Time/Time;Bool2/Boolean;String/String/set/size=30;Bool3/Boolean;Double/Double;Bool4/Boolean;Float/Float;Bool5/Boolean;Decimal/Decimal/set/precision=6/set/scale=3;Geometry/Geometry/set/geomtype=Point:2D/set/srs=EPSG:4326
+0;  ; ;    ;              ;        ;      ; ;      ; ;           ; ;      ;T;       ;
+1;10;T;1000;20191229121314;20191229;121314;T;Yo yo1;F;12345.54321;T;123.21;T;456.123;POINT (-3.8945156972987958 42.01053743584765)
+2;20;T;2000;20191129121314;20191129;131314;T;Yo yo2;F;12100.54321;T;100.21;T;456.123;POINT (-2.1079618220646115 41.983079082675474)
+3;30;T;3000;20191029121314;20191029;141314;T;Yo yo3;F;12101.54321;T;101.21;T;456.123;POINT (-2.57249737803327 41.35372113353277)
+4;40;T;4000;20190929121314;20190929;151314;T;Yo yo4;F;12102.54321;T;102.21;T;456.123;POINT (-4.061822048036304 41.35877680235475)
+5;50;T;5000;20190829121314;20190829;161314;T;Yo yo5;F;12103.54321;T;103.21;T;456.123;POINT (-3.974317066986988 40.78701209315094)
+6;60;T;6000;20190729121314;20190729;171314;T;Yo yo6;F;12104.54321;T;104.21;T;456.123;POINT (-2.510509736717547 40.69847453392384)
+7;70;T;7000;20190629121314;20190629;181314;T;Yo yo7;F;12105.54321;T;105.21;T;456.123;POINT (-0.5317736981843011 40.66396082637622)
+8;80;T;8000;20190529121314;20190529;191314;T;Yo yo8;F;12106.54321;T;106.21;T;456.123;POINT (-0.3626917259170671 41.13652386601604)
+9;90;T;9000;20190429121314;20190429;201314;T;Yo yo9;F;12107.54321;T;107.21;T;456.123;POINT (-1.2461823078608523 41.84950010180092)
+10;;T;1001;20191229121314;20191229;121314;T;Yo yo1;F;12345.54321;T;123.21;T;456.123;POINT (-1.2145405488596532 41.22158511004416)
+11;22; ;2002;20191129121314;20191129;131314;T;Yo yo2;F;12100.54321;T;100.21;T;456.123;POINT (-0.7699089544899235 41.630581204431756)
+12;33;T; ;20190929121314;20191029;141314;T;Yo yo3;F;12101.54321;T;101.21;T;456.123;POINT (0.4821915816701051 41.75970939133133)
+13;41;T;4001; ;20190929;151314;T;Yo yo4;F;12102.54321;T;102.21;T;456.123;POINT (0.7912661147227479 41.919324620992036)
+14;52;T;5002;20190829121314; ;161314;T;Yo yo5;F;12103.54321;T;103.21;T;456.123;POINT (1.052534629531243 41.493736996249545)
+15;63;T;6003;20190729121314;20190729; ;T;Yo yo6;F;12104.54321;T;104.21;T;456.123;POINT (0.8097002367335026 41.0899480235613)
+16;74;T;7004;20190629121314;20190629;181314;T; ;F;12105.54321;T;105.21;T;456.123;POINT (-0.4883960310112362 41.17597288081971)
+17;85;T;8005;20190529121314;20190529;191314;T;Yo yo8;F; ;T;106.21;T;456.123;POINT (-0.6439030698437881 40.89530766155764)
+18;96;T;9006;20190429121314;20190429;201314;T;Yo yo9;F;12107.54321;T; ;T; ;POINT (-1.3061826868199504 40.72372835570524)
\ No newline at end of file
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/tableIsEmpty.sql
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/tableIsEmpty.sql	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/tableIsEmpty.sql	(revision 928)
@@ -0,0 +1,3 @@
+
+-- Table is empty
+SELECT * FROM "dbtest"."public"."test" LIMIT 1;
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/performChanges.sql
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/performChanges.sql	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/resources/org/gvsig/postgresql/dal/performChanges.sql	(revision 928)
@@ -0,0 +1,53 @@
+
+-- Insert SQL
+INSERT INTO "dbtest"."public"."test" ( 
+      "ID", "Byte", "Bool1", "Long", "Timestamp", "Date", "Time", 
+      "Bool2", "String", "Bool3", "Double", "Bool4", "Float", "Bool5", 
+      "Decimal", "Geometry" 
+  ) VALUES ( 
+    ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ST_GeomFromWKB((?), (?)) 
+  );
+
+-- Delete SQL
+DELETE FROM "dbtest"."public"."test" WHERE ( ("ID") = (?) );
+
+-- Update SQL
+UPDATE "dbtest"."public"."test" 
+  SET 
+    "Byte" = ?, 
+    "Bool1" = ?, 
+    "Long" = ?, 
+    "Timestamp" = ?, 
+    "Date" = ?, 
+    "Time" = ?, 
+    "Bool2" = ?, 
+    "String" = ?, 
+    "Bool3" = ?, 
+    "Double" = ?, 
+    "Bool4" = ?, 
+    "Float" = ?, 
+    "Bool5" = ?, 
+    "Decimal" = ?, 
+    "Geometry" = ST_GeomFromWKB((?), (?)) 
+  WHERE 
+    ( ("ID") = (?) );
+
+
+-- Update Table SQL
+ALTER TABLE "dbtest"."public"."test" ADD COLUMN "Byte" TINYINT DEFAULT NULL NULL;
+ALTER TABLE "dbtest"."public"."test" ADD COLUMN "Bool1" BOOLEAN DEFAULT NULL NULL;
+ALTER TABLE "dbtest"."public"."test" ADD COLUMN "Long" BIGINT DEFAULT NULL NULL;
+ALTER TABLE "dbtest"."public"."test" ADD COLUMN "Timestamp" TIMESTAMP DEFAULT NULL NULL;
+ALTER TABLE "dbtest"."public"."test" ADD COLUMN "Date" DATE DEFAULT NULL NULL;
+ALTER TABLE "dbtest"."public"."test" ADD COLUMN "Time" TIME DEFAULT NULL NULL;
+ALTER TABLE "dbtest"."public"."test" ADD COLUMN "Bool2" BOOLEAN DEFAULT NULL NULL;
+ALTER TABLE "dbtest"."public"."test" ADD COLUMN "String" VARCHAR(30) DEFAULT NULL NULL;
+ALTER TABLE "dbtest"."public"."test" ADD COLUMN "Bool3" BOOLEAN DEFAULT NULL NULL;
+ALTER TABLE "dbtest"."public"."test" ADD COLUMN "Double" DOUBLE PRECISION DEFAULT NULL NULL;
+ALTER TABLE "dbtest"."public"."test" ADD COLUMN "Bool4" BOOLEAN DEFAULT NULL NULL;
+ALTER TABLE "dbtest"."public"."test" ADD COLUMN "Float" REAL DEFAULT NULL NULL;
+ALTER TABLE "dbtest"."public"."test" ADD COLUMN "Bool5" BOOLEAN DEFAULT NULL NULL;
+ALTER TABLE "dbtest"."public"."test" ADD COLUMN "Decimal" NUMERIC(6,3) DEFAULT NULL NULL;
+ALTER TABLE "dbtest"."public"."test" ADD COLUMN "Geometry" TEXT DEFAULT NULL NULL;
+
+-- FIXME: El ALTER TABLE de una columna geometria no funciona
\ No newline at end of file
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/PostgreSQLBuilderTest.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/PostgreSQLBuilderTest.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/PostgreSQLBuilderTest.java	(revision 928)
@@ -0,0 +1,556 @@
+package org.gvsig.postgresql.dal;
+
+import junit.framework.TestCase;
+import org.apache.commons.lang3.ArrayUtils;
+import org.cresques.cts.IProjection;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
+import org.gvsig.fmap.crs.CRSFactory;
+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.dal.store.jdbc2.OperationsFactory.TableReference;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.OperationsFactoryBase;
+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.library.impl.DefaultLibrariesInitializer;
+
+public class PostgreSQLBuilderTest extends TestCase {
+    
+    public PostgreSQLBuilderTest(String testName) {
+        super(testName);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        new DefaultLibrariesInitializer().fullInitialize();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    private SQLBuilder createSQLBuilder() {
+        return new PostgreSQLBuilder(new PostgreSQLHelper(new FakePostgreSQLConnectionParameters()));
+    }
+    
+    public void testCalulateEnvelopeOfColumn() throws Exception {
+        
+        TableReference table = new OperationsFactoryBase.DefaultTableReference("master","dbo","test1", null);
+        String columnName = "the_geom";
+        
+        SQLBuilder sqlbuilder = createSQLBuilder();
+        GeometryExpressionBuilder expbuilder = sqlbuilder.expression();
+        
+        sqlbuilder.select().column().value(
+            expbuilder.as_geometry(
+                expbuilder.ST_ExtentAggregate(
+                        expbuilder.column(columnName)
+                )
+            )
+        );
+        //sqlbuilder.select().group_by(expbuilder.column(columnName));
+        sqlbuilder.select().from().table()
+                .database(table.getDatabase())
+                .schema(table.getSchema())
+                .name(table.getTable());
+        sqlbuilder.select().from().subquery(table.getSubquery());
+
+        sqlbuilder.select().where().and(        
+            expbuilder.not_is_null(expbuilder.column(columnName))
+        );
+        
+        System.out.println("# Test:: testCalulateEnvelopeOfColumn");
+        System.out.println("# SQL:: " + sqlbuilder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
+        assertEquals(
+                "SELECT ST_AsBinary(ST_Extent(\"the_geom\")) FROM \"master\".\"dbo\".\"test1\" WHERE ( (\"the_geom\") IS NOT NULL )",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[the_geom]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+ 
+    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 sqlbuilder = createSQLBuilder();
+        GeometryExpressionBuilder expbuilder = sqlbuilder.expression();
+        
+        sqlbuilder.select().column().value(
+            expbuilder.as_geometry(
+              expbuilder.ST_ExtentAggregate(
+                expbuilder.column("the_geom")
+              )
+            )
+        ).as("envelope");
+        sqlbuilder.select().from().table().database("master").schema("dbo").name("test1");
+        sqlbuilder.select().where().set(
+            expbuilder.ST_Intersects(
+                expbuilder.ST_Envelope(
+                    expbuilder.column("the_geom")
+                ),
+                expbuilder.geometry(limit, proj)
+            )
+        );
+        sqlbuilder.select().where().and(
+                expbuilder.custom("x = 27")
+        );
+        
+        System.out.println("# Test:: testCalulateEnvelope");
+        System.out.println("# SQL:: " + sqlbuilder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
+        assertEquals(
+                "SELECT ST_AsBinary(ST_Extent(\"the_geom\")) AS \"envelope\" FROM \"master\".\"dbo\".\"test1\" WHERE (ST_Intersects((ST_Envelope(\"the_geom\")), (ST_GeomFromWKB(('\\x000000000300000001000000050000000000000000000000000000000000000000000000004059000000000000405900000000000040590000000000004059000000000000000000000000000000000000000000000000000000000000'::bytea), (4326)))) AND x = 27)",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[the_geom]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+
+    public void testCount() throws Exception {
+        SQLBuilder sqlbuilder = createSQLBuilder();
+        ExpressionBuilder expbuilder = sqlbuilder.expression();
+        
+        sqlbuilder.select().column().value(sqlbuilder.count().all());
+        sqlbuilder.select().from().table().database("master").schema("dbo").name("test1");
+        sqlbuilder.select().from().subquery(null);
+        sqlbuilder.select().where().set( expbuilder.custom("pp = 200"));
+
+        System.out.println("# Test:: testCount");
+        System.out.println("# SQL:: " + sqlbuilder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
+
+        //# Test:: testCount
+        //# SQL:: SELECT COUNT(*) FROM "test1" WHERE pp = 200
+        //# Variables:: []
+        //# Parametros:: []
+
+        assertEquals(
+                "SELECT COUNT(*) FROM \"master\".\"dbo\".\"test1\" WHERE pp = 200",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+    
+    public void testCreateTable() throws Exception {
+        SQLBuilder sqlbuilder = createSQLBuilder();
+        ExpressionBuilder expbuilder = sqlbuilder.expression();
+
+        sqlbuilder.create_table().table().database("master").schema("dbo").name("test1");
+        sqlbuilder.create_table().add_column(
+                "name",
+                DataTypes.STRING,
+                45,
+                0,
+                0,
+                false,
+                false,
+                true,
+                false,
+                null
+        );
+        sqlbuilder.create_table().add_column(
+                "id",
+                DataTypes.INT,
+                0,
+                0,
+                0,
+                true,
+                false,
+                false,
+                true,
+                0
+        );
+        sqlbuilder.create_table().add_column(
+                "geom",
+                DataTypes.GEOMETRY,
+                0,
+                0,
+                0,
+                false,
+                false,
+                true,
+                false,
+                null
+        );
+
+        
+        // CREATE TABLE "test1" ("name" VARCHAR(45) DEFAULT NULL, "id" INTEGER PRIMARY KEY AUTO_INCREMENT DEFAULT '0' NOT NULL, "geom" GEOMETRY ); ALTER TABLE "test1" ADD CONSTRAINT IF NOT EXISTS "constraint_test1_geom_dim" CHECK ST_CoordDim("geom") = 2
+        System.out.println("# Test:: testCreateTable");
+        System.out.println("# SQL:: " + sqlbuilder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
+        assertEquals(
+                "CREATE TABLE \"master\".\"dbo\".\"test1\" (\"name\" VARCHAR(45) DEFAULT NULL NULL, \"id\"  SERIAL PRIMARY KEY ); SELECT AddGeometryColumn('dbo' , 'test1' , 'geom', null , 'GEOMETRY' , 2, TRUE)",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+
+    public void testDropTable() throws Exception {
+        SQLBuilder sqlbuilder = createSQLBuilder();
+        ExpressionBuilder expbuilder = sqlbuilder.expression();
+        
+        sqlbuilder.drop_table().table().database("master").schema("dbo").name("test1");
+
+        // DROP TABLE "test1"
+        
+        System.out.println("# Test:: testDropTable");
+        System.out.println("# SQL:: " + sqlbuilder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
+        assertEquals(
+                "DROP TABLE \"master\".\"dbo\".\"test1\"",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+    
+    public void testFetchFeatureProviderByReference() throws Exception {
+        SQLBuilder sqlbuilder = new SQLBuilderBase();
+        ExpressionBuilder expbuilder = sqlbuilder.expression();
+        
+        String value = "yoyo";
+        sqlbuilder.select().column().name("name");
+        sqlbuilder.select().column().name("id");
+        sqlbuilder.select().column().name("geom").as_geometry();
+        sqlbuilder.select().from().table().database("master").schema("dbo").name("test1");
+        sqlbuilder.select().where().set(
+            expbuilder.eq(
+                expbuilder.column("name"),
+                expbuilder.parameter(value).as_constant()
+            )
+        );
+        sqlbuilder.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:: " + sqlbuilder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
+        assertEquals(
+                "SELECT \"name\", \"id\", ST_AsBinary(\"geom\") FROM \"master\".\"dbo\".\"test1\" WHERE ( (\"name\") = (?) ) LIMIT 1",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[geom, id, name]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "['yoyo']",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+    
+    public void testFetchFeatureType() throws Exception {
+        SQLBuilder sqlbuilder = createSQLBuilder();
+        ExpressionBuilder expbuilder = sqlbuilder.expression();
+
+        sqlbuilder.select().column().all();
+        sqlbuilder.select().from().table().database("master").schema("dbo").name("test1");
+        sqlbuilder.select().limit(1);
+
+        System.out.println("# Test:: testFetchFeatureType");
+        System.out.println("# SQL:: " + sqlbuilder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
+        
+        //# Test:: testFetchFeatureType
+        //# SQL:: SELECT * FROM "test1" LIMIT 1
+        //# Variables:: []
+        //# Parametros:: []        
+        
+        assertEquals(
+                "SELECT * FROM \"master\".\"dbo\".\"test1\" LIMIT 1",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+        
+    public void testPerformDeletes() throws Exception {
+        SQLBuilder sqlbuilder = createSQLBuilder();
+        ExpressionBuilder expbuilder = sqlbuilder.expression();
+
+        sqlbuilder.delete().table().database("master").schema("dbo").name("test1");
+        sqlbuilder.delete().where().and(
+            expbuilder.eq( 
+                expbuilder.column("id1"),
+                expbuilder.parameter("id1").as_variable()
+            )
+        );
+        sqlbuilder.delete().where().and(
+            expbuilder.eq( 
+                expbuilder.column("id2"),
+                expbuilder.parameter("id2").as_variable()
+            )
+        );
+
+        // DELETE FROM "test1" WHERE ( ("id1") = (?) ) AND ( ("id2") = (?) )
+
+        System.out.println("# Test:: testPerformDeletes");
+        System.out.println("# SQL:: " + sqlbuilder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
+        assertEquals(
+                "DELETE FROM \"master\".\"dbo\".\"test1\" WHERE (( (\"id1\") = (?) ) AND ( (\"id2\") = (?) ))",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[id1, id2]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[\"id1\", \"id2\"]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+
+    public void testPerformInserts1() throws Exception {
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+
+        SQLBuilder sqlbuilder = createSQLBuilder();
+        GeometryExpressionBuilder expbuilder = sqlbuilder.expression();
+
+        sqlbuilder.insert().table().database("master").schema("dbo").name("test1");
+        sqlbuilder.insert().column().name("id").with_value(expbuilder.parameter("id"));
+        sqlbuilder.insert().column().name("name").with_value(expbuilder.parameter("name"));
+        sqlbuilder.insert().column().name("geom").with_value(expbuilder.parameter("geom").as_geometry_variable().srs(proj));
+        
+        System.out.println("# Test:: testPerformInserts1");
+        System.out.println("# SQL:: " + sqlbuilder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
+        assertEquals(
+                "INSERT INTO \"master\".\"dbo\".\"test1\" ( \"id\", \"name\", \"geom\" ) VALUES ( ?, ?, ST_GeomFromWKB((?), (4326)) )",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[geom, id, name]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[\"id\", \"name\", \"geom\"]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+
+    public void testPerformInserts2() throws Exception {
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+
+        SQLBuilder sqlbuilder = createSQLBuilder();
+        GeometryExpressionBuilder expbuilder = sqlbuilder.expression();
+
+        sqlbuilder.insert().table().database("master").schema("dbo").name("test1");
+        sqlbuilder.insert().column().name("id").with_value(expbuilder.parameter("id"));
+        sqlbuilder.insert().column().name("name").with_value(expbuilder.parameter("name"));
+        sqlbuilder.insert().column().name("geom").with_value(expbuilder.parameter("geom").as_geometry_variable().srs(proj));
+        
+        System.out.println("# Test:: testPerformInserts2");
+        System.out.println("# SQL:: " + sqlbuilder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
+        assertEquals(
+                "INSERT INTO \"master\".\"dbo\".\"test1\" ( \"id\", \"name\", \"geom\" ) VALUES ( ?, ?, ST_GeomFromWKB((?), (4326)) )",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[geom, id, name]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[\"id\", \"name\", \"geom\"]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+
+    public void testPerformUpdates1() throws Exception {
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+
+        SQLBuilder sqlbuilder = createSQLBuilder();
+        GeometryExpressionBuilder expbuilder = sqlbuilder.expression();
+
+        sqlbuilder.update().table().database("master").schema("dbo").name("test1");
+        sqlbuilder.update().where().and(
+            expbuilder.eq(
+                expbuilder.column("id"), 
+                expbuilder.parameter("id").as_variable()
+            )
+        );
+        sqlbuilder.update().column().name("name").with_value(expbuilder.parameter("name"));
+        sqlbuilder.update().column().name("geom").with_value(
+                expbuilder.parameter("geom").as_geometry_variable().srs(proj) 
+        );
+
+        System.out.println("# Test:: testPerformUpdates");
+        System.out.println("# SQL:: " + sqlbuilder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
+        assertEquals(
+                "UPDATE \"master\".\"dbo\".\"test1\" SET \"name\" = ?, \"geom\" = ST_GeomFromWKB((?), (4326)) WHERE ( (\"id\") = (?) )",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[geom, id, name]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[\"name\", \"geom\", \"id\"]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+
+    public void testPerformUpdates2() throws Exception {
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+
+        SQLBuilder sqlbuilder = createSQLBuilder();
+        GeometryExpressionBuilder expbuilder = sqlbuilder.expression();
+
+        sqlbuilder.update().table().database("master").schema("dbo").name("test1");
+        sqlbuilder.update().where().and(
+            expbuilder.eq(
+                expbuilder.column("id"), 
+                expbuilder.parameter("id").as_variable()
+            )
+        );
+        sqlbuilder.update().column().name("name").with_value(expbuilder.parameter("name"));
+        sqlbuilder.update().column().name("geom").with_value(
+                expbuilder.parameter("geom").as_geometry_variable()
+                        .srs(expbuilder.parameter().value(proj)) 
+        );
+
+        System.out.println("# Test:: testPerformUpdates");
+        System.out.println("# SQL:: " + sqlbuilder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
+        assertEquals(
+                "UPDATE \"master\".\"dbo\".\"test1\" SET \"name\" = ?, \"geom\" = ST_GeomFromWKB((?), (?)) WHERE ( (\"id\") = (?) )",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[geom, id, name]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[\"name\", \"geom\", 4326, \"id\"]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+
+    public void testGrant1() throws Exception {
+
+        SQLBuilder sqlbuilder = createSQLBuilder();
+        ExpressionBuilder expbuilder = sqlbuilder.expression();
+
+        sqlbuilder.grant().table().database("master").schema("dbo").name("test1");
+        sqlbuilder.grant().role("prueba").select().insert().update();
+        sqlbuilder.grant().role("gis").all();
+                
+        
+        System.out.println("# Test:: testGrant1");
+        System.out.println("# SQL:: " + sqlbuilder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
+        assertEquals(
+                "",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+
+    public void testGrant2() throws Exception {
+
+        SQLBuilder sqlbuilder = new SQLBuilderBase();
+        ExpressionBuilder expbuilder = sqlbuilder.expression();
+
+        sqlbuilder.grant().table().database("master").schema("dbo").name("test1");
+        sqlbuilder.grant().role("prueba").privilege(Privilege.SELECT)
+                .privilege(Privilege.INSERT)
+                .privilege(Privilege.UPDATE);
+        sqlbuilder.grant().role("gis").privilege(Privilege.ALL);
+                
+        
+        System.out.println("# Test:: testGrant2");
+        System.out.println("# SQL:: " + sqlbuilder.toString());
+        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
+        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
+        assertEquals(
+                "",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+
+
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/TestUtils.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/TestUtils.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/TestUtils.java	(revision 928)
@@ -0,0 +1,88 @@
+package org.gvsig.postgresql.dal;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.fmap.dal.DALLocator;
+import org.gvsig.fmap.dal.DataManager;
+import org.gvsig.fmap.dal.DataStore;
+import org.gvsig.fmap.dal.feature.Feature;
+import org.gvsig.fmap.dal.feature.FeatureStore;
+import org.gvsig.fmap.dal.feature.impl.DefaultFeature;
+import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.spi.FakeConnectionParameters;
+import org.gvsig.fmap.dal.store.jdbc2.spi.FakeConnectionProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestUtils  {
+    
+    public static final Logger LOGGER = LoggerFactory.getLogger(TestUtils.class);
+
+    public static final String PROVIDER_NAME = PostgreSQLLibrary.NAME;
+
+    public static File getTargetFolder() throws Exception {
+        URL url = TestUtils.class.getResource("/");
+        File x = new File(url.toURI());
+        File target = x.getParentFile();
+        return target;
+    }
+    
+    public static File getResource(String name) throws Exception {
+        File x = new File(getTargetFolder(), name);
+        return x;
+    }
+    
+    public static File getResourceAsFile(String pathname) throws Exception {
+        URL url = TestUtils.class.getResource(pathname);
+        File x = new File(url.toURI());
+        return x;
+    }
+
+    public static FeatureStore openSourceStore1() throws Exception {
+        DataManager dataManager = DALLocator.getDataManager();
+        File f = getResourceAsFile("/org/gvsig/postgresql/dal/testCreateSource1.csv");
+        FeatureStore store = (FeatureStore) dataManager.openStore(
+                DataStore.CSV_PROVIDER_NAME, 
+                "file=",f,
+                "automaticTypesDetection=", false,
+                "locale=","en"
+        );
+        return store;
+    }
+ 
+
+    public static List<String> getSQLs(String name) throws Exception {
+      File f = getResourceAsFile("/org/gvsig/postgresql/dal/"+name);
+      List<String> SQLs = new ArrayList<>();
+      List<String> lines = FileUtils.readLines(f);
+      StringBuilder sb = new StringBuilder();
+      for (String line : lines) {
+        line = StringUtils.stripStart(line, null);
+        if( line.startsWith("--") ) {
+          continue;
+        }
+        if( line.endsWith(";") ) {
+          sb.append(line.substring(0, line.length()-1));
+          SQLs.add(sb.toString());
+          sb.setLength(0);
+        } else {
+          sb.append(line);
+        }
+      }
+      return SQLs;
+    }
+    
+    public static JDBCHelper getJDBCHelper() {
+      JDBCHelper helper = new PostgreSQLHelper(new FakePostgreSQLConnectionParameters(), new FakeConnectionProvider());
+      return helper;
+    }
+    
+    public static FeatureProvider getFeatureProvider(Feature feature) {
+      return ((DefaultFeature)feature).getData();
+    }
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestAppend.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestAppend.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestAppend.java	(revision 928)
@@ -0,0 +1,98 @@
+package org.gvsig.postgresql.dal.operations.sql;
+
+import java.util.ArrayList;
+import java.util.List;
+import junit.framework.TestCase;
+import org.gvsig.fmap.dal.DataTypes;
+import org.gvsig.fmap.dal.feature.Feature;
+import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
+import org.gvsig.fmap.dal.feature.FeatureStore;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.AppendOperation;
+import org.gvsig.postgresql.dal.TestUtils;
+import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestAppend extends TestCase {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(TestAppend.class);
+
+  public TestAppend(String testName) {
+    super(testName);
+  }
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    new DefaultLibrariesInitializer().fullInitialize();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  // TODO add test methods here. The name must begin with 'test'. For example:
+  // public void testHello() {}
+  
+  public void testAppend() throws Exception {
+    JDBCHelper helper = TestUtils.getJDBCHelper();
+    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
+    OperationsFactory operations = helper.getOperations();
+
+    List<String> expectedSQLs = TestUtils.getSQLs("append.sql");
+    
+    FeatureStore sourceStore = TestUtils.openSourceStore1();
+
+    TableReference table = operations.createTableReference(
+            "dbtest", 
+            sqlbuilder.default_schema(), 
+            "test", 
+            null
+    );
+    FeatureType featureType = sourceStore.getDefaultFeatureType();
+    AppendOperation append = operations.createAppend(
+            table,
+            featureType
+    );
+    append.begin();
+    List<String> SQLs = new ArrayList<>();
+    SQLs.addAll(append.getPreviousSQLs());
+    SQLs.add( append.getSQL());
+    SQLs.addAll(append.getPostSQLs());
+    assertEquals("Append num SQLs", expectedSQLs.size(), SQLs.size());
+    for (int i = 0; i < expectedSQLs.size(); i++) {
+      assertEquals("Append SQL "+i, expectedSQLs.get(i), SQLs.get(i));
+    }
+    
+    for (Feature sourceFeature : sourceStore.getFeatureSet()) {
+      List<Object> parametersSQL = append.getSQLParameters(TestUtils.getFeatureProvider(sourceFeature));
+      List<Object> expectedParameters = this.getExpectedparameters(sourceFeature);
+      assertEquals("Append num. parameters", parametersSQL.size(), expectedParameters.size());
+      for (int i = 0; i < expectedParameters.size(); i++) {
+        assertEquals("Append parameter "+i, expectedParameters.get(i), parametersSQL.get(i));
+      }
+    }
+    append.end();
+  }
+
+  private List<Object> getExpectedparameters(Feature sourceFeature) {
+    FeatureType ft = sourceFeature.getType();
+    List<Object> values = new ArrayList<>();
+    for (FeatureAttributeDescriptor attr : ft) {
+      Object v = sourceFeature.get(attr.getIndex());
+      values.add(v);
+      if( attr.getType()==DataTypes.GEOMETRY ) {
+        String srs = attr.getSRS().getAbrev();
+        values.add(Integer.parseInt(srs.split(":")[1]));
+      }
+    }
+    return values;
+  }
+
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestFetchFeatureType.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestFetchFeatureType.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestFetchFeatureType.java	(revision 928)
@@ -0,0 +1,72 @@
+package org.gvsig.postgresql.dal.operations.sql;
+
+import java.util.Collections;
+import java.util.List;
+import junit.framework.TestCase;
+import org.gvsig.fmap.dal.feature.FeatureStore;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.FetchFeatureTypeOperation;
+import org.gvsig.postgresql.dal.TestUtils;
+import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestFetchFeatureType extends TestCase {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(TestFetchFeatureType.class);
+
+  public TestFetchFeatureType(String testName) {
+    super(testName);
+  }
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    new DefaultLibrariesInitializer().fullInitialize();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  // TODO add test methods here. The name must begin with 'test'. For example:
+  // public void testHello() {}
+  
+  public void testFetchFeatureType() throws Exception {
+    JDBCHelper helper = TestUtils.getJDBCHelper();
+    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
+    OperationsFactory operations = helper.getOperations();
+
+    List<String> expectedSQLs = TestUtils.getSQLs("fetchFeatureType.sql");
+    
+    FeatureStore sourceStore = TestUtils.openSourceStore1();
+
+    TableReference table = operations.createTableReference(
+            "dbtest", 
+            sqlbuilder.default_schema(), 
+            "test", 
+            null
+    );
+    FeatureType featureType = sourceStore.getDefaultFeatureType();
+    FetchFeatureTypeOperation fetchFeatureType = operations.createFetchFeatureType(
+            featureType.getEditable(),
+            table,
+            Collections.EMPTY_LIST,
+            null, // "Geometry" 
+            featureType.getDefaultSRS()
+    );
+    
+    
+    String retrieveFirstRowOfTableSQL = fetchFeatureType.getSQLToRetrieveFirstRowOfTable();
+    String retrievePrimaryKeysFromInformationSchemaSQL = fetchFeatureType.getSQLToRetrievePrimaryKeysFromInformationSchema();
+
+    assertEquals("FetchFeatureType first row SQL", expectedSQLs.get(0), retrieveFirstRowOfTableSQL);
+    assertEquals("FetchFeatureType get primery keys SQL", expectedSQLs.get(1), retrievePrimaryKeysFromInformationSchemaSQL);
+  }
+
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestCount.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestCount.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestCount.java	(revision 928)
@@ -0,0 +1,65 @@
+package org.gvsig.postgresql.dal.operations.sql;
+
+import java.util.List;
+import junit.framework.TestCase;
+import org.gvsig.fmap.dal.feature.FeatureStore;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CountOperation;
+import org.gvsig.postgresql.dal.TestUtils;
+import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestCount extends TestCase {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(TestCount.class);
+
+  public TestCount(String testName) {
+    super(testName);
+  }
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    new DefaultLibrariesInitializer().fullInitialize();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  // TODO add test methods here. The name must begin with 'test'. For example:
+  // public void testHello() {}
+  
+  public void testCount() throws Exception {
+    JDBCHelper helper = TestUtils.getJDBCHelper();
+    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
+    OperationsFactory operations = helper.getOperations();
+
+    List<String> expectedSQLs = TestUtils.getSQLs("count.sql");
+    
+    FeatureStore sourceStore = TestUtils.openSourceStore1();
+
+    TableReference table = operations.createTableReference(
+            "dbtest", 
+            sqlbuilder.default_schema(), 
+            "test", 
+            null
+    );
+    FeatureType featureType = sourceStore.getDefaultFeatureType();
+    CountOperation count = operations.createCount(
+            featureType,
+            table, 
+            null, null
+    );
+    
+    String sql = count.getSQL();
+    assertEquals("Count SQL", expectedSQLs.get(0), sql);
+  }
+
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestResultSetForSetProvider.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestResultSetForSetProvider.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestResultSetForSetProvider.java	(revision 928)
@@ -0,0 +1,70 @@
+package org.gvsig.postgresql.dal.operations.sql;
+
+import java.util.List;
+import junit.framework.TestCase;
+import org.gvsig.fmap.dal.feature.FeatureStore;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation;
+import org.gvsig.postgresql.dal.TestUtils;
+import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestResultSetForSetProvider extends TestCase {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(TestResultSetForSetProvider.class);
+
+  public TestResultSetForSetProvider(String testName) {
+    super(testName);
+  }
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    new DefaultLibrariesInitializer().fullInitialize();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  // TODO add test methods here. The name must begin with 'test'. For example:
+  // public void testHello() {}
+  
+  public void testResultSetForSetProvider() throws Exception {
+    JDBCHelper helper = TestUtils.getJDBCHelper();
+    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
+    OperationsFactory operations = helper.getOperations();
+
+    List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql");
+    
+    FeatureStore sourceStore = TestUtils.openSourceStore1();
+
+    TableReference table = operations.createTableReference(
+            "dbtest", 
+            sqlbuilder.default_schema(), 
+            "test", 
+            null
+    );
+    FeatureType featureType = sourceStore.getDefaultFeatureType();
+    ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider(
+            table,
+            null,
+            null,
+            null,
+            featureType,
+            featureType,
+            0,
+            0, 
+            0
+    );
+    String sql = resultSetForSetProvider.getSQL();
+    assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(0), sql);
+  }
+
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestFetchFeatureProviderByReference.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestFetchFeatureProviderByReference.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestFetchFeatureProviderByReference.java	(revision 928)
@@ -0,0 +1,71 @@
+package org.gvsig.postgresql.dal.operations.sql;
+
+import java.util.List;
+import junit.framework.TestCase;
+import org.gvsig.fmap.dal.feature.Feature;
+import org.gvsig.fmap.dal.feature.FeatureReference;
+import org.gvsig.fmap.dal.feature.FeatureStore;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import org.gvsig.fmap.dal.feature.impl.featurereference.FeatureReferenceFactory;
+import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.FetchFeatureProviderByReferenceOperation;
+import org.gvsig.postgresql.dal.TestUtils;
+import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestFetchFeatureProviderByReference extends TestCase {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(TestFetchFeatureProviderByReference.class);
+
+  public TestFetchFeatureProviderByReference(String testName) {
+    super(testName);
+  }
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    new DefaultLibrariesInitializer().fullInitialize();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  // TODO add test methods here. The name must begin with 'test'. For example:
+  // public void testHello() {}
+  
+  public void testFetchFeatureProviderByReference() throws Exception {
+    JDBCHelper helper = TestUtils.getJDBCHelper();
+    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
+    OperationsFactory operations = helper.getOperations();
+
+    List<String> expectedSQLs = TestUtils.getSQLs("fetchFeatureProviderByReference.sql");
+    
+    FeatureStore sourceStore = TestUtils.openSourceStore1();
+    TableReference table = operations.createTableReference(
+            "dbtest", 
+            sqlbuilder.default_schema(), 
+            "test", 
+            null
+    );
+    FeatureType featureType = sourceStore.getDefaultFeatureType();
+    Feature feature = sourceStore.getFeatures().get(1);    
+    FeatureReference reference = FeatureReferenceFactory.createReferencePKFromFeature(feature);
+    
+    FetchFeatureProviderByReferenceOperation fetchFeatureProviderByReference = operations.createFetchFeatureProviderByReference(
+            (FeatureReferenceProviderServices) reference,
+            featureType, 
+            table
+    );
+    
+    String sql = fetchFeatureProviderByReference.getSQL();
+    assertEquals("FetchFeatureProviderByReference SQL", expectedSQLs.get(0), sql);
+  }
+
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestCalculateEnvelope.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestCalculateEnvelope.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestCalculateEnvelope.java	(revision 928)
@@ -0,0 +1,68 @@
+package org.gvsig.postgresql.dal.operations.sql;
+
+import java.util.List;
+import junit.framework.TestCase;
+import org.gvsig.fmap.dal.feature.FeatureStore;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CalculateEnvelopeOfColumnOperation;
+import org.gvsig.postgresql.dal.TestUtils;
+import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestCalculateEnvelope extends TestCase {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(TestCalculateEnvelope.class);
+
+  public TestCalculateEnvelope(String testName) {
+    super(testName);
+  }
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    new DefaultLibrariesInitializer().fullInitialize();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  // TODO add test methods here. The name must begin with 'test'. For example:
+  // public void testHello() {}
+  
+  public void testCalculateEnvelope() throws Exception {
+    JDBCHelper helper = TestUtils.getJDBCHelper();
+    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
+    OperationsFactory operations = helper.getOperations();
+
+    List<String> expectedSQLs = TestUtils.getSQLs("calculateEnvelope.sql");
+    
+    FeatureStore sourceStore = TestUtils.openSourceStore1();
+
+    TableReference table = operations.createTableReference(
+            "dbtest", 
+            sqlbuilder.default_schema(), 
+            "test", 
+            null
+    );
+    FeatureType featureType = sourceStore.getDefaultFeatureType();
+    CalculateEnvelopeOfColumnOperation calculateEnvelope = operations.createCalculateEnvelopeOfColumn(
+            featureType,
+            table, 
+            "Geometry",
+            null,
+            null, 
+            featureType.getDefaultSRS()
+    );
+    
+    String sql = calculateEnvelope.getSQL();
+    assertEquals("CalculateEnvelope SQL", expectedSQLs.get(0), sql);
+  }
+
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestCreateTable.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestCreateTable.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestCreateTable.java	(revision 928)
@@ -0,0 +1,69 @@
+package org.gvsig.postgresql.dal.operations.sql;
+
+import java.util.List;
+import junit.framework.TestCase;
+import org.gvsig.fmap.dal.feature.FeatureStore;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CreateTableOperation;
+import org.gvsig.postgresql.dal.TestUtils;
+import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestCreateTable extends TestCase {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(TestCreateTable.class);
+
+  public TestCreateTable(String testName) {
+    super(testName);
+  }
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    new DefaultLibrariesInitializer().fullInitialize();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  // TODO add test methods here. The name must begin with 'test'. For example:
+  // public void testHello() {}
+  
+  public void testCreateTable() throws Exception {
+    JDBCHelper helper = TestUtils.getJDBCHelper();
+    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
+    OperationsFactory operations = helper.getOperations();
+
+    List<String> expectedSQLs = TestUtils.getSQLs("createTable.sql");
+    
+    FeatureStore sourceStore = TestUtils.openSourceStore1();
+
+    TableReference table = operations.createTableReference(
+            "dbtest", 
+            sqlbuilder.default_schema(), 
+            "test", 
+            null
+    );
+    FeatureType featureType = sourceStore.getDefaultFeatureType();
+    CreateTableOperation createTable = operations.createTable(
+            table,
+            featureType,
+            null,
+            null
+    );
+    List<String> SQLs = createTable.getSQLs();
+    assertEquals("CreateTable num. SQLs", expectedSQLs.size(), SQLs.size());
+    for (int i = 0; i < expectedSQLs.size(); i++) {
+      assertEquals("CreateTable SQL "+i, expectedSQLs.get(i), SQLs.get(i));
+    }
+
+  }
+
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestDropTable.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestDropTable.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestDropTable.java	(revision 928)
@@ -0,0 +1,63 @@
+package org.gvsig.postgresql.dal.operations.sql;
+
+import java.util.List;
+import junit.framework.TestCase;
+import org.gvsig.fmap.dal.feature.FeatureStore;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.DropTableOperation;
+import org.gvsig.postgresql.dal.TestUtils;
+import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestDropTable extends TestCase {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(TestDropTable.class);
+
+  public TestDropTable(String testName) {
+    super(testName);
+  }
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    new DefaultLibrariesInitializer().fullInitialize();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  // TODO add test methods here. The name must begin with 'test'. For example:
+  // public void testHello() {}
+  
+  public void testDropTable() throws Exception {
+    JDBCHelper helper = TestUtils.getJDBCHelper();
+    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
+    OperationsFactory operations = helper.getOperations();
+
+    List<String> expectedSQLs = TestUtils.getSQLs("dropTable.sql");
+    
+    FeatureStore sourceStore = TestUtils.openSourceStore1();
+
+    TableReference table = operations.createTableReference(
+            "dbtest", 
+            sqlbuilder.default_schema(), 
+            "test", 
+            null
+    );
+    DropTableOperation dropTable = operations.createDropTable(
+            table
+    );
+    List<String> SQLs = dropTable.getSQLs();
+    assertEquals("DropTable num. SQLs", expectedSQLs.size(), SQLs.size());
+    for (int i = 0; i < expectedSQLs.size(); i++) {
+      assertEquals("DropTable SQL "+i, expectedSQLs.get(i), SQLs.get(i));
+    }
+  }
+
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestTableIsEmpty.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestTableIsEmpty.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestTableIsEmpty.java	(revision 928)
@@ -0,0 +1,66 @@
+package org.gvsig.postgresql.dal.operations.sql;
+
+import java.util.List;
+import junit.framework.TestCase;
+import org.gvsig.fmap.dal.feature.FeatureStore;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.TableIsEmptyOperation;
+import org.gvsig.postgresql.dal.TestUtils;
+import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestTableIsEmpty extends TestCase {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(TestTableIsEmpty.class);
+
+  public TestTableIsEmpty(String testName) {
+    super(testName);
+  }
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    new DefaultLibrariesInitializer().fullInitialize();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  // TODO add test methods here. The name must begin with 'test'. For example:
+  // public void testHello() {}
+  
+  public void testTableIsEmpty() throws Exception {
+    JDBCHelper helper = TestUtils.getJDBCHelper();
+    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
+    OperationsFactory operations = helper.getOperations();
+
+    List<String> expectedSQLs = TestUtils.getSQLs("tableIsEmpty.sql");
+    
+    FeatureStore sourceStore = TestUtils.openSourceStore1();
+
+    TableReference table = operations.createTableReference(
+            "dbtest", 
+            sqlbuilder.default_schema(), 
+            "test", 
+            null
+    );
+    FeatureType featureType = sourceStore.getDefaultFeatureType();
+    TableIsEmptyOperation tableIsEmpty = operations.createTableIsEmpty(
+            featureType,
+            table,
+            null, 
+            null
+    );
+    
+    String sql = tableIsEmpty.getSQL();
+    assertEquals("TableIsEmpty SQL", expectedSQLs.get(0), sql);
+  }
+
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestPerformChanges.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestPerformChanges.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestPerformChanges.java	(revision 928)
@@ -0,0 +1,103 @@
+package org.gvsig.postgresql.dal.operations.sql;
+
+import java.util.Collections;
+import java.util.List;
+import junit.framework.TestCase;
+import org.gvsig.fmap.dal.DALLocator;
+import org.gvsig.fmap.dal.DataTypes;
+import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
+import org.gvsig.fmap.dal.feature.EditableFeatureType;
+import org.gvsig.fmap.dal.feature.FeatureStore;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import org.gvsig.fmap.dal.feature.FeatureType.FeatureTypeChanged;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.PerformChangesOperation;
+import org.gvsig.postgresql.dal.TestUtils;
+import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestPerformChanges extends TestCase {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(TestPerformChanges.class);
+
+  public TestPerformChanges(String testName) {
+    super(testName);
+  }
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    new DefaultLibrariesInitializer().fullInitialize();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  // TODO add test methods here. The name must begin with 'test'. For example:
+  // public void testHello() {}
+  
+  public void testPerformChanges() throws Exception {
+    JDBCHelper helper = TestUtils.getJDBCHelper();
+    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
+    OperationsFactory operations = helper.getOperations();
+
+    List<String> expectedSQLs = TestUtils.getSQLs("performChanges.sql");
+    
+    FeatureStore sourceStore = TestUtils.openSourceStore1();
+
+    TableReference table = operations.createTableReference(
+            "dbtest", 
+            sqlbuilder.default_schema(), 
+            "test", 
+            null
+    );
+    FeatureType featureType = sourceStore.getDefaultFeatureType();
+    
+    
+    FeatureTypeChanged featureTypeChanged = new FeatureTypeChanged() {
+      @Override
+      public FeatureType getSource() {
+        EditableFeatureType ft = DALLocator.getDataManager().createFeatureType();
+        EditableFeatureAttributeDescriptor id = ft.add("ID", DataTypes.INT);
+        id.copyFrom(featureType.getAttributeDescriptor("ID"));
+        return ft;
+      }
+
+      @Override
+      public FeatureType getTarget() {
+        return featureType;
+      }
+    };
+    List<FeatureTypeChanged> featureTypesChangeds = Collections.singletonList(featureTypeChanged);
+    
+    PerformChangesOperation performChanges = operations.createPerformChanges(
+            table, 
+            sourceStore.getDefaultFeatureType(),
+            null, 
+            null, 
+            null, 
+            featureTypesChangeds.iterator()
+    );
+    String insertSQL = performChanges.getInsertSQL();
+    String deleteSQL = performChanges.getDeleteSQL();
+    String updateSQL = performChanges.getUpdateSQL();
+    List<String> updateTableSQLs = performChanges.getUpdateTableSQLs();
+
+    assertEquals("Insert SQL", expectedSQLs.get(0), insertSQL);
+    assertEquals("Delete SQL", expectedSQLs.get(1), deleteSQL);
+    assertEquals("Update SQL", expectedSQLs.get(2), updateSQL);
+    assertEquals("UpdateTable num. SQLs", expectedSQLs.size()-3, updateTableSQLs.size());
+    for (int i = 0; i < updateTableSQLs.size(); i++) {
+      assertEquals("UpdateTable SQL "+i, expectedSQLs.get(i+3), updateTableSQLs.get(i));
+    }
+    
+    // FIXME: El ALTER TABLE de una columna geometria no funciona
+  }
+
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestUpdateTableStatistics.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestUpdateTableStatistics.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestUpdateTableStatistics.java	(revision 928)
@@ -0,0 +1,66 @@
+package org.gvsig.postgresql.dal.operations.sql;
+
+import java.util.List;
+import junit.framework.TestCase;
+import org.gvsig.fmap.dal.feature.FeatureStore;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.UpdateTableStatisticsOperation;
+import org.gvsig.postgresql.dal.TestUtils;
+import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestUpdateTableStatistics extends TestCase {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(TestUpdateTableStatistics.class);
+
+  public TestUpdateTableStatistics(String testName) {
+    super(testName);
+  }
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    new DefaultLibrariesInitializer().fullInitialize();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  // TODO add test methods here. The name must begin with 'test'. For example:
+  // public void testHello() {}
+  
+  public void testUpdateTableStatistics() throws Exception {
+    JDBCHelper helper = TestUtils.getJDBCHelper();
+    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
+    OperationsFactory operations = helper.getOperations();
+
+    List<String> expectedSQLs = TestUtils.getSQLs("updateTableStatistics.sql");
+    
+    FeatureStore sourceStore = TestUtils.openSourceStore1();
+
+    TableReference table = operations.createTableReference(
+            "dbtest", 
+            sqlbuilder.default_schema(), 
+            "test", 
+            null
+    );
+    FeatureType featureType = sourceStore.getDefaultFeatureType();
+    UpdateTableStatisticsOperation updateTableStatistics = operations.createUpdateTableStatistics(
+            table
+    );
+    
+    List<String> SQLs = updateTableStatistics.getSQLs();
+    assertEquals("UpdateTableStatistics num. SQLs", expectedSQLs.size(), SQLs.size());
+    for (int i = 0; i < expectedSQLs.size(); i++) {
+      assertEquals("UpdateTableStatistics SQL "+i, expectedSQLs.get(i), SQLs.get(i));
+    }
+  }
+
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/resources/META-INF/services/org.gvsig.tools.library.Library	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/resources/META-INF/services/org.gvsig.tools.library.Library	(revision 928)
@@ -0,0 +1 @@
+org.gvsig.postgresql.dal.PostgreSQLLibrary
\ No newline at end of file
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/resources/org/gvsig/postgresql/dal/PostgreSQLParameters.xml
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/resources/org/gvsig/postgresql/dal/PostgreSQLParameters.xml	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/resources/org/gvsig/postgresql/dal/PostgreSQLParameters.xml	(revision 928)
@@ -0,0 +1,65 @@
+<?xml version="1.0"?>
+<definitions>
+  <version>1.0.0</version>
+  <classes>
+    <class name="PostgreSQLResourceParameters">
+      <extends>
+        <class>JDBC2ResourceParameters</class>
+      </extends>
+      <description>_PostgreSQL_loading_parameters</description>
+      <fields>
+        <field name="JDBCDriverClass" type="string" mandatory="true"
+          defaultValue="org.postgresql.Driver" group="Advanced">
+          <description>JDBC Driver class</description>
+        </field>
+	<field name="port" type="integer" mandatory="false"
+          defaultValue="5432" group="Connection">
+          <description></description>
+        </field>
+        <field name="host" type="string" mandatory="false" 
+            defaultValue="127.0.0.1" group="Connection">
+          <description></description>
+        </field>
+        <field name="UseSSL" type="boolean" mandatory="false"
+          defaultValue="false" group="Basic">
+          <description>Use SSL connetion</description>
+        </field>
+        <field name="maxIdle" type="integer" mandatory="false"
+          defaultValue="8" group="Advanced">
+          <description>The maximum number of connections that can remail idle in the pool.</description>
+        </field>
+        <field name="networkTimeout" type="integer" mandatory="false"
+          defaultValue="30000" group="Advanced">
+          <description>The maximum period a connection or objects created from the connection will wait for the database to reply to any one request.</description>
+        </field>
+      </fields>
+    </class>
+
+    <class name="PostgreSQLStoreParameters">
+      <extends>
+        <class>JDBC2StoreParameters</class>
+        <class>PostgreSQLResourceParameters</class>
+      </extends>
+      <fields/>
+    </class>
+
+    <class name="PostgreSQLNewStoreParameters">
+      <extends>
+        <class>JDBC2NewStoreParameters</class>
+        <class>PostgreSQLResourceParameters</class>
+      </extends>
+      <fields/>
+    </class>
+
+
+    <class name="PostgreSQLServerExplorerParameters">
+      <extends>
+        <class>PostgreSQLResourceParameters</class>
+        <class>JDBC2ServerExplorerParameters</class>
+      </extends>
+      <fields/>
+    </class>
+
+
+  </classes>
+</definitions>  
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/resources/org/gvsig/postgresql/dal/PostgreSQLMetadata.xml
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/resources/org/gvsig/postgresql/dal/PostgreSQLMetadata.xml	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/resources/org/gvsig/postgresql/dal/PostgreSQLMetadata.xml	(revision 928)
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<definitions>
+  <version>1.0.0</version>
+  <classes>
+    <class name="PostgreSQL" namespace="Metadata">
+      <extends>
+      	<class name="JDBC2" namespace="Metadata"/>
+      </extends>
+      <description>Metadata of a PostgreSQL store</description>
+      <fields>
+      </fields>
+    </class>
+
+  </classes>
+</definitions>  
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLLibrary.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLLibrary.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLLibrary.java	(revision 928)
@@ -0,0 +1,103 @@
+
+package org.gvsig.postgresql.dal;
+
+import org.gvsig.fmap.dal.DALLibrary;
+import org.gvsig.fmap.dal.DALLocator;
+import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
+import org.gvsig.fmap.dal.store.db.DBHelper;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCLibrary;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCStoreProviderBase;
+import org.gvsig.json.Json;
+import org.gvsig.metadata.exceptions.MetadataException;
+import org.gvsig.tools.library.AbstractLibrary;
+import org.gvsig.tools.library.LibraryException;
+
+
+public class PostgreSQLLibrary extends AbstractLibrary {
+
+    public static final String NAME = "PostgreSQL";
+
+    @Override
+    public void doRegistration() {
+        registerAsServiceOf(DALLibrary.class);
+        require(JDBCLibrary.class);
+    }
+
+    @Override
+    protected void doInitialize() throws LibraryException {
+    }
+
+    @Override
+    protected void doPostInitialize() throws LibraryException {
+        LibraryException ex = null;
+
+        DataManagerProviderServices dataman = 
+                (DataManagerProviderServices) DALLocator.getDataManager();
+
+        try {
+            Class.forName(PostgreSQLHelper.POSTGRESQL_JDBC_DRIVER);
+        } catch(Throwable th) {
+            PostgreSQLHelper.LOGGER.warn("Can't load PostgreSQL JDBC Driver.",th);
+        }
+        
+        DBHelper.registerParametersDefinition(
+                NAME + "StoreParameters",
+                PostgreSQLStoreParameters.class,
+                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
+        );
+        DBHelper.registerParametersDefinition(
+                NAME + "NewStoreParameters",
+                PostgreSQLNewStoreParameters.class,
+                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
+        );
+        DBHelper.registerParametersDefinition(
+                NAME + "ServerExplorerParameters",
+                PostgreSQLServerExplorerParameters.class,
+                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
+        );
+//        DBHelper.registerParametersDefinition(
+//                NAME + "ResourceParameters",
+//                PostgreSQLResourceParameters.class,
+//                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
+//        );
+        try {
+            DBHelper.registerMetadataDefinition(
+                NAME,
+                JDBCStoreProviderBase.class,
+                dataman.getResourceAsStream(this, NAME + "Metadata.xml")
+            );
+        } catch (MetadataException e) {
+            ex = new LibraryException(this.getClass(), e);
+        }
+
+//        ResourceManagerProviderServices resman = (ResourceManagerProviderServices) DALLocator
+//                .getResourceManager();
+//
+//        if (!resman.getResourceProviders().contains(NAME)) {
+//            resman.register(NAME,
+//                "Resource for " + NAME,
+//                PostgreSQLResource.class,
+//                PostgreSQLResourceParameters.class
+//            );
+//        }
+
+        if (!dataman.getStoreProviderRegister().exits(NAME)) {
+            dataman.registerStoreProviderFactory(new PostgreSQLStoreProviderFactory());
+        }
+
+        if (!dataman.getServerExplorerRegister().exits(NAME)) {
+            dataman.registerServerExplorerFactory(new PostgreSQLServerExplorerFactory());
+        }
+
+        // Por compatibilidad con gvSIG 2.3 registramos otra vez la factoria con
+        // el nombre que tenia antes.
+        if (!dataman.getServerExplorerRegister().exits("PostgreSQLExplorer")) {
+            dataman.registerServerExplorerFactory(new PostgreSQLServerExplorerFactory("PostgreSQLExplorer"));
+        }
+        Json.registerSerializer(PostgreSQLServerExplorerParameters.class);
+        if (ex != null) {
+            throw ex;
+        }
+    }
+
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLBuilder.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLBuilder.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLBuilder.java	(revision 928)
@@ -0,0 +1,373 @@
+/**
+ * gvSIG. Desktop Geographic Information System.
+ *
+ * Copyright (C) 2007-2013 gvSIG Association.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * For any additional information, do not hesitate to contact us
+ * at info AT gvsig.com, or visit our website www.gvsig.com.
+ */
+
+package org.gvsig.postgresql.dal;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.postgresql.dal.expressionbuilderformatter.PostgreSQLFormatter;
+
+@SuppressWarnings("UseSpecificCatch")
+public class PostgreSQLBuilder extends JDBCSQLBuilderBase {
+
+    protected Formatter formatter = null;
+    
+    public static class Version {
+
+        private final int major;
+        private final int minor;
+        
+        public Version(int major, int minor) {
+            this.major = major;
+            this.minor = minor;
+        }
+
+        public int getMajor() {
+            return major;
+        }
+
+        public int getMinor() {
+            return minor;
+        }
+        
+    }
+    private Version databaseVersion = null;
+    
+    public Version getDatabaseVersion() {
+        if( databaseVersion == null ) {
+            Connection conn = null;
+            try {
+                conn = this.getHelper().getConnection();
+                DatabaseMetaData metadata = conn.getMetaData();
+                databaseVersion = new Version(
+                    metadata.getDatabaseMajorVersion(),
+                    metadata.getDatabaseMinorVersion()
+                );
+            } catch (Exception ex) {
+                databaseVersion = new Version(0,0);
+            } finally {
+                this.getHelper().closeConnectionQuietly(conn);
+            }
+        }
+        return databaseVersion;
+    }
+    
+    public PostgreSQLBuilder(JDBCHelper helper) {
+        super(helper);
+        this.defaultSchema = "public";
+        this.supportSchemas = true;
+        this.allowAutomaticValues = true;
+        this.geometrySupportType = this.helper.getGeometrySupportType();
+        this.hasSpatialFunctions = this.helper.hasSpatialFunctions();
+
+        this.STMT_DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table = null;
+        this.STMT_DELETE_GEOMETRY_COLUMN_FROM_TABLE_table = null;
+
+        this.STMT_UPDATE_TABLE_STATISTICS_table = "ANALYZE {0}";
+
+//        config.set(SQLConfig.ST_GeomFromEWKB, "ST_GeomFromEWKB({0}, {1})");
+//        config.set(SQLConfig.ST_AsEWKB, "ST_AsEWKB(({0}))");        
+//        config.set(SQLConfig.ST_ExtentAggregate, "ST_Extent({0})");        
+//        config.set(SQLConfig.ST_UnionAggregate, "ST_Union({0})");
+        
+//        config.set(SQLConfig.isNull, "( ({0}) ISNULL )");
+//        config.set(SQLConfig.notIsNull, "( ({0}) NOT NULL )");
+
+    }
+    
+    public class PostgreSQLUpdateTableStatisticsBuilderBase extends UpdateTableStatisticsBuilderBase {
+        @Override
+        public List<String> toStrings() {
+            List<String> sqls = new ArrayList<>();
+            
+            if( !StringUtils.isBlank(STMT_UPDATE_TABLE_STATISTICS_table) ) {
+                // In postGIS, UpdateLayerStatistics function, don't allow to 
+                // use the database name in the table name.
+                String name = as_identifier(this.table.getName());
+                if( table.has_schema()) {
+                    name = as_identifier(this.table.getSchema()) + "." + name;
+                }
+                String sql = MessageFormat.format(
+                        STMT_UPDATE_TABLE_STATISTICS_table,
+                        name
+                    );
+                if( !StringUtils.isEmpty(sql) ) {
+                    sqls.add(sql);
+                }
+            }
+            return sqls;
+        }        
+    }
+    protected class PostgreSQLCreateIndexBuilder extends CreateIndexBuilderBase {
+
+        @Override
+        public List<String> toStrings(Formatter formatter) {
+            StringBuilder builder = new StringBuilder();
+            builder.append("CREATE ");
+//            if( this.isUnique ) {
+//                builder.append("UNIQUE ");
+//            }
+            builder.append("INDEX ");
+            if( this.ifNotExist ) {
+                Version version = getDatabaseVersion();
+                if( version.getMajor()>=9 && version.getMinor()>=5 ) {
+                    builder.append("IF NOT EXISTS ");
+                }
+            }
+            builder.append(as_identifier(this.indexName));
+            builder.append(" ON ");
+            builder.append(this.table.toString(formatter));
+            if( this.isSpatial ) {
+                builder.append(" USING GIST ");
+            }
+            builder.append(" ( ");
+            boolean is_first_column = true;
+            for( String column : this.columns) {
+                if( is_first_column ) {
+                    is_first_column = false;
+                } else {
+                    builder.append(", ");
+                }
+                builder.append(as_identifier(column));
+            }
+            builder.append(" )");
+            
+            List<String> sqls = new ArrayList<>();
+            sqls.add(builder.toString());
+            return sqls;
+        }
+        
+    }
+    
+    protected class PostgreSQLCreateTableBuilder extends CreateTableBuilderBase {
+
+        @Override
+       public List<String> toStrings(Formatter formatter) {
+           // 
+           // https://www.postgresql.org/docs/9.1/static/sql-createtable.html
+           //
+            List<String> sqls = new ArrayList<>();
+            StringBuilder builder = new StringBuilder();
+
+            builder.append("CREATE TABLE ");
+            builder.append(this.table.toString(formatter));
+            builder.append(" (");
+            boolean first = true;
+            for (ColumnDescriptor column : columns) {
+                if( column.isGeometry() ) {
+                    continue;
+                }
+                if (first) {
+                    first = false;
+                } else {
+                    builder.append(", ");
+                }
+                builder.append(as_identifier(column.getName()));
+                builder.append(" ");
+                if( column.isAutomatic() ) {
+                    builder.append(" SERIAL");
+                } else {
+                    builder.append(sqltype(
+                            column.getType(), 
+                            column.getSize(),
+                            column.getPrecision(), 
+                            column.getScale(), 
+                            column.getGeometryType(),
+                            column.getGeometrySubtype()
+                    ));
+                    if (column.getDefaultValue() == null) {
+                        if (column.allowNulls()) {
+                            builder.append(" DEFAULT NULL");
+                        }
+                    } else {
+                        builder.append(" DEFAULT '");
+                        builder.append(column.getDefaultValue().toString());
+                        builder.append("'");
+                    }
+                    if (column.allowNulls()) {
+                        builder.append(" NULL");
+                    } else {
+                        builder.append(" NOT NULL");
+                    }
+                }
+                if (column.isPrimaryKey()) {
+                    builder.append(" PRIMARY KEY");
+                }
+            }
+            builder.append(" )");
+            sqls.add(builder.toString());
+
+            String AddGeometryColumn = "SELECT AddGeometryColumn({0} , {1} , {2}, {3,number,#######} , {4} , {5}, {6})";
+            for (ColumnDescriptor column : columns) {
+                if( column.isGeometry() ) {
+                    String sql = MessageFormat.format(
+                        AddGeometryColumn,
+                        as_string(this.table.has_schema()?this.table.getSchema():"public"),
+                        as_string(this.table.getName()),
+                        as_string(column.getName()),
+                        column.getGeometrySRSId(),
+                        as_string(sqlgeometrytype(column.getGeometryType(), column.getGeometrySubtype())),
+                        as_string(sqlgeometrydimension(column.getGeometryType(), column.getGeometrySubtype())),
+                        as_string(column.allowNulls())
+                    );
+                    sqls.add(sql);
+                }
+            }
+            return sqls;
+        }
+    }
+
+    public class PostgreSQLSelectBuilderBase extends SelectBuilderBase {
+        
+        @Override
+        protected boolean isValid(StringBuilder message) {
+            if( message == null ) {
+                message = new StringBuilder();
+            }
+            if( this.has_offset() && !this.has_order_by() ) {
+                // Algunos gestores de BBDD requieren que se especifique un
+                // orden para poder usar OFFSET. Como eso parece buena idea para
+                // asegurar que siempre tengamos los mismo resultados, lo exijimos
+                // siempre.
+                message.append("Can't use OFFSET without an ORDER BY.");
+                return false;
+            }
+            return true;
+        }        
+        
+        @Override
+        public String toString(Formatter formatter) {
+            //
+            // https://www.postgresql.org/docs/9.1/static/sql-select.html
+            //
+            StringBuilder builder = new StringBuilder();
+            if( !isValid(builder) ) {
+                throw new IllegalStateException(builder.toString());
+            }
+            builder.append("SELECT ");
+            if( this.distinct ) {
+                builder.append("DISTINCT ");
+            }
+            boolean first = true;
+            for (SelectColumnBuilder column : columns) {
+                if (first) {
+                    first = false;
+                } else {
+                    builder.append(", ");
+                }
+                builder.append(column.toString(formatter));
+            }
+
+            if ( this.has_from() ) {
+                builder.append(" FROM ");
+                builder.append(this.from.toString(formatter));
+            }
+            
+            if ( this.has_where() ) {
+                builder.append(" WHERE ");
+                builder.append(this.where.toString(formatter));
+            }
+            if( this.has_group_by() ) {
+                builder.append(" GROUP BY ");
+                builder.append(this.groupColumn.get(0).toString(formatter));
+                for (int i = 1; i < groupColumn.size(); i++) {
+                    builder.append(", ");
+                    builder.append(this.groupColumn.get(i).toString(formatter));
+                }
+            } 
+            
+            if( this.has_order_by() ) {
+                builder.append(" ORDER BY ");
+                first = true;
+                for (OrderByBuilder item : this.order_by) {
+                    if (first) {
+                        first = false;
+                    } else {
+                        builder.append(", ");
+                    }
+                    builder.append(item.toString(formatter));
+                }   
+            }
+            
+            if ( this.has_limit() && this.has_offset() ) {
+                builder.append(" OFFSET ");
+                builder.append(this.offset);
+                builder.append(" FETCH NEXT ");
+                builder.append(this.limit);
+                builder.append(" ROWS ONLY");
+
+            } else if ( this.has_limit()) {
+                builder.append(" LIMIT ");
+                builder.append(this.limit);
+
+            } else if ( this.has_offset() ) {
+                builder.append(" LIMIT ALL OFFSET ");
+                builder.append(this.offset);    
+            }
+            return builder.toString();
+
+        }
+    }
+
+    @Override
+    protected Formatter formatter() {
+        if( this.formatter==null ) {
+            this.formatter = new PostgreSQLFormatter(this);
+        }
+        return this.formatter;
+    }
+
+    @Override
+    public PostgreSQLHelper getHelper() {
+        return (PostgreSQLHelper) helper;
+    }
+    
+    @Override
+    protected CreateTableBuilder createCreateTableBuilder() {
+        return new PostgreSQLCreateTableBuilder();
+    }
+
+    @Override
+    protected CreateIndexBuilder createCreateIndexBuilder() {
+        return new PostgreSQLCreateIndexBuilder();
+    }
+
+    @Override
+    protected SelectBuilder createSelectBuilder() {
+        return new PostgreSQLSelectBuilderBase();
+    }
+
+    @Override
+    protected UpdateTableStatisticsBuilder createUpdateTableStatisticsBuilder() {
+        return new PostgreSQLUpdateTableStatisticsBuilderBase();
+    }       
+   
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/Getattr.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/Getattr.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/Getattr.java	(revision 928)
@@ -0,0 +1,46 @@
+package org.gvsig.postgresql.dal.expressionbuilderformatter;
+
+import org.apache.commons.lang3.StringUtils;
+import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_GETATTR;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Variable;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Constant;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+public class Getattr implements Formatter<Value> {
+    
+    private final SQLBuilder sqlbuilder;
+    private final Formatter<Value> formatter;
+    
+    public Getattr(SQLBuilder sqlbuilder, Formatter<Value> formatter) {
+        this.sqlbuilder = sqlbuilder;
+        this.formatter = formatter;
+    }
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            if( StringUtils.equalsIgnoreCase(FUNCTION_GETATTR, ((Function) value).name()) ) {
+              Value obj = ((Function) value).parameters().get(0);
+              Value attrname = ((Function) value).parameters().get(1);
+              return obj instanceof Variable && attrname instanceof Constant;
+              
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public String format(Value function0) {
+        Function function = (Function) function0;
+        Variable obj = (Variable) function.parameters().get(0);
+        Constant attrname = (Constant) function.parameters().get(1);
+        return this.sqlbuilder.as_identifier(obj.name())+"."+this.sqlbuilder.as_identifier((String) attrname.value());
+    }
+    
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ILike.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ILike.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ILike.java	(revision 928)
@@ -0,0 +1,43 @@
+package org.gvsig.postgresql.dal.expressionbuilderformatter;
+
+import java.text.MessageFormat;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import static org.gvsig.expressionevaluator.ExpressionBuilder.OPERATOR_ILIKE;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ILike implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+    
+    public ILike(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+    
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(OPERATOR_ILIKE, ((Function) value).name());
+        }
+        return false;
+    }
+
+    @Override
+    public String format(Value function) {
+        List<Value> parameters = ((Function) function).parameters();
+        String p1 = parameters.get(0).toString(formatter);
+        String p2 = parameters.get(1).toString(formatter);
+        String r = MessageFormat.format("({0}) ~~* ({1})", p1, p2);
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/Decode.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/Decode.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/Decode.java	(revision 928)
@@ -0,0 +1,62 @@
+package org.gvsig.postgresql.dal.expressionbuilderformatter;
+
+import java.util.List;
+import java.util.Objects;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_DECODE;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+public class Decode implements Formatter<Value> {
+    
+    private final SQLBuilder sqlbuilder;
+    private final Formatter<Value> formatter;
+    
+    public Decode(SQLBuilder sqlbuilder, Formatter<Value> formatter) {
+        this.sqlbuilder = sqlbuilder;
+        this.formatter = formatter;
+    }
+    
+    @Override
+    public boolean canApply(ExpressionBuilder.Value value) {
+        if (value instanceof ExpressionBuilder.Function) {
+            if( StringUtils.equalsIgnoreCase(FUNCTION_DECODE, ((Function) value).name()) ) {
+                List<Value> parameters = ((Function) value).parameters();
+                if( parameters.size()==2) {
+                    Value p1 = parameters.get(0);
+                    Value p2 = parameters.get(1);
+                    if( p1 instanceof ExpressionBuilder.Constant && 
+                        p2 instanceof ExpressionBuilder.Constant &&
+                        ((ExpressionBuilder.Constant)p1).value() instanceof String &&
+                        ((ExpressionBuilder.Constant)p2).value() instanceof String 
+                        ) {
+                        String p2value = ((ExpressionBuilder.Constant)p2).value().toString();
+                        if( StringUtils.equalsIgnoreCase(p2value, "hex") ) {
+                            return true;
+                        }
+                    }
+                    
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public String format(Value function) {
+        ExpressionBuilder builder = this.sqlbuilder.expression();
+        List<Value> parameters = ((Function) function).parameters();
+        Value p1 = parameters.get(0);
+        String p1value = Objects.toString(((ExpressionBuilder.Constant)p1).value(), "");
+        String r = builder.string("\\x"+p1value)+"::bytea";
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ST_ExtentAggregate.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ST_ExtentAggregate.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ST_ExtentAggregate.java	(revision 928)
@@ -0,0 +1,42 @@
+package org.gvsig.postgresql.dal.expressionbuilderformatter;
+
+import java.text.MessageFormat;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import static org.gvsig.expressionevaluator.GeometryExpressionBuilder.FUNCTION_ST_EXTENTAGGREGATE;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+public class ST_ExtentAggregate implements Formatter<Value> {
+    
+    private final SQLBuilder sqlbuilder;
+    private final Formatter<Value> formatter;
+    
+    public ST_ExtentAggregate(SQLBuilder sqlbuilder, Formatter<Value> formatter) {
+        this.sqlbuilder = sqlbuilder;
+        this.formatter = formatter;
+    }
+    @Override
+    public boolean canApply(ExpressionBuilder.Value value) {
+        if (value instanceof ExpressionBuilder.Function) {
+            return StringUtils.equalsIgnoreCase(FUNCTION_ST_EXTENTAGGREGATE, ((Function) value).name());
+        }
+        return false;
+    }
+
+    @Override
+    public String format(Value function) {
+        List<Value> parameters = ((Function) function).parameters();
+        String p1 = parameters.get(0).toString(formatter);
+        String r = MessageFormat.format("ST_Extent({0})", p1);
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ST_GeomFromWKB.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ST_GeomFromWKB.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ST_GeomFromWKB.java	(revision 928)
@@ -0,0 +1,67 @@
+package org.gvsig.postgresql.dal.expressionbuilderformatter;
+
+import java.text.MessageFormat;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
+import org.gvsig.fmap.dal.SQLBuilder;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_FEATURE_TYPE;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+public class ST_GeomFromWKB implements Formatter<Value> {
+    
+    private final SQLBuilder sqlbuilder;
+    private final Formatter<Value> formatter;
+    
+    public ST_GeomFromWKB(SQLBuilder sqlbuilder, Formatter<Value> formatter) {
+        this.sqlbuilder = sqlbuilder;
+        this.formatter = formatter;
+    }
+    @Override
+    public boolean canApply(ExpressionBuilder.Value value) {
+        if (value instanceof ExpressionBuilder.Function) {
+            return StringUtils.equalsIgnoreCase(GeometryExpressionBuilder.FUNCTION_ST_GEOMFROMWKB, ((Function) value).name());
+        }
+        return false;
+    }
+
+    @Override
+    public String format(Value function) {
+        String r;
+        String wkb;
+        String srid;
+        List<Value> parameters = ((Function) function).parameters();
+        switch(parameters.size()) {
+            case 1:
+                wkb = parameters.get(0).toString(formatter);
+                r = MessageFormat.format("ST_GeomFromWKB({0})", wkb);
+                break;
+            case 2:
+                wkb = parameters.get(0).toString(formatter);
+                srid = parameters.get(1).toString(formatter);
+                if( StringUtils.equals("0", srid) ) {
+                    r = MessageFormat.format("ST_GeomFromWKB({0})", wkb);
+                } else {
+                    FeatureType ftype = (FeatureType) function.getProperty(PROP_FEATURE_TYPE);
+                    if( ftype == null || ftype.getDefaultSRS()!=null ) {
+                        r = MessageFormat.format("ST_GeomFromWKB({0},{1})", wkb, srid);
+                    } else {
+                        r = MessageFormat.format("ST_GeomFromWKB({0})", wkb);
+                    }
+                }
+                break;
+            default:
+                throw new IllegalArgumentException("Wrong number of arguments ("+parameters.size()+") in function ST_GeomFromWKB; requiered 1 or 2 arguments.");
+        }
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/IsNull.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/IsNull.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/IsNull.java	(revision 928)
@@ -0,0 +1,49 @@
+package org.gvsig.postgresql.dal.expressionbuilderformatter;
+
+import java.text.MessageFormat;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.Code.Constant;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import static org.gvsig.expressionevaluator.ExpressionBuilder.OPERATOR_IS;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class IsNull implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+    
+    public IsNull(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+    
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            if( StringUtils.equalsIgnoreCase(OPERATOR_IS, ((Function) value).name()) ) {
+                List<Value> parameters = ((Function) value).parameters();
+                Value p2 = parameters.get(1);
+                if( p2 instanceof Constant && ((Constant)p2).value()==null ) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public String format(Value function) {
+        List<Value> parameters = ((Function) function).parameters();
+        String p1 = parameters.get(0).toString(formatter);
+        String r = MessageFormat.format("( ({0}) ISNULL )", p1);
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ST_GeomFromText.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ST_GeomFromText.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/ST_GeomFromText.java	(revision 928)
@@ -0,0 +1,67 @@
+package org.gvsig.postgresql.dal.expressionbuilderformatter;
+
+import java.text.MessageFormat;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
+import org.gvsig.fmap.dal.SQLBuilder;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_FEATURE_TYPE;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+public class ST_GeomFromText implements Formatter<Value> {
+    
+    private final SQLBuilder sqlbuilder;
+    private final Formatter<Value> formatter;
+    
+    public ST_GeomFromText(SQLBuilder sqlbuilder, Formatter<Value> formatter) {
+        this.sqlbuilder = sqlbuilder;
+        this.formatter = formatter;
+    }
+    @Override
+    public boolean canApply(ExpressionBuilder.Value value) {
+        if (value instanceof ExpressionBuilder.Function) {
+            return StringUtils.equalsIgnoreCase(GeometryExpressionBuilder.FUNCTION_ST_GEOMFROMTEXT, ((Function) value).name());
+        }
+        return false;
+    }
+
+    @Override
+    public String format(Value function) {
+        String r;
+        String wkt;
+        String srid;
+        List<Value> parameters = ((Function) function).parameters();
+        switch(parameters.size()) {
+            case 1:
+                wkt = parameters.get(0).toString(formatter);
+                r = MessageFormat.format("ST_GeomFromText({0})", wkt);
+                break;
+            case 2:
+                wkt = parameters.get(0).toString(formatter);
+                srid = parameters.get(1).toString(formatter);
+                if( StringUtils.equals("0", srid) ) {
+                    r = MessageFormat.format("ST_GeomFromText({0})", wkt);
+                } else {
+                    FeatureType ftype = (FeatureType) function.getProperty(PROP_FEATURE_TYPE);
+                    if( ftype == null || ftype.getDefaultSRS()!=null ) {
+                        r = MessageFormat.format("ST_GeomFromText({0},{1})", wkt, srid);
+                    } else {
+                        r = MessageFormat.format("ST_GeomFromText({0})", wkt);
+                    }
+                }
+                break;
+            default:
+                throw new IllegalArgumentException("Wrong number of arguments ("+parameters.size()+") in function ST_GeomFromText; requiered 1 or 2 arguments.");
+        }
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/IsNotNull.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/IsNotNull.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/IsNotNull.java	(revision 928)
@@ -0,0 +1,62 @@
+package org.gvsig.postgresql.dal.expressionbuilderformatter;
+
+import java.text.MessageFormat;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.Code.Constant;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import static org.gvsig.expressionevaluator.ExpressionBuilder.OPERATOR_IS;
+import static org.gvsig.expressionevaluator.ExpressionBuilder.OPERATOR_NOT;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class IsNotNull implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+    
+    public IsNotNull(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+    
+    @Override
+    public boolean canApply(Value value_not) {
+        if (value_not instanceof Function) {
+            // NOT( IS( p1, NULL) )
+            if( StringUtils.equalsIgnoreCase(OPERATOR_NOT, ((Function) value_not).name()) ) {
+                List<Value> parameters = ((Function) value_not).parameters();
+                Value value_is = parameters.get(0);
+                if( value_is instanceof Function && StringUtils.equalsIgnoreCase(OPERATOR_IS, ((Function)value_is).name()) ) {
+                    List<Value> parameters_is = ((Function) value_is).parameters();
+                    Value is_p2 = parameters_is.get(1);
+                    if( is_p2 instanceof Constant && ((Constant)is_p2).value()==null ) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public String format(Value value_not) {
+        // NOT( IS( p1, NULL) )
+
+        List<Value> parameters = ((Function) value_not).parameters();
+        Value value_is = parameters.get(0);
+        List<Value> parameters_is = ((Function)value_is).parameters();
+        Value is_p1 = parameters_is.get(0);
+        String r = MessageFormat.format(
+                "( ({0}) IS NOT NULL )", 
+                is_p1.toString(formatter)
+        );
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/PostgreSQLFormatter.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/PostgreSQLFormatter.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/PostgreSQLFormatter.java	(revision 928)
@@ -0,0 +1,62 @@
+package org.gvsig.postgresql.dal.expressionbuilderformatter;
+
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.DALLocator;
+import org.gvsig.fmap.dal.SQLBuilder;
+import org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters.ComputedAttribute;
+import org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters.Exists;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+public class PostgreSQLFormatter implements Formatter<Value> {
+
+    private final SQLBuilder builder;
+    private final Formatter<ExpressionBuilder.Value>[] formatters;
+
+    @SuppressWarnings("LeakingThisInConstructor")
+    public PostgreSQLFormatter(SQLBuilder builder) {
+
+        this.builder = builder;
+        this.formatters = new Formatter[]{
+            new Decode(this.builder, this),
+            new Constant(this.builder, this),
+            new ILike(this.builder, this),
+            new IfNull(this.builder, this),
+            new IsNull(this.builder, this),
+            new IsNotNull(this.builder, this),
+            new ST_ExtentAggregate(this.builder, this),
+            new ST_GeomFromWKB(this.builder, this),
+            new ST_GeomFromText(this.builder, this),
+            new Getattr(this.builder, this),
+//            new Iff(this),
+            new Exists(this),
+            new ComputedAttribute(this.builder, this),
+            DALLocator.getDataManager().createDALExpressionBuilder().formatter(this),
+        };
+    }
+
+    @Override
+    public boolean canApply(Value value) {
+        for (Formatter<Value> formatter : formatters) {
+            if (formatter.canApply(value)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public String format(Value value) {
+        for (Formatter<Value> formatter : formatters) {
+            if (formatter.canApply(value)) {
+                return formatter.format(value);
+            }
+        }
+        return value.toString(this);
+    }
+    
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/Constant.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/Constant.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/Constant.java	(revision 928)
@@ -0,0 +1,79 @@
+package org.gvsig.postgresql.dal.expressionbuilderformatter;
+
+import java.text.MessageFormat;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
+import org.gvsig.fmap.dal.SQLBuilder;
+import org.gvsig.fmap.geom.Geometry;
+import org.gvsig.fmap.geom.GeometryUtils;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+public class Constant implements Formatter<Value> {
+    
+    private static final String FORMAT_ST_GEOMFROMWKB = "ST_GeomFromWKB(({0}), ({1}))";
+    private static final String FORMAT_ST_GEOMFROMEWKB = "ST_GeomFromEWKB(({0}), ({1}))";
+    private static final String FORMAT_ST_GEOMFROMTEXT = "ST_GeomFromText(({0}), ({1}))";
+
+    private final SQLBuilder sqlbuilder;
+    private final Formatter<Value> formatter;
+    
+    public Constant(SQLBuilder sqlbuilder, Formatter<Value> formatter) {
+        this.sqlbuilder = sqlbuilder;
+        this.formatter = formatter;
+    }
+    
+    @Override
+    public boolean canApply(ExpressionBuilder.Value value) {
+        if (value instanceof ExpressionBuilder.Constant) {
+            Object x = ((ExpressionBuilder.Constant)value).value();
+            if( x instanceof byte[] ) {
+                return true;
+            }
+            if( x instanceof Geometry ) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public String format(Value constant) {
+        Object x = ((ExpressionBuilder.Constant)constant).value();
+        GeometryExpressionBuilder builder = this.sqlbuilder.expression();
+        if( x instanceof byte[] ) {
+            return builder.string("\\x"+builder.bytearray_hex((byte[]) x))+"::bytea";
+        }
+        if( x instanceof Geometry ) {
+            Geometry geometry = (Geometry) x;
+            switch (builder.geometry_support_type()) {
+                case EWKB:
+                    return MessageFormat.format(
+                            FORMAT_ST_GEOMFROMEWKB,
+                            builder.string("\\x"+builder.bytearray_hex(GeometryUtils.toEWKB(geometry)))+"::bytea",
+                            String.valueOf(builder.srs_id(geometry.getProjection()))
+                    );
+                case WKB:
+                    return MessageFormat.format(
+                            FORMAT_ST_GEOMFROMWKB,
+                            builder.string("\\x"+builder.bytearray_hex(GeometryUtils.toWKB(geometry)))+"::bytea",
+                            String.valueOf(builder.srs_id(geometry.getProjection()))
+                    );
+                case WKT:
+                default:
+                    return MessageFormat.format(
+                            FORMAT_ST_GEOMFROMTEXT,
+                            builder.string(GeometryUtils.toWKT(geometry)),
+                            String.valueOf(builder.srs_id(geometry.getProjection()))
+                    );
+            }
+            
+        }
+        return null;
+    }
+    
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/IfNull.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/IfNull.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/expressionbuilderformatter/IfNull.java	(revision 928)
@@ -0,0 +1,53 @@
+package org.gvsig.postgresql.dal.expressionbuilderformatter;
+
+import java.text.MessageFormat;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_IFNULL;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class IfNull implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+    
+    public IfNull(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+    
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            if (value instanceof ExpressionBuilder.Function) {
+                return StringUtils.equalsIgnoreCase(FUNCTION_IFNULL, ((Function) value).name());
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public String format(Value function) {
+            List<Value> parameters = ((Function) function).parameters();
+            String p1 = parameters.get(0).toString(formatter);
+            String p2 = parameters.get(1).toString(formatter);
+            String p3 = parameters.get(2).toString(formatter);
+            String r = MessageFormat.format(
+                    "CASE WHEN ({0}) IS NULL THEN ({1}) ELSE ({2}) END",
+                    p1,
+                    p3,
+                    p2
+            );
+            return r;
+            
+    }
+    
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/FakePostgreSQLConnectionParameters.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/FakePostgreSQLConnectionParameters.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/FakePostgreSQLConnectionParameters.java	(revision 928)
@@ -0,0 +1,31 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.gvsig.postgresql.dal;
+
+import org.gvsig.fmap.dal.store.jdbc2.spi.FakeConnectionParameters;
+
+/**
+ *
+ * @author fdiaz
+ */
+public class FakePostgreSQLConnectionParameters extends FakeConnectionParameters implements PostgreSQLConnectionParameters {
+
+    @Override
+    public boolean getUseSSL() {
+        return false;
+    }
+
+    @Override
+    public int getMaxIdle() {
+        return 8;
+    }
+
+    @Override
+    public int getNetworkTimeout() {
+        return 30000;
+    }
+    
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLNewStoreParameters.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLNewStoreParameters.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLNewStoreParameters.java	(revision 928)
@@ -0,0 +1,73 @@
+/* gvSIG. Geographic Information System of the Valencian Government
+ *
+ * Copyright (C) 2007-2008 Infrastructures and Transports Department
+ * of the Valencian Government (CIT)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ */
+package org.gvsig.postgresql.dal;
+
+import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
+import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters;
+
+public class PostgreSQLNewStoreParameters 
+    extends 
+        JDBCNewStoreParameters 
+    implements 
+        PostgreSQLConnectionParameters 
+    {
+
+    private final PostgreSQLConnectionParametersHelper helper;
+    
+    public PostgreSQLNewStoreParameters() {
+        super(
+            PostgreSQLLibrary.NAME + "NewStoreParameters", 
+            PostgreSQLLibrary.NAME
+        );
+        this.helper = new PostgreSQLConnectionParametersHelper(this);
+    }
+
+    @Override
+    public String getUrl() {
+        return this.helper.getUrl();
+    }
+    
+    @Override
+    public void validate() throws ValidateDataParametersException {
+        this.helper.validate();
+    }
+        
+    @Override
+    public boolean getUseSSL() {
+        return this.helper.getUseSSL();
+    }
+
+    @Override
+    public int getMaxIdle() {
+        return this.helper.getMaxIdle();
+    }
+
+    public void setUseSSL(boolean v) {
+        this.helper.setUseSSL(v);
+    }
+
+    @Override
+    public int getNetworkTimeout() {
+        return this.helper.getNetworkTimeout();
+    }
+
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLServerExplorerParameters.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLServerExplorerParameters.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLServerExplorerParameters.java	(revision 928)
@@ -0,0 +1,80 @@
+/* gvSIG. Geographic Information System of the Valencian Government
+*
+* Copyright (C) 2007-2008 Infrastructures and Transports Department
+* of the Valencian Government (CIT)
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+* MA  02110-1301, USA.
+*
+ */
+/**
+ *
+ */
+package org.gvsig.postgresql.dal;
+
+import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
+import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
+
+             
+public class PostgreSQLServerExplorerParameters extends
+        JDBCServerExplorerParameters 
+    implements
+        PostgreSQLConnectionParameters
+    {
+    
+    private final PostgreSQLConnectionParametersHelper helper;
+
+    public PostgreSQLServerExplorerParameters() {
+        super(
+                PostgreSQLLibrary.NAME + "ServerExplorerParameters",
+                PostgreSQLLibrary.NAME
+        );
+        this.helper = new PostgreSQLConnectionParametersHelper(this);
+    }
+
+    @Override
+    public String getUrl() {
+        return this.helper.getUrl();
+    }
+    
+    @Override
+    public void validate() throws ValidateDataParametersException {
+        // Esto seria para convertir los parametros de gvSIG 2.3 a 2.4.
+//        if( !StringUtils.equalsIgnoreCase(PostgreSQLLibrary.NAME, (CharSequence) getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME)) ) {
+//            setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, PostgreSQLLibrary.NAME);
+//        }
+        this.helper.validate();
+        super.validate();        
+    }
+
+    @Override
+    public boolean getUseSSL() {
+        return this.helper.getUseSSL();
+    }
+
+    @Override
+    public int getMaxIdle() {
+        return this.helper.getMaxIdle();
+    }
+
+    public void setUseSSL(boolean v) {
+        this.helper.setUseSSL(v);
+    }
+
+    @Override
+    public int getNetworkTimeout() {
+        return this.helper.getNetworkTimeout();
+    }
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLHelper.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLHelper.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLHelper.java	(revision 928)
@@ -0,0 +1,377 @@
+
+package org.gvsig.postgresql.dal;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import org.apache.commons.dbcp2.BasicDataSource;
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType;
+import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
+import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters;
+import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters;
+import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
+import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
+import org.gvsig.fmap.dal.store.jdbc.exception.JDBCDriverClassNotFoundException;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
+import org.gvsig.fmap.dal.store.jdbc2.spi.ConnectionProvider;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolverBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolverDumb;
+import org.gvsig.postgresql.dal.operations.PostgreSQLOperationsFactory;
+import org.gvsig.tools.dispose.Disposable;
+import org.gvsig.tools.exception.BaseException;
+import org.postgresql.util.DriverInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@SuppressWarnings("UseSpecificCatch")
+public class PostgreSQLHelper extends JDBCHelperBase {
+
+    /* friend */ static final Logger LOGGER = LoggerFactory.getLogger(PostgreSQLHelper.class);
+
+    public static final String POSTGRESQL_JDBC_DRIVER = "org.postgresql.Driver";
+    
+    public static final boolean USE_CONNECTIONS_POOL = true;
+    
+    public static String getConnectionURL(PostgreSQLConnectionParameters params) {
+        return getConnectionURL(
+            params.getHost(),
+            params.getPort(),
+            params.getDBName()
+        );
+    }
+    
+    public static String getConnectionURL(String host, Integer port, String db) {
+        if( StringUtils.isEmpty(host) ) {
+            throw new IllegalArgumentException("Parameter 'host' can't be null.");
+        }
+        String connectionURL = "jdbc:postgresql://" + host;
+        if (port != null) {
+            connectionURL = connectionURL + ":" + port;
+        }
+        connectionURL = connectionURL + "/" + db;
+        LOGGER.debug("connectionURL: {}", connectionURL);
+        return connectionURL;
+    }
+
+    private static class PostgreSQLConnectionProvider implements Disposable, ConnectionProvider {
+
+        private static boolean needRegisterDriver = true;
+
+        private BasicDataSource dataSource = null;
+
+        private PostgreSQLConnectionParameters connectionParameters;
+
+        public PostgreSQLConnectionProvider(PostgreSQLConnectionParameters connectionParameters) {
+            this.connectionParameters = connectionParameters;
+        }
+
+        @Override
+        public Connection getConnection() throws SQLException {
+            
+            Connection conn;
+            if( USE_CONNECTIONS_POOL ) {
+                if (this.dataSource == null) {
+                    this.dataSource = this.createDataSource();               
+                }
+                if( LOGGER.isDebugEnabled() ) {
+                    LOGGER.debug("getConnection:\n" + getStatusInformation());
+                }
+                try {
+                    conn = this.dataSource.getConnection();
+                } catch(Throwable ex) {
+                    LOGGER.debug("Error getting connection from pool.",ex);
+                    throw ex;
+                }
+                try {
+                    conn.setNetworkTimeout(null, this.connectionParameters.getNetworkTimeout());
+                } catch(Throwable ex) {
+                    LOGGER.warn("Error setting the network timeout.",ex);
+                }
+                if( LOGGER.isDebugEnabled() ) {
+                    LOGGER.debug("Created connection: {}\n  NumActive: {}\n  NumIdle: {}",
+                        new Object[] {
+                            conn.hashCode(), 
+                            this.dataSource.getNumActive(),
+                            this.dataSource.getNumIdle()
+                        }
+                    );
+                }
+            } else {
+                try {
+                    conn = DriverManager.getConnection(
+                        connectionParameters.getUrl(), 
+                        connectionParameters.getUser(), 
+                        connectionParameters.getPassword()
+                    );
+                } catch(Throwable th) {
+                    throw th;
+                }
+                if( LOGGER.isDebugEnabled() ) {
+                    LOGGER.debug("Created not polled connection: {}",
+                        new Object[] {
+                            conn.hashCode()
+                        }
+                    );
+                }
+            }
+            LOGGER.debug("PostgreSQL JDBC Driver: "+DriverInfo.DRIVER_VERSION);
+            return conn;
+        }
+        
+        public String getStatusInformation() {
+            StringBuilder builder = new StringBuilder();
+            if( this.dataSource==null ) {
+                builder.append("Not poolled connection:\n");
+                builder.append("  Connection URL: '").append(this.connectionParameters.getUrl()).append("'\n");
+            } else {
+                builder.append("BasicDataSource pool status:\n");
+                builder.append("  Connection URL: '").append(this.dataSource.getUrl()).append("'\n");
+                if( this.dataSource.getInitialSize()>0 ) {
+                    builder.append("  InitialSize: ").append(this.dataSource.getInitialSize()).append(" (The initial number of connections that are created when the pool is started)\n");
+                }
+                if( this.dataSource.isPoolPreparedStatements() ) {
+                    builder.append("  PoolPreparedStatements: ").append(this.dataSource.isPoolPreparedStatements()).append("\n");
+                    builder.append("  MaxOpenPreparedStatements: ").append(this.dataSource.getMaxOpenPreparedStatements()).append(" (The maximum number of open statements that can be allocated from the statement pool at the same time, or non-positive for no limit)\n");
+                }
+                builder.append("  MaxTotal: ").append(this.dataSource.getMaxTotal()).append(" (The maximum number of active connections that can be allocated from this pool at the same time)\n");
+                builder.append("  MaxIdle: ").append(this.dataSource.getMaxIdle()).append(" (The maximum number of connections that can remain idle in the pool)\n");
+                builder.append("  NumActive:").append(this.dataSource.getNumActive()).append(" (the current number of active connections)\n");
+                builder.append("  NumIdle:").append(this.dataSource.getNumIdle()).append(" (the current number of idle connections)\n");
+            }
+            return builder.toString();
+        }
+
+        private BasicDataSource createDataSource() throws SQLException {
+            if (!this.isRegistered()) {
+                this.registerDriver();
+            }
+            PostgreSQLConnectionParameters params = connectionParameters;
+
+            BasicDataSource ds = new BasicDataSource();
+            ds.setMaxIdle(params.getMaxIdle());
+            ds.setDriverClassName(params.getJDBCDriverClassName());
+            if( params.getUseSSL() ) {
+                String s = BooleanUtils.toStringTrueFalse(params.getUseSSL());
+                ds.addConnectionProperty("ssl", s );
+            }
+            if( !StringUtils.isEmpty(params.getUser()) ) {
+                ds.setUsername(params.getUser());
+            }
+            if( !StringUtils.isEmpty(params.getPassword()) ) {
+                ds.setPassword(params.getPassword());
+            }
+            ds.setUrl(params.getUrl());
+            
+            ds.setMinEvictableIdleTimeMillis(20*1000);
+            ds.setTimeBetweenEvictionRunsMillis(20*1000);
+            ds.setMinIdle(0);
+            
+            ds.setMaxWaitMillis(60L * 1000);
+            return ds;
+        }
+
+        private boolean isRegistered() {
+            return needRegisterDriver;
+        }
+
+        @Override
+        public void registerDriver() throws SQLException {
+            String className = this.connectionParameters.getJDBCDriverClassName();
+            if (className == null) {
+                return;
+            }
+            try {
+                Class theClass = Class.forName(className);
+                if (theClass == null) {
+                    throw new JDBCDriverClassNotFoundException(PostgreSQLLibrary.NAME, className);
+                }
+            } catch (Exception e) {
+                throw new SQLException("Can't register JDBC driver '" + className + "'.", e);
+            }
+            needRegisterDriver = false;
+        }
+
+        @Override
+        public void dispose() {
+            if( this.dataSource!=null ) {
+                try {
+                    this.dataSource.close();
+                } catch (SQLException ex) {
+                    LOGGER.warn("Can't close BasicDataSource", ex);
+                }
+                this.dataSource = null;
+            }
+            this.connectionParameters = null;
+        }
+
+        @Override
+        public String getStatus() {
+            if( dataSource==null ) {
+                return "Not polled";
+            }
+            StringBuilder builder = new StringBuilder();
+            builder.append("Pool: ");
+            builder.append(JDBCUtils.getHexId(dataSource));
+            builder.append(" Actives: ");
+            builder.append(dataSource.getNumActive());
+            builder.append("/");
+            builder.append(dataSource.getMaxTotal()); //.getMaxActive());
+            builder.append(" idle: ");
+            builder.append(dataSource.getNumIdle());
+            builder.append("/");
+            builder.append(dataSource.getMinIdle());
+            builder.append(":");
+            builder.append(dataSource.getMaxIdle());
+            return builder.toString();
+        }
+
+    }
+
+    private ConnectionProvider connectionProvider = null;
+   
+    /**
+     * Constructor for use only for testing purposes.
+     * 
+     * @param connectionParameters
+     * @param connectionProvider
+     */
+    public PostgreSQLHelper(PostgreSQLConnectionParameters connectionParameters, ConnectionProvider connectionProvider) { 
+        super(connectionParameters);
+        this.srssolver = new SRSSolverDumb(this);
+        this.connectionProvider = connectionProvider;
+    }
+  
+
+
+    public PostgreSQLHelper(JDBCConnectionParameters connectionParameters) {
+        super(connectionParameters);
+        this.srssolver = new SRSSolverBase(this);
+    }
+
+    @Override
+    protected void doDispose() throws BaseException {
+        if( this.connectionProvider!=null ) {
+            this.connectionProvider.dispose();
+            this.connectionProvider = null;
+        }
+        super.doDispose(); 
+    }
+
+    @Override
+    public Connection getConnection() throws AccessResourceException {
+        try {
+            if (this.connectionProvider == null) {
+              if( this.getConnectionParameters()==null ) {
+                return null;
+              }
+              this.connectionProvider = new PostgreSQLConnectionProvider(this.getConnectionParameters());
+            }
+            return this.connectionProvider.getConnection();
+        } catch (SQLException ex) {
+            throw new AccessResourceException(PostgreSQLLibrary.NAME, ex);
+        }
+    }
+
+    @Override
+    public void closeConnection(Connection connection) {
+        if (connection != null) { // In test ???
+            LOGGER.debug("[" + JDBCUtils.getConnId(connection) + "] closeConnection " + this.connectionProvider.getStatus());
+        }
+        super.closeConnection(connection);
+    }
+    
+    @Override
+    public PostgreSQLConnectionParameters getConnectionParameters() {
+        return (PostgreSQLConnectionParameters) super.getConnectionParameters();
+    }
+    
+    @Override
+    public String getConnectionURL() {
+        return getConnectionURL(this.getConnectionParameters());
+    }
+
+    @Override
+    protected String getResourceType() {
+        return PostgreSQLLibrary.NAME;
+    }
+
+    @Override
+    public String getProviderName() {
+        return PostgreSQLLibrary.NAME;
+    }
+
+    @Override
+    public JDBCSQLBuilderBase createSQLBuilder() {
+        return new PostgreSQLBuilder(this);
+    }
+    
+    @Override
+    public OperationsFactory getOperations() {
+        if (this.operationsFactory == null) {
+            this.operationsFactory = new PostgreSQLOperationsFactory(this);
+        }
+        return operationsFactory;
+    }
+
+    @Override
+    public GeometrySupportType getGeometrySupportType() {
+        return GeometrySupportType.EWKB;
+    }
+
+    @Override
+    public boolean hasSpatialFunctions() {
+        return true;
+    }
+
+    @Override
+    public boolean canWriteGeometry(int geometryType, int geometrySubtype) {
+        return true;
+    }
+
+    @Override
+    public String getQuoteForIdentifiers() {
+        return "\"";
+    }
+
+    @Override
+    public boolean allowAutomaticValues() {
+        return true;
+    }
+
+    @Override
+    public boolean supportOffsetInSelect() {
+        return true;
+    }
+
+    @Override
+    public String getQuoteForStrings() {
+        return "'";
+    }
+    
+    @Override
+    public String getSourceId(JDBCStoreParameters parameters) {
+        return parameters.getDBName() + "." + 
+               parameters.getSchema()+ "." + 
+               parameters.getTable();
+    }
+
+    @Override
+    public JDBCNewStoreParameters createNewStoreParameters() {
+        return new PostgreSQLNewStoreParameters();
+    }
+
+    @Override
+    public JDBCStoreParameters createOpenStoreParameters() {
+        return new PostgreSQLStoreParameters();
+    }
+
+    @Override
+    public JDBCServerExplorerParameters createServerExplorerParameters() {
+        return new PostgreSQLServerExplorerParameters();
+    }
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLServerExplorerFactory.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLServerExplorerFactory.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLServerExplorerFactory.java	(revision 928)
@@ -0,0 +1,64 @@
+
+package org.gvsig.postgresql.dal;
+
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.fmap.dal.DataServerExplorerParameters;
+import org.gvsig.fmap.dal.exception.InitializeException;
+import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
+import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
+import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters;
+import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
+import org.gvsig.fmap.dal.store.jdbc2.impl.JDBCServerExplorerFactory;
+
+
+public class PostgreSQLServerExplorerFactory extends JDBCServerExplorerFactory {
+
+    private static final String NAME = PostgreSQLLibrary.NAME;
+    
+    public PostgreSQLServerExplorerFactory() {
+        super(
+            NAME,
+            "PostgreSQL Server"
+        );
+    }
+
+    public PostgreSQLServerExplorerFactory(String name) {
+        // Cuando se instancia la factoria con un "name" que no es el de por
+        // defecto, es para declarar "alias" para el ServerExplorer, normalmente
+        // para mantener compatibilidad con versiones anteriores. 
+        // Marcaremos la factoria como "hidden" para que no aparezca
+        // en el interface de usuario.
+        super(
+            name,
+            "PostgreSQL Server (for compatibility)",
+            true
+        );
+    }
+
+    @Override
+    public JDBCServerExplorer create(
+            DataServerExplorerParameters parameters, 
+            DataServerExplorerProviderServices providerServices
+        ) throws InitializeException {
+        // Esto seria para convertir los parametros de gvSIG 2.3 a 2.4.
+//        if( !StringUtils.equalsIgnoreCase(NAME, (CharSequence) parameters.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME)) ) {
+//            parameters.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, NAME);
+//        }
+        JDBCHelper helper = new PostgreSQLHelper((JDBCConnectionParameters) parameters);
+        JDBCServerExplorer server = helper.createServerExplorer(
+                (JDBCServerExplorerParameters) parameters, 
+                providerServices
+        );
+        return server;
+    }
+        
+
+    @Override
+    public JDBCServerExplorerParameters createParameters() {
+        JDBCServerExplorerParameters params = new PostgreSQLServerExplorerParameters();
+        return params;    
+    }
+    
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLStoreProviderFactory.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLStoreProviderFactory.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLStoreProviderFactory.java	(revision 928)
@@ -0,0 +1,96 @@
+package org.gvsig.postgresql.dal;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.function.Function;
+import org.gvsig.fmap.dal.DataParameters;
+import static org.gvsig.fmap.dal.DataStoreProviderFactory.NO;
+import static org.gvsig.fmap.dal.DataStoreProviderFactory.UNKNOWN;
+import static org.gvsig.fmap.dal.DataStoreProviderFactory.YES;
+import org.gvsig.fmap.dal.exception.InitializeException;
+import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
+import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters;
+import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCStoreProvider;
+import org.gvsig.fmap.dal.store.jdbc2.impl.JDBCStoreProviderFactory;
+
+public class PostgreSQLStoreProviderFactory extends JDBCStoreProviderFactory {
+
+    private static final Set<String> ALLOWED_FUNCTIONS = new HashSet<>(
+            Arrays.asList(new String[]{
+        "COUNT",
+        "SUM",
+        "MIN",
+        "MAX"
+    }
+            )
+    );
+    private static final Set<String> DENIED_FUNCTIONS = Collections.EMPTY_SET;
+
+    public PostgreSQLStoreProviderFactory() {
+        super(
+                PostgreSQLLibrary.NAME,
+                "PostgreSQL store"
+        );
+    }
+
+    @Override
+    public JDBCStoreProvider createProvider(
+            DataParameters parameters,
+            DataStoreProviderServices providerServices
+    ) throws InitializeException {
+        JDBCHelper helper = new PostgreSQLHelper((JDBCConnectionParameters) parameters);
+        JDBCStoreProvider provider = helper.createProvider(
+                (JDBCStoreParameters) parameters,
+                providerServices
+        );
+        return provider;
+    }
+
+    @Override
+    public JDBCStoreParameters createParameters() {
+        JDBCStoreParameters params = new PostgreSQLStoreParameters();
+        return params;
+    }
+
+    @Override
+    public Function<String, Integer> allowFunction() {
+        return (Function<String, Integer>) (String name) -> {
+            if (ALLOWED_FUNCTIONS.contains(name)) {
+                return YES;
+            }
+            if (DENIED_FUNCTIONS.contains(name)) {
+                return NO;
+            }
+            return UNKNOWN;
+        };
+    }
+
+    @Override
+    public int allowGroupBy() {
+        return YES;
+    }
+
+    @Override
+    public int hasVectorialSupport() {
+        return YES;
+    }
+
+    @Override
+    public int hasRasterSupport() {
+        return NO;
+    }
+
+    @Override
+    public int hasTabularSupport() {
+        return YES;
+    }
+
+    @Override
+    public int hasSQLSupport() {
+        return YES;
+    }
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/operations/PostgreSQLFetchFeatureTypeOperation.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/operations/PostgreSQLFetchFeatureTypeOperation.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/operations/PostgreSQLFetchFeatureTypeOperation.java	(revision 928)
@@ -0,0 +1,239 @@
+
+package org.gvsig.postgresql.dal.operations;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.cresques.cts.IProjection;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import org.gvsig.fmap.dal.DataTypes;
+import org.gvsig.fmap.dal.exception.DataException;
+import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
+import org.gvsig.fmap.dal.feature.EditableFeatureType;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolver;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.FetchFeatureTypeOperation;
+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.gvsig.postgresql.dal.PostgreSQLBuilder;
+
+@SuppressWarnings("UseSpecificCatch")
+public class PostgreSQLFetchFeatureTypeOperation extends FetchFeatureTypeOperation {
+
+    private static Map<String,GeometryType>databaseGeometryTypes = null;
+    
+    public PostgreSQLFetchFeatureTypeOperation(
+            JDBCHelper helper
+        ) {
+        super(helper);
+    }
+
+    private GeometryType getGT(
+            GeometryManager manager, 
+            int type, 
+            int subtype
+        ) {
+        try {
+            return manager.getGeometryType(type, subtype);
+        } catch (Exception ex) {
+            return null;
+        }
+    }
+    
+    public PostgreSQLFetchFeatureTypeOperation(
+            JDBCHelper helper,
+            EditableFeatureType featureType,
+            TableReference table,
+            List<String> primaryKeys,
+            String defaultGeometryColumn,
+            IProjection crs,
+            int geometryType,
+            int geometrySubtype
+    ) {
+        super(helper, featureType, table, primaryKeys, defaultGeometryColumn, crs, geometryType, geometrySubtype);
+    }
+    
+
+    @Override
+    public void fetch(Connection conn) throws DataException {
+        super.fetch(conn);
+    }
+
+    @Override
+    protected int getDataTypeFromMetadata(
+            ResultSetMetaData rsMetadata,
+            int colIndex
+        ) throws SQLException {
+
+        return super.getDataTypeFromMetadata(rsMetadata, colIndex);
+    }
+    
+    @Override
+    public String getSQLToRetrievePrimaryKeysFromInformationSchema() throws SQLException {
+        PostgreSQLBuilder sqlbuilder = (PostgreSQLBuilder) this.createSQLBuilder();
+        ExpressionBuilder expbuilder = sqlbuilder.expression();
+        
+        String column_COLUMN_NAME = "column_name";
+        String column_CONSTRAINT_TYPE = "constraint_type";
+        
+        if( sqlbuilder.getDatabaseVersion().getMajor()<10 ) {
+            column_COLUMN_NAME = "COLUMN_NAME";
+            column_CONSTRAINT_TYPE = "CONSTRAINT_TYPE";
+        }
+        sqlbuilder.select().column().name(column_COLUMN_NAME);
+        sqlbuilder.select().column().name(column_CONSTRAINT_TYPE);
+        sqlbuilder.select().from().custom(
+                "INFORMATION_SCHEMA.table_constraints t_cons "
+                + "inner join INFORMATION_SCHEMA.key_column_usage c on "
+                + "c.constraint_catalog = t_cons.constraint_catalog and "
+                + "c.table_schema = t_cons.table_schema and "
+                + "c.table_name = t_cons.table_name and "
+                + "c.constraint_name = t_cons.constraint_name "
+        );
+        sqlbuilder.select().where().set(
+                expbuilder.like(
+                        expbuilder.custom("c.TABLE_NAME"), 
+                        expbuilder.constant(table.getTable())
+                )
+        );
+        if (table.hasSchema()) {
+            sqlbuilder.select().where().and(
+                    expbuilder.like(
+                            expbuilder.custom("c.TABLE_SCHEMA"),
+                            expbuilder.constant(table.getSchema())
+                    )
+            );
+        }
+//        if (catalog != null) {
+//            sqlbuilder.select().where().and(
+//                    expbuilder.like(
+//                            expbuilder.custom("c.CONSTRAINT_CATALOG"),
+//                            expbuilder.constant(catalog)
+//                    )
+//            );
+//        }
+        sqlbuilder.select().where().and(
+                expbuilder.eq(
+                        expbuilder.column(column_CONSTRAINT_TYPE),
+                        expbuilder.constant("PRIMARY KEY")
+                )
+        );
+        return sqlbuilder.toString();
+    }
+        
+    @Override
+    protected void fetchGeometryTypeAndSRS(
+            EditableFeatureAttributeDescriptor attr,
+            ResultSetMetaData rsMetadata,
+            int colIndex
+        ) {
+        if( attr.getType()!=DataTypes.GEOMETRY ) {
+            return;
+        }
+        try {
+            JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
+            ExpressionBuilder expbuilder = sqlbuilder.expression();
+            
+            sqlbuilder.select().column().name("f_table_catalog");
+            sqlbuilder.select().column().name("f_table_schema");
+            sqlbuilder.select().column().name("f_table_name");
+            sqlbuilder.select().column().name("f_geometry_column");
+            sqlbuilder.select().column().name("coord_dimension");
+            sqlbuilder.select().column().name("srid");
+            sqlbuilder.select().column().name("type");
+            sqlbuilder.select().where().set(
+                    expbuilder.eq(
+                            expbuilder.column("f_table_name"),
+                            expbuilder.constant(this.getTable().getTable())
+                    )
+            );                
+            sqlbuilder.select().where().and(
+                    expbuilder.eq(
+                            expbuilder.column("f_geometry_column"),
+                            expbuilder.constant(attr.getName())
+                    )
+            );         
+            sqlbuilder.select().from().table().name("geometry_columns");
+            Statement st = null;
+            ResultSet rs = null;
+            
+            Integer srsid = null;
+            String geometryTypeName = null;
+            try {
+                st = this.getConnection().createStatement();
+                rs = JDBCUtils.executeQuery(st, sqlbuilder.toString());
+                if (rs.next()) {
+                    srsid = rs.getInt("srid");
+                    geometryTypeName = rs.getString("type");
+                }
+            } finally {
+                JDBCUtils.closeQuietly(rs);
+                JDBCUtils.closeQuietly(st);
+            }
+            if( !StringUtils.isEmpty(geometryTypeName) ) {
+                GeometryType gt = getGeometryTypeFromDatabaseTypeName(geometryTypeName);
+                attr.setGeometryType(gt);
+            }
+            if( srsid!=null ) {
+                SRSSolver srssolver = this.helper.getSRSSolver();
+                attr.setSRS(srssolver.getProjection(this.getConnection(),srsid));
+            }
+        } catch (Exception ex) {
+            LOGGER.debug("Can't get geometry type and srs from column '"+attr.getName()+"'.",ex);
+        }
+    }
+
+    private GeometryType getGeometryTypeFromDatabaseTypeName(String typeName) {
+        if( databaseGeometryTypes==null ) {
+            GeometryManager manager = GeometryLocator.getGeometryManager();
+            databaseGeometryTypes = new HashMap<>();
+            databaseGeometryTypes.put("POINT", getGT(manager, Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM2D));
+            databaseGeometryTypes.put("POINTZ", getGT(manager, Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM3D));
+            databaseGeometryTypes.put("POINTM", getGT(manager, Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM2DM));
+            databaseGeometryTypes.put("POINTZM", getGT(manager, Geometry.TYPES.POINT,Geometry.SUBTYPES.GEOM3DM));
+            
+            databaseGeometryTypes.put("LINESTRING", getGT(manager, Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM2D));
+            databaseGeometryTypes.put("LINESTRINGZ", getGT(manager, Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM3D));
+            databaseGeometryTypes.put("LINESTRINGM", getGT(manager, Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM2DM));
+            databaseGeometryTypes.put("LINESTRINGZM", getGT(manager, Geometry.TYPES.LINE,Geometry.SUBTYPES.GEOM3DM));
+            
+            databaseGeometryTypes.put("POLYGON", getGT(manager, Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM2D));
+            databaseGeometryTypes.put("POLYGONZ", getGT(manager, Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM3D));
+            databaseGeometryTypes.put("POLYGONM", getGT(manager, Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM2DM));
+            databaseGeometryTypes.put("POLYGONZM", getGT(manager, Geometry.TYPES.POLYGON,Geometry.SUBTYPES.GEOM3DM));
+
+            databaseGeometryTypes.put("MULTIPOINT", getGT(manager, Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM2D));
+            databaseGeometryTypes.put("MULTIPOINTZ", getGT(manager, Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM3D));
+            databaseGeometryTypes.put("MULTIPOINTM", getGT(manager, Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM2DM));
+            databaseGeometryTypes.put("MULTIPOINTZM", getGT(manager, Geometry.TYPES.MULTIPOINT,Geometry.SUBTYPES.GEOM3DM));
+
+            databaseGeometryTypes.put("MULTILINESTRING", getGT(manager, Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM2D));
+            databaseGeometryTypes.put("MULTILINESTRINGZ", getGT(manager, Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM3D));
+            databaseGeometryTypes.put("MULTILINESTRINGM", getGT(manager, Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM2DM));
+            databaseGeometryTypes.put("MULTILINESTRINGZM", getGT(manager, Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM3DM));
+
+            databaseGeometryTypes.put("MULTIPOLYGON", getGT(manager, Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM2D));
+            databaseGeometryTypes.put("MULTIPOLYGONZ", getGT(manager, Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM3D));
+            databaseGeometryTypes.put("MULTIPOLYGONM", getGT(manager, Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM2DM));
+            databaseGeometryTypes.put("MULTIPOLYGONZM", getGT(manager, Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM3DM));
+
+            databaseGeometryTypes.put("GEOMETRY", getGT(manager, Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM2D));
+            databaseGeometryTypes.put("GEOMETRYZ", getGT(manager, Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM3D));
+            databaseGeometryTypes.put("GEOMETRYM", getGT(manager, Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM2DM));
+            databaseGeometryTypes.put("GEOMETRYZM", getGT(manager, Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM3DM));
+        }
+        return databaseGeometryTypes.get(typeName);
+    }
+    
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/operations/PostgreSQLOperationsFactory.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/operations/PostgreSQLOperationsFactory.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/operations/PostgreSQLOperationsFactory.java	(revision 928)
@@ -0,0 +1,34 @@
+
+package org.gvsig.postgresql.dal.operations;
+
+import java.util.List;
+import org.cresques.cts.IProjection;
+import org.gvsig.fmap.dal.feature.EditableFeatureType;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.FetchFeatureTypeOperation;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.OperationsFactoryBase;
+
+
+public class PostgreSQLOperationsFactory extends OperationsFactoryBase {
+    
+    public PostgreSQLOperationsFactory(JDBCHelper helper) {
+        super(helper);
+    }
+
+    @Override
+    public FetchFeatureTypeOperation createFetchFeatureType(EditableFeatureType type, TableReference table, List<String> primaryKeys, String defaultGeometryField, IProjection crs) {
+        return new PostgreSQLFetchFeatureTypeOperation(
+                helper, type, table, primaryKeys, 
+                defaultGeometryField, crs, -1, -1
+        );
+    }  
+
+    @Override
+    public FetchFeatureTypeOperation createFetchFeatureType(EditableFeatureType type, TableReference table, List<String> primaryKeys, String defaultGeometryField, IProjection crs, int geometryType, int geometrySubtype) {
+        return new PostgreSQLFetchFeatureTypeOperation(
+                helper, type, table, primaryKeys, 
+                defaultGeometryField, crs, geometryType, geometrySubtype
+        );
+    }  
+
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLStoreParameters.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLStoreParameters.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLStoreParameters.java	(revision 928)
@@ -0,0 +1,69 @@
+/* gvSIG. Geographic Information System of the Valencian Government
+*
+* Copyright (C) 2007-2008 Infrastructures and Transports Department
+* of the Valencian Government (CIT)
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+* MA  02110-1301, USA.
+*
+ */
+package org.gvsig.postgresql.dal;
+
+import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
+import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
+
+public class PostgreSQLStoreParameters extends JDBCStoreParameters implements PostgreSQLConnectionParameters {
+
+    private final PostgreSQLConnectionParametersHelper helper;
+    
+    public PostgreSQLStoreParameters() {
+        super(
+                PostgreSQLLibrary.NAME + "StoreParameters",
+                PostgreSQLLibrary.NAME
+        );
+        this.helper = new PostgreSQLConnectionParametersHelper(this);
+    }
+
+    @Override
+    public String getUrl() {
+        return this.helper.getUrl();
+    }
+    
+    @Override
+    public void validate() throws ValidateDataParametersException {
+        this.helper.validate();
+        super.validate();
+    }
+
+    @Override
+    public boolean getUseSSL() {
+        return this.helper.getUseSSL();
+    }
+
+    @Override
+    public int getMaxIdle() {
+        return this.helper.getMaxIdle();
+    }
+
+    public void setUseSSL(boolean v) {
+        this.helper.setUseSSL(v);
+    }
+
+    @Override
+    public int getNetworkTimeout() {
+        return this.helper.getNetworkTimeout();
+    }
+    
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLConnectionParameters.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLConnectionParameters.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLConnectionParameters.java	(revision 928)
@@ -0,0 +1,17 @@
+package org.gvsig.postgresql.dal;
+
+import org.gvsig.fmap.dal.resource.db.DBParameters;
+import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters;
+
+public interface PostgreSQLConnectionParameters extends JDBCConnectionParameters, DBParameters {
+
+    public static final String USESSL_PARAMTER_NAME = "UseSSL";
+    public static final String MAXIDLE_PARAMTER_NAME = "maxIdle";
+    public static final String NETWORK_TIMEOUT = "networkTimeout";
+
+    public boolean getUseSSL();
+
+    public int getMaxIdle();
+
+    public int getNetworkTimeout();
+}
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLConnectionParametersHelper.java
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLConnectionParametersHelper.java	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLConnectionParametersHelper.java	(revision 928)
@@ -0,0 +1,71 @@
+
+package org.gvsig.postgresql.dal;
+
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.fmap.dal.DataParameters;
+import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
+import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters;
+
+
+public class PostgreSQLConnectionParametersHelper {
+
+    private final JDBCConnectionParameters parameters;
+    
+    public PostgreSQLConnectionParametersHelper(JDBCConnectionParameters parameters) {
+        this.parameters = parameters;
+    }
+
+    public String getUrl() {
+        String url = (String) this.getDynValue(JDBCConnectionParameters.URL_PARAMTER_NAME);
+        if( StringUtils.isEmpty(url) ) {
+            url = PostgreSQLHelper.getConnectionURL((PostgreSQLConnectionParameters) this.parameters);
+            this.setDynValue(JDBCConnectionParameters.URL_PARAMTER_NAME,url);
+        }
+        return url;
+    }
+    
+    public void validate() throws ValidateDataParametersException {
+        if (this.getDynValue(JDBCConnectionParameters.JDBC_DRIVER_CLASS_PARAMTER_NAME) == null) {
+            this.setDynValue(
+                JDBCConnectionParameters.JDBC_DRIVER_CLASS_PARAMTER_NAME,
+                PostgreSQLHelper.POSTGRESQL_JDBC_DRIVER
+            );
+        }
+        if( this.getDynValue(JDBCConnectionParameters.PORT_PARAMTER_NAME)==null ) {
+            this.setDynValue(JDBCConnectionParameters.PORT_PARAMTER_NAME, 5432);
+        }
+		if ( StringUtils.isEmpty((CharSequence) this.getDynValue(JDBCConnectionParameters.URL_PARAMTER_NAME))) {
+            String url = PostgreSQLHelper.getConnectionURL(
+                parameters.getHost(),
+                parameters.getPort(),
+                parameters.getDBName()
+            );
+            this.setDynValue(JDBCConnectionParameters.URL_PARAMTER_NAME, url);
+		}
+    }
+
+    private Object getDynValue(String name) {
+        return ((DataParameters)this.parameters).getDynValue(name);
+    }
+    
+    private void setDynValue(String name, Object value) {
+        ((DataParameters)this.parameters).setDynValue(name,value);
+    }
+    
+    public int getMaxIdle() {
+        return (int) this.getDynValue(PostgreSQLConnectionParameters.MAXIDLE_PARAMTER_NAME);
+    }
+
+    public boolean getUseSSL() {
+        return (boolean) this.getDynValue(PostgreSQLConnectionParameters.USESSL_PARAMTER_NAME);
+    }
+
+    public void setUseSSL(boolean v) {
+        this.setDynValue(PostgreSQLConnectionParameters.USESSL_PARAMTER_NAME, v);
+    }
+
+    public int getNetworkTimeout() {
+        return (int) this.getDynValue(PostgreSQLConnectionParameters.NETWORK_TIMEOUT);
+    }
+
+}

Property changes on: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.provider
___________________________________________________________________
Added: svn:ignore
   + target


Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/buildNumber.properties
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/buildNumber.properties	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/buildNumber.properties	(revision 928)
@@ -0,0 +1,2 @@
+#Fri Nov 26 00:53:29 CET 2021
+buildNumber=2239
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml	(revision 928)
@@ -0,0 +1,49 @@
+<assembly>
+  <id>gvsig-plugin-package</id>
+  <formats>
+    <format>zip</format>
+  </formats>
+  <baseDirectory>${project.artifactId}</baseDirectory>
+  <includeBaseDirectory>true</includeBaseDirectory>
+  <files>
+    <file>
+      <source>target/${project.artifactId}-${project.version}.jar</source>
+      <outputDirectory>lib</outputDirectory>
+    </file>
+    <file>
+      <source>target/package.info</source>
+    </file>
+    <file>
+      <source>src/main/resources-plugin/config.xml</source>
+    </file>
+  </files>
+
+  <dependencySets>
+  
+    <dependencySet>
+      <useProjectArtifact>false</useProjectArtifact>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+      <outputDirectory>lib</outputDirectory>
+      <includes>
+        <include>org.gvsig:org.gvsig.postgresql.provider</include>
+      </includes>
+    </dependencySet>
+    
+    <dependencySet>
+      <useProjectArtifact>false</useProjectArtifact>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+      <outputDirectory>lib</outputDirectory>
+      <includes>
+		<include>org.postgresql:postgresql</include>
+		<include>org.apache.commons:commons-dbcp2</include>
+		<include>org.apache.commons:commons-pool2</include>
+      </includes>
+    </dependencySet>
+    
+  </dependencySets>
+
+</assembly>
+
+
+
+
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/resources-plugin/i18n/text.properties
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/resources-plugin/i18n/text.properties	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/resources-plugin/i18n/text.properties	(revision 928)
@@ -0,0 +1 @@
+_PostgreSQL_loading_parameters=Par\u00e1metros de carga de PostgreSQL
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties	(revision 928)
@@ -0,0 +1 @@
+_PostgreSQL_loading_parameters=PostgreSQL loading parameters
\ No newline at end of file
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/resources-plugin/config.xml
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/resources-plugin/config.xml	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/resources-plugin/config.xml	(revision 928)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<plugin-config>
+  <libraries library-dir="lib/"/>
+  <depends plugin-name="org.gvsig.app.mainplugin"/>
+  <resourceBundle name="text"/>
+  <extensions>
+     <extension class-name="org.gvsig.andami.LibraryExtension" active="false"/>
+  </extensions>    
+</plugin-config>
Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/pom.xml
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/pom.xml	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/pom.xml	(revision 928)
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>org.gvsig.postgresql.app.mainplugin</artifactId>
+  <packaging>jar</packaging>
+  <name>${project.artifactId}</name>
+  <description>PostgreSQL file format support</description>
+
+  <parent>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.postgresql.app</artifactId>
+      <version>2.0.182</version>
+  </parent>
+
+  <dependencies>
+    <dependency>
+        <groupId>org.gvsig</groupId>
+        <artifactId>org.gvsig.tools.lib</artifactId>
+        <scope>compile</scope>
+    </dependency>
+    <dependency>
+        <groupId>org.gvsig</groupId>
+        <artifactId>org.gvsig.andami</artifactId>
+        <scope>compile</scope>
+    </dependency>
+    <dependency>
+        <groupId>org.gvsig</groupId>
+        <artifactId>org.gvsig.postgresql.provider</artifactId>
+        <scope>compile</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.postgresql</groupId>
+      <artifactId>postgresql</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-dbcp2</artifactId>
+      <scope>runtime</scope>
+    </dependency>    
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-pool2</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+
+  </dependencies>
+  
+    <properties>
+        <!-- Package info property values -->
+        <!-- Default values in org.gvsig.desktop -->
+        <gvsig.package.info.name>Formats: PostgreSQL support</gvsig.package.info.name>
+        <gvsig.package.info.state>testing</gvsig.package.info.state>
+        <gvsig.package.info.official>true</gvsig.package.info.official>
+        <gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.0.1</gvsig.package.info.dependencies>
+        <gvsig.package.info.categories>Formats,Vector,Database</gvsig.package.info.categories>
+        <gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-postgresql/pool/</gvsig.package.info.poolURL>
+    </properties>
+  
+
+</project>

Property changes on: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin
___________________________________________________________________
Added: svn:ignore
   + target
.buildNumber.properties.swp


Index: tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/pom.xml
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/pom.xml	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/org.gvsig.postgresql.app/pom.xml	(revision 928)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>org.gvsig.postgresql.app</artifactId>
+  <packaging>pom</packaging>
+  <name>${project.artifactId}</name>
+  <parent>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.postgresql</artifactId>
+      <version>2.0.182</version>
+  </parent>
+
+  <modules>
+    <module>org.gvsig.postgresql.app.mainplugin</module>
+    <!--
+    <module>org.gvsig.postgresql.app.export</module>
+    -->
+  </modules>
+
+</project>
Index: tags/org.gvsig.postgresql-2.0.182/pom.xml
===================================================================
--- tags/org.gvsig.postgresql-2.0.182/pom.xml	(revision 0)
+++ tags/org.gvsig.postgresql-2.0.182/pom.xml	(revision 928)
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>org.gvsig.postgresql</artifactId>
+  <version>2.0.182</version>
+  <packaging>pom</packaging>
+  <name>${project.artifactId}</name>
+  <description>PostgreSQL support fort DAL and gvSIG</description>
+  <parent>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.desktop</artifactId>
+      <version>2.0.343</version>
+  </parent>
+
+  <url>https://devel.gvsig.org/redmine/projects/gvsig-postgresql</url>
+  <scm>
+      <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-postgresql/tags/org.gvsig.postgresql-2.0.182</connection>
+      <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-postgresql/tags/org.gvsig.postgresql-2.0.182</developerConnection>
+      <url>https://devel.gvsig.org/redmine/projects/gvsig-postgresql/repository/show/tags/org.gvsig.postgresql-2.0.182</url>
+  </scm>
+
+    <repositories>
+        <repository>
+            <id>gvsig-public-http-repository</id>
+            <name>gvSIG maven public HTTP repository</name>
+            <url>http://devel.gvsig.org/m2repo/j2se</url>
+            <releases>
+                <enabled>true</enabled>
+                <updatePolicy>daily</updatePolicy>
+                <checksumPolicy>warn</checksumPolicy>
+            </releases>
+            <snapshots>
+                <enabled>true</enabled>
+                <updatePolicy>daily</updatePolicy>
+                <checksumPolicy>warn</checksumPolicy>
+            </snapshots>
+        </repository>
+    </repositories>
+  
+  
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-release-plugin</artifactId>
+				<configuration>
+					<tagBase>https://devel.gvsig.org/svn/gvsig-postgresql/tags/</tagBase>
+					<goals>deploy</goals>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+
+  <dependencyManagement>
+      <dependencies>
+          <dependency>
+            <groupId>org.gvsig</groupId>
+            <artifactId>org.gvsig.postgresql.provider</artifactId>
+            <version>2.0.182</version>
+          </dependency>
+          <dependency>
+            <groupId>org.gvsig</groupId>
+            <artifactId>org.gvsig.postgresql.app.mainplugin</artifactId>
+            <version>2.0.182</version>
+          </dependency>
+        <dependency>
+            <groupId>org.postgresql</groupId>
+            <artifactId>postgresql</artifactId>
+            <version>42.3.1</version>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.commons</groupId>
+          <artifactId>commons-dbcp2</artifactId>
+          <version>2.7.0</version>
+        </dependency>   
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-pool2</artifactId>
+            <version>2.7.0</version>
+        </dependency>
+      </dependencies>
+  </dependencyManagement>
+ 
+  <modules>
+    <module>org.gvsig.postgresql.app</module>
+    <module>org.gvsig.postgresql.provider</module>
+  </modules>
+
+</project>

Property changes on: tags/org.gvsig.postgresql-2.0.182
___________________________________________________________________
Added: svn:ignore
   + .pom.xml.swp
.directory


