Revision 2145
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/persistence/impl/AbstractPersistenceManager.java | ||
---|---|---|
32 | 32 |
import java.util.List; |
33 | 33 |
import java.util.Map; |
34 | 34 |
import java.util.Set; |
35 |
import org.apache.commons.lang3.mutable.MutableInt; |
|
35 | 36 |
|
36 | 37 |
import org.gvsig.tools.ToolsLocator; |
37 | 38 |
import org.gvsig.tools.dynobject.DynClass; |
... | ... | |
77 | 78 |
private DefaultFactories factories; |
78 | 79 |
private Domains domainsURL; |
79 | 80 |
private int autoValidationMode = PersistenceManager.DISABLED; |
80 |
|
|
81 |
private MutableInt globalReferenceCounter; |
|
81 | 82 |
|
82 | 83 |
|
83 | 84 |
protected AbstractPersistenceManager() { |
84 | 85 |
domainsURL = new Domains(); |
85 | 86 |
factories = new DefaultFactories(); |
87 |
globalReferenceCounter = new MutableInt(0); |
|
86 | 88 |
} |
87 | 89 |
|
88 | 90 |
public void addAlias(String name, Class aClass) |
... | ... | |
95 | 97 |
return this.factories; |
96 | 98 |
} |
97 | 99 |
|
100 |
@Override |
|
98 | 101 |
public PersistentContextServices getNewContext() { |
99 |
return new DefaultPersistentContext(this); |
|
102 |
return new DefaultPersistentContext(this, this.globalReferenceCounter); |
|
103 |
} |
|
104 |
|
|
105 |
@Override |
|
106 |
public PersistentContextServices getNewContext(MutableInt referenceCounter) { |
|
107 |
return new DefaultPersistentContext(this, referenceCounter); |
|
100 | 108 |
} |
101 | 109 |
|
102 | 110 |
public Object create(PersistentState state) throws PersistenceException { |
... | ... | |
288 | 296 |
} |
289 | 297 |
} |
290 | 298 |
|
299 |
@Override |
|
291 | 300 |
public PersistentState getState(Object obj) |
292 | 301 |
throws PersistenceException, PersistenceValidateExceptions, PersistenceTypeNotSupportedException { |
293 |
return this.getState(obj, false); |
|
302 |
return this.getState(obj, false, this.globalReferenceCounter);
|
|
294 | 303 |
} |
295 | 304 |
|
305 |
@Override |
|
296 | 306 |
public PersistentState getState(Object obj, boolean collectAllErrors) |
297 | 307 |
throws PersistenceException { |
308 |
return this.getState(obj, collectAllErrors, globalReferenceCounter); |
|
309 |
} |
|
310 |
|
|
311 |
@Override |
|
312 |
public PersistentState getState(Object obj, boolean collectAllErrors, MutableInt referenceCounter) |
|
313 |
throws PersistenceException { |
|
298 | 314 |
PersistentStateServices state = null; |
299 | 315 |
if( collectAllErrors ) { |
300 |
PersistentContextServices context = this.getNewContext(); |
|
316 |
PersistentContextServices context = this.getNewContext(referenceCounter);
|
|
301 | 317 |
context.setCollectErrors(true); |
302 | 318 |
try { |
303 | 319 |
state = createState(obj, context); |
... | ... | |
309 | 325 |
context.addError(ex); |
310 | 326 |
} |
311 | 327 |
} else { |
312 |
PersistentContextServices context = this.getNewContext(); |
|
328 |
PersistentContextServices context = this.getNewContext(referenceCounter);
|
|
313 | 329 |
state = createState(obj, context); |
314 | 330 |
context.setRootId(state.getId()); |
315 | 331 |
this.validateAll(state, this.autoValidationMode); |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/persistence/impl/DefaultPersistentContext.java | ||
---|---|---|
56 | 56 |
import java.util.List; |
57 | 57 |
import java.util.Map; |
58 | 58 |
import java.util.Map.Entry; |
59 |
import org.apache.commons.lang3.mutable.MutableInt; |
|
59 | 60 |
|
60 | 61 |
import org.gvsig.tools.persistence.PersistenceFactory; |
61 | 62 |
import org.gvsig.tools.persistence.PersistenceManager; |
... | ... | |
74 | 75 |
import org.slf4j.LoggerFactory; |
75 | 76 |
|
76 | 77 |
public class DefaultPersistentContext implements PersistentContextServices { |
77 |
private static int IdentifiersCounter = 1; |
|
78 | 78 |
|
79 | 79 |
private static Logger LOG = LoggerFactory.getLogger(DefaultPersistentContext.class); |
80 | 80 |
|
... | ... | |
85 | 85 |
private boolean collectErrors; |
86 | 86 |
private PersistenceException errors; |
87 | 87 |
private boolean validated; |
88 |
private MutableInt referenceCounter; |
|
88 | 89 |
|
89 |
public DefaultPersistentContext(PersistenceManager manager) { |
|
90 |
public DefaultPersistentContext(PersistenceManager manager, MutableInt referenceCounter) {
|
|
90 | 91 |
this.manager = manager; |
91 | 92 |
this.collectErrors = false; |
92 | 93 |
this.errors = null; |
93 | 94 |
this.validated = false; |
95 |
this.referenceCounter = referenceCounter; |
|
94 | 96 |
|
95 | 97 |
// Use LinkedHashMap for predictable order when save to a file |
96 | 98 |
this.idToReference = new LinkedHashMap(); |
... | ... | |
232 | 234 |
|
233 | 235 |
@Override |
234 | 236 |
public PersistentIdentifier getNewIdentifier() { |
235 |
return new DefaultPersistentIdentifier(String.valueOf( IdentifiersCounter++));
|
|
237 |
return new DefaultPersistentIdentifier(String.valueOf(referenceCounter.getAndIncrement()));
|
|
236 | 238 |
} |
237 | 239 |
|
238 | 240 |
@Override |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/persistence/spi/PersistenceManagerServices.java | ||
---|---|---|
26 | 26 |
import java.util.List; |
27 | 27 |
import java.util.Map; |
28 | 28 |
import java.util.Set; |
29 |
import org.apache.commons.lang3.mutable.MutableInt; |
|
29 | 30 |
|
30 | 31 |
import org.gvsig.tools.persistence.PersistenceManager; |
31 | 32 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
... | ... | |
34 | 35 |
|
35 | 36 |
public PersistentStateServices createState(Object theOriginal, PersistentContextServices context) throws PersistenceException; |
36 | 37 |
|
38 |
@Override |
|
37 | 39 |
public PersistentContextServices getNewContext(); |
38 | 40 |
|
39 |
public List getWrappedList(List list, PersistentContextServices context); |
|
41 |
@Override |
|
42 |
public PersistentContextServices getNewContext(MutableInt referenceCounter); |
|
40 | 43 |
|
44 |
public List getWrappedList(List list, PersistentContextServices context); |
|
45 |
|
|
41 | 46 |
public Map getWrappedMap(Map map, PersistentContextServices context); |
42 | 47 |
|
43 | 48 |
public Set getWrappedSet(Set set, PersistentContextServices context); |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/persistence/PersistenceManager.java | ||
---|---|---|
27 | 27 |
import java.io.OutputStream; |
28 | 28 |
import java.util.List; |
29 | 29 |
import java.util.Map; |
30 |
import org.apache.commons.lang3.mutable.MutableInt; |
|
30 | 31 |
|
31 | 32 |
import org.gvsig.tools.dynobject.DynStruct; |
32 | 33 |
import org.gvsig.tools.persistence.exception.AddDefinitionException; |
... | ... | |
34 | 35 |
import org.gvsig.tools.persistence.exception.PersistenceCreateException; |
35 | 36 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
36 | 37 |
import org.gvsig.tools.persistence.exception.PersistenceValidateExceptions; |
38 |
import org.gvsig.tools.persistence.spi.PersistentContextServices; |
|
37 | 39 |
|
38 | 40 |
/** |
39 | 41 |
* <p> |
... | ... | |
165 | 167 |
*/ |
166 | 168 |
public PersistentState getState(Object obj, boolean collectAllErrors) throws PersistenceException; |
167 | 169 |
|
170 |
public PersistentState getState(Object obj, boolean collectAllErrors, MutableInt referenceCounter) throws PersistenceException; |
|
171 |
|
|
168 | 172 |
/** |
169 | 173 |
* <p> |
170 | 174 |
* Instantiates an object from a persistent state. The PersistentState |
... | ... | |
573 | 577 |
|
574 | 578 |
public PersistentContext getNewContext(); |
575 | 579 |
|
580 |
public PersistentContext getNewContext(MutableInt referenceCounter); |
|
581 |
|
|
576 | 582 |
} |
Also available in: Unified diff