Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/pom.xml
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/pom.xml	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/pom.xml	(revision 262)
@@ -0,0 +1,19 @@
+<?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.mssqlserver.app</artifactId>
+  <packaging>pom</packaging>
+  <name>${project.artifactId}</name>
+  <parent>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.mssqlserver</artifactId>
+      <version>1.0.46</version>
+  </parent>
+
+  <modules>
+    <module>org.gvsig.mssqlserver.app.mainplugin</module>
+  </modules>
+
+</project>
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/buildNumber.properties
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/buildNumber.properties	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/buildNumber.properties	(revision 262)
@@ -0,0 +1,2 @@
+#Fri Nov 01 02:08:38 CET 2019
+buildNumber=48
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml	(revision 262)
@@ -0,0 +1,55 @@
+<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>
+  <fileSets>
+    <fileSet>
+      <directory>src/main/resources-plugin</directory>
+      <outputDirectory>.</outputDirectory>
+    </fileSet>
+  </fileSets>
+  <dependencySets>
+
+    <dependencySet>
+      <useProjectArtifact>false</useProjectArtifact>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+      <outputDirectory>lib</outputDirectory>
+      <includes>
+        <include>org.gvsig:org.gvsig.mssqlserver.provider</include>
+      </includes>
+    </dependencySet>
+
+    <dependencySet>
+      <useProjectArtifact>false</useProjectArtifact>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+      <outputDirectory>lib</outputDirectory>
+      <includes>
+		<include>com.microsoft.sqlserver:sqlserver-jdbc</include>
+		<include>commons-dbcp:commons-dbcp</include>
+		<include>commons-collections:commons-collections</include>
+		<include>commons-pool:commons-pool</include>
+      </includes>
+    </dependencySet>
+
+  </dependencySets>
+
+</assembly>
+
+
+
+
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/java/org/gvsig/mssqlserver/MSSQLServerExtension.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/java/org/gvsig/mssqlserver/MSSQLServerExtension.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/java/org/gvsig/mssqlserver/MSSQLServerExtension.java	(revision 262)
@@ -0,0 +1,38 @@
+
+package org.gvsig.mssqlserver;
+
+import org.gvsig.andami.IconThemeHelper;
+import org.gvsig.andami.plugins.Extension;
+import org.gvsig.fmap.mapcontext.MapContextLocator;
+import org.gvsig.fmap.mapcontext.MapContextManager;
+
+
+public class MSSQLServerExtension  extends Extension {
+
+    @Override
+    public void initialize() {
+    }
+
+    @Override
+    public void postInitialize() {
+        MapContextManager mapContextMgr = MapContextLocator.getMapContextManager();
+        
+        IconThemeHelper.registerIcon("layer", "layer-icon-mssqlserver", this);
+        mapContextMgr.registerIconLayer("MSSQLServer", "layer-icon-mssqlserver");
+    }
+    
+    @Override
+    public void execute(String actionCommand) {
+    }
+
+    @Override
+    public boolean isEnabled() {
+        return false;
+    }
+
+    @Override
+    public boolean isVisible() {
+        return false;
+    }
+    
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/resources-plugin/readme_es.txt
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/resources-plugin/readme_es.txt	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/resources-plugin/readme_es.txt	(revision 262)
@@ -0,0 +1,106 @@
+
+Notas acerca de la implementacion del proveedor de MS SQLServer.
+====================================================================
+
+Software
+----------
+
+Las pruebas realizadas durante el desarrollo se han hecho sobre:
+
+- Microsoft SQL Server Express 2014 (64-bit), versión 12.0.2000.8
+- Microsoft Windows NT 6.3 (9600), plataforma NT x64
+
+El acceso al servidor se realiza a traves de JDBC usando el driver:
+
+- Microsoft JDBC Driver 6.0 for SQL Server, may 2016 (sqljdbc42.jar).
+
+Configuración
+--------------
+
+Las pruebas se han realizado usando la instancia por defecto "SQLEXPRESS".
+
+Para poder acceder al servidor es necesario:
+
+- Habilitar la conexion al servidor a traves de TCP/IP. Esto se activara
+  desde:
+  - Sql Server Configuration Manager
+  - Configuracion de red de SQL Server
+  - Protocolos de SQLEXPRESS
+  - TCP/IP
+   - General
+     - Habilitado: Si
+   - Direcciones IP
+     - IP4
+       - Activo: Si
+       - Habilitado: Si
+
+- Deberan estar "En ejecucion" los servicios de:
+  - SQL Server (SQLEXPRESS)
+  - SQL Server Browser.
+    Este servicio es necesario para poder aceptar conexiones TCP/IP contra el
+    servidor y por defecto, tras la instalacion de MS SQL Sever, no se iniciaba
+    automaticamente en mi equipo.
+
+- Durante todas las pruebas se ha utilizado "Autenticación de SQL Server".
+  Es posible que para otros tipos de autenticación sea necesario incluir alguna
+  otra libreria (como sqljdbc_auth.dll x64/x86).
+
+Soporte espacial
+-------------------
+
+Siempre que se exporta a BBDD se utilizara el tipo "geometry" para crear los
+campos de tipo geometria, y en general se usara siempre este tipo de datos.
+
+Se ha implementado un soporte limitado para el tipo de datos "geography". Si una
+tabla contiene un campo de este tipo se leera y gvSIG podra trabajar con el. Si
+una tabla contiene mas de un campo de tipo geometria siendo estos de tipos distintos,
+unos "geometry" y otros "geography", gvSIG puede dar problemas para acceder a estos,
+especialmente al de tipo "geography".
+
+Ahora mismo el tipo de geometria asociado a una columna de la BBDD es GEOMETRY,
+es decir, no se sabe si es punto, linea o poligono.
+
+Sistemas de referencia
+------------------------
+
+La lista de sistemas de referencia disponibles esta almacenada en la tabla
+sys.spatial_reference_systems, y solo tiene definidas unos 390 sistemas
+de referencia. Habria que averiguar cargar otros sistemas de referencia.
+
+Valores por defecto
+---------------------
+
+Los datos de conexion por defecto son:
+
+- Host: 127.0.0.1
+- Instance: SQLEXPRESS
+- Database: master
+- Schema: dbo
+- user: sa
+- password: 123
+
+Los valores instance, database, schema y user se corresponden con valores
+validos para una instalacion por defecto de SQL Server.
+
+Problemas conocidos
+--------------------
+
+- No se guardan los datos de la conexion entre sesiones de gvSIG.
+
+- La herramienta "Selection by layer" no funciona.
+
+- Si una capa de gvSIG declara un campo "double" con precision y size,
+  al expportarlo a BBDD lo exporta como "DOUBLE PRECISION" en lugar de como
+  "NUMERIC(size,precision)".
+
+- No se estan creando indices sobre los campos al exportar a BBDD.
+
+- En la exportacion a BBDD, en el paso que pide el nombre de la tabla,
+  primero muestra como esquema "public" y cuando termina de leer las tablas
+  de la BBDD para mostrarlas (tarda unos segundos) cambia de public a "dbo".
+  Esto puede causar problemas si el usuario pulsa en siguiente antes de que se
+  haya actualizado el esquema con el que se corresponde con la BBDD ya que
+  intentaria crear la tabla en el esquema "public" y este no existe en SQLServer.
+
+- Solo se ha implememtado soporte para geometrias 2D (no 3D, 2DM o 3DM).
+
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/resources-plugin/mssqlserver-jdbc-driver-license60.txt
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/resources-plugin/mssqlserver-jdbc-driver-license60.txt	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/resources-plugin/mssqlserver-jdbc-driver-license60.txt	(revision 262)
@@ -0,0 +1,169 @@
+MICROSOFT SOFTWARE LICENSE TERMS
+
+MICROSOFT JDBC DRIVER 6.0 FOR SQL SERVER
+
+These license terms are an agreement between Microsoft Corporation (or based on where you 
+live, one of its affiliates) and you. Please read them. They apply to the software 
+named above, which includes the media on which you received it, if any. The terms also apply to 
+any Microsoft
+
+• updates,
+• supplements,
+• Internet-based services, and
+• support services
+
+for this software, unless other terms accompany those items. If so, those terms apply.
+
+BY USING THE SOFTWARE, YOU ACCEPT THESE TERMS. IF YOU DO NOT 
+ACCEPT THEM, DO NOT USE THE SOFTWARE.
+
+If you comply with these license terms, you have the rights below.
+
+1. INSTALLATION AND USE RIGHTS. 
+
+a. Installation and Use.
+
+i. You may install and use any number of copies of the software on your devices.
+
+b. Third Party Programs. The software may include third party programs that Microsoft, 
+not the third party, licenses to you under this agreement. Notices, if any, for the third 
+party program are included for your information only.
+
+2. ADDITIONAL LICENSING REQUIREMENTS AND/OR USE RIGHTS.
+
+a. Distributable Code.
+
+i.	Right to Use and Distribute. You are permitted to distribute the software in programs you 
+develop if you comply with the terms below:
+
+* You may copy and distribute the object code form of the software (“Distributable Code”) in 
+programs you develop. You may not modify the software.
+* You may permit distributors of your programs to copy and distribute the Distributable Code 
+as part of those programs.
+ii.	Distribution Requirements. For any Distributable Code you distribute, you must
+* add significant primary functionality to it in your programs;
+* require distributors and external end users to agree to terms that protect it at least as 
+much as this agreement;
+* display your valid copyright notice on your programs; and
+* indemnify, defend, and hold harmless Microsoft from any claims, including attorneys’ fees, 
+related to the distribution or use of your programs.
+iii.	Distribution Restrictions. You may not
+* alter any copyright, trademark or patent notice in the Distributable Code;
+* use Microsoft’s trademarks in your programs’ names or in a way that suggests your programs 
+come from or are endorsed by Microsoft;
+* include Distributable Code in malicious, deceptive or unlawful programs; or
+* modify or distribute the source code of any Distributable Code so that any part of it 
+becomes subject to an Excluded License. An Excluded License is one that requires, as a 
+condition of use, modification or distribution, that
+* the code be disclosed or distributed in source code form; or
+* others have the right to modify it.
+
+
+3. SCOPE OF LICENSE. The software is licensed, not sold. This agreement only gives you 
+some rights to use the software. Microsoft reserves all other rights. Unless applicable law 
+gives you more rights despite this limitation, you may use the software only as expressly 
+permitted in this agreement. In doing so, you must comply with any technical limitations in 
+the software that only allow you to use it in certain ways. You may not
+
+• work around any technical limitations in the software;
+• reverse engineer, decompile or disassemble the software, except and only to the extent 
+that applicable law expressly permits, despite this limitation;
+• make more copies of the software than specified in this agreement or allowed by 
+applicable law, despite this limitation;
+• publish the software for others to copy;
+• rent, lease or lend the software;
+• transfer the software or this agreement to any third party; or
+• use the software for commercial software hosting services.
+
+4. EXPORT RESTRICTIONS. The software is subject to United States export laws and 
+regulations. You must comply with all domestic and international export laws and 
+regulations that apply to the software. These laws include restrictions on destinations, end 
+users and end use. For additional information, see www.microsoft.com/exporting.
+
+5. SUPPORT SERVICES. Because this software is “as is,” we may not provide support 
+services for it.
+
+6. ENTIRE AGREEMENT. This agreement, and the terms for supplements, updates, Internet-
+based services and support services that you use, are the entire agreement for the software 
+and support services.
+
+7. APPLICABLE LAW.
+
+a. United States. If you acquired the software in the United States, Washington state law 
+governs the interpretation of this agreement and applies to claims for breach of it, 
+regardless of conflict of laws principles. The laws of the state where you live govern all 
+other claims, including claims under state consumer protection laws, unfair competition 
+laws, and in tort.
+
+b. Outside the United States. If you acquired the software in any other country, the laws of 
+that country apply.
+
+8. LEGAL EFFECT. This agreement describes certain legal rights. You may have other rights 
+under the laws of your country. You may also have rights with respect to the party from 
+whom you acquired the software. This agreement does not change your rights under the laws 
+of your country if the laws of your country do not permit it to do so.
+
+9. DISCLAIMER OF WARRANTY. THE SOFTWARE IS LICENSED “AS-IS.” YOU 
+BEAR THE RISK OF USING IT. MICROSOFT GIVES NO EXPRESS 
+WARRANTIES, GUARANTEES OR CONDITIONS. YOU MAY HAVE 
+ADDITIONAL CONSUMER RIGHTS UNDER YOUR LOCAL LAWS WHICH THIS 
+AGREEMENT CANNOT CHANGE. TO THE EXTENT PERMITTED UNDER 
+YOUR LOCAL LAWS, MICROSOFT EXCLUDES THE IMPLIED WARRANTIES 
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-
+INFRINGEMENT.
+
+10. LIMITATION ON AND EXCLUSION OF REMEDIES AND DAMAGES. YOU CAN 
+RECOVER FROM MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP 
+TO U.S. $5.00. YOU CANNOT RECOVER ANY OTHER DAMAGES, INCLUDING 
+CONSEQUENTIAL, LOST PROFITS, SPECIAL, INDIRECT OR INCIDENTAL 
+DAMAGES.
+
+This limitation applies to
+
+• anything related to the software, services, content (including code) on third party Internet 
+sites, or third party programs, and
+• claims for breach of contract, breach of warranty, guarantee or condition, strict liability, 
+negligence, or other tort to the extent permitted by applicable law.
+
+It also applies even if Microsoft knew or should have known about the possibility of the 
+damages. The above limitation or exclusion may not apply to you because your country may 
+not allow the exclusion or limitation of incidental, consequential or other damages.
+
+Please note: As this software is distributed in Quebec, Canada, some of the clauses in this 
+agreement are provided below in French.
+
+Remarque : Ce logiciel étant distribué au Québec, Canada, certaines des clauses dans ce 
+contrat sont fournies ci-dessous en français.
+
+EXONÉRATION DE GARANTIE. Le logiciel visé par une licence est offert « tel quel ». 
+Toute utilisation de ce logiciel est à votre seule risque et péril. Microsoft n’accorde aucune 
+autre garantie expresse. Vous pouvez bénéficier de droits additionnels en vertu du droit local 
+sur la protection des consommateurs, que ce contrat ne peut modifier. La ou elles sont 
+permises par le droit locale, les garanties implicites de qualité marchande, d’adéquation à un 
+usage particulier et d’absence de contrefaçon sont exclues.
+
+LIMITATION DES DOMMAGES-INTÉRÊTS ET EXCLUSION DE 
+RESPONSABILITÉ POUR LES DOMMAGES. Vous pouvez obtenir de Microsoft et de 
+ses fournisseurs une indemnisation en cas de dommages directs uniquement à hauteur de 5,00 
+$ US. Vous ne pouvez prétendre à aucune indemnisation pour les autres dommages, y 
+compris les dommages spéciaux, indirects ou accessoires et pertes de bénéfices.
+
+Cette limitation concerne :
+• tout ce qui est relié au logiciel, aux services ou au contenu (y compris le code) figurant 
+sur des sites Internet tiers ou dans des programmes tiers ; et
+• les réclamations au titre de violation de contrat ou de garantie, ou au titre de 
+responsabilité stricte, de négligence ou d’une autre faute dans la limite autorisée par la loi 
+en vigueur.
+
+Elle s’applique également, même si Microsoft connaissait ou devrait connaître l’éventualité 
+d’un tel dommage. Si votre pays n’autorise pas l’exclusion ou la limitation de responsabilité 
+pour les dommages indirects, accessoires ou de quelque nature que ce soit, il se peut que la 
+limitation ou l’exclusion ci-dessus ne s’appliquera pas à votre égard.
+
+EFFET JURIDIQUE. Le présent contrat décrit certains droits juridiques. Vous pourriez avoir 
+d’autres droits prévus par les lois de votre pays. Le présent contrat ne modifie pas les droits 
+que vous confèrent les lois de votre pays si celles-ci ne le permettent pas.
+
+
+
+
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/resources-plugin/config.xml
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/resources-plugin/config.xml	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/resources-plugin/config.xml	(revision 262)
@@ -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.mssqlserver.MSSQLServerExtension" active="true"/>
+  </extensions>    
+</plugin-config>
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/resources-plugin/images/layer/layer-icon-mssqlserver.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/resources-plugin/images/layer/layer-icon-mssqlserver.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/pom.xml
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/pom.xml	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/pom.xml	(revision 262)
@@ -0,0 +1,74 @@
+<?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.mssqlserver.app.mainplugin</artifactId>
+  <packaging>jar</packaging>
+  <name>${project.artifactId}</name>
+  <description>MS SQLServer support</description>
+
+  <parent>
+      <groupId>org.gvsig</groupId>
+      <artifactId>org.gvsig.mssqlserver.app</artifactId>
+      <version>1.0.46</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.fmap.mapcontext.api</artifactId>
+        <scope>compile</scope>
+    </dependency>
+    <dependency>
+        <groupId>org.gvsig</groupId>
+        <artifactId>org.gvsig.mssqlserver.provider</artifactId>
+        <scope>compile</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>com.microsoft.sqlserver</groupId>
+      <artifactId>sqlserver-jdbc</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-dbcp</groupId>
+      <artifactId>commons-dbcp</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-pool</groupId>
+      <artifactId>commons-pool</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+  </dependencies>
+
+    <properties>
+        <!-- Package info property values -->
+        <!-- Default values in org.gvsig.desktop -->
+        <gvsig.package.info.name>Formats: MS SQLServer 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.javaVM>j1_8</gvsig.package.info.javaVM>
+        <gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.3.0</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-mssqlserver/pool/</gvsig.package.info.poolURL>
+    </properties>
+
+
+</project>

Property changes on: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin
___________________________________________________________________
Added: svn:ignore
   + target


Index: tags/org.gvsig.mssqlserver-1.0.46/pom.xml
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/pom.xml	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/pom.xml	(revision 262)
@@ -0,0 +1,83 @@
+<?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.mssqlserver</artifactId>
+    <version>1.0.46</version>
+    <packaging>pom</packaging>
+    <name>${project.artifactId}</name>
+    <description>MS SQLServer support fort DAL and gvSIG</description>
+    <parent>
+        <groupId>org.gvsig</groupId>
+        <artifactId>org.gvsig.desktop</artifactId>
+        <version>2.0.256</version>
+    </parent>
+
+    <url>https://devel.gvsig.org/redmine/projects/gvsig-mssqlserver</url>
+    <scm>
+        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-mssqlserver/tags/org.gvsig.mssqlserver-1.0.46</connection>
+        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-mssqlserver/tags/org.gvsig.mssqlserver-1.0.46</developerConnection>
+        <url>https://devel.gvsig.org/redmine/projects/gvsig-mssqlserver/repository/show/tags/org.gvsig.mssqlserver-1.0.46</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-mssqlserver/tags/</tagBase>
+                    <goals>deploy</goals>
+                </configuration>
+            </plugin>                     
+        </plugins>
+    </build>
+
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.gvsig</groupId>
+                <artifactId>org.gvsig.mssqlserver.provider</artifactId>
+                <version>1.0.46</version>
+            </dependency>
+            <dependency>
+                <groupId>org.gvsig</groupId>
+                <artifactId>org.gvsig.mssqlserver.app.mainplugin</artifactId>
+                <version>1.0.46</version>
+            </dependency>
+            <dependency>
+                <groupId>com.microsoft.sqlserver</groupId>
+                <artifactId>sqlserver-jdbc</artifactId>
+                <version>6.0.0</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+  
+    <modules>
+        <module>org.gvsig.mssqlserver.app</module>
+        <module>org.gvsig.mssqlserver.provider</module>
+    </modules>
+
+
+</project>
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/test/java/org/gvsig/mssqlserver/dal/MSSQLServerSQLBuilderTest.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/test/java/org/gvsig/mssqlserver/dal/MSSQLServerSQLBuilderTest.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/test/java/org/gvsig/mssqlserver/dal/MSSQLServerSQLBuilderTest.java	(revision 262)
@@ -0,0 +1,540 @@
+package org.gvsig.mssqlserver.dal;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.lang3.ArrayUtils;
+import org.cresques.cts.IProjection;
+import org.gvsig.fmap.crs.CRSFactory;
+import org.gvsig.fmap.dal.DALLocator;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Parameter;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Variable;
+import org.gvsig.fmap.dal.SQLBuilder;
+import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
+import org.gvsig.fmap.dal.store.db.DBHelper;
+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 static org.gvsig.mssqlserver.dal.MSSQLServerLibrary.NAME;
+import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
+
+public class MSSQLServerSQLBuilderTest extends AbstractLibraryAutoInitTestCase {
+
+    private MSSQLServerHelper helper;
+    
+    @Override
+    protected void doSetUp() throws Exception {
+        DataManagerProviderServices dataman = 
+                (DataManagerProviderServices) DALLocator.getDataManager();
+
+        DBHelper.registerParametersDefinition(
+                NAME + "StoreParameters",
+                MSSQLServerStoreParameters.class,
+                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
+        );
+        
+        MSSQLServerStoreParameters params = new MSSQLServerStoreParameters();
+        params.setHost("127.0.0.1");
+        params.setDynValue("InstanceName", "SQLEXPRESS");
+        params.setDBName("master");
+        params.setSchema("dbo");
+        params.setTable("test1");
+        params.setPort(1433);
+        params.setUser("sa");
+        params.setPassword("123");
+        helper = new MSSQLServerHelper(params);
+    }
+    
+    
+    public SQLBuilder createSQLBuilder() {
+        return new MSSQLServerSQLBuilder(helper);
+    }
+ 
+    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();
+        ExpressionBuilder 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").add( expbuilder.variable("x") )
+        );
+        
+        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()));
+    
+        //# Test:: testCalulateEnvelope
+        //# SQL:: SELECT (geometry::EnvelopeAggregate([the_geom])).STAsBinary() AS [envelope] FROM [master].[dbo].[test1] WHERE (([the_geom]).STEnvelope()).STIntersects(geometry::STGeomFromWKB(0x000000000300000001000000050000000000000000000000000000000000000000000000004059000000000000405900000000000040590000000000004059000000000000000000000000000000000000000000000000000000000000, 4326)) AND x = 27
+        //# Variables:: [the_geom, x]
+        //# Parametros:: []    
+        assertEquals(
+                "SELECT (geometry::EnvelopeAggregate([the_geom])).STAsBinary() AS [envelope] FROM [master].[dbo].[test1] WHERE (([the_geom]).STEnvelope()).STIntersects(geometry::STGeomFromWKB(0x000000000300000001000000050000000000000000000000000000000000000000000000004059000000000000405900000000000040590000000000004059000000000000000000000000000000000000000000000000000000000000, 4326)) AND x = 27",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[the_geom, x]",
+                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").add(expbuilder.variable("pp")));
+
+        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 [master].[dbo].[test1] WHERE pp = 200
+        //# Variables:: []
+        //# Parametros:: []
+    
+        assertEquals(
+                "SELECT COUNT(*) FROM [master].[dbo].[test1] WHERE pp = 200",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[pp]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+    
+    public void testUpdateStatistics() throws Exception {
+        SQLBuilder sqlbuilder = createSQLBuilder();
+        ExpressionBuilder expbuilder = sqlbuilder.expression();
+        
+        sqlbuilder.update_table_statistics().table().database("master").schema("dbo").name("test1");
+
+        System.out.println("# Test:: testUpdateStatistics");
+        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:: testUpdateStatistics
+        //# SQL:: UPDATE STATISTICS [master].[dbo].[test1]
+        //# Variables:: []
+        //# Parametros:: []
+    
+        assertEquals(
+                "UPDATE STATISTICS [master].[dbo].[test1]",
+                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,
+                false,
+                false,
+                true,
+                false,
+                null
+        );
+        sqlbuilder.create_table().add_column(
+                "id",
+                DataTypes.INT,
+                0,
+                0,
+                true,
+                false,
+                false,
+                true,
+                0
+        );
+        sqlbuilder.create_table().add_column(
+                "geom",
+                DataTypes.GEOMETRY,
+                0,
+                0,
+                false,
+                false,
+                true,
+                false,
+                null
+        );
+
+        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()));
+
+        //# Test:: testCreateTable
+        //# SQL:: CREATE TABLE [master].[dbo].[test1] ([name] VARCHAR(45) DEFAULT NULL NULL, [id] INT IDENTITY(1,1) DEFAULT '0' NOT NULL PRIMARY KEY, [geom] GEOMETRY DEFAULT NULL NULL )
+        //# Variables:: []
+        //# Parametros:: []
+
+        assertEquals(
+                "CREATE TABLE [master].[dbo].[test1] ([name] VARCHAR(45) DEFAULT NULL NULL, [id] INT IDENTITY(1,1) DEFAULT '0' NOT NULL PRIMARY KEY, [geom] GEOMETRY DEFAULT NULL NULL )",
+                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");
+
+        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()));
+
+        //# Test:: testDropTable
+        //# SQL:: DROP TABLE [master].[dbo].[test1]
+        //# Variables:: []
+        //# Parametros:: []
+        
+        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 = createSQLBuilder();
+        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);
+
+        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()));
+
+        //# Test:: testFetchFeatureProviderByReference
+        //# SQL:: SELECT TOP 1 [name], [id], ([geom]).STAsBinary() FROM [master].[dbo].[test1] WHERE ( ([name]) = (?) )
+        //# Variables:: [geom, id, name]
+        //# Parametros:: ['yoyo']
+
+        assertEquals(
+                "SELECT TOP 1 [name], [id], ([geom]).STAsBinary() FROM [master].[dbo].[test1] WHERE ( ([name]) = (?) )",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[geom, id, name]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "['yoyo']",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+    
+    public void testIsNull() throws Exception {
+        SQLBuilder sqlbuilder = createSQLBuilder();
+        ExpressionBuilder expbuilder = sqlbuilder.expression();
+        
+        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.and(
+                expbuilder.is_null(
+                    expbuilder.column("name")
+                ),
+                expbuilder.not_is_null(
+                    expbuilder.column("id")
+                )
+            )
+        );
+        sqlbuilder.select().limit(2);
+
+        System.out.println("# Test:: testIsNull");
+        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:: testIsNull
+        //# SQL:: SELECT TOP 2 [name], [id], ([geom]).STAsBinary() FROM [master].[dbo].[test1] WHERE ( ([name]) IS NULL ) AND ( ([id]) NOT IS NULL )
+        //# Variables:: [geom, id, name]
+        //# Parametros:: []
+
+        assertEquals(
+                "SELECT TOP 2 [name], [id], ([geom]).STAsBinary() FROM [master].[dbo].[test1] WHERE ( ([name]) IS NULL ) AND ( ([id]) NOT IS NULL )",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[geom, id, name]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[]",
+                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 TOP 1 * FROM [master].[dbo].[test1]
+        //# Variables:: []
+        //# Parametros:: []
+    
+        assertEquals(
+                "SELECT TOP 1 * FROM [master].[dbo].[test1]",
+                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()
+            )
+        );
+
+        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()));
+
+        //# Test:: testPerformDeletes
+        //# SQL:: DELETE FROM [master].[dbo].[test1] WHERE ( ([id1]) = (?) ) AND ( ([id2]) = (?) )
+        //# Variables:: [id1, id2]
+        //# Parametros:: ["id1", "id2"]
+
+        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();
+        ExpressionBuilder 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()));
+
+        //# Test:: testPerformInserts1
+        //# SQL:: INSERT INTO [master].[dbo].[test1] ( [id], [name], [geom] ) VALUES ( ?, ?, geometry::STGeomFromWKB(?, 4326) )
+        //# Variables:: [geom, id, name]
+        //# Parametros:: ["id", "name", "geom"]
+        
+        assertEquals(
+                "INSERT INTO [master].[dbo].[test1] ( [id], [name], [geom] ) VALUES ( ?, ?, geometry::STGeomFromWKB(?, 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();
+        ExpressionBuilder 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()));
+    
+        //# Test:: testPerformInserts2
+        //# SQL:: INSERT INTO [master].[dbo].[test1] ( [id], [name], [geom] ) VALUES ( ?, ?, geometry::STGeomFromWKB(?, ?) )
+        //# Variables:: [geom, id, name]
+        //# Parametros:: ["id", "name", "geom", 4326]
+
+        assertEquals(
+                "INSERT INTO [master].[dbo].[test1] ( [id], [name], [geom] ) VALUES ( ?, ?, geometry::STGeomFromWKB(?, ?) )",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[geom, id, name]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[\"id\", \"name\", \"geom\", 4326]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+
+    public void testPerformUpdates() throws Exception {
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+
+        SQLBuilder sqlbuilder = createSQLBuilder();
+        ExpressionBuilder 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()));
+
+        //# Test:: testPerformUpdates
+        //# SQL:: UPDATE [master].[dbo].[test1] SET [name] = ?, [geom] = geometry::STGeomFromWKB(?, ?) WHERE ( ([id]) = (?) )
+        //# Variables:: [geom, id, name]
+        //# Parametros:: ["name", "geom", 4326, "id"]
+
+        assertEquals(
+                "UPDATE [master].[dbo].[test1] SET [name] = ?, [geom] = geometry::STGeomFromWKB(?, ?) WHERE ( ([id]) = (?) )",
+                sqlbuilder.toString()
+        );
+        assertEquals(
+                "[geom, id, name]",
+                ArrayUtils.toString(sqlbuilder.variables_names())
+        );
+        assertEquals(
+                "[\"name\", \"geom\", 4326, \"id\"]",
+                ArrayUtils.toString(sqlbuilder.parameters_names())
+        );
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/test/java/org/gvsig/fmap/dal/store/jdbc2/SQLBuilderTest.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/test/java/org/gvsig/fmap/dal/store/jdbc2/SQLBuilderTest.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/test/java/org/gvsig/fmap/dal/store/jdbc2/SQLBuilderTest.java	(revision 262)
@@ -0,0 +1,488 @@
+//package org.gvsig.fmap.dal.store.jdbc2;
+//
+//import java.util.ArrayList;
+//import java.util.List;
+//import org.apache.commons.lang3.ArrayUtils;
+//import org.cresques.cts.IProjection;
+//import org.gvsig.fmap.crs.CRSFactory;
+//import org.gvsig.expressionevaluator.ExpressionBuilder;
+//import org.gvsig.expressionevaluator.ExpressionBuilder.Parameter;
+//import org.gvsig.expressionevaluator.ExpressionBuilder.Variable;
+//import org.gvsig.fmap.dal.SQLBuilder;
+//import org.gvsig.fmap.dal.SQLBuilder.Privilege;
+//import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase;
+//import org.gvsig.fmap.geom.DataTypes;
+//import org.gvsig.fmap.geom.Geometry;
+//import org.gvsig.fmap.geom.GeometryLocator;
+//import org.gvsig.fmap.geom.GeometryManager;
+//import org.gvsig.fmap.geom.primitive.Polygon;
+//import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
+//
+//public class SQLBuilderTest extends AbstractLibraryAutoInitTestCase {
+//    
+//    @Override
+//    protected void doSetUp() throws Exception {
+//
+//    }
+////    
+////    List<String> getVariableNames(ExpressionBuilder builder) {
+////        List<String> vars = new ArrayList<>();
+////        for (Variable var : builder.getVariables()) {
+////            vars.add(var.getName());
+////        }
+////        return vars;
+////    }
+////    
+////    List<String> getParameterNames(ExpressionBuilder builder) {
+////        List<String> params = new ArrayList<>();
+////        for (Parameter param : builder.getParameters()) {
+////            String s;
+////            switch(param.getType()) {
+////                case Constant:
+////                    Object value = param.getValue();
+////                    if( value==null ) {
+////                        s = "null";
+////                    } else if( value instanceof String ) {
+////                        s = "'" + (String)value + "'";
+////                    } else {
+////                        s = value.toString();
+////                    }    
+////                    break;
+////                case Geometry:
+////                case Variable:
+////                default:
+////                    s = "\"" + param.getName() + "\"";
+////            }
+////            params.add(s);
+////        }
+////        return params;
+//    }
+//    
+// 
+//    public void testCalulateEnvelope() throws Exception {
+//        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
+//        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+//        
+//        Polygon limit = geometryManager.createPolygon(Geometry.SUBTYPES.GEOM2D);
+//        limit.addVertex(0, 0);
+//        limit.addVertex(0, 100);
+//        limit.addVertex(100, 100);
+//        limit.addVertex(100, 0);
+//        limit.addVertex(0, 0);
+//        
+//        SQLBuilder builder = new SQLBuilderBase();
+//        
+//        builder.select().column().value(
+//            builder.getAsGeometry(
+//              builder.ST_ExtentAggregate(
+//                builder.column("the_geom")
+//              )
+//            )
+//        ).as("envelope");
+//        builder.select().from().table().database("master").schema("dbo").name("test1");
+//        builder.select().where().set(
+//            builder.ST_Intersects(
+//                builder.ST_Envelope(
+//                    builder.column("the_geom")
+//                ),
+//                builder.geometry(limit, proj)
+//            )
+//        );
+//        builder.select().where().and(
+//                builder.custom("x = 27")
+//        );
+//        
+//        // SELECT ST_AsBinary(ST_Extent("the_geom")) AS "envelope" FROM "master"."dbo"."test1" WHERE ST_Intersects((ST_Envelope("the_geom")), (ST_GeomFromText('POLYGON ((0 0, 0 100, 100 100, 100 0, 0 0))', (4326)))) AND x = 27
+//        
+//        System.out.println("# Test:: testCalulateEnvelope");
+//        System.out.println("# SQL:: " + builder.toString());
+//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+//        assertEquals(
+//                "SELECT ST_AsBinary(ST_Extent(\"the_geom\")) AS \"envelope\" FROM \"master\".\"dbo\".\"test1\" WHERE ST_Intersects((ST_Envelope(\"the_geom\")), (ST_GeomFromText('POLYGON ((0 0, 0 100, 100 100, 100 0, 0 0))', (4326)))) AND x = 27",
+//                builder.toString()
+//        );
+//        assertEquals(
+//                "[the_geom]",
+//                ArrayUtils.toString(getVariableNames(builder))
+//        );
+//        assertEquals(
+//                "[]",
+//                ArrayUtils.toString(getParameterNames(builder))
+//        );
+//    }
+//
+//    public void testCount() throws Exception {
+//        SQLBuilder builder = new SQLBuilderBase();
+//        
+//        builder.select().column().value(builder.count().all());
+//        builder.select().from().table().database("master").schema("dbo").name("test1");
+//        builder.select().from().subquery(null);
+//        builder.select().where().set( builder.custom("pp = 200"));
+//
+//        System.out.println("# Test:: testCount");
+//        System.out.println("# SQL:: " + builder.toString());
+//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+//
+//        //# Test:: testCount
+//        //# SQL:: SELECT COUNT(*) FROM "master"."dbo"."test1" WHERE pp = 200
+//        //# Variables:: []
+//        //# Parametros:: []
+//
+//        assertEquals(
+//                "SELECT COUNT(*) FROM \"master\".\"dbo\".\"test1\" WHERE pp = 200",
+//                builder.toString()
+//        );
+//        assertEquals(
+//                "[]",
+//                ArrayUtils.toString(getVariableNames(builder))
+//        );
+//        assertEquals(
+//                "[]",
+//                ArrayUtils.toString(getParameterNames(builder))
+//        );
+//    }
+//    
+//    public void testCreateTable() throws Exception {
+//        SQLBuilder builder = new SQLBuilderBase();
+//
+//        builder.create_table().table().database("master").schema("dbo").name("test1");
+//        builder.create_table().add_column(
+//                "name",
+//                DataTypes.STRING,
+//                45,
+//                0,
+//                false,
+//                false,
+//                true,
+//                false,
+//                null
+//        );
+//        builder.create_table().add_column(
+//                "id",
+//                DataTypes.INT,
+//                0,
+//                0,
+//                true,
+//                false,
+//                false,
+//                true,
+//                0
+//        );
+//        builder.create_table().add_column(
+//                "geom",
+//                DataTypes.GEOMETRY,
+//                0,
+//                0,
+//                false,
+//                false,
+//                true,
+//                false,
+//                null
+//        );
+//
+//        
+//        // CREATE TABLE "master"."dbo"."test1" ("name" VARCHAR(45) DEFAULT NULL NULL, "id" SERIAL DEFAULT '0' NOT NULL PRIMARY KEY, "geom" TEXT DEFAULT NULL NULL )
+//        System.out.println("# Test:: testCreateTable");
+//        System.out.println("# SQL:: " + builder.toString());
+//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+//        assertEquals(
+//                "CREATE TABLE \"master\".\"dbo\".\"test1\" (\"name\" VARCHAR(45) DEFAULT NULL NULL, \"id\" SERIAL DEFAULT '0' NOT NULL PRIMARY KEY, \"geom\" TEXT DEFAULT NULL NULL )",
+//                builder.toString()
+//        );
+//        assertEquals(
+//                "[]",
+//                ArrayUtils.toString(getVariableNames(builder))
+//        );
+//        assertEquals(
+//                "[]",
+//                ArrayUtils.toString(getParameterNames(builder))
+//        );
+//    }
+//
+//    public void testDropTable() throws Exception {
+//        SQLBuilder builder = new SQLBuilderBase();
+//        
+//        builder.drop_table().table().database("master").schema("dbo").name("test1");
+//
+//        // DROP TABLE "master"."dbo"."test1"; DELETE FROM GEOMETRY_COLUMNS WHERE f_table_schema = 'dbo' AND f_table_name = 'test1'
+//        
+//        System.out.println("# Test:: testDropTable");
+//        System.out.println("# SQL:: " + builder.toString());
+//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+//        assertEquals(
+//                "DROP TABLE \"master\".\"dbo\".\"test1\"; DELETE FROM GEOMETRY_COLUMNS WHERE f_table_schema = 'dbo' AND f_table_name = 'test1'",
+//                builder.toString()
+//        );
+//        assertEquals(
+//                "[]",
+//                ArrayUtils.toString(getVariableNames(builder))
+//        );
+//        assertEquals(
+//                "[]",
+//                ArrayUtils.toString(getParameterNames(builder))
+//        );
+//    }
+//    
+//    public void testFetchFeatureProviderByReference() throws Exception {
+//        SQLBuilder builder = new SQLBuilderBase();
+//        
+//        String value = "yoyo";
+//        builder.select().column().name("name");
+//        builder.select().column().name("id");
+//        builder.select().column().name("geom").as_geometry();
+//        builder.select().from().table().database("master").schema("dbo").name("test1");
+//        builder.select().where().set(
+//            builder.eq(
+//                builder.column("name"),
+//                builder.parameter(value).as_constant()
+//            )
+//        );
+//        builder.select().limit(1);
+//
+//        // SELECT "name", "id", ST_AsBinary("geom") FROM "master"."dbo"."test1" WHERE ( ("name") = (?) ) LIMIT 1
+//
+//        System.out.println("# Test:: testFetchFeatureProviderByReference");
+//        System.out.println("# SQL:: " + builder.toString());
+//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+//        assertEquals(
+//                "SELECT \"name\", \"id\", ST_AsBinary(\"geom\") FROM \"master\".\"dbo\".\"test1\" WHERE ( (\"name\") = (?) ) LIMIT 1",
+//                builder.toString()
+//        );
+//        assertEquals(
+//                "[geom, id, name]",
+//                ArrayUtils.toString(getVariableNames(builder))
+//        );
+//        assertEquals(
+//                "['yoyo']",
+//                ArrayUtils.toString(getParameterNames(builder))
+//        );
+//    }
+//    
+//    public void testFetchFeatureType() throws Exception {
+//        SQLBuilder builder = new SQLBuilderBase();
+//
+//        builder.select().column().all();
+//        builder.select().from().table().database("master").schema("dbo").name("test1");
+//        builder.select().limit(1);
+//
+//        System.out.println("# Test:: testFetchFeatureType");
+//        System.out.println("# SQL:: " + builder.toString());
+//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+//        
+//        //# Test:: testFetchFeatureType
+//        //# SQL:: SELECT * FROM [master].[dbo].[test1] LIMMIT 1
+//        //# Variables:: []
+//        //# Parametros:: []        
+//        
+//        assertEquals(
+//                "SELECT * FROM \"master\".\"dbo\".\"test1\" LIMIT 1",
+//                builder.toString()
+//        );
+//        assertEquals(
+//                "[]",
+//                ArrayUtils.toString(getVariableNames(builder))
+//        );
+//        assertEquals(
+//                "[]",
+//                ArrayUtils.toString(getParameterNames(builder))
+//        );
+//    }
+//        
+//    public void testPerformDeletes() throws Exception {
+//        SQLBuilder builder = new SQLBuilderBase();
+//
+//        builder.delete().table().database("master").schema("dbo").name("test1");
+//        builder.delete().where().and(
+//            builder.eq( 
+//                builder.column("id1"),
+//                builder.parameter("id1").as_variable()
+//            )
+//        );
+//        builder.delete().where().and(
+//            builder.eq( 
+//                builder.column("id2"),
+//                builder.parameter("id2").as_variable()
+//            )
+//        );
+//
+//        // DELETE FROM "master"."dbo"."test1" WHERE ( ("id1") = (?) ) AND ( ("id2") = (?) )
+//
+//        System.out.println("# Test:: testPerformDeletes");
+//        System.out.println("# SQL:: " + builder.toString());
+//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+//        assertEquals(
+//                "DELETE FROM \"master\".\"dbo\".\"test1\" WHERE ( (\"id1\") = (?) ) AND ( (\"id2\") = (?) )",
+//                builder.toString()
+//        );
+//        assertEquals(
+//                "[id1, id2]",
+//                ArrayUtils.toString(getVariableNames(builder))
+//        );
+//        assertEquals(
+//                "[\"id1\", \"id2\"]",
+//                ArrayUtils.toString(getParameterNames(builder))
+//        );
+//    }
+//
+//    public void testPerformInserts1() throws Exception {
+//        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+//
+//        SQLBuilder builder = new SQLBuilderBase();
+//
+//        builder.insert().table().database("master").schema("dbo").name("test1");
+//        builder.insert().column().name("id").with_value(builder.parameter("id"));
+//        builder.insert().column().name("name").with_value(builder.parameter("name"));
+//        builder.insert().column().name("geom").with_value(builder.parameter("geom").as_geometry_variable().srs(proj));
+//        
+//        // INSERT INTO "master"."dbo"."test1" ( "id", "name", "geom" ) VALUES ( ?, ?, ST_GeomFromText(?, (4326)) )
+//        
+//        System.out.println("# Test:: testPerformInserts1");
+//        System.out.println("# SQL:: " + builder.toString());
+//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+//        assertEquals(
+//                "INSERT INTO \"master\".\"dbo\".\"test1\" ( \"id\", \"name\", \"geom\" ) VALUES ( ?, ?, ST_GeomFromText(?, (4326)) )",
+//                builder.toString()
+//        );
+//        assertEquals(
+//                "[geom, id, name]",
+//                ArrayUtils.toString(getVariableNames(builder))
+//        );
+//        assertEquals(
+//                "[\"id\", \"name\", \"geom\"]",
+//                ArrayUtils.toString(getParameterNames(builder))
+//        );
+//    }
+//
+//    public void testPerformInserts2() throws Exception {
+//        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+//
+//        SQLBuilder builder = new SQLBuilderBase();
+//
+//        builder.insert().table().database("master").schema("dbo").name("test1");
+//        builder.insert().column().name("id").with_value(builder.parameter("id"));
+//        builder.insert().column().name("name").with_value(builder.parameter("name"));
+//        builder.insert().column().name("geom").with_value(builder.parameter("geom").as_geometry_variable().srs(builder.parameter().value(proj)));
+//        
+//        // INSERT INTO "master"."dbo"."test1" ( "id", "name", "geom" ) VALUES ( ?, ?, ST_GeomFromText(?, (?)) )
+//        
+//        System.out.println("# Test:: testPerformInserts2");
+//        System.out.println("# SQL:: " + builder.toString());
+//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+//        assertEquals(
+//                "INSERT INTO \"master\".\"dbo\".\"test1\" ( \"id\", \"name\", \"geom\" ) VALUES ( ?, ?, ST_GeomFromText(?, (?)) )",
+//                builder.toString()
+//        );
+//        assertEquals(
+//                "[geom, id, name]",
+//                ArrayUtils.toString(getVariableNames(builder))
+//        );
+//        assertEquals(
+//                "[\"id\", \"name\", \"geom\", 4326]",
+//                ArrayUtils.toString(getParameterNames(builder))
+//        );
+//    }
+//
+//    public void testPerformUpdates() throws Exception {
+//        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+//
+//        SQLBuilder builder = new SQLBuilderBase();
+//
+//        builder.update().table().database("master").schema("dbo").name("test1");
+//        builder.update().where().and(
+//            builder.eq(
+//                builder.column("id"), 
+//                builder.parameter("id").as_variable()
+//            )
+//        );
+//        builder.update().column().name("name").with_value(builder.parameter("name"));
+//        builder.update().column().name("geom").with_value(
+//                builder.parameter("geom").as_geometry_variable().srs( builder.parameter().value(proj)) 
+//        );
+//
+//        // UPDATE "master"."dbo"."test1" SET "name" = ?, "geom" = ST_GeomFromText(?, (?)) WHERE ( ("id") = (?) )
+//
+//        System.out.println("# Test:: testPerformUpdates");
+//        System.out.println("# SQL:: " + builder.toString());
+//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+//        assertEquals(
+//                "UPDATE \"master\".\"dbo\".\"test1\" SET \"name\" = ?, \"geom\" = ST_GeomFromText(?, (?)) WHERE ( (\"id\") = (?) )",
+//                builder.toString()
+//        );
+//        assertEquals(
+//                "[geom, id, name]",
+//                ArrayUtils.toString(getVariableNames(builder))
+//        );
+//        assertEquals(
+//                "[\"name\", \"geom\", 4326, \"id\"]",
+//                ArrayUtils.toString(getParameterNames(builder))
+//        );
+//    }
+//
+//    public void testGrant1() throws Exception {
+//
+//        SQLBuilder builder = new SQLBuilderBase();
+//
+//        builder.grant().table().database("master").schema("dbo").name("test1");
+//        builder.grant().role("prueba").select().insert().update();
+//        builder.grant().role("gis").all();
+//                
+//        
+//        System.out.println("# Test:: testGrant1");
+//        System.out.println("# SQL:: " + builder.toString());
+//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+//        assertEquals(
+//                "",
+//                builder.toString()
+//        );
+//        assertEquals(
+//                "[]",
+//                ArrayUtils.toString(getVariableNames(builder))
+//        );
+//        assertEquals(
+//                "[]",
+//                ArrayUtils.toString(getParameterNames(builder))
+//        );
+//    }
+//
+//    public void testGrant2() throws Exception {
+//
+//        SQLBuilder builder = new SQLBuilderBase();
+//
+//        builder.grant().table().database("master").schema("dbo").name("test1");
+//        builder.grant().role("prueba").privilege(Privilege.SELECT)
+//                .privilege(Privilege.INSERT)
+//                .privilege(Privilege.UPDATE);
+//        builder.grant().role("gis").privilege(Privilege.ALL);
+//                
+//        
+//        System.out.println("# Test:: testGrant2");
+//        System.out.println("# SQL:: " + builder.toString());
+//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
+//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
+//        assertEquals(
+//                "",
+//                builder.toString()
+//        );
+//        assertEquals(
+//                "[]",
+//                ArrayUtils.toString(getVariableNames(builder))
+//        );
+//        assertEquals(
+//                "[]",
+//                ArrayUtils.toString(getParameterNames(builder))
+//        );
+//    }
+//
+//
+//}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/META-INF/services/org.gvsig.tools.library.Library	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/META-INF/services/org.gvsig.tools.library.Library	(revision 262)
@@ -0,0 +1,2 @@
+org.gvsig.fmap.dal.store.jdbc2.JDBCLibrary
+org.gvsig.mssqlserver.dal.MSSQLServerLibrary
\ No newline at end of file
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/org/gvsig/fmap/dal/store/jdbc2/JDBC2Parameters.xml
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/org/gvsig/fmap/dal/store/jdbc2/JDBC2Parameters.xml	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/org/gvsig/fmap/dal/store/jdbc2/JDBC2Parameters.xml	(revision 262)
@@ -0,0 +1,122 @@
+<?xml version="1.0"?>
+<!--
+
+    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.
+
+-->
+<definitions>
+  <version>1.0.0</version>
+  <classes>
+    <class name="JDBC2ResourceParameters">
+      <description></description>
+      <extends>
+        <class>DBResourceParameters</class>
+      </extends>
+      <fields>
+        <field name="JDBCDriverClass" type="string" mandatory="true" group="Advanced">
+          <description>JDBC Driver class</description>
+        </field>
+        <field name="URL" type="string" mandatory="true" group="Connection">
+          <description>JDBC url connection</description>
+        </field>
+        <field name="Catalog" type="string" mandatory="false" group="Basic">
+          <description>Database catalog</description>
+        </field>
+        <field name="Schema" type="string" mandatory="false" group="Basic">
+          <description>Database schema</description>
+        </field>
+      </fields>
+    </class>
+
+    <class name="JDBC2StoreParameters">
+      <extends>
+        <class>JDBC2ResourceParameters</class>
+        <class>DBStoreParameters</class>
+      </extends>
+      <tags>
+          <value name="defaultGroup" value="Basic"/>
+      </tags>
+      <fields>
+      </fields>
+    </class>
+
+    <class name="JDBC2NewStoreParameters">
+      <description></description>
+      <extends>
+        <class>JDBC2ResourceParameters</class>
+        <class>DBNewStoreParameters</class>
+      </extends>
+      <tags>
+          <value name="defaultGroup" value="Basic"/>
+      </tags>
+      <fields>
+        <field name="selectRole" label="Roles for select" type="String" mandatory="false" defaultValue="" group="Permissions">
+          <description>Roles asigned to have select privilegies</description>
+        </field>
+        <field name="insertRole" label="Roles for insert" type="String" mandatory="false" defaultValue="" group="Permissions">
+          <description>Roles asigned to have insert privilegies</description>
+        </field>
+        <field name="updateRole" label="Roles for update" type="String" mandatory="false" defaultValue="" group="Permissions">
+          <description>Roles asigned to have update privilegies</description>
+        </field>
+        <field name="deleteRole" label="Roles for delete" type="String" mandatory="false" defaultValue="" group="Permissions">
+          <description>Roles asigned to have delete privilegies</description>
+        </field>
+        <field name="truncateRole" label="Roles for truncate" type="String" mandatory="false" defaultValue="" group="Permissions">
+          <description>Roles asigned to have truncate privilegies</description>
+        </field>
+        <field name="referenceRole" label="Roles for reference" type="String" mandatory="false" defaultValue="" group="Permissions">
+          <description>Roles asigned to have reference privilegies</description>
+        </field>
+        <field name="triggerRole" label="Roles for trigger" type="String" mandatory="false" defaultValue="" group="Permissions">
+          <description>Roles asigned to have trigger privilegies</description>
+        </field>
+        <field name="allRole" label="Roles for all" type="String" mandatory="false" defaultValue="" group="Permissions">
+          <description>Roles asigned to have all privilegies</description>
+        </field>
+        <field name="postCreatingStatement" label="Post-creating statement" type="String" mandatory="false" defaultValue="" group="Advanced">
+          <description>Roles asigned to have all privilegies</description>
+        </field>
+
+      </fields>
+    </class>
+    
+    <class name="JDBC2ServerExplorerParameters">
+      <extends>
+        <class>JDBC2ResourceParameters</class>
+        <class>DBServerExplorerParameters</class>
+      </extends>
+      <tags>
+          <value name="defaultGroup" value="Basic"/>
+      </tags>
+      <fields>
+        <field name="ShowInformationDBTables" type="boolean" 
+            mandatory="false" defaultValue="false" group="Basic">
+          <description>Show information tables</description>
+        </field>
+      </fields>
+    </class>
+
+
+  </classes>
+</definitions>  
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/org/gvsig/fmap/dal/store/jdbc2/JDBC2Metadata.xml
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/org/gvsig/fmap/dal/store/jdbc2/JDBC2Metadata.xml	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/org/gvsig/fmap/dal/store/jdbc2/JDBC2Metadata.xml	(revision 262)
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<!--
+
+    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.
+
+-->
+<definitions>
+  <version>1.0.0</version>
+  <classes>
+    <class name="JDBC2" namespace="Metadata">
+      <extends>
+      	<class name="SpatialProvider" namespace="Metadata"/>
+      </extends>
+      <description>Metadata of a JDBC store</description>
+      <fields>
+      </fields>
+    </class>
+
+  </classes>
+</definitions>  
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/org/gvsig/mssqlserver/dal/MSSQLServerMetadata.xml
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/org/gvsig/mssqlserver/dal/MSSQLServerMetadata.xml	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/org/gvsig/mssqlserver/dal/MSSQLServerMetadata.xml	(revision 262)
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<definitions>
+  <version>1.0.0</version>
+  <classes>
+    <class name="MSSQLServer" namespace="Metadata">
+      <extends>
+      	<class name="JDBC2" namespace="Metadata"/>
+      </extends>
+      <description>Metadata for MSSQLServer</description>
+      <fields>
+      </fields>
+    </class>
+
+  </classes>
+</definitions>  
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/org/gvsig/mssqlserver/dal/MSSQLServerParameters.xml
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/org/gvsig/mssqlserver/dal/MSSQLServerParameters.xml	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/org/gvsig/mssqlserver/dal/MSSQLServerParameters.xml	(revision 262)
@@ -0,0 +1,65 @@
+<?xml version="1.0"?>
+<definitions>
+  <version>1.0.0</version>
+  <classes>
+    <class name="MSSQLServerResourceParameters">
+      <extends>
+        <class>JDBC2ResourceParameters</class>
+      </extends>
+      <fields>
+        <field name="JDBCDriverClass" type="string" mandatory="true"
+          defaultValue="com.microsoft.sqlserver.jdbc.SQLServerDriver" group="Advanced">
+          <description>JDBC driver class for MS-SQlServer</description>
+        </field>
+        <field name="port" type="integer" mandatory="false"
+          defaultValue="1433" group="Connection">
+          <description></description>
+        </field>
+        <field name="host" type="string" mandatory="false" 
+            defaultValue="127.0.0.1" group="Connection">
+          <description></description>
+        </field>
+        <field name="instanceName" type="string" mandatory="false" 
+            defaultValue="SQLEXPRESS" group="Connection">
+          <description></description>
+        </field>     
+        <field name="dbname" type="string" mandatory="false" defaultValue="master" group="Basic">
+          <description></description>
+        </field>
+        <field name="dbuser" type="string" mandatory="false" defaultValue="sa" group="Basic">
+          <description></description>
+        </field>
+        <field name="password" type="string" mandatory="false" defaultValue="123" group="Basic">
+          <description></description>
+        </field>           
+      </fields>
+    </class>
+
+    <class name="MSSQLServerStoreParameters">
+      <extends>
+        <class>JDBC2StoreParameters</class>
+        <class>MSSQLServerResourceParameters</class>
+      </extends>
+      <fields/>
+    </class>
+
+    <class name="MSSQLServerNewStoreParameters">
+      <extends>
+        <class>JDBC2NewStoreParameters</class>
+        <class>MSSQLServerResourceParameters</class>
+      </extends>
+      <fields/>
+    </class>
+
+
+    <class name="MSSQLServerServerExplorerParameters">
+      <extends>
+        <class>MSSQLServerResourceParameters</class>
+        <class>JDBC2ServerExplorerParameters</class>
+      </extends>
+      <fields/>
+    </class>
+
+
+  </classes>
+</definitions>  
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/org/gvsig/mssqlserver/dal/MSSQLServerConfig.xml
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/org/gvsig/mssqlserver/dal/MSSQLServerConfig.xml	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/resources/org/gvsig/mssqlserver/dal/MSSQLServerConfig.xml	(revision 262)
@@ -0,0 +1,183 @@
+<?xml version="1.0"?>
+<definitions>
+  <version>1.0.0</version>
+  <classes>
+    <class name="JDBC2">
+      <extends>
+      </extends>
+      <fields>
+        <field name="function_ST_AsWKB" type="string" group="functions" 
+          defaultValue="ST_AsWKB({0})" >
+          <description></description>
+        </field>
+        <field name="function_ST_envelope" type="string" group="functions" 
+          defaultValue="ST_envelope({0})" >
+          <description></description>
+        </field>
+        <field name="function_ST_Extent" type="string" group="functions" 
+          defaultValue="ST_Extent({0})" >
+          <description></description>
+        </field>
+        <field name="function_ST_intersects" type="string" group="functions" 
+          defaultValue="ST_intersects({0}, {1})" >
+          <description></description>
+        </field>
+        <field name="function_ST_GeomFromText" type="string" group="functions" 
+          defaultValue="ST_GeomFromText({0}, {1})" >
+          <description></description>
+        </field>
+        <field name="function_ST_GeomFromWKB" type="string" group="functions" 
+          defaultValue="ST_GeomFromWKB({0}, {1})" >
+          <description></description>
+        </field>
+        <field name="function_ST_GeomFromEWKB" type="string" group="functions" 
+          defaultValue="ST_GeomFromEWKB({0}, {1})" >
+          <description></description>
+        </field>
+        <field name="function_current_schema" type="string" group="functions" 
+          defaultValue="current_schema()" >
+          <description></description>
+        </field>
+        <field name="function_lcase" type="string" group="functions" 
+          defaultValue="LCASE({0})" >
+          <description></description>
+        </field>
+        <field name="function_count" type="string" group="functions" 
+          defaultValue="count({0})" >
+          <description></description>
+        </field>
+        <field name="function_crs" type="string" group="functions" 
+          defaultValue="{0}" >
+          <description>Use {0} for the abbreviature, {1} for the autority name and {2} for the autority code</description>
+        </field>
+        
+        <!-- operators -->
+        <field name="operator_isnull" type="string" group="operators" 
+          defaultValue="{0} is null" >
+          <description></description>
+        </field>
+        <field name="operator_eq" type="string" group="operators" 
+          defaultValue="{0} = {1}" >
+          <description></description>
+        </field>
+        <field name="operator_neq" type="string" group="operators" 
+          defaultValue="{0} &lt;&gt; {1}" >
+          <description></description>
+        </field>
+        <field name="operator_lt" type="string" group="operators" 
+          defaultValue="{0} &lt; {1}" >
+          <description></description>
+        </field>
+        <field name="operator_le" type="string" group="operators" 
+          defaultValue="{0} &lt;= {1}" >
+          <description></description>
+        </field>
+        <field name="operator_gt" type="string" group="operators" 
+          defaultValue="{0} &gt; {1}" >
+          <description></description>
+        </field>
+        <field name="operator_ge" type="string" group="operators" 
+          defaultValue="{0} &gt;= {1}" >
+          <description></description>
+        </field>
+        <field name="operator_and" type="string" group="operators" 
+          defaultValue="{0} AND {1}" >
+          <description></description>
+        </field>
+        <field name="operator_or" type="string" group="operators" 
+          defaultValue="{0} OR {1}" >
+          <description></description>
+        </field>
+        <field name="operator_like" type="string" group="operators" 
+          defaultValue="{0} LIKE {1}" >
+          <description></description>
+        </field>
+        <field name="operator_ilike" type="string" group="operators" 
+          defaultValue="{0} ILIKE {1}" >
+          <description></description>
+        </field>
+        
+        <!-- properties -->
+        <field name="AllowAutomaticValues" type="boolean" group="properties" 
+          defaultValue="true" >
+          <description></description>
+        </field>
+        <field name="QuoteForStrings" type="string" group="properties" 
+          defaultValue="'" >
+          <description></description>
+        </field>
+        <field name="QuoteForIdentifiers" type="string" group="properties" 
+          defaultValue="" >
+          <description></description>
+        </field>
+        <field name="GeometrySupportType" type="string" group="properties" 
+            defaultValue="WKB" >
+            <description></description>
+            <availableValues>
+                <value label="WKT">WKT</value>
+                <value label="WKB">WKB</value>
+                <value label="EWKB">EWKB</value>
+            </availableValues>          
+        </field>
+
+
+
+      </fields>
+    </class>
+    
+    
+    <class name="MSSQLServer">
+      <extends>
+          <class>JDBC2</class>
+      </extends>
+      <fields>
+        <field name="function_ST_AsWKB" type="string" group="functions" 
+          defaultValue="({0}).STAsWKB" >
+          <description></description>
+        </field>
+        <field name="function_ST_envelope" type="string" group="functions" 
+          defaultValue="({0}).STEnvelope" >
+          <description></description>
+        </field>
+        <field name="function_ST_Extent" type="string" group="functions" 
+          defaultValue="({0}).STEnvelope" >
+          <description></description>
+        </field>
+        <field name="function_ST_intersects" type="string" group="functions" 
+          defaultValue="({0}).STIntersects({1})" >
+          <description></description>
+        </field>
+        <field name="function_ST_GeomFromText" type="string" group="functions" 
+          defaultValue="geometry::STGeomFromText({0}, {1})" >
+          <description></description>
+        </field>
+        <field name="function_ST_GeomFromWKB" type="string" group="functions" 
+          defaultValue="geometry::STGeomFromWKB({0}, {1})" >
+          <description></description>
+        </field>
+        <field name="function_ST_GeomFromEWKB" type="string" group="functions" 
+          defaultValue="geometry::STGeomFromWKB({0}, {1})" >
+          <description></description>
+        </field>
+        <field name="function_current_schema" type="string" group="functions" 
+          defaultValue="current_schema()" >
+          <description></description>
+        </field>
+        <field name="function_crs" type="string" group="functions" 
+          defaultValue="{2}" >
+          <description>Use {0} for the abbreviature, {1} for the autority name and {2} for the autority code</description>
+        </field>
+        <field name="function_lcase" type="string" group="functions" 
+          defaultValue="LOWER({0})" >
+          <description></description>
+        </field>
+        
+        <!-- operators -->
+        <field name="operator_ilike" type="string" group="operators" 
+          defaultValue="{0} ILIKE {1}" >
+          <description></description>
+        </field>
+    
+    
+  </classes>
+</definitions>  
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Envelope.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Envelope.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Envelope.java	(revision 262)
@@ -0,0 +1,42 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_Envelope implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+
+    public ST_Envelope(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_ENVELOPE, ((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("(({0}).STEnvelope())", p1);
+        return r;
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Contains.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Contains.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Contains.java	(revision 262)
@@ -0,0 +1,44 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_Contains implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+
+    public ST_Contains(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_CONTAINS, ((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}).STContains({1})=1)", p1, p2);
+        return r;
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_ExtentAggregate.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_ExtentAggregate.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_ExtentAggregate.java	(revision 262)
@@ -0,0 +1,42 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_ExtentAggregate implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+    
+    public ST_ExtentAggregate(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+    
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.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("geometry::EnvelopeAggregate({0})", p1);
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_GeomFromWKB.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_GeomFromWKB.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_GeomFromWKB.java	(revision 262)
@@ -0,0 +1,43 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_GeomFromWKB implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+    
+    public ST_GeomFromWKB(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+    
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_GEOMFROMWKB, ((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("geometry::STGeomFromWKB({0}, {1})", p1, p2);
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_GeomFromText.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_GeomFromText.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_GeomFromText.java	(revision 262)
@@ -0,0 +1,43 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_GeomFromText implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+    
+    public ST_GeomFromText(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+    
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_GEOMFROMTEXT, ((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("geometry::STGeomFromText({0}, {1})", p1, p2);
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/NotIsNull.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/NotIsNull.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/NotIsNull.java	(revision 262)
@@ -0,0 +1,45 @@
+package org.gvsig.mssqlserver.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.BinaryOperator;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.SQLBuilder;
+import org.gvsig.mssqlserver.dal.MSSQLServerSQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class NotIsNull implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+
+    public NotIsNull(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase("NOT IS NULL", ((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(MSSQLServerSQLBuilder.FORMAT_OPERATOR_NOTISNULL, p1);
+        return r;
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Crosses.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Crosses.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Crosses.java	(revision 262)
@@ -0,0 +1,44 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_Crosses implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+
+    public ST_Crosses(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_CROSSES, ((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}).STCrosses({1})=1)", p1, p2);
+        return r;
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Disjoint.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Disjoint.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Disjoint.java	(revision 262)
@@ -0,0 +1,44 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_Disjoint implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+
+    public ST_Disjoint(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_DISJOINT, ((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}).ST_Disjoint({1})=1)", p1, p2);
+        return r;
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Intersects.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Intersects.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Intersects.java	(revision 262)
@@ -0,0 +1,44 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_Intersects implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+
+    public ST_Intersects(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_INTERSECTS, ((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}).STIntersects({1})=1)", p1, p2);
+        return r;
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ILike.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ILike.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ILike.java	(revision 262)
@@ -0,0 +1,46 @@
+package org.gvsig.mssqlserver.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.BinaryOperator;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.SQLBuilder;
+import org.gvsig.mssqlserver.dal.MSSQLServerSQLBuilder;
+
+/**
+ *
+ * @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 BinaryOperator) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.OPERATOR_ILIKE, ((BinaryOperator) 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(MSSQLServerSQLBuilder.FORMAT_OPERATOR_ILIKE, p1, p2);
+        return r;
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Equals.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Equals.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Equals.java	(revision 262)
@@ -0,0 +1,44 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_Equals implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+
+    public ST_Equals(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_EQUALS, ((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}).STEquals({1})=1)", p1, p2);
+        return r;
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/MSSQLParameter.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/MSSQLParameter.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/MSSQLParameter.java	(revision 262)
@@ -0,0 +1,124 @@
+package org.gvsig.mssqlserver.dal.expressionbuilderformatter;
+
+import java.text.MessageFormat;
+import org.cresques.cts.IProjection;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Parameter;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.SQLBuilder;
+import org.gvsig.fmap.geom.Geometry;
+import org.gvsig.fmap.geom.GeometryUtils;
+import org.gvsig.mssqlserver.dal.MSSQLServerSQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class MSSQLParameter implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final MSSQLServerSQLBuilder builder;
+    private final ExpressionBuilder expbuilder;
+
+    public MSSQLParameter(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = (MSSQLServerSQLBuilder) builder;
+        this.formatter = formatter;
+        this.expbuilder = builder.expression();
+    }
+
+    @Override
+    public boolean canApply(Value value) {
+        return value instanceof Parameter;
+    }
+
+//    public Object value(Object value) {
+//        try {
+//            switch (this.type()) {
+//                case Constant:
+//                    if (value instanceof Geometry) {
+//                        Geometry geometry = (Geometry) value;
+//                        switch (this.expbuilder.geometry_support_type()) {
+//                            case EWKB:
+//                                return GeometryUtils.toEWKB(geometry);
+//                            case WKB:
+//                                return GeometryUtils.toWKB(geometry);
+//                            case WKT:
+//                            default:
+//                                return GeometryUtils.toWKT(geometry);
+//                        }
+//                    } else if (value instanceof IProjection) {
+//                        return this.expbuilder.srs_id((IProjection) value);
+//                    }
+//                    return value;
+//                case Variable:
+//                case Geometry:
+//                default:
+//                    return value;
+//            }
+//        } catch (Exception ex) {
+//            throw new RuntimeException("Can't get value from parameter.", ex);
+//        }
+//    }
+    
+    private String getSRS(Parameter param) {
+            if( param.srs()!=null ) {
+                return param.srs().toString(formatter);
+            }
+            if( param instanceof Geometry ) {
+                IProjection proj = ((Geometry)param).getProjection();
+                Object s = this.expbuilder.srs_id(proj);
+                if( s == null ) {
+                    throw new IllegalArgumentException("A parameter of type Geometry with an invalid SRS.");
+                }
+                return s.toString();
+            }
+            throw new IllegalArgumentException("The parameter of type Geometry need a SRS.");
+        }
+    @Override
+    public String format(Value function) {
+        Parameter value = (Parameter) function;
+        switch (value.type()) {
+            case Constant:
+                if (value instanceof Geometry) {
+                    switch (this.expbuilder.geometry_support_type()) {
+                        case EWKB:
+                        case WKB:
+                            return MessageFormat.format(
+                                    this.builder.FORMAT_ST_GEOMFROMWKB,
+                                    "?",
+                                    this.getSRS(value)
+                            );
+                        case WKT:
+                        default:
+                            return MessageFormat.format(
+                                    this.builder.FORMAT_ST_GEOMFROMTEXT,
+                                    "?",
+                                    this.getSRS(value)
+                            );
+                    }
+                }
+            case Variable:
+            default:
+                return "?";
+            case Geometry:
+                switch (this.expbuilder.geometry_support_type()) {
+                    case EWKB:
+                    case WKB:
+                        return MessageFormat.format(
+                                this.builder.FORMAT_ST_GEOMFROMWKB,
+                                "?",
+                                this.getSRS(value)
+                        );
+                    case WKT:
+                    default:
+                        return MessageFormat.format(
+                                this.builder.FORMAT_ST_GEOMFROMTEXT,
+                                "?",
+                                this.getSRS(value)
+                        );
+                }
+        }
+    }
+}
+
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Overlaps.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Overlaps.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Overlaps.java	(revision 262)
@@ -0,0 +1,44 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_Overlaps implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+
+    public ST_Overlaps(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_OVERLAPS, ((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}).STOverlaps({1})=1)", p1, p2);
+        return r;
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Simplify.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Simplify.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Simplify.java	(revision 262)
@@ -0,0 +1,44 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_Simplify implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+
+    public ST_Simplify(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_CONTAINS, ((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}).Reduce({1}))", p1, p2);
+        return r;
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/MSSQLVariable.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/MSSQLVariable.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/MSSQLVariable.java	(revision 262)
@@ -0,0 +1,44 @@
+package org.gvsig.mssqlserver.dal.expressionbuilderformatter;
+
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import static org.gvsig.expressionevaluator.ExpressionBuilder.EMPTY_FORMATTER;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Variable;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class MSSQLVariable implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+    private final ExpressionBuilder expbuilder;
+    
+    public MSSQLVariable(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+        this.expbuilder = builder.expression();
+    }
+    
+    @Override
+    public boolean canApply(Value value) {
+        return value instanceof Variable;
+    }
+
+    @Override
+    public String format(Value function) {
+        String name = ((Variable) function).name();
+
+        if (StringUtils.isEmpty(name)) {
+            return this.expbuilder.toString(EMPTY_FORMATTER);
+        }
+
+        return this.builder.as_identifier(name);
+
+    }
+}
+
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_UnionAggregate.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_UnionAggregate.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_UnionAggregate.java	(revision 262)
@@ -0,0 +1,42 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_UnionAggregate implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+    
+    public ST_UnionAggregate(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+    
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_UNIONAGGREGATE, ((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("geometry::UnionAggregate({0})", p1);
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_SRID.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_SRID.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_SRID.java	(revision 262)
@@ -0,0 +1,42 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_SRID implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+    
+    public ST_SRID(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+    
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_SRID, ((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("(({0}).STSrid)", p1);
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Within.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Within.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Within.java	(revision 262)
@@ -0,0 +1,44 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_Within implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+
+    public ST_Within(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_WITHIN, ((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}).STWithin({1})=1)", p1, p2);
+        return r;
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/MSSQLConstant.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/MSSQLConstant.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/MSSQLConstant.java	(revision 262)
@@ -0,0 +1,84 @@
+package org.gvsig.mssqlserver.dal.expressionbuilderformatter;
+
+import java.text.MessageFormat;
+import java.util.List;
+import java.util.Objects;
+import org.apache.commons.lang3.StringUtils;
+import org.cresques.cts.IProjection;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Constant;
+import static org.gvsig.expressionevaluator.ExpressionBuilder.EMPTY_FORMATTER;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
+import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.SQLBuilder;
+import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase;
+import org.gvsig.fmap.geom.Geometry;
+import org.gvsig.fmap.geom.GeometryUtils;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class MSSQLConstant implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+    private final ExpressionBuilder expbuilder;
+    
+    public MSSQLConstant(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+        this.expbuilder = builder.expression();
+    }
+    
+    @Override
+    public boolean canApply(Value value) {
+        return value instanceof Constant;
+    }
+
+    @Override
+    public String format(Value function) {
+          Object value = ((Constant) function).value();
+
+            if( value==null ) {
+                return "NULL";
+            }
+            if( value instanceof byte[] ) {
+                return this.expbuilder.bytearray_0x((byte[]) value);
+            }
+            if (value instanceof String) {
+                return this.builder.as_string((String) value);
+            }
+            if( value instanceof Geometry ) {
+                Geometry geometry = (Geometry) value;
+                switch (this.builder.geometry_support_type()) {
+                    case EWKB:
+                    case WKB:
+                        String p1 = this.expbuilder.bytearray_0x(GeometryUtils.toWKB(geometry));
+                        String p2 = String.valueOf(this.expbuilder.srs_id(geometry.getProjection()));
+                        String r = MessageFormat.format("geometry::STGeomFromWKB({0}, {1})", p1, p2);
+                        return r;
+                    case WKT:
+                    default:
+                        String p3 = this.expbuilder.bytearray_0x(GeometryUtils.toWKB(geometry));
+                        String p4 = String.valueOf(this.expbuilder.srs_id(geometry.getProjection()));
+                        String r1 = MessageFormat.format("geometry::STGeomFromText({0}, {1})", p3, p4);
+                        return r1;
+                }
+            }
+            if( value instanceof IProjection ) {
+                return Objects.toString(this.expbuilder.srs_id((IProjection)(value)));
+            }
+            if (value instanceof Boolean) {
+                // TODO correct values
+                if (((Boolean) value)) {
+                    return "(1=1)";
+                } else {
+                    return "(1<>1)";
+                }
+            }
+            return Objects.toString(value, "");
+        }
+    }
+
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/MSSQLServerFormatter.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/MSSQLServerFormatter.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/MSSQLServerFormatter.java	(revision 262)
@@ -0,0 +1,82 @@
+/*
+ * 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.mssqlserver.dal.expressionbuilderformatter;
+
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author osc
+ */
+public class MSSQLServerFormatter implements Formatter<ExpressionBuilder.Value> {
+
+    private final SQLBuilder builder;
+    private final Formatter<ExpressionBuilder.Value>[] formatters;
+
+    public MSSQLServerFormatter(SQLBuilder builder) {
+
+        this.builder = builder;
+        this.formatters = new Formatter[]{
+            new ILike(this.builder, this),
+            new NotIsNull(this.builder, this),
+            
+            new ST_AsBinary(this.builder, this),
+            new ST_AsEWKB(this.builder, this),
+            new ST_AsText(this.builder, this),
+            new ST_Contains(this.builder, this),
+            new ST_Crosses(this.builder, this),
+            new ST_Disjoint(this.builder, this),
+            new ST_Envelope(this.builder, this),
+            new ST_Equals(this.builder, this),
+            new ST_ExtentAggregate(this.builder, this),
+            new ST_GeomFromText(this.builder, this),
+            new ST_GeomFromWKB(this.builder, this),
+            new ST_Intersects(this.builder, this),
+            new ST_IsClosed(this.builder, this),
+            new ST_Overlaps(this.builder, this),
+            new ST_SRID(this.builder, this),
+            new ST_Simplify(this.builder, this),
+            new ST_Touches(this.builder, this),
+            new ST_UnionAggregate(this.builder, this),
+            new ST_Within(this.builder, this),
+            new MSSQLConstant(this.builder, this),
+            new MSSQLVariable(this.builder, this),
+            new MSSQLParameter(this.builder, this)
+
+//            new ILike(this.builder, this),
+//            new IsNull(this.builder, this),
+//            new IsNotNull(this.builder, this)
+//            new ST_AsEWKB(this.builder, this),
+//            new ST_ExtentAggregate(this.builder, this),
+//            new ST_GeomFromEWKB(this.builder, this),
+//            new ST_Intersects(this.builder, this),
+//            new ST_UnionAggregate(this.builder, this)
+        };
+    }
+
+    @Override
+    public boolean canApply(ExpressionBuilder.Value value) {
+        for (Formatter<ExpressionBuilder.Value> formatter : formatters) {
+            if (formatter.canApply(value)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public String format(ExpressionBuilder.Value value) {
+        for (Formatter<ExpressionBuilder.Value> formatter : formatters) {
+            if (formatter.canApply(value)) {
+                return formatter.format(value);
+            }
+        }
+        return value.toString(this);
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_IsClosed.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_IsClosed.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_IsClosed.java	(revision 262)
@@ -0,0 +1,42 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_IsClosed implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+    
+    public ST_IsClosed(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+    
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_ISCLOSED, ((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("(({0}).STIsClosed()=1)", p1);
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_AsBinary.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_AsBinary.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_AsBinary.java	(revision 262)
@@ -0,0 +1,42 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_AsBinary implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+    
+    public ST_AsBinary(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+    
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_ASBINARY, ((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("({0}).STAsBinary()", p1);
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_AsText.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_AsText.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_AsText.java	(revision 262)
@@ -0,0 +1,42 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_AsText implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+    
+    public ST_AsText(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+    
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_ASTEXT, ((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("({0}).STAsText()", p1);
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Touches.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Touches.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_Touches.java	(revision 262)
@@ -0,0 +1,44 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_Touches implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+
+    public ST_Touches(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_TOUCHES, ((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}).STTouches({1})=1)", p1, p2);
+        return r;
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_AsEWKB.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_AsEWKB.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/expressionbuilderformatter/ST_AsEWKB.java	(revision 262)
@@ -0,0 +1,42 @@
+package org.gvsig.mssqlserver.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.fmap.dal.SQLBuilder;
+
+/**
+ *
+ * @author jjdelcerro
+ */
+class ST_AsEWKB implements Formatter<Value> {
+
+    private final Formatter<Value> formatter;
+    private final SQLBuilder builder;
+    
+    public ST_AsEWKB(SQLBuilder builder, Formatter<Value> formatter) {
+        this.builder = builder;
+        this.formatter = formatter;
+    }
+    
+    @Override
+    public boolean canApply(Value value) {
+        if (value instanceof Function) {
+            return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_ASEWKB, ((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("({0}).STAsBinary()", p1);
+        return r;
+    }
+    
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerExplorerParameters.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerExplorerParameters.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerExplorerParameters.java	(revision 262)
@@ -0,0 +1,64 @@
+/* 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.mssqlserver.dal;
+
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
+import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
+
+public class MSSQLServerExplorerParameters extends
+        JDBCServerExplorerParameters {
+
+    public MSSQLServerExplorerParameters() {
+        super(
+                MSSQLServerLibrary.NAME + "ServerExplorerParameters",
+                MSSQLServerLibrary.NAME
+        );
+    }
+
+    @Override
+    public String getUrl() {
+        String url = super.getUrl();
+        if( StringUtils.isEmpty(url) ) {
+            url = MSSQLServerHelper.getConnectionURL(this);
+            this.setUrl(url);
+        }
+        return url;
+    }
+
+    @Override
+    public void validate() throws ValidateDataParametersException {
+        if (getJDBCDriverClassName() == null) {
+            setJDBCDriverClassName(MSSQLServerHelper.MSSQLServerJDBCDriver);
+        }
+        if (getPort() == null) {
+            setPort(MSSQLServerHelper.PORT);
+        }
+        if( getDynValue("instanceName") == null ) {
+            setDynValue("InstanceName", MSSQLServerHelper.INSTANCE_NAME);
+        }
+        super.validate();
+    }
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerLibrary.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerLibrary.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerLibrary.java	(revision 262)
@@ -0,0 +1,110 @@
+/* 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.mssqlserver.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.metadata.exceptions.MetadataException;
+import org.gvsig.tools.library.AbstractLibrary;
+import org.gvsig.tools.library.LibraryException;
+
+public class MSSQLServerLibrary extends AbstractLibrary {
+
+    // com.microsoft.sqlserver.jdbc.SQLServerDriver
+
+    public static final String NAME = "MSSQLServer";
+
+    @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();
+
+        DBHelper.registerParametersDefinition(
+                NAME + "StoreParameters",
+                MSSQLServerStoreParameters.class,
+                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
+        );
+        DBHelper.registerParametersDefinition(
+                NAME + "NewStoreParameters",
+                MSSQLServerNewStoreParameters.class,
+                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
+        );
+        DBHelper.registerParametersDefinition(
+                NAME + "ServerExplorerParameters",
+                MSSQLServerExplorerParameters.class,
+                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
+        );
+//        DBHelper.registerParametersDefinition(
+//                NAME + "ResourceParameters",
+//                MSSQLServerResourceParameters.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,
+//                MSSQLServerResource.class,
+//                MSSQLServerResourceParameters.class
+//            );
+//        }
+
+        if (!dataman.getStoreProviderRegister().exits(NAME)) {
+            dataman.registerStoreProviderFactory(new MSSQLServerStoreProviderFactory());
+        }
+
+        if (!dataman.getServerExplorerRegister().exits(NAME)) {
+            dataman.registerServerExplorerFactory(new MSSQLServerExplorerFactory());
+        }
+        if (ex != null) {
+            throw ex;
+        }
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerSQLBuilder.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerSQLBuilder.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerSQLBuilder.java	(revision 262)
@@ -0,0 +1,555 @@
+package org.gvsig.mssqlserver.dal;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import org.gvsig.expressionevaluator.Formatter;
+import org.gvsig.fmap.dal.DataTypes;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.fmap.geom.primitive.Envelope;
+import org.gvsig.mssqlserver.dal.expressionbuilderformatter.MSSQLServerFormatter;
+
+public class MSSQLServerSQLBuilder extends JDBCSQLBuilderBase {
+    
+    protected Formatter formatter = null;
+    public static final String FORMAT_ST_GEOMFROMEWKB= "geometry::STGeomFromWKB({0}, {1})";
+    public static final String FORMAT_ST_GEOMFROMWKB= "geometry::STGeomFromWKB({0}, {1})";
+    public static final String FORMAT_ST_GEOMFROMTEXT= "geometry::STGeomFromText({0}, {1})";
+    public static final String FORMAT_OPERATOR_ILIKE = "LOWER({0}) LIKE LOWER({1})";
+    public static final String FORMAT_OPERATOR_NOTISNULL = "( ({0}) IS NOT NULL )";
+    
+//    public interface MSSQLServerSQLConfig extends SQLConfig {
+//        public static final String ST_GeomFromTextEx = "ST_GeomFromTextEx";
+//        public static final String ST_GeomFromWKBEx = "ST_GeomFromWKBEx";
+//        public static final String ST_GeomFromEWKBEx = "ST_GeomFromEWKBEx";
+//        public static final String ST_ExtentAggregateEx = "ST_ExtentAggregateEx";
+//        public static final String ST_UnionAggregateEx = "ST_UnionAggregateEx";
+//    }
+ 
+    public MSSQLServerSQLBuilder(MSSQLServerHelper helper) {
+        super(helper);
+        
+        this.defaultSchema = "dbo";
+        this.allowAutomaticValues = true;
+        this.geometrySupportType = this.helper.getGeometrySupportType();
+        this.hasSpatialFunctions = this.helper.hasSpatialFunctions();
+
+        STMT_DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table = null;
+        STMT_DELETE_GEOMETRY_COLUMN_FROM_TABLE_table = null;
+ 
+        this.STMT_UPDATE_TABLE_STATISTICS_table ="UPDATE STATISTICS {0}";
+
+        this.type_geometry = "GEOMETRY";
+        this.constant_true = "1=1"; // TODO ?
+        this.constant_false = "1<>1"; // TODO ?
+    
+        this.type_boolean = "BIT";
+        this.type_double = "FLOAT"; //float con 53 bits de mantisa = float(54)
+        this.type_numeric_p = "NUMERIC({0})";
+        this.type_numeric_ps = "NUMERIC({0},{1})";
+        this.type_bigdecimal = "NUMERIC({0},{1})";
+        this.type_float = "REAL"; //float con 24 bits de mantisa = float(24)
+        this.type_int = "INT";
+        this.type_long = "BIGINT";        
+        this.type_byte = "TINYINT";
+        
+        this.type_date = "DATE";
+        this.type_time = "TIME";
+
+        this.type_char = "CHAR(1)";
+        this.type_string = "TEXT";
+        this.type_string_p = "VARCHAR({0})";
+
+        this.type_version = "VARCHAR(30)";
+        this.type_URI = "TEXT";
+        this.type_URL = "TEXT";
+        this.type_FILE = "TEXT";
+        this.type_FOLDER = "TEXT";
+        
+        this.type_bytearray = "VARBINARY";
+        
+        this.type_timestamp = "TIMESTAMP";
+
+//       DID this.ST_SRID, "(({0}).STSrid)");
+//       DID this.ST_AsText, "({0}).STAsText()");
+//       DID this.ST_AsBinary, "({0}).STAsBinary()");
+//       DID this.ST_AsEWKB, "({0}).STAsBinary()");
+//       DID this.ST_ExtentAggregate, "geometry::EnvelopeAggregate({0})");
+//       DID this.ST_UnionAggregate, "geometry::UnionAggregate({0})");
+//       DID this.ST_Contains, "(({0}).STContains({1})=1)");
+//       DID this.ST_Crosses, "(({0}).STCrosses({1})=1)");
+//       DID this.ST_Disjoint, "(({0}).STDisjoint({1})=1)");
+//       DID this.ST_Equals, "(({0}).STEquals({1})=1)");
+//       DID this.ST_IsClosed, "(({0}).STIsClosed()=1)");
+//       DID this.ST_Overlaps, "(({0}).STOverlaps({1})=1)");
+//       DID this.ST_Touches, "(({0}).STTouches({1})=1)");
+//       DID this.ST_Within, "(({0}).STWithin ({1})=1)");
+//       DID this.ST_Envelope, "({0}).STEnvelope()");
+//       DID this.ST_Intersects, "(({0}).STIntersects({1})=1)");
+//       DID this.ST_GeomFromText, "geometry::STGeomFromText({0}, {1})");
+//       DID this.ST_GeomFromWKB, "geometry::STGeomFromWKB({0}, {1})");
+//       DID this.ST_GeomFromEWKB, "geometry::STGeomFromWKB({0}, {1})");
+//       DID this.ST_Simplify, "({0}).Reduce({1})");
+//        this.lcase, "LOWER({0})");
+//        this.ucase, "UPPER({0})");
+//
+//        config.set(MSSQLServerSQLConfig.ST_ExtentAggregateEx, "{1}::EnvelopeAggregate({0})");
+//        config.set(MSSQLServerSQLConfig.ST_UnionAggregateEx, "{1}::UnionAggregate({0})");
+//        config.set(MSSQLServerSQLConfig.ST_GeomFromTextEx, "{2}::STGeomFromText({0}, {1})");
+//        config.set(MSSQLServerSQLConfig.ST_GeomFromWKBEx, "{2}::STGeomFromWKB({0}, {1})");
+//        config.set(MSSQLServerSQLConfig.ST_GeomFromEWKBEx, "{2}::STGeomFromWKB({0}, {1})");
+
+    }
+
+    @Override
+    public MSSQLServerHelper getHelper() {
+        return (MSSQLServerHelper) helper;
+    }
+    
+    @Override
+    protected Formatter formatter() {
+        if( this.formatter==null ) {
+            this.formatter = new MSSQLServerFormatter(this);
+        }
+        return this.formatter;
+    }
+    
+    protected class MSSQLServerDropTableBuilder extends DropTableBuilderBase {
+
+        @Override
+           public List<String> toStrings(Formatter formatter) {
+            List<String> sqls = new ArrayList<>();
+
+            sqls.add(
+                    MessageFormat.format(
+                            STMT_DROP_TABLE_table,
+                            this.table.toString(formatter)
+                    )
+            );
+            return sqls;
+        }
+    }
+    
+    public class MSSQLServerCreateIndexBuilder extends CreateIndexBuilderBase {
+
+        private Envelope boundingBox;
+        
+        public MSSQLServerCreateIndexBuilder() {
+            super();
+            this.boundingBox = null;
+        }
+        
+        public void setBoundingBox(Envelope boundingBox) {
+            this.boundingBox = boundingBox;
+        }
+        
+        private double getXMin() {
+            // https://alastaira.wordpress.com/2011/07/26/determining-the-geographic-extent-of-spatial-features-in-a-sql-server-table/
+            return Math.min(boundingBox.getUpperCorner().getX(), boundingBox.getLowerCorner().getX());
+        }
+        
+        private double getYMin() {
+            return Math.min(boundingBox.getUpperCorner().getY(), boundingBox.getLowerCorner().getY());
+        }
+        
+        private double getXMax() {
+            return Math.max(boundingBox.getUpperCorner().getX(), boundingBox.getLowerCorner().getX());
+        }
+        
+        private double getYMax() {
+            return Math.max(boundingBox.getUpperCorner().getY(), boundingBox.getLowerCorner().getY());
+        }
+        
+        @Override
+        public List<String> toStrings() {
+            StringBuilder builder = new StringBuilder();
+            if( this.isSpatial ) {
+                builder.append("CREATE SPATIAL INDEX ");
+                builder.append(as_identifier(this.indexName));
+                builder.append(" ON ");
+                builder.append(this.table.toString());
+                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(column);
+                }
+                builder.append(" ) ");
+                builder.append("USING GEOMETRY_GRID ");
+                builder.append("WITH( ");
+                builder.append("BOUNDING_BOX  = ( ");
+                builder.append("xmin  = ").append(this.getXMin()).append(", ");
+                builder.append("ymin  = ").append(this.getYMin()).append(", ");
+                builder.append("xmax  = ").append(this.getXMax()).append(", ");
+                builder.append("ymax  = ").append(this.getYMax());
+                builder.append(" )");
+//                builder.append(", DROP_EXISTING = ON");
+//                builder.append(", GRIDS  = ( LEVEL_1  = MEDIUM, LEVEL_2  = MEDIUM, LEVEL_3  = MEDIUM, LEVEL_4  = MEDIUM)");
+//                builder.append(", CELLS_PER_OBJECT  = 16");
+//                builder.append(", STATISTICS_NORECOMPUTE = OFF");
+//                builder.append(", ALLOW_ROW_LOCKS = ON");
+//                builder.append(", ALLOW_PAGE_LOCKS = ON");
+                builder.append(" ) ");
+            } else {
+                builder.append("CREATE ");
+                if( this.isUnique ) {
+                    builder.append("UNIQUE ");
+                }
+                builder.append("INDEX ");
+//                if( this.ifNotExist ) {
+//                    builder.append("IF NOT EXISTS ");
+//                }
+                builder.append(as_identifier(this.indexName));
+                builder.append(" ON ");
+                builder.append(this.table.toString());
+                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(column);
+                }
+                builder.append(" )");
+            }
+            List<String> sqls = new ArrayList<>();
+            sqls.add(builder.toString());
+            return sqls;
+        }
+        
+    }
+    
+//    public class MSSQLServerParameter extends ParameterBase {
+//
+//        public MSSQLServerParameter() {
+//            super();
+//        }
+//
+//        @Override
+//        public String toString() {
+//            if( this.type == ParameterType.Geometry ) {
+//                String spatialType = getHelper().getSpatialType(this.getName());
+//                switch( config.getGeometryTypeSupport() ) {
+//                    case EWKB:
+//                        return MessageFormat.format(
+//                                config.getString(MSSQLServerSQLConfig.ST_GeomFromEWKBEx),
+//                                "?",
+//                                String.valueOf(this.srs.toString()),
+//                                custom(spatialType)
+//                        );
+//                    case NATIVE:
+//                    case WKB:
+//                        return MessageFormat.format(
+//                                config.getString(MSSQLServerSQLConfig.ST_GeomFromWKBEx),
+//                                "?",
+//                                String.valueOf(this.srs.toString()),
+//                                custom(spatialType)
+//                        );
+//                    case WKT:
+//                    default:
+//                        return MessageFormat.format(
+//                                config.getString(MSSQLServerSQLConfig.ST_GeomFromTextEx),
+//                                "?",
+//                                String.valueOf(this.srs.toString()),
+//                                custom(spatialType)
+//                        );                        
+//                }                            
+//            }
+//            return super.toString();
+//        }
+//    }
+//    
+//    public class MSSQLServerGeometryValue extends GeometryValueBase {
+//        
+//        public MSSQLServerGeometryValue(Geometry geometry, IProjection projection) {
+//            super(geometry, projection);
+//        }
+//        
+//        @Override
+//        public String toString() {
+//            try {
+//                String spatialType = getHelper().getSpatialType();
+//                switch( config.getGeometryTypeSupport() ) {
+//                    case EWKB:
+//                        return MessageFormat.format(
+//                                config.getString(MSSQLServerSQLConfig.ST_GeomFromEWKBEx),
+//                                bytearray(this.geometry.convertToEWKB()),
+//                                String.valueOf(getSRSId(this.projection)),
+//                                custom(spatialType)
+//                        );
+//                    case NATIVE:
+//                    case WKB:
+//                        return MessageFormat.format(
+//                                config.getString(MSSQLServerSQLConfig.ST_GeomFromWKBEx),
+//                                bytearray(this.geometry.convertToWKB()),
+//                                String.valueOf(getSRSId(this.projection)),
+//                                custom(spatialType)
+//                        );
+//                    case WKT:
+//                    default:
+//                        return MessageFormat.format(
+//                                config.getString(MSSQLServerSQLConfig.ST_GeomFromTextEx),
+//                                string(this.geometry.convertToWKT()),
+//                                String.valueOf(getSRSId(this.projection)),
+//                                custom(spatialType)
+//                        );                        
+//                }
+//            } catch (Exception ex) {
+//                throw new RuntimeException("Can't convert geometry to string.",ex);
+//            }
+//        }
+//    }
+
+    protected class MSSQLServerSelectBuilder 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<ExpressionBuilder.Value> formatter) {
+            // MSSQLServer usa TOP en lugar de LIMIT y la sintaxis para OFFSET
+            // es ligeramente distinta de la que hay en SelectBuilderBase
+            StringBuilder builder = new StringBuilder();
+
+            builder.append("SELECT ");
+            if( this.distinct ) {
+                builder.append("DISTINCT ");
+            }
+            if (this.has_limit() && !this.has_offset() ) {
+                builder.append("TOP ");
+                builder.append(this.limit);
+                builder.append(" ");
+           }
+            boolean first = true;
+            for (SelectColumnBuilder column : columns) {
+                if (first) {
+                    first = false;
+                } else {
+                    builder.append(", ");
+                }
+                builder.append(column.toString());
+            }
+
+            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_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());
+                }
+            }
+
+            if (this.has_offset()) {
+                // Require SQLSeerver >= 2012
+                builder.append(" OFFSET ");
+                builder.append(this.offset);
+                builder.append(" ROWS");
+                if( this.has_limit() ) {
+                    builder.append(" FETCH NEXT ");
+                    builder.append(this.limit);
+                    builder.append(" ROWS ONLY ");
+                }
+            }
+            return builder.toString();
+        }
+    }
+
+    protected class MSSQLServerCreateTableBuilder extends CreateTableBuilderBase {
+
+        @Override
+//        List<String> toStrings(Formatter formatter)
+        public List<String> toStrings(Formatter formatter) {
+            //
+            // Respecto al base cambia la declaracion de campo automaticos
+            // SQLServer usa IDENTITY en lugar de SERIAL.
+            //
+            List<String> sqls = new ArrayList<>();
+            StringBuilder builder = new StringBuilder();
+
+            builder.append("CREATE TABLE ");
+            builder.append(this.table.toString());
+            builder.append(" (");
+            boolean first = true;
+            for (ColumnDescriptor column : columns) {
+                if (first) {
+                    first = false;
+                } else {
+                    builder.append(", ");
+                }
+                builder.append(as_identifier(column.getName()));
+                builder.append(" ");
+                if( column.isAutomatic() && column.getType() == DataTypes.INT ) {
+                    builder.append("INT");
+                    builder.append(" IDENTITY(1,1)");
+                } else if( column.isAutomatic() && column.getType() == DataTypes.LONG ) {
+                    builder.append("BIGINT");
+                    builder.append(" IDENTITY(1,1)");
+                } else {
+                    builder.append(
+                        sqltype(
+                            column.getType(), 
+                            column.getPrecision(), 
+                            column.getSize(),
+                            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());
+
+            return sqls;
+        }
+    }
+
+    @Override
+    protected SelectBuilder createSelectBuilder() {
+        return new MSSQLServerSelectBuilder();
+    }
+
+    @Override
+    protected CreateTableBuilder createCreateTableBuilder() {
+        return new MSSQLServerCreateTableBuilder();
+    }
+    
+    protected DropTableBuilder createDropTableBuilder() {
+        return new MSSQLServerDropTableBuilder();
+    }
+    
+    @Override
+    protected CreateIndexBuilder createCreateIndexBuilder() {
+        return new MSSQLServerCreateIndexBuilder();
+    }
+      
+    @Override
+    public String as_identifier(String id) {
+        // En SQLServer se aceptan las comillas dobles pero se prefiere
+        // corchetes [xx]. Asi que si hay comillas dobles las quitamos
+        // y ponemos los corchetes.
+        String quote = this.quote_for_identifiers();
+        if (id.startsWith(quote)) {
+            id = id.substring(1, id.length()-1);
+        } else if( id.startsWith("[") ) {
+            return id;
+        }
+        if( id.contains("(") ) {
+            LOGGER.warn("Suspicious use of 'identifier' in sql.");
+        }
+        return "[" + id + "]";
+    }
+
+//    @Override
+//    public GeometryValue geometry(Geometry geom, IProjection projection) {
+//        return new MSSQLServerGeometryValue(geom, projection);
+//    }
+
+//    @Override
+//    public Parameter parameter() {
+//        return new MSSQLServerParameter();
+//    }
+    
+//    @Override
+//    public Function ST_ExtentAggregate(Value geom) {
+//        String spatialType = getHelper().getSpatialType();
+//        return builtin_function("ST_ExtentAggregate", 
+//                config.getString(MSSQLServerSQLConfig.ST_ExtentAggregateEx), 
+//                geom,
+//                custom(spatialType)
+//        );
+//    }
+//
+//    @Override
+//    public Function ST_UnionAggregate(Value geom) {
+//        String spatialType = getHelper().getSpatialType();
+//        return builtin_function("ST_UnionAggregate", 
+//                config.getString(MSSQLServerSQLConfig.ST_UnionAggregateEx), 
+//                geom,
+//                custom(spatialType)
+//        );
+//    }
+//
+//    @Override
+//    public Function ST_GeomFromText(Value geom, Value crs) {
+//        String spatialType = getHelper().getSpatialType();
+//        return builtin_function("ST_GeomFromText", 
+//                config.getString(MSSQLServerSQLConfig.ST_GeomFromTextEx), 
+//                geom, 
+//                crs,
+//                custom(spatialType)
+//        );
+//    }
+//
+//    @Override
+//    public Function ST_GeomFromWKB(Value geom, Value crs) {
+//        String spatialType = getHelper().getSpatialType();
+//        return builtin_function("ST_GeomFromWKB", 
+//                config.getString(MSSQLServerSQLConfig.ST_GeomFromWKBEx), 
+//                geom, 
+//                crs,
+//                custom(spatialType)
+//        );
+//    }
+//
+//    @Override
+//    public Function ST_GeomFromEWKB(Value geom, Value crs) {
+//        String spatialType = getHelper().getSpatialType();
+//        return builtin_function("ST_GeomFromEWKB", 
+//                config.getString(MSSQLServerSQLConfig.ST_GeomFromEWKBEx), 
+//                geom, 
+//                crs,
+//                custom(spatialType)
+//        );
+//    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerExplorerFactory.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerExplorerFactory.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerExplorerFactory.java	(revision 262)
@@ -0,0 +1,46 @@
+
+package org.gvsig.mssqlserver.dal;
+
+import org.gvsig.fmap.dal.DataServerExplorer;
+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.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 MSSQLServerExplorerFactory extends JDBCServerExplorerFactory {
+
+    private static final String NAME = MSSQLServerLibrary.NAME;
+    
+    public MSSQLServerExplorerFactory() {
+        super(
+                NAME,
+                "Microsoft SQL Server"
+        );
+    }
+
+    @Override
+    public JDBCServerExplorer create(
+            DataServerExplorerParameters parameters, 
+            DataServerExplorerProviderServices providerServices
+        ) throws InitializeException {
+        JDBCHelper helper = new MSSQLServerHelper((JDBCConnectionParameters) parameters);
+        JDBCServerExplorer server = helper.createServerExplorer(
+                (JDBCServerExplorerParameters) parameters, 
+                providerServices
+        );
+        return server;
+    }
+        
+
+    @Override
+    public JDBCServerExplorerParameters createParameters() {
+        JDBCServerExplorerParameters params = new MSSQLServerExplorerParameters();
+        return params;    
+    }
+    
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerNewStoreParameters.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerNewStoreParameters.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerNewStoreParameters.java	(revision 262)
@@ -0,0 +1,45 @@
+/* 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.mssqlserver.dal;
+
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters;
+
+public class MSSQLServerNewStoreParameters extends JDBCNewStoreParameters {
+
+    public MSSQLServerNewStoreParameters() {
+        super(
+            MSSQLServerLibrary.NAME + "NewStoreParameters", 
+            MSSQLServerLibrary.NAME
+        );
+    }
+
+    @Override
+    public String getUrl() {
+        String url = super.getUrl();
+        if( StringUtils.isEmpty(url) ) {
+            url = MSSQLServerHelper.getConnectionURL(this);
+            this.setUrl(url);
+        }
+        return url;
+    }
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/operations/MSSQLServerCanModifyTableOperation.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/operations/MSSQLServerCanModifyTableOperation.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/operations/MSSQLServerCanModifyTableOperation.java	(revision 262)
@@ -0,0 +1,79 @@
+package org.gvsig.mssqlserver.dal.operations;
+
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.*;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.fmap.dal.exception.DataException;
+import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException;
+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;
+
+public class MSSQLServerCanModifyTableOperation extends CanModifyTableOperation {
+
+    public MSSQLServerCanModifyTableOperation(
+            JDBCHelper helper
+        ) {
+        this(helper, null);
+    }
+
+    public MSSQLServerCanModifyTableOperation(
+            JDBCHelper helper,
+            TableReference table
+        ) {
+        super(helper,table);
+    }
+
+    private String getFullTableName( 
+            TableReference table
+    ) {
+        StringBuilder builder = new StringBuilder();
+        if( table.hasDatabase() ) {
+            builder.append(table.getDatabase());
+        }
+        if( table.hasSchema() ) {
+            if( builder.length()>0 ) {
+                builder.append(".");
+            }
+            builder.append(table.getSchema());
+        }
+        if( table.hasTable() ) {
+            if( builder.length()>0 ) {
+                builder.append(".");
+            }
+            builder.append(table.getTable());
+        }
+        return builder.toString();
+    }
+    
+    @Override
+    public boolean canModifyTable(Connection conn,
+            TableReference table
+        ) throws DataException {
+
+        String sql = "SELECT count(*) " + 
+                     "FROM fn_my_permissions('"+getFullTableName(table)+"', 'OBJECT') " +
+                     "WHERE permission_name in ('UPDATE', 'INSERT', 'DELETE') AND subentity_name = ''";
+        Statement st = null;
+        ResultSet rs = null;
+        try {
+            st = conn.createStatement();
+            rs = JDBCUtils.executeQuery(st, sql);
+            if (!rs.next()) {
+                return false;
+            }
+            return rs.getInt(1)==3;
+
+        } catch (SQLException ex) {
+            throw new JDBCSQLException(ex);
+        } finally {
+            JDBCUtils.closeQuietly(st);
+            JDBCUtils.closeQuietly(rs);
+        }
+
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/operations/MSSQLServerPerformChangesOperation.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/operations/MSSQLServerPerformChangesOperation.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/operations/MSSQLServerPerformChangesOperation.java	(revision 262)
@@ -0,0 +1,89 @@
+package org.gvsig.mssqlserver.dal.operations;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import org.gvsig.fmap.dal.DataTypes;
+import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
+import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
+import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+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.mssqlserver.dal.MSSQLServerHelper;
+import org.gvsig.mssqlserver.dal.MSSQLServerSQLBuilder.MSSQLServerCreateIndexBuilder;
+
+@SuppressWarnings("UseSpecificCatch")
+public class MSSQLServerPerformChangesOperation extends PerformChangesOperation {
+
+    public MSSQLServerPerformChangesOperation(JDBCHelper helper) {
+        this(helper, null, null, null, null, null, null);
+    }
+
+    public MSSQLServerPerformChangesOperation(JDBCHelper helper,
+            TableReference table,
+            FeatureType featureType,
+            Iterator<FeatureReferenceProviderServices> deleteds,
+            Iterator<FeatureProvider> inserteds,
+            Iterator<FeatureProvider> updateds,
+            Iterator<FeatureStoreProvider.FeatureTypeChanged> featureTypesChanged) {
+        super(helper, table, featureType, deleteds, inserteds, updateds, featureTypesChanged);
+    }
+    
+    protected MSSQLServerHelper getHelper() {
+        return (MSSQLServerHelper) this.helper;
+    }
+    
+    @Override
+    protected List<String> buildCreateIndexSQL(
+            TableReference table,
+            FeatureType original,
+            FeatureType target
+        ) {
+        for (FeatureAttributeDescriptor attrTarget : target) {
+            boolean createIndex = false;
+            if( attrTarget.isIndexed() ) {
+                FeatureAttributeDescriptor attrOriginal = original.getAttributeDescriptor(attrTarget.getName());
+                if ( attrOriginal == null) {
+                    createIndex = true;
+                } else {
+                    if( attrOriginal.isIndexed() ) {
+                        createIndex = false;
+                    } else {
+                        createIndex = true;
+                    }
+                }
+            }
+            if( createIndex ) {
+                if( attrTarget.getType()==DataTypes.GEOMETRY ) {
+                    try {
+                        return this.getHelper().createOrUpdateSpatialIndexSql(
+                                this.getConnection(),
+                                table.getDatabase(),
+                                table.getSchema(),
+                                table.getTable(),
+                                attrTarget.getName()
+                        );
+                    } catch (Exception ex) {
+                        throw new RuntimeException("Can't create or update spatial index.", ex);
+                    }
+                } else {
+                    JDBCSQLBuilderBase sqlbuilder = createSQLBuilder();
+                    MSSQLServerCreateIndexBuilder create_index = (MSSQLServerCreateIndexBuilder) sqlbuilder.create_index();
+                    create_index.if_not_exist();
+                    create_index.name("idx_" + table + "_" + attrTarget.getName());
+                    create_index.column(attrTarget.getName());
+                    create_index.table()
+                        .database(table.getDatabase())
+                        .schema(table.getSchema())
+                        .name(table.getTable());
+                    return create_index.toStrings();
+                }
+            }
+        }
+        return new ArrayList<>();
+    }    
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/operations/MSSQLServerFetchFeatureTypeOperation.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/operations/MSSQLServerFetchFeatureTypeOperation.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/operations/MSSQLServerFetchFeatureTypeOperation.java	(revision 262)
@@ -0,0 +1,111 @@
+package org.gvsig.mssqlserver.dal.operations;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.Statement;
+import java.util.List;
+import org.cresques.cts.IProjection;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+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.operations.FetchFeatureTypeOperation;
+import org.gvsig.fmap.geom.Geometry;
+import org.gvsig.fmap.geom.GeometryLocator;
+import org.gvsig.fmap.geom.type.GeometryType;
+import org.gvsig.mssqlserver.dal.MSSQLServerHelper;
+
+public class MSSQLServerFetchFeatureTypeOperation extends FetchFeatureTypeOperation {
+
+    public MSSQLServerFetchFeatureTypeOperation(
+            JDBCHelper helper
+    ) {
+        super(helper);
+    }
+
+    public MSSQLServerFetchFeatureTypeOperation(
+            JDBCHelper helper,
+            EditableFeatureType featureType,
+            TableReference table,
+            List<String> primaryKeys,
+            String defaultGeometryColumn,
+            IProjection crs
+    ) {
+        super(helper, featureType, table, primaryKeys, defaultGeometryColumn, crs);
+    }
+
+    @Override
+    public void fetch(EditableFeatureType featureType, Connection conn, TableReference table, List<String> pks, String defaultGeometryColumn, IProjection crs) throws DataException {
+        super.fetch(featureType, conn, table, pks, defaultGeometryColumn, crs);
+        ((MSSQLServerHelper) this.helper).setLastUsedFeatureType(featureType);
+    }
+
+    @Override
+    protected void fetchGeometryTypeAndSRS(
+            EditableFeatureAttributeDescriptor attr,
+            ResultSetMetaData rsMetadata,
+            int colIndex
+    ) {
+        try {
+            GeometryType geomType = GeometryLocator.getGeometryManager().getGeometryType(
+                    Geometry.TYPES.GEOMETRY,
+                    Geometry.SUBTYPES.GEOM2D
+            );
+            attr.setGeometryType(geomType);
+
+            String typeName = rsMetadata.getColumnTypeName(colIndex);
+            attr.setAdditionalInfo("SQLServer_type_name", typeName);
+            attr.setSRS(getProjectionOfColumn(attr.getName()));
+        } catch (Exception ex) {
+            LOGGER.warn("Can't get default geometry type.", ex);
+        }
+    }
+    
+    private IProjection getProjectionOfColumn(String columnName) {
+       
+        JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
+        ExpressionBuilder expbuilder = sqlbuilder.expression();
+        
+        sqlbuilder.select().limit(1);
+        sqlbuilder.select().column().value(
+                expbuilder.ST_SRID(expbuilder.column(columnName))
+        );
+        sqlbuilder.select().where().set(
+                expbuilder.and(
+                        expbuilder.not_is_null(expbuilder.column(columnName)),
+                        expbuilder.not_is_null(expbuilder.ST_SRID(expbuilder.column(columnName)))
+                )
+        );
+        sqlbuilder.select().from().table()
+                .database(this.getTable().getDatabase())
+                .schema(this.getTable().getSchema())
+                .name(this.getTable().getTable());
+        Statement st = null;
+        ResultSet rs = null;
+        try {
+            st = this.getConnection().createStatement();
+            rs = JDBCUtils.executeQuery(st, sqlbuilder.toString());
+            if (rs.next()) {
+                int code = rs.getInt(1);
+                try {
+                    IProjection proj = this.helper.getSRSSolver().getProjection(conn, code);
+                    return proj;
+                } catch (Exception ex) {
+                    LOGGER.warn("Can't create projection from code '" + code + "'.", ex);
+                }
+            }
+        } catch (Exception ex) {
+            // Do nothing, return null
+        } finally {
+            JDBCUtils.closeQuietly(rs);
+            JDBCUtils.closeQuietly(st);
+        }
+        return null;
+
+    }
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/operations/MSSQLServerOperationsFactory.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/operations/MSSQLServerOperationsFactory.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/operations/MSSQLServerOperationsFactory.java	(revision 262)
@@ -0,0 +1,50 @@
+
+package org.gvsig.mssqlserver.dal.operations;
+
+import java.util.Iterator;
+import java.util.List;
+import org.apache.commons.lang3.tuple.Pair;
+import org.cresques.cts.IProjection;
+import org.gvsig.fmap.dal.SQLBuilder;
+import org.gvsig.fmap.dal.exception.DataException;
+import org.gvsig.fmap.dal.feature.EditableFeatureType;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CanModifyTableOperation;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CreateTableOperation;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.FetchFeatureTypeOperation;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.OperationsFactoryBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.PerformChangesOperation;
+
+
+public class MSSQLServerOperationsFactory extends OperationsFactoryBase {
+    
+    public MSSQLServerOperationsFactory(JDBCHelper helper) {
+        super(helper);
+    }
+
+    @Override
+    public FetchFeatureTypeOperation createFetchFeatureType(EditableFeatureType type, TableReference table, List<String> primaryKeys, String defaultGeometryField, IProjection crs) {
+        return new MSSQLServerFetchFeatureTypeOperation(
+                helper, type, table, primaryKeys, 
+                defaultGeometryField, crs
+        );
+    }
+
+    @Override
+    public CanModifyTableOperation createCanModifyTableOperation(TableReference table) {
+        return new MSSQLServerCanModifyTableOperation(
+                helper, table
+        );
+    }
+
+    @Override
+    public CreateTableOperation createTable(TableReference table, FeatureType type, List<Pair<String, SQLBuilder.Privilege>> userAndPrivileges, List<String> additionalSQLs) throws DataException {
+        return new MSSQLServerCreateTableOperation( helper, table, type, userAndPrivileges, additionalSQLs);
+    }
+
+    @Override
+    public PerformChangesOperation createPerformChanges(TableReference table, FeatureType type, Iterator deleteds, Iterator inserteds, Iterator updateds, Iterator featureTypesChanged) {
+        return new MSSQLServerPerformChangesOperation(helper, table, type, deleteds, inserteds, updateds, featureTypesChanged);
+    }
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/operations/MSSQLServerCreateTableOperation.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/operations/MSSQLServerCreateTableOperation.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/operations/MSSQLServerCreateTableOperation.java	(revision 262)
@@ -0,0 +1,39 @@
+
+package org.gvsig.mssqlserver.dal.operations;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.lang3.tuple.Pair;
+import org.gvsig.fmap.dal.SQLBuilder;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
+import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CreateTableOperation;
+
+
+public class MSSQLServerCreateTableOperation extends CreateTableOperation {
+    
+    public MSSQLServerCreateTableOperation(JDBCHelper helper) {
+        this(helper, null, null, null, null);
+    }
+    
+    public MSSQLServerCreateTableOperation(
+            JDBCHelper helper,
+            TableReference table,
+            FeatureType type,
+            List<Pair<String, SQLBuilder.Privilege>> userAndPrivileges,
+            List<String> additionalSQLs
+        ) {
+        super(helper, table, type, userAndPrivileges, additionalSQLs);
+    }
+
+    @Override
+    protected List<String> buildCreateIndexesSQL(
+            TableReference table,
+            FeatureType type
+        ) {
+        // No podemos crear indices espaciales con la tabla vacia ya que SQLServer
+        // requiere que se indique en bounding box y aun no lo sabemos.
+        return new ArrayList<>();
+    }
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerHelper.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerHelper.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerHelper.java	(revision 262)
@@ -0,0 +1,419 @@
+/* gvSIG. Geographic Information System of the Valencian Government
+ *
+ * Copyright (C) 2007-2016 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 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.
+ *
+ */
+package org.gvsig.mssqlserver.dal;
+
+import org.gvsig.mssqlserver.dal.operations.MSSQLServerOperationsFactory;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.expressionevaluator.ExpressionBuilder;
+import org.gvsig.fmap.dal.DataParameters;
+import org.gvsig.fmap.dal.DataTypes;
+import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
+import org.gvsig.fmap.dal.feature.FeatureType;
+import org.gvsig.fmap.dal.SQLBuilder;
+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.jdbc.exception.JDBCSQLException;
+import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
+import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase;
+import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
+import org.gvsig.fmap.geom.Geometry;
+import org.gvsig.fmap.geom.primitive.Envelope;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MSSQLServerHelper extends JDBCHelperBase {
+
+    private static final Logger logger = LoggerFactory.getLogger(MSSQLServerHelper.class);
+
+    public static final String NAME = "MSSQLServer";
+    public static final String INSTANCE_NAME = "SQLEXPRESS";
+    public static final int PORT = 1433;
+    public static final String MSSQLServerJDBCDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
+    
+//    private static final boolean ALLOW_AUTOMATIC_VALUES = true;
+//    private static final String QUOTE_FOR_USE_IN_IDENTIFIERS = "\"";
+//    private static final String QUOTE_FOR_USE_IN_STRINGS = "'";
+
+    public static String getConnectionURL(JDBCConnectionParameters params) {
+        String connectionURL = MessageFormat.format(
+                //"jdbc:sqlserver://{0}:{1,number,#};databaseName={2};instanceName={3};",
+                "jdbc:sqlserver://{0};databaseName={2};instanceName={3};",
+                params.getHost(),
+                params.getPort(),
+                params.getDBName(),
+                ((DataParameters) params).getDynValue("instanceName")
+        );
+        logger.debug("connectionURL: {}", connectionURL);
+        return connectionURL;
+    }
+
+    private static class ConnectionProvider {
+
+        private static boolean needRegisterDriver = true;
+
+        private BasicDataSource dataSource = null;
+
+        private final JDBCConnectionParameters connectionParameters;
+
+        public ConnectionProvider(JDBCConnectionParameters connectionParameters) {
+            this.connectionParameters = connectionParameters;
+        }
+
+        public Connection getConnection() throws SQLException {
+            if (this.dataSource == null) {
+                this.dataSource = this.createDataSource();
+            }
+            Connection conn = this.dataSource.getConnection();
+            return conn;
+        }
+
+        private BasicDataSource createDataSource() throws SQLException {
+            if (!this.isRegistered()) {
+                this.registerDriver();
+            }
+            JDBCConnectionParameters params = connectionParameters;
+
+            BasicDataSource dataSource = new BasicDataSource();
+            dataSource.setDriverClassName(params.getJDBCDriverClassName());
+            dataSource.setUsername(params.getUser());
+            dataSource.setPassword(params.getPassword());
+            dataSource.setUrl(params.getUrl());
+
+            dataSource.setMaxWait(60L * 1000);
+            return dataSource;
+        }
+
+        private boolean isRegistered() {
+            return needRegisterDriver;
+        }
+
+        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(MSSQLServerLibrary.NAME, className);
+                }
+            } catch (Exception e) {
+                throw new SQLException("Can't register JDBC driver '" + className + "'.", e);
+            }
+            needRegisterDriver = false;
+        }
+
+    }
+
+    private ConnectionProvider connectionProvider = null;
+
+    private FeatureType lastUsedFeatureType = null;
+    private String lastUsedSpatialType = null;
+    
+    public MSSQLServerHelper(JDBCConnectionParameters connectionParameters) {
+        super(connectionParameters);
+    }
+
+    @Override
+    public Connection getConnection() throws AccessResourceException {
+        try {
+            if (this.connectionProvider == null) {
+                this.connectionProvider = new ConnectionProvider(this.getConnectionParameters());
+            }
+            return this.connectionProvider.getConnection();
+        } catch (SQLException ex) {
+            throw new AccessResourceException(MSSQLServerLibrary.NAME, ex);
+        }
+    }
+    
+    @Override
+    public String getConnectionURL() {
+        return getConnectionURL(this.getConnectionParameters());
+    }
+
+    @Override
+    protected String getResourceType() {
+        return MSSQLServerLibrary.NAME;
+    }
+
+    @Override
+    public String getProviderName() {
+        return MSSQLServerLibrary.NAME;
+    }
+
+    @Override
+    public JDBCSQLBuilderBase createSQLBuilder() {
+        return new MSSQLServerSQLBuilder(this);
+    }
+
+    /**
+     * Devuelbe el nombre del tipo de datos espacial de SQLServer asociado 
+     * al ultimo FeatureType cargado.
+     * 
+     * Esta funcion es usada para dar un soporte limitado al tipo de datos
+     * spaciales "geography".
+     * 
+     * Si no disponemos de un FeatureType asumimos "geometry".
+     * Si hay un solo campo espacial asume el tipo de ese campo, y si 
+     * hay mas de uno asume "geometry".
+     * En caso de que no haya ningun campo espacial asumimos "geometry".
+     * 
+     * @return "geometry" or "geography" for the last used table.
+     */
+    public String getSpatialType() {
+        if( this.lastUsedSpatialType != null ) {
+            return this.lastUsedSpatialType;
+        }
+        if( this.lastUsedFeatureType == null ) {
+            this.lastUsedSpatialType = "geometry";
+            return this.lastUsedSpatialType;
+        }
+        String spatialType = null;
+        for (FeatureAttributeDescriptor attr : lastUsedFeatureType) {
+            if( attr.getType() == DataTypes.GEOMETRY ) {
+                if( spatialType != null ) {
+                    this.lastUsedSpatialType = "geometry";
+                    return this.lastUsedSpatialType;
+                }
+                spatialType = (String) attr.getAdditionalInfo("SQLServer_type_name");
+            }
+        }
+        if( StringUtils.isEmpty(spatialType) ) {
+            this.lastUsedSpatialType = "geometry";
+            return this.lastUsedSpatialType;
+        }
+        this.lastUsedSpatialType = spatialType;
+        return this.lastUsedSpatialType;
+    }
+
+    /**
+     * Devuelbe el tipo de datos espacial de SQLServer asociado a la columna 
+     * indicada.
+     * 
+     * Esta funcion es usada para dar un soporte limitado al tipo de datos
+     * spaciales "geography".
+     * 
+     * Si no disponemos de un FeatureType asumimos "geometry".
+     * Si no existe el campo solicitado o no es de tipo geoemtria, asumimos 
+     * el tipo espacia asociado al FeatureType (getSpatialType()).
+     * 
+     * @param columnName
+     * @return "geometry" or "geography" for column in the last used table.
+     */
+    public String getSpatialType(String columnName) {
+        if( this.lastUsedFeatureType == null ) {
+            return "geometry";
+        }
+        FeatureAttributeDescriptor attr = this.lastUsedFeatureType.getAttributeDescriptor(columnName);
+        if( attr == null ) {
+            return this.getSpatialType();
+        }
+        if( attr.getType() != DataTypes.GEOMETRY ) {
+            return this.getSpatialType();
+        }
+        String spatialType = (String) attr.getAdditionalInfo("SQLServer_type_name");
+        if( StringUtils.isEmpty(spatialType) ) {
+            return "geometry";
+        }
+        return spatialType;
+    }
+    
+    public void setLastUsedFeatureType(FeatureType featureType) {
+        this.lastUsedSpatialType = null;
+        this.lastUsedFeatureType = featureType;
+    }
+
+    public void createOrUpdateSpatialIndex(
+            Connection conn,
+            String database,
+            String schema,
+            String table,
+            String columnName
+        ) throws JDBCSQLException {
+        List<String> sqls = this.createOrUpdateSpatialIndexSql(
+                conn, database, schema, table, columnName
+        );
+        Statement st = null;
+        try {
+            st = conn.createStatement();
+            for (String sql : sqls) {
+                JDBCUtils.execute(st, sql);
+            }
+        } catch (SQLException ex) {
+            throw new JDBCSQLException(ex);
+        } finally {
+            JDBCUtils.closeQuietly(st);
+        }
+        
+    }
+    
+    public List<String> createOrUpdateSpatialIndexSql(
+            Connection conn,
+            String database,
+            String schema,
+            String table,
+            String columnName
+        ) throws JDBCSQLException {
+        JDBCSQLBuilderBase sqlbuilder = createSQLBuilder();
+        MSSQLServerSQLBuilder.MSSQLServerCreateIndexBuilder create_index = (MSSQLServerSQLBuilder.MSSQLServerCreateIndexBuilder) sqlbuilder.create_index();
+
+        sqlbuilder.create_index().spatial();
+        create_index.setBoundingBox(
+                this.getBoundingBox(
+                        conn,
+                        database,
+                        schema,
+                        table,
+                        columnName
+                )
+        );
+        create_index.if_not_exist();
+        create_index.name("idx_" + table + "_" + columnName);
+        create_index.column(columnName);
+        create_index.table().database(database).schema(schema).name(table);
+
+        return create_index.toStrings();
+    }    
+    
+    public Envelope getBoundingBox(
+            Connection conn,
+            String database,
+            String schema,
+            String table,
+            String columnName
+        ) throws JDBCSQLException {
+        JDBCSQLBuilderBase sqlbuilder = createSQLBuilder();
+        ExpressionBuilder expbuilder = sqlbuilder.expression();
+        
+        sqlbuilder.select().column().value(
+            expbuilder.as_geometry(
+                expbuilder.ST_ExtentAggregate(
+                        expbuilder.column(columnName)
+                )
+            )
+        );
+        sqlbuilder.select().from().table().database(database).schema(schema).name(table);
+
+        String sql = sqlbuilder.select().toString();
+        Statement st = null;
+        ResultSet rs = null;
+        try {
+            st = conn.createStatement();
+            rs = JDBCUtils.executeQuery(st, sql);
+            if (!rs.next()) {
+                return null;
+            }
+            Geometry geom = this.getGeometryFromColumn(rs, 1);
+            if (geom == null) {
+                return null;
+            }
+            return geom.getEnvelope();
+
+        } catch (Exception ex) {
+            throw new JDBCSQLException(ex);
+        } finally {
+            JDBCUtils.closeQuietly(st);
+            JDBCUtils.closeQuietly(rs);
+        }        
+    }
+    
+    @Override
+    public OperationsFactory getOperations() {
+        if (this.operationsFactory == null) {
+            this.operationsFactory = new MSSQLServerOperationsFactory(this);
+        }
+        return operationsFactory;
+    }
+
+    @Override
+    public ExpressionBuilder.GeometrySupportType getGeometrySupportType() {
+        return ExpressionBuilder.GeometrySupportType.WKB;
+    }
+
+    @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.getHost() + ":" +
+               parameters.getDynValue("InstanceName")+ ":" + 
+               parameters.getDBName() + "." + 
+               parameters.getSchema()+ "." + 
+               parameters.getTable();
+    }
+
+    @Override
+    public JDBCNewStoreParameters createNewStoreParameters() {
+        return new MSSQLServerNewStoreParameters();
+    }
+
+    @Override
+    public JDBCStoreParameters createOpenStoreParameters() {
+        return new MSSQLServerStoreParameters();
+    }
+
+    @Override
+    public JDBCServerExplorerParameters createServerExplorerParameters() {
+        return new MSSQLServerExplorerParameters();
+    }
+
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerStoreProviderFactory.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerStoreProviderFactory.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerStoreProviderFactory.java	(revision 262)
@@ -0,0 +1,44 @@
+
+package org.gvsig.mssqlserver.dal;
+
+import org.gvsig.fmap.dal.DataParameters;
+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 MSSQLServerStoreProviderFactory extends JDBCStoreProviderFactory {
+
+    private static final String NAME = MSSQLServerLibrary.NAME;
+    
+    public MSSQLServerStoreProviderFactory() {
+        super(
+                NAME, 
+                "Microsoft SQL Server store"
+        );
+    }
+
+    @Override
+    public JDBCStoreProvider createProvider(
+            DataParameters parameters,
+            DataStoreProviderServices providerServices
+    ) throws InitializeException {
+        JDBCHelper helper = new MSSQLServerHelper((JDBCConnectionParameters) parameters);
+        JDBCStoreProvider provider = helper.createProvider(
+                (JDBCStoreParameters) parameters, 
+                providerServices
+        );
+        return provider;
+    }
+
+    @Override
+    public JDBCStoreParameters createParameters() {
+        JDBCStoreParameters params = new MSSQLServerStoreParameters();
+        return params;
+    }
+    
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerStoreParameters.java
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerStoreParameters.java	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerStoreParameters.java	(revision 262)
@@ -0,0 +1,60 @@
+/* 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.mssqlserver.dal;
+
+import org.apache.commons.lang3.StringUtils;
+import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
+import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
+
+public class MSSQLServerStoreParameters extends JDBCStoreParameters {
+
+    public MSSQLServerStoreParameters() {
+        super(
+                MSSQLServerLibrary.NAME + "StoreParameters",
+                MSSQLServerLibrary.NAME
+        );
+    }
+
+    @Override
+    public String getUrl() {
+        String url = super.getUrl();
+        if( StringUtils.isEmpty(url) ) {
+            url = MSSQLServerHelper.getConnectionURL(this);
+            this.setUrl(url);
+        }
+        return url;
+    }
+
+    @Override
+    public void validate() throws ValidateDataParametersException {
+        if (getJDBCDriverClassName() == null) {
+            setJDBCDriverClassName(MSSQLServerHelper.MSSQLServerJDBCDriver);
+        }
+        if (getPort() == null) {
+            setPort(MSSQLServerHelper.PORT);
+        }
+        if (getDynValue("instanceName") == null) {
+            setDynValue("InstanceName", MSSQLServerHelper.INSTANCE_NAME);
+        }
+        super.validate();
+    }
+}
Index: tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/pom.xml
===================================================================
--- tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/pom.xml	(revision 0)
+++ tags/org.gvsig.mssqlserver-1.0.46/org.gvsig.mssqlserver.provider/pom.xml	(revision 262)
@@ -0,0 +1,190 @@
+<?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.mssqlserver.provider</artifactId>
+    <packaging>jar</packaging>
+    <name>${project.artifactId}</name>
+    <description>DAL provider for MS SQLServer</description>
+    <parent>
+        <groupId>org.gvsig</groupId>
+        <artifactId>org.gvsig.mssqlserver</artifactId>
+        <version>1.0.46</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.impl</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.gvsig</groupId>
+            <artifactId>org.gvsig.fmap.dal.spi</artifactId>
+            <scope>test</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.expressionevaluator.lib.api</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.impl}</artifactId>
+            <scope>test</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>com.microsoft.sqlserver</groupId>
+            <artifactId>sqlserver-jdbc</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>commons-dbcp</groupId>
+            <artifactId>commons-dbcp</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>commons-collections</groupId>
+            <artifactId>commons-collections</artifactId>
+            <scope>compile</scope>
+        </dependency>
+
+
+        <!-- TESTS -->
+               <dependency>
+            <groupId>org.gvsig</groupId>
+            <artifactId>org.gvsig.expressionevaluator.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.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>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.gvsig</groupId>
+            <artifactId>org.gvsig.metadata.lib.basic.impl</artifactId>
+            <scope>compile</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>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.11</version>
+            <type>jar</type>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+                        
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>animal-sniffer-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>check-java-api</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>check</goal>
+                        </goals>
+                        <configuration>
+                            <skip>true</skip>
+                            <signature>
+                                <groupId>org.codehaus.mojo.signature</groupId>
+                                <artifactId>java18</artifactId>
+                                <version>1.0</version>
+                            </signature>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+
+        </plugins>
+    </build>
+
+</project>

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



Property changes on: tags/org.gvsig.mssqlserver-1.0.46
___________________________________________________________________
Added: svn:ignore
   + nbactions.xml


