activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuconic <...@git.apache.org>
Subject [GitHub] activemq-artemis pull request #550: Jdbc refactor post
Date Wed, 01 Jun 2016 21:56:40 GMT
Github user clebertsuconic commented on a diff in the pull request:

    https://github.com/apache/activemq-artemis/pull/550#discussion_r65450589
  
    --- Diff: artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/AbstractJDBCDriver.java
---
    @@ -0,0 +1,129 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements. See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License. You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.activemq.artemis.jdbc.store.drivers;
    +
    +import java.sql.Connection;
    +import java.sql.Driver;
    +import java.sql.SQLException;
    +import java.sql.Statement;
    +import java.util.Properties;
    +
    +import org.apache.activemq.artemis.jdbc.store.JDBCUtils;
    +import org.apache.activemq.artemis.jdbc.store.sql.SQLProvider;
    +import org.apache.activemq.artemis.journal.ActiveMQJournalLogger;
    +
    +/**
    + * Class to hold common database functionality such as drivers and connections
    + */
    +public abstract class AbstractJDBCDriver {
    +
    +   protected Connection connection;
    +
    +   protected SQLProvider sqlProvider;
    +
    +   protected String jdbcConnectionUrl;
    +
    +   protected String jdbcDriverClass;
    +
    +   protected Driver dbDriver;
    +
    +   public AbstractJDBCDriver() {
    +   }
    +
    +   public AbstractJDBCDriver(String tableName, String jdbcConnectionUrl, String jdbcDriverClass)
{
    +      this.jdbcConnectionUrl = jdbcConnectionUrl;
    +      this.jdbcDriverClass = jdbcDriverClass;
    +      this.sqlProvider = JDBCUtils.getSQLProvider(jdbcDriverClass, tableName);
    +   }
    +
    +   public void start() throws Exception {
    +      connect();
    +      createSchema();
    +      prepareStatements();
    +   }
    +
    +   public void stop() throws SQLException {
    +      if (sqlProvider.closeConnectionOnShutdown()) {
    +         connection.close();
    +      }
    +   }
    +
    +   protected abstract void prepareStatements() throws SQLException;
    +
    +   protected abstract void createSchema() throws SQLException;
    +
    +   protected void createTable(String schemaSql) throws SQLException {
    +      JDBCUtils.createTableIfNotExists(connection, sqlProvider.getTableName(), schemaSql);
    +   }
    +
    +   protected void connect() throws Exception {
    +      try {
    +         dbDriver = JDBCUtils.getDriver(jdbcDriverClass);
    +         connection = dbDriver.connect(jdbcConnectionUrl, new Properties());
    +      }
    +      catch (SQLException e) {
    +         ActiveMQJournalLogger.LOGGER.error("Unable to connect to database using URL:
" + jdbcConnectionUrl);
    --- End diff --
    
    @mtaylor this should be using the Loggers with messages.
    Any chance you can send another PR for these kind of things?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message