Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.h2spatial / org.gvsig.h2spatial.h2gis132 / org.gvsig.h2spatial.h2gis132.provider / src / main / java / org / gvsig / fmap / dal / store / h2 / H2SpatialStoreParameters.java @ 47784

History | View | Annotate | Download (5.26 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
 */
22
package org.gvsig.fmap.dal.store.h2;
23

    
24
import java.io.File;
25
import java.io.IOException;
26
import java.util.Properties;
27
import org.apache.commons.io.FilenameUtils;
28
import org.gvsig.fmap.dal.DataStoreParameters;
29
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
30
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters;
31
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
32
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParametersBase;
33

    
34
public class H2SpatialStoreParameters extends JDBCStoreParametersBase implements H2SpatialConnectionParameters {
35

    
36
    private final H2SpatialConnectionParametersHelper helper;
37

    
38
    public H2SpatialStoreParameters() {
39
        super(
40
                H2SpatialLibrary.NAME + "StoreParameters",
41
                H2SpatialLibrary.NAME
42
        );
43
        this.helper = new H2SpatialConnectionParametersHelper(this);
44
    }
45

    
46
    @Override
47
    public String getUrl() {
48
        return this.helper.getUrl();
49
    }
50

    
51
    @Override
52
    public void validate() throws ValidateDataParametersException {
53
        this.helper.validate();
54
        super.validate();
55
    }
56

    
57
    @Override
58
    public Properties getProperties() {
59
        return this.helper.getProperties();
60
    }
61

    
62
    @Override
63
    public File getFile() {
64
        return this.helper.getFile();
65
    }
66

    
67
    @Override
68
    public void setFile(File database) {
69
        try {
70
            this.helper.setFile(database);
71
            String url = H2SpatialUtils.getConnectionURL((H2SpatialConnectionParameters) this);
72
            this.setDynValue(JDBCConnectionParameters.URL_PARAMTER_NAME, url);
73
        } catch (Exception ex) {
74
        }
75
    }
76

    
77
    @Override
78
    public int getMaxSecondsIdle() {
79
        return this.helper.getMaxSecondsIdle();
80
    }
81

    
82
    @Override
83
    public boolean getServerAllowOthers() {
84
        return this.helper.getServerAllowOthers();
85
    }
86

    
87
    @Override
88
    public int getServerPort() {
89
        return this.helper.getServerPort();
90
    }
91

    
92
    @Override
93
    public String getServerPortAsString() {
94
        return this.helper.getServerPortAsString();
95
    }
96

    
97
    public int getSplitSize() {
98
        return this.helper.getSplitSize();
99
    }
100

    
101
    @Override
102
    public boolean isTheSameStore(DataStoreParameters params) {
103
        if(!(params instanceof H2SpatialStoreParameters)){
104
            return false;
105
        }
106
        File f1 = H2SpatialUtils.normalizeH2File(this.getFile());
107
        File f2 = H2SpatialUtils.normalizeH2File(((H2SpatialStoreParameters)params).getFile());
108
        try {
109
            if(!FilenameUtils.equalsOnSystem(f1.getCanonicalPath(), f2.getCanonicalPath())){
110
                return false;
111
            }
112
        } catch (IOException ex) {
113
            if(!FilenameUtils.equalsOnSystem(f1.getAbsolutePath(), f2.getAbsolutePath())){
114
                return false;
115
            }
116
        }
117
        return super.isTheSameStore(params);
118
        
119
    }
120
    
121
    
122
    @Override
123
    public boolean getMaintainGlobalConnection() {
124
        return this.helper.getMaintainGlobalConnection();
125
    }
126

    
127
    @Override
128
    public String getSourceId() {
129
        StringBuilder builder = new StringBuilder();
130
        builder.append(this.getTable());
131
        builder.append("(");
132
        boolean needComma = false;
133
        if( StringUtils.isNotBlank(this.getHost()) ) {
134
            builder.append("host=");
135
            builder.append(this.getHost());
136
            needComma = true;
137
        }
138
        if( this.getPort()>0 ) {
139
            if (needComma ) {
140
                builder.append(", ");
141
            }
142
            builder.append("port=");
143
            builder.append(this.getPort());
144
            needComma = true;
145
        }
146
        if( StringUtils.isNotBlank(this.getDBName()) ) {
147
            if (needComma ) {
148
                builder.append(", ");
149
            }
150
            builder.append("db=");
151
            builder.append(this.getDBName());
152
            needComma = true;
153
        }
154
        if( StringUtils.isNotBlank(this.getSchema()) ) {
155
            if (needComma ) {
156
                builder.append(", ");
157
            }
158
            builder.append("schema=");
159
            builder.append(this.getSchema());
160
            needComma = true;
161
        }
162
        File f = this.getFile();       
163
        if( f != null) {
164
            if (needComma ) {
165
                builder.append(", ");
166
            }
167
            builder.append("file=");
168
            builder.append(this.getFile().getAbsolutePath());
169
        }
170
        builder.append(")");
171
        return builder.toString();
172

    
173
    }
174
}