当前位置: 首页>>代码示例>>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;未经允许,请勿转载。