Revision 24 branches/org.gvsig.mssqlserver-1.0.1-SP/org.gvsig.mssqlserver.provider/src/main/java/org/gvsig/mssqlserver/dal/MSSQLServerSQLHelper.java
MSSQLServerSQLHelper.java | ||
---|---|---|
25 | 25 |
import java.sql.Connection; |
26 | 26 |
import java.sql.SQLException; |
27 | 27 |
import java.text.MessageFormat; |
28 |
import java.util.logging.Level; |
|
28 | 29 |
import org.apache.commons.dbcp.BasicDataSource; |
29 | 30 |
import org.apache.commons.lang3.StringUtils; |
30 | 31 |
import org.cresques.cts.IProjection; |
... | ... | |
33 | 34 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
34 | 35 |
import org.gvsig.fmap.dal.feature.FeatureType; |
35 | 36 |
import org.gvsig.fmap.dal.SQLBuilder; |
37 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
36 | 38 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
37 | 39 |
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters; |
38 | 40 |
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters; |
41 |
import org.gvsig.fmap.dal.store.jdbc.JDBCResource; |
|
39 | 42 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
40 | 43 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
41 | 44 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCDriverClassNotFoundException; |
... | ... | |
71 | 74 |
return connectionURL; |
72 | 75 |
} |
73 | 76 |
|
74 |
private static class ConnectionProvider {
|
|
77 |
public static class ConnectionProvider {
|
|
75 | 78 |
|
76 | 79 |
private static boolean needRegisterDriver = true; |
77 | 80 |
|
... | ... | |
84 | 87 |
} |
85 | 88 |
|
86 | 89 |
public Connection getConnection() throws SQLException { |
90 |
Connection conn = this.getDataSource().getConnection(); |
|
91 |
return conn; |
|
92 |
} |
|
93 |
|
|
94 |
public BasicDataSource getDataSource() throws SQLException { |
|
87 | 95 |
if (this.dataSource == null) { |
88 | 96 |
this.dataSource = this.createDataSource(); |
89 | 97 |
} |
90 |
Connection conn = this.dataSource.getConnection(); |
|
91 |
return conn; |
|
98 |
return this.dataSource; |
|
92 | 99 |
} |
93 | 100 |
|
94 | 101 |
private BasicDataSource createDataSource() throws SQLException { |
... | ... | |
130 | 137 |
} |
131 | 138 |
|
132 | 139 |
private ConnectionProvider connectionProvider = null; |
133 |
|
|
140 |
private MSSQLServerResource resource = null; |
|
134 | 141 |
private FeatureType lastUsedFeatureType = null; |
135 | 142 |
private String lastUsedSpatialType = null; |
136 | 143 |
|
... | ... | |
138 | 145 |
super(connectionParameters); |
139 | 146 |
} |
140 | 147 |
|
141 |
@Override |
|
142 |
public Connection getConnection() throws AccessResourceException { |
|
148 |
public ConnectionProvider getConnectionProvider() throws AccessResourceException { |
|
143 | 149 |
try { |
144 | 150 |
if (this.connectionProvider == null) { |
145 | 151 |
this.connectionProvider = new ConnectionProvider(this.getConnectionParameters()); |
146 | 152 |
} |
147 |
return this.connectionProvider.getConnection(); |
|
153 |
return this.connectionProvider; |
|
154 |
} catch (Exception ex) { |
|
155 |
throw new AccessResourceException(MSSQLServerLibrary.NAME, ex); |
|
156 |
} |
|
157 |
} |
|
158 |
|
|
159 |
@Override |
|
160 |
public Connection getConnection() throws AccessResourceException { |
|
161 |
try { |
|
162 |
return this.getConnectionProvider().getConnection(); |
|
148 | 163 |
} catch (SQLException ex) { |
149 | 164 |
throw new AccessResourceException(MSSQLServerLibrary.NAME, ex); |
150 | 165 |
} |
151 | 166 |
} |
167 |
|
|
168 |
@Override |
|
169 |
public JDBCResource getResource() { |
|
170 |
if( this.resource == null ) { |
|
171 |
try { |
|
172 |
this.resource = new MSSQLServerResource(this); |
|
173 |
} catch (InitializeException ex) { |
|
174 |
throw new RuntimeException(ex); |
|
175 |
} |
|
176 |
} |
|
177 |
return this.resource; |
|
178 |
} |
|
152 | 179 |
|
153 | 180 |
@Override |
154 | 181 |
public String getConnectionURL() { |
Also available in: Unified diff