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();
TestData testData = new TestData(); testData.prepare(); Session session = openSession(); session.enableFilter( "effectiveDate" ).setParameter( "asOfDate", new Date() ); List result = session.createQuery( "from Product p inner join fetch p.categories" ).list(); assertTrue( "No products returned from HQL many-to-many filter case", !result.isEmpty() ); Product prod = ( Product ) result.get( 0 ); assertNotNull( prod ); assertEquals( "Incorrect Product.categories count for filter with HQL", 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 testManyToManyFilterOnCriteria() Method name: void testManyToManyFilterOnQuery()
Number of AST nodes: 9 Number of AST nodes: 11
1
TestData testData = new TestData();
1
TestData testData = new TestData();
2
		testData.prepare();
2
		testData.prepare();
3
		Session session = openSession();
3
		Session session = openSession();
4
		session.enableFilter( "effectiveDate" ).setParameter( "asOfDate", new Date() );
4
		session.enableFilter( "effectiveDate" ).setParameter( "asOfDate", new Date() );
5
		Product prod = ( Product ) session.createCriteria( Product.class )
5
		List result = session.create
6
		        .setResultTransformer( new DistinctRootEntityResultTransformer() )
7
		        .add( Restrictions.eq( "id", testData.prod1Id 
6
Query( "from Product p inner join fetch p.categories" ).list();
8
) )
7
		assertTrue( "No products returned from HQL many-to-many filter case", !result.isEmpty() );
9
		        .uniqueResult();
8
		Product prod = ( Product ) result.get( 0 );
10
		assertNotNull( prod );
9
		assertNotNull( prod );
11
		assertEquals( "Incorrect Product.categories count for filter", 1, prod.getCategories().size() );
10
		assertEquals( "Incorrect Product.categories count for filter with HQL", 1, prod.getCategories().size() );
12
		session.close();
11
		session.close();
13
		testData.release();
12
		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 statements8
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment3
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    TestData testData = new TestData();
    1
    TestData testData = new TestData();
    2
    testData.prepare();
    2
    testData.prepare();
    3
    Session session = openSession();
    3
    Session session = openSession();
    4
    session.enableFilter("effectiveDate").setParameter("asOfDate", new Date());
    4
    session.enableFilter("effectiveDate").setParameter("asOfDate", new Date());
                                                                                                                                                                                        
    5
    List result = session.createQuery("from Product p inner join fetch p.categories").list();
    Preondition Violations
    Unmatched statement List result=session.createQuery("from Product p inner join fetch p.categories").list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5
    List result = session.createQuery("from Product p inner join fetch p.categories").list();
    5
    Product prod = (Product)session.createCriteria(Product.class).setResultTransformer(new DistinctRootEntityResultTransformer()).add(Restrictions.eq("id", testData.prod1Id)).uniqueResult();
    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
                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                        
    6
    assertTrue("No products returned from HQL many-to-many filter case", !result.isEmpty());
                                                                                  
    7
    Product prod = (Product)result.get(0);
    6
    assertNotNull(prod);
    8
    assertNotNull(prod);
    7
    assertEquals("Incorrect Product.categories count for filter", 1, prod.getCategories().size());
    7
    assertEquals("Incorrect Product.categories count for filter", 1, prod.getCategories().size());
    9
    assertEquals("Incorrect Product.categories count for filter with HQL", 1, prod.getCategories().size());
    Differences
    Expression1Expression2Difference
    "Incorrect Product.categories count for filter""Incorrect Product.categories count for filter with HQL"LITERAL_VALUE_MISMATCH
    9
    assertEquals("Incorrect Product.categories count for filter with HQL", 1, prod.getCategories().size());
    8
    session.close();
    10
    session.close();
    9
    testData.release();
    11
    testData.release();
    Precondition Violations (2)
    Row Violation
    1Unmatched statement List result=session.createQuery("from Product p inner join fetch p.categories").list(); cannot be moved before or after the extracted code, 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