Revision 44304
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/BaseStoresRepository.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal; |
|
2 |
|
|
3 |
import java.util.HashMap; |
|
4 |
import java.util.Map; |
|
5 |
import org.gvsig.tools.util.UnmodifiableBasicSet; |
|
6 |
import org.gvsig.tools.util.UnmodifiableBasicSetAdapter; |
|
7 |
|
|
8 |
/** |
|
9 |
* |
|
10 |
* @author jjdelcerro |
|
11 |
*/ |
|
12 |
@SuppressWarnings("UseSpecificCatch") |
|
13 |
public class BaseStoresRepository |
|
14 |
extends AbstractStoresRepository |
|
15 |
implements StoresRepository |
|
16 |
{ |
|
17 |
|
|
18 |
private final Map<String,DataStoreParameters> repository; |
|
19 |
|
|
20 |
public BaseStoresRepository(String name) { |
|
21 |
super(name); |
|
22 |
this.repository = new HashMap<>(); |
|
23 |
} |
|
24 |
|
|
25 |
|
|
26 |
@Override |
|
27 |
protected DataStoreParameters getMyParameters(String name) { |
|
28 |
return this.repository.get(name); |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
protected boolean isEmptyMyRepository() { |
|
33 |
return this.repository.isEmpty(); |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
protected int getMySize() { |
|
38 |
return this.repository.size(); |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
protected UnmodifiableBasicSet<String> getMyKeySet() { |
|
43 |
return new UnmodifiableBasicSetAdapter<>(this.repository.keySet()); |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public void add(String name, DataStoreParameters parameters) { |
|
48 |
this.repository.put(name, parameters); |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public void remove(String name) { |
|
53 |
this.repository.remove(name); |
|
54 |
} |
|
55 |
|
|
56 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/StoresRepository.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal; |
2 | 2 |
|
3 |
import java.util.Collection; |
|
3 | 4 |
import org.gvsig.tools.util.UnmodifiableBasicMap; |
4 | 5 |
|
5 | 6 |
/** |
6 | 7 |
* |
7 | 8 |
* @author jjdelcerro |
8 | 9 |
*/ |
9 |
public interface StoresRepository extends UnmodifiableBasicMap<String, DataStore> { |
|
10 |
public interface StoresRepository extends UnmodifiableBasicMap<String, DataStoreParameters> {
|
|
10 | 11 |
|
12 |
public String getID(); |
|
13 |
|
|
14 |
public String getLabel(); |
|
15 |
|
|
16 |
public Collection<StoresRepository> getSubrepositories(); |
|
17 |
|
|
18 |
public boolean addRepository(StoresRepository repository); |
|
19 |
|
|
20 |
public boolean removeRepository(String name); |
|
21 |
|
|
11 | 22 |
public void add(String name, DataStoreParameters parameters); |
12 | 23 |
|
13 | 24 |
public void remove(String name); |
14 | 25 |
|
26 |
public DataStore getStore(String name); |
|
27 |
|
|
15 | 28 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/AbstractStoresRepository.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Collection; |
|
5 |
import java.util.Iterator; |
|
6 |
import java.util.List; |
|
7 |
import java.util.Map; |
|
8 |
import org.apache.commons.lang3.StringUtils; |
|
9 |
import org.gvsig.tools.util.UnmodifiableBasicSet; |
|
10 |
import org.gvsig.tools.util.UnmodifiableBasicSetChained; |
|
11 |
|
|
12 |
/** |
|
13 |
* |
|
14 |
* @author jjdelcerro |
|
15 |
*/ |
|
16 |
@SuppressWarnings("UseSpecificCatch") |
|
17 |
public abstract class AbstractStoresRepository implements StoresRepository { |
|
18 |
|
|
19 |
private final String name; |
|
20 |
private final String label; |
|
21 |
private final List<StoresRepository> subrepositories; |
|
22 |
|
|
23 |
public AbstractStoresRepository(String name) { |
|
24 |
this(name, null); |
|
25 |
} |
|
26 |
|
|
27 |
public AbstractStoresRepository(String name, String label) { |
|
28 |
this.name = name; |
|
29 |
this.label = label; |
|
30 |
this.subrepositories = new ArrayList<>(); |
|
31 |
} |
|
32 |
|
|
33 |
protected abstract DataStoreParameters getMyParameters(String name); |
|
34 |
|
|
35 |
protected abstract boolean isEmptyMyRepository(); |
|
36 |
|
|
37 |
protected abstract int getMySize(); |
|
38 |
|
|
39 |
protected abstract UnmodifiableBasicSet<String> getMyKeySet(); |
|
40 |
|
|
41 |
@Override |
|
42 |
public void add(String name, DataStoreParameters parameters) { |
|
43 |
throw new UnsupportedOperationException(); |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public void remove(String name) { |
|
48 |
throw new UnsupportedOperationException(); |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public String getID() { |
|
53 |
return this.name; |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public String getLabel() { |
|
58 |
if( StringUtils.isBlank(this.label) ) { |
|
59 |
return this.getID(); |
|
60 |
} |
|
61 |
return this.label; |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public Collection<StoresRepository> getSubrepositories() { |
|
66 |
return this.subrepositories; |
|
67 |
} |
|
68 |
|
|
69 |
@Override |
|
70 |
public boolean addRepository(StoresRepository repository) { |
|
71 |
this.removeRepository(repository.getID()); |
|
72 |
this.subrepositories.add(repository); |
|
73 |
return true; |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public boolean removeRepository(String name) { |
|
78 |
for (int i = 0; i < subrepositories.size(); i++) { |
|
79 |
StoresRepository repo = subrepositories.get(i); |
|
80 |
if( StringUtils.equalsIgnoreCase(name, repo.getID()) ) { |
|
81 |
this.subrepositories.remove(i); |
|
82 |
return true; |
|
83 |
} |
|
84 |
} |
|
85 |
return false; |
|
86 |
} |
|
87 |
|
|
88 |
@Override |
|
89 |
public DataStoreParameters get(String name) { |
|
90 |
DataStoreParameters parameters = this.getMyParameters(name); |
|
91 |
if( parameters!=null ) { |
|
92 |
return parameters; |
|
93 |
} |
|
94 |
for ( StoresRepository theRepository : this.subrepositories) { |
|
95 |
parameters = theRepository.get(name); |
|
96 |
if( parameters!=null ) { |
|
97 |
return parameters; |
|
98 |
} |
|
99 |
} |
|
100 |
return null; |
|
101 |
} |
|
102 |
|
|
103 |
@Override |
|
104 |
public DataStore getStore(String name) { |
|
105 |
DataStoreParameters parameters = this.get(name); |
|
106 |
if( parameters!=null ) { |
|
107 |
try { |
|
108 |
DataStore store = DALLocator.getDataManager().openStore( |
|
109 |
parameters.getDataStoreName(), |
|
110 |
parameters |
|
111 |
); |
|
112 |
return store; |
|
113 |
} catch (Exception ex) { |
|
114 |
throw new RuntimeException("Can't open store '"+name+"'.", ex); |
|
115 |
} |
|
116 |
} |
|
117 |
return null; |
|
118 |
} |
|
119 |
|
|
120 |
@Override |
|
121 |
public boolean containsKey(String key) { |
|
122 |
DataStoreParameters parameters = this.getMyParameters(name); |
|
123 |
if( parameters!=null ) { |
|
124 |
return true; |
|
125 |
} |
|
126 |
for ( StoresRepository theRepository : this.subrepositories) { |
|
127 |
if( theRepository.containsKey(key) ) { |
|
128 |
return true; |
|
129 |
} |
|
130 |
} |
|
131 |
return false; |
|
132 |
} |
|
133 |
|
|
134 |
@Override |
|
135 |
public UnmodifiableBasicSet<String> keySet() { |
|
136 |
List<UnmodifiableBasicSet<String>> sets = new ArrayList<>(); |
|
137 |
sets.add(this.getMyKeySet()); |
|
138 |
for (StoresRepository theRepository : this.subrepositories) { |
|
139 |
sets.add(theRepository.keySet()); |
|
140 |
} |
|
141 |
if( sets.isEmpty() ) { |
|
142 |
return UnmodifiableBasicSet.EMPTY_UNMODIFIABLEBASICSET; |
|
143 |
} |
|
144 |
if( sets.size()==1 ) { |
|
145 |
return sets.get(0); |
|
146 |
} |
|
147 |
return new UnmodifiableBasicSetChained( |
|
148 |
sets.toArray( |
|
149 |
new UnmodifiableBasicSet[sets.size()] |
|
150 |
) |
|
151 |
); |
|
152 |
} |
|
153 |
|
|
154 |
@Override |
|
155 |
public Map<String, DataStoreParameters> toMap() { |
|
156 |
throw new UnsupportedOperationException(); |
|
157 |
} |
|
158 |
|
|
159 |
@Override |
|
160 |
public boolean isEmpty() { |
|
161 |
if( !this.isEmptyMyRepository() ) { |
|
162 |
return false; |
|
163 |
} |
|
164 |
for ( StoresRepository theRepository : this.subrepositories) { |
|
165 |
if( !theRepository.isEmpty() ) { |
|
166 |
return false; |
|
167 |
} |
|
168 |
} |
|
169 |
return true; |
|
170 |
} |
|
171 |
|
|
172 |
@Override |
|
173 |
public int size() { |
|
174 |
int sz = 0; |
|
175 |
if( !this.isEmptyMyRepository() ) { |
|
176 |
sz = this.getMySize(); |
|
177 |
} |
|
178 |
for ( StoresRepository theRepository : this.subrepositories) { |
|
179 |
sz += theRepository.size(); |
|
180 |
} |
|
181 |
return sz; |
|
182 |
} |
|
183 |
|
|
184 |
@Override |
|
185 |
public Iterator<DataStoreParameters> iterator() { |
|
186 |
final Iterator<String> it = this.keySet().iterator(); |
|
187 |
return new Iterator<DataStoreParameters>() { |
|
188 |
@Override |
|
189 |
public boolean hasNext() { |
|
190 |
return it.hasNext(); |
|
191 |
} |
|
192 |
|
|
193 |
@Override |
|
194 |
public DataStoreParameters next() { |
|
195 |
String name = it.next(); |
|
196 |
return get(name); |
|
197 |
} |
|
198 |
}; |
|
199 |
} |
|
200 |
|
|
201 |
|
|
202 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/DataManager.java | ||
---|---|---|
73 | 73 |
|
74 | 74 |
public static final String FUNCTION_FOREING_VALUE = "FOREING_VALUE"; |
75 | 75 |
|
76 |
// Constant to manage ResourcesStorage in a DDBB. |
|
77 |
public static final String RESOURCES_TABLE_NAME = "gvsigd_resources"; |
|
78 |
public static final String RESOURCES_FIELD_NAME = "name"; |
|
79 |
public static final String RESOURCES_FIELD_RESOURCE = "resource"; |
|
80 |
|
|
81 | 76 |
/** |
82 | 77 |
* |
83 | 78 |
* Returns the default DAL's temporary directory |
... | ... | |
108 | 103 |
public DataStoreParameters createStoreParameters(String name) |
109 | 104 |
throws InitializeException, ProviderNotRegisteredException; |
110 | 105 |
|
106 |
public DataStoreParameters createStoreParameters(byte[] data); |
|
107 |
|
|
111 | 108 |
/** |
112 | 109 |
* Creates, initializes and fill an instance of DataStoreParameters from the |
113 | 110 |
* tags of the DynStruct passed as parameter. |
... | ... | |
511 | 508 |
|
512 | 509 |
public StoresRepository getStoresRepository(); |
513 | 510 |
|
514 |
public void addStoresRepository(String name, UnmodifiableBasicMap<String,DataStoreParameters> repository); |
|
511 |
public DatabaseWorkspaceManager createDatabaseWorkspaceManager(DataServerExplorerParameters connection); |
|
512 |
|
|
515 | 513 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/DatabaseWorkspaceManager.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
4 |
|
|
5 |
/** |
|
6 |
* |
|
7 |
* @author jjdelcerro |
|
8 |
*/ |
|
9 |
public interface DatabaseWorkspaceManager { |
|
10 |
|
|
11 |
public static final String CONFIG_CAN_ANONYMOUS_USER_WRITE_IN_THE_TABLES = "CanAnonymousUserWriteInTheTables"; |
|
12 |
|
|
13 |
public static final String TABLE_REPOSITORY_NAME = "gvsigd_repository"; |
|
14 |
public static final String TABLE_RESOURCES_NAME = "gvsigd_resources"; |
|
15 |
public static final String TABLE_CONFIGURATION_NAME = "gvsigd_config"; |
|
16 |
|
|
17 |
public static final String FIELD_RESOURCES_NAME = "name"; |
|
18 |
public static final String FIELD_RESOURCES_RESOURCE = "resource"; |
|
19 |
|
|
20 |
public static final String FIELD_REPOSITORY_NAME = "name"; |
|
21 |
public static final String FIELD_REPOSITORY_PARAMETERS = "parameters"; |
|
22 |
|
|
23 |
public static final String FIELD_CONFIGURATION_NAME = "name"; |
|
24 |
public static final String FIELD_CONFIGURATION_VALUE = "value"; |
|
25 |
|
|
26 |
public static final int TABLE_RESOURCES = 0; |
|
27 |
public static final int TABLE_REPOSITORY = 1; |
|
28 |
public static final int TABLE_CONFIGURATION = 2; |
|
29 |
|
|
30 |
public static final String CONFIG_NAME_STORESREPOSITORYID = "StoresRepository.id"; |
|
31 |
public static final String CONFIG_NAME_STORESREPOSITORYLABEL = "StoresRepository.label"; |
|
32 |
|
|
33 |
public String get(String name); |
|
34 |
|
|
35 |
public void set(String name, String value); |
|
36 |
|
|
37 |
public StoresRepository getStoresRepository(); |
|
38 |
|
|
39 |
public boolean storesRepositoryWriteEntry(String name, DataStoreParameters parameters); |
|
40 |
|
|
41 |
public boolean canAnonymousUserWriteInTheTables(); |
|
42 |
|
|
43 |
public boolean existsTable(int tableid); |
|
44 |
|
|
45 |
public FeatureStore getTable(int tableid); |
|
46 |
|
|
47 |
public void createTable(int tableid); |
|
48 |
|
|
49 |
public void dropTable(int tableid); |
|
50 |
|
|
51 |
public boolean isValidStoresRepository(); |
|
52 |
|
|
53 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/DataParameters.java | ||
---|---|---|
53 | 53 |
* if any problem was detected |
54 | 54 |
*/ |
55 | 55 |
public void validate() throws ValidateDataParametersException; |
56 |
|
|
57 |
public byte[] toByteArray(); |
|
56 | 58 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/AbstractFeatureStoreProvider.java | ||
---|---|---|
42 | 42 |
import org.gvsig.fmap.dal.DataServerExplorer; |
43 | 43 |
import org.gvsig.fmap.dal.DataStore; |
44 | 44 |
import org.gvsig.fmap.dal.DataStoreParameters; |
45 |
import org.gvsig.fmap.dal.StoresRepository; |
|
45 | 46 |
import org.gvsig.fmap.dal.exception.CloseException; |
46 | 47 |
import org.gvsig.fmap.dal.exception.DataException; |
47 | 48 |
import org.gvsig.fmap.dal.exception.InitializeException; |
... | ... | |
476 | 477 |
throw new UnsupportedOperationException(); |
477 | 478 |
} |
478 | 479 |
|
479 |
/** |
|
480 |
* unsupported by default, override this otherwise |
|
481 |
* |
|
482 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#supportsAppendMode() |
|
483 |
*/ |
|
484 | 480 |
@Override |
485 | 481 |
public boolean supportsAppendMode() { |
486 | 482 |
return false; |
... | ... | |
491 | 487 |
return UnmodifiableBasicMap.EMPTY_UNMODIFIABLEBASICMAP; |
492 | 488 |
} |
493 | 489 |
|
490 |
@Override |
|
491 |
public StoresRepository getStoresRepository() { |
|
492 |
return null; |
|
493 |
} |
|
494 |
|
|
494 | 495 |
/** |
495 | 496 |
* unsupported by default (return null), override this otherwise |
496 | 497 |
* |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/spi/AbstractDataParameters.java | ||
---|---|---|
22 | 22 |
*/ |
23 | 23 |
package org.gvsig.fmap.dal.spi; |
24 | 24 |
|
25 |
import java.io.ByteArrayOutputStream; |
|
25 | 26 |
import java.io.File; |
26 | 27 |
import java.io.IOException; |
27 | 28 |
import java.util.Iterator; |
... | ... | |
48 | 49 |
import org.gvsig.tools.dynobject.DynObjectManager; |
49 | 50 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
50 | 51 |
import org.gvsig.tools.dynobject.exception.DynObjectValidateException; |
52 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
51 | 53 |
import org.gvsig.tools.persistence.PersistentState; |
52 | 54 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
53 | 55 |
|
... | ... | |
55 | 57 |
* @author jmvivo |
56 | 58 |
* |
57 | 59 |
*/ |
60 |
@SuppressWarnings("UseSpecificCatch") |
|
58 | 61 |
public abstract class AbstractDataParameters implements DataParameters { |
59 | 62 |
|
60 |
private static final Logger logger = LoggerFactory.getLogger(AbstractDataParameters.class);
|
|
63 |
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractDataParameters.class);
|
|
61 | 64 |
|
62 | 65 |
@Override |
63 | 66 |
public Object getDynValue(String name) { |
... | ... | |
87 | 90 |
try { |
88 | 91 |
throw new IllegalArgumentException(name); |
89 | 92 |
} catch (IllegalArgumentException ex) { |
90 |
logger.warn("Attribute '" + name + "' is not defined in "
|
|
93 |
LOGGER.warn("Attribute '" + name + "' is not defined in "
|
|
91 | 94 |
+ delegated.getDynClass().getFullName() + " definition", ex); |
92 | 95 |
} |
93 | 96 |
} |
... | ... | |
140 | 143 |
Object value = state.get(name); |
141 | 144 |
this.setDynValue(name, value); |
142 | 145 |
} catch (Throwable t) { |
143 |
logger.warn("Can't load '" + name + "' property", t);
|
|
146 |
LOGGER.warn("Can't load '" + name + "' property", t);
|
|
144 | 147 |
} |
145 | 148 |
} |
146 | 149 |
} |
... | ... | |
197 | 200 |
this.setDynValue(parameterName, crs); |
198 | 201 |
} |
199 | 202 |
} catch (IOException e) { |
200 |
logger.warn("Couldn't read prj file ''{}''", prjFile.getAbsolutePath());
|
|
203 |
LOGGER.warn("Couldn't read prj file ''{}''", prjFile.getAbsolutePath());
|
|
201 | 204 |
} |
202 | 205 |
} |
203 | 206 |
} |
... | ... | |
212 | 215 |
} |
213 | 216 |
|
214 | 217 |
} catch (IOException e) { |
215 |
logger.warn("Couldn't read wld file ''{}''", wldFile.getAbsolutePath());
|
|
218 |
LOGGER.warn("Couldn't read wld file ''{}''", wldFile.getAbsolutePath());
|
|
216 | 219 |
} |
217 | 220 |
} |
218 | 221 |
} |
219 | 222 |
|
223 |
@Override |
|
224 |
public byte[] toByteArray() { |
|
225 |
try { |
|
226 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
|
227 |
ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
|
228 |
PersistentState state = persistenceManager.getState(this); |
|
229 |
persistenceManager.saveState(state, stream); |
|
230 |
return stream.toByteArray(); |
|
231 |
} catch (Exception ex) { |
|
232 |
LOGGER.warn("Can't get byte[] from parameters.",ex); |
|
233 |
return null; |
|
234 |
} |
|
235 |
} |
|
236 |
|
|
220 | 237 |
/** |
221 | 238 |
* Returns an instance of the {@link DynObject} to delegate to. |
222 | 239 |
* |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/spi/DataStoreProvider.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
import org.gvsig.fmap.dal.DataServerExplorer; |
29 | 29 |
import org.gvsig.fmap.dal.DataStore; |
30 |
import org.gvsig.fmap.dal.StoresRepository; |
|
30 | 31 |
import org.gvsig.fmap.dal.exception.CloseException; |
31 | 32 |
import org.gvsig.fmap.dal.exception.InitializeException; |
32 | 33 |
import org.gvsig.fmap.dal.exception.OpenException; |
... | ... | |
57 | 58 |
*/ |
58 | 59 |
public UnmodifiableBasicMap<String,DataStore> getChildren(); |
59 | 60 |
|
61 |
public StoresRepository getStoresRepository(); |
|
62 |
|
|
60 | 63 |
/** |
61 | 64 |
* Create a {@link DataServerExplorer} from the same source that this store. |
62 | 65 |
* |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/feature/spi/simpleprovider/AbstractSimpleSequentialReader.java | ||
---|---|---|
3 | 3 |
import java.util.Collections; |
4 | 4 |
import java.util.List; |
5 | 5 |
import java.util.Map; |
6 |
import org.gvsig.fmap.dal.StoresRepository; |
|
6 | 7 |
import org.gvsig.fmap.dal.feature.OpenFeatureStoreParameters; |
7 | 8 |
|
8 | 9 |
/** |
... | ... | |
60 | 61 |
return -1; |
61 | 62 |
} |
62 | 63 |
|
64 |
@Override |
|
65 |
public StoresRepository getStoresRepository() { |
|
66 |
return null; |
|
67 |
} |
|
68 |
|
|
63 | 69 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/feature/spi/simpleprovider/SimpleSequentialReaderStoreProvider.java | ||
---|---|---|
41 | 41 |
import org.gvsig.fmap.dal.DataStoreNotification; |
42 | 42 |
import org.gvsig.fmap.dal.DataTypes; |
43 | 43 |
import org.gvsig.fmap.dal.FileHelper; |
44 |
import org.gvsig.fmap.dal.StoresRepository; |
|
44 | 45 |
import org.gvsig.fmap.dal.exception.DataException; |
45 | 46 |
import org.gvsig.fmap.dal.exception.InitializeException; |
46 | 47 |
import org.gvsig.fmap.dal.exception.OpenException; |
... | ... | |
107 | 108 |
private String name; |
108 | 109 |
private long OIDcounter; |
109 | 110 |
private DataStore store; |
111 |
private StoresRepository storesRepository; |
|
110 | 112 |
|
111 | 113 |
public ReaderData() { |
112 | 114 |
this.needCalculateEnvelope = false; |
... | ... | |
172 | 174 |
} |
173 | 175 |
return this.store; |
174 | 176 |
} |
177 |
|
|
178 |
public void setStoresRepository(StoresRepository storesRepository) { |
|
179 |
this.storesRepository = storesRepository; |
|
180 |
} |
|
181 |
|
|
182 |
public StoresRepository getStoresRepository() { |
|
183 |
return storesRepository; |
|
184 |
} |
|
185 |
|
|
175 | 186 |
} |
176 | 187 |
|
177 | 188 |
class Children implements UnmodifiableBasicMap<String, DataStore> { |
... | ... | |
955 | 966 |
|
956 | 967 |
taskStatus.message("_preparing"); |
957 | 968 |
readerData.setName(reader.getName()); |
969 |
readerData.setStoresRepository(reader.getStoresRepository()); |
|
958 | 970 |
|
959 | 971 |
boolean ignore_errors = getParameters().getIgnoreErrors(); |
960 | 972 |
|
... | ... | |
1120 | 1132 |
return new Children(); |
1121 | 1133 |
} |
1122 | 1134 |
|
1135 |
@Override |
|
1136 |
public StoresRepository getStoresRepository() { |
|
1137 |
StoresRepository repo = this.readerData.getStoresRepository(); |
|
1138 |
if( repo == null ) { |
|
1139 |
return super.getStoresRepository(); |
|
1140 |
} |
|
1141 |
return repo; |
|
1142 |
} |
|
1143 |
|
|
1123 | 1144 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/feature/spi/simpleprovider/SimpleSequentialReader.java | ||
---|---|---|
8 | 8 |
import java.io.File; |
9 | 9 |
import java.util.List; |
10 | 10 |
import java.util.Map; |
11 |
import org.gvsig.fmap.dal.StoresRepository; |
|
11 | 12 |
import org.gvsig.fmap.dal.feature.spi.simpleprovider.AutomaticDetectionOfTypes.Rows; |
12 | 13 |
|
13 | 14 |
/** |
... | ... | |
41 | 42 |
|
42 | 43 |
public long getRowCount(); |
43 | 44 |
|
45 |
public StoresRepository getStoresRepository(); |
|
46 |
|
|
44 | 47 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/raster/impl/DefaultCoverageStore.java | ||
---|---|---|
24 | 24 |
package org.gvsig.fmap.dal.raster.impl; |
25 | 25 |
|
26 | 26 |
import java.util.Collection; |
27 |
import java.util.Iterator; |
|
28 |
import java.util.Map; |
|
29 | 27 |
import java.util.Set; |
28 |
import org.gvsig.fmap.dal.BaseStoresRepository; |
|
30 | 29 |
|
31 | 30 |
import org.gvsig.fmap.dal.DataCache; |
32 | 31 |
import org.gvsig.fmap.dal.DataManager; |
... | ... | |
72 | 71 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
73 | 72 |
import org.gvsig.tools.undo.command.Command; |
74 | 73 |
import org.gvsig.tools.util.UnmodifiableBasicMap; |
75 |
import org.gvsig.tools.util.UnmodifiableBasicSet; |
|
76 |
import org.gvsig.tools.util.UnmodifiableBasicSetChained; |
|
77 | 74 |
import org.gvsig.tools.visitor.Visitor; |
78 | 75 |
import org.slf4j.Logger; |
79 | 76 |
import org.slf4j.LoggerFactory; |
... | ... | |
548 | 545 |
@Override |
549 | 546 |
public StoresRepository getStoresRepository() { |
550 | 547 |
final StoresRepository mainRepository = this.dataManager.getStoresRepository(); |
551 |
StoresRepository repository = new StoresRepository() { |
|
548 |
StoresRepository repository = new BaseStoresRepository(this.getName()) { |
|
549 |
|
|
552 | 550 |
@Override |
553 |
public void add(String name, DataStoreParameters parameters) { |
|
554 |
mainRepository.add(name, parameters); |
|
551 |
protected DataStoreParameters getMyParameters(String name) { |
|
552 |
// Uff, esta implementacion no es nada buena |
|
553 |
DataStore store = getChildren().get(name); |
|
554 |
if( store==null ) { |
|
555 |
return null; |
|
556 |
} |
|
557 |
return store.getParameters(); |
|
555 | 558 |
} |
556 | 559 |
|
557 | 560 |
@Override |
558 |
public void remove(String name) { |
|
559 |
mainRepository.remove(name); |
|
561 |
protected boolean isEmptyMyRepository() { |
|
562 |
UnmodifiableBasicMap<String, DataStore> children = getChildren(); |
|
563 |
return children==null || children.isEmpty(); |
|
560 | 564 |
} |
561 | 565 |
|
562 | 566 |
@Override |
563 |
public DataStore get(String key) {
|
|
564 |
DataStore store = getChildren().get(key);
|
|
565 |
if( store != null ) {
|
|
566 |
return store;
|
|
567 |
protected int getMySize() {
|
|
568 |
UnmodifiableBasicMap<String, DataStore> children = getChildren();
|
|
569 |
if( children==null ) {
|
|
570 |
return 0;
|
|
567 | 571 |
} |
568 |
return mainRepository.get(key);
|
|
572 |
return children.size();
|
|
569 | 573 |
} |
570 | 574 |
|
571 | 575 |
@Override |
572 |
public boolean isEmpty() {
|
|
573 |
return getChildren().isEmpty() && mainRepository.isEmpty();
|
|
576 |
public void add(String name, DataStoreParameters parameters) {
|
|
577 |
mainRepository.add(name, parameters);
|
|
574 | 578 |
} |
575 | 579 |
|
576 | 580 |
@Override |
577 |
public boolean containsKey(String key) {
|
|
578 |
return getChildren().containsKey(key) || mainRepository.containsKey(key);
|
|
581 |
public void remove(String name) {
|
|
582 |
mainRepository.remove(name);
|
|
579 | 583 |
} |
580 | 584 |
|
581 |
@Override |
|
582 |
public Map<String, DataStore> toMap() { |
|
583 |
return null; |
|
584 |
} |
|
585 |
|
|
586 |
@Override |
|
587 |
public int size() { |
|
588 |
return getChildren().size()+mainRepository.size(); |
|
589 |
} |
|
590 |
|
|
591 |
@Override |
|
592 |
public UnmodifiableBasicSet<String> keySet() { |
|
593 |
UnmodifiableBasicMap<String, DataStore> children = getChildren(); |
|
594 |
if( children.isEmpty() ) { |
|
595 |
return mainRepository.keySet(); |
|
596 |
} |
|
597 |
return new UnmodifiableBasicSetChained<>( |
|
598 |
children.keySet(), |
|
599 |
mainRepository.keySet() |
|
600 |
); |
|
601 |
} |
|
602 |
|
|
603 |
@Override |
|
604 |
public Iterator<DataStore> iterator() { |
|
605 |
final Iterator<String> it = this.keySet().iterator(); |
|
606 |
return new Iterator<DataStore>() { |
|
607 |
@Override |
|
608 |
public boolean hasNext() { |
|
609 |
return it.hasNext(); |
|
610 |
} |
|
611 |
|
|
612 |
@Override |
|
613 |
public DataStore next() { |
|
614 |
String name = it.next(); |
|
615 |
return get(name); |
|
616 |
} |
|
617 |
}; |
|
618 |
} |
|
619 | 585 |
}; |
620 | 586 |
return repository; |
621 | 587 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/DefaultStoresRepository.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.impl; |
|
2 |
|
|
3 |
import java.util.HashMap; |
|
4 |
import java.util.Iterator; |
|
5 |
import java.util.Map; |
|
6 |
import org.gvsig.fmap.dal.DALLocator; |
|
7 |
import org.gvsig.fmap.dal.DataStore; |
|
8 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
9 |
import org.gvsig.fmap.dal.StoresRepository; |
|
10 |
import org.gvsig.tools.util.GetItemByKey; |
|
11 |
import org.gvsig.tools.util.UnmodifiableBasicMap; |
|
12 |
import org.gvsig.tools.util.UnmodifiableBasicSet; |
|
13 |
import org.gvsig.tools.util.UnmodifiableBasicSetAdapter; |
|
14 |
import org.gvsig.tools.util.UnmodifiableBasicSetChained; |
|
15 |
|
|
16 |
/** |
|
17 |
* |
|
18 |
* @author jjdelcerro |
|
19 |
*/ |
|
20 |
@SuppressWarnings("UseSpecificCatch") |
|
21 |
public class DefaultStoresRepository implements StoresRepository { |
|
22 |
|
|
23 |
private final Map<String,DataStoreParameters> repository; |
|
24 |
private final Map<String,UnmodifiableBasicMap<String,DataStoreParameters>> delegateds; |
|
25 |
|
|
26 |
public DefaultStoresRepository() { |
|
27 |
this.repository = new HashMap<>(); |
|
28 |
this.delegateds = new HashMap<>(); |
|
29 |
} |
|
30 |
|
|
31 |
public void add(String name, UnmodifiableBasicMap<String,DataStoreParameters> repository) { |
|
32 |
this.delegateds.put(name, repository); |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public void add(String name, DataStoreParameters parameters) { |
|
37 |
this.repository.put(name, parameters); |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public void remove(String name) { |
|
42 |
this.repository.remove(name); |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public DataStore get(String name) { |
|
47 |
DataStoreParameters parameters = this.repository.get(name); |
|
48 |
if( parameters==null ) { |
|
49 |
for (GetItemByKey<String,DataStoreParameters> theRepository : this.delegateds.values()) { |
|
50 |
parameters = theRepository.get(name); |
|
51 |
if( parameters!=null ) { |
|
52 |
break; |
|
53 |
} |
|
54 |
} |
|
55 |
if( parameters==null ) { |
|
56 |
throw new IllegalArgumentException("Can't exists store '"+name+"' in the repository."); |
|
57 |
} |
|
58 |
} |
|
59 |
DataStore store; |
|
60 |
try { |
|
61 |
store = DALLocator.getDataManager().openStore(parameters.getDataStoreName(), parameters); |
|
62 |
} catch (Exception ex) { |
|
63 |
throw new RuntimeException("Can't open store '"+name+"'.", ex); |
|
64 |
} |
|
65 |
return store; |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public boolean isEmpty() { |
|
70 |
if( !this.repository.isEmpty() ) { |
|
71 |
return false; |
|
72 |
} |
|
73 |
for (UnmodifiableBasicMap<String,DataStoreParameters> theRepository : this.delegateds.values()) { |
|
74 |
if( !theRepository.isEmpty() ) { |
|
75 |
return false; |
|
76 |
} |
|
77 |
} |
|
78 |
return true; |
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
public boolean containsKey(String name) { |
|
83 |
if( this.repository.containsKey(name) ) { |
|
84 |
return true; |
|
85 |
} |
|
86 |
for (GetItemByKey<String,DataStoreParameters> theRepository : this.delegateds.values()) { |
|
87 |
DataStoreParameters parameters = theRepository.get(name); |
|
88 |
if( parameters!=null ) { |
|
89 |
return true; |
|
90 |
} |
|
91 |
} |
|
92 |
return false; |
|
93 |
} |
|
94 |
|
|
95 |
@Override |
|
96 |
public Map<String, DataStore> toMap() { |
|
97 |
throw new UnsupportedOperationException(); |
|
98 |
} |
|
99 |
|
|
100 |
@Override |
|
101 |
public int size() { |
|
102 |
int sz = this.repository.size(); |
|
103 |
for (UnmodifiableBasicMap<String,DataStoreParameters> theRepository : this.delegateds.values()) { |
|
104 |
sz += theRepository.size(); |
|
105 |
} |
|
106 |
return sz; |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public Iterator<DataStore> iterator() { |
|
111 |
final Iterator<String> it = this.keySet().iterator(); |
|
112 |
return new Iterator<DataStore>() { |
|
113 |
@Override |
|
114 |
public boolean hasNext() { |
|
115 |
return it.hasNext(); |
|
116 |
} |
|
117 |
|
|
118 |
@Override |
|
119 |
public DataStore next() { |
|
120 |
String name = it.next(); |
|
121 |
return get(name); |
|
122 |
} |
|
123 |
}; |
|
124 |
} |
|
125 |
|
|
126 |
@Override |
|
127 |
public UnmodifiableBasicSet<String> keySet() { |
|
128 |
UnmodifiableBasicSet[] sets = new UnmodifiableBasicSet[this.delegateds.size()+1]; |
|
129 |
int i=0; |
|
130 |
sets[i++] = new UnmodifiableBasicSetAdapter(this.repository.keySet()); |
|
131 |
for (UnmodifiableBasicMap<String,DataStoreParameters> theRepository : this.delegateds.values()) { |
|
132 |
sets[i++] = theRepository.keySet(); |
|
133 |
} |
|
134 |
return new UnmodifiableBasicSetChained(sets); |
|
135 |
} |
|
136 |
|
|
137 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/expressionevaluator/DALSymbolTable.java | ||
---|---|---|
89 | 89 |
|
90 | 90 |
protected DataStore getStore(String storeName) { |
91 | 91 |
DataManager dataManager = DALLocator.getDataManager(); |
92 |
DataStore store = dataManager.getStoresRepository().get(storeName); |
|
92 |
DataStore store = dataManager.getStoresRepository().getStore(storeName);
|
|
93 | 93 |
return store; |
94 | 94 |
} |
95 | 95 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/expressionevaluator/DefaultFeatureSymbolTable.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.impl.expressionevaluator; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
4 | 3 |
import java.util.Arrays; |
5 | 4 |
import java.util.List; |
6 | 5 |
import org.apache.commons.lang3.Range; |
... | ... | |
25 | 24 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
26 | 25 |
import org.gvsig.fmap.dal.feature.FeatureType; |
27 | 26 |
import org.gvsig.fmap.dal.feature.ForeingKey; |
28 |
import org.gvsig.fmap.dal.feature.ForeingKey.ContextForeingKey; |
|
29 | 27 |
import static org.gvsig.fmap.dal.impl.expressionevaluator.DALSymbolTable.FUNCTION_FEATURES; |
30 | 28 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DALSymbolTable.FeaturesFunction; |
31 |
import org.gvsig.tools.ToolsLocator; |
|
32 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
33 |
import org.gvsig.tools.dynobject.Tagged; |
|
34 |
import org.gvsig.tools.dynobject.Tags; |
|
35 | 29 |
import org.gvsig.tools.script.Script; |
36 | 30 |
import org.gvsig.tools.util.UnmodifiableBasicList; |
37 | 31 |
import org.gvsig.tools.util.UnmodifiableBasicListAdapter; |
... | ... | |
122 | 116 |
if (store == null) { |
123 | 117 |
StoresRepository repository = dataManager.getStoresRepository(); |
124 | 118 |
if (repository.containsKey(storeName)) { |
125 |
store = repository.get(storeName); |
|
119 |
store = repository.getStore(storeName);
|
|
126 | 120 |
} |
127 | 121 |
} |
128 | 122 |
return store; |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/DatabaseWorkspaceStoresRepository.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.impl; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
|
4 |
import java.util.HashMap; |
|
5 |
import java.util.Map; |
|
6 |
import org.gvsig.fmap.dal.AbstractStoresRepository; |
|
7 |
import org.gvsig.fmap.dal.DALLocator; |
|
8 |
import org.gvsig.fmap.dal.DataManager; |
|
9 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
10 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
11 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
12 |
import org.gvsig.fmap.dal.StoresRepository; |
|
13 |
import org.gvsig.fmap.dal.feature.Feature; |
|
14 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
15 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_REPOSITORY_NAME; |
|
16 |
import org.gvsig.tools.exception.BaseException; |
|
17 |
import org.gvsig.tools.util.UnmodifiableBasicSet; |
|
18 |
import org.gvsig.tools.util.UnmodifiableBasicSetAdapter; |
|
19 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
20 |
import org.gvsig.tools.visitor.Visitor; |
|
21 |
import org.slf4j.Logger; |
|
22 |
import org.slf4j.LoggerFactory; |
|
23 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_REPOSITORY_PARAMETERS; |
|
24 |
|
|
25 |
/** |
|
26 |
* |
|
27 |
* @author jjdelcerro |
|
28 |
*/ |
|
29 |
@SuppressWarnings("UseSpecificCatch") |
|
30 |
public class DatabaseWorkspaceStoresRepository |
|
31 |
extends AbstractStoresRepository |
|
32 |
implements StoresRepository |
|
33 |
{ |
|
34 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDatabaseWorkspaceManager.class); |
|
35 |
|
|
36 |
private final DataServerExplorerParameters connection; |
|
37 |
private Map<String,DataStoreParameters> repository; |
|
38 |
|
|
39 |
public DatabaseWorkspaceStoresRepository(String name, String label, DataServerExplorerParameters connection) { |
|
40 |
super(name, label); |
|
41 |
this.connection = connection; |
|
42 |
this.repository = null; |
|
43 |
} |
|
44 |
|
|
45 |
private FeatureStore getTable() { |
|
46 |
String tableName = DatabaseWorkspaceManager.TABLE_REPOSITORY_NAME; |
|
47 |
try { |
|
48 |
DataManager dataManager = DALLocator.getDataManager(); |
|
49 |
DataServerExplorer server = dataManager.openServerExplorer( |
|
50 |
this.connection.getExplorerName(), |
|
51 |
this.connection |
|
52 |
); |
|
53 |
DataStoreParameters params = server.get(tableName); |
|
54 |
if( params!=null ) { |
|
55 |
FeatureStore store = (FeatureStore) dataManager.openStore( |
|
56 |
params.getDataStoreName(), |
|
57 |
params |
|
58 |
); |
|
59 |
return store; |
|
60 |
} |
|
61 |
} catch (Exception ex) { |
|
62 |
LOGGER.warn("Can't open table '"+tableName+"'.",ex); |
|
63 |
} |
|
64 |
return null; |
|
65 |
} |
|
66 |
|
|
67 |
private void load() { |
|
68 |
try { |
|
69 |
this.repository = new HashMap<>(); |
|
70 |
final DataManager dataManager = DALLocator.getDataManager(); |
|
71 |
FeatureStore store = this.getTable(); |
|
72 |
store.accept(new Visitor() { |
|
73 |
@Override |
|
74 |
public void visit(Object obj) throws VisitCanceledException, BaseException { |
|
75 |
Feature f = (Feature) obj; |
|
76 |
String name = f.getString(FIELD_REPOSITORY_NAME); |
|
77 |
byte[] data = f.getByteArray(FIELD_REPOSITORY_PARAMETERS); |
|
78 |
DataStoreParameters params = dataManager.createStoreParameters(data); |
|
79 |
if( params==null ) { |
|
80 |
LOGGER.warn("Can't restore parameters from repository entry '"+name+"'."); |
|
81 |
return; |
|
82 |
} |
|
83 |
repository.put(name, params); |
|
84 |
} |
|
85 |
}); |
|
86 |
} catch (Exception ex) { |
|
87 |
LOGGER.warn("Can't load repository information", ex); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
@Override |
|
92 |
protected DataStoreParameters getMyParameters(String name) { |
|
93 |
if( this.repository==null ) { |
|
94 |
this.load(); |
|
95 |
} |
|
96 |
return this.repository.get(name); |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
protected boolean isEmptyMyRepository() { |
|
101 |
if( this.repository==null ) { |
|
102 |
this.load(); |
|
103 |
} |
|
104 |
return this.repository.isEmpty(); |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
protected int getMySize() { |
|
109 |
if( this.repository==null ) { |
|
110 |
this.load(); |
|
111 |
} |
|
112 |
return this.repository.size(); |
|
113 |
} |
|
114 |
|
|
115 |
@Override |
|
116 |
protected UnmodifiableBasicSet<String> getMyKeySet() { |
|
117 |
if( this.repository==null ) { |
|
118 |
this.load(); |
|
119 |
} |
|
120 |
return new UnmodifiableBasicSetAdapter<>(this.repository.keySet()); |
|
121 |
} |
|
122 |
|
|
123 |
|
|
124 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/DefaultDatabaseWorkspaceManager.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.impl; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
|
4 |
import org.apache.commons.lang3.StringUtils; |
|
5 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
6 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
7 |
import org.gvsig.fmap.dal.DALLocator; |
|
8 |
import org.gvsig.fmap.dal.DataManager; |
|
9 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
10 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
11 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
12 |
import org.gvsig.fmap.dal.DataTypes; |
|
13 |
import org.gvsig.fmap.dal.StoresRepository; |
|
14 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
15 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
16 |
import org.gvsig.fmap.dal.feature.Feature; |
|
17 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
18 |
//import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters; |
|
19 |
//import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer; |
|
20 |
//import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
21 |
//import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
22 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_REPOSITORY_NAME; |
|
23 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
24 |
import org.slf4j.Logger; |
|
25 |
import org.slf4j.LoggerFactory; |
|
26 |
|
|
27 |
/** |
|
28 |
* |
|
29 |
* @author jjdelcerro |
|
30 |
*/ |
|
31 |
@SuppressWarnings("UseSpecificCatch") |
|
32 |
public class DefaultDatabaseWorkspaceManager implements DatabaseWorkspaceManager { |
|
33 |
|
|
34 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDatabaseWorkspaceManager.class); |
|
35 |
|
|
36 |
private final DataServerExplorerParameters connection; |
|
37 |
private Boolean existsConfiguration = null; |
|
38 |
private StoresRepository storesRepository; |
|
39 |
|
|
40 |
public DefaultDatabaseWorkspaceManager(DataServerExplorerParameters connection) { |
|
41 |
this.connection = connection; |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public boolean existsTable(int tableid) { |
|
46 |
switch(tableid) { |
|
47 |
case TABLE_RESOURCES: |
|
48 |
return this.existsTable(TABLE_RESOURCES_NAME); |
|
49 |
case TABLE_REPOSITORY: |
|
50 |
return this.existsTable(TABLE_REPOSITORY_NAME); |
|
51 |
case TABLE_CONFIGURATION: |
|
52 |
return this.existsTable(TABLE_CONFIGURATION_NAME); |
|
53 |
default: |
|
54 |
throw new IllegalArgumentException("Invalid table identitier "+tableid); |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public void createTable(int tableid) { |
|
60 |
switch(tableid) { |
|
61 |
case TABLE_RESOURCES: |
|
62 |
createTableResources(); |
|
63 |
break; |
|
64 |
case TABLE_REPOSITORY: |
|
65 |
createTableRepository(); |
|
66 |
break; |
|
67 |
case TABLE_CONFIGURATION: |
|
68 |
createTableConfiguration(); |
|
69 |
break; |
|
70 |
default: |
|
71 |
throw new IllegalArgumentException("Invalid table identitier "+tableid); |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
@Override |
|
76 |
public void dropTable(int tableid) { |
|
77 |
switch(tableid) { |
|
78 |
case TABLE_RESOURCES: |
|
79 |
this.dropTable(TABLE_RESOURCES_NAME); |
|
80 |
break; |
|
81 |
case TABLE_REPOSITORY: |
|
82 |
this.dropTable(TABLE_REPOSITORY_NAME); |
|
83 |
break; |
|
84 |
case TABLE_CONFIGURATION: |
|
85 |
this.dropTable(TABLE_CONFIGURATION_NAME); |
|
86 |
break; |
|
87 |
default: |
|
88 |
throw new IllegalArgumentException("Invalid table identitier "+tableid); |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
public FeatureStore getTable(int tableid) { |
|
94 |
switch(tableid) { |
|
95 |
case TABLE_RESOURCES: |
|
96 |
return this.getTable(TABLE_RESOURCES_NAME); |
|
97 |
case TABLE_REPOSITORY: |
|
98 |
return this.getTable(TABLE_REPOSITORY_NAME); |
|
99 |
case TABLE_CONFIGURATION: |
|
100 |
return this.getTable(TABLE_CONFIGURATION_NAME); |
|
101 |
default: |
|
102 |
throw new IllegalArgumentException("Invalid table identitier "+tableid); |
|
103 |
} |
|
104 |
} |
|
105 |
|
|
106 |
private boolean existsTable(String tableName) { |
|
107 |
try { |
|
108 |
DataManager dataManager = DALLocator.getDataManager(); |
|
109 |
DataServerExplorer server = dataManager.openServerExplorer( |
|
110 |
this.connection.getExplorerName(), |
|
111 |
this.connection |
|
112 |
); |
|
113 |
for (DataStoreParameters params : server.list()) { |
|
114 |
String theTableName = (String) params.getDynValue("Table"); |
|
115 |
if( StringUtils.equals(theTableName, tableName) ) { |
|
116 |
return true; |
|
117 |
} |
|
118 |
} |
|
119 |
} catch (Exception ex) { |
|
120 |
LOGGER.warn("Can't check if the table '"+tableName+"' exists.",ex); |
|
121 |
} |
|
122 |
return false; |
|
123 |
} |
|
124 |
|
|
125 |
private FeatureStore getTable(String tableName) { |
|
126 |
try { |
|
127 |
DataManager dataManager = DALLocator.getDataManager(); |
|
128 |
DataServerExplorer server = dataManager.openServerExplorer( |
|
129 |
this.connection.getExplorerName(), |
|
130 |
this.connection |
|
131 |
); |
|
132 |
DataStoreParameters params = server.get(tableName); |
|
133 |
if( params!=null ) { |
|
134 |
FeatureStore store = (FeatureStore) dataManager.openStore( |
|
135 |
params.getDataStoreName(), |
|
136 |
params |
|
137 |
); |
|
138 |
return store; |
|
139 |
} |
|
140 |
} catch (Exception ex) { |
|
141 |
LOGGER.warn("Can't open table '"+tableName+"'.",ex); |
|
142 |
} |
|
143 |
return null; |
|
144 |
} |
|
145 |
|
|
146 |
private void dropTable(String tableName) { |
|
147 |
try { |
|
148 |
DataManager dataManager = DALLocator.getDataManager(); |
|
149 |
DataServerExplorer server = dataManager.openServerExplorer( |
|
150 |
this.connection.getExplorerName(), |
|
151 |
this.connection |
|
152 |
); |
|
153 |
DataStoreParameters params = server.get(tableName); |
|
154 |
if( params!=null ) { |
|
155 |
server.remove(params); |
|
156 |
} |
|
157 |
} catch (Exception ex) { |
|
158 |
LOGGER.warn("Can't drop table '"+tableName+"'.",ex); |
|
159 |
} |
|
160 |
} |
|
161 |
|
|
162 |
private void createTableResources() { |
|
163 |
String tableName = TABLE_RESOURCES_NAME; |
|
164 |
try { |
|
165 |
DataManager dataManager = DALLocator.getDataManager(); |
|
166 |
DataServerExplorer server = dataManager.openServerExplorer( |
|
167 |
this.connection.getExplorerName(), |
|
168 |
this.connection |
|
169 |
); |
|
170 |
NewFeatureStoreParameters params = (NewFeatureStoreParameters) server.getAddParameters(tableName); |
|
171 |
EditableFeatureType ft = params.getDefaultFeatureType(); |
|
172 |
ft.add(FIELD_RESOURCES_NAME, DataTypes.STRING, 150) |
|
173 |
.setAllowNull(false) |
|
174 |
.setIsPrimaryKey(true); |
|
175 |
ft.add(FIELD_RESOURCES_RESOURCE, DataTypes.BYTEARRAY) |
|
176 |
.setAllowNull(true); |
|
177 |
server.add(tableName, params, false); |
|
178 |
} catch (Exception ex) { |
|
179 |
LOGGER.warn("Can't create table '"+tableName+"'.",ex); |
|
180 |
} |
|
181 |
} |
|
182 |
|
|
183 |
private void createTableRepository() { |
|
184 |
String tableName = TABLE_REPOSITORY_NAME; |
|
185 |
try { |
|
186 |
DataManager dataManager = DALLocator.getDataManager(); |
|
187 |
DataServerExplorer server = dataManager.openServerExplorer( |
|
188 |
this.connection.getExplorerName(), |
|
189 |
this.connection |
|
190 |
); |
|
191 |
NewFeatureStoreParameters params = (NewFeatureStoreParameters) server.getAddParameters(tableName); |
|
192 |
EditableFeatureType ft = params.getDefaultFeatureType(); |
|
193 |
ft.add(FIELD_REPOSITORY_NAME, DataTypes.STRING, 150) |
|
194 |
.setAllowNull(false) |
|
195 |
.setIsPrimaryKey(true); |
|
196 |
ft.add(FIELD_REPOSITORY_PARAMETERS, DataTypes.BYTEARRAY) |
|
197 |
.setAllowNull(true); |
|
198 |
server.add(tableName, params, false); |
|
199 |
} catch (Exception ex) { |
|
200 |
LOGGER.warn("Can't create table '"+tableName+"'.",ex); |
|
201 |
} |
|
202 |
} |
|
203 |
|
|
204 |
private void createTableConfiguration() { |
|
205 |
String tableName = TABLE_CONFIGURATION_NAME; |
|
206 |
try { |
|
207 |
DataManager dataManager = DALLocator.getDataManager(); |
|
208 |
DataServerExplorer server = dataManager.openServerExplorer( |
|
209 |
this.connection.getExplorerName(), |
|
210 |
this.connection |
|
211 |
); |
|
212 |
NewFeatureStoreParameters params = (NewFeatureStoreParameters) server.getAddParameters(tableName); |
|
213 |
EditableFeatureType ft = params.getDefaultFeatureType(); |
|
214 |
ft.add(FIELD_CONFIGURATION_NAME, DataTypes.STRING, 200) |
|
215 |
.setAllowNull(false) |
|
216 |
.setIsPrimaryKey(true); |
|
217 |
ft.add(FIELD_CONFIGURATION_VALUE, DataTypes.STRING, 200) |
|
218 |
.setAllowNull(true); |
|
219 |
server.add(tableName, params, false); |
|
220 |
} catch (Exception ex) { |
|
221 |
LOGGER.warn("Can't create table '"+tableName+"'.",ex); |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
225 |
private boolean existsConfiguration() { |
|
226 |
if( this.existsConfiguration==null ) { |
|
227 |
this.existsConfiguration = this.existsTable(TABLE_CONFIGURATION_NAME); |
|
228 |
} |
|
229 |
return this.existsConfiguration; |
|
230 |
} |
|
231 |
|
|
232 |
@Override |
|
233 |
public String get(String name) { |
|
234 |
try { |
|
235 |
if( !this.existsConfiguration() ) { |
|
236 |
return null; |
|
237 |
} |
|
238 |
FeatureStore store = this.getTable(TABLE_CONFIGURATION); |
|
239 |
if( store == null ) { |
|
240 |
return null; |
|
241 |
} |
|
242 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
|
243 |
String filter = builder.eq( |
|
244 |
builder.column(FIELD_CONFIGURATION_NAME), |
|
245 |
builder.constant(name) |
|
246 |
).toString(); |
|
247 |
Feature feature = store.findFirst(filter); |
|
248 |
if( feature == null ) { |
|
249 |
return null; |
|
250 |
} |
|
251 |
String value = feature.getString(FIELD_CONFIGURATION_VALUE); |
|
252 |
return value; |
|
253 |
|
|
254 |
} catch (Exception ex) { |
|
255 |
LOGGER.warn("Can't read configuration value '"+name+"'", ex); |
|
256 |
return null; |
|
257 |
} |
|
258 |
} |
|
259 |
|
|
260 |
@Override |
|
261 |
public void set(String name, String value) { |
|
262 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
263 |
} |
|
264 |
|
|
265 |
@Override |
|
266 |
public StoresRepository getStoresRepository() { |
|
267 |
if( this.storesRepository==null ) { |
|
268 |
String id = this.get(CONFIG_NAME_STORESREPOSITORYID); |
|
269 |
String label = this.get(CONFIG_NAME_STORESREPOSITORYLABEL); |
|
270 |
this.storesRepository = new DatabaseWorkspaceStoresRepository( |
|
271 |
id, |
|
272 |
label, |
|
273 |
this.connection |
|
274 |
); |
|
275 |
} |
|
276 |
return this.storesRepository; |
|
277 |
} |
|
278 |
|
|
279 |
@Override |
|
280 |
public boolean canAnonymousUserWriteInTheTables() { |
|
281 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|
282 |
} |
|
283 |
|
|
284 |
@Override |
|
285 |
public boolean storesRepositoryWriteEntry(String name, DataStoreParameters parameters) { |
|
286 |
try { |
|
287 |
byte[] data = parameters.toByteArray(); |
|
288 |
if( data == null ) { |
|
289 |
throw new RuntimeException("Can't convert parameters to byte array."); |
|
290 |
} |
|
291 |
FeatureStore store = this.getTable(TABLE_REPOSITORY); |
|
292 |
store.edit(); |
|
293 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
|
294 |
String filter = builder.eq( |
|
295 |
builder.column(FIELD_REPOSITORY_NAME), |
|
296 |
builder.constant(name) |
|
297 |
).toString(); |
|
298 |
Feature feature = store.findFirst(filter); |
|
299 |
EditableFeature efeature; |
|
300 |
if (feature == null) { |
|
301 |
efeature = store.createNewFeature(); |
|
302 |
efeature.set(FIELD_REPOSITORY_NAME, name); |
|
303 |
efeature.set(FIELD_REPOSITORY_PARAMETERS, data); |
|
304 |
store.insert(efeature); |
|
305 |
} else { |
|
306 |
efeature = feature.getEditable(); |
|
307 |
efeature.set(FIELD_REPOSITORY_PARAMETERS, data); |
|
308 |
store.update(efeature); |
|
309 |
} |
|
310 |
store.finishEditing(); |
|
311 |
return true; |
|
312 |
|
|
313 |
} catch (Exception ex) { |
|
314 |
LOGGER.warn("Can't save entry '"+name+"' in repository information", ex); |
|
315 |
return false; |
|
316 |
} |
|
317 |
} |
|
318 |
|
|
319 |
@Override |
|
320 |
public boolean isValidStoresRepository() { |
|
321 |
String id = this.get(CONFIG_NAME_STORESREPOSITORYID); |
|
322 |
if( StringUtils.isBlank(id) ) { |
|
323 |
return false; |
|
324 |
} |
|
325 |
if( !this.existsTable(TABLE_REPOSITORY_NAME) ) { |
|
326 |
return false; |
|
327 |
} |
|
328 |
return true; |
|
329 |
|
|
330 |
} |
|
331 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/DefaultDataManager.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.impl; |
2 | 2 |
|
3 |
import java.io.ByteArrayInputStream; |
|
3 | 4 |
import java.io.File; |
4 | 5 |
import java.io.InputStream; |
5 | 6 |
import java.net.URL; |
... | ... | |
13 | 14 |
import org.gvsig.expressionevaluator.Expression; |
14 | 15 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
15 | 16 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
17 |
import org.gvsig.fmap.dal.BaseStoresRepository; |
|
16 | 18 |
|
17 | 19 |
import org.gvsig.fmap.dal.DataFactory; |
18 | 20 |
import org.gvsig.fmap.dal.DataManager; |
... | ... | |
25 | 27 |
import org.gvsig.fmap.dal.DataStoreParameters; |
26 | 28 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
27 | 29 |
import org.gvsig.fmap.dal.DataTypes; |
30 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
|
28 | 31 |
|
29 | 32 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
30 | 33 |
import org.gvsig.fmap.dal.OpenErrorHandler; |
... | ... | |
80 | 83 |
import org.gvsig.tools.folders.FoldersManager; |
81 | 84 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
82 | 85 |
import org.gvsig.tools.identitymanagement.UnauthorizedException; |
86 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
83 | 87 |
import org.gvsig.tools.service.spi.Services; |
84 |
import org.gvsig.tools.util.GetItemByKey; |
|
85 |
import org.gvsig.tools.util.UnmodifiableBasicMap; |
|
86 | 88 |
import org.slf4j.Logger; |
87 | 89 |
import org.slf4j.LoggerFactory; |
88 | 90 |
|
91 |
@SuppressWarnings("UseSpecificCatch") |
|
89 | 92 |
public class DefaultDataManager |
90 | 93 |
implements DataManager, DataManagerProviderServices, Services { |
91 | 94 |
|
... | ... | |
278 | 281 |
} |
279 | 282 |
|
280 | 283 |
@Override |
284 |
public DataStoreParameters createStoreParameters(byte[] data) { |
|
285 |
try { |
|
286 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
|
287 |
ByteArrayInputStream stream = new ByteArrayInputStream(data); |
|
288 |
DataStoreParameters parameters = (DataStoreParameters) persistenceManager.getObject(stream); |
|
289 |
return parameters; |
|
290 |
} catch (Exception ex) { |
|
291 |
LOGGER.warn("Can't get parameters from byte[].",ex); |
|
292 |
return null; |
|
293 |
} |
|
294 |
} |
|
295 |
|
|
296 |
@Override |
|
281 | 297 |
public DataStoreParameters createStoreParameters(String providerName) throws InitializeException, ProviderNotRegisteredException { |
282 | 298 |
if( providerName == null ) { |
283 | 299 |
String msg = "Provider name can't be null."; |
... | ... | |
1000 | 1016 |
@Override |
1001 | 1017 |
public StoresRepository getStoresRepository() { |
1002 | 1018 |
if( this.storesRepository==null ) { |
1003 |
this.storesRepository = new DefaultStoresRepository();
|
|
1019 |
this.storesRepository = new BaseStoresRepository("DAL");
|
|
1004 | 1020 |
} |
1005 | 1021 |
return this.storesRepository; |
1006 | 1022 |
} |
1007 |
|
|
1023 |
|
|
1008 | 1024 |
@Override |
1009 |
public void addStoresRepository(String name, UnmodifiableBasicMap<String,DataStoreParameters> repository) { |
|
1010 |
((DefaultStoresRepository)this.getStoresRepository()).add(name, repository); |
|
1025 |
public DatabaseWorkspaceManager createDatabaseWorkspaceManager(DataServerExplorerParameters connection) { |
|
1026 |
DatabaseWorkspaceManager workspace = new DefaultDatabaseWorkspaceManager(connection); |
|
1027 |
return workspace; |
|
1011 | 1028 |
} |
1012 |
|
Also available in: Unified diff