Revision 45097 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialHelper.java

View differences:

H2SpatialHelper.java
40 40
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
41 41
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCDriverClassNotFoundException;
42 42
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
43
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
43 44
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
44 45
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase;
45 46
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
......
132 133
        public ConnectionProviderImpl(H2SpatialConnectionParameters connectionParameters) {
133 134
            this.connectionParameters = connectionParameters;
134 135
        }
136

  
137
        @Override
138
        public String getStatus() {
139
            StringBuilder builder = new StringBuilder();
140
            builder.append("Pool: ");
141
            builder.append(JDBCUtils.getHexId(dataSource));
142
            builder.append(" Actives: ");
143
            builder.append(dataSource.getNumActive());
144
            builder.append("/");
145
            builder.append(dataSource.getMaxActive());
146
            builder.append(" idle: ");
147
            builder.append(dataSource.getNumIdle());
148
            builder.append("/");
149
            builder.append(dataSource.getMinIdle());
150
            builder.append(":");
151
            builder.append(dataSource.getMaxIdle());
152
            return builder.toString();
153
        }
135 154
        
136 155
        @SuppressWarnings("ConvertToTryWithResources")
137 156
        public void shutdown() {
......
146 165
            try {
147 166
                if( dataSource!=null ) {
148 167
                    LOGGER.info("Clossing connection pool.");
149
                    LOGGER.info("  Actives: "+dataSource.getNumActive());
150
                    LOGGER.info("  Idle   : "+dataSource.getNumIdle());
168
                    LOGGER.info(this.getStatus());
151 169
                    dataSource.close();
152 170
                    LOGGER.info("Connection pool closed.");
153
                    LOGGER.info("  Actives: "+dataSource.getNumActive());
154
                    LOGGER.info("  Idle   : "+dataSource.getNumIdle());
171
                    LOGGER.info(this.getStatus());
155 172
                }
156 173
            } catch (Throwable th) {
157 174
                LOGGER.warn("Problems closing connections pool.", th);
......
230 247
        
231 248
        @Override
232 249
        public Connection getConnection() throws SQLException {
233
//            File f = getLocalFile(connectionParameters);
234
//            boolean newdb = f != null && !f.exists();
235

  
236 250
            if (this.dataSource == null) {
237 251
                this.dataSource = this.createDataSource();               
238 252
            }
......
240 254
            try {
241 255
                conn = this.dataSource.getConnection();
242 256
            } catch(Throwable th) {
257
                LOGGER.warn("Can't create connection to '"+this.dataSource.getUrl()+"'. "+this.getStatus());
243 258
                LOGGER.warn("Can't create connection to '"+this.dataSource.getUrl()+"'.",th);
244 259
                throw th;
245 260
            }
......
357 372
            LOGGER.warn("Problems shutdown H2", ex);
358 373
        }
359 374
    }
375

  
376
    private void logConnectionStatus(String msg, Connection conn) {
377
        ConnectionProvider cp = this.getConnectionProvider();
378
        StringBuilder builder = new StringBuilder();
379
        builder.append(msg);
380
        if( conn == null ) {
381
            builder.append(": connection null");
382
        } else {
383
            Boolean closed = null;
384
            try {
385
                closed = conn.isClosed();
386
            } catch(Throwable th) {
387
            }
388
            builder.append(": connection ");
389
            builder.append(JDBCUtils.getConnId(conn));
390
            if( closed ) {
391
                builder.append(" (c)");
392
            }
393
            builder.append(" ");
394
        }
395
        builder.append(cp.getStatus());
396
        LOGGER.info(builder.toString());
397
    }
398
        
399
    private ConnectionProvider getConnectionProvider() {
400
        if (this.connectionProvider == null) {
401
          H2SpatialConnectionParameters connectionParameters = this.getConnectionParameters();
402
          if( connectionParameters==null ) {
403
            return null; // Testing mode?
404
          }
405
          this.connectionProvider = new ConnectionProviderImpl(connectionParameters);
406
        }
407
        return this.connectionProvider;
408
    }
360 409
    
361 410
    @Override
362 411
    public synchronized Connection  getConnection() throws AccessResourceException {
......
370 419
            }
371 420
            Connection connection = this.connectionProvider.getConnection();
372 421
            if( LOGGER.isDebugEnabled() ) {
373
                LOGGER.debug("getConnection: connection = "+connection.hashCode()+ connectionProvider.toString());
422
                LOGGER.debug("["+JDBCUtils.getConnId(connection)+"] getConnection "+connectionProvider.getStatus()+" "+ connectionProvider.toString());
374 423
            }
375 424
            return connection;
376 425
        } catch (SQLException ex) {
......
381 430
    @Override
382 431
    public void closeConnection(Connection connection) {
383 432
      if( connection!=null ) { // In test ???
384
        LOGGER.debug("closeConnection: connection = "+connection.hashCode());
433
        LOGGER.debug("["+JDBCUtils.getConnId(connection)+"] closeConnection "+ this.connectionProvider.getStatus());
385 434
      }
386 435
      super.closeConnection(connection);
387 436
    }

Also available in: Unified diff