下面列出了javax.xml.bind.helpers.DefaultValidationEventHandler#org.eclipse.persistence.logging.AbstractSessionLog 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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 );
}
}
}
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;
}
private int getLogLevel()
{
return AbstractSessionLog.translateStringToLoggingLevel(logLevel);
}