Java 类org.hibernate.envers.Audited 实例源码

项目:kie-wb-common    文件:JPADataObjectEditorTest.java   
@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" ) );
}
项目:kie-wb-common    文件:JPADomainHandler.java   
@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 );
            }
        }
    }
}