Revision 23859

View differences:

branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/index/IndexFactory.java
1
/* 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
 
28

  
29
package org.gvsig.fmap.data.index;
30

  
31
import org.apache.log4j.Logger;
32
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor;
33
import org.gvsig.tools.extensionPoint.ExtensionPoint;
34
import org.gvsig.tools.extensionPoint.ExtensionPointsSingleton;
35

  
36
/**
37
 * Abstract factory for registering and retrieving available indexing engines. 
38
 * You can force the use of a specific implementation by passing its key, or you can use the default
39
 * implementation for a given data type by specifying the {@link AttributeDescriptor} of the column 
40
 * to be indexed.
41
 * 
42
 * @author jyarza
43
 *
44
 */
45
public abstract class IndexFactory {
46

  
47
	private static Logger logger = Logger.getLogger(IndexFactory.class);
48
	
49
	/**
50
	 * Convenience constants to identify sets of implemented factories classified by supported data types. 
51
	 * Using these from a client is not permitted as implementations are optional and not visible.
52
	 */
53
	public interface Factories {
54
		
55
		public interface GEOMETRY {
56
			public static final String GT2_QUADTREE = "QuadTreeGt2Factory";
57
			public static final String JSI_RTREE = "RTreeJsiFactory";
58
			public static final String JTS_QUADTREE = "QuadTreeJtsFactory";
59
			public static final String SPATIALINDEX_RTREE = "RTreeSptLibFactory";
60
			public static final String DEFAULT = GT2_QUADTREE;
61
		}
62
		
63
		public interface DATE {
64
			// added as example
65
		}
66
		
67
		public interface INTEGER {
68
			// added as example			
69
		}
70
		
71
	}
72
	
73
	// Register extension point, all available factory implementations will hang off here.
74
	public static final String EXTENSION_POINT_NAME =  "IndexFactory";
75
	private static ExtensionPoint ep = new ExtensionPoint(EXTENSION_POINT_NAME, "Index Factory");
76
	
77
	static {		
78
		ExtensionPointsSingleton.getInstance().put(ep);
79
	}
80

  
81
	/**
82
	 * Returns the default index factory registered for the given data type.
83
	 * @param col
84
	 * @return
85
	 * @throws InstantiationException
86
	 * @throws IllegalAccessException
87
	 */
88
	public static IndexFactory getDefaultFactory(FeatureAttributeDescriptor col) throws InstantiationException, IllegalAccessException {
89
		int type = col.getDataType();
90
		if (type == FeatureAttributeDescriptor.GEOMETRY) {
91
			return getFactory(Factories.GEOMETRY.DEFAULT);
92
		} else {
93
			throw new UnsupportedOperationException(type + " indexes are not supported.");
94
		}
95
		
96
	}
97
	
98
	/**
99
	 * Returns a specific index factory by key. 
100
	 * The argument implType must be one of the constants defined in {@link IndexFactory.Factories}
101
	 * @param implType
102
	 * @return
103
	 * @throws InstantiationException
104
	 * @throws IllegalAccessException
105
	 */
106
	public static IndexFactory getFactory(String key) throws InstantiationException, IllegalAccessException {
107
		if (!ep.containsKey(key)) {
108
			throw new IllegalArgumentException(key + " is not a valid factory.");
109
		}
110
		return (IndexFactory) ep.create(key);
111
	}
112
	
113
	/**
114
	 * Registers an index factory.
115
	 * @param key Name by which the factory will be identified
116
	 * @param description
117
	 * @param value
118
	 */
119
	protected static void registerFactory(String key, String description, Class value) {
120
		ep.put(key, description, value);
121
		logger.debug(key + " registered.");
122
	}
123

  
124
	/**
125
	 * Creates and returns a new index using default parameters.
126
	 * @return
127
	 * @throws IndexException
128
	 */
129
	public Index createIndex() throws IndexException {
130
		return createIndex(null);
131
	}
132
	
133
	/**
134
	 * Creates and returns a new index using the given parameters.
135
	 * @param params
136
	 * @return
137
	 * @throws IndexException
138
	 */
139
	public abstract Index createIndex(IndexParameters params) throws IndexException;
140
	
141
}
142

  
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/index/IndexRegistry.java
1
/* 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

  
28
package org.gvsig.fmap.data.index;
29

  
30
import java.util.HashMap;
31
import java.util.Iterator;
32
import java.util.Map;
33

  
34
import org.gvsig.fmap.data.exceptions.DataException;
35
import org.gvsig.fmap.data.feature.FeatureStore;
36
import org.gvsig.fmap.data.feature.FeatureType;
37

  
38
/**
39
 * This class provides access to a FeatureStore local indexes.
40
 * This class holds the correspondence (FeatureType, columName) -> Index
41
 * TODO there is not persistence and works only in memory
42
 * @author jyarza
43
 */
44
public class IndexRegistry {
45

  
46
	private Map featureTypes = new HashMap();
47

  
48
	/**
49
	 * Creates an empty IndexRegistry for the given FeatureStore
50
	 * 
51
	 * @param store
52
	 *            FeatureStore to whom this IndexRegistry belongs
53
	 * @throws DataException
54
	 */
55
	public IndexRegistry(FeatureStore store) throws DataException {
56
		Iterator it = store.getFeatureTypes().iterator();
57
		while (it.hasNext()) {
58
			FeatureType type = (FeatureType) it.next();
59
			featureTypes.put(type, new HashMap());
60
		}
61
	}
62

  
63
	/**
64
	 * Returns an Index given the FeatureType and the name of the column.
65
	 * If the column has no index then this method returns <code>null</code>.
66
	 * @param fType FeatureType to which belongs the index
67
	 * @param colName name of the column
68
	 * @return if the index exists then this method returns the index, otherwise it returns null.
69
	 */
70
	public Index getIndex(FeatureType fType, String colName) {
71
		Map indexes = (Map) featureTypes.get(fType);
72
		if (indexes != null) {
73
			return (Index) (featureTypes.get(fType));
74
		}
75
		return null;
76
	}
77

  
78
	/**
79
	 * Adds an index to the registry, given its FeatureType and column name
80
	 * @param fType
81
	 * @param colName
82
	 * @param index
83
	 */
84
	public void addIndex(FeatureType fType, String colName, Index index) {
85
		Map indexes = (Map) featureTypes.get(fType);
86
		if (indexes == null) {
87
			// A new feature type has been added to the FeatureStore since this IndexStore was created
88
			indexes = new HashMap();
89
			featureTypes.put(fType, indexes);
90
		}
91
		indexes.put(colName, index);
92
	}
93

  
94
	/**
95
	 * Returns true if this registry contains an index for the given FeatureType and column name, otherwise
96
	 * it returns false.
97
	 * @param fType
98
	 * @param colName
99
	 * @return <code>true</code> if the index exists, <code>false</code> if it does not.
100
	 */
101
	public boolean contains(FeatureType fType, String colName) {
102
		Map map = (Map) featureTypes.get(fType);
103
		return map == null ? false : map.containsKey(colName);
104
	}
105
}
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/index/IndexException.java
1
/* 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

  
28
package org.gvsig.fmap.data.index;
29

  
30
import java.util.HashMap;
31
import java.util.Map;
32

  
33
import org.gvsig.tools.exception.BaseException;
34

  
35
/**
36
 * 
37
 * @author azabala
38
 * @author vcaballero
39
 * @author jiyarza
40
 */
41
public class IndexException extends BaseException {
42
	
43
	private static final long serialVersionUID = 932690269454242645L;	
44
	
45
	private static final String MESSAGE_KEY = "index_exception";
46
	private static final String FORMAT_STRING = 
47
		"Index Exception.";	
48
	
49
	/**
50
	 * Main constructor that provides a cause Exception
51
	 * @param e
52
	 */
53
	public IndexException(Exception e) {
54
		super(FORMAT_STRING, e, MESSAGE_KEY, serialVersionUID);
55
	}
56
	
57
	protected Map values() {
58
		HashMap map = new HashMap();
59
		return map;
60
	}
61
}
62

  
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/index/PersistentIndex.java
1
/* 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
 
28

  
29
package org.gvsig.fmap.data.index;
30

  
31
import java.io.File;
32

  
33
/**
34
 * FIXME This specification is due to change
35
 * 
36
 * -open()
37
 * -close()
38
 * -delete()
39
 * -getFile()
40
 * 
41
 * @author azabala
42
 * @author jyarza
43
 */
44
public interface PersistentIndex {
45

  
46
	/**
47
	 * Makes persistent all changes in the index
48
	 */
49
	public void flush() throws IndexException;	
50
	public void flush(File f) throws IndexException;
51
	
52
	/**
53
	 * Checks if the persistent store of this index exists
54
	 * @return
55
	 */
56
	public boolean exists();
57
	
58
	/**
59
	 * Loads an index from a file
60
	 * @throws IndexException
61
	 */
62
	public void load() throws IndexException;
63
	public void load(File f) throws IndexException;
64
	
65
	/**
66
	 * Frees resources of persistent data store
67
	 * (closes files, etc)
68
	 *
69
	 */
70
	public void close();
71
	
72
	/**
73
	 * Obtains the index File
74
	 * @return
75
	 */
76
	public File getFile();	
77
	
78
}
79

  

Also available in: Unified diff