/**
   * Returns all the properties associated with this <code>ConnectionPoolDataSource</code>.
   *
   * @return Reference Object containing all the Type 4 property references.
   * @throws NamingException
   */
  public Reference getReference() throws NamingException {
    if (t4Logger_ != null && t4Logger_.isLoggable(Level.FINE) == true) {
      Object p[] = T4LoggingUtilities.makeParams(null);
      t4Logger_.logp(Level.FINE, "HPT4ConnectionPoolDataSource", "getReference", "", p);
    }
    try {
      if (getLogWriter() != null) {
        LogRecord lr = new LogRecord(Level.FINE, "");
        Object p[] = T4LoggingUtilities.makeParams(null);
        lr.setParameters(p);
        lr.setSourceClassName("HPT4ConnectionPoolDataSource");
        lr.setSourceMethodName("getReference");
        T4LogFormatter lf = new T4LogFormatter();
        String temp = lf.format(lr);
        getLogWriter().println(temp);
      }
    } catch (SQLException se) {
      // ignore
    }

    Reference ref =
        new Reference(
            this.getClass().getName(),
            "org.trafodion.jdbc.t4.HPT4ConnectionPoolDataSourceFactory",
            null);
    ref = addReferences(ref);
    ref.add(new StringRefAddr("propertyCycle", Integer.toString(propertyCycle_)));
    return ref;
  }
  // Private method to infer the caller's class and method names
  private void inferCaller() {
    needToInferCaller = false;
    // Android-changed: Use VMStack.getThreadStackTrace.
    StackTraceElement[] stack = VMStack.getThreadStackTrace(Thread.currentThread());
    int depth = stack.length;

    boolean lookingForLogger = true;
    for (int ix = 0; ix < depth; ix++) {
      // Calling getStackTraceElement directly prevents the VM
      // from paying the cost of building the entire stack frame.
      //
      // Android-changed: Use value from getThreadStackTrace.
      StackTraceElement frame = stack[ix];
      String cname = frame.getClassName();
      boolean isLoggerImpl = isLoggerImplFrame(cname);
      if (lookingForLogger) {
        // Skip all frames until we have found the first logger frame.
        if (isLoggerImpl) {
          lookingForLogger = false;
        }
      } else {
        if (!isLoggerImpl) {
          // skip reflection call
          if (!cname.startsWith("java.lang.reflect.") && !cname.startsWith("sun.reflect.")) {
            // We've found the relevant frame.
            setSourceClassName(cname);
            setSourceMethodName(frame.getMethodName());
            return;
          }
        }
      }
    }
    // We haven't found a suitable frame, so just punt.  This is
    // OK as we are only committed to making a "best effort" here.
  }
예제 #3
0
  /** Infer a caller, ignoring logging-related classes. */
  private final void inferCallerELKI() {
    needToInferCaller = false;
    StackTraceElement stack[] = (new Throwable()).getStackTrace();
    int ix = 0;
    // skip back to the logger.
    while (ix < stack.length) {
      StackTraceElement frame = stack[ix];
      final String cls = frame.getClassName();
      if (cls.equals(START_TRACE_AT)) {
        break;
      }
      ix++;
    }
    // skip further back through helper functions
    while (ix < stack.length) {
      StackTraceElement frame = stack[ix];
      final String cls = frame.getClassName();

      boolean ignore = false;
      for (int i = 0; i < IGNORE_CLASSES.length; i++) {
        if (cls.equals(IGNORE_CLASSES[i])) {
          ignore = true;
          break;
        }
      }
      if (!ignore) {
        super.setSourceClassName(frame.getClassName());
        super.setSourceMethodName(frame.getMethodName());
        break;
      }
      ix++;
    }
  }
예제 #4
0
 /**
  * Logs a debug message for {@link #getServiceProvider} method. Note: we are not required to
  * insert the method name ({@code "GetServiceProvider"}) in the message because it is part of the
  * informations already stored by {@link LogRecord}, and formatted by the default {@link
  * java.util.logging.SimpleFormatter}.
  *
  * @param status {@code "ENTRY"}, {@code "RETURN"} or {@code "THROW"}, according {@link Logger}
  *     conventions.
  * @param category The category given to the {@link #getServiceProvider} method.
  * @param key The key being examined, or {@code null}.
  * @param message Optional message, or {@code null} if none.
  * @param type Optional class to format after the message, or {@code null}.
  */
 private static void debug(
     final String status,
     final Class<?> category,
     final Hints.Key key,
     final String message,
     final Class type) {
   final StringBuilder buffer = new StringBuilder(status);
   buffer
       .append(Utilities.spaces(Math.max(1, 7 - status.length())))
       .append('(')
       .append(Classes.getShortName(category));
   if (key != null) {
     buffer.append(", ").append(key);
   }
   buffer.append(')');
   if (message != null) {
     buffer.append(": ").append(message);
   }
   if (type != null) {
     buffer.append(' ').append(Classes.getShortName(type)).append('.');
   }
   final LogRecord record = new LogRecord(DEBUG_LEVEL, buffer.toString());
   record.setSourceClassName(FactoryRegistry.class.getName());
   record.setSourceMethodName("getServiceProvider");
   record.setLoggerName(LOGGER.getName());
   LOGGER.log(record);
 }
 /**
  * Creates a pooled connection object with the properties specified.
  *
  * @param props properties for the Type 4 connection
  * @see #HPT4ConnectionPoolDataSource()
  * @link T4Properties
  */
 public HPT4ConnectionPoolDataSource(Properties props) {
   super(props);
   if (getT4LogLevel() != Level.OFF) setupLogFileHandler();
   if (t4Logger_.isLoggable(Level.FINE) == true) {
     Object p[] = T4LoggingUtilities.makeParams(null, props);
     t4Logger_.logp(
         Level.FINE,
         "HPT4ConnectionPoolDataSource",
         "HPT4ConnectionPoolDataSource",
         "Note, super called before this.",
         p);
   }
   try {
     if (getLogWriter() != null) {
       LogRecord lr = new LogRecord(Level.FINE, "");
       Object p[] = T4LoggingUtilities.makeParams(null, props);
       lr.setParameters(p);
       lr.setSourceClassName("HPT4ConnectionPoolDataSource");
       lr.setSourceMethodName("");
       T4LogFormatter lf = new T4LogFormatter();
       String temp = lf.format(lr);
       getLogWriter().println(temp);
     }
   } catch (SQLException se) {
     // ignore
   }
 }
예제 #6
0
 /** Log the specified message after all provider for a given category have been registered. */
 private static void log(final String method, final StringBuilder message) {
   final LogRecord record = new LogRecord(Level.CONFIG, message.toString());
   record.setSourceClassName(FactoryRegistry.class.getName());
   record.setSourceMethodName(method);
   record.setLoggerName(LOGGER.getName());
   LOGGER.log(record);
 }
예제 #7
0
 /**
  * Log the message at the specified level with the specified exception if any.
  *
  * @param level The level to log at.
  * @param message The message to log.
  * @param e The exception, if any.
  */
 private void log(Level level, String message, Exception e) {
   // millis and thread are filled by the constructor
   LogRecord record = new LogRecord(level, message);
   record.setLoggerName(logger.getName());
   record.setThrown(e);
   record.setSourceClassName(logger.getName());
   record.setSourceMethodName(getMethodName());
   logger.log(record);
 }
예제 #8
0
파일: Logger.java 프로젝트: OPSF/uClinux
  public void logp(
      Level level, String sourceClass, String sourceMethod, String message, Throwable thrown) {
    synchronized (lock) {
      LogRecord rec = new LogRecord(level, message);

      rec.setResourceBundle(resourceBundle);
      rec.setSourceClassName(sourceClass);
      rec.setSourceMethodName(sourceMethod);
      rec.setThrown(thrown);

      log(rec);
    }
  }
예제 #9
0
파일: Logger.java 프로젝트: OPSF/uClinux
  private void logImpl(
      Level level, String sourceClass, String sourceMethod, String message, Object[] params) {
    synchronized (lock) {
      LogRecord rec = new LogRecord(level, message);

      rec.setResourceBundle(findResourceBundle());
      rec.setSourceClassName(sourceClass);
      rec.setSourceMethodName(sourceMethod);
      rec.setParameters(params);

      log(rec);
    }
  }
예제 #10
0
  public static void main(String[] args) {
    for (int i = 1; i <= 5; i++) {
      LogRecord logRecord = new LogRecord(Level.SEVERE, "This is a severe message #" + i + "!");

      logRecord.setLoggerName("test app");
      logRecord.setMillis(System.currentTimeMillis());
      logRecord.setParameters(new Object[] {Thread.currentThread().getName()});
      logRecord.setSourceClassName(HTMLFormatter.class.getName());
      logRecord.setSourceMethodName("SourceMethodName");

      System.out.print(new HTMLFormatter().format(logRecord));

      logRecord = new LogRecord(Level.WARNING, "This is a warning message #" + i + "!");

      logRecord.setLoggerName("test app");
      logRecord.setMillis(System.currentTimeMillis());
      logRecord.setParameters(new Object[] {Thread.currentThread().getName()});
      logRecord.setSourceClassName(HTMLFormatter.class.getName());
      logRecord.setSourceMethodName("SourceMethodName");

      System.out.print(new HTMLFormatter().format(logRecord));
    }
  }
예제 #11
0
 protected void logp(
     Object clazz, String methodName, Throwable t, Level level, String msg, Object[] objs) {
   LogRecord lr = createLogRecord(level, msg);
   if (t != null) {
     lr.setThrown(t);
   }
   if (clazz != null) {
     lr.setSourceClassName(toClassName(clazz));
   }
   if (methodName != null) {
     lr.setSourceMethodName(methodName);
   }
   if (objs != null) {
     // serializeCheck(objs);
     lr.setParameters(objs);
   }
   getLogger().log(lr);
 }
예제 #12
0
파일: Logger.java 프로젝트: OPSF/uClinux
  public void logrb(
      Level level,
      String sourceClass,
      String sourceMethod,
      String bundleName,
      String message,
      Object[] params) {
    synchronized (lock) {
      LogRecord rec = new LogRecord(level, message);

      rec.setResourceBundleName(bundleName);
      rec.setSourceClassName(sourceClass);
      rec.setSourceMethodName(sourceMethod);
      rec.setParameters(params);

      log(rec);
    }
  }
예제 #13
0
 /** Invoked when a factory can't be loaded. Log a warning, but do not stop the process. */
 private static void loadingFailure(
     final Class<?> category, final Throwable error, final boolean showStackTrace) {
   final String name = Classes.getShortName(category);
   final StringBuilder cause = new StringBuilder(Classes.getShortClassName(error));
   final String message = error.getLocalizedMessage();
   if (message != null) {
     cause.append(": ");
     cause.append(message);
   }
   final LogRecord record =
       Loggings.format(Level.WARNING, LoggingKeys.CANT_LOAD_SERVICE_$2, name, cause.toString());
   if (showStackTrace) {
     record.setThrown(error);
   }
   record.setSourceClassName(FactoryRegistry.class.getName());
   record.setSourceMethodName("scanForPlugins");
   record.setLoggerName(LOGGER.getName());
   LOGGER.log(record);
 }
 /**
  * Returns {@code true} if this factory is available. The default implementation returns {@code
  * false} if no backing store were setup and {@link DeferredAuthorityFactory#createBackingStore}
  * throws an exception.
  */
 @Override
 synchronized boolean isAvailable() {
   try {
     return getBackingStore().isAvailable();
   } catch (FactoryNotFoundException exception) {
     /*
      * The factory is not available. This is error may be normal; it happens
      * for example if no gt2-epsg-hsql.jar (or similar JAR) are found in the
      * classpath, which is the case for example in GeoServer 1.3. Do not log
      * any stack trace,  since stack traces suggest more serious errors than
      * what we really have here.
      */
   } catch (FactoryException exception) {
     /*
      * The factory creation failed for an other reason, which may be more
      * serious. Now it is time to log a warning with a stack trace.
      */
     final Citation citation = getAuthority();
     final Collection titles = citation.getAlternateTitles();
     InternationalString title = citation.getTitle();
     if (titles != null) {
       for (final Iterator it = titles.iterator(); it.hasNext(); ) {
         /*
          * Uses the longuest title instead of the main one. In Geotools
          * implementation, the alternate title may contains usefull informations
          * like the EPSG database version number and the database engine.
          */
         final InternationalString candidate = (InternationalString) it.next();
         if (candidate.length() > title.length()) {
           title = candidate;
         }
       }
     }
     final LogRecord record =
         Loggings.format(Level.WARNING, LoggingKeys.UNAVAILABLE_AUTHORITY_FACTORY_$1, title);
     record.setSourceClassName(getClass().getName());
     record.setSourceMethodName("isAvailable");
     record.setThrown(exception);
     record.setLoggerName(LOGGER.getName());
     LOGGER.log(record);
   }
   return false;
 }
 /**
  * Returns the Property cycle property. This property is not supprted by the Type 4 driver. This
  * property is ignored by the Type 4 driver.
  *
  * @return propertyCycle
  */
 public int getPropertyCycle() {
   if (t4Logger_.isLoggable(Level.FINE) == true) {
     Object p[] = T4LoggingUtilities.makeParams(null);
     t4Logger_.logp(Level.FINE, "HPT4ConnectionPoolDataSource", "getPropertyCycle", "", p);
   }
   try {
     if (getLogWriter() != null) {
       LogRecord lr = new LogRecord(Level.FINE, "");
       Object p[] = T4LoggingUtilities.makeParams(null);
       lr.setParameters(p);
       lr.setSourceClassName("HPT4ConnectionPoolDataSource");
       lr.setSourceMethodName("getPropertyCycle");
       T4LogFormatter lf = new T4LogFormatter();
       String temp = lf.format(lr);
       getLogWriter().println(temp);
     }
   } catch (SQLException se) {
     // ignore
   }
   return propertyCycle_;
 }
  /**
   * Attempts to establish a physical database connection that can be used as a pooled connection.
   *
   * @param username Safeguard user name.
   * @param password Safeguard user password.
   * @return A <code>PooledConnection</code> object that is a physical connection to the NDCS server
   *     that this <code>HPT4ConnectionPoolDataSource</code> object represents.
   * @throws SQLException If any NDCS error occurs.
   */
  public PooledConnection getPooledConnection(String username, String password)
      throws SQLException {
    if (t4Logger_.isLoggable(Level.FINE) == true) {
      Object p[] = T4LoggingUtilities.makeParams(null, username);
      t4Logger_.logp(Level.FINE, "HPT4ConnectionPoolDataSource", "getPooledConnection", "", p);
    }
    if (getLogWriter() != null) {
      LogRecord lr = new LogRecord(Level.FINE, "");
      Object p[] = T4LoggingUtilities.makeParams(null, username);
      lr.setParameters(p);
      lr.setSourceClassName("HPT4ConnectionPoolDataSource");
      lr.setSourceMethodName("getPooledConnection");
      T4LogFormatter lf = new T4LogFormatter();
      String temp = lf.format(lr);
      getLogWriter().println(temp);
    }
    HPT4PooledConnection connect;

    setUser(username);
    setPassword(password);
    return getPooledConnection();
  }
  /**
   * Attempts to establish a physical database connection that can be used as a pooled connection.
   *
   * @return A <code>PooledConnection</code> object that is a physical connection to the NDCS server
   *     that this <code>HPT4ConnectionPoolDataSource</code> object represents.
   * @throws SQLException If any NDCS error occurs.
   */
  public PooledConnection getPooledConnection() throws SQLException {
    if (t4Logger_.isLoggable(Level.FINE) == true) {
      Object p[] = T4LoggingUtilities.makeParams(null);
      t4Logger_.logp(Level.FINE, "HPT4ConnectionPoolDataSource", "getPooledConnection", "", p);
    }
    if (getLogWriter() != null) {
      LogRecord lr = new LogRecord(Level.FINE, "");
      Object p[] = T4LoggingUtilities.makeParams(null);
      lr.setParameters(p);
      lr.setSourceClassName("HPT4ConnectionPoolDataSource");
      lr.setSourceMethodName("getPooledConnection");
      T4LogFormatter lf = new T4LogFormatter();
      String temp = lf.format(lr);
      getLogWriter().println(temp);
    }
    HPT4PooledConnection connect;

    Properties l_props = super.getProperties();
    T4Properties l_t4props = new T4Properties(l_props);
    connect = new HPT4PooledConnection(this, l_t4props);

    return connect;
  }
예제 #18
0
 /*
  * use our inferCaller implementation.
  */
 @Override
 public void setSourceClassName(String sourceClassName) {
   super.setSourceClassName(sourceClassName);
   needToInferCaller = false;
 }
예제 #19
0
 /**
  * Implementation of {@link #unexpectedException(Logger, Class, String, Throwable)}.
  *
  * @param logger Where to log the error, or {@code null}.
  * @param classe The fully qualified class name where the error occurred, or {@code null}.
  * @param method The method where the error occurred, or {@code null}.
  * @param error The error.
  * @param level The logging level.
  * @return {@code true} if the error has been logged, or {@code false} if the logger doesn't log
  *     anything at the specified level.
  */
 private static boolean unexpectedException(
     Logger logger, String classe, String method, final Throwable error, final Level level) {
   /*
    * Checks if loggable, inferring the logger from the classe name if needed.
    */
   if (error == null) {
     return false;
   }
   if (logger == null && classe != null) {
     final int separator = classe.lastIndexOf('.');
     final String paquet = (separator >= 1) ? classe.substring(0, separator - 1) : "";
     logger = getLogger(paquet);
   }
   if (logger != null && !logger.isLoggable(level)) {
     return false;
   }
   /*
    * Loggeable, so complete the null argument from the stack trace if we can.
    */
   if (logger == null || classe == null || method == null) {
     String paquet = (logger != null) ? logger.getName() : null;
     final StackTraceElement[] elements = error.getStackTrace();
     for (int i = 0; i < elements.length; i++) {
       /*
        * Searchs for the first stack trace element with a classname matching the
        * expected one. We compare preferably against the name of the class given
        * in argument, or against the logger name (taken as the package name) otherwise.
        */
       final StackTraceElement element = elements[i];
       final String classname = element.getClassName();
       if (classe != null) {
         if (!classname.equals(classe)) {
           continue;
         }
       } else if (paquet != null) {
         if (!classname.startsWith(paquet)) {
           continue;
         }
         final int length = paquet.length();
         if (classname.length() > length) {
           // We expect '.' but we accept also '$' or end of string.
           final char separator = classname.charAt(length);
           if (Character.isJavaIdentifierPart(separator)) {
             continue;
           }
         }
       }
       /*
        * Now that we have a stack trace element from the expected class (or any
        * element if we don't know the class), make sure that we have the right method.
        */
       final String methodName = element.getMethodName();
       if (method != null && !methodName.equals(method)) {
         continue;
       }
       /*
        * Now computes every values that are null, and stop the loop.
        */
       if (paquet == null) {
         final int separator = classname.lastIndexOf('.');
         paquet = (separator >= 1) ? classname.substring(0, separator - 1) : "";
         logger = getLogger(paquet);
         if (!logger.isLoggable(level)) {
           return false;
         }
       }
       if (classe == null) {
         classe = classname;
       }
       if (method == null) {
         method = methodName;
       }
       break;
     }
     /*
      * The logger may stay null if we have been unable to find a suitable
      * stack trace. Fallback on the global logger.
      *
      * TODO: Use GLOBAL_LOGGER_NAME constant when we will be allowed to target Java 6.
      */
     if (logger == null) {
       logger = getLogger("global");
       if (!logger.isLoggable(level)) {
         return false;
       }
     }
   }
   /*
    * Now prepare the log message. If we have been unable to figure out a source class and
    * method name, we will fallback on Java logging default mechanism, which may returns a
    * less relevant name than our attempt to use the logger name as the package name.
    */
   final StringBuilder buffer = new StringBuilder(Classes.getShortClassName(error));
   final String message = error.getLocalizedMessage();
   if (message != null) {
     buffer.append(": ").append(message);
   }
   final LogRecord record = new LogRecord(level, buffer.toString());
   if (classe != null) {
     record.setSourceClassName(classe);
   }
   if (method != null) {
     record.setSourceMethodName(method);
   }
   if (level.intValue() > 500) {
     record.setThrown(error);
   }
   record.setLoggerName(logger.getName());
   logger.log(record);
   return true;
 }