org.eclipse.persistence.logging.AbstractSessionLog Java Examples

The following examples show how to use org.eclipse.persistence.logging.AbstractSessionLog. 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: XmlTransformer.java    From recheck with GNU Affero General Public License v3.0 5 votes vote down vote up
public void toXML( final Object obj, final OutputStream out, final Marshaller.Listener listener ) {
	Marshaller marshaller = null;
	try {
		final JAXBContext jc = createJAXBContext( additionalClazzes );
		marshaller = jc.createMarshaller();
		marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true );
		marshaller.setProperty( MarshallerProperties.NAMESPACE_PREFIX_MAPPER,
				new MapNamespacePrefixMapper( NAMESPACE_MAPPINGS ) );
		marshaller.setProperty( MarshallerProperties.INDENT_STRING, "\t" );
		marshaller.setEventHandler( new DefaultValidationEventHandler() );
		marshaller.setListener( listener );
		final SessionLogDelegate sessionLog = new SessionLogDelegate( AbstractSessionLog.getLog() );
		AbstractSessionLog.setLog( sessionLog );

		if ( config.isOnlyFragment() ) {
			log.info( "Create only fragment for '{}'.", obj );
			marshaller.setProperty( Marshaller.JAXB_FRAGMENT, true );
		}

		if ( config.isLightweightXml() ) {
			log.info( "Use lightweight XML for '{}'.", obj );
			lightweightMarshallerSet.add( marshaller );
			XmlUtil.addLightWeightAdapter( marshaller );
		}

		marshaller.marshal( obj, out );

		if ( sessionLog.containsMessages() ) {
			throw new RuntimeException( "Error persisting XML: " + sessionLog.getLog() );
		}
	} catch ( final JAXBException e ) {
		throw new RuntimeException( e );
	} finally {
		if ( config.isLightweightXml() && marshaller != null ) {
			lightweightMarshallerSet.remove( marshaller );
		}
	}
}
 
Example #2
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 #3
Source File: EclipselinkStaticWeaveMojo.java    From eclipselink-maven-plugin with Apache License 2.0 4 votes vote down vote up
private int getLogLevel()
{
    return AbstractSessionLog.translateStringToLoggingLevel(logLevel);
}