Пример #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 static void logm(String t, int lvl, String msg, Object o) {
   // System.out.println("LOG:" + t + ":" + lvl + ":" + msg + ":" + (o != null ? ser_json(o) :
   // ""));
   if (lvl <= LogLvlMax) {
     logger.info(t + ":" + lvl + ":" + msg + ":" + (o != null ? ser_json(o) : ""));
   }
 }
Пример #3
0
 /**
  * 检验LineName 是否存在
  *
  * @param name String
  * @return boolean
  */
 public boolean validateLineName(String name, String type, String region) {
   String sql =
       "select count(lineid) i from lineinfo where linename='"
           + name
           + "' and regionid='"
           + region
           + "'";
   ResultSet rs = null;
   try {
     QueryUtil query = new QueryUtil();
     logger.info("validateLineName() sql :" + sql);
     rs = query.executeQuery(sql);
     rs.next();
     int i = rs.getInt("i");
     logger.info("i=" + i);
     if ("edit".equals(type)) {
       if (i < 1) {
         rs.close();
         return true;
       } else {
         rs.close();
         return false;
       }
     } else {
       if (i == 0) {
         rs.close();
         return true;
       } else {
         rs.close();
         return false;
       }
     }
   } catch (Exception ex) {
     logger.error("检查线路是否重名时出错: " + ex.getMessage());
     return false;
   }
 }
Пример #4
0
 public List getLine(String sql) {
   QueryUtil query = null;
   BasicDynaBean dynaBean = null;
   // Vector resultVct = new Vector();
   ArrayList lableList = new ArrayList();
   logger.info("SQL :" + sql);
   try {
     query = new QueryUtil();
     Iterator it = query.queryBeans(sql).iterator();
     while (it.hasNext()) {
       dynaBean = (BasicDynaBean) it.next();
       // logger.info("lavel :"+dynaBean.get("linename")+"  value :"+dynaBean.get("lineid"));
       lableList.add(
           new LabelValueBean(
               (String) (dynaBean.get("linename")), (String) (dynaBean.get("lineid"))));
     }
     // resultVct.add(lableList);
     logger.info(lableList);
     return lableList;
   } catch (Exception ex) {
     logger.error("加载线路时出错:" + ex.getMessage());
     return null;
   }
 }
Пример #5
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);
      }
    }
  }
Пример #7
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);
 }