本文整理匯總了Java中org.hibernate.envers.Audited類的典型用法代碼示例。如果您正苦於以下問題:Java Audited類的具體用法?Java Audited怎麽用?Java Audited使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Audited類屬於org.hibernate.envers包,在下文中一共展示了Audited類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: auditChangeTest
import org.hibernate.envers.Audited; //導入依賴的package包/類
@Test
public void auditChangeTest() {
//enable audit option.
when( jpaDomainHandler.isDataObjectAuditEnabled() ).thenReturn( true );
JPADataObjectEditor objectEditor = createObjectEditor();
//load the editor
objectEditor.onContextChange( context );
//by construction the currently loaded data object org.test.TestObject1 is not audited.
DataObject dataObject = context.getDataObject();
//emulate user interaction setting TestObject1 as persistable
objectEditor.onAuditedFieldChange( "true" );
//the object should now be annotated as Audited.
assertNotNull( dataObject.getAnnotation( Audited.class.getName() ) );
assertEquals( RelationTargetAuditMode.NOT_AUDITED.name(),
AnnotationValueHandler.getStringValue( dataObject, Audited.class.getName(), "targetAuditMode" ) );
}
示例2: setDefaultValues
import org.hibernate.envers.Audited; //導入依賴的package包/類
@Override
public void setDefaultValues( DataObject dataObject, Map<String, Object> portableParams ) {
if ( portableParams != null ) {
Object currentValue = portableParams.get( "persistable" );
boolean isPersistable = Boolean.valueOf( currentValue != null ? currentValue.toString() : null );
currentValue = portableParams.get( "tableName" );
String tableName = currentValue != null ? currentValue.toString() : null;
if ( isPersistable ) {
//add default parameters for a persistable data object
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
//mark the class as Entity
dataObject.addAnnotation( new AnnotationImpl( modelDriver.getConfiguredAnnotation( Entity.class.getName() ) ) );
if ( tableName != null && !"".equals( tableName.trim() ) ) {
Annotation tableAnnotation = new AnnotationImpl( modelDriver.getConfiguredAnnotation( Table.class.getName() ) );
tableAnnotation.setValue( "name", tableName.trim() );
dataObject.addAnnotation( tableAnnotation );
}
//add the by default id field
ObjectProperty id = dataObject.addProperty( "id", Long.class.getName() );
id.addAnnotation( new AnnotationImpl( modelDriver.getConfiguredAnnotation( Id.class.getName() ) ) );
//set the by default generated value annotation.
String generatorName = createDefaultGeneratorName( dataObject.getName() );
Annotation generatedValue = new AnnotationImpl( modelDriver.getConfiguredAnnotation( GeneratedValue.class.getName() ) );
generatedValue.setValue( "generator", generatorName );
generatedValue.setValue( "strategy", GenerationType.AUTO.name() );
id.addAnnotation( generatedValue );
//set by default sequence generator
Annotation sequenceGenerator = new AnnotationImpl( modelDriver.getConfiguredAnnotation( SequenceGenerator.class.getName() ) );
String sequenceName = createDefaultSequenceName( dataObject.getName() );
sequenceGenerator.setValue( "name", generatorName );
sequenceGenerator.setValue( "sequenceName", sequenceName );
id.addAnnotation( sequenceGenerator );
boolean isAuditable = portableParams.containsKey( "audited" ) ?
Boolean.valueOf( portableParams.get( "audited" ).toString() ) : false;
if ( isAuditable ) {
Annotation audited = new AnnotationImpl( modelDriver.getConfiguredAnnotation( Audited.class.getName() ) );
audited.setValue( "targetAuditMode", RelationTargetAuditMode.NOT_AUDITED.name() );
dataObject.addAnnotation( audited );
}
}
}
}