/** * INTERNAL: * Log exceptions to the default log then throw them. */ private void logAndThrowException(int level, RuntimeException exception) throws RuntimeException { AbstractSessionLog.getLog().logThrowable(level, exception); throw exception; }
/** * PUBLIC: * Return the date format to be used when printing a log entry date. * @return the date format */ public DateFormat getDateFormat() { if (dateFormat == null) { dateFormat = this.buildDefaultDateFormat(); } return dateFormat; }
/** * PUBLIC: * <p> * Set the session. * </p> * * @param session a Session * </p> */ public void setSession(Session session) { if (this.session == null) { this.session = session; buildSessionType(); buildSessionHashCode(); } }
/** * Return the supplement detail information including date, session, thread and connection. */ protected String getSupplementDetailString(SessionLogEntry entry) { StringWriter writer = new StringWriter(); if (shouldPrintDate()) { writer.write(getDateString(entry.getDate())); writer.write("--"); } if (shouldPrintSession() && (entry.getSession() != null)) { writer.write(this.getSessionString(entry.getSession())); writer.write("--"); } if (shouldPrintConnection() && (entry.getConnection() != null)) { writer.write(this.getConnectionString(entry.getConnection())); writer.write("--"); } if (shouldPrintThread()) { writer.write(this.getThreadString(entry.getThread())); writer.write("--"); } return writer.toString(); }
/** * PUBLIC: * <p> * Return the log level. It is used when session is not available. * </p><p> * * @return the log level * </p> */ public int getLevel() { return getLevel(null); }
/** * INTERNAL: * Each session owns its own session log because session is stored in the session log */ public Object clone() { // There is no special treatment required for cloning here // The state of this object is described by member variables sessionLogger and categoryLoggers. // This state depends on session. // If session for the clone is going to be the same as session for this there is no // need to do "deep" cloning. // If not, the session being cloned should call setSession() on its JavaLog object to initialize it correctly. JavaLog cloneLog = (JavaLog)super.clone(); return cloneLog; } }
/** * Return the specified date and/or time information in string. * The format will be determined by the date format settings. */ protected String getDateString(Date date) { return this.getDateFormat().format(date); }
/** * Return the current session including the type and id. */ protected String getSessionString(Session session) { // For bug 3422759 the session to log against should be the one in the // event, not the static one in the SessionLog, for there are many // sessions but only one SessionLog. if (session != null) { return ((AbstractSession)session).getLogSessionString(); } else { return getSessionString(); } }
/** * By default the stack is logged for FINER or less (finest). * The logging of the stack can also be explicitly turned on or off. */ public boolean shouldLogExceptionStackTrace() { if (shouldLogExceptionStackTrace == null) { return getLevel() <= FINER; } else { return shouldLogExceptionStackTrace.booleanValue(); } }
/** * PUBLIC: * Set the session log to which an accessor logs messages and SQL. * If not set, this will default to a session log on a writer on System.out. * To enable logging, log level can not be OFF. * Also set a backpointer to this session in SessionLog. To avoid a sessionLog * being shared by more than one session, it needs to be cloned. * * @see #logMessage(String) */ public void setSessionLog(SessionLog sessionLog) { this.sessionLog = (SessionLog)((AbstractSessionLog)sessionLog).clone(); if (this.sessionLog != null) { this.sessionLog.setSession(this); } }
protected ClassLoader createTempLoader(Collection col, boolean shouldOverrideLoadClassForCollectionMembers) { if (!shouldCreateInternalLoader) { return Thread.currentThread().getContextClassLoader(); } ClassLoader currentLoader = Thread.currentThread().getContextClassLoader(); if (!(currentLoader instanceof URLClassLoader)) { //we can't create a TempEntityLoader so just use the current one //shouldn't be a problem (and should only occur) in JavaSE return currentLoader; } URL[] urlPath = ((URLClassLoader)currentLoader).getURLs(); ClassLoader tempLoader = new TempEntityLoader(urlPath, currentLoader, col, shouldOverrideLoadClassForCollectionMembers); AbstractSessionLog.getLog().log(SessionLog.FINER, "cmp_init_tempLoader_created", tempLoader); AbstractSessionLog.getLog().log(SessionLog.FINER, "cmp_init_shouldOverrideLoadClassForCollectionMembers", new Boolean(shouldOverrideLoadClassForCollectionMembers)); return tempLoader; }
/** * By default the thread is logged for FINE or less (finer,etc.). * The logging of the thread can also be explicitly turned on or off. */ public boolean shouldPrintThread() { if (shouldPrintThread == null) { return getLevel() <= FINE; } else { return shouldPrintThread.booleanValue(); } }
/** * Load the given class name with the given class loader. */ public static Class loadClass(String className, ClassLoader loader, boolean throwExceptionIfNotFound) { Class candidateClass = null; try { candidateClass = loader.loadClass(className); } catch (ClassNotFoundException exc){ if (throwExceptionIfNotFound){ throw PersistenceUnitLoadingException.exceptionLoadingClassWhileLookingForAnnotations(className, exc); } else { AbstractSessionLog.getLog().log(AbstractSessionLog.WARNING, "persistence_unit_processor_error_loading_class", exc.getClass().getName(), exc.getLocalizedMessage() , className); } } catch (Exception exception){ AbstractSessionLog.getLog().log(AbstractSessionLog.WARNING, "persistence_unit_processor_error_loading_class", exception.getClass().getName(), exception.getLocalizedMessage() , className); } return candidateClass; }
/** * INTERNAL: * Create a list of java.lang.Class that contains the classes of all the entities * that we will be deploying */ protected Set loadEntityClasses(Collection entityNames, ClassLoader classLoader) { Set entityClasses = new HashSet(); // Load the classes using the loader passed in AbstractSessionLog.getLog().log(SessionLog.FINER, "cmp_loading_entities_using_loader", classLoader); for (Iterator iter = entityNames.iterator(); iter.hasNext();) { String entityClassName = (String)iter.next(); try { entityClasses.add(classLoader.loadClass(entityClassName)); } catch (ClassNotFoundException cnfEx) { throw ValidationException.entityClassNotFound(entityClassName, classLoader, cnfEx); } } return entityClasses; }
/** * Log an untranslated message to the TopLink log at FINER level. * @param msg message to be logged */ private void logMessage(String msg) { if (m_session == null){ AbstractSessionLog.getLog().log(SessionLog.FINER, msg); } else { m_session.logMessage(msg); } }
/** * Create a list of the entities that will be deployed. This list is built * from the information provided in the PersistenceUnitInfo argument. * The list contains Classes specified in the PersistenceUnitInfo's class * list and also files that are annotated with @Entity and @Embeddable in * the jar files provided in the persistence info. This list of classes will * used by TopLink to build a deployment project and to decide what classes * to weave. */ public static Collection<Class> buildEntityList(MetadataProcessor processor, ClassLoader loader) { ArrayList<Class> entityList = new ArrayList<Class>(); for (String className : processor.getProject().getWeavableClassNames()) { try { Class entityClass = loader.loadClass(className); entityList.add(entityClass); } catch (ClassNotFoundException exc) { AbstractSessionLog.getLog().log(SessionLog.CONFIG, "exception_loading_entity_class", className, exc); } } return entityList; }
private void preProcess() throws URISyntaxException,MalformedURLException{ AbstractSessionLog.getLog().setLevel(this.logLevel); if(logWriter!=null){ ((DefaultSessionLog)AbstractSessionLog.getLog()).setWriter(logWriter); AbstractSessionLog.getLog().log(SessionLog.WARNING, ToStringLocalization.buildMessage("staticweave_processor_unknown_outcome", new Object[]{null}));
/** * INTERNAL: * Get the singleton entityContainer. * @return EnityContainer */ public static synchronized JavaSECMPInitializer getJavaSECMPInitializer() { if (javaSECMPInitializer == null) { javaSECMPInitializer = new JavaSECMPInitializer(); } AbstractSessionLog.getLog().setLevel(JavaSECMPInitializer.getTopLinkLoggingLevel()); return javaSECMPInitializer; }
/** * INTERNAL: * Should be called only by the agent. (when weaving classes) * If succeeded return true, false otherwise. */ protected static void initializeFromAgent(Instrumentation instrumentation) throws Exception { AbstractSessionLog.getLog().setLevel(JavaSECMPInitializer.getTopLinkLoggingLevel()); // Squirrel away the instrumentation for later globalInstrumentation = instrumentation; // Create JavaSECMPInitializer singleton javaSECMPInitializer = new JavaSECMPInitializer(); // Initialize it javaSECMPInitializer.initialize(new HashMap(), javaSECMPInitializer); }