org.eclipse.persistence.logging.SessionLog Java Examples

The following examples show how to use org.eclipse.persistence.logging.SessionLog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EclipseLinkOSGiSessionLogger.java    From lb-karaf-examples-jpa with Apache License 2.0 6 votes vote down vote up
/**
 *
 */
@Override
public void log(SessionLogEntry sle) {
    Logger lg  = getLogger(sle);
    String msg = getMessage(sle);

    if(lg != null && StringUtils.isNotBlank(msg)) {
        switch(sle.getLevel()) {
            case SessionLog.SEVERE  : lg.error(msg); break;
            case SessionLog.WARNING : lg.warn (msg); break;
            case SessionLog.INFO    : lg.info (msg); break;
            case SessionLog.FINE    : lg.debug(msg); break;
            case SessionLog.FINER   : lg.trace(msg); break;
            case SessionLog.FINEST  : lg.trace(msg); break;
            case SessionLog.ALL     : lg.trace(msg); break;
            default                 : lg.debug(msg); break;
        }
    }
}
 
Example #2
Source File: EclipseLinkOSGiSessionLogger.java    From lb-karaf-examples-jpa with Apache License 2.0 6 votes vote down vote up
/**
 *
 */
@Override
public void log(SessionLogEntry sle) {
    Logger lg  = getLogger(sle);
    String msg = getMessage(sle);

    if(lg != null && StringUtils.isNotBlank(msg)) {
        switch(sle.getLevel()) {
            case SessionLog.SEVERE  : lg.error(msg); break;
            case SessionLog.WARNING : lg.warn (msg); break;
            case SessionLog.INFO    : lg.info (msg); break;
            case SessionLog.FINE    : lg.debug(msg); break;
            case SessionLog.FINER   : lg.trace(msg); break;
            case SessionLog.FINEST  : lg.trace(msg); break;
            case SessionLog.ALL     : lg.trace(msg); break;
            default                 : lg.debug(msg); break;
        }
    }
}
 
Example #3
Source File: EclipseLinkOSGiSessionLogger.java    From lb-karaf-examples-jpa with Apache License 2.0 6 votes vote down vote up
/**
 *
 */
@Override
public void log(SessionLogEntry sle) {
    Logger lg  = getLogger(sle);
    String msg = getMessage(sle);

    if(lg != null && StringUtils.isNotBlank(msg)) {
        switch(sle.getLevel()) {
            case SessionLog.SEVERE  : lg.error(msg); break;
            case SessionLog.WARNING : lg.warn (msg); break;
            case SessionLog.INFO    : lg.info (msg); break;
            case SessionLog.FINE    : lg.debug(msg); break;
            case SessionLog.FINER   : lg.trace(msg); break;
            case SessionLog.FINEST  : lg.trace(msg); break;
            case SessionLog.ALL     : lg.trace(msg); break;
            default                 : lg.debug(msg); break;
        }
    }
}
 
Example #4
Source File: Slf4jSessionLogger.java    From testgrid with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of Slf4jSessionLogger
 */
public Slf4jSessionLogger() {
   super();
    for (String category : SessionLog.loggerCatagories) {
        addLogger(category, ECLIPSELINK_NAMESPACE + "." + category);
    }
    addLogger(DEFAULT_CATEGORY, DEFAULT_ECLIPSELINK_NAMESPACE);
}
 
Example #5
Source File: Slf4jSessionLogger.java    From gazpachoquest with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initialize loggers eagerly
 */
private void createCategoryLoggers() {
    for (String category : SessionLog.loggerCatagories) {
        addLogger(category, ECLIPSELINK_NAMESPACE + "." + category);
    }
    // Logger default para cuando no hay categoría.
    addLogger(DEFAULT_CATEGORY, DEFAULT_ECLIPSELINK_NAMESPACE);
}
 
Example #6
Source File: Slf4jSessionLogger.java    From gazpachoquest with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Relación de los niveles de log de EclipseLink y los de SLF4J
 */
private void initMapLevels() {
    mapLevels = new HashMap<Integer, LogLevel>();

    mapLevels.put(SessionLog.ALL, LogLevel.TRACE);
    mapLevels.put(SessionLog.FINEST, LogLevel.TRACE);
    mapLevels.put(SessionLog.FINER, LogLevel.TRACE);
    mapLevels.put(SessionLog.FINE, LogLevel.DEBUG);
    mapLevels.put(SessionLog.CONFIG, LogLevel.INFO);
    mapLevels.put(SessionLog.INFO, LogLevel.INFO);
    mapLevels.put(SessionLog.WARNING, LogLevel.WARN);
    mapLevels.put(SessionLog.SEVERE, LogLevel.ERROR);
}
 
Example #7
Source File: Slf4jSessionLogger.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Initialize loggers eagerly
 */
private void createCategoryLoggers(){
	for (String category : SessionLog.loggerCatagories) {
		addLogger(category, ECLIPSELINK_NAMESPACE + "." + category);
	}
	// Logger default para cuando no hay categoría.
	addLogger(DEFAULT_CATEGORY, DEFAULT_ECLIPSELINK_NAMESPACE);
}
 
Example #8
Source File: SessionLogDelegate.java    From recheck with GNU Affero General Public License v3.0 4 votes vote down vote up
public SessionLogDelegate( final SessionLog delegate ) {
	this.delegate = delegate;
	delegate.setWriter( writer );
}
 
Example #9
Source File: JPAMDefaultTableGenerator.java    From jeddict with Apache License 2.0 4 votes vote down vote up
/**
 * Generate a default TableCreator object from the EclipseLink project
 * object, and perform the table existence check through jdbc table
 * metadata, and filter out tables which are already in the database.
 */
public JPAMTableCreator generateFilteredDefaultTableCreator(AbstractSession session) throws DatabaseException {
    JPAMTableCreator tblCreator = generateDefaultTableCreator();

    try {
        //table exisitence check.
        java.sql.Connection conn = null;
        if (session.isServerSession()) {
            //acquire a connection from the pool
            conn = ((ServerSession) session).getDefaultConnectionPool().acquireConnection().getConnection();
        } else if (session.isDatabaseSession()) {
            conn = ((DatabaseSessionImpl) session).getAccessor().getConnection();
        }
        if (conn == null) {
            //TODO: this is not pretty, connection is not obtained for some reason.
            return tblCreator;
        }
        DatabaseMetaData dbMetaData = conn.getMetaData();
        ResultSet resultSet = dbMetaData.getTables(null, dbMetaData.getUserName(), null, new String[]{"TABLE"});
        List tablesInDatabase = new ArrayList();

        while (resultSet.next()) {
            //save all tables from the database
            tablesInDatabase.add(resultSet.getString("TABLE_NAME"));
        }

        resultSet.close();

        List existedTables = new ArrayList();
        List existedTableNames = new ArrayList();
        Iterator tblDefIter = tblCreator.getTableDefinitions().iterator();

        while (tblDefIter.hasNext()) {
            TableDefinition tblDef = (TableDefinition) tblDefIter.next();

            //check if the to-be-created table is already in the database
            if (tablesInDatabase.contains(tblDef.getFullName())) {
                existedTables.add(tblDef);
                existedTableNames.add(tblDef.getFullName());
            }
        }

        if (!existedTableNames.isEmpty()) {
            session.getSessionLog().log(SessionLog.FINEST, SessionLog.DDL, "skip_create_existing_tables", existedTableNames);

            //remove the existed tables, won't create them.
            tblCreator.getTableDefinitions().removeAll(existedTables);
        }
    } catch (SQLException sqlEx) {
        throw DatabaseException.errorRetrieveDbMetadataThroughJDBCConnection();
    }

    return tblCreator;
}
 
Example #10
Source File: JPAMDefaultTableGenerator.java    From jeddict with Apache License 2.0 4 votes vote down vote up
protected FieldDefinition getFieldDefFromDBField(Supplier<JPAMFieldDefinition> fieldDefSupplier, DatabaseField dbField) {
    FieldDefinition fieldDef = this.fieldMap.get(dbField);
    if (fieldDef == null) {
        fieldDef = fieldDefSupplier.get();
        fieldDef.setName(dbField.getNameDelimited(databasePlatform));

        //added for extending tables where the field needs to be looked up
        fieldDef.setDatabaseField(dbField);

        if (dbField.getColumnDefinition() != null && dbField.getColumnDefinition().length() > 0) {
            // This column definition would include the complete definition of the
            // column like type, size,  "NULL/NOT NULL" clause, unique key clause
            fieldDef.setTypeDefinition(dbField.getColumnDefinition());
        } else {
            Class fieldType = dbField.getType();
            FieldTypeDefinition fieldTypeDef = (fieldType == null) ? null : databasePlatform.getFieldTypeDefinition(fieldType);

            // Check if the user field is a String and only then allow the length specified
            // in the @Column annotation to be set on the field.
            if (fieldType != null) {
                // If a length has been specified, set it, otherwise let the
                // field def from individual platforms handle it.
                if (dbField.getLength() > 0) {
                    fieldDef.setSize(dbField.getLength());
                } else if (dbField.getPrecision() > 0) {
                    fieldDef.setSize(dbField.getPrecision());
                    fieldDef.setSubSize(dbField.getScale());
                }
            }

            if ((fieldType == null) || (!fieldType.isPrimitive() && (fieldTypeDef == null))) {
                //TODO: log a warning for inaccessible type or not convertable type.
                AbstractSessionLog.getLog().log(SessionLog.CONFIG, SessionLog.METADATA, "field_type_set_to_java_lang_string", dbField.getQualifiedName(), fieldType);

                //set the default type (lang.String) to all un-resolved java type, like null, Number, util.Date, NChar/NType, Calendar
                //sql.Blob/Clob, Object, or unknown type). Please refer to bug 4352820.
                fieldDef.setType(ClassConstants.STRING);
            } else {
                //need to convert the primitive type if applied.
                fieldDef.setType(ConversionManager.getObjectClass(fieldType));
            }

            fieldDef.setShouldAllowNull(dbField.isNullable());
            fieldDef.setUnique(dbField.isUnique());
        }
        this.fieldMap.put(dbField, fieldDef);
        this.databaseFields.put(dbField, dbField);
    }

    return fieldDef;
}
 
Example #11
Source File: JPAMTableCreator.java    From jeddict with Apache License 2.0 4 votes vote down vote up
/**
 * Drop the tables from the database.
 */
public void dropTables(DatabaseSession session, JPAMSchemaManager schemaManager, boolean build) {
    buildConstraints(schemaManager, build);

    // CR 3870467, do not log stack, or log at all if not fine
    boolean shouldLogExceptionStackTrace = session.getSessionLog().shouldLogExceptionStackTrace();
    int level = session.getSessionLog().getLevel();
    if (shouldLogExceptionStackTrace) {
        session.getSessionLog().setShouldLogExceptionStackTrace(false);
    }
    if (level > SessionLog.FINE) {
        session.getSessionLog().setLevel(SessionLog.SEVERE);
    }
    try {
        dropConstraints(session, schemaManager, false);

        String sequenceTableName = getSequenceTableName(session);
        List<JPAMTableDefinition> tables = getTableDefinitions();
        int trys = 1;
        if (JPAMSchemaManager.FORCE_DROP) {
            trys = 5;
        }
        while ((trys > 0) && !tables.isEmpty()) {
            trys--;
            List<JPAMTableDefinition> failed = new ArrayList<>();
            for (JPAMTableDefinition table : tables) {
                // Must not create sequence table as done in createSequences.
                if (!table.getName().equals(sequenceTableName)) {
                    try {
                        schemaManager.dropObject(table);
                    } catch (DatabaseException exception) {
                        failed.add(table);
                        if (!shouldIgnoreDatabaseException()) {
                            throw exception;
                        }
                    }
                }
            }
            tables = failed;
        }
    } finally {
        if (shouldLogExceptionStackTrace) {
            session.getSessionLog().setShouldLogExceptionStackTrace(true);
        }
        if (level > SessionLog.FINE) {
            session.getSessionLog().setLevel(level);
        }
    }
}