Search in sources :

Example 1 with HeaderPrintWriter

use of org.apache.derby.shared.common.stream.HeaderPrintWriter in project derby by apache.

the class Util method logError.

private static void logError(String errorMessage, Throwable t) {
    HeaderPrintWriter errorStream = Monitor.getStream();
    if (errorStream == null) {
        t.printStackTrace();
        return;
    }
    ErrorStringBuilder errorStringBuilder = new ErrorStringBuilder(errorStream.getHeader());
    errorStringBuilder.append(errorMessage);
    errorStringBuilder.stackTrace(t);
    errorStream.print(errorStringBuilder.get().toString());
    errorStream.flush();
    errorStringBuilder.reset();
}
Also used : ErrorStringBuilder(org.apache.derby.shared.common.error.ErrorStringBuilder) HeaderPrintWriter(org.apache.derby.shared.common.stream.HeaderPrintWriter)

Example 2 with HeaderPrintWriter

use of org.apache.derby.shared.common.stream.HeaderPrintWriter in project derby by apache.

the class SingleStream method makeStyleHPW.

private HeaderPrintWriter makeStyleHPW(String style, PrintWriterGetHeader header) {
    HeaderPrintWriter res = null;
    if ("rollingFile".equals(style)) {
        String className = "org.apache.derby.impl.services.stream.RollingFileStreamProvider.getOutputStream";
        res = makeMethodHPW(className, header, true);
    } else {
        try {
            IllegalArgumentException ex = new IllegalArgumentException("unknown derby.stream.error.style: " + style);
            throw ex;
        } catch (IllegalArgumentException t) {
            res = useDefaultStream(header, t);
        } catch (Exception t) {
            res = useDefaultStream(header, t);
        }
    }
    return res;
}
Also used : HeaderPrintWriter(org.apache.derby.shared.common.stream.HeaderPrintWriter) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with HeaderPrintWriter

use of org.apache.derby.shared.common.stream.HeaderPrintWriter in project derby by apache.

the class SingleStream method makeFieldHPW.

private HeaderPrintWriter makeFieldHPW(String fieldAccess, PrintWriterGetHeader header) {
    int lastDot = fieldAccess.lastIndexOf('.');
    String className = fieldAccess.substring(0, lastDot);
    String fieldName = fieldAccess.substring(lastDot + 1, fieldAccess.length());
    Throwable t;
    try {
        Class theClass = Class.forName(className);
        try {
            Field theField = theClass.getField(fieldName);
            if (!Modifier.isStatic(theField.getModifiers())) {
                HeaderPrintWriter hpw = useDefaultStream(header);
                hpw.printlnWithHeader(theField.toString() + " is not static");
                return hpw;
            }
            try {
                return makeValueHPW(theField, theField.get((Object) null), header, fieldAccess, false);
            } catch (IllegalAccessException iae) {
                t = iae;
            } catch (IllegalArgumentException iarge) {
                t = iarge;
            }
        } catch (NoSuchFieldException nsfe) {
            t = nsfe;
        }
    } catch (ClassNotFoundException cnfe) {
        t = cnfe;
    } catch (SecurityException se) {
        t = se;
    }
    return useDefaultStream(header, t);
/*
			If we decide it is a bad idea to use reflect and need
			an alternate implementation, we can hard-wire those
			fields that we desire to give configurations access to,
			like so:

		if ("java.lang.System.out".equals(fieldAccess))
		 	os = System.out;
		else if ("java.lang.System.err".equals(fieldAccess))
		 	os = System.err;
		*/
}
Also used : Field(java.lang.reflect.Field) HeaderPrintWriter(org.apache.derby.shared.common.stream.HeaderPrintWriter)

Example 4 with HeaderPrintWriter

use of org.apache.derby.shared.common.stream.HeaderPrintWriter in project derby by apache.

the class SingleStream method useDefaultStream.

private HeaderPrintWriter useDefaultStream(PrintWriterGetHeader header, Throwable t) {
    HeaderPrintWriter hpw = useDefaultStream(header);
    while (t != null) {
        Throwable causedBy = t.getCause();
        String causedByStr = MessageService.getTextMessage(MessageId.CAUSED_BY);
        hpw.printlnWithHeader(t.toString() + (causedBy != null ? " " + causedByStr : ""));
        t = causedBy;
    }
    return hpw;
}
Also used : HeaderPrintWriter(org.apache.derby.shared.common.stream.HeaderPrintWriter)

Example 5 with HeaderPrintWriter

use of org.apache.derby.shared.common.stream.HeaderPrintWriter in project derby by apache.

the class SingleStream method makeStream.

// 
// class interface
// 
/**
 *		Make the stream; note that service properties override
 *		application and system properties.
 */
private HeaderPrintWriter makeStream() {
    // get the header
    PrintWriterGetHeader header = makeHeader();
    HeaderPrintWriter hpw = makeHPW(header);
    // so use/create the default stream.
    if (hpw == null)
        hpw = createDefaultStream(header);
    return hpw;
}
Also used : HeaderPrintWriter(org.apache.derby.shared.common.stream.HeaderPrintWriter) PrintWriterGetHeader(org.apache.derby.shared.common.stream.PrintWriterGetHeader)

Aggregations

HeaderPrintWriter (org.apache.derby.shared.common.stream.HeaderPrintWriter)10 IOException (java.io.IOException)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 PrivilegedActionException (java.security.PrivilegedActionException)2 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1 IndexStatisticsDaemon (org.apache.derby.iapi.services.daemon.IndexStatisticsDaemon)1 GeneratedClass (org.apache.derby.iapi.services.loader.GeneratedClass)1 CompilerContext (org.apache.derby.iapi.sql.compile.CompilerContext)1 Parser (org.apache.derby.iapi.sql.compile.Parser)1 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)1 StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)1 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)1 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)1 StatementNode (org.apache.derby.impl.sql.compile.StatementNode)1