log.info( "Starting one-to-many collection loader filter tests." ); TestData testData = new TestData(); testData.prepare(); Session session = openSession(); session.enableFilter( "seniorSalespersons" ) .setParameter( "asOfDate", testData.lastMonth.getTime() ); log.info( "Performing load of Department..." ); Department department = ( Department ) session.load( Department.class, testData.deptId ); Set salespersons = department.getSalespersons(); assertEquals( "Incorrect salesperson count", 1, salespersons.size() ); session.close(); testData.release();
TestData testData = new TestData(); testData.prepare(); Session session = openSession(); session.enableFilter( "effectiveDate" ).setParameter( "asOfDate", new Date() ); Product prod = ( Product ) session.createCriteria( Product.class ) .setResultTransformer( new DistinctRootEntityResultTransformer() ) .add( Restrictions.eq( "id", testData.prod1Id ) ) .uniqueResult(); assertNotNull( prod ); assertEquals( "Incorrect Product.categories count for filter", 1, prod.getCategories().size() ); session.close(); testData.release();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java
Method name: void testOneToManyFilters() Method name: void testManyToManyFilterOnCriteria()
Number of AST nodes: 11 Number of AST nodes: 9
1
log.info( "Starting one-to-many collection loader filter tests." );
2
		TestData testData = new TestData();
1
TestData testData = new TestData();
3
		testData.prepare();
2
		testData.prepare();
4
		Session session = openSession();
3
		Session session = openSession();
5
		session.enableFilter( "seniorSalespersons" )
4
		session.enableFilter( "
6
		        .setParameter( "asOfDate", testData.lastMonth.getTime() );
5
effectiveDate" ).setParameter( "asOfDate", 
7
		log.info( "Performing load of Department..."
6
new Date() );
8
 );
7
		Product prod = ( Product ) session.createCriteria( Product.class )
9
		Department department = ( Department ) session.load( Department.class
8
		        .setResultTransformer( new DistinctRootEntityResultTransformer() )
10
, testData.deptId );
9
		        .add( Restrictions.eq( "id", testData.prod1Id ) )
11
		Set salespersons = department.getSalespersons();
10
		
12
		assertEquals( "Incorrect salesperson count", 1, salespersons
11
        .uniqueResult();
12
		assertNotNull( prod );
13
.size() );
13
		assertEquals( "Incorrect Product.categories count for filter", 1, prod.getCategories().size() );
14
		session.close();
14
		session.close();
15
		testData.release();
15
		testData.release();
Summary
Number of common nesting structure subtrees1
Number of refactorable cases1
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones locationClones are declared in the same class
Number of node comparisons67
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements7
    Number of unmapped statements in the first code fragment4
    Number of unmapped statements in the second code fragment2
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    log.info("Starting one-to-many collection loader filter tests.");
                                                                                                                                            
    2
    TestData testData = new TestData();
    1
    TestData testData = new TestData();
    3
    testData.prepare();
    2
    testData.prepare();
    4
    Session session = openSession();
    3
    Session session = openSession();
    5
    session.enableFilter("seniorSalespersons").setParameter("asOfDate", testData.lastMonth.getTime());
    5
    session.enableFilter("seniorSalespersons").setParameter("asOfDate", testData.lastMonth.getTime());
    4
    session.enableFilter("effectiveDate").setParameter("asOfDate", new Date());
    Differences
    Expression1Expression2Difference
    testData.lastMonth.getTime()new Date()TYPE_COMPATIBLE_REPLACEMENT
    "seniorSalespersons""effectiveDate"LITERAL_VALUE_MISMATCH
    Preondition Violations
    Expression testData.lastMonth.getTime() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4
    session.enableFilter("effectiveDate").setParameter("asOfDate", new Date());
                                                                                                                                                                                                                                                                                                                                                                                        
    5
    Product prod = (Product)session.createCriteria(Product.class).setResultTransformer(new DistinctRootEntityResultTransformer()).add(Restrictions.eq("id", testData.prod1Id)).uniqueResult();
    Preondition Violations
    Unmatched statement Product prod=(Product)session.createCriteria(Product.class).setResultTransformer(new DistinctRootEntityResultTransformer()).add(Restrictions.eq("id",testData.prod1Id)).uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5
    Product prod = (Product)session.createCriteria(Product.class).setResultTransformer(new DistinctRootEntityResultTransformer()).add(Restrictions.eq("id", testData.prod1Id)).uniqueResult();
    6
    log.info("Performing load of Department...");
                                                                                                    
                                                                                                                                                                                                  
    7
    assertEquals("Incorrect Product.categories count for filter", 1, prod.getCategories().size());
    7
    Department department = (Department)session.load(Department.class, testData.deptId);
    7
    Department department = (Department)session.load(Department.class, testData.deptId);
    Preondition Violations
    Unmatched statement Department department=(Department)session.load(Department.class,testData.deptId); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                            
    8
    Set salespersons = department.getSalespersons();
                                                                                                      
    9
    assertEquals("Incorrect salesperson count", 1, salespersons.size());
    9
    assertEquals("Incorrect salesperson count", 1, salespersons.size());
    6
    assertNotNull(prod);
    Differences
    Expression1Expression2Difference
    assertEqualsassertNotNullMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals("Incorrect salesperson count",1,salespersons.size())assertNotNull(prod)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals("Incorrect salesperson count",1,salespersons.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNotNull(prod) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("Incorrect salesperson count",1,salespersons.size()) is a void method call, and thus it cannot be parameterized
    Expression assertNotNull(prod) is a void method call, and thus it cannot be parameterized
    Expression assertEquals("Incorrect salesperson count",1,salespersons.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNotNull(prod) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("Incorrect salesperson count",1,salespersons.size()) is a void method call, and thus it cannot be parameterized
    Expression assertNotNull(prod) is a void method call, and thus it cannot be parameterized
    6
    assertNotNull(prod);
    10
    session.close();
    8
    session.close();
    11
    testData.release();
    9
    testData.release();
    Precondition Violations (11)
    Row Violation
    1Expression testData.lastMonth.getTime() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Unmatched statement Product prod=(Product)session.createCriteria(Product.class).setResultTransformer(new DistinctRootEntityResultTransformer()).add(Restrictions.eq("id",testData.prod1Id)).uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched statement Department department=(Department)session.load(Department.class,testData.deptId); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Expression assertEquals("Incorrect salesperson count",1,salespersons.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5Expression assertNotNull(prod) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression assertEquals("Incorrect salesperson count",1,salespersons.size()) is a void method call, and thus it cannot be parameterized
    7Expression assertNotNull(prod) is a void method call, and thus it cannot be parameterized
    8Expression assertEquals("Incorrect salesperson count",1,salespersons.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Expression assertNotNull(prod) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression assertEquals("Incorrect salesperson count",1,salespersons.size()) is a void method call, and thus it cannot be parameterized
    11Expression assertNotNull(prod) is a void method call, and thus it cannot be parameterized