svn-gvsig-desktop / 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 / memory / AbstractMemoryStoreProvider.java @ 40435
History | View | Annotate | Download (4.6 KB)
1 | 40435 | jjdelcerro | /* 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 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2008 {{Company}} {{Task}}
|
||
26 | */
|
||
27 | package org.gvsig.fmap.dal.feature.spi.memory; |
||
28 | |||
29 | import java.util.Iterator; |
||
30 | import java.util.List; |
||
31 | |||
32 | import org.gvsig.fmap.dal.DataStoreParameters; |
||
33 | import org.gvsig.fmap.dal.exception.DataException; |
||
34 | import org.gvsig.fmap.dal.feature.FeatureQuery; |
||
35 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
36 | import org.gvsig.fmap.dal.feature.exception.PerformEditingException; |
||
37 | import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider; |
||
38 | import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider; |
||
39 | import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
||
40 | import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
||
41 | import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
||
42 | import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
||
43 | import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
||
44 | import org.gvsig.tools.dynobject.DynObject; |
||
45 | import org.gvsig.tools.exception.BaseException; |
||
46 | |||
47 | /**
|
||
48 | * Abstract implementation for {@link FeatureStoreProvider} for provider that
|
||
49 | * are loaded statically in memory
|
||
50 | *
|
||
51 | */
|
||
52 | public abstract class AbstractMemoryStoreProvider extends |
||
53 | AbstractFeatureStoreProvider { |
||
54 | |||
55 | protected List data; |
||
56 | |||
57 | protected AbstractMemoryStoreProvider(DataStoreParameters params,
|
||
58 | DataStoreProviderServices storeServices, DynObject metadata) { |
||
59 | super(params, storeServices, metadata);
|
||
60 | } |
||
61 | |||
62 | protected AbstractMemoryStoreProvider(DataStoreParameters params,
|
||
63 | DataStoreProviderServices storeServices) { |
||
64 | super(params, storeServices);
|
||
65 | } |
||
66 | |||
67 | public void performChanges(Iterator deleteds, Iterator inserteds, Iterator updateds, Iterator originalFeatureTypesUpdated) throws PerformEditingException { |
||
68 | throw new UnsupportedOperationException(); |
||
69 | } |
||
70 | |||
71 | /**
|
||
72 | * Load a {@link FeatureProvider} into memory store.<br>
|
||
73 | * Use this when loading data.
|
||
74 | *
|
||
75 | * @param data
|
||
76 | */
|
||
77 | public void addFeatureProvider(FeatureProvider data) { |
||
78 | data.setOID(this.createNewOID());
|
||
79 | this.data.add(data);
|
||
80 | } |
||
81 | |||
82 | /**
|
||
83 | * Return the current size of the memory store.
|
||
84 | *
|
||
85 | * @return
|
||
86 | * @throws DataException
|
||
87 | */
|
||
88 | public long getDataSize() throws DataException { |
||
89 | this.open();
|
||
90 | return this.data.size(); |
||
91 | } |
||
92 | |||
93 | protected FeatureProvider internalGetFeatureProviderByReference(
|
||
94 | FeatureReferenceProviderServices reference) throws DataException {
|
||
95 | int oid = ((Long) reference.getOID()).intValue(); |
||
96 | return (FeatureProvider) this.data.get(oid); |
||
97 | } |
||
98 | |||
99 | protected FeatureProvider internalGetFeatureProviderByReference(
|
||
100 | FeatureReferenceProviderServices reference, FeatureType featureType) |
||
101 | throws DataException {
|
||
102 | return new MemoryFeatureProviderAttributeMapper( |
||
103 | (DefaultFeatureProvider) internalGetFeatureProviderByReference(reference), |
||
104 | featureType); |
||
105 | } |
||
106 | |||
107 | /*
|
||
108 | * (non-Javadoc)
|
||
109 | * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#createSet(org.gvsig.fmap.dal.feature.FeatureQuery, org.gvsig.fmap.dal.feature.FeatureType)
|
||
110 | */
|
||
111 | public FeatureSetProvider createSet(FeatureQuery query, FeatureType featureType)
|
||
112 | throws DataException {
|
||
113 | this.open();
|
||
114 | return new MemoryFeatureSet(this, query, featureType, this.data); |
||
115 | } |
||
116 | |||
117 | /*
|
||
118 | * (non-Javadoc)
|
||
119 | * @see org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider#createFeatureProvider(org.gvsig.fmap.dal.feature.FeatureType)
|
||
120 | */
|
||
121 | public FeatureProvider createFeatureProvider(FeatureType featureType)throws DataException { |
||
122 | this.open();
|
||
123 | return new DefaultFeatureProvider(featureType); |
||
124 | } |
||
125 | |||
126 | /*
|
||
127 | * (non-Javadoc)
|
||
128 | * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#getFeatureCount()
|
||
129 | */
|
||
130 | public long getFeatureCount() throws DataException { |
||
131 | return data.size();
|
||
132 | } |
||
133 | |||
134 | protected AbstractMemoryStoreProvider getMemoryProvider() {
|
||
135 | return this; |
||
136 | } |
||
137 | |||
138 | protected void doDispose() throws BaseException { |
||
139 | super.doDispose();
|
||
140 | data = null;
|
||
141 | } |
||
142 | } |