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