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 @ 47787

History | View | Annotate | Download (5.3 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.apache.commons.lang3.StringUtils;
29
import org.gvsig.fmap.dal.DataStoreParameters;
30
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
31
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters;
32
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
33
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParametersBase;
34

    
35
public class H2SpatialStoreParameters extends JDBCStoreParametersBase implements H2SpatialConnectionParameters {
36

    
37
    private final H2SpatialConnectionParametersHelper helper;
38

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

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

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

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

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

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

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

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

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

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

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

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

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

    
174
    }
175
}