svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dataDB / src / org / gvsig / data / datastores / vectorial / db / jdbc / postgresqlbin / PostgresqlBinStore.java @ 20973
History | View | Annotate | Download (4.9 KB)
1 |
package org.gvsig.data.datastores.vectorial.db.jdbc.postgresqlbin; |
---|---|
2 |
|
3 |
import java.lang.ref.WeakReference; |
4 |
import java.sql.Connection; |
5 |
import java.sql.ResultSet; |
6 |
import java.sql.Statement; |
7 |
import java.util.Locale; |
8 |
|
9 |
import org.gvsig.data.CloseException; |
10 |
import org.gvsig.data.IDataCollection; |
11 |
import org.gvsig.data.IDataExplorer; |
12 |
import org.gvsig.data.InitializeException; |
13 |
import org.gvsig.data.OpenException; |
14 |
import org.gvsig.data.ReadException; |
15 |
import org.gvsig.data.datastores.vectorial.db.DBFeatureType; |
16 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeaturesWriter; |
17 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCResource; |
18 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStoreParameters; |
19 |
import org.gvsig.data.datastores.vectorial.db.jdbc.postgresql.PostgresqlStore; |
20 |
import org.gvsig.data.datastores.vectorial.db.jdbc.postgresql.PostgresqlStoreParameters; |
21 |
import org.gvsig.data.vectorial.IFeature; |
22 |
import org.gvsig.data.vectorial.IFeatureCollection; |
23 |
import org.gvsig.data.vectorial.IFeatureType; |
24 |
import org.gvsig.metadata.IMetadata; |
25 |
|
26 |
public class PostgresqlBinStore extends PostgresqlStore{ |
27 |
public static final String CONNECTION_STRING = "postgresql"; |
28 |
public static String DATASTORE_NAME = "PostgresqlStore"; |
29 |
protected static Locale ukLocale = new Locale("en", "UK"); // English, UK version |
30 |
PostgresqlBinStoreParameters getParametersPostgresql(){ |
31 |
return (PostgresqlBinStoreParameters)this.parameters; |
32 |
} |
33 |
|
34 |
/* (non-Javadoc)
|
35 |
* @see org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStore#createResource(org.gvsig.data.datastores.vectorial.file.dbf.DBFStoreParameters)
|
36 |
*/
|
37 |
protected JDBCResource createResource(JDBCStoreParameters params) {
|
38 |
return new PostgresqlBinResource((PostgresqlBinStoreParameters)params); |
39 |
} |
40 |
|
41 |
public String getName() { |
42 |
return DATASTORE_NAME;
|
43 |
} |
44 |
|
45 |
public IDataCollection getDataCollection(IFeatureType type, String filter, String order) throws ReadException { |
46 |
if (useSqlSource ){
|
47 |
if (filter != null || order != null){ |
48 |
throw new ReadException(DATASTORE_NAME, |
49 |
new UnsupportedOperationException("Unsuported filter/order in sqlSource mode")); |
50 |
} |
51 |
} |
52 |
if (type==null){ |
53 |
type=getDefaultFeatureType(); |
54 |
} |
55 |
IFeatureCollection coll=null;
|
56 |
if (featureManager == null){ |
57 |
coll=new PostgresqlBinFeatureCollection(this,type,filter,order); |
58 |
}else{
|
59 |
// if ((order != null && order != "")){
|
60 |
// coll=new H2FeatureCollectionWithFeatureID(featureManager,this,type,filter,order);
|
61 |
// } else{
|
62 |
// if (filter == null || filter == ""){
|
63 |
// coll=new H2FeatureCollectionEditing(featureManager,this,type);
|
64 |
// } else {
|
65 |
// coll=new H2FeatureCollectionEditingFiltered(featureManager,this,type,filter);
|
66 |
// }
|
67 |
// }
|
68 |
//
|
69 |
|
70 |
} |
71 |
this.addObserver(new WeakReference(coll)); |
72 |
|
73 |
return coll;
|
74 |
} |
75 |
|
76 |
|
77 |
public IFeature getFeatureByID(IFeatureType featureType2, Object[] featureKey) throws ReadException{ |
78 |
if (useSqlSource){
|
79 |
throw new ReadException(this.getName(), |
80 |
new UnsupportedOperationException("Unsuported featureByID in sqlSource mode")); |
81 |
} |
82 |
ResultSet rs=null; |
83 |
try{
|
84 |
this.open();
|
85 |
|
86 |
Statement st=this.getConnection().createStatement( |
87 |
ResultSet.TYPE_SCROLL_INSENSITIVE,
|
88 |
ResultSet.CONCUR_READ_ONLY);
|
89 |
String sql = this.getSqlSelectPart() + |
90 |
" WHERE "+
|
91 |
this.getFilterForID(
|
92 |
(DBFeatureType)this.getDefaultFeatureType(),
|
93 |
featureKey); |
94 |
String cursorName = PostgresqlBinStoreUtils.createCursorName();
|
95 |
String mSql="BEGIN"; |
96 |
st.execute(mSql); |
97 |
mSql="declare " + cursorName + " binary cursor for " + sql; |
98 |
st.execute(mSql); |
99 |
rs=st.executeQuery("fetch 1 in "+ cursorName);
|
100 |
if (rs.isLast()) {
|
101 |
|
102 |
return null; |
103 |
}else{
|
104 |
if(rs.next()){
|
105 |
return this.createFeatureFromResulset( |
106 |
rs, |
107 |
(DBFeatureType)this.getDefaultFeatureType());
|
108 |
} |
109 |
|
110 |
} |
111 |
|
112 |
} catch (java.sql.SQLException e) {
|
113 |
e.printStackTrace(); |
114 |
throw new ReadException(this.getName(), e); |
115 |
} finally{
|
116 |
if (rs != null) |
117 |
try {
|
118 |
rs.close(); |
119 |
} catch (java.sql.SQLException e) {
|
120 |
// TODO ?????
|
121 |
e.printStackTrace(); |
122 |
} |
123 |
} |
124 |
return null; |
125 |
} |
126 |
|
127 |
|
128 |
|
129 |
/* (non-Javadoc)
|
130 |
* @see org.gvsig.data.datastores.vectorial.db.jdbc.postgresql.PostgresqlStore#getConnection()
|
131 |
*/
|
132 |
protected Connection getConnection() throws ReadException { |
133 |
return super.getConnection(); |
134 |
} |
135 |
|
136 |
public boolean canAlterFeatureType() { |
137 |
return true; |
138 |
} |
139 |
|
140 |
|
141 |
|
142 |
public JDBCFeaturesWriter getFeaturesWriter() {
|
143 |
// IFeaturesWriter writer = new H2FeaturesWriter();
|
144 |
// writer.init(this);
|
145 |
// return writer;
|
146 |
return null; |
147 |
} |
148 |
|
149 |
public IDataExplorer getExplorer() {
|
150 |
// TODO Auto-generated method stub
|
151 |
return null; |
152 |
} |
153 |
|
154 |
public boolean isEditable() { |
155 |
return false; |
156 |
|
157 |
// return super.isEditable();
|
158 |
} |
159 |
|
160 |
|
161 |
public IMetadata getMetadata() {
|
162 |
if (metadata==null){ |
163 |
IMetadata tmp=super.getMetadata();
|
164 |
|
165 |
return tmp;
|
166 |
}else{
|
167 |
return super.getMetadata(); |
168 |
} |
169 |
|
170 |
} |
171 |
|
172 |
|
173 |
protected IFeature createFeatureFromResulset(ResultSet rs, DBFeatureType featureType2) throws ReadException { |
174 |
return new PostgresqlBinFeature(featureType2,this,rs); |
175 |
} |
176 |
|
177 |
} |