Revision 433
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLNewStoreParameters.java | ||
---|---|---|
56 | 56 |
return this.helper.getUseSSL(); |
57 | 57 |
} |
58 | 58 |
|
59 |
@Override |
|
60 |
public int getMaxIdle() { |
|
61 |
return this.helper.getMaxIdle(); |
|
62 |
} |
|
63 |
|
|
59 | 64 |
public void setUseSSL(boolean v) { |
60 | 65 |
this.helper.setUseSSL(v); |
61 | 66 |
} |
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLServerExplorerParameters.java | ||
---|---|---|
66 | 66 |
return this.helper.getUseSSL(); |
67 | 67 |
} |
68 | 68 |
|
69 |
@Override |
|
70 |
public int getMaxIdle() { |
|
71 |
return this.helper.getMaxIdle(); |
|
72 |
} |
|
73 |
|
|
69 | 74 |
public void setUseSSL(boolean v) { |
70 | 75 |
this.helper.setUseSSL(v); |
71 | 76 |
} |
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLHelper.java | ||
---|---|---|
7 | 7 |
import java.util.ArrayList; |
8 | 8 |
import java.util.List; |
9 | 9 |
import org.apache.commons.dbcp.BasicDataSource; |
10 |
import org.apache.commons.dbcp.BasicDataSourceFactory; |
|
10 | 11 |
import org.apache.commons.lang3.BooleanUtils; |
11 | 12 |
import org.apache.commons.lang3.StringUtils; |
12 | 13 |
import org.gvsig.fmap.dal.DataTypes; |
... | ... | |
25 | 26 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
26 | 27 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase; |
27 | 28 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
28 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSRSsBase;
|
|
29 |
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolverBase;
|
|
29 | 30 |
import org.gvsig.fmap.geom.Geometry; |
30 | 31 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
31 | 32 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
... | ... | |
80 | 81 |
if (this.dataSource == null) { |
81 | 82 |
this.dataSource = this.createDataSource(); |
82 | 83 |
} |
83 |
Connection conn = this.dataSource.getConnection(); |
|
84 |
if( logger.isDebugEnabled() ) { |
|
85 |
logger.debug("getConnection:\n" + getStatusInformation()); |
|
86 |
} |
|
87 |
Connection conn; |
|
88 |
try { |
|
89 |
conn = this.dataSource.getConnection(); |
|
90 |
} catch(Throwable ex) { |
|
91 |
logger.debug("Error getting connection from pool.",ex); |
|
92 |
throw ex; |
|
93 |
} |
|
94 |
if( logger.isDebugEnabled() ) { |
|
95 |
logger.debug("Created connection: {}\n NumActive: {}\n NumIdle: {}", |
|
96 |
new Object[] { |
|
97 |
conn.hashCode(), |
|
98 |
this.dataSource.getNumActive(), |
|
99 |
this.dataSource.getNumIdle() |
|
100 |
} |
|
101 |
); |
|
102 |
} |
|
84 | 103 |
return conn; |
85 | 104 |
} |
105 |
|
|
106 |
public void closeConnection(Connection connection) { |
|
107 |
if( connection != null ) { |
|
108 |
int connectionId = connection.hashCode(); |
|
109 |
try { |
|
110 |
connection.close(); |
|
111 |
} catch(Throwable ex) { |
|
112 |
logger.warn("Can't close connection.", ex); |
|
113 |
} |
|
114 |
if( logger.isDebugEnabled() ) { |
|
115 |
Boolean isClosed; |
|
116 |
try { |
|
117 |
isClosed = connection.isClosed(); |
|
118 |
} catch(Throwable th) { |
|
119 |
isClosed = null; |
|
120 |
} |
|
121 |
logger.debug("Closed connection: {}\n isClosed: {}\n NumActive: {}\n NumIdle: {}", |
|
122 |
new Object[] { |
|
123 |
connectionId, |
|
124 |
isClosed, |
|
125 |
this.dataSource.getNumActive(), |
|
126 |
this.dataSource.getNumIdle() |
|
127 |
} |
|
128 |
); |
|
129 |
} |
|
130 |
} else if( logger.isDebugEnabled() ) { |
|
131 |
logger.debug("Close connection: null"); |
|
132 |
} |
|
133 |
} |
|
134 |
|
|
135 |
public String getStatusInformation() { |
|
136 |
StringBuilder builder = new StringBuilder(); |
|
137 |
builder.append("BasicDataSource pool status:\n"); |
|
138 |
builder.append(" Connection URL: '").append(this.dataSource.getUrl()).append("'\n"); |
|
139 |
if( this.dataSource.getInitialSize()>0 ) { |
|
140 |
builder.append(" InitialSize: ").append(this.dataSource.getInitialSize()).append(" (The initial number of connections that are created when the pool is started)\n"); |
|
141 |
} |
|
142 |
if( this.dataSource.isPoolPreparedStatements() ) { |
|
143 |
builder.append(" PoolPreparedStatements: ").append(this.dataSource.isPoolPreparedStatements()).append("\n"); |
|
144 |
builder.append(" MaxOpenPreparedStatements: ").append(this.dataSource.getMaxOpenPreparedStatements()).append(" (The maximum number of open statements that can be allocated from the statement pool at the same time, or non-positive for no limit)\n"); |
|
145 |
} |
|
146 |
builder.append(" MaxActive: ").append(this.dataSource.getMaxActive()).append(" (The maximum number of active connections that can be allocated from this pool at the same time)\n"); |
|
147 |
builder.append(" MaxIdle: ").append(this.dataSource.getMaxIdle()).append(" (The maximum number of connections that can remain idle in the pool)\n"); |
|
148 |
builder.append(" NumActive:").append(this.dataSource.getNumActive()).append(" (the current number of active connections)\n"); |
|
149 |
builder.append(" NumIdle:").append(this.dataSource.getNumIdle()).append(" (the current number of idle connections)\n"); |
|
150 |
return builder.toString(); |
|
151 |
} |
|
86 | 152 |
|
87 | 153 |
private BasicDataSource createDataSource() throws SQLException { |
88 | 154 |
if (!this.isRegistered()) { |
... | ... | |
91 | 157 |
PostgreSQLConnectionParameters params = connectionParameters; |
92 | 158 |
|
93 | 159 |
BasicDataSource ds = new BasicDataSource(); |
160 |
ds.setMaxIdle(params.getMaxIdle()); |
|
94 | 161 |
ds.setDriverClassName(params.getJDBCDriverClassName()); |
95 | 162 |
if( params.getUseSSL() ) { |
96 | 163 |
String s = BooleanUtils.toStringTrueFalse(params.getUseSSL()); |
... | ... | |
134 | 201 |
|
135 | 202 |
public PostgreSQLHelper(JDBCConnectionParameters connectionParameters) { |
136 | 203 |
super(connectionParameters); |
137 |
this.srss = new JDBCSRSsBase(this);
|
|
204 |
this.srssolver = new SRSSolverBase(this);
|
|
138 | 205 |
} |
139 | 206 |
|
140 | 207 |
@Override |
... | ... | |
148 | 215 |
throw new AccessResourceException(PostgreSQLLibrary.NAME, ex); |
149 | 216 |
} |
150 | 217 |
} |
218 |
|
|
219 |
@Override |
|
220 |
public void closeConnection(Connection connection) { |
|
221 |
this.connectionProvider.closeConnection(connection); |
|
222 |
} |
|
151 | 223 |
|
224 |
|
|
225 |
|
|
152 | 226 |
@Override |
153 | 227 |
public PostgreSQLConnectionParameters getConnectionParameters() { |
154 | 228 |
return (PostgreSQLConnectionParameters) super.getConnectionParameters(); |
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/operations/PostgreSQLFetchFeatureTypeOperation.java | ||
---|---|---|
18 | 18 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
19 | 19 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
20 | 20 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
21 |
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolver; |
|
21 | 22 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.FetchFeatureTypeOperation; |
22 | 23 |
import org.gvsig.fmap.geom.Geometry; |
23 | 24 |
import org.gvsig.fmap.geom.GeometryLocator; |
... | ... | |
125 | 126 |
attr.setGeometryType(gt); |
126 | 127 |
} |
127 | 128 |
if( !StringUtils.isEmpty(srsid) ) { |
128 |
attr.setSRS(this.helper.getProjectionFromDatabaseCode(srsid)); |
|
129 |
SRSSolver srssolver = this.helper.getSRSSolver(); |
|
130 |
attr.setSRS(srssolver.getProjection(this.getConnection(),srsid)); |
|
129 | 131 |
} |
130 | 132 |
} catch (Exception ex) { |
131 | 133 |
logger.debug("Can't get geometry type and srs from column '"+attr.getName()+"'.",ex); |
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLStoreParameters.java | ||
---|---|---|
52 | 52 |
return this.helper.getUseSSL(); |
53 | 53 |
} |
54 | 54 |
|
55 |
@Override |
|
56 |
public int getMaxIdle() { |
|
57 |
return this.helper.getMaxIdle(); |
|
58 |
} |
|
59 |
|
|
55 | 60 |
public void setUseSSL(boolean v) { |
56 | 61 |
this.helper.setUseSSL(v); |
57 | 62 |
} |
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLConnectionParameters.java | ||
---|---|---|
6 | 6 |
|
7 | 7 |
public interface PostgreSQLConnectionParameters extends JDBCConnectionParameters, DBParameters { |
8 | 8 |
public static final String USESSL_PARAMTER_NAME = "UseSSL"; |
9 |
public static final String MAXIDLE_PARAMTER_NAME = "maxIdle"; |
|
9 | 10 |
|
10 |
public boolean getUseSSL(); |
|
11 |
public boolean getUseSSL(); |
|
12 |
|
|
13 |
public int getMaxIdle(); |
|
11 | 14 |
} |
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLConnectionParametersHelper.java | ||
---|---|---|
52 | 52 |
((DataParameters)this.parameters).setDynValue(name,value); |
53 | 53 |
} |
54 | 54 |
|
55 |
public int getMaxIdle() { |
|
56 |
return (int) this.getDynValue(PostgreSQLConnectionParameters.MAXIDLE_PARAMTER_NAME); |
|
57 |
} |
|
55 | 58 |
|
56 | 59 |
public boolean getUseSSL() { |
57 | 60 |
return (boolean) this.getDynValue(PostgreSQLConnectionParameters.USESSL_PARAMTER_NAME); |
trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/resources/org/gvsig/postgresql/dal/PostgreSQLParameters.xml | ||
---|---|---|
23 | 23 |
defaultValue="false" group="Basic"> |
24 | 24 |
<description>Use SSL connetion</description> |
25 | 25 |
</field> |
26 |
<field name="maxIdle" type="integer" mandatory="false" |
|
27 |
defaultValue="8" group="Advanced"> |
|
28 |
<description>The maximum number of connections that can remail idle in the pool.</description> |
|
29 |
</field> |
|
26 | 30 |
</fields> |
27 | 31 |
</class> |
28 | 32 |
|
Also available in: Unified diff