@SuppressWarnings("unchecked") public void testVisitJoinWithoutLock() throws Exception { Select select = new Select("test"); select.setLocked(false); Visitor queryVis = getVisitor(); Table tab1 = new Table("tab1"); Column col1 = tab1.column("col1"); Table tab2 = new Table("tab2"); Column col2 = tab2.column("col2"); Join join = new Join(JoinOperator.LEFT, new Table("tab1"), col1.equal(col2)); Class[] clazz = {Select.class}; Object[] obj = {select}; try { Method method = queryVis.getClass().getDeclaredMethod("setSelect", clazz); method.setAccessible(true); method.invoke(queryVis, obj); } catch (Exception e) { fail("Something went wrong using reflection to execute private method."); e.printStackTrace(); } queryVis.visit(join); assertEquals("LEFT JOIN \"tab1\" ON \"tab1\".\"col1\"=\"tab2\".\"col2\"", queryVis.toString()); }
@SuppressWarnings("unchecked") public void testHandleJoinConstructionWithLock() { Select select = new Select("test"); select.setLocked(true); Visitor queryVis = getVisitor(); Table table = new Table("tab1"); Column col1 = table.column("col1"); Table table2 = new Table("tab2"); Column col2 = table2.column("col2"); Class[] clazz = {Select.class}; Object[] obj = {select}; try { Method method = queryVis.getClass().getDeclaredMethod("setSelect", clazz); method.setAccessible(true); method.invoke(queryVis, obj); } catch (Exception e) { fail("Something went wrong using reflection to execute private method."); e.printStackTrace(); } ((SybaseQueryVisitor) queryVis).handleJoinConstruction(table); assertEquals("\"tab1\" HOLDLOCK", queryVis.toString()); table.addFullJoin(table2, col1.equal(col2)); queryVis = getVisitor(); try { Method method = queryVis.getClass().getDeclaredMethod("setSelect", clazz); method.setAccessible(true); method.invoke(queryVis, obj); } catch (Exception e) { fail("Something went wrong using reflection to execute private method."); e.printStackTrace(); } ((SybaseQueryVisitor) queryVis).handleJoinConstruction(table); assertEquals( "(\"tab1\" HOLDLOCK FULL JOIN \"tab2\" HOLDLOCK ON " + "\"tab1\".\"col1\"=\"tab2\".\"col2\")", queryVis.toString()); }