當前位置: 首頁>>代碼示例>>Java>>正文


Java Audited類代碼示例

本文整理匯總了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" ) );
}
 
開發者ID:kiegroup,項目名稱:kie-wb-common,代碼行數:23,代碼來源:JPADataObjectEditorTest.java

示例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 );
            }
        }
    }
}
 
開發者ID:kiegroup,項目名稱:kie-wb-common,代碼行數:53,代碼來源:JPADomainHandler.java


注:本文中的org.hibernate.envers.Audited類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。