Example usage for org.apache.commons.lang SystemUtils LINE_SEPARATOR

List of usage examples for org.apache.commons.lang SystemUtils LINE_SEPARATOR

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils LINE_SEPARATOR.

Prototype

String LINE_SEPARATOR

To view the source code for org.apache.commons.lang SystemUtils LINE_SEPARATOR.

Click Source Link

Document

The line.separator System Property.

Usage

From source file:org.apache.ojb.broker.util.logging.LoggingConfiguration.java

protected void load() {
    Logger bootLogger = LoggerFactory.getBootLogger();

    // first we check whether the system property
    //   org.apache.ojb.broker.util.logging.Logger
    // is set (or its alias LoggerClass which is deprecated)
    ClassLoader contextLoader = ClassHelper.getClassLoader();
    String loggerClassName;//from  w w w. j  a  v a2  s.c  o m

    _loggerClass = null;
    properties = new Properties();
    loggerClassName = getLoggerClass(System.getProperties());
    _loggerConfigFile = getLoggerConfigFile(System.getProperties());

    InputStream ojbLogPropFile;
    if (loggerClassName == null) {
        // now we're trying to load the OJB-logging.properties file
        String ojbLogPropFilePath = System.getProperty(OJB_LOGGING_PROPERTIES_FILE,
                OJB_LOGGING_PROPERTIES_FILE);
        try {
            URL ojbLoggingURL = ClassHelper.getResource(ojbLogPropFilePath);
            if (ojbLoggingURL == null) {
                ojbLoggingURL = (new File(ojbLogPropFilePath)).toURL();
            }
            ojbLogPropFile = ojbLoggingURL.openStream();
            try {
                bootLogger.info("Found logging properties file: " + ojbLogPropFilePath);
                properties.load(ojbLogPropFile);
                _loggerConfigFile = getLoggerConfigFile(properties);
                loggerClassName = getLoggerClass(properties);
            } finally {
                ojbLogPropFile.close();
            }
        } catch (Exception ex) {
            if (loggerClassName == null) {
                bootLogger.warn("Can't read logging properties file using path '" + ojbLogPropFilePath
                        + "', message is: " + SystemUtils.LINE_SEPARATOR + ex.getMessage()
                        + SystemUtils.LINE_SEPARATOR
                        + "Will try to load logging properties from OJB.properties file");
            } else {
                bootLogger.info("Problems while closing resources for path '" + ojbLogPropFilePath
                        + "', message is: " + SystemUtils.LINE_SEPARATOR + ex.getMessage(), ex);
            }
        }
    }
    if (loggerClassName == null) {
        // deprecated: load the OJB.properties file
        // this is not good because we have all OJB properties in this config
        String ojbPropFile = System.getProperty("OJB.properties", "OJB.properties");

        try {
            ojbLogPropFile = contextLoader.getResourceAsStream(ojbPropFile);
            if (ojbLogPropFile != null) {
                try {
                    properties.load(ojbLogPropFile);
                    loggerClassName = getLoggerClass(properties);
                    _loggerConfigFile = getLoggerConfigFile(properties);
                    if (loggerClassName != null) {
                        // deprecation warning for after 1.0
                        bootLogger.warn("Please use a separate '" + OJB_LOGGING_PROPERTIES_FILE
                                + "' file to specify your logging settings");
                    }
                } finally {
                    ojbLogPropFile.close();
                }
            }
        } catch (Exception ex) {
        }
    }
    if (loggerClassName != null) {
        try {
            _loggerClass = ClassHelper.getClass(loggerClassName);
            bootLogger.info("Logging: Found logger class '" + loggerClassName);
        } catch (ClassNotFoundException ex) {
            _loggerClass = PoorMansLoggerImpl.class;
            bootLogger.warn("Could not load logger class " + loggerClassName + ", defaulting to "
                    + _loggerClass.getName(), ex);
        }
    } else {
        // still no logger configured - lets check whether commons-logging is configured
        if ((System.getProperty(PROPERTY_COMMONS_LOGGING_LOG) != null)
                || (System.getProperty(PROPERTY_COMMONS_LOGGING_LOGFACTORY) != null)) {
            // yep, so use commons-logging
            _loggerClass = CommonsLoggerImpl.class;
            bootLogger.info("Logging: Found commons logging properties, use " + _loggerClass);
        } else {
            // but perhaps there is a log4j.properties file ?
            try {
                ojbLogPropFile = contextLoader.getResourceAsStream("log4j.properties");
                if (ojbLogPropFile != null) {
                    // yep, so use log4j
                    _loggerClass = Log4jLoggerImpl.class;
                    _loggerConfigFile = "log4j.properties";
                    bootLogger.info("Logging: Found 'log4j.properties' file, use " + _loggerClass);
                    ojbLogPropFile.close();
                }
            } catch (Exception ex) {
            }
            if (_loggerClass == null) {
                // or a commons-logging.properties file ?
                try {
                    ojbLogPropFile = contextLoader.getResourceAsStream("commons-logging.properties");
                    if (ojbLogPropFile != null) {
                        // yep, so use commons-logging
                        _loggerClass = CommonsLoggerImpl.class;
                        _loggerConfigFile = "commons-logging.properties";
                        bootLogger
                                .info("Logging: Found 'commons-logging.properties' file, use " + _loggerClass);
                        ojbLogPropFile.close();
                    }
                } catch (Exception ex) {
                }
                if (_loggerClass == null) {
                    // no, so default to poor man's logging
                    bootLogger.info("** Can't find logging configuration file, use default logger **");
                    _loggerClass = PoorMansLoggerImpl.class;
                }
            }
        }
    }
}

From source file:org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl.java

protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException {
    HighLowSequence seq;//from  www.ja v  a  2  s  .  co m
    String sequenceName = buildSequenceName(field);
    synchronized (SequenceManagerHighLowImpl.class) {
        // try to find sequence
        seq = getSequence(sequenceName);

        if (seq == null) {
            // not found, get sequence from database or create new
            seq = getSequence(getBrokerForClass(), field, sequenceName);
            addSequence(sequenceName, seq);
        }

        // now we have a sequence
        long id = seq.getNextId();
        // seq does not have reserved IDs => catch new block of keys
        if (id == 0) {
            seq = getSequence(getBrokerForClass(), field, sequenceName);
            // replace old sequence!!
            addSequence(sequenceName, seq);
            id = seq.getNextId();
            if (id == 0) {
                // something going wrong
                removeSequence(sequenceName);
                throw new SequenceManagerException("Sequence generation failed: " + SystemUtils.LINE_SEPARATOR
                        + "Sequence: " + seq + ". Unable to build new ID, id was always 0."
                        + SystemUtils.LINE_SEPARATOR + "Thread: " + Thread.currentThread()
                        + SystemUtils.LINE_SEPARATOR + "PB: " + getBrokerForClass());
            }
        }
        return id;
    }
}

From source file:org.apache.ojb.broker.util.sequence.SequenceManagerMSSQLGuidImpl.java

/**
 * Returns a new unique int for the given Class and fieldname.
 *///from w  w  w  . ja  v a2  s. com
protected int getUniqueId(FieldDescriptor field) throws SequenceManagerException {
    throw new SequenceManagerException(SystemUtils.LINE_SEPARATOR
            + "Failure attempting to retrieve a Guid for a field that is an int -- field should be returned as a VARCHAR");
}

From source file:org.apache.ojb.broker.util.sequence.SequenceManagerMSSQLGuidImpl.java

/**
 * Returns a new unique int for the given Class and fieldname.
 *///from   ww  w  . j  av  a 2s . co m
protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException {
    throw new SequenceManagerException(SystemUtils.LINE_SEPARATOR
            + "Failure attempting to retrieve a Guid for a field that is a long -- field should be returned as a VARCHAR");
}

From source file:org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl.java

/**
 * returns a unique long value for class clazz and field fieldName.
 * the returned number is unique accross all tables in the extent of clazz.
 *//*w  w w .  j a  v a2  s  .  c om*/
protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException {
    long result;
    // lookup sequence name
    String sequenceName = calculateSequenceName(field);
    try {
        result = buildNextSequence(field.getClassDescriptor(), sequenceName);
    } catch (Throwable e) {
        // maybe the sequence was not created
        try {
            log.info("Create DB sequence key '" + sequenceName + "'");
            createSequence(field.getClassDescriptor(), sequenceName);
        } catch (Exception e1) {
            throw new SequenceManagerException(SystemUtils.LINE_SEPARATOR
                    + "Could not grab next id, failed with " + SystemUtils.LINE_SEPARATOR + e.getMessage()
                    + SystemUtils.LINE_SEPARATOR + "Creation of new sequence failed with "
                    + SystemUtils.LINE_SEPARATOR + e1.getMessage() + SystemUtils.LINE_SEPARATOR, e1);
        }
        try {
            result = buildNextSequence(field.getClassDescriptor(), sequenceName);
        } catch (Throwable e1) {
            throw new SequenceManagerException("Could not grab next id, sequence seems to exist", e);
        }
    }
    return result;
}

From source file:org.apache.ojb.broker.util.sequence.SequenceManagerStoredProcedureImpl.java

/**
 * Gets the actual key - will create a new row with the max key of table if it
 * does not exist.//from   ww  w .  ja  v a 2 s .  co m
 * @param field
 * @return
 * @throws SequenceManagerException
 */
protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException {
    boolean needsCommit = false;
    long result = 0;
    /*
    arminw:
    use the associated broker instance, check if broker was in tx or
    we need to commit used connection.
    */
    PersistenceBroker targetBroker = getBrokerForClass();
    if (!targetBroker.isInTransaction()) {
        targetBroker.beginTransaction();
        needsCommit = true;
    }
    try {
        // lookup sequence name
        String sequenceName = calculateSequenceName(field);
        try {
            result = buildNextSequence(targetBroker, field.getClassDescriptor(), sequenceName);
            /*
            if 0 was returned we assume that the stored procedure
            did not work properly.
            */
            if (result == 0) {
                throw new SequenceManagerException("No incremented value retrieved");
            }
        } catch (Exception e) {
            // maybe the sequence was not created
            log.info("Could not grab next key, message was " + e.getMessage()
                    + " - try to write a new sequence entry to database");
            try {
                // on create, make sure to get the max key for the table first
                long maxKey = SequenceManagerHelper.getMaxForExtent(targetBroker, field);
                createSequence(targetBroker, field, sequenceName, maxKey);
            } catch (Exception e1) {
                String eol = SystemUtils.LINE_SEPARATOR;
                throw new SequenceManagerException(
                        eol + "Could not grab next id, failed with " + eol + e.getMessage() + eol
                                + "Creation of new sequence failed with " + eol + e1.getMessage() + eol,
                        e1);
            }
            try {
                result = buildNextSequence(targetBroker, field.getClassDescriptor(), sequenceName);
            } catch (Exception e1) {
                throw new SequenceManagerException("Could not grab next id although a sequence seems to exist",
                        e);
            }
        }
    } finally {
        if (targetBroker != null && needsCommit) {
            targetBroker.commitTransaction();
        }
    }
    return result;
}

From source file:org.apache.ojb.ejb.odmg.StressTest.java

private void runMultithreaded() throws Exception {
    String sep = SystemUtils.LINE_SEPARATOR;

    System.out.println(sep + sep + "++ Start thread generation for ODMG api test ++");
    System.out.println("Begin with performance test, " + concurrentThreads + " concurrent threads, handle "
            + iterationsPerThread + " articles per thread");
    ODMGTestClient[] clientsODMG = new ODMGTestClient[concurrentThreads];
    for (int i = 0; i < concurrentThreads; i++) {
        ODMGTestClient obj = new ODMGTestClient(this);
        clientsODMG[i] = obj;/*from   www.ja  v a 2 s.com*/
    }
    System.out.println("");
    times[0] = System.currentTimeMillis();
    runTestClients(clientsODMG);
    times[0] = (System.currentTimeMillis() - times[0]);
    System.out.println(buildTestSummary("ODMG API"));
    System.out.println("++ End of performance test ODMG api ++" + sep + sep);
}

From source file:org.apache.ojb.ejb.odmg.StressTestClient.java

public void testStressPB() throws Exception {
    int loops = 3;
    int concurrentThreads = 10;
    int objectsPerThread = 200;

    String eol = SystemUtils.LINE_SEPARATOR;
    for (int i = 0; i < loops; i++) {
        System.out.println(eol + "##  perform loop " + (i + 1) + "   ##");
        StressTest.performTest(new int[] { concurrentThreads, objectsPerThread });
    }//  ww  w  .j a  v a2  s.  c o m
}

From source file:org.apache.ojb.ejb.pb.StressTest.java

private void runMultithreaded() throws Exception {
    String sep = SystemUtils.LINE_SEPARATOR;

    System.out.println(sep + sep + "++ Start thread generation for PB api test ++");
    System.out.println("Begin with performance test, " + concurrentThreads + " concurrent threads, handle "
            + iterationsPerThread + " articles per thread");
    PBTestClient[] clientsPB = new PBTestClient[concurrentThreads];
    for (int i = 0; i < concurrentThreads; i++) {
        PBTestClient obj = new PBTestClient(this);
        clientsPB[i] = obj;/*w ww  . j  ava  2 s .  co  m*/
    }
    System.out.println("");
    times[0] = System.currentTimeMillis();
    runTestClients(clientsPB);
    times[0] = (System.currentTimeMillis() - times[0]);
    System.out.println(buildTestSummary("PB API"));
    System.out.println("++ End of performance test PB api ++" + sep + sep);
}

From source file:org.apache.ojb.ejb.pb.StressTestClient.java

public void testStressPB() throws Exception {
    int loops = 2;
    int concurrentThreads = 10;
    int objectsPerThread = 200;
    String eol = SystemUtils.LINE_SEPARATOR;
    for (int i = 0; i < loops; i++) {
        System.out.println(eol + "##  perform loop " + (i + 1) + "   ##");
        StressTest.performTest(new int[] { concurrentThreads, objectsPerThread });
    }//from  w w w. jav  a 2 s.com
}