示例#1
0
 protected void executeQuery(Statement stmt, String q) throws SQLException {
   q = q.replace("$PREFIX", getPrefix());
   LOG.info(" Executing " + q);
   ResultSet rs = stmt.executeQuery(q);
   StringBuilder header = new StringBuilder();
   for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
     if (i > 1) {
       header.append("|");
     }
     header.append(rs.getMetaData().getColumnName(i));
   }
   LOG.info(header);
   int seq = 0;
   while (true) {
     boolean valid = rs.next();
     if (!valid) break;
     seq++;
     StringBuilder line = new StringBuilder();
     for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
       if (i > 1) {
         line.append("|");
       }
       line.append(rs.getString(i));
     }
     LOG.info(seq + ":" + line);
   }
 }
示例#2
0
 public void run() {
   Connection con = null;
   Statement stmt = null;
   try {
     DataSource ds = getDataSource();
     con = ds.getConnection();
     if (executeOnlyIf(con, onlyIfQuery)) {
       stmt = con.createStatement();
       if (query != null) {
         executeQuery(stmt, query);
       } else if (update != null) {
         executeUpdate(stmt, update);
       } else {
         throw new IllegalStateException("Both query and update properties are unset");
       }
     } else {
       LOG.debug("Skipped because of " + onlyIfQuery);
     }
   } catch (RuntimeException e) {
     throw e;
   } catch (Throwable t) {
     if (ignore.matcher(t.getMessage()).matches()) {
       LOG.info("Ignoring " + t.getMessage());
     } else {
       throw new RuntimeException(t.getMessage(), t);
     }
   } finally {
     try {
       if (stmt != null) {
         stmt.close();
       }
     } catch (Exception g) {
     }
     try {
       if (con != null) {
         con.close();
       }
     } catch (Exception g) {
     }
   }
 }
  private void initializeDatabaseConnectionConfigurationParameters() {
    String propertyValue;
    Properties systemProperties;

    systemProperties = GlobalProperties.instance().getProperties();

    userAccount = systemProperties.getProperty(DatabaseGlobals.DatabaseConnectionUserAccountKey);
    if (userAccount == null) {
      userAccount = DatabaseGlobals.DatabaseConnectionUserAccountDefault;
    }
    logger.info(DatabaseGlobals.UserAccountValueMsg + userAccount);

    password = systemProperties.getProperty(DatabaseGlobals.DatabaseConnectionPasswordKey);
    if (password == null) {
      password = DatabaseGlobals.DatabaseConnectionPasswordDefault;
    }
    logger.info(DatabaseGlobals.PasswordValueMsg + password);

    databaseName = systemProperties.getProperty(DatabaseGlobals.DatabaseConnectionDatabaseNameKey);
    if (databaseName == null) {
      databaseName = DatabaseGlobals.DatabaseConnectionDatabaseNameDefault;
    }
    logger.info(DatabaseGlobals.DatabaseNameValueMsg + databaseName);

    databaseHost = systemProperties.getProperty(DatabaseGlobals.DatabaseConnectionDatabaseHostKey);
    if (databaseHost == null) {
      databaseHost = DatabaseGlobals.DatabaseConnectionDatabaseHostDefault;
    }
    logger.info(DatabaseGlobals.DatabaseHostValueMsg + databaseHost);

    clientAppName =
        systemProperties.getProperty(DatabaseGlobals.DatabaseConnectionClientAppNameKey);
    if (clientAppName == null) {
      clientAppName = DatabaseGlobals.DatabaseConnectionClientAppNameDefault;
    }
    logger.info(DatabaseGlobals.ClientAppNameValueMsg + clientAppName);

    userMetaData = systemProperties.getProperty(DatabaseGlobals.DatabaseConnectionUserMetaDataKey);
    if (userMetaData == null) {
      userMetaData = DatabaseGlobals.DatabaseConnectionUserMetaDataDefault;
    }
    logger.info(DatabaseGlobals.UserMetaDataValueMsg + userMetaData);

    useRepeatRead =
        systemProperties.getProperty(DatabaseGlobals.DatabaseConnectionUseRepeatReadKey);
    if (useRepeatRead == null) {
      useRepeatRead = DatabaseGlobals.DatabaseConnectionUseRepeatReadDefault;
    }
    logger.info(DatabaseGlobals.UseRepeatReadValueMsg + useRepeatRead);

    charsetConverter =
        systemProperties.getProperty(DatabaseGlobals.DatabaseConnectionCharsetConverterKey);
    if (charsetConverter == null) {
      charsetConverter = DatabaseGlobals.DatabaseConnectionCharsetConverterDefault;
    }
    logger.info(DatabaseGlobals.CharsetConverterValueMsg + charsetConverter);

    connectionPoolDescription =
        systemProperties.getProperty(
            DatabaseGlobals.DatabaseConnectionConnectionPoolDescriptionKey);
    if (connectionPoolDescription == null) {
      connectionPoolDescription =
          DatabaseGlobals.DatabaseConnectionConnectionPoolDescriptionDefault;
    }
    logger.info(DatabaseGlobals.ConnectionPoolDescriptionValueMsg + connectionPoolDescription);

    propertyValue =
        systemProperties.getProperty(DatabaseGlobals.DatabaseConnectionConnectionPortKey);
    if (propertyValue == null) {
      connectionPort = DatabaseGlobals.DatabaseConnectionConnectionPortDefault;
      logger.info("Using default connectionPort value: " + connectionPort);
    } else {
      try {
        connectionPort = Integer.parseInt(propertyValue);
        logger.info("Using connectionPort value: " + connectionPort);
      } catch (NumberFormatException e) {
        connectionPort = DatabaseGlobals.DatabaseConnectionConnectionPortDefault;
        logger.info(
            "Error converting property value.  Using default connectionPort value: "
                + connectionPort);
      }
    }

    propertyValue =
        systemProperties.getProperty(DatabaseGlobals.DatabaseConnectionConnectionPoolSizeKey);
    if (propertyValue == null) {
      connectionPoolSize = DatabaseGlobals.DatabaseConnectionConnectionPoolSizeDefault;
      logger.info("Using default connectionPoolSize value: " + connectionPoolSize);
    } else {
      try {
        connectionPoolSize = Integer.parseInt(propertyValue);
        logger.info("Using connectionPoolSize value: " + connectionPoolSize);
      } catch (NumberFormatException e) {
        connectionPoolSize = DatabaseGlobals.DatabaseConnectionConnectionPoolSizeDefault;
        logger.info(
            "Error converting property value.  Using default connectionPoolSize value: "
                + connectionPoolSize);
      }
    }
  }
示例#4
0
 protected void executeUpdate(Statement stmt, String u) throws SQLException {
   u = u.replace("$PREFIX", getPrefix());
   LOG.info(" Executing update " + u);
   int result = stmt.executeUpdate(u);
   LOG.service("Result :" + result);
 }