Revision 247

View differences:

tags/org.gvsig.mssqlserver-1.0.43/org.gvsig.mssqlserver.app/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<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">
4

  
5
  <modelVersion>4.0.0</modelVersion>
6
  <artifactId>org.gvsig.mssqlserver.app</artifactId>
7
  <packaging>pom</packaging>
8
  <name>${project.artifactId}</name>
9
  <parent>
10
      <groupId>org.gvsig</groupId>
11
      <artifactId>org.gvsig.mssqlserver</artifactId>
12
      <version>1.0.43</version>
13
  </parent>
14

  
15
  <modules>
16
    <module>org.gvsig.mssqlserver.app.mainplugin</module>
17
  </modules>
18

  
19
</project>
tags/org.gvsig.mssqlserver-1.0.43/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
    <file>
17
      <source>src/main/resources-plugin/config.xml</source>
18
    </file>
19
  </files>
20
  <fileSets>
21
    <fileSet>
22
      <directory>src/main/resources-plugin</directory>
23
      <outputDirectory>.</outputDirectory>
24
    </fileSet>
25
  </fileSets>
26
  <dependencySets>
27

  
28
    <dependencySet>
29
      <useProjectArtifact>false</useProjectArtifact>
30
      <useTransitiveDependencies>false</useTransitiveDependencies>
31
      <outputDirectory>lib</outputDirectory>
32
      <includes>
33
        <include>org.gvsig:org.gvsig.mssqlserver.provider</include>
34
      </includes>
35
    </dependencySet>
36

  
37
    <dependencySet>
38
      <useProjectArtifact>false</useProjectArtifact>
39
      <useTransitiveDependencies>false</useTransitiveDependencies>
40
      <outputDirectory>lib</outputDirectory>
41
      <includes>
42
		<include>com.microsoft.sqlserver:sqlserver-jdbc</include>
43
		<include>commons-dbcp:commons-dbcp</include>
44
		<include>commons-collections:commons-collections</include>
45
		<include>commons-pool:commons-pool</include>
46
      </includes>
47
    </dependencySet>
48

  
49
  </dependencySets>
50

  
51
</assembly>
52

  
53

  
54

  
55

  
tags/org.gvsig.mssqlserver-1.0.43/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/java/org/gvsig/mssqlserver/MSSQLServerExtension.java
1

  
2
package org.gvsig.mssqlserver;
3

  
4
import org.gvsig.andami.IconThemeHelper;
5
import org.gvsig.andami.plugins.Extension;
6
import org.gvsig.fmap.mapcontext.MapContextLocator;
7
import org.gvsig.fmap.mapcontext.MapContextManager;
8

  
9

  
10
public class MSSQLServerExtension  extends Extension {
11

  
12
    @Override
13
    public void initialize() {
14
    }
15

  
16
    @Override
17
    public void postInitialize() {
18
        MapContextManager mapContextMgr = MapContextLocator.getMapContextManager();
19
        
20
        IconThemeHelper.registerIcon("layer", "layer-icon-mssqlserver", this);
21
        mapContextMgr.registerIconLayer("MSSQLServer", "layer-icon-mssqlserver");
22
    }
23
    
24
    @Override
25
    public void execute(String actionCommand) {
26
    }
27

  
28
    @Override
29
    public boolean isEnabled() {
30
        return false;
31
    }
32

  
33
    @Override
34
    public boolean isVisible() {
35
        return false;
36
    }
37
    
38
}
tags/org.gvsig.mssqlserver-1.0.43/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/resources-plugin/readme_es.txt
1

  
2
Notas acerca de la implementacion del proveedor de MS SQLServer.
3
====================================================================
4

  
5
Software
6
----------
7

  
8
Las pruebas realizadas durante el desarrollo se han hecho sobre:
9

  
10
- Microsoft SQL Server Express 2014 (64-bit), versi?n 12.0.2000.8
11
- Microsoft Windows NT 6.3 (9600), plataforma NT x64
12

  
13
El acceso al servidor se realiza a traves de JDBC usando el driver:
14

  
15
- Microsoft JDBC Driver 6.0 for SQL Server, may 2016 (sqljdbc42.jar).
16

  
17
Configuraci?n
18
--------------
19

  
20
Las pruebas se han realizado usando la instancia por defecto "SQLEXPRESS".
21

  
22
Para poder acceder al servidor es necesario:
23

  
24
- Habilitar la conexion al servidor a traves de TCP/IP. Esto se activara
25
  desde:
26
  - Sql Server Configuration Manager
27
  - Configuracion de red de SQL Server
28
  - Protocolos de SQLEXPRESS
29
  - TCP/IP
30
   - General
31
     - Habilitado: Si
32
   - Direcciones IP
33
     - IP4
34
       - Activo: Si
35
       - Habilitado: Si
36

  
37
- Deberan estar "En ejecucion" los servicios de:
38
  - SQL Server (SQLEXPRESS)
39
  - SQL Server Browser.
40
    Este servicio es necesario para poder aceptar conexiones TCP/IP contra el
41
    servidor y por defecto, tras la instalacion de MS SQL Sever, no se iniciaba
42
    automaticamente en mi equipo.
43

  
44
- Durante todas las pruebas se ha utilizado "Autenticaci?n de SQL Server".
45
  Es posible que para otros tipos de autenticaci?n sea necesario incluir alguna
46
  otra libreria (como sqljdbc_auth.dll x64/x86).
47

  
48
Soporte espacial
49
-------------------
50

  
51
Siempre que se exporta a BBDD se utilizara el tipo "geometry" para crear los
52
campos de tipo geometria, y en general se usara siempre este tipo de datos.
53

  
54
Se ha implementado un soporte limitado para el tipo de datos "geography". Si una
55
tabla contiene un campo de este tipo se leera y gvSIG podra trabajar con el. Si
56
una tabla contiene mas de un campo de tipo geometria siendo estos de tipos distintos,
57
unos "geometry" y otros "geography", gvSIG puede dar problemas para acceder a estos,
58
especialmente al de tipo "geography".
59

  
60
Ahora mismo el tipo de geometria asociado a una columna de la BBDD es GEOMETRY,
61
es decir, no se sabe si es punto, linea o poligono.
62

  
63
Sistemas de referencia
64
------------------------
65

  
66
La lista de sistemas de referencia disponibles esta almacenada en la tabla
67
sys.spatial_reference_systems, y solo tiene definidas unos 390 sistemas
68
de referencia. Habria que averiguar cargar otros sistemas de referencia.
69

  
70
Valores por defecto
71
---------------------
72

  
73
Los datos de conexion por defecto son:
74

  
75
- Host: 127.0.0.1
76
- Instance: SQLEXPRESS
77
- Database: master
78
- Schema: dbo
79
- user: sa
80
- password: 123
81

  
82
Los valores instance, database, schema y user se corresponden con valores
83
validos para una instalacion por defecto de SQL Server.
84

  
85
Problemas conocidos
86
--------------------
87

  
88
- No se guardan los datos de la conexion entre sesiones de gvSIG.
89

  
90
- La herramienta "Selection by layer" no funciona.
91

  
92
- Si una capa de gvSIG declara un campo "double" con precision y size,
93
  al expportarlo a BBDD lo exporta como "DOUBLE PRECISION" en lugar de como
94
  "NUMERIC(size,precision)".
95

  
96
- No se estan creando indices sobre los campos al exportar a BBDD.
97

  
98
- En la exportacion a BBDD, en el paso que pide el nombre de la tabla,
99
  primero muestra como esquema "public" y cuando termina de leer las tablas
100
  de la BBDD para mostrarlas (tarda unos segundos) cambia de public a "dbo".
101
  Esto puede causar problemas si el usuario pulsa en siguiente antes de que se
102
  haya actualizado el esquema con el que se corresponde con la BBDD ya que
103
  intentaria crear la tabla en el esquema "public" y este no existe en SQLServer.
104

  
105
- Solo se ha implememtado soporte para geometrias 2D (no 3D, 2DM o 3DM).
106

  
tags/org.gvsig.mssqlserver-1.0.43/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/resources-plugin/mssqlserver-jdbc-driver-license60.txt
1
MICROSOFT SOFTWARE LICENSE TERMS
2

  
3
MICROSOFT JDBC DRIVER 6.0 FOR SQL SERVER
4

  
5
These license terms are an agreement between Microsoft Corporation (or based on where you 
6
live, one of its affiliates) and you. Please read them. They apply to the software 
7
named above, which includes the media on which you received it, if any. The terms also apply to 
8
any Microsoft
9

  
10
? updates,
11
? supplements,
12
? Internet-based services, and
13
? support services
14

  
15
for this software, unless other terms accompany those items. If so, those terms apply.
16

  
17
BY USING THE SOFTWARE, YOU ACCEPT THESE TERMS. IF YOU DO NOT 
18
ACCEPT THEM, DO NOT USE THE SOFTWARE.
19

  
20
If you comply with these license terms, you have the rights below.
21

  
22
1. INSTALLATION AND USE RIGHTS. 
23

  
24
a. Installation and Use.
25

  
26
i. You may install and use any number of copies of the software on your devices.
27

  
28
b. Third Party Programs. The software may include third party programs that Microsoft, 
29
not the third party, licenses to you under this agreement. Notices, if any, for the third 
30
party program are included for your information only.
31

  
32
2. ADDITIONAL LICENSING REQUIREMENTS AND/OR USE RIGHTS.
33

  
34
a. Distributable Code.
35

  
36
i.	Right to Use and Distribute. You are permitted to distribute the software in programs you 
37
develop if you comply with the terms below:
38

  
39
* You may copy and distribute the object code form of the software (?Distributable Code?) in 
40
programs you develop. You may not modify the software.
41
* You may permit distributors of your programs to copy and distribute the Distributable Code 
42
as part of those programs.
43
ii.	Distribution Requirements. For any Distributable Code you distribute, you must
44
* add significant primary functionality to it in your programs;
45
* require distributors and external end users to agree to terms that protect it at least as 
46
much as this agreement;
47
* display your valid copyright notice on your programs; and
48
* indemnify, defend, and hold harmless Microsoft from any claims, including attorneys? fees, 
49
related to the distribution or use of your programs.
50
iii.	Distribution Restrictions. You may not
51
* alter any copyright, trademark or patent notice in the Distributable Code;
52
* use Microsoft?s trademarks in your programs? names or in a way that suggests your programs 
53
come from or are endorsed by Microsoft;
54
* include Distributable Code in malicious, deceptive or unlawful programs; or
55
* modify or distribute the source code of any Distributable Code so that any part of it 
56
becomes subject to an Excluded License. An Excluded License is one that requires, as a 
57
condition of use, modification or distribution, that
58
* the code be disclosed or distributed in source code form; or
59
* others have the right to modify it.
60

  
61

  
62
3. SCOPE OF LICENSE. The software is licensed, not sold. This agreement only gives you 
63
some rights to use the software. Microsoft reserves all other rights. Unless applicable law 
64
gives you more rights despite this limitation, you may use the software only as expressly 
65
permitted in this agreement. In doing so, you must comply with any technical limitations in 
66
the software that only allow you to use it in certain ways. You may not
67

  
68
? work around any technical limitations in the software;
69
? reverse engineer, decompile or disassemble the software, except and only to the extent 
70
that applicable law expressly permits, despite this limitation;
71
? make more copies of the software than specified in this agreement or allowed by 
72
applicable law, despite this limitation;
73
? publish the software for others to copy;
74
? rent, lease or lend the software;
75
? transfer the software or this agreement to any third party; or
76
? use the software for commercial software hosting services.
77

  
78
4. EXPORT RESTRICTIONS. The software is subject to United States export laws and 
79
regulations. You must comply with all domestic and international export laws and 
80
regulations that apply to the software. These laws include restrictions on destinations, end 
81
users and end use. For additional information, see www.microsoft.com/exporting.
82

  
83
5. SUPPORT SERVICES. Because this software is ?as is,? we may not provide support 
84
services for it.
85

  
86
6. ENTIRE AGREEMENT. This agreement, and the terms for supplements, updates, Internet-
87
based services and support services that you use, are the entire agreement for the software 
88
and support services.
89

  
90
7. APPLICABLE LAW.
91

  
92
a. United States. If you acquired the software in the United States, Washington state law 
93
governs the interpretation of this agreement and applies to claims for breach of it, 
94
regardless of conflict of laws principles. The laws of the state where you live govern all 
95
other claims, including claims under state consumer protection laws, unfair competition 
96
laws, and in tort.
97

  
98
b. Outside the United States. If you acquired the software in any other country, the laws of 
99
that country apply.
100

  
101
8. LEGAL EFFECT. This agreement describes certain legal rights. You may have other rights 
102
under the laws of your country. You may also have rights with respect to the party from 
103
whom you acquired the software. This agreement does not change your rights under the laws 
104
of your country if the laws of your country do not permit it to do so.
105

  
106
9. DISCLAIMER OF WARRANTY. THE SOFTWARE IS LICENSED ?AS-IS.? YOU 
107
BEAR THE RISK OF USING IT. MICROSOFT GIVES NO EXPRESS 
108
WARRANTIES, GUARANTEES OR CONDITIONS. YOU MAY HAVE 
109
ADDITIONAL CONSUMER RIGHTS UNDER YOUR LOCAL LAWS WHICH THIS 
110
AGREEMENT CANNOT CHANGE. TO THE EXTENT PERMITTED UNDER 
111
YOUR LOCAL LAWS, MICROSOFT EXCLUDES THE IMPLIED WARRANTIES 
112
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-
113
INFRINGEMENT.
114

  
115
10. LIMITATION ON AND EXCLUSION OF REMEDIES AND DAMAGES. YOU CAN 
116
RECOVER FROM MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP 
117
TO U.S. $5.00. YOU CANNOT RECOVER ANY OTHER DAMAGES, INCLUDING 
118
CONSEQUENTIAL, LOST PROFITS, SPECIAL, INDIRECT OR INCIDENTAL 
119
DAMAGES.
120

  
121
This limitation applies to
122

  
123
? anything related to the software, services, content (including code) on third party Internet 
124
sites, or third party programs, and
125
? claims for breach of contract, breach of warranty, guarantee or condition, strict liability, 
126
negligence, or other tort to the extent permitted by applicable law.
127

  
128
It also applies even if Microsoft knew or should have known about the possibility of the 
129
damages. The above limitation or exclusion may not apply to you because your country may 
130
not allow the exclusion or limitation of incidental, consequential or other damages.
131

  
132
Please note: As this software is distributed in Quebec, Canada, some of the clauses in this 
133
agreement are provided below in French.
134

  
135
Remarque : Ce logiciel ?tant distribu? au Qu?bec, Canada, certaines des clauses dans ce 
136
contrat sont fournies ci-dessous en fran?ais.
137

  
138
EXON?RATION DE GARANTIE. Le logiciel vis? par une licence est offert ? tel quel ?. 
139
Toute utilisation de ce logiciel est ? votre seule risque et p?ril. Microsoft n?accorde aucune 
140
autre garantie expresse. Vous pouvez b?n?ficier de droits additionnels en vertu du droit local 
141
sur la protection des consommateurs, que ce contrat ne peut modifier. La ou elles sont 
142
permises par le droit locale, les garanties implicites de qualit? marchande, d?ad?quation ? un 
143
usage particulier et d?absence de contrefa?on sont exclues.
144

  
145
LIMITATION DES DOMMAGES-INT?R?TS ET EXCLUSION DE 
146
RESPONSABILIT? POUR LES DOMMAGES. Vous pouvez obtenir de Microsoft et de 
147
ses fournisseurs une indemnisation en cas de dommages directs uniquement ? hauteur de 5,00 
148
$ US. Vous ne pouvez pr?tendre ? aucune indemnisation pour les autres dommages, y 
149
compris les dommages sp?ciaux, indirects ou accessoires et pertes de b?n?fices.
150

  
151
Cette limitation concerne :
152
? tout ce qui est reli? au logiciel, aux services ou au contenu (y compris le code) figurant 
153
sur des sites Internet tiers ou dans des programmes tiers ; et
154
? les r?clamations au titre de violation de contrat ou de garantie, ou au titre de 
155
responsabilit? stricte, de n?gligence ou d?une autre faute dans la limite autoris?e par la loi 
156
en vigueur.
157

  
158
Elle s?applique ?galement, m?me si Microsoft connaissait ou devrait conna?tre l??ventualit? 
159
d?un tel dommage. Si votre pays n?autorise pas l?exclusion ou la limitation de responsabilit? 
160
pour les dommages indirects, accessoires ou de quelque nature que ce soit, il se peut que la 
161
limitation ou l?exclusion ci-dessus ne s?appliquera pas ? votre ?gard.
162

  
163
EFFET JURIDIQUE. Le pr?sent contrat d?crit certains droits juridiques. Vous pourriez avoir 
164
d?autres droits pr?vus par les lois de votre pays. Le pr?sent contrat ne modifie pas les droits 
165
que vous conf?rent les lois de votre pays si celles-ci ne le permettent pas.
166

  
167

  
168

  
169

  
tags/org.gvsig.mssqlserver-1.0.43/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/src/main/resources-plugin/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
  <libraries library-dir="lib/"/>
4
  <depends plugin-name="org.gvsig.app.mainplugin"/>
5
  <resourceBundle name="text"/>
6
  <extensions>
7
     <extension class-name="org.gvsig.mssqlserver.MSSQLServerExtension" active="true"/>
8
  </extensions>    
9
</plugin-config>
tags/org.gvsig.mssqlserver-1.0.43/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<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">
4

  
5
  <modelVersion>4.0.0</modelVersion>
6
  <artifactId>org.gvsig.mssqlserver.app.mainplugin</artifactId>
7
  <packaging>jar</packaging>
8
  <name>${project.artifactId}</name>
9
  <description>MS SQLServer support</description>
10

  
11
  <parent>
12
      <groupId>org.gvsig</groupId>
13
      <artifactId>org.gvsig.mssqlserver.app</artifactId>
14
      <version>1.0.43</version>
15
  </parent>
16

  
17
  <dependencies>
18
    <dependency>
19
        <groupId>org.gvsig</groupId>
20
        <artifactId>org.gvsig.tools.lib</artifactId>
21
        <scope>compile</scope>
22
    </dependency>
23
    <dependency>
24
        <groupId>org.gvsig</groupId>
25
        <artifactId>org.gvsig.andami</artifactId>
26
        <scope>compile</scope>
27
    </dependency>
28
    <dependency>
29
        <groupId>org.gvsig</groupId>
30
        <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
31
        <scope>compile</scope>
32
    </dependency>
33
    <dependency>
34
        <groupId>org.gvsig</groupId>
35
        <artifactId>org.gvsig.mssqlserver.provider</artifactId>
36
        <scope>compile</scope>
37
    </dependency>
38

  
39
    <dependency>
40
      <groupId>com.microsoft.sqlserver</groupId>
41
      <artifactId>sqlserver-jdbc</artifactId>
42
      <scope>runtime</scope>
43
    </dependency>
44
    <dependency>
45
      <groupId>commons-dbcp</groupId>
46
      <artifactId>commons-dbcp</artifactId>
47
      <scope>runtime</scope>
48
    </dependency>
49
    <dependency>
50
      <groupId>commons-collections</groupId>
51
      <artifactId>commons-collections</artifactId>
52
      <scope>runtime</scope>
53
    </dependency>
54
    <dependency>
55
      <groupId>commons-pool</groupId>
56
      <artifactId>commons-pool</artifactId>
57
      <scope>runtime</scope>
58
    </dependency>
59
  </dependencies>
60

  
61
    <properties>
62
        <!-- Package info property values -->
63
        <!-- Default values in org.gvsig.desktop -->
64
        <gvsig.package.info.name>Formats: MS SQLServer support</gvsig.package.info.name>
65
        <gvsig.package.info.state>testing</gvsig.package.info.state>
66
        <gvsig.package.info.official>true</gvsig.package.info.official>
67
        <gvsig.package.info.javaVM>j1_8</gvsig.package.info.javaVM>
68
        <gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.3.0</gvsig.package.info.dependencies>
69
        <gvsig.package.info.categories>Formats,Vector,Database</gvsig.package.info.categories>
70
        <gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-mssqlserver/pool/</gvsig.package.info.poolURL>
71
    </properties>
72

  
73

  
74
</project>
tags/org.gvsig.mssqlserver-1.0.43/org.gvsig.mssqlserver.app/org.gvsig.mssqlserver.app.mainplugin/buildNumber.properties
1
#Tue Oct 15 23:52:19 CEST 2019
2
buildNumber=45
0 3

  
tags/org.gvsig.mssqlserver-1.0.43/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<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">
4

  
5
    <modelVersion>4.0.0</modelVersion>
6
    <artifactId>org.gvsig.mssqlserver</artifactId>
7
    <version>1.0.43</version>
8
    <packaging>pom</packaging>
9
    <name>${project.artifactId}</name>
10
    <description>MS SQLServer support fort DAL and gvSIG</description>
11
    <parent>
12
        <groupId>org.gvsig</groupId>
13
        <artifactId>org.gvsig.desktop</artifactId>
14
        <version>2.0.250</version>
15
    </parent>
16

  
17
    <url>https://devel.gvsig.org/redmine/projects/gvsig-mssqlserver</url>
18
    <scm>
19
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-mssqlserver/tags/org.gvsig.mssqlserver-1.0.43</connection>
20
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-mssqlserver/tags/org.gvsig.mssqlserver-1.0.43</developerConnection>
21
        <url>https://devel.gvsig.org/redmine/projects/gvsig-mssqlserver/repository/show/tags/org.gvsig.mssqlserver-1.0.43</url>
22
    </scm>
23

  
24
    <repositories>
25
        <repository>
26
            <id>gvsig-public-http-repository</id>
27
            <name>gvSIG maven public HTTP repository</name>
28
            <url>http://devel.gvsig.org/m2repo/j2se</url>
29
            <releases>
30
                <enabled>true</enabled>
31
                <updatePolicy>daily</updatePolicy>
32
                <checksumPolicy>warn</checksumPolicy>
33
            </releases>
34
            <snapshots>
35
                <enabled>true</enabled>
36
                <updatePolicy>daily</updatePolicy>
37
                <checksumPolicy>warn</checksumPolicy>
38
            </snapshots>
39
        </repository>
40
    </repositories>
41

  
42

  
43
    <build>
44
        <plugins>
45
            <plugin>
46
                <groupId>org.apache.maven.plugins</groupId>
47
                <artifactId>maven-release-plugin</artifactId>
48
                <configuration>
49
                    <tagBase>https://devel.gvsig.org/svn/gvsig-mssqlserver/tags/</tagBase>
50
                    <goals>deploy</goals>
51
                </configuration>
52
            </plugin>                     
53
        </plugins>
54
    </build>
55

  
56

  
57
    <dependencyManagement>
58
        <dependencies>
59
            <dependency>
60
                <groupId>org.gvsig</groupId>
61
                <artifactId>org.gvsig.mssqlserver.provider</artifactId>
62
                <version>1.0.43</version>
63
            </dependency>
64
            <dependency>
65
                <groupId>org.gvsig</groupId>
66
                <artifactId>org.gvsig.mssqlserver.app.mainplugin</artifactId>
67
                <version>1.0.43</version>
68
            </dependency>
69
            <dependency>
70
                <groupId>com.microsoft.sqlserver</groupId>
71
                <artifactId>sqlserver-jdbc</artifactId>
72
                <version>6.0.0</version>
73
            </dependency>
74
        </dependencies>
75
    </dependencyManagement>
76
  
77
    <modules>
78
        <module>org.gvsig.mssqlserver.app</module>
79
        <module>org.gvsig.mssqlserver.provider</module>
80
    </modules>
81

  
82

  
83
</project>
tags/org.gvsig.mssqlserver-1.0.43/org.gvsig.mssqlserver.provider/src/test/java/org/gvsig/mssqlserver/dal/MSSQLServerSQLBuilderTest.java
1
package org.gvsig.mssqlserver.dal;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5
import org.apache.commons.lang3.ArrayUtils;
6
import org.cresques.cts.IProjection;
7
import org.gvsig.fmap.crs.CRSFactory;
8
import org.gvsig.fmap.dal.DALLocator;
9
import org.gvsig.expressionevaluator.ExpressionBuilder;
10
import org.gvsig.expressionevaluator.ExpressionBuilder.Parameter;
11
import org.gvsig.expressionevaluator.ExpressionBuilder.Variable;
12
import org.gvsig.fmap.dal.SQLBuilder;
13
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
14
import org.gvsig.fmap.dal.store.db.DBHelper;
15
import org.gvsig.fmap.geom.DataTypes;
16
import org.gvsig.fmap.geom.Geometry;
17
import org.gvsig.fmap.geom.GeometryLocator;
18
import org.gvsig.fmap.geom.GeometryManager;
19
import org.gvsig.fmap.geom.primitive.Polygon;
20
import static org.gvsig.mssqlserver.dal.MSSQLServerLibrary.NAME;
21
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
22

  
23
public class MSSQLServerSQLBuilderTest extends AbstractLibraryAutoInitTestCase {
24

  
25
    private MSSQLServerHelper helper;
26
    
27
    @Override
28
    protected void doSetUp() throws Exception {
29
        DataManagerProviderServices dataman = 
30
                (DataManagerProviderServices) DALLocator.getDataManager();
31

  
32
        DBHelper.registerParametersDefinition(
33
                NAME + "StoreParameters",
34
                MSSQLServerStoreParameters.class,
35
                dataman.getResourceAsStream(this, NAME + "Parameters.xml")
36
        );
37
        
38
        MSSQLServerStoreParameters params = new MSSQLServerStoreParameters();
39
        params.setHost("127.0.0.1");
40
        params.setDynValue("InstanceName", "SQLEXPRESS");
41
        params.setDBName("master");
42
        params.setSchema("dbo");
43
        params.setTable("test1");
44
        params.setPort(1433);
45
        params.setUser("sa");
46
        params.setPassword("123");
47
        helper = new MSSQLServerHelper(params);
48
    }
49
    
50
    
51
    public SQLBuilder createSQLBuilder() {
52
        return new MSSQLServerSQLBuilder(helper);
53
    }
54
 
55
    public void testCalulateEnvelope() throws Exception {
56
        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
57
        IProjection proj = CRSFactory.getCRS("EPSG:4326");
58
        
59
        Polygon limit = geometryManager.createPolygon(Geometry.SUBTYPES.GEOM2D);
60
        limit.addVertex(0, 0);
61
        limit.addVertex(0, 100);
62
        limit.addVertex(100, 100);
63
        limit.addVertex(100, 0);
64
        limit.addVertex(0, 0);
65
        
66
        SQLBuilder sqlbuilder = createSQLBuilder();
67
        ExpressionBuilder expbuilder = sqlbuilder.expression();
68
        
69
        sqlbuilder.select().column().value(
70
            expbuilder.as_geometry(
71
              expbuilder.ST_ExtentAggregate(
72
                expbuilder.column("the_geom")
73
              )
74
            )
75
        ).as("envelope");
76
        sqlbuilder.select().from().table().database("master").schema("dbo").name("test1");
77
        sqlbuilder.select().where().set(
78
            expbuilder.ST_Intersects(
79
                expbuilder.ST_Envelope(
80
                    expbuilder.column("the_geom")
81
                ),
82
                expbuilder.geometry(limit, proj)
83
            )
84
        );
85
        sqlbuilder.select().where().and(
86
                expbuilder.custom("x = 27").add( expbuilder.variable("x") )
87
        );
88
        
89
        System.out.println("# Test:: testCalulateEnvelope");
90
        System.out.println("# SQL:: " + sqlbuilder.toString());
91
        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
92
        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
93
    
94
        //# Test:: testCalulateEnvelope
95
        //# 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
96
        //# Variables:: [the_geom, x]
97
        //# Parametros:: []    
98
        assertEquals(
99
                "SELECT (geometry::EnvelopeAggregate([the_geom])).STAsBinary() AS [envelope] FROM [master].[dbo].[test1] WHERE (([the_geom]).STEnvelope()).STIntersects(geometry::STGeomFromWKB(0x000000000300000001000000050000000000000000000000000000000000000000000000004059000000000000405900000000000040590000000000004059000000000000000000000000000000000000000000000000000000000000, 4326)) AND x = 27",
100
                sqlbuilder.toString()
101
        );
102
        assertEquals(
103
                "[the_geom, x]",
104
                ArrayUtils.toString(sqlbuilder.variables_names())
105
        );
106
        assertEquals(
107
                "[]",
108
                ArrayUtils.toString(sqlbuilder.parameters_names())
109
        );
110
    }
111

  
112
    public void testCount() throws Exception {
113
        SQLBuilder sqlbuilder = createSQLBuilder();
114
        ExpressionBuilder expbuilder = sqlbuilder.expression();
115
        
116
        sqlbuilder.select().column().value(sqlbuilder.count().all());
117
        sqlbuilder.select().from().table().database("master").schema("dbo").name("test1");
118
        sqlbuilder.select().from().subquery(null);
119
        sqlbuilder.select().where().set( expbuilder.custom("pp = 200").add(expbuilder.variable("pp")));
120

  
121
        System.out.println("# Test:: testCount");
122
        System.out.println("# SQL:: " + sqlbuilder.toString());
123
        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
124
        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
125

  
126
        //# Test:: testCount
127
        //# SQL:: SELECT COUNT(*) FROM [master].[dbo].[test1] WHERE pp = 200
128
        //# Variables:: []
129
        //# Parametros:: []
130
    
131
        assertEquals(
132
                "SELECT COUNT(*) FROM [master].[dbo].[test1] WHERE pp = 200",
133
                sqlbuilder.toString()
134
        );
135
        assertEquals(
136
                "[pp]",
137
                ArrayUtils.toString(sqlbuilder.variables_names())
138
        );
139
        assertEquals(
140
                "[]",
141
                ArrayUtils.toString(sqlbuilder.parameters_names())
142
        );
143
    }
144
    
145
    public void testUpdateStatistics() throws Exception {
146
        SQLBuilder sqlbuilder = createSQLBuilder();
147
        ExpressionBuilder expbuilder = sqlbuilder.expression();
148
        
149
        sqlbuilder.update_table_statistics().table().database("master").schema("dbo").name("test1");
150

  
151
        System.out.println("# Test:: testUpdateStatistics");
152
        System.out.println("# SQL:: " + sqlbuilder.toString());
153
        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
154
        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
155

  
156
        //# Test:: testUpdateStatistics
157
        //# SQL:: UPDATE STATISTICS [master].[dbo].[test1]
158
        //# Variables:: []
159
        //# Parametros:: []
160
    
161
        assertEquals(
162
                "UPDATE STATISTICS [master].[dbo].[test1]",
163
                sqlbuilder.toString()
164
        );
165
        assertEquals(
166
                "[]",
167
                ArrayUtils.toString(sqlbuilder.variables_names())
168
        );
169
        assertEquals(
170
                "[]",
171
                ArrayUtils.toString(sqlbuilder.parameters_names())
172
        );
173
    }
174
    
175
    public void testCreateTable() throws Exception {
176
        SQLBuilder sqlbuilder = createSQLBuilder();
177
        ExpressionBuilder expbuilder = sqlbuilder.expression();
178
        
179
        sqlbuilder.create_table().table().database("master").schema("dbo").name("test1");
180
        sqlbuilder.create_table().add_column(
181
                "name",
182
                DataTypes.STRING,
183
                45,
184
                0,
185
                false,
186
                false,
187
                true,
188
                false,
189
                null
190
        );
191
        sqlbuilder.create_table().add_column(
192
                "id",
193
                DataTypes.INT,
194
                0,
195
                0,
196
                true,
197
                false,
198
                false,
199
                true,
200
                0
201
        );
202
        sqlbuilder.create_table().add_column(
203
                "geom",
204
                DataTypes.GEOMETRY,
205
                0,
206
                0,
207
                false,
208
                false,
209
                true,
210
                false,
211
                null
212
        );
213

  
214
        System.out.println("# Test:: testCreateTable");
215
        System.out.println("# SQL:: " + sqlbuilder.toString());
216
        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
217
        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
218

  
219
        //# Test:: testCreateTable
220
        //# 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 )
221
        //# Variables:: []
222
        //# Parametros:: []
223

  
224
        assertEquals(
225
                "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 )",
226
                sqlbuilder.toString()
227
        );
228
        assertEquals(
229
                "[]",
230
                ArrayUtils.toString(sqlbuilder.variables_names())
231
        );
232
        assertEquals(
233
                "[]",
234
                ArrayUtils.toString(sqlbuilder.parameters_names())
235
        );
236
    }
237

  
238
    public void testDropTable() throws Exception {
239
        SQLBuilder sqlbuilder = createSQLBuilder();
240
        ExpressionBuilder expbuilder = sqlbuilder.expression();
241
        
242
        sqlbuilder.drop_table().table().database("master").schema("dbo").name("test1");
243

  
244
        System.out.println("# Test:: testDropTable");
245
        System.out.println("# SQL:: " + sqlbuilder.toString());
246
        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
247
        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
248

  
249
        //# Test:: testDropTable
250
        //# SQL:: DROP TABLE [master].[dbo].[test1]
251
        //# Variables:: []
252
        //# Parametros:: []
253
        
254
        assertEquals(
255
                "DROP TABLE [master].[dbo].[test1]",
256
                sqlbuilder.toString()
257
        );
258
        assertEquals(
259
                "[]",
260
                ArrayUtils.toString(sqlbuilder.variables_names())
261
        );
262
        assertEquals(
263
                "[]",
264
                ArrayUtils.toString(sqlbuilder.parameters_names())
265
        );
266
    }
267
    
268
    public void testFetchFeatureProviderByReference() throws Exception {
269
        SQLBuilder sqlbuilder = createSQLBuilder();
270
        ExpressionBuilder expbuilder = sqlbuilder.expression();
271
        
272
        String value = "yoyo";
273
        sqlbuilder.select().column().name("name");
274
        sqlbuilder.select().column().name("id");
275
        sqlbuilder.select().column().name("geom").as_geometry();
276
        sqlbuilder.select().from().table().database("master").schema("dbo").name("test1");
277
        sqlbuilder.select().where().set(
278
            expbuilder.eq(
279
                expbuilder.column("name"),
280
                expbuilder.parameter(value).as_constant()
281
            )
282
        );
283
        sqlbuilder.select().limit(1);
284

  
285
        System.out.println("# Test:: testFetchFeatureProviderByReference");
286
        System.out.println("# SQL:: " + sqlbuilder.toString());
287
        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
288
        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
289

  
290
        //# Test:: testFetchFeatureProviderByReference
291
        //# SQL:: SELECT TOP 1 [name], [id], ([geom]).STAsBinary() FROM [master].[dbo].[test1] WHERE ( ([name]) = (?) )
292
        //# Variables:: [geom, id, name]
293
        //# Parametros:: ['yoyo']
294

  
295
        assertEquals(
296
                "SELECT TOP 1 [name], [id], ([geom]).STAsBinary() FROM [master].[dbo].[test1] WHERE ( ([name]) = (?) )",
297
                sqlbuilder.toString()
298
        );
299
        assertEquals(
300
                "[geom, id, name]",
301
                ArrayUtils.toString(sqlbuilder.variables_names())
302
        );
303
        assertEquals(
304
                "['yoyo']",
305
                ArrayUtils.toString(sqlbuilder.parameters_names())
306
        );
307
    }
308
    
309
    public void testIsNull() throws Exception {
310
        SQLBuilder sqlbuilder = createSQLBuilder();
311
        ExpressionBuilder expbuilder = sqlbuilder.expression();
312
        
313
        sqlbuilder.select().column().name("name");
314
        sqlbuilder.select().column().name("id");
315
        sqlbuilder.select().column().name("geom").as_geometry();
316
        sqlbuilder.select().from().table().database("master").schema("dbo").name("test1");
317
        sqlbuilder.select().where().set(
318
            expbuilder.and(
319
                expbuilder.is_null(
320
                    expbuilder.column("name")
321
                ),
322
                expbuilder.not_is_null(
323
                    expbuilder.column("id")
324
                )
325
            )
326
        );
327
        sqlbuilder.select().limit(2);
328

  
329
        System.out.println("# Test:: testIsNull");
330
        System.out.println("# SQL:: " + sqlbuilder.toString());
331
        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
332
        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
333

  
334
        //# Test:: testIsNull
335
        //# SQL:: SELECT TOP 2 [name], [id], ([geom]).STAsBinary() FROM [master].[dbo].[test1] WHERE ( ([name]) IS NULL ) AND ( ([id]) NOT IS NULL )
336
        //# Variables:: [geom, id, name]
337
        //# Parametros:: []
338

  
339
        assertEquals(
340
                "SELECT TOP 2 [name], [id], ([geom]).STAsBinary() FROM [master].[dbo].[test1] WHERE ( ([name]) IS NULL ) AND ( ([id]) NOT IS NULL )",
341
                sqlbuilder.toString()
342
        );
343
        assertEquals(
344
                "[geom, id, name]",
345
                ArrayUtils.toString(sqlbuilder.variables_names())
346
        );
347
        assertEquals(
348
                "[]",
349
                ArrayUtils.toString(sqlbuilder.parameters_names())
350
        );
351
    }
352
    
353
    public void testFetchFeatureType() throws Exception {
354
        SQLBuilder sqlbuilder = createSQLBuilder();
355
        ExpressionBuilder expbuilder = sqlbuilder.expression();
356
        
357
        sqlbuilder.select().column().all();
358
        sqlbuilder.select().from().table().database("master").schema("dbo").name("test1");
359
        sqlbuilder.select().limit(1);
360

  
361
        System.out.println("# Test:: testFetchFeatureType");
362
        System.out.println("# SQL:: " + sqlbuilder.toString());
363
         System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
364
        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
365

  
366
        //# Test:: testFetchFeatureType
367
        //# SQL:: SELECT TOP 1 * FROM [master].[dbo].[test1]
368
        //# Variables:: []
369
        //# Parametros:: []
370
    
371
        assertEquals(
372
                "SELECT TOP 1 * FROM [master].[dbo].[test1]",
373
                sqlbuilder.toString()
374
        );
375
        assertEquals(
376
                "[]",
377
                ArrayUtils.toString(sqlbuilder.variables_names())
378
        );
379
        assertEquals(
380
                "[]",
381
                ArrayUtils.toString(sqlbuilder.parameters_names())
382
        );
383
    }
384
        
385
    public void testPerformDeletes() throws Exception {
386
        SQLBuilder sqlbuilder = createSQLBuilder();
387
        ExpressionBuilder expbuilder = sqlbuilder.expression();
388
        
389
        sqlbuilder.delete().table().database("master").schema("dbo").name("test1");
390
        sqlbuilder.delete().where().and(
391
            expbuilder.eq( 
392
                expbuilder.column("id1"),
393
                expbuilder.parameter("id1").as_variable()
394
            )
395
        );
396
        sqlbuilder.delete().where().and(
397
            expbuilder.eq( 
398
                expbuilder.column("id2"),
399
                expbuilder.parameter("id2").as_variable()
400
            )
401
        );
402

  
403
        System.out.println("# Test:: testPerformDeletes");
404
        System.out.println("# SQL:: " + sqlbuilder.toString());
405
        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
406
        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
407

  
408
        //# Test:: testPerformDeletes
409
        //# SQL:: DELETE FROM [master].[dbo].[test1] WHERE ( ([id1]) = (?) ) AND ( ([id2]) = (?) )
410
        //# Variables:: [id1, id2]
411
        //# Parametros:: ["id1", "id2"]
412

  
413
        assertEquals(
414
                "DELETE FROM [master].[dbo].[test1] WHERE ( ([id1]) = (?) ) AND ( ([id2]) = (?) )",
415
                sqlbuilder.toString()
416
        );
417
        assertEquals(
418
                "[id1, id2]",
419
                ArrayUtils.toString(sqlbuilder.variables_names())
420
        );
421
        assertEquals(
422
                "[\"id1\", \"id2\"]",
423
                ArrayUtils.toString(sqlbuilder.parameters_names())
424
        );
425
    }
426

  
427
    public void testPerformInserts1() throws Exception {
428
        IProjection proj = CRSFactory.getCRS("EPSG:4326");
429

  
430
        SQLBuilder sqlbuilder = createSQLBuilder();
431
        ExpressionBuilder expbuilder = sqlbuilder.expression();
432
        
433
        sqlbuilder.insert().table().database("master").schema("dbo").name("test1");
434
        sqlbuilder.insert().column().name("id").with_value(expbuilder.parameter("id"));
435
        sqlbuilder.insert().column().name("name").with_value(expbuilder.parameter("name"));
436
        sqlbuilder.insert().column().name("geom").with_value(expbuilder.parameter("geom").as_geometry_variable().srs(proj));
437
        
438
        System.out.println("# Test:: testPerformInserts1");
439
        System.out.println("# SQL:: " + sqlbuilder.toString());
440
        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
441
        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
442

  
443
        //# Test:: testPerformInserts1
444
        //# SQL:: INSERT INTO [master].[dbo].[test1] ( [id], [name], [geom] ) VALUES ( ?, ?, geometry::STGeomFromWKB(?, 4326) )
445
        //# Variables:: [geom, id, name]
446
        //# Parametros:: ["id", "name", "geom"]
447
        
448
        assertEquals(
449
                "INSERT INTO [master].[dbo].[test1] ( [id], [name], [geom] ) VALUES ( ?, ?, geometry::STGeomFromWKB(?, 4326) )",
450
                sqlbuilder.toString()
451
        );
452
        assertEquals(
453
                "[geom, id, name]",
454
                ArrayUtils.toString(sqlbuilder.variables_names())
455
        );
456
        assertEquals(
457
                "[\"id\", \"name\", \"geom\"]",
458
                ArrayUtils.toString(sqlbuilder.parameters_names())
459
        );
460
    }
461

  
462
    public void testPerformInserts2() throws Exception {
463
        IProjection proj = CRSFactory.getCRS("EPSG:4326");
464

  
465
        SQLBuilder sqlbuilder = createSQLBuilder();
466
        ExpressionBuilder expbuilder = sqlbuilder.expression();
467
        
468
        sqlbuilder.insert().table().database("master").schema("dbo").name("test1");
469
        sqlbuilder.insert().column().name("id").with_value(expbuilder.parameter("id"));
470
        sqlbuilder.insert().column().name("name").with_value(expbuilder.parameter("name"));
471
        sqlbuilder.insert().column().name("geom").with_value(expbuilder.parameter("geom").as_geometry_variable().srs(proj));
472
        
473
        System.out.println("# Test:: testPerformInserts2");
474
        System.out.println("# SQL:: " + sqlbuilder.toString());
475
        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
476
        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
477
    
478
        //# Test:: testPerformInserts2
479
        //# SQL:: INSERT INTO [master].[dbo].[test1] ( [id], [name], [geom] ) VALUES ( ?, ?, geometry::STGeomFromWKB(?, ?) )
480
        //# Variables:: [geom, id, name]
481
        //# Parametros:: ["id", "name", "geom", 4326]
482

  
483
        assertEquals(
484
                "INSERT INTO [master].[dbo].[test1] ( [id], [name], [geom] ) VALUES ( ?, ?, geometry::STGeomFromWKB(?, ?) )",
485
                sqlbuilder.toString()
486
        );
487
        assertEquals(
488
                "[geom, id, name]",
489
                ArrayUtils.toString(sqlbuilder.variables_names())
490
        );
491
        assertEquals(
492
                "[\"id\", \"name\", \"geom\", 4326]",
493
                ArrayUtils.toString(sqlbuilder.parameters_names())
494
        );
495
    }
496

  
497
    public void testPerformUpdates() throws Exception {
498
        IProjection proj = CRSFactory.getCRS("EPSG:4326");
499

  
500
        SQLBuilder sqlbuilder = createSQLBuilder();
501
        ExpressionBuilder expbuilder = sqlbuilder.expression();
502
        
503
        sqlbuilder.update().table().database("master").schema("dbo").name("test1");
504
        sqlbuilder.update().where().and(
505
            expbuilder.eq(
506
                expbuilder.column("id"), 
507
                expbuilder.parameter("id").as_variable()
508
            )
509
        );
510
        sqlbuilder.update().column().name("name").with_value(expbuilder.parameter("name"));
511
        sqlbuilder.update().column().name("geom").with_value(
512
                expbuilder.parameter("geom").as_geometry_variable().srs(
513
                        expbuilder.parameter().value(proj))
514
        );
515

  
516
        System.out.println("# Test:: testPerformUpdates");
517
        System.out.println("# SQL:: " + sqlbuilder.toString());
518
        System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names()));
519
        System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names()));
520

  
521
        //# Test:: testPerformUpdates
522
        //# SQL:: UPDATE [master].[dbo].[test1] SET [name] = ?, [geom] = geometry::STGeomFromWKB(?, ?) WHERE ( ([id]) = (?) )
523
        //# Variables:: [geom, id, name]
524
        //# Parametros:: ["name", "geom", 4326, "id"]
525

  
526
        assertEquals(
527
                "UPDATE [master].[dbo].[test1] SET [name] = ?, [geom] = geometry::STGeomFromWKB(?, ?) WHERE ( ([id]) = (?) )",
528
                sqlbuilder.toString()
529
        );
530
        assertEquals(
531
                "[geom, id, name]",
532
                ArrayUtils.toString(sqlbuilder.variables_names())
533
        );
534
        assertEquals(
535
                "[\"name\", \"geom\", 4326, \"id\"]",
536
                ArrayUtils.toString(sqlbuilder.parameters_names())
537
        );
538
    }
539

  
540
}
tags/org.gvsig.mssqlserver-1.0.43/org.gvsig.mssqlserver.provider/src/test/java/org/gvsig/fmap/dal/store/jdbc2/SQLBuilderTest.java
1
//package org.gvsig.fmap.dal.store.jdbc2;
2
//
3
//import java.util.ArrayList;
4
//import java.util.List;
5
//import org.apache.commons.lang3.ArrayUtils;
6
//import org.cresques.cts.IProjection;
7
//import org.gvsig.fmap.crs.CRSFactory;
8
//import org.gvsig.expressionevaluator.ExpressionBuilder;
9
//import org.gvsig.expressionevaluator.ExpressionBuilder.Parameter;
10
//import org.gvsig.expressionevaluator.ExpressionBuilder.Variable;
11
//import org.gvsig.fmap.dal.SQLBuilder;
12
//import org.gvsig.fmap.dal.SQLBuilder.Privilege;
13
//import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase;
14
//import org.gvsig.fmap.geom.DataTypes;
15
//import org.gvsig.fmap.geom.Geometry;
16
//import org.gvsig.fmap.geom.GeometryLocator;
17
//import org.gvsig.fmap.geom.GeometryManager;
18
//import org.gvsig.fmap.geom.primitive.Polygon;
19
//import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
20
//
21
//public class SQLBuilderTest extends AbstractLibraryAutoInitTestCase {
22
//    
23
//    @Override
24
//    protected void doSetUp() throws Exception {
25
//
26
//    }
27
////    
28
////    List<String> getVariableNames(ExpressionBuilder builder) {
29
////        List<String> vars = new ArrayList<>();
30
////        for (Variable var : builder.getVariables()) {
31
////            vars.add(var.getName());
32
////        }
33
////        return vars;
34
////    }
35
////    
36
////    List<String> getParameterNames(ExpressionBuilder builder) {
37
////        List<String> params = new ArrayList<>();
38
////        for (Parameter param : builder.getParameters()) {
39
////            String s;
40
////            switch(param.getType()) {
41
////                case Constant:
42
////                    Object value = param.getValue();
43
////                    if( value==null ) {
44
////                        s = "null";
45
////                    } else if( value instanceof String ) {
46
////                        s = "'" + (String)value + "'";
47
////                    } else {
48
////                        s = value.toString();
49
////                    }    
50
////                    break;
51
////                case Geometry:
52
////                case Variable:
53
////                default:
54
////                    s = "\"" + param.getName() + "\"";
55
////            }
56
////            params.add(s);
57
////        }
58
////        return params;
59
//    }
60
//    
61
// 
62
//    public void testCalulateEnvelope() throws Exception {
63
//        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
64
//        IProjection proj = CRSFactory.getCRS("EPSG:4326");
65
//        
66
//        Polygon limit = geometryManager.createPolygon(Geometry.SUBTYPES.GEOM2D);
67
//        limit.addVertex(0, 0);
68
//        limit.addVertex(0, 100);
69
//        limit.addVertex(100, 100);
70
//        limit.addVertex(100, 0);
71
//        limit.addVertex(0, 0);
72
//        
73
//        SQLBuilder builder = new SQLBuilderBase();
74
//        
75
//        builder.select().column().value(
76
//            builder.getAsGeometry(
77
//              builder.ST_ExtentAggregate(
78
//                builder.column("the_geom")
79
//              )
80
//            )
81
//        ).as("envelope");
82
//        builder.select().from().table().database("master").schema("dbo").name("test1");
83
//        builder.select().where().set(
84
//            builder.ST_Intersects(
85
//                builder.ST_Envelope(
86
//                    builder.column("the_geom")
87
//                ),
88
//                builder.geometry(limit, proj)
89
//            )
90
//        );
91
//        builder.select().where().and(
92
//                builder.custom("x = 27")
93
//        );
94
//        
95
//        // 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
96
//        
97
//        System.out.println("# Test:: testCalulateEnvelope");
98
//        System.out.println("# SQL:: " + builder.toString());
99
//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
100
//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
101
//        assertEquals(
102
//                "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",
103
//                builder.toString()
104
//        );
105
//        assertEquals(
106
//                "[the_geom]",
107
//                ArrayUtils.toString(getVariableNames(builder))
108
//        );
109
//        assertEquals(
110
//                "[]",
111
//                ArrayUtils.toString(getParameterNames(builder))
112
//        );
113
//    }
114
//
115
//    public void testCount() throws Exception {
116
//        SQLBuilder builder = new SQLBuilderBase();
117
//        
118
//        builder.select().column().value(builder.count().all());
119
//        builder.select().from().table().database("master").schema("dbo").name("test1");
120
//        builder.select().from().subquery(null);
121
//        builder.select().where().set( builder.custom("pp = 200"));
122
//
123
//        System.out.println("# Test:: testCount");
124
//        System.out.println("# SQL:: " + builder.toString());
125
//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
126
//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
127
//
128
//        //# Test:: testCount
129
//        //# SQL:: SELECT COUNT(*) FROM "master"."dbo"."test1" WHERE pp = 200
130
//        //# Variables:: []
131
//        //# Parametros:: []
132
//
133
//        assertEquals(
134
//                "SELECT COUNT(*) FROM \"master\".\"dbo\".\"test1\" WHERE pp = 200",
135
//                builder.toString()
136
//        );
137
//        assertEquals(
138
//                "[]",
139
//                ArrayUtils.toString(getVariableNames(builder))
140
//        );
141
//        assertEquals(
142
//                "[]",
143
//                ArrayUtils.toString(getParameterNames(builder))
144
//        );
145
//    }
146
//    
147
//    public void testCreateTable() throws Exception {
148
//        SQLBuilder builder = new SQLBuilderBase();
149
//
150
//        builder.create_table().table().database("master").schema("dbo").name("test1");
151
//        builder.create_table().add_column(
152
//                "name",
153
//                DataTypes.STRING,
154
//                45,
155
//                0,
156
//                false,
157
//                false,
158
//                true,
159
//                false,
160
//                null
161
//        );
162
//        builder.create_table().add_column(
163
//                "id",
164
//                DataTypes.INT,
165
//                0,
166
//                0,
167
//                true,
168
//                false,
169
//                false,
170
//                true,
171
//                0
172
//        );
173
//        builder.create_table().add_column(
174
//                "geom",
175
//                DataTypes.GEOMETRY,
176
//                0,
177
//                0,
178
//                false,
179
//                false,
180
//                true,
181
//                false,
182
//                null
183
//        );
184
//
185
//        
186
//        // CREATE TABLE "master"."dbo"."test1" ("name" VARCHAR(45) DEFAULT NULL NULL, "id" SERIAL DEFAULT '0' NOT NULL PRIMARY KEY, "geom" TEXT DEFAULT NULL NULL )
187
//        System.out.println("# Test:: testCreateTable");
188
//        System.out.println("# SQL:: " + builder.toString());
189
//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
190
//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
191
//        assertEquals(
192
//                "CREATE TABLE \"master\".\"dbo\".\"test1\" (\"name\" VARCHAR(45) DEFAULT NULL NULL, \"id\" SERIAL DEFAULT '0' NOT NULL PRIMARY KEY, \"geom\" TEXT DEFAULT NULL NULL )",
193
//                builder.toString()
194
//        );
195
//        assertEquals(
196
//                "[]",
197
//                ArrayUtils.toString(getVariableNames(builder))
198
//        );
199
//        assertEquals(
200
//                "[]",
201
//                ArrayUtils.toString(getParameterNames(builder))
202
//        );
203
//    }
204
//
205
//    public void testDropTable() throws Exception {
206
//        SQLBuilder builder = new SQLBuilderBase();
207
//        
208
//        builder.drop_table().table().database("master").schema("dbo").name("test1");
209
//
210
//        // DROP TABLE "master"."dbo"."test1"; DELETE FROM GEOMETRY_COLUMNS WHERE f_table_schema = 'dbo' AND f_table_name = 'test1'
211
//        
212
//        System.out.println("# Test:: testDropTable");
213
//        System.out.println("# SQL:: " + builder.toString());
214
//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
215
//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
216
//        assertEquals(
217
//                "DROP TABLE \"master\".\"dbo\".\"test1\"; DELETE FROM GEOMETRY_COLUMNS WHERE f_table_schema = 'dbo' AND f_table_name = 'test1'",
218
//                builder.toString()
219
//        );
220
//        assertEquals(
221
//                "[]",
222
//                ArrayUtils.toString(getVariableNames(builder))
223
//        );
224
//        assertEquals(
225
//                "[]",
226
//                ArrayUtils.toString(getParameterNames(builder))
227
//        );
228
//    }
229
//    
230
//    public void testFetchFeatureProviderByReference() throws Exception {
231
//        SQLBuilder builder = new SQLBuilderBase();
232
//        
233
//        String value = "yoyo";
234
//        builder.select().column().name("name");
235
//        builder.select().column().name("id");
236
//        builder.select().column().name("geom").as_geometry();
237
//        builder.select().from().table().database("master").schema("dbo").name("test1");
238
//        builder.select().where().set(
239
//            builder.eq(
240
//                builder.column("name"),
241
//                builder.parameter(value).as_constant()
242
//            )
243
//        );
244
//        builder.select().limit(1);
245
//
246
//        // SELECT "name", "id", ST_AsBinary("geom") FROM "master"."dbo"."test1" WHERE ( ("name") = (?) ) LIMIT 1
247
//
248
//        System.out.println("# Test:: testFetchFeatureProviderByReference");
249
//        System.out.println("# SQL:: " + builder.toString());
250
//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
251
//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
252
//        assertEquals(
253
//                "SELECT \"name\", \"id\", ST_AsBinary(\"geom\") FROM \"master\".\"dbo\".\"test1\" WHERE ( (\"name\") = (?) ) LIMIT 1",
254
//                builder.toString()
255
//        );
256
//        assertEquals(
257
//                "[geom, id, name]",
258
//                ArrayUtils.toString(getVariableNames(builder))
259
//        );
260
//        assertEquals(
261
//                "['yoyo']",
262
//                ArrayUtils.toString(getParameterNames(builder))
263
//        );
264
//    }
265
//    
266
//    public void testFetchFeatureType() throws Exception {
267
//        SQLBuilder builder = new SQLBuilderBase();
268
//
269
//        builder.select().column().all();
270
//        builder.select().from().table().database("master").schema("dbo").name("test1");
271
//        builder.select().limit(1);
272
//
273
//        System.out.println("# Test:: testFetchFeatureType");
274
//        System.out.println("# SQL:: " + builder.toString());
275
//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
276
//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
277
//        
278
//        //# Test:: testFetchFeatureType
279
//        //# SQL:: SELECT * FROM [master].[dbo].[test1] LIMMIT 1
280
//        //# Variables:: []
281
//        //# Parametros:: []        
282
//        
283
//        assertEquals(
284
//                "SELECT * FROM \"master\".\"dbo\".\"test1\" LIMIT 1",
285
//                builder.toString()
286
//        );
287
//        assertEquals(
288
//                "[]",
289
//                ArrayUtils.toString(getVariableNames(builder))
290
//        );
291
//        assertEquals(
292
//                "[]",
293
//                ArrayUtils.toString(getParameterNames(builder))
294
//        );
295
//    }
296
//        
297
//    public void testPerformDeletes() throws Exception {
298
//        SQLBuilder builder = new SQLBuilderBase();
299
//
300
//        builder.delete().table().database("master").schema("dbo").name("test1");
301
//        builder.delete().where().and(
302
//            builder.eq( 
303
//                builder.column("id1"),
304
//                builder.parameter("id1").as_variable()
305
//            )
306
//        );
307
//        builder.delete().where().and(
308
//            builder.eq( 
309
//                builder.column("id2"),
310
//                builder.parameter("id2").as_variable()
311
//            )
312
//        );
313
//
314
//        // DELETE FROM "master"."dbo"."test1" WHERE ( ("id1") = (?) ) AND ( ("id2") = (?) )
315
//
316
//        System.out.println("# Test:: testPerformDeletes");
317
//        System.out.println("# SQL:: " + builder.toString());
318
//        System.out.println("# Variables:: " + ArrayUtils.toString(getVariableNames(builder)));
319
//        System.out.println("# Parametros:: " + ArrayUtils.toString(getParameterNames(builder)));
320
//        assertEquals(
321
//                "DELETE FROM \"master\".\"dbo\".\"test1\" WHERE ( (\"id1\") = (?) ) AND ( (\"id2\") = (?) )",
322
//                builder.toString()
323
//        );
324
//        assertEquals(
325
//                "[id1, id2]",
326
//                ArrayUtils.toString(getVariableNames(builder))
327
//        );
328
//        assertEquals(
329
//                "[\"id1\", \"id2\"]",
330
//                ArrayUtils.toString(getParameterNames(builder))
331
//        );
332
//    }
333
//
334
//    public void testPerformInserts1() throws Exception {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff