Revision 42517
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/resource/ResourceManager.java | ||
---|---|---|
37 | 37 |
* collecting resources to free them as they become unused |
38 | 38 |
* |
39 | 39 |
*/ |
40 |
public interface ResourceManager extends WeakReferencingObservable { |
|
40 |
public interface ResourceManager extends WeakReferencingObservable, Iterable<Resource> {
|
|
41 | 41 |
public Resource getResource(String name); |
42 | 42 |
|
43 | 43 |
/** |
... | ... | |
46 | 46 |
* @return |
47 | 47 |
* iterator over the resources. |
48 | 48 |
*/ |
49 |
public Iterator iterator(); |
|
49 |
public Iterator<Resource> iterator();
|
|
50 | 50 |
|
51 | 51 |
/** |
52 | 52 |
* Iterates over the resources and frees them if they are ready to be freed |
53 | 53 |
* or try to close them if they are idle. |
54 |
*
|
|
54 |
* |
|
55 | 55 |
* @throws DataException |
56 | 56 |
* @see {@link ResourceManager#getTimeToBeIdle()} |
57 | 57 |
* {@link ResourceManager#setTimeToBeIdle(int)} |
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/resource/spi/MultiResource.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal.resource.spi; |
25 | 25 |
|
26 |
import java.lang.ref.WeakReference; |
|
26 | 27 |
import java.util.ArrayList; |
28 |
import java.util.HashMap; |
|
29 |
import java.util.Iterator; |
|
27 | 30 |
import java.util.List; |
31 |
import java.util.Map; |
|
28 | 32 |
|
29 | 33 |
import org.gvsig.fmap.dal.DALLocator; |
30 | 34 |
import org.gvsig.fmap.dal.exception.InitializeException; |
35 |
import org.gvsig.fmap.dal.resource.Resource; |
|
36 |
import org.gvsig.fmap.dal.resource.ResourceAction; |
|
31 | 37 |
import org.gvsig.fmap.dal.resource.ResourceParameters; |
32 | 38 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
33 | 39 |
import org.gvsig.fmap.dal.resource.exception.PrepareResourceException; |
34 | 40 |
import org.gvsig.fmap.dal.resource.exception.ResourceException; |
41 |
import org.gvsig.fmap.dal.resource.exception.ResourceExecuteException; |
|
35 | 42 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyChangesException; |
36 | 43 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyCloseException; |
37 | 44 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyDisposeException; |
... | ... | |
42 | 49 |
/** |
43 | 50 |
* Resource implementation which is able to show an unique interface to a group |
44 | 51 |
* of Resources. |
45 |
*
|
|
52 |
* |
|
46 | 53 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team |
47 | 54 |
*/ |
48 | 55 |
public class MultiResource extends AbstractResource { |
... | ... | |
54 | 61 |
private static final Logger LOG = |
55 | 62 |
LoggerFactory.getLogger(MultiResource.class); |
56 | 63 |
|
57 |
private List resources = new ArrayList();
|
|
64 |
private Map resources = new HashMap<>();
|
|
58 | 65 |
|
59 | 66 |
// Initially, the first one |
60 | 67 |
private int defaultResourcePos = 0; |
61 | 68 |
|
69 |
//Blocks adding methods |
|
70 |
private boolean isFrozen=false; |
|
71 |
|
|
62 | 72 |
/** |
63 | 73 |
* Creates a new {@link MultiResource} from the given parameters. |
64 |
*
|
|
74 |
* |
|
65 | 75 |
* @param parameters |
66 | 76 |
* to create the resource from |
67 | 77 |
* @throws InitializeException |
... | ... | |
73 | 83 |
} |
74 | 84 |
|
75 | 85 |
private List getResources() { |
76 |
return resources;
|
|
86 |
return new ArrayList<>(resources.values());
|
|
77 | 87 |
} |
78 | 88 |
|
79 | 89 |
/** |
80 | 90 |
* Adds a new {@link ResourceProvider} to the list of Resources managed by |
81 | 91 |
* this group. |
82 |
*
|
|
92 |
* |
|
83 | 93 |
* @param parameters |
84 | 94 |
* to create the resource from |
85 | 95 |
* @param defaultResource |
... | ... | |
90 | 100 |
*/ |
91 | 101 |
public void addResource(ResourceParameters parameters, |
92 | 102 |
boolean defaultResource) throws InitializeException { |
93 |
ResourceProvider resourceProvider = |
|
94 |
((ResourceManagerProviderServices) DALLocator.getResourceManager()).createResource(parameters); |
|
95 |
resources.add(resourceProvider); |
|
96 |
if (defaultResource) { |
|
97 |
defaultResourcePos = resources.size() - 1; |
|
98 |
} |
|
103 |
String name=(String)parameters.getDynValue("name"); |
|
104 |
commonAddResource(name, parameters,defaultResource); |
|
99 | 105 |
} |
100 | 106 |
|
101 | 107 |
/** |
102 | 108 |
* Adds a new {@link ResourceProvider} to the list of Resources managed by |
103 | 109 |
* this group. |
104 |
*
|
|
110 |
* |
|
105 | 111 |
* @param name |
106 | 112 |
* of the resource to add |
107 | 113 |
* @param params |
... | ... | |
114 | 120 |
*/ |
115 | 121 |
public void addResource(String name, Object[] params, |
116 | 122 |
boolean defaultResource) throws InitializeException { |
117 |
ResourceProvider resourceProvider = |
|
118 |
((ResourceManagerProviderServices) DALLocator.getResourceManager()).createResource( |
|
119 |
name, params); |
|
120 |
resources.add(resourceProvider); |
|
121 |
if (defaultResource) { |
|
122 |
defaultResourcePos = resources.size() - 1; |
|
123 |
} |
|
123 |
commonAddResource(name, params,defaultResource); |
|
124 | 124 |
} |
125 | 125 |
|
126 |
private void commonAddResource(String name, Object params, |
|
127 |
boolean defaultResource) throws InitializeException { |
|
128 |
String multiresourceName=null; |
|
129 |
try { |
|
130 |
multiresourceName=this.getName(); |
|
131 |
} catch (AccessResourceException e1) { |
|
132 |
LOG.warn("Imposible to get MultiResource name"); |
|
133 |
} |
|
134 |
Resource res = (Resource)(this.resources.get(name)); |
|
135 |
if( res!=null ) { |
|
136 |
return; |
|
137 |
} |
|
138 |
if (isFrozen){ |
|
139 |
LOG.warn("Added resource "+name+" to a frozen multiresource "+multiresourceName); |
|
140 |
} |
|
141 |
ResourceProvider resourceProvider =null; |
|
142 |
if (params instanceof ResourceParameters){ |
|
143 |
resourceProvider = ((ResourceManagerProviderServices) DALLocator. |
|
144 |
getResourceManager()).createAddResource((ResourceParameters)params); |
|
145 |
}else if (params instanceof Object[]){ |
|
146 |
resourceProvider = ((ResourceManagerProviderServices) DALLocator. |
|
147 |
getResourceManager()).createAddResource(name,(Object[])params); |
|
148 |
}else{ |
|
149 |
LOG.warn("Resource could not be created "+name); |
|
150 |
} |
|
151 |
try { |
|
152 |
resources.put(resourceProvider.getName(),resourceProvider); |
|
153 |
} catch (AccessResourceException e) { |
|
154 |
LOG.warn("Resource not added "+name+ " to "+multiresourceName); |
|
155 |
} |
|
156 |
if (defaultResource) { |
|
157 |
defaultResourcePos = resources.size() - 1; |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
126 | 164 |
public boolean isThis(ResourceParameters parameters) |
127 | 165 |
throws ResourceException { |
128 | 166 |
if (parameters instanceof MultiResourceParameters) { |
... | ... | |
141 | 179 |
for (int i = 0; i < resources.size(); i++) { |
142 | 180 |
((ResourceProvider) getResources().get(i)).notifyChanges(); |
143 | 181 |
} |
182 |
super.notifyChanges(); |
|
144 | 183 |
} |
145 | 184 |
|
146 | 185 |
public void notifyClose() throws ResourceNotifyCloseException { |
... | ... | |
148 | 187 |
for (int i = 0; i < resources.size(); i++) { |
149 | 188 |
((ResourceProvider) getResources().get(i)).notifyClose(); |
150 | 189 |
} |
190 |
super.notifyClose(); |
|
151 | 191 |
} |
152 | 192 |
|
153 | 193 |
public void notifyDispose() throws ResourceNotifyDisposeException { |
... | ... | |
155 | 195 |
for (int i = 0; i < resources.size(); i++) { |
156 | 196 |
((ResourceProvider) getResources().get(i)).notifyDispose(); |
157 | 197 |
} |
198 |
super.notifyDispose(); |
|
158 | 199 |
} |
159 | 200 |
|
160 | 201 |
public void notifyOpen() throws ResourceNotifyOpenException { |
... | ... | |
162 | 203 |
for (int i = 0; i < resources.size(); i++) { |
163 | 204 |
((ResourceProvider) getResources().get(i)).notifyOpen(); |
164 | 205 |
} |
206 |
super.notifyOpen(); |
|
165 | 207 |
} |
166 | 208 |
|
167 | 209 |
public void prepare() throws PrepareResourceException { |
... | ... | |
169 | 211 |
for (int i = 0; i < resources.size(); i++) { |
170 | 212 |
((ResourceProvider) getResources().get(i)).prepare(); |
171 | 213 |
} |
214 |
super.prepare(); |
|
172 | 215 |
} |
173 | 216 |
|
174 | 217 |
public void closeRequest() throws ResourceException { |
... | ... | |
176 | 219 |
for (int i = 0; i < resources.size(); i++) { |
177 | 220 |
((ResourceProvider) getResources().get(i)).closeRequest(); |
178 | 221 |
} |
222 |
super.closeRequest(); |
|
179 | 223 |
} |
180 | 224 |
|
181 | 225 |
public Object get() throws AccessResourceException { |
... | ... | |
201 | 245 |
} |
202 | 246 |
|
203 | 247 |
public String getName() throws AccessResourceException { |
248 |
String name ="MultiResource "+ getMultiResourceParameters().getName(); |
|
249 |
return name; |
|
250 |
/* |
|
204 | 251 |
StringBuffer buffer = |
205 | 252 |
new StringBuffer().append("MultiResource ").append( |
206 | 253 |
getMultiResourceParameters().getName()).append(":: "); |
... | ... | |
215 | 262 |
} |
216 | 263 |
} |
217 | 264 |
return buffer.toString(); |
265 |
*/ |
|
218 | 266 |
} |
219 | 267 |
|
220 | 268 |
public String toString() { |
... | ... | |
240 | 288 |
defaultResource.setData(data); |
241 | 289 |
} |
242 | 290 |
} |
291 |
|
|
292 |
/** |
|
293 |
* Blocks the adding methods. It is called when all their resources components are added. |
|
294 |
*/ |
|
295 |
public void frozen(){ |
|
296 |
this.isFrozen=true; |
|
297 |
} |
|
298 |
|
|
299 |
/** |
|
300 |
* Locks the multiresource components to avoid another concurrent modification |
|
301 |
*/ |
|
302 |
@Override |
|
303 |
public Object execute(ResourceAction action) |
|
304 |
throws ResourceExecuteException { |
|
305 |
Object value = null; |
|
306 |
synchronized (lock) { |
|
307 |
Iterator it=resources.values().iterator(); |
|
308 |
while (it.hasNext()){ |
|
309 |
AbstractResource resource=(AbstractResource)it.next(); |
|
310 |
resource.multiResourcelock=this.lock; |
|
311 |
} |
|
312 |
executeBegins(); |
|
313 |
try { |
|
314 |
value = performExecution(action); |
|
315 |
} catch (Exception e) { |
|
316 |
throw new ResourceExecuteException(this, e); |
|
317 |
} finally { |
|
318 |
executeEnds(); |
|
319 |
} |
|
320 |
} |
|
321 |
return value; |
|
322 |
} |
|
323 |
|
|
324 |
public void addMultiResourceConsumer(ResourceConsumer consumer) { |
|
325 |
super.addConsumer(consumer); |
|
326 |
Iterator it=resources.values().iterator(); |
|
327 |
while (it.hasNext()){ |
|
328 |
AbstractResource resource=(AbstractResource)it.next(); |
|
329 |
resource.addConsumer(consumer); |
|
330 |
} |
|
331 |
} |
|
332 |
|
|
243 | 333 |
} |
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/resource/spi/AbstractResource.java | ||
---|---|---|
54 | 54 |
* <p> |
55 | 55 |
* Base implementation for Resource |
56 | 56 |
* </p> |
57 |
*
|
|
57 |
* |
|
58 | 58 |
* <p> |
59 | 59 |
* This implementation not define the {@link Resource#begin()} and |
60 | 60 |
* {@link Resource#end()} |
61 | 61 |
* </p> |
62 |
*
|
|
62 |
* |
|
63 | 63 |
* @author jmvivo |
64 |
*
|
|
64 |
* |
|
65 | 65 |
*/ |
66 | 66 |
public abstract class AbstractResource implements ResourceProvider, |
67 | 67 |
WeakReferencingObservable { |
68 | 68 |
|
69 | 69 |
private static Logger logger = LoggerFactory.getLogger(AbstractResource.class); |
70 |
|
|
70 |
|
|
71 | 71 |
private DelegateWeakReferencingObservable delegateObservable; |
72 | 72 |
|
73 | 73 |
private List consumers; |
... | ... | |
90 | 90 |
|
91 | 91 |
protected final Object lock; |
92 | 92 |
|
93 |
protected Object multiResourcelock; |
|
94 |
|
|
93 | 95 |
protected AbstractResource(ResourceParameters parameters) |
94 | 96 |
throws InitializeException { |
95 | 97 |
consumers = new ArrayList(); |
... | ... | |
101 | 103 |
preparedParameters = null; |
102 | 104 |
delegateObservable = new DelegateWeakReferencingObservable(this); |
103 | 105 |
lock = new Object(); |
106 |
multiResourcelock = new Object(); |
|
104 | 107 |
try { |
105 | 108 |
this.parameters = (ResourceParameters) parameters.getCopy(); |
106 | 109 |
} catch (CopyParametersException e) { |
... | ... | |
230 | 233 |
it.remove(); |
231 | 234 |
} |
232 | 235 |
} |
236 |
|
|
233 | 237 |
} |
234 | 238 |
|
235 | 239 |
public int getConsumersCount() { |
... | ... | |
237 | 241 |
return consumers.size(); |
238 | 242 |
} |
239 | 243 |
|
244 |
public ResourceConsumer getConsumerAt(int i){ |
|
245 |
this.updateConsumersList(); |
|
246 |
if (consumers==null){ |
|
247 |
return null; |
|
248 |
}else{ |
|
249 |
return (ResourceConsumer)consumers.get(i); |
|
250 |
} |
|
251 |
} |
|
252 |
|
|
240 | 253 |
private synchronized void updateConsumersList() { |
241 | 254 |
Iterator it = consumers.iterator(); |
242 | 255 |
WeakReference ref; |
... | ... | |
252 | 265 |
if (inUse()) { |
253 | 266 |
return; |
254 | 267 |
} |
255 |
if (consumers != null) { |
|
256 |
for (int i = 0; i < consumers.size(); i++) { |
|
257 | 268 |
|
258 |
} |
|
259 |
} |
|
260 | 269 |
if (consumers != null) { |
261 | 270 |
Iterator it = consumers.iterator(); |
262 | 271 |
while (it.hasNext()) { |
... | ... | |
311 | 320 |
throws ResourceExecuteException { |
312 | 321 |
Object value = null; |
313 | 322 |
synchronized (lock) { |
314 |
executeBegins(); |
|
315 |
try { |
|
316 |
value = performExecution(action); |
|
317 |
} catch (Exception e) { |
|
318 |
throw new ResourceExecuteException(this, e); |
|
319 |
} finally { |
|
320 |
executeEnds(); |
|
321 |
} |
|
323 |
synchronized (multiResourcelock) { |
|
324 |
executeBegins(); |
|
325 |
try { |
|
326 |
value = performExecution(action); |
|
327 |
} catch (Exception e) { |
|
328 |
throw new ResourceExecuteException(this, e); |
|
329 |
} finally { |
|
330 |
executeEnds(); |
|
331 |
} |
|
332 |
} |
|
322 | 333 |
} |
323 | 334 |
return value; |
324 | 335 |
} |
... | ... | |
338 | 349 |
|
339 | 350 |
/** |
340 | 351 |
* Returns the name of the {@link Resource}. |
341 |
*
|
|
352 |
* |
|
342 | 353 |
* @throws AccessResourceException |
343 | 354 |
* if there is an error while accessing the resource |
344 | 355 |
*/ |
... | ... | |
346 | 357 |
|
347 | 358 |
/** |
348 | 359 |
* Returns the real resource represented by this object. |
349 |
*
|
|
360 |
* |
|
350 | 361 |
* @throws AccessResourceException |
351 | 362 |
* if there is an error while accessing the resource |
352 | 363 |
*/ |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.shp/src/main/java/org/gvsig/fmap/dal/store/shp/SHPStoreProvider.java | ||
---|---|---|
89 | 89 |
|
90 | 90 |
private SHPFeatureWriter writer = null; |
91 | 91 |
|
92 |
private boolean loTengoEnUso; |
|
93 |
|
|
92 | 94 |
public SHPStoreProvider(SHPStoreParameters params, |
93 | 95 |
DataStoreProviderServices storeServices) |
94 | 96 |
throws InitializeException { |
... | ... | |
137 | 139 |
resource.addResource(FileResource.NAME, |
138 | 140 |
new Object[]{shpParams.getDBFFileName()}, true); |
139 | 141 |
|
140 |
resource.addConsumer(this); |
|
142 |
resource.frozen(); |
|
143 |
resource.addMultiResourceConsumer(this); |
|
141 | 144 |
} |
142 | 145 |
|
143 | 146 |
; |
... | ... | |
315 | 318 |
*/ |
316 | 319 |
protected FeatureProvider getFeatureProviderByIndex(long index, |
317 | 320 |
FeatureType featureType) throws DataException { |
318 |
// this.open();
|
|
319 |
// this.resourcesBegin();
|
|
321 |
this.open(); |
|
322 |
// this.resourcesBegin();
|
|
320 | 323 |
try { |
321 | 324 |
|
322 | 325 |
FeatureProvider featureProvider = super.getFeatureProviderByIndex(index, |
... | ... | |
466 | 469 |
// throw new PerformEditingException(this.getName(), e1); |
467 | 470 |
// } |
468 | 471 |
try { |
472 |
// TODO repasar el concepto de enUso de un recurso. |
|
473 |
loTengoEnUso = true; |
|
474 |
resourceCloseRequest(); |
|
469 | 475 |
|
470 | 476 |
getResource().execute(new ResourceAction() { |
471 | 477 |
public Object run() throws Exception { |
... | ... | |
496 | 502 |
} |
497 | 503 |
|
498 | 504 |
writer.end(); |
499 |
|
|
505 |
loTengoEnUso = false; |
|
500 | 506 |
close(); |
501 |
resourceCloseRequest(); |
|
502 | 507 |
|
508 |
|
|
503 | 509 |
//FIXME: Descomentarizar este c?digo cuando se consiga exportar la proyecci?n al formato de WKT_ESRI. |
504 | 510 |
// File tmpPrjFile = SHP.getPrjFile(tmpParams.getSHPFile()); |
505 | 511 |
// try { |
... | ... | |
548 | 554 |
initFeatureType(); |
549 | 555 |
return null; |
550 | 556 |
} finally { |
557 |
loTengoEnUso = false; |
|
551 | 558 |
dispose(set); |
552 | 559 |
dispose(iter); |
553 | 560 |
} |
... | ... | |
560 | 567 |
|
561 | 568 |
} |
562 | 569 |
|
570 |
|
|
563 | 571 |
protected void resourceCloseRequest() throws ResourceException { |
564 | 572 |
// super.resourceCloseRequest(); |
565 | 573 |
// this.shpResource.closeRequest(); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.dbf/src/main/java/org/gvsig/fmap/dal/store/dbf/DBFLibrary.java | ||
---|---|---|
38 | 38 |
import org.gvsig.fmap.dal.DALLibrary; |
39 | 39 |
import org.gvsig.fmap.dal.DALLocator; |
40 | 40 |
import org.gvsig.fmap.dal.FileHelper; |
41 |
import org.gvsig.fmap.dal.resource.file.FileResource; |
|
42 |
import org.gvsig.fmap.dal.resource.file.FileResourceParameters; |
|
43 |
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices; |
|
41 | 44 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
45 |
import org.gvsig.fmap.dal.store.dbf.utils.DbaseFile; |
|
42 | 46 |
import org.gvsig.metadata.exceptions.MetadataException; |
43 | 47 |
import org.gvsig.tools.ToolsLocator; |
44 | 48 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
... | ... | |
63 | 67 |
List<Throwable> exs = new ArrayList<Throwable>(); |
64 | 68 |
|
65 | 69 |
FileHelper.registerParametersDefinition( |
66 |
DBFStoreParameters.PARAMETERS_DEFINITION_NAME,
|
|
70 |
DBFStoreParameters.PARAMETERS_DEFINITION_NAME, |
|
67 | 71 |
DBFStoreParameters.class, |
68 | 72 |
"DBFParameters.xml" |
69 | 73 |
); |
70 | 74 |
updateEncodingDefinition(); |
71 | 75 |
FileHelper.registerParametersDefinition( |
72 |
DBFNewStoreParameters.PARAMETERS_DEFINITION_NAME,
|
|
76 |
DBFNewStoreParameters.PARAMETERS_DEFINITION_NAME, |
|
73 | 77 |
DBFNewStoreParameters.class, |
74 | 78 |
"DBFParameters.xml" |
75 | 79 |
); |
76 | 80 |
try { |
77 | 81 |
FileHelper.registerMetadataDefinition( |
78 |
DBFStoreProvider.METADATA_DEFINITION_NAME,
|
|
82 |
DBFStoreProvider.METADATA_DEFINITION_NAME, |
|
79 | 83 |
DBFStoreProvider.class, |
80 | 84 |
"DBFMetadata.xml" |
81 | 85 |
); |
... | ... | |
108 | 112 |
throw new LibraryException(this.getClass(), exs); |
109 | 113 |
} |
110 | 114 |
} |
111 |
|
|
115 |
|
|
112 | 116 |
private static void updateEncodingDefinition() { |
113 | 117 |
DynStruct parametersDefinition = ToolsLocator.getPersistenceManager().getDefinition(DBFStoreParameters.PARAMETERS_DEFINITION_NAME); |
114 |
|
|
118 |
|
|
115 | 119 |
DynObjectValueItem[] values = parametersDefinition.getDynField("encoding").getAvailableValues(); |
116 |
|
|
120 |
|
|
117 | 121 |
Set<DynObjectValueItem> charsetSet = new LinkedHashSet<DynObjectValueItem>(160); |
118 | 122 |
|
119 | 123 |
charsetSet.addAll( Arrays.asList(values) ); |
... | ... | |
130 | 134 |
(DynObjectValueItem[]) charsetSet.toArray(new DynObjectValueItem[charsets.size()]) |
131 | 135 |
); |
132 | 136 |
|
133 |
|
|
137 |
|
|
134 | 138 |
} |
135 | 139 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.dbf/src/main/java/org/gvsig/fmap/dal/store/dbf/DBFStoreProvider.java | ||
---|---|---|
36 | 36 |
|
37 | 37 |
import org.apache.commons.io.FileUtils; |
38 | 38 |
import org.apache.commons.lang3.StringUtils; |
39 |
import org.slf4j.Logger; |
|
40 |
import org.slf4j.LoggerFactory; |
|
41 |
|
|
42 | 39 |
import org.gvsig.fmap.dal.DALLocator; |
43 | 40 |
import org.gvsig.fmap.dal.DataManager; |
44 | 41 |
import org.gvsig.fmap.dal.DataServerExplorer; |
... | ... | |
69 | 66 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
70 | 67 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
71 | 68 |
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
72 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider.FeatureTypeChanged; |
|
73 | 69 |
import org.gvsig.fmap.dal.resource.ResourceAction; |
74 | 70 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
75 | 71 |
import org.gvsig.fmap.dal.resource.exception.ResourceException; |
... | ... | |
91 | 87 |
import org.gvsig.tools.dynobject.DynObject; |
92 | 88 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
93 | 89 |
import org.gvsig.tools.exception.BaseException; |
90 |
import org.slf4j.Logger; |
|
91 |
import org.slf4j.LoggerFactory; |
|
94 | 92 |
|
95 | 93 |
public class DBFStoreProvider extends AbstractFeatureStoreProvider implements |
96 | 94 |
ResourceConsumer { |
... | ... | |
114 | 112 |
|
115 | 113 |
private static long lastLogTime = 0; |
116 | 114 |
|
115 |
private boolean loTengoEnUso; |
|
116 |
|
|
117 | 117 |
protected static void registerMetadataDefinition() throws MetadataException { |
118 | 118 |
MetadataManager manager = MetadataLocator.getMetadataManager(); |
119 | 119 |
if (manager.getDefinition(METADATA_DEFINITION_NAME) == null) { |
... | ... | |
169 | 169 |
} catch (OpenException e) { |
170 | 170 |
throw new RuntimeException(e); |
171 | 171 |
} |
172 |
|
|
172 | 173 |
if (METADATA_ENCODING.equalsIgnoreCase(name)) { |
173 | 174 |
return this.dbfFile.getOriginalCharset(); |
174 | 175 |
} else if (METADATA_CODEPAGE.equalsIgnoreCase(name)) { |
... | ... | |
229 | 230 |
checkNewFieldsNameSize(originalFeatureTypesUpdated); |
230 | 231 |
|
231 | 232 |
try { |
233 |
// TODO repasar el concepto de enUso de un recurso. |
|
234 |
loTengoEnUso = true; |
|
232 | 235 |
final FeatureStore store |
233 | 236 |
= this.getStoreServices().getFeatureStore(); |
237 |
resourceCloseRequest(); |
|
234 | 238 |
getResource().execute(new ResourceAction() { |
235 | 239 |
|
236 | 240 |
public Object run() throws Exception { |
... | ... | |
257 | 261 |
} |
258 | 262 |
|
259 | 263 |
writer.end(); |
260 |
|
|
264 |
loTengoEnUso = false; |
|
261 | 265 |
try { |
262 | 266 |
close(); |
263 | 267 |
} catch (CloseException e1) { |
... | ... | |
284 | 288 |
resourcesNotifyChanges(); |
285 | 289 |
initFeatureType(); |
286 | 290 |
} finally { |
291 |
loTengoEnUso = false; |
|
287 | 292 |
if (set != null) { |
288 | 293 |
set.dispose(); |
289 | 294 |
} |
... | ... | |
294 | 299 |
return null; |
295 | 300 |
} |
296 | 301 |
}); |
297 |
} catch (ResourceExecuteException e) { |
|
302 |
} catch (ResourceExecuteException | ResourceException e) {
|
|
298 | 303 |
throw new PerformEditingException(this.getProviderName(), e); |
299 | 304 |
} |
300 | 305 |
|
... | ... | |
441 | 446 |
} else { |
442 | 447 |
throw new InitializeException(getProviderName(), |
443 | 448 |
new UnknownDataTypeException( |
444 |
dbfFile.getFieldName(i), ""
|
|
449 |
dbfFile.getFieldName(i), "" |
|
445 | 450 |
+ fieldType, getProviderName())); |
446 | 451 |
} |
447 | 452 |
} |
... | ... | |
466 | 471 |
|
467 | 472 |
if (dbfIndex < 0) { |
468 | 473 |
// Someone asked to load a field |
469 |
// which does not exist in the DBF file. This can happen
|
|
474 |
// which does not exist in the DBF file. This can happen |
|
470 | 475 |
// in editing process when a field has been added |
471 | 476 |
// in the current editing session, so we simply do nothing. |
472 | 477 |
// The expansion manager is expected to manage those new fields |
... | ... | |
574 | 579 |
); |
575 | 580 |
setValue("dateFormat",dateFormat); |
576 | 581 |
setValue("value", value); |
577 |
setValue("store",store);
|
|
582 |
setValue("store",store); |
|
578 | 583 |
} |
579 | 584 |
} |
580 |
|
|
585 |
|
|
581 | 586 |
/** |
582 | 587 |
* * |
583 | 588 |
* NOT supported in Alter Mode |
... | ... | |
639 | 644 |
} |
640 | 645 |
|
641 | 646 |
public void close() throws CloseException { |
647 |
if( loTengoEnUso ) { |
|
648 |
return; |
|
649 |
} |
|
642 | 650 |
if (dbfFile == null || !this.dbfFile.isOpen()) { |
643 | 651 |
return; |
644 | 652 |
} |
645 | 653 |
super.close(); |
654 |
|
|
646 | 655 |
//Cerrar recurso |
647 | 656 |
try { |
648 | 657 |
getResource().execute(new ResourceAction() { |
... | ... | |
652 | 661 |
return null; |
653 | 662 |
} |
654 | 663 |
}); |
655 |
} catch (ResourceExecuteException e) { |
|
664 |
} catch (ResourceExecuteException e) {
|
|
656 | 665 |
throw new CloseException(this.getProviderName(), e); |
657 | 666 |
} |
658 | 667 |
} |
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/resource/impl/DefaultResourceManager.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal.resource.impl; |
25 | 25 |
|
26 |
import java.io.File; |
|
26 | 27 |
import java.lang.reflect.InvocationTargetException; |
27 | 28 |
import java.util.HashMap; |
28 | 29 |
import java.util.Iterator; |
... | ... | |
32 | 33 |
import java.util.Timer; |
33 | 34 |
import java.util.TimerTask; |
34 | 35 |
|
35 |
import org.slf4j.Logger; |
|
36 |
import org.slf4j.LoggerFactory; |
|
37 |
|
|
38 | 36 |
import org.gvsig.fmap.dal.DALLocator; |
39 | 37 |
import org.gvsig.fmap.dal.DataParameters; |
40 | 38 |
import org.gvsig.fmap.dal.exception.CopyParametersException; |
... | ... | |
48 | 46 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotClosedOnDisposeManagerException; |
49 | 47 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotRegisteredException; |
50 | 48 |
import org.gvsig.fmap.dal.resource.spi.AbstractResource; |
49 |
import org.gvsig.fmap.dal.resource.spi.MultiResource; |
|
51 | 50 |
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices; |
52 | 51 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
53 | 52 |
import org.gvsig.tools.ToolsLocator; |
53 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
|
54 | 54 |
import org.gvsig.tools.observer.Observer; |
55 | 55 |
import org.gvsig.tools.observer.impl.DelegateWeakReferencingObservable; |
56 |
import org.slf4j.Logger; |
|
57 |
import org.slf4j.LoggerFactory; |
|
56 | 58 |
|
57 | 59 |
|
58 | 60 |
public class DefaultResourceManager implements ResourceManagerProviderServices { |
... | ... | |
64 | 66 |
private static final String DATA_MANAGER_RESOURCE_DESCRIPTION = "DAL Resources types"; |
65 | 67 |
private static final String DATA_MANAGER_RESOURCE_PARAMS_DESCRIPTION = "DAL Resources types Parameters"; |
66 | 68 |
|
67 |
private Map resources = new HashMap(); |
|
69 |
private Map<String,Resource> resources = new HashMap();
|
|
68 | 70 |
|
69 | 71 |
private DelegateWeakReferencingObservable delegateObservable = new DelegateWeakReferencingObservable(this); |
70 | 72 |
|
... | ... | |
114 | 116 |
return (Resource)this.resources.get(key); |
115 | 117 |
} |
116 | 118 |
|
117 |
public synchronized Iterator iterator() { |
|
119 |
public synchronized Iterator<Resource> iterator() {
|
|
118 | 120 |
return this.resources.values().iterator(); |
119 | 121 |
} |
120 | 122 |
|
... | ... | |
299 | 301 |
throws InitializeException { |
300 | 302 |
|
301 | 303 |
try { |
304 |
String name; |
|
305 |
try { |
|
306 |
name= (String)params.getDynValue("name"); |
|
307 |
}catch (DynFieldNotFoundException nfe){ |
|
308 |
try{ |
|
309 |
File file= (File)params.getDynValue("file"); |
|
310 |
name= file.getAbsolutePath(); |
|
311 |
}catch(DynFieldNotFoundException nfe1){ |
|
312 |
throw new InitializeException(params.getTypeName(), nfe1); |
|
313 |
} |
|
314 |
} |
|
315 |
Resource res = (Resource)(this.resources.get(name)); |
|
316 |
if( res!=null ) { |
|
317 |
return (AbstractResource)res; |
|
318 |
} |
|
302 | 319 |
return addResource((AbstractResource) createResource(params)); |
303 | 320 |
} catch (AccessResourceException e) { |
304 | 321 |
throw new InitializeException(params.getTypeName(), e); |
... | ... | |
383 | 400 |
} |
384 | 401 |
mlsecondsToBeIdle = seconds * 1000; |
385 | 402 |
} |
386 |
|
|
387 | 403 |
} |
Also available in: Unified diff