target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test public void testAddJPAEdmRefConstraintView() { localView = new JPAEdmAssociationTest(); objAssociation = new JPAEdmAssociation(localView, localView, localView, 1); try { objAssociation.getBuilder().build(); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } objAssociation.addJPAEdmRefConstraintView(localView); assertTrue(objAssociation.getConsistentEdmAssociationList() .size() > 0); }
@Override public void addJPAEdmRefConstraintView( final JPAEdmReferentialConstraintView refView) { if (refView != null && refView.isExists()) { inconsistentRefConstraintViewList.add(refView); } }
JPAEdmAssociation extends JPAEdmBaseViewImpl implements JPAEdmAssociationView { @Override public void addJPAEdmRefConstraintView( final JPAEdmReferentialConstraintView refView) { if (refView != null && refView.isExists()) { inconsistentRefConstraintViewList.add(refView); } } }
JPAEdmAssociation extends JPAEdmBaseViewImpl implements JPAEdmAssociationView { @Override public void addJPAEdmRefConstraintView( final JPAEdmReferentialConstraintView refView) { if (refView != null && refView.isExists()) { inconsistentRefConstraintViewList.add(refView); } } JPAEdmAssociation(final JPAEdmAssociationEndView associationEndview, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final int value); JPAEdmAssociation(final JPAEdmSchemaView view); }
JPAEdmAssociation extends JPAEdmBaseViewImpl implements JPAEdmAssociationView { @Override public void addJPAEdmRefConstraintView( final JPAEdmReferentialConstraintView refView) { if (refView != null && refView.isExists()) { inconsistentRefConstraintViewList.add(refView); } } JPAEdmAssociation(final JPAEdmAssociationEndView associationEndview, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final int value); JPAEdmAssociation(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override Association getEdmAssociation(); @Override List<Association> getConsistentEdmAssociationList(); @Override Association searchAssociation(final JPAEdmAssociationEndView view); @Override void addJPAEdmAssociationView(final JPAEdmAssociationView associationView, final JPAEdmAssociationEndView associationEndView); @Override void addJPAEdmRefConstraintView( final JPAEdmReferentialConstraintView refView); @Override JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView(); @Override int getNumberOfAssociationsWithSimilarEndPoints( final JPAEdmAssociationEndView view); }
JPAEdmAssociation extends JPAEdmBaseViewImpl implements JPAEdmAssociationView { @Override public void addJPAEdmRefConstraintView( final JPAEdmReferentialConstraintView refView) { if (refView != null && refView.isExists()) { inconsistentRefConstraintViewList.add(refView); } } JPAEdmAssociation(final JPAEdmAssociationEndView associationEndview, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final int value); JPAEdmAssociation(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override Association getEdmAssociation(); @Override List<Association> getConsistentEdmAssociationList(); @Override Association searchAssociation(final JPAEdmAssociationEndView view); @Override void addJPAEdmAssociationView(final JPAEdmAssociationView associationView, final JPAEdmAssociationEndView associationEndView); @Override void addJPAEdmRefConstraintView( final JPAEdmReferentialConstraintView refView); @Override JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView(); @Override int getNumberOfAssociationsWithSimilarEndPoints( final JPAEdmAssociationEndView view); }
@Test public void testGetJPAEdmReferentialConstraintView() { }
@Override public JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView() { if (inconsistentRefConstraintViewList.isEmpty()) { return null; } return inconsistentRefConstraintViewList.get(0); }
JPAEdmAssociation extends JPAEdmBaseViewImpl implements JPAEdmAssociationView { @Override public JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView() { if (inconsistentRefConstraintViewList.isEmpty()) { return null; } return inconsistentRefConstraintViewList.get(0); } }
JPAEdmAssociation extends JPAEdmBaseViewImpl implements JPAEdmAssociationView { @Override public JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView() { if (inconsistentRefConstraintViewList.isEmpty()) { return null; } return inconsistentRefConstraintViewList.get(0); } JPAEdmAssociation(final JPAEdmAssociationEndView associationEndview, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final int value); JPAEdmAssociation(final JPAEdmSchemaView view); }
JPAEdmAssociation extends JPAEdmBaseViewImpl implements JPAEdmAssociationView { @Override public JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView() { if (inconsistentRefConstraintViewList.isEmpty()) { return null; } return inconsistentRefConstraintViewList.get(0); } JPAEdmAssociation(final JPAEdmAssociationEndView associationEndview, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final int value); JPAEdmAssociation(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override Association getEdmAssociation(); @Override List<Association> getConsistentEdmAssociationList(); @Override Association searchAssociation(final JPAEdmAssociationEndView view); @Override void addJPAEdmAssociationView(final JPAEdmAssociationView associationView, final JPAEdmAssociationEndView associationEndView); @Override void addJPAEdmRefConstraintView( final JPAEdmReferentialConstraintView refView); @Override JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView(); @Override int getNumberOfAssociationsWithSimilarEndPoints( final JPAEdmAssociationEndView view); }
JPAEdmAssociation extends JPAEdmBaseViewImpl implements JPAEdmAssociationView { @Override public JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView() { if (inconsistentRefConstraintViewList.isEmpty()) { return null; } return inconsistentRefConstraintViewList.get(0); } JPAEdmAssociation(final JPAEdmAssociationEndView associationEndview, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final int value); JPAEdmAssociation(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override Association getEdmAssociation(); @Override List<Association> getConsistentEdmAssociationList(); @Override Association searchAssociation(final JPAEdmAssociationEndView view); @Override void addJPAEdmAssociationView(final JPAEdmAssociationView associationView, final JPAEdmAssociationEndView associationEndView); @Override void addJPAEdmRefConstraintView( final JPAEdmReferentialConstraintView refView); @Override JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView(); @Override int getNumberOfAssociationsWithSimilarEndPoints( final JPAEdmAssociationEndView view); }
@Test public void testIsExists() { assertTrue(objJPAEdmReferentialConstraintRole.isExists()); }
@Override public boolean isExists() { return roleExists; }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public boolean isExists() { return roleExists; } }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public boolean isExists() { return roleExists; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public boolean isExists() { return roleExists; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public boolean isExists() { return roleExists; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
@Test public void testGetBuilder() { assertNotNull(objJPAEdmReferentialConstraintRole.getBuilder()); }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmRefConstraintRoleBuilder(); } return builder; }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmRefConstraintRoleBuilder(); } return builder; } }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmRefConstraintRoleBuilder(); } return builder; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmRefConstraintRoleBuilder(); } return builder; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmRefConstraintRoleBuilder(); } return builder; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
@Test public void testGetBuilderIdempotent() { JPAEdmBuilder builder1 = objJPAEdmReferentialConstraintRole .getBuilder(); JPAEdmBuilder builder2 = objJPAEdmReferentialConstraintRole .getBuilder(); assertEquals(builder1.hashCode(), builder2.hashCode()); }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmRefConstraintRoleBuilder(); } return builder; }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmRefConstraintRoleBuilder(); } return builder; } }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmRefConstraintRoleBuilder(); } return builder; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmRefConstraintRoleBuilder(); } return builder; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmRefConstraintRoleBuilder(); } return builder; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
@Test public void testGetRoleTypePrincipal() { assertEquals(objJPAEdmReferentialConstraintRole.getRoleType(), RoleType.PRINCIPAL); }
@Override public RoleType getRoleType() { return roleType; }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public RoleType getRoleType() { return roleType; } }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public RoleType getRoleType() { return roleType; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public RoleType getRoleType() { return roleType; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public RoleType getRoleType() { return roleType; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
@Test public void testManager() { Manager manager = new Manager(1, "Walter Winter"); Employee employee = new Employee(2, "Peter Burke"); Manager manager2 = new Manager(3, "Jonathan Smith"); List<Employee> list = Arrays.asList(manager2, employee, manager); manager.getEmployees().addAll(list); for (Employee emp : list) { emp.setManager(manager); } assertEquals(list, manager.getEmployees()); assertEquals(manager, employee.getManager()); }
public Manager(final int id, final String name) { super(id, name); }
Manager extends Employee { public Manager(final int id, final String name) { super(id, name); } }
Manager extends Employee { public Manager(final int id, final String name) { super(id, name); } Manager(final int id, final String name); }
Manager extends Employee { public Manager(final int id, final String name) { super(id, name); } Manager(final int id, final String name); List<Employee> getEmployees(); }
Manager extends Employee { public Manager(final int id, final String name) { super(id, name); } Manager(final int id, final String name); List<Employee> getEmployees(); }
@Test public void testGetEdmReferentialConstraintRole() { try { objJPAEdmReferentialConstraintRole.getBuilder().build(); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } assertNotNull(objJPAEdmReferentialConstraintRole .getEdmReferentialConstraintRole()); }
@Override public ReferentialConstraintRole getEdmReferentialConstraintRole() { return currentRole; }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public ReferentialConstraintRole getEdmReferentialConstraintRole() { return currentRole; } }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public ReferentialConstraintRole getEdmReferentialConstraintRole() { return currentRole; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public ReferentialConstraintRole getEdmReferentialConstraintRole() { return currentRole; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public ReferentialConstraintRole getEdmReferentialConstraintRole() { return currentRole; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
@Test public void testGetJPAColumnName() { assertNull(objJPAEdmReferentialConstraintRole.getJPAColumnName()); }
@Override public String getJPAColumnName() { return null; }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public String getJPAColumnName() { return null; } }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public String getJPAColumnName() { return null; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public String getJPAColumnName() { return null; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public String getJPAColumnName() { return null; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
@Test public void testGetEdmEntityTypeName() { assertNull(objJPAEdmReferentialConstraintRole.getEdmEntityTypeName()); }
@Override public String getEdmEntityTypeName() { return null; }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public String getEdmEntityTypeName() { return null; } }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public String getEdmEntityTypeName() { return null; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public String getEdmEntityTypeName() { return null; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public String getEdmEntityTypeName() { return null; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
@Test public void testGetEdmAssociationName() { assertNull(objJPAEdmReferentialConstraintRole.getEdmAssociationName()); }
@Override public String getEdmAssociationName() { return null; }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public String getEdmAssociationName() { return null; } }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public String getEdmAssociationName() { return null; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public String getEdmAssociationName() { return null; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView { @Override public String getEdmAssociationName() { return null; } JPAEdmReferentialConstraintRole( final JPAEdmReferentialConstraintRoleView.RoleType roleType, final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final JPAEdmAssociationView associationView); @Override boolean isExists(); @Override JPAEdmBuilder getBuilder(); @Override RoleType getRoleType(); @Override ReferentialConstraintRole getEdmReferentialConstraintRole(); @Override String getJPAColumnName(); @Override String getEdmEntityTypeName(); @Override String getEdmAssociationName(); }
@Test public void testGetBuilder() { assertNotNull(objJPAEdmEntityType.getBuilder()); }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmEntityTypeBuilder(); } return builder; }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmEntityTypeBuilder(); } return builder; } }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmEntityTypeBuilder(); } return builder; } JPAEdmEntityType(final JPAEdmSchemaView view); }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmEntityTypeBuilder(); } return builder; } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmEntityTypeBuilder(); } return builder; } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); }
@Test public void testGetBuilderIdempotent() { JPAEdmBuilder builder1 = objJPAEdmEntityType.getBuilder(); JPAEdmBuilder builder2 = objJPAEdmEntityType.getBuilder(); assertEquals(builder1.hashCode(), builder2.hashCode()); }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmEntityTypeBuilder(); } return builder; }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmEntityTypeBuilder(); } return builder; } }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmEntityTypeBuilder(); } return builder; } JPAEdmEntityType(final JPAEdmSchemaView view); }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmEntityTypeBuilder(); } return builder; } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmEntityTypeBuilder(); } return builder; } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); }
@Test public void testGetEdmEntityType() { assertNotNull(objJPAEdmEntityType.getEdmEntityType()); assertNotNull(objJPAEdmEntityType.getEdmEntityType().getKey()); }
@Override public EntityType getEdmEntityType() { return currentEdmEntityType; }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public EntityType getEdmEntityType() { return currentEdmEntityType; } }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public EntityType getEdmEntityType() { return currentEdmEntityType; } JPAEdmEntityType(final JPAEdmSchemaView view); }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public EntityType getEdmEntityType() { return currentEdmEntityType; } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public EntityType getEdmEntityType() { return currentEdmEntityType; } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); }
@Test public void testGetJPAEntityType() { assertNotNull(objJPAEdmEntityType.getJPAEntityType()); }
@Override public javax.persistence.metamodel.EntityType<?> getJPAEntityType() { return currentJPAEntityType; }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public javax.persistence.metamodel.EntityType<?> getJPAEntityType() { return currentJPAEntityType; } }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public javax.persistence.metamodel.EntityType<?> getJPAEntityType() { return currentJPAEntityType; } JPAEdmEntityType(final JPAEdmSchemaView view); }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public javax.persistence.metamodel.EntityType<?> getJPAEntityType() { return currentJPAEntityType; } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public javax.persistence.metamodel.EntityType<?> getJPAEntityType() { return currentJPAEntityType; } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); }
@Test public void testGetConsistentEdmEntityTypes() { assertTrue(objJPAEdmEntityType.getConsistentEdmEntityTypes().size() > 0); }
@Override public List<EntityType> getConsistentEdmEntityTypes() { return consistentEntityTypes; }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public List<EntityType> getConsistentEdmEntityTypes() { return consistentEntityTypes; } }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public List<EntityType> getConsistentEdmEntityTypes() { return consistentEntityTypes; } JPAEdmEntityType(final JPAEdmSchemaView view); }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public List<EntityType> getConsistentEdmEntityTypes() { return consistentEntityTypes; } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public List<EntityType> getConsistentEdmEntityTypes() { return consistentEntityTypes; } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); }
@Test public void testSearchEdmEntityType() { assertNotNull(objJPAEdmEntityType.searchEdmEntityType("SalesOrderHeader")); }
@Override public EntityType searchEdmEntityType(final String jpaEntityTypeName) { return consistentEntityTypeMap.get(jpaEntityTypeName); }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public EntityType searchEdmEntityType(final String jpaEntityTypeName) { return consistentEntityTypeMap.get(jpaEntityTypeName); } }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public EntityType searchEdmEntityType(final String jpaEntityTypeName) { return consistentEntityTypeMap.get(jpaEntityTypeName); } JPAEdmEntityType(final JPAEdmSchemaView view); }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public EntityType searchEdmEntityType(final String jpaEntityTypeName) { return consistentEntityTypeMap.get(jpaEntityTypeName); } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); }
JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView { @Override public EntityType searchEdmEntityType(final String jpaEntityTypeName) { return consistentEntityTypeMap.get(jpaEntityTypeName); } JPAEdmEntityType(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override EntityType getEdmEntityType(); @Override javax.persistence.metamodel.EntityType<?> getJPAEntityType(); @Override List<EntityType> getConsistentEdmEntityTypes(); @Override EntityType searchEdmEntityType(final String jpaEntityTypeName); }
@Test public void testRoom() { Employee manager = new Manager(1, null); Room room = new Room(1, null); room.getEmployees().add(manager); manager.setRoom(room); assertEquals(room, manager.getRoom()); assertEquals(manager, room.getEmployees().get(0)); }
public List<Employee> getEmployees() { return employees; }
Manager extends Employee { public List<Employee> getEmployees() { return employees; } }
Manager extends Employee { public List<Employee> getEmployees() { return employees; } Manager(final int id, final String name); }
Manager extends Employee { public List<Employee> getEmployees() { return employees; } Manager(final int id, final String name); List<Employee> getEmployees(); }
Manager extends Employee { public List<Employee> getEmployees() { return employees; } Manager(final int id, final String name); List<Employee> getEmployees(); }
@Test public void testFunctionImportBasic() { VARIANT = 0; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); for (FunctionImport functionImport : functionImportList) { assertEquals(functionImport.getName(), "Method1"); assertNotNull(functionImport.getMapping()); Mapping mapping = new Mapping(); mapping.setInternalName("method1"); assertEquals(mapping.getInternalName(), functionImport.getMapping() .getInternalName()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity()); List<FunctionImportParameter> funcImpList = functionImport .getParameters(); assertEquals(2, funcImpList.size()); assertEquals("Param1", funcImpList.get(0).getName()); assertEquals(EdmSimpleTypeKind.String, funcImpList.get(0).getType()); assertEquals(Mode.IN.toString(), funcImpList.get(0).getMode()); assertEquals("Param3", funcImpList.get(1).getName()); assertEquals(EdmSimpleTypeKind.Double, funcImpList.get(1).getType()); assertEquals(Mode.IN.toString(), funcImpList.get(1).getMode()); } }
@Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testFunctionImportNoSuchMethod() { VARIANT = 1; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 0); }
@Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testFunctionImportAllMethods() { VARIANT = 2; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(METHOD_COUNT, functionImportList.size()); }
@Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testFunctionImportNoName() { VARIANT = 3; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); FunctionImport functionImport = functionImportList.get(0); assertEquals(functionImport.getName(), "method3"); assertNotNull(functionImport.getMapping()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity()); assertEquals(returnType.getTypeName().toString(), EdmSimpleTypeKind.Int32.getFullQualifiedName().toString()); }
@Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testNoReturnType() { VARIANT = 4; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 0); }
@Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testNoEntitySet() { VARIANT = 5; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals(ODataJPAModelException.FUNC_ENTITYSET_EXP.getKey(), e .getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testNoReturnTypeButAnnotated() { VARIANT = 6; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testFunctionImportEntityTypeSingleReturn() { VARIANT = 7; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); FunctionImport functionImport = functionImportList.get(0); assertEquals(functionImport.getName(), "method7"); assertNotNull(functionImport.getMapping()); JPAEdmMapping mapping = (JPAEdmMapping) functionImport.getMapping(); assertEquals(JPACustomProcessorMock.class, mapping.getJPAType()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity()); assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "." + JPACustomProcessorMock.edmName); }
@Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testFunctionImportEntityTypeInvalid() { VARIANT = 8; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals( ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND .getKey(), e.getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testFunctionImportComplexType() { VARIANT = 9; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); FunctionImport functionImport = functionImportList.get(0); assertEquals(functionImport.getName(), "method9"); assertNotNull(functionImport.getMapping()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity()); assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "." + JPACustomProcessorMock.edmName); }
@Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testTeam() { Employee manager = new Manager(1, null); List<Employee> list = Arrays.asList(manager); Team team = new Team(1, TEAM_NAME); team.getEmployees().add(manager); manager.setTeam(team); assertEquals(team, manager.getTeam()); assertEquals(list, team.getEmployees()); }
public List<Employee> getEmployees() { return employees; }
Manager extends Employee { public List<Employee> getEmployees() { return employees; } }
Manager extends Employee { public List<Employee> getEmployees() { return employees; } Manager(final int id, final String name); }
Manager extends Employee { public List<Employee> getEmployees() { return employees; } Manager(final int id, final String name); List<Employee> getEmployees(); }
Manager extends Employee { public List<Employee> getEmployees() { return employees; } Manager(final int id, final String name); List<Employee> getEmployees(); }
@Test public void testFunctionImportComplexTypeMany() { VARIANT = 10; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); FunctionImport functionImport = functionImportList.get(0); assertEquals(functionImport.getName(), "method10"); assertNotNull(functionImport.getMapping()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity()); assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "." + JPACustomProcessorMock.edmName); }
@Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testFunctionImportComplexTypeInvalid() { VARIANT = 11; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals( ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND .getKey(), e.getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testFunctionImportScalarTypeInvalid() { VARIANT = 12; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals(ODataJPAModelException.TYPE_NOT_SUPPORTED.getKey(), e .getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testFunctionImportParamNoName() { VARIANT = 13; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals(ODataJPAModelException.FUNC_PARAM_NAME_EXP.getKey(), e .getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testFunctionImportParamFacets() { VARIANT = 14; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); List<FunctionImportParameter> funcImpParamList = functionImportList .get(0).getParameters(); EdmFacets facets = funcImpParamList.get(0).getFacets(); assertNotNull(facets); assertEquals(2, facets.getMaxLength().intValue()); assertEquals(true, facets.isNullable()); facets = funcImpParamList.get(1).getFacets(); assertNotNull(facets); assertEquals(false, facets.isNullable()); assertEquals(10, facets.getPrecision().intValue()); assertEquals(2, facets.getScale().intValue()); }
@Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testFunctionImportParamFacetsDefault() { VARIANT = 15; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); List<FunctionImportParameter> funcImpParamList = functionImportList .get(0).getParameters(); EdmFacets facets = funcImpParamList.get(0).getFacets(); assertNotNull(facets); assertNull(facets.getMaxLength()); assertEquals(false, facets.isNullable()); assertNull(facets.getPrecision()); assertNull(facets.getScale()); }
@Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testWrongReturnTypeScalar() { VARIANT = 16; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e .getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testWrongReturnTypeComplex() { VARIANT = 17; try { jpaEdmfunctionImport.getBuilder().build(); fail("Exception Expected"); } catch (ODataJPAModelException e) { assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e .getMessageReference().getKey()); } catch (ODataJPARuntimeException e) { fail("Model Exception Expected"); } }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testNoFunctionImport() { VARIANT = 99; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport .getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 0); }
@Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testGetBuilderIdempotent() { JPAEdmFunctionImport jpaEdmfunctionImport = new JPAEdmFunctionImport( this); JPAEdmBuilder builder1 = jpaEdmfunctionImport.getBuilder(); JPAEdmBuilder builder2 = jpaEdmfunctionImport.getBuilder(); assertEquals(builder1.hashCode(), builder2.hashCode()); }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmFunctionImportBuilder(); } return builder; } JPAEdmFunctionImport(final JPAEdmSchemaView view); @Override JPAEdmBuilder getBuilder(); @Override List<FunctionImport> getConsistentFunctionImportList(); }
@Test public void testEmployees() { Manager manager = new Manager(1, null); Employee employee1 = new Employee(2, null); Employee employee2 = new Employee(3, null); List<Employee> employeesList = Arrays.asList(employee1, employee2); manager.getEmployees().addAll(employeesList); for (Employee emp : employeesList) { emp.setManager(manager); } List<Employee> testList = manager.getEmployees(); assertEquals(testList, employeesList); assertEquals(manager, employee1.getManager()); }
public List<Employee> getEmployees() { return employees; }
Manager extends Employee { public List<Employee> getEmployees() { return employees; } }
Manager extends Employee { public List<Employee> getEmployees() { return employees; } Manager(final int id, final String name); }
Manager extends Employee { public List<Employee> getEmployees() { return employees; } Manager(final int id, final String name); List<Employee> getEmployees(); }
Manager extends Employee { public List<Employee> getEmployees() { return employees; } Manager(final int id, final String name); List<Employee> getEmployees(); }
@Test public void testGetBuilder() { assertNotNull(objJPAEdmProperty.getBuilder()); objJPAEdmPropertyTest = new JPAEdmPropertyTest(); objJPAEdmProperty = new JPAEdmProperty(objJPAEdmPropertyTest, objJPAEdmPropertyTest); try { objJPAEdmProperty.getBuilder().build(); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; } }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
@Test public void testGetBuilderIdempotent() { JPAEdmBuilder builder1 = objJPAEdmProperty.getBuilder(); JPAEdmBuilder builder2 = objJPAEdmProperty.getBuilder(); assertEquals(builder1.hashCode(), builder2.hashCode()); }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; } }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
@Test public void testGetPropertyList() { assertNotNull(objJPAEdmProperty.getEdmPropertyList()); assertTrue(objJPAEdmProperty.getEdmPropertyList().size() > 0); }
@Override public List<Property> getEdmPropertyList() { return properties; }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public List<Property> getEdmPropertyList() { return properties; } }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public List<Property> getEdmPropertyList() { return properties; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public List<Property> getEdmPropertyList() { return properties; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public List<Property> getEdmPropertyList() { return properties; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
@Test public void testGetJPAEdmKeyView() { assertNotNull(objJPAEdmProperty.getJPAEdmKeyView()); }
@Override public JPAEdmKeyView getJPAEdmKeyView() { return keyView; }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmKeyView getJPAEdmKeyView() { return keyView; } }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmKeyView getJPAEdmKeyView() { return keyView; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmKeyView getJPAEdmKeyView() { return keyView; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmKeyView getJPAEdmKeyView() { return keyView; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
@Test public void testGetSimpleProperty() { assertNotNull(objJPAEdmProperty.getEdmSimpleProperty()); }
@Override public SimpleProperty getEdmSimpleProperty() { return currentSimpleProperty; }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public SimpleProperty getEdmSimpleProperty() { return currentSimpleProperty; } }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public SimpleProperty getEdmSimpleProperty() { return currentSimpleProperty; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public SimpleProperty getEdmSimpleProperty() { return currentSimpleProperty; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public SimpleProperty getEdmSimpleProperty() { return currentSimpleProperty; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
@Test public void testGetJPAAttribute() { assertNotNull(objJPAEdmProperty.getJPAAttribute()); }
@Override public Attribute<?, ?> getJPAAttribute() { return currentAttribute; }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public Attribute<?, ?> getJPAAttribute() { return currentAttribute; } }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public Attribute<?, ?> getJPAAttribute() { return currentAttribute; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public Attribute<?, ?> getJPAAttribute() { return currentAttribute; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public Attribute<?, ?> getJPAAttribute() { return currentAttribute; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
@Test public void testGetEdmComplexProperty() { assertNull(objJPAEdmProperty.getEdmComplexProperty()); }
@Override public ComplexProperty getEdmComplexProperty() { return currentComplexProperty; }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public ComplexProperty getEdmComplexProperty() { return currentComplexProperty; } }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public ComplexProperty getEdmComplexProperty() { return currentComplexProperty; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public ComplexProperty getEdmComplexProperty() { return currentComplexProperty; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public ComplexProperty getEdmComplexProperty() { return currentComplexProperty; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
@Test public void testGetJPAEdmNavigationPropertyView() { assertNotNull(objJPAEdmProperty.getJPAEdmNavigationPropertyView()); }
@Override public JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView() { return navigationPropertyView; }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView() { return navigationPropertyView; } }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView() { return navigationPropertyView; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView() { return navigationPropertyView; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView() { return navigationPropertyView; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
@Test public void testBuildManyToOne() { ATTRIBUTE_TYPE = 3; objJPAEdmPropertyTest = new JPAEdmPropertyTest(); objJPAEdmProperty = new JPAEdmProperty(objJPAEdmPropertyTest); try { objJPAEdmProperty.getBuilder().build(); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } ATTRIBUTE_TYPE = 1; objJPAEdmPropertyTest = new JPAEdmPropertyTest(); objJPAEdmProperty = new JPAEdmProperty(objJPAEdmPropertyTest); try { objJPAEdmProperty.getBuilder().build(); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; } }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
JPAEdmProperty extends JPAEdmBaseViewImpl implements JPAEdmPropertyView, JPAEdmComplexPropertyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmPropertyBuilder(); } return builder; } JPAEdmProperty(final JPAEdmSchemaView view); JPAEdmProperty(final JPAEdmSchemaView schemaView, final JPAEdmComplexTypeView view); @Override JPAEdmBuilder getBuilder(); @Override List<Property> getEdmPropertyList(); @Override JPAEdmKeyView getJPAEdmKeyView(); @Override SimpleProperty getEdmSimpleProperty(); @Override Attribute<?, ?> getJPAAttribute(); @Override ComplexProperty getEdmComplexProperty(); @Override JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView(); @Override JPAEdmEntityTypeView getJPAEdmEntityTypeView(); @Override JPAEdmComplexTypeView getJPAEdmComplexTypeView(); }
@Test public void testGetBuilderIdempotent() { JPAEdmBuilder builder1 = keyView.getBuilder(); JPAEdmBuilder builder2 = keyView.getBuilder(); assertEquals(builder1.hashCode(), builder2.hashCode()); }
@Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmKeyBuider(); } return builder; }
JPAEdmKey extends JPAEdmBaseViewImpl implements JPAEdmKeyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmKeyBuider(); } return builder; } }
JPAEdmKey extends JPAEdmBaseViewImpl implements JPAEdmKeyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmKeyBuider(); } return builder; } JPAEdmKey(final JPAEdmProperty view); JPAEdmKey(final JPAEdmComplexTypeView complexTypeView, final JPAEdmPropertyView propertyView); }
JPAEdmKey extends JPAEdmBaseViewImpl implements JPAEdmKeyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmKeyBuider(); } return builder; } JPAEdmKey(final JPAEdmProperty view); JPAEdmKey(final JPAEdmComplexTypeView complexTypeView, final JPAEdmPropertyView propertyView); @Override JPAEdmBuilder getBuilder(); @Override Key getEdmKey(); }
JPAEdmKey extends JPAEdmBaseViewImpl implements JPAEdmKeyView { @Override public JPAEdmBuilder getBuilder() { if (builder == null) { builder = new JPAEdmKeyBuider(); } return builder; } JPAEdmKey(final JPAEdmProperty view); JPAEdmKey(final JPAEdmComplexTypeView complexTypeView, final JPAEdmPropertyView propertyView); @Override JPAEdmBuilder getBuilder(); @Override Key getEdmKey(); }
@Test public void testProcessGetEntitySetCountUriInfo() { try { Assert.assertEquals(11, objJPAProcessorImpl.process(getEntitySetCountUriInfo())); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") @Override List<Object> process(final GetFunctionImportUriInfo uriParserResultView); @SuppressWarnings("unchecked") @Override List<T> process(final GetEntitySetUriInfo uriParserResultView); @Override Object process(GetEntityUriInfo uriParserResultView); @Override long process(final GetEntitySetCountUriInfo resultsView); @Override long process(final GetEntityCountUriInfo resultsView); @Override List<T> process(final PostUriInfo createView, final InputStream content, final String requestedContentType); @Override List<T> process(final PostUriInfo createView, final Map<String, Object> content); @Override Object process(final PutMergePatchUriInfo updateView, final InputStream content, final String requestContentType); @Override Object process(final PutMergePatchUriInfo updateView, final Map<String, Object> content); Object processUpdate(PutMergePatchUriInfo updateView, final InputStream content, final Map<String, Object> properties, final String requestContentType); @Override Object process(DeleteUriInfo uriParserResultView, final String contentType); @Override Object process(final GetEntityLinkUriInfo uriParserResultView); @Override List<T> process(final GetEntitySetLinksUriInfo uriParserResultView); @Override void process(final PostUriInfo uriInfo, final InputStream content, final String requestContentType, final String contentType); @Override void process(final PutMergePatchUriInfo putUriInfo, final InputStream content, final String requestContentType, final String contentType); }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") @Override List<Object> process(final GetFunctionImportUriInfo uriParserResultView); @SuppressWarnings("unchecked") @Override List<T> process(final GetEntitySetUriInfo uriParserResultView); @Override Object process(GetEntityUriInfo uriParserResultView); @Override long process(final GetEntitySetCountUriInfo resultsView); @Override long process(final GetEntityCountUriInfo resultsView); @Override List<T> process(final PostUriInfo createView, final InputStream content, final String requestedContentType); @Override List<T> process(final PostUriInfo createView, final Map<String, Object> content); @Override Object process(final PutMergePatchUriInfo updateView, final InputStream content, final String requestContentType); @Override Object process(final PutMergePatchUriInfo updateView, final Map<String, Object> content); Object processUpdate(PutMergePatchUriInfo updateView, final InputStream content, final Map<String, Object> properties, final String requestContentType); @Override Object process(DeleteUriInfo uriParserResultView, final String contentType); @Override Object process(final GetEntityLinkUriInfo uriParserResultView); @Override List<T> process(final GetEntitySetLinksUriInfo uriParserResultView); @Override void process(final PostUriInfo uriInfo, final InputStream content, final String requestContentType, final String contentType); @Override void process(final PutMergePatchUriInfo putUriInfo, final InputStream content, final String requestContentType, final String contentType); }
@SuppressWarnings("unchecked") @Test public void testConstructListofNavProperty() { List<ArrayList<NavigationPropertySegment>> expand = new ArrayList<ArrayList<NavigationPropertySegment>>(); ArrayList<NavigationPropertySegment> navPropList1 = new ArrayList<NavigationPropertySegment>(); navPropList1.add(getNavigationPropertySegment("DemoNavigationProperties11")); navPropList1.add(getNavigationPropertySegment("DemoNavigationProperties12")); expand.add(navPropList1); ArrayList<NavigationPropertySegment> navPropList2 = new ArrayList<NavigationPropertySegment>(); navPropList2.add(getNavigationPropertySegment("DemoNavigationProperties21")); navPropList2.add(getNavigationPropertySegment("DemoNavigationProperties22")); expand.add(navPropList2); Class<?> clazz = ODataJPAResponseBuilder.class; Object[] actualParameters = { expand }; Class<?>[] formalParameters = { List.class }; List<EdmNavigationProperty> navigationProperties = null; try { ODataJPAResponseBuilder responseBuilder = (ODataJPAResponseBuilder) clazz .newInstance(); Method method = clazz.getDeclaredMethod( "constructListofNavProperty", formalParameters); method.setAccessible(true); navigationProperties = (List<EdmNavigationProperty>) method.invoke( responseBuilder, actualParameters); assertEquals("DemoNavigationProperties21", navigationProperties.get(1).getName()); assertEquals("DemoNavigationProperties11", navigationProperties.get(0).getName()); } catch (SecurityException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (NoSuchMethodException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (IllegalArgumentException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (IllegalAccessException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (InvocationTargetException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (InstantiationException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (EdmException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
private static List<EdmNavigationProperty> constructListofNavProperty( final List<ArrayList<NavigationPropertySegment>> expandList) { List<EdmNavigationProperty> navigationPropertyList = new ArrayList<EdmNavigationProperty>(); for (ArrayList<NavigationPropertySegment> navpropSegment : expandList) { navigationPropertyList.add(navpropSegment.get(0) .getNavigationProperty()); } return navigationPropertyList; }
ODataJPAResponseBuilder { private static List<EdmNavigationProperty> constructListofNavProperty( final List<ArrayList<NavigationPropertySegment>> expandList) { List<EdmNavigationProperty> navigationPropertyList = new ArrayList<EdmNavigationProperty>(); for (ArrayList<NavigationPropertySegment> navpropSegment : expandList) { navigationPropertyList.add(navpropSegment.get(0) .getNavigationProperty()); } return navigationPropertyList; } }
ODataJPAResponseBuilder { private static List<EdmNavigationProperty> constructListofNavProperty( final List<ArrayList<NavigationPropertySegment>> expandList) { List<EdmNavigationProperty> navigationPropertyList = new ArrayList<EdmNavigationProperty>(); for (ArrayList<NavigationPropertySegment> navpropSegment : expandList) { navigationPropertyList.add(navpropSegment.get(0) .getNavigationProperty()); } return navigationPropertyList; } }
ODataJPAResponseBuilder { private static List<EdmNavigationProperty> constructListofNavProperty( final List<ArrayList<NavigationPropertySegment>> expandList) { List<EdmNavigationProperty> navigationPropertyList = new ArrayList<EdmNavigationProperty>(); for (ArrayList<NavigationPropertySegment> navpropSegment : expandList) { navigationPropertyList.add(navpropSegment.get(0) .getNavigationProperty()); } return navigationPropertyList; } static ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final long jpaEntityCount, final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") static ODataResponse build(final List<Object> createdObjectList, final PostUriInfo uriInfo, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object updatedObject, final PutMergePatchUriInfo putUriInfo); static ODataResponse build(final Object deletedObject, final DeleteUriInfo deleteUriInfo); static ODataResponse build(final Object result, final GetFunctionImportUriInfo resultsView); static ODataResponse build(final List<Object> resultList, final GetFunctionImportUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityLinkUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final List<T> jpaEntities, final GetEntitySetLinksUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); }
ODataJPAResponseBuilder { private static List<EdmNavigationProperty> constructListofNavProperty( final List<ArrayList<NavigationPropertySegment>> expandList) { List<EdmNavigationProperty> navigationPropertyList = new ArrayList<EdmNavigationProperty>(); for (ArrayList<NavigationPropertySegment> navpropSegment : expandList) { navigationPropertyList.add(navpropSegment.get(0) .getNavigationProperty()); } return navigationPropertyList; } static ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final long jpaEntityCount, final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") static ODataResponse build(final List<Object> createdObjectList, final PostUriInfo uriInfo, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object updatedObject, final PutMergePatchUriInfo putUriInfo); static ODataResponse build(final Object deletedObject, final DeleteUriInfo deleteUriInfo); static ODataResponse build(final Object result, final GetFunctionImportUriInfo resultsView); static ODataResponse build(final List<Object> resultList, final GetFunctionImportUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityLinkUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final List<T> jpaEntities, final GetEntitySetLinksUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); }
@Test public void testBuildListOfTGetEntitySetUriInfoStringODataJPAContext() { try { assertNotNull(ODataJPAResponseBuilder.build(getJPAEntities(), getResultsView(), "application/xml", getODataJPAContext())); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } static ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final long jpaEntityCount, final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") static ODataResponse build(final List<Object> createdObjectList, final PostUriInfo uriInfo, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object updatedObject, final PutMergePatchUriInfo putUriInfo); static ODataResponse build(final Object deletedObject, final DeleteUriInfo deleteUriInfo); static ODataResponse build(final Object result, final GetFunctionImportUriInfo resultsView); static ODataResponse build(final List<Object> resultList, final GetFunctionImportUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityLinkUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final List<T> jpaEntities, final GetEntitySetLinksUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } static ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final long jpaEntityCount, final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") static ODataResponse build(final List<Object> createdObjectList, final PostUriInfo uriInfo, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object updatedObject, final PutMergePatchUriInfo putUriInfo); static ODataResponse build(final Object deletedObject, final DeleteUriInfo deleteUriInfo); static ODataResponse build(final Object result, final GetFunctionImportUriInfo resultsView); static ODataResponse build(final List<Object> resultList, final GetFunctionImportUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityLinkUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final List<T> jpaEntities, final GetEntitySetLinksUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); }
@Test public void testBuildNegatives() { try { EntityType entity = new EntityType(); entity.setName("SalesOrderHeader"); try { assertNotNull(ODataJPAResponseBuilder.build(getEntity(), getLocalGetURIInfo(), "xml", getODataJPAContext())); } catch (ODataNotFoundException e) { assertTrue(true); } } catch (ODataJPARuntimeException e) { assertTrue(true); } try { assertNotNull(ODataJPAResponseBuilder.build(getJPAEntities(), getResultsView(), "xml", getODataJPAContext())); } catch (ODataJPARuntimeException e) { assertTrue(true); } }
public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } static ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final long jpaEntityCount, final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") static ODataResponse build(final List<Object> createdObjectList, final PostUriInfo uriInfo, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object updatedObject, final PutMergePatchUriInfo putUriInfo); static ODataResponse build(final Object deletedObject, final DeleteUriInfo deleteUriInfo); static ODataResponse build(final Object result, final GetFunctionImportUriInfo resultsView); static ODataResponse build(final List<Object> resultList, final GetFunctionImportUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityLinkUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final List<T> jpaEntities, final GetEntitySetLinksUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } static ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final long jpaEntityCount, final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") static ODataResponse build(final List<Object> createdObjectList, final PostUriInfo uriInfo, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object updatedObject, final PutMergePatchUriInfo putUriInfo); static ODataResponse build(final Object deletedObject, final DeleteUriInfo deleteUriInfo); static ODataResponse build(final Object result, final GetFunctionImportUriInfo resultsView); static ODataResponse build(final List<Object> resultList, final GetFunctionImportUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityLinkUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final List<T> jpaEntities, final GetEntitySetLinksUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); }
@Test public void testBuildObjectGetEntityUriInfoStringODataJPAContext() throws ODataNotFoundException { try { assertNotNull(ODataJPAResponseBuilder.build(new SalesOrderHeader(2, 10), getLocalGetURIInfo(), "application/xml", getODataJPAContext())); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } static ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final long jpaEntityCount, final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") static ODataResponse build(final List<Object> createdObjectList, final PostUriInfo uriInfo, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object updatedObject, final PutMergePatchUriInfo putUriInfo); static ODataResponse build(final Object deletedObject, final DeleteUriInfo deleteUriInfo); static ODataResponse build(final Object result, final GetFunctionImportUriInfo resultsView); static ODataResponse build(final List<Object> resultList, final GetFunctionImportUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityLinkUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final List<T> jpaEntities, final GetEntitySetLinksUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } static ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final long jpaEntityCount, final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") static ODataResponse build(final List<Object> createdObjectList, final PostUriInfo uriInfo, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object updatedObject, final PutMergePatchUriInfo putUriInfo); static ODataResponse build(final Object deletedObject, final DeleteUriInfo deleteUriInfo); static ODataResponse build(final Object result, final GetFunctionImportUriInfo resultsView); static ODataResponse build(final List<Object> resultList, final GetFunctionImportUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityLinkUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final List<T> jpaEntities, final GetEntitySetLinksUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); }
@Test public void testBuildNullSelects() { try { ODataJPAResponseBuilder.build(getJPAEntities(), getResultsViewWithNullSelects(), "xml", getODataJPAContext()); } catch (ODataJPARuntimeException e) { assertTrue(true); } catch (Exception e) { assertTrue(true); } }
public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } static ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final long jpaEntityCount, final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") static ODataResponse build(final List<Object> createdObjectList, final PostUriInfo uriInfo, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object updatedObject, final PutMergePatchUriInfo putUriInfo); static ODataResponse build(final Object deletedObject, final DeleteUriInfo deleteUriInfo); static ODataResponse build(final Object result, final GetFunctionImportUriInfo resultsView); static ODataResponse build(final List<Object> resultList, final GetFunctionImportUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityLinkUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final List<T> jpaEntities, final GetEntitySetLinksUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } static ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final long jpaEntityCount, final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") static ODataResponse build(final List<Object> createdObjectList, final PostUriInfo uriInfo, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object updatedObject, final PutMergePatchUriInfo putUriInfo); static ODataResponse build(final Object deletedObject, final DeleteUriInfo deleteUriInfo); static ODataResponse build(final Object result, final GetFunctionImportUriInfo resultsView); static ODataResponse build(final List<Object> resultList, final GetFunctionImportUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityLinkUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final List<T> jpaEntities, final GetEntitySetLinksUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); }
@Test public void testBuildGetCount() { ODataResponse objODataResponse = null; try { objODataResponse = ODataJPAResponseBuilder.build(1, getODataJPAContext()); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } assertNotNull(objODataResponse); }
public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } static ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final long jpaEntityCount, final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") static ODataResponse build(final List<Object> createdObjectList, final PostUriInfo uriInfo, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object updatedObject, final PutMergePatchUriInfo putUriInfo); static ODataResponse build(final Object deletedObject, final DeleteUriInfo deleteUriInfo); static ODataResponse build(final Object result, final GetFunctionImportUriInfo resultsView); static ODataResponse build(final List<Object> resultList, final GetFunctionImportUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityLinkUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final List<T> jpaEntities, final GetEntitySetLinksUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); }
ODataJPAResponseBuilder { public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; List<ArrayList<NavigationPropertySegment>> expandList = null; try { edmEntityType = resultsView.getTargetEntitySet().getEntityType(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); final List<SelectItem> selectedItems = resultsView.getSelect(); if (selectedItems != null && selectedItems.size() > 0) { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap( jpaEntity, buildSelectItemList(selectedItems, edmEntityType)); edmEntityList.add(edmPropertyValueMap); } } else { for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser .parse2EdmPropertyValueMap(jpaEntity, edmEntityType); edmEntityList.add(edmPropertyValueMap); } } expandList = resultsView.getExpand(); if (expandList != null && expandList.size() != 0) { int count = 0; for (Object jpaEntity : jpaEntities) { Map<String, Object> relationShipMap = edmEntityList.get(count); HashMap<String, Object> navigationMap = jpaResultParser.parse2EdmNavigationValueMap( jpaEntity, constructListofNavProperty(expandList)); relationShipMap.putAll(navigationMap); count++; } } EntityProviderWriteProperties feedProperties = null; feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList); odataResponse = EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse) .status(HttpStatusCodes.OK).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } return odataResponse; } static ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView, final String contentType, final ODataJPAContext odataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final long jpaEntityCount, final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") static ODataResponse build(final List<Object> createdObjectList, final PostUriInfo uriInfo, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object updatedObject, final PutMergePatchUriInfo putUriInfo); static ODataResponse build(final Object deletedObject, final DeleteUriInfo deleteUriInfo); static ODataResponse build(final Object result, final GetFunctionImportUriInfo resultsView); static ODataResponse build(final List<Object> resultList, final GetFunctionImportUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final Object jpaEntity, final GetEntityLinkUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); static ODataResponse build(final List<T> jpaEntities, final GetEntitySetLinksUriInfo resultsView, final String contentType, final ODataJPAContext oDataJPAContext); }
@Test public void testReadEntitySetGetEntitySetUriInfoString() { try { GetEntityUriInfo getEntityView = getEntityUriInfo(); Assert.assertNotNull(objODataJPAProcessorDefault.readEntity(getEntityView, HttpContentType.APPLICATION_XML)); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e1) { assertTrue(true); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@Override public ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType) throws ODataException { Object jpaEntity = jpaProcessor.process(uriParserResultView); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView, contentType, oDataJPAContext); return oDataResponse; }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType) throws ODataException { Object jpaEntity = jpaProcessor.process(uriParserResultView); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView, contentType, oDataJPAContext); return oDataResponse; } }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType) throws ODataException { Object jpaEntity = jpaProcessor.process(uriParserResultView); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView, contentType, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType) throws ODataException { Object jpaEntity = jpaProcessor.process(uriParserResultView); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView, contentType, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImport( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImportValue( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLink( final GetEntityLinkUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLinks( final GetEntitySetLinksUriInfo uriParserResultView, final String contentType); @Override ODataResponse createEntityLink( final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType) throws ODataException { Object jpaEntity = jpaProcessor.process(uriParserResultView); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView, contentType, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImport( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImportValue( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLink( final GetEntityLinkUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLinks( final GetEntitySetLinksUriInfo uriParserResultView, final String contentType); @Override ODataResponse createEntityLink( final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); }
@Test public void testcountEntitySet() { try { Assert.assertNotNull(objODataJPAProcessorDefault.countEntitySet(getEntitySetCountUriInfo(), HttpContentType.APPLICATION_XML)); Assert.assertEquals(TEXT_PLAIN_CHARSET_UTF_8, objODataJPAProcessorDefault.countEntitySet(getEntitySetCountUriInfo(), HttpContentType.APPLICATION_XML).getHeader(STR_CONTENT_TYPE)); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (Exception e) { assertTrue(true); } }
@Override public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType) throws ODataException { long jpaEntityCount = jpaProcessor.process(uriParserResultView); ODataResponse oDataResponse = ODataJPAResponseBuilder.build( jpaEntityCount, oDataJPAContext); return oDataResponse; }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType) throws ODataException { long jpaEntityCount = jpaProcessor.process(uriParserResultView); ODataResponse oDataResponse = ODataJPAResponseBuilder.build( jpaEntityCount, oDataJPAContext); return oDataResponse; } }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType) throws ODataException { long jpaEntityCount = jpaProcessor.process(uriParserResultView); ODataResponse oDataResponse = ODataJPAResponseBuilder.build( jpaEntityCount, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType) throws ODataException { long jpaEntityCount = jpaProcessor.process(uriParserResultView); ODataResponse oDataResponse = ODataJPAResponseBuilder.build( jpaEntityCount, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImport( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImportValue( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLink( final GetEntityLinkUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLinks( final GetEntitySetLinksUriInfo uriParserResultView, final String contentType); @Override ODataResponse createEntityLink( final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType) throws ODataException { long jpaEntityCount = jpaProcessor.process(uriParserResultView); ODataResponse oDataResponse = ODataJPAResponseBuilder.build( jpaEntityCount, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImport( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImportValue( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLink( final GetEntityLinkUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLinks( final GetEntitySetLinksUriInfo uriParserResultView, final String contentType); @Override ODataResponse createEntityLink( final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); }
@Test public void testExistsEntity() { try { Assert.assertNotNull(objODataJPAProcessorDefault.existsEntity(getEntityCountCountUriInfo(), HttpContentType.APPLICATION_XML)); Assert.assertEquals(TEXT_PLAIN_CHARSET_UTF_8, objODataJPAProcessorDefault.existsEntity(getEntityCountCountUriInfo(), HttpContentType.APPLICATION_XML).getHeader(STR_CONTENT_TYPE)); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (Exception e) { assertTrue(true); } }
@Override public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType) throws ODataException { long jpaEntityCount = jpaProcessor.process(uriInfo); ODataResponse oDataResponse = ODataJPAResponseBuilder.build( jpaEntityCount, oDataJPAContext); return oDataResponse; }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType) throws ODataException { long jpaEntityCount = jpaProcessor.process(uriInfo); ODataResponse oDataResponse = ODataJPAResponseBuilder.build( jpaEntityCount, oDataJPAContext); return oDataResponse; } }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType) throws ODataException { long jpaEntityCount = jpaProcessor.process(uriInfo); ODataResponse oDataResponse = ODataJPAResponseBuilder.build( jpaEntityCount, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType) throws ODataException { long jpaEntityCount = jpaProcessor.process(uriInfo); ODataResponse oDataResponse = ODataJPAResponseBuilder.build( jpaEntityCount, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImport( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImportValue( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLink( final GetEntityLinkUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLinks( final GetEntitySetLinksUriInfo uriParserResultView, final String contentType); @Override ODataResponse createEntityLink( final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType) throws ODataException { long jpaEntityCount = jpaProcessor.process(uriInfo); ODataResponse oDataResponse = ODataJPAResponseBuilder.build( jpaEntityCount, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImport( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImportValue( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLink( final GetEntityLinkUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLinks( final GetEntitySetLinksUriInfo uriParserResultView, final String contentType); @Override ODataResponse createEntityLink( final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); }
@Test public void testDeleteEntity() { try { Assert.assertNotNull(objODataJPAProcessorDefault.deleteEntity(getDeletetUriInfo(), HttpContentType.APPLICATION_XML)); Assert.assertEquals(TEXT_PLAIN_CHARSET_UTF_8, objODataJPAProcessorDefault.countEntitySet(getEntitySetCountUriInfo(), HttpContentType.APPLICATION_XML).getHeader(STR_CONTENT_TYPE)); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@Override public ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType) throws ODataException { Object deletedObj = jpaProcessor.process(uriParserResultView, contentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(deletedObj, uriParserResultView); return oDataResponse; }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType) throws ODataException { Object deletedObj = jpaProcessor.process(uriParserResultView, contentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(deletedObj, uriParserResultView); return oDataResponse; } }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType) throws ODataException { Object deletedObj = jpaProcessor.process(uriParserResultView, contentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(deletedObj, uriParserResultView); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType) throws ODataException { Object deletedObj = jpaProcessor.process(uriParserResultView, contentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(deletedObj, uriParserResultView); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImport( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImportValue( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLink( final GetEntityLinkUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLinks( final GetEntitySetLinksUriInfo uriParserResultView, final String contentType); @Override ODataResponse createEntityLink( final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType) throws ODataException { Object deletedObj = jpaProcessor.process(uriParserResultView, contentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(deletedObj, uriParserResultView); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImport( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImportValue( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLink( final GetEntityLinkUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLinks( final GetEntitySetLinksUriInfo uriParserResultView, final String contentType); @Override ODataResponse createEntityLink( final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); }
@Test public void testProcessGetEntityCountUriInfo() { try { Assert.assertEquals(11, objJPAProcessorImpl.process(getEntityCountUriInfo())); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") @Override List<Object> process(final GetFunctionImportUriInfo uriParserResultView); @SuppressWarnings("unchecked") @Override List<T> process(final GetEntitySetUriInfo uriParserResultView); @Override Object process(GetEntityUriInfo uriParserResultView); @Override long process(final GetEntitySetCountUriInfo resultsView); @Override long process(final GetEntityCountUriInfo resultsView); @Override List<T> process(final PostUriInfo createView, final InputStream content, final String requestedContentType); @Override List<T> process(final PostUriInfo createView, final Map<String, Object> content); @Override Object process(final PutMergePatchUriInfo updateView, final InputStream content, final String requestContentType); @Override Object process(final PutMergePatchUriInfo updateView, final Map<String, Object> content); Object processUpdate(PutMergePatchUriInfo updateView, final InputStream content, final Map<String, Object> properties, final String requestContentType); @Override Object process(DeleteUriInfo uriParserResultView, final String contentType); @Override Object process(final GetEntityLinkUriInfo uriParserResultView); @Override List<T> process(final GetEntitySetLinksUriInfo uriParserResultView); @Override void process(final PostUriInfo uriInfo, final InputStream content, final String requestContentType, final String contentType); @Override void process(final PutMergePatchUriInfo putUriInfo, final InputStream content, final String requestContentType, final String contentType); }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") @Override List<Object> process(final GetFunctionImportUriInfo uriParserResultView); @SuppressWarnings("unchecked") @Override List<T> process(final GetEntitySetUriInfo uriParserResultView); @Override Object process(GetEntityUriInfo uriParserResultView); @Override long process(final GetEntitySetCountUriInfo resultsView); @Override long process(final GetEntityCountUriInfo resultsView); @Override List<T> process(final PostUriInfo createView, final InputStream content, final String requestedContentType); @Override List<T> process(final PostUriInfo createView, final Map<String, Object> content); @Override Object process(final PutMergePatchUriInfo updateView, final InputStream content, final String requestContentType); @Override Object process(final PutMergePatchUriInfo updateView, final Map<String, Object> content); Object processUpdate(PutMergePatchUriInfo updateView, final InputStream content, final Map<String, Object> properties, final String requestContentType); @Override Object process(DeleteUriInfo uriParserResultView, final String contentType); @Override Object process(final GetEntityLinkUriInfo uriParserResultView); @Override List<T> process(final GetEntitySetLinksUriInfo uriParserResultView); @Override void process(final PostUriInfo uriInfo, final InputStream content, final String requestContentType, final String contentType); @Override void process(final PutMergePatchUriInfo putUriInfo, final InputStream content, final String requestContentType, final String contentType); }
@Test public void testCreateEntity() { try { Assert.assertNotNull(objODataJPAProcessorDefault.createEntity(getPostUriInfo(), getMockedInputStreamContent(), HttpContentType.APPLICATION_XML, HttpContentType.APPLICATION_XML)); } catch (ODataException e) { Assert.assertTrue(true); } }
@Override public ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType) throws ODataException { List<Object> createdJpaEntityList = jpaProcessor.process(uriParserResultView, content, requestContentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(createdJpaEntityList, uriParserResultView, contentType, oDataJPAContext); return oDataResponse; }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType) throws ODataException { List<Object> createdJpaEntityList = jpaProcessor.process(uriParserResultView, content, requestContentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(createdJpaEntityList, uriParserResultView, contentType, oDataJPAContext); return oDataResponse; } }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType) throws ODataException { List<Object> createdJpaEntityList = jpaProcessor.process(uriParserResultView, content, requestContentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(createdJpaEntityList, uriParserResultView, contentType, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType) throws ODataException { List<Object> createdJpaEntityList = jpaProcessor.process(uriParserResultView, content, requestContentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(createdJpaEntityList, uriParserResultView, contentType, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImport( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImportValue( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLink( final GetEntityLinkUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLinks( final GetEntitySetLinksUriInfo uriParserResultView, final String contentType); @Override ODataResponse createEntityLink( final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType) throws ODataException { List<Object> createdJpaEntityList = jpaProcessor.process(uriParserResultView, content, requestContentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(createdJpaEntityList, uriParserResultView, contentType, oDataJPAContext); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImport( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImportValue( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLink( final GetEntityLinkUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLinks( final GetEntitySetLinksUriInfo uriParserResultView, final String contentType); @Override ODataResponse createEntityLink( final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); }
@Test public void testUpdateEntity() { try { Assert.assertNotNull(objODataJPAProcessorDefault.updateEntity(getPutUriInfo(), getMockedInputStreamContent(), HttpContentType.APPLICATION_XML, false, HttpContentType.APPLICATION_XML)); } catch (ODataException e) { Assert.assertTrue(true); } }
@Override public ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType) throws ODataException { Object jpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView); return oDataResponse; }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType) throws ODataException { Object jpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView); return oDataResponse; } }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType) throws ODataException { Object jpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType) throws ODataException { Object jpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImport( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImportValue( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLink( final GetEntityLinkUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLinks( final GetEntitySetLinksUriInfo uriParserResultView, final String contentType); @Override ODataResponse createEntityLink( final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); }
ODataJPAProcessorDefault extends ODataJPAProcessor { @Override public ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType) throws ODataException { Object jpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType); ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView); return oDataResponse; } ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext); @Override ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType); @Override ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType); @Override ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType); @Override ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final boolean merge, final String contentType); @Override ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImport( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse executeFunctionImportValue( final GetFunctionImportUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLink( final GetEntityLinkUriInfo uriParserResultView, final String contentType); @Override ODataResponse readEntityLinks( final GetEntitySetLinksUriInfo uriParserResultView, final String contentType); @Override ODataResponse createEntityLink( final PostUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); @Override ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content, final String requestContentType, final String contentType); }
@Test public void testParseWhereExpression() { try { String parsedStr = ODataJPATestConstants.EMPTY_STRING; parsedStr = ODataExpressionParser.parseToJPAWhereExpression( getBinaryExpressionMockedObj(BinaryOperator.EQ, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1), TABLE_ALIAS); assertEquals(EXPECTED_STR_1, parsedStr); parsedStr = ODataJPATestConstants.EMPTY_STRING; CommonExpression exp1 = getBinaryExpressionMockedObj( BinaryOperator.GE, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1); CommonExpression exp2 = getBinaryExpressionMockedObj( BinaryOperator.NE, ExpressionKind.PROPERTY, SALES_ABC, SAMPLE_DATA_XYZ); parsedStr = ODataExpressionParser.parseToJPAWhereExpression( getBinaryExpression(exp1, BinaryOperator.AND, exp2), TABLE_ALIAS); assertEquals(EXPECTED_STR_2, parsedStr); } catch (EdmException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); static final String EMPTY; static Integer methodFlag; }
@Test public void testMoreThanOneBinaryExpression() { String parsedStr = ODataJPATestConstants.EMPTY_STRING; CommonExpression exp1 = getBinaryExpressionMockedObj(BinaryOperator.GE, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1); CommonExpression exp2 = getBinaryExpressionMockedObj(BinaryOperator.NE, ExpressionKind.PROPERTY, SALES_ABC, SAMPLE_DATA_XYZ); try { parsedStr = ODataExpressionParser.parseToJPAWhereExpression( getBinaryExpression(exp1, BinaryOperator.AND, exp2), TABLE_ALIAS); assertEquals(EXPECTED_STR_2, parsedStr); parsedStr = ODataExpressionParser .parseToJPAWhereExpression( getBinaryExpression(exp1, BinaryOperator.OR, exp2), TABLE_ALIAS); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } assertEquals(EXPECTED_STR_3, parsedStr); }
public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); static final String EMPTY; static Integer methodFlag; }
@Test public void testParseFilterExpression() { try { assertEquals(EXPECTED_STR_10, ODataExpressionParser.parseToJPAWhereExpression( getFilterExpressionMockedObj(ExpressionKind.PROPERTY, SALES_ORDER), TABLE_ALIAS)); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); static final String EMPTY; static Integer methodFlag; }
@Test public void testAllBinaryOperators() { String parsedStr1 = ODataJPATestConstants.EMPTY_STRING; String parsedStr2 = ODataJPATestConstants.EMPTY_STRING; CommonExpression exp1 = getBinaryExpressionMockedObj(BinaryOperator.LT, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1); CommonExpression exp2 = getBinaryExpressionMockedObj(BinaryOperator.LE, ExpressionKind.PROPERTY, SALES_ABC, SAMPLE_DATA_XYZ); try { parsedStr1 = ODataExpressionParser.parseToJPAWhereExpression( (BinaryExpression) getBinaryExpression(exp1, BinaryOperator.AND, exp2), TABLE_ALIAS); assertEquals(EXPECTED_STR_4, parsedStr1); CommonExpression exp3 = getBinaryExpressionMockedObj(BinaryOperator.GT, ExpressionKind.PROPERTY, SAMPLE_DATA_LINE_ITEMS, SAMPLE_DATA_2); CommonExpression exp4 = getBinaryExpressionMockedObj(BinaryOperator.GE, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_AMAZON); parsedStr2 = ODataExpressionParser.parseToJPAWhereExpression( getBinaryExpression(exp3, BinaryOperator.AND, exp4), TABLE_ALIAS); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } assertEquals(EXPECTED_STR_5, parsedStr2); }
public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); static final String EMPTY; static Integer methodFlag; }
@Test public void testParseMemberExpression() { try { assertEquals(EXPECTED_STR_6, ODataExpressionParser .parseToJPAWhereExpression( getBinaryExpression( getMemberExpressionMockedObj(ADDRESS, CITY), BinaryOperator.EQ, getLiteralExpressionMockedObj(SAMPLE_DATA_CITY_3)), TABLE_ALIAS)); assertEquals(EXPECTED_STR_7, ODataExpressionParser .parseToJPAWhereExpression( getBinaryExpression( getMultipleMemberExpressionMockedObj(ADDRESS, CITY, AREA), BinaryOperator.EQ, getLiteralExpressionMockedObj(SAMPLE_DATA_BTM)), TABLE_ALIAS)); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); static final String EMPTY; static Integer methodFlag; }
@Test public void testParseMethodExpression() { try { assertEquals(EXPECTED_STR_12, ODataExpressionParser .parseToJPAWhereExpression( getBinaryExpression( getMethodExpressionMockedObj(MethodOperator.SUBSTRINGOF, "'Ru'", "currencyCode", null, 2), BinaryOperator.EQ, getLiteralExpressionMockedObj("true")), TABLE_ALIAS)); assertEquals(EXPECTED_STR_13, ODataExpressionParser .parseToJPAWhereExpression( getBinaryExpression( getMethodExpressionMockedObj(MethodOperator.SUBSTRING, "currencyCode", "1", "2", 3), BinaryOperator.EQ, getLiteralExpressionMockedObj("'NR'")), TABLE_ALIAS)); assertEquals(EXPECTED_STR_14, ODataExpressionParser .parseToJPAWhereExpression( getBinaryExpression( getMethodExpressionMockedObj(MethodOperator.TOLOWER, "currencyCode", null, null, 1), BinaryOperator.EQ, getLiteralExpressionMockedObj("'inr rupees'")), TABLE_ALIAS)); assertEquals(EXPECTED_STR_15, ODataExpressionParser .parseToJPAWhereExpression( getBinaryExpression( getMultipleMethodExpressionMockedObj(MethodOperator.SUBSTRINGOF, "'nr rupees'", MethodOperator.TOLOWER, "currencyCode", 2, 1), BinaryOperator.EQ, getLiteralExpressionMockedObj("true")), TABLE_ALIAS)); assertEquals(EXPECTED_STR_16, ODataExpressionParser .parseToJPAWhereExpression(getFilterExpressionForFunctionsMockedObj(MethodOperator.SUBSTRINGOF, "'INR'", null, "currencyCode", 2, null) , TABLE_ALIAS)); assertEquals(EXPECTED_STR_17, ODataExpressionParser .parseToJPAWhereExpression(getFilterExpressionForFunctionsMockedObj(MethodOperator.SUBSTRINGOF, "'nr rupees'", MethodOperator.TOLOWER, "currencyCode", 2, 1) , TABLE_ALIAS)); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); static final String EMPTY; static Integer methodFlag; }
@Test public void testParseUnaryExpression() { UnaryExpression unaryExpression = getUnaryExpressionMockedObj( getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, "deliveryStatus"), com.sap.core.odata.api.uri.expression.UnaryOperator.NOT); try { assertEquals(EXPECTED_STR_11, ODataExpressionParser.parseToJPAWhereExpression( unaryExpression, TABLE_ALIAS)); } catch (ODataException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); }
ODataExpressionParser { public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias) throws ODataException { switch (whereExpression.getKind()) { case UNARY: final UnaryExpression unaryExpression = (UnaryExpression) whereExpression; final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias); switch (unaryExpression.getOperator()) { case NOT: return JPQLStatement.Operator.NOT + "(" + operand + ")"; case MINUS: if (operand.startsWith("-")) { return operand.substring(1); } else { return "-" + operand; } default: throw new ODataNotImplementedException(); } case FILTER: return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias); case BINARY: final BinaryExpression binaryExpression = (BinaryExpression) whereExpression; if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) { methodFlag = 1; } final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias); final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias); switch (binaryExpression.getOperator()) { case AND: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE + right; case OR: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right; case EQ: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right; case NE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right; case LT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right; case LE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right; case GT: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right; case GE: return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right; case PROPERTY_ACCESS: throw new ODataNotImplementedException(); default: throw new ODataNotImplementedException(); } case PROPERTY: String returnStr = tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName(); return returnStr; case MEMBER: String memberExpStr = EMPTY; int i = 0; MemberExpression member = null; CommonExpression tempExp = whereExpression; while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) { member = (MemberExpression) tempExp; if (i > 0) { memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr; } i++; memberExpStr = ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr; tempExp = member.getPath(); } memberExpStr = ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr; return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr; case LITERAL: final LiteralExpression literal = (LiteralExpression) whereExpression; final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType(); String value = literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null, literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null); return evaluateComparingExpression(value, literalType); case METHOD: final MethodExpression methodExpression = (MethodExpression) whereExpression; String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias); final String second = methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1), tableAlias) : null; String third = methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2), tableAlias) : null; switch (methodExpression.getMethod()) { case SUBSTRING: third = third != null ? ", " + third : ""; return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third); case SUBSTRINGOF: first = first.substring(1, first.length() - 1); if (methodFlag == 1) { methodFlag = 0; return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first); } else { return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first); } case TOLOWER: return String.format("LOWER(%s)", first); default: throw new ODataNotImplementedException(); } default: throw new ODataNotImplementedException(); } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); static final String EMPTY; static Integer methodFlag; }
@Test public void testParseKeyPredicates() { KeyPredicate keyPredicate1 = EasyMock.createMock(KeyPredicate.class); EdmProperty kpProperty1 = EasyMock.createMock(EdmProperty.class); EasyMock.expect(keyPredicate1.getLiteral()).andStubReturn("1"); KeyPredicate keyPredicate2 = EasyMock.createMock(KeyPredicate.class); EdmProperty kpProperty2 = EasyMock.createMock(EdmProperty.class); EasyMock.expect(keyPredicate2.getLiteral()).andStubReturn("abc"); EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class); try { EasyMock.expect(kpProperty1.getName()).andStubReturn(SAMPLE_DATA_FIELD1); EasyMock.expect(kpProperty1.getType()).andStubReturn( EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance()); EasyMock.expect(kpProperty2.getName()).andStubReturn(SAMPLE_DATA_FIELD2); EasyMock.expect(kpProperty2.getType()).andStubReturn( EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()); EasyMock.expect(keyPredicate1.getProperty()).andStubReturn(kpProperty1); EasyMock.expect(kpProperty1.getMapping()).andStubReturn(edmMapping); EasyMock.expect(edmMapping.getInternalName()).andReturn(SAMPLE_DATA_FIELD1); EasyMock.expect(keyPredicate2.getProperty()).andStubReturn(kpProperty2); EasyMock.expect(kpProperty2.getMapping()).andStubReturn(edmMapping); } catch (EdmException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } EasyMock.expect(edmMapping.getInternalName()).andReturn(SAMPLE_DATA_FIELD2); EasyMock.replay(edmMapping); EasyMock.replay(kpProperty1, keyPredicate1, kpProperty2, keyPredicate2); ArrayList<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>(); keyPredicates.add(keyPredicate1); keyPredicates.add(keyPredicate2); String str = null; try { str = ODataExpressionParser.parseKeyPredicates(keyPredicates, TABLE_ALIAS); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } assertEquals(EXPECTED_STR_8, str); }
public static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias) throws ODataJPARuntimeException { String literal = null; String propertyName = null; EdmSimpleType edmSimpleType = null; StringBuilder keyFilters = new StringBuilder(); int i = 0; for (KeyPredicate keyPredicate : keyPredicates) { if (i > 0) { keyFilters.append(JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE); } i++; literal = keyPredicate.getLiteral(); try { EdmMapping mapping = keyPredicate.getProperty().getMapping(); if (mapping != null) { propertyName = keyPredicate.getProperty().getMapping().getInternalName(); } else { propertyName = keyPredicate.getProperty().getName(); } edmSimpleType = (EdmSimpleType) keyPredicate.getProperty().getType(); } catch (EdmException e) { throw ODataJPARuntimeException.throwException( ODataJPARuntimeException.GENERAL.addContent(e .getMessage()), e); } literal = evaluateComparingExpression(literal, edmSimpleType); if (edmSimpleType == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance() || edmSimpleType == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()) { literal = literal.substring(literal.indexOf('\''), literal.indexOf('}')); } keyFilters.append(tableAlias + JPQLStatement.DELIMITER.PERIOD + propertyName + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + literal); } if (keyFilters.length() > 0) { return keyFilters.toString(); } else { return null; } }
ODataExpressionParser { public static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias) throws ODataJPARuntimeException { String literal = null; String propertyName = null; EdmSimpleType edmSimpleType = null; StringBuilder keyFilters = new StringBuilder(); int i = 0; for (KeyPredicate keyPredicate : keyPredicates) { if (i > 0) { keyFilters.append(JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE); } i++; literal = keyPredicate.getLiteral(); try { EdmMapping mapping = keyPredicate.getProperty().getMapping(); if (mapping != null) { propertyName = keyPredicate.getProperty().getMapping().getInternalName(); } else { propertyName = keyPredicate.getProperty().getName(); } edmSimpleType = (EdmSimpleType) keyPredicate.getProperty().getType(); } catch (EdmException e) { throw ODataJPARuntimeException.throwException( ODataJPARuntimeException.GENERAL.addContent(e .getMessage()), e); } literal = evaluateComparingExpression(literal, edmSimpleType); if (edmSimpleType == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance() || edmSimpleType == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()) { literal = literal.substring(literal.indexOf('\''), literal.indexOf('}')); } keyFilters.append(tableAlias + JPQLStatement.DELIMITER.PERIOD + propertyName + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + literal); } if (keyFilters.length() > 0) { return keyFilters.toString(); } else { return null; } } }
ODataExpressionParser { public static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias) throws ODataJPARuntimeException { String literal = null; String propertyName = null; EdmSimpleType edmSimpleType = null; StringBuilder keyFilters = new StringBuilder(); int i = 0; for (KeyPredicate keyPredicate : keyPredicates) { if (i > 0) { keyFilters.append(JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE); } i++; literal = keyPredicate.getLiteral(); try { EdmMapping mapping = keyPredicate.getProperty().getMapping(); if (mapping != null) { propertyName = keyPredicate.getProperty().getMapping().getInternalName(); } else { propertyName = keyPredicate.getProperty().getName(); } edmSimpleType = (EdmSimpleType) keyPredicate.getProperty().getType(); } catch (EdmException e) { throw ODataJPARuntimeException.throwException( ODataJPARuntimeException.GENERAL.addContent(e .getMessage()), e); } literal = evaluateComparingExpression(literal, edmSimpleType); if (edmSimpleType == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance() || edmSimpleType == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()) { literal = literal.substring(literal.indexOf('\''), literal.indexOf('}')); } keyFilters.append(tableAlias + JPQLStatement.DELIMITER.PERIOD + propertyName + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + literal); } if (keyFilters.length() > 0) { return keyFilters.toString(); } else { return null; } } }
ODataExpressionParser { public static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias) throws ODataJPARuntimeException { String literal = null; String propertyName = null; EdmSimpleType edmSimpleType = null; StringBuilder keyFilters = new StringBuilder(); int i = 0; for (KeyPredicate keyPredicate : keyPredicates) { if (i > 0) { keyFilters.append(JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE); } i++; literal = keyPredicate.getLiteral(); try { EdmMapping mapping = keyPredicate.getProperty().getMapping(); if (mapping != null) { propertyName = keyPredicate.getProperty().getMapping().getInternalName(); } else { propertyName = keyPredicate.getProperty().getName(); } edmSimpleType = (EdmSimpleType) keyPredicate.getProperty().getType(); } catch (EdmException e) { throw ODataJPARuntimeException.throwException( ODataJPARuntimeException.GENERAL.addContent(e .getMessage()), e); } literal = evaluateComparingExpression(literal, edmSimpleType); if (edmSimpleType == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance() || edmSimpleType == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()) { literal = literal.substring(literal.indexOf('\''), literal.indexOf('}')); } keyFilters.append(tableAlias + JPQLStatement.DELIMITER.PERIOD + propertyName + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + literal); } if (keyFilters.length() > 0) { return keyFilters.toString(); } else { return null; } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); }
ODataExpressionParser { public static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias) throws ODataJPARuntimeException { String literal = null; String propertyName = null; EdmSimpleType edmSimpleType = null; StringBuilder keyFilters = new StringBuilder(); int i = 0; for (KeyPredicate keyPredicate : keyPredicates) { if (i > 0) { keyFilters.append(JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE); } i++; literal = keyPredicate.getLiteral(); try { EdmMapping mapping = keyPredicate.getProperty().getMapping(); if (mapping != null) { propertyName = keyPredicate.getProperty().getMapping().getInternalName(); } else { propertyName = keyPredicate.getProperty().getName(); } edmSimpleType = (EdmSimpleType) keyPredicate.getProperty().getType(); } catch (EdmException e) { throw ODataJPARuntimeException.throwException( ODataJPARuntimeException.GENERAL.addContent(e .getMessage()), e); } literal = evaluateComparingExpression(literal, edmSimpleType); if (edmSimpleType == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance() || edmSimpleType == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()) { literal = literal.substring(literal.indexOf('\''), literal.indexOf('}')); } keyFilters.append(tableAlias + JPQLStatement.DELIMITER.PERIOD + propertyName + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + literal); } if (keyFilters.length() > 0) { return keyFilters.toString(); } else { return null; } } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); static final String EMPTY; static Integer methodFlag; }
@Test public void testProcessGetEntitySetUriInfo() { try { Assert.assertNotNull(objJPAProcessorImpl.process(getEntitySetUriInfo())); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") @Override List<Object> process(final GetFunctionImportUriInfo uriParserResultView); @SuppressWarnings("unchecked") @Override List<T> process(final GetEntitySetUriInfo uriParserResultView); @Override Object process(GetEntityUriInfo uriParserResultView); @Override long process(final GetEntitySetCountUriInfo resultsView); @Override long process(final GetEntityCountUriInfo resultsView); @Override List<T> process(final PostUriInfo createView, final InputStream content, final String requestedContentType); @Override List<T> process(final PostUriInfo createView, final Map<String, Object> content); @Override Object process(final PutMergePatchUriInfo updateView, final InputStream content, final String requestContentType); @Override Object process(final PutMergePatchUriInfo updateView, final Map<String, Object> content); Object processUpdate(PutMergePatchUriInfo updateView, final InputStream content, final Map<String, Object> properties, final String requestContentType); @Override Object process(DeleteUriInfo uriParserResultView, final String contentType); @Override Object process(final GetEntityLinkUriInfo uriParserResultView); @Override List<T> process(final GetEntitySetLinksUriInfo uriParserResultView); @Override void process(final PostUriInfo uriInfo, final InputStream content, final String requestContentType, final String contentType); @Override void process(final PutMergePatchUriInfo putUriInfo, final InputStream content, final String requestContentType, final String contentType); }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") @Override List<Object> process(final GetFunctionImportUriInfo uriParserResultView); @SuppressWarnings("unchecked") @Override List<T> process(final GetEntitySetUriInfo uriParserResultView); @Override Object process(GetEntityUriInfo uriParserResultView); @Override long process(final GetEntitySetCountUriInfo resultsView); @Override long process(final GetEntityCountUriInfo resultsView); @Override List<T> process(final PostUriInfo createView, final InputStream content, final String requestedContentType); @Override List<T> process(final PostUriInfo createView, final Map<String, Object> content); @Override Object process(final PutMergePatchUriInfo updateView, final InputStream content, final String requestContentType); @Override Object process(final PutMergePatchUriInfo updateView, final Map<String, Object> content); Object processUpdate(PutMergePatchUriInfo updateView, final InputStream content, final Map<String, Object> properties, final String requestContentType); @Override Object process(DeleteUriInfo uriParserResultView, final String contentType); @Override Object process(final GetEntityLinkUriInfo uriParserResultView); @Override List<T> process(final GetEntitySetLinksUriInfo uriParserResultView); @Override void process(final PostUriInfo uriInfo, final InputStream content, final String requestContentType, final String contentType); @Override void process(final PutMergePatchUriInfo putUriInfo, final InputStream content, final String requestContentType, final String contentType); }
@Test public void testName() { Team team1 = new Team(1, VALUE_NAME); assertEquals(team1.getName(), VALUE_NAME); }
public String getName() { return name; }
Team { public String getName() { return name; } }
Team { public String getName() { return name; } Team(final int id, final String name); }
Team { public String getName() { return name; } Team(final int id, final String name); String getId(); String getName(); void setName(final String name); boolean isScrumTeam(); void setScrumTeam(final boolean isScrumTeam); List<Employee> getEmployees(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); }
Team { public String getName() { return name; } Team(final int id, final String name); String getId(); String getName(); void setName(final String name); boolean isScrumTeam(); void setScrumTeam(final boolean isScrumTeam); List<Employee> getEmployees(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); }
@Test public void testParseToJPASelectExpression() { ArrayList<String> selectedFields = new ArrayList<String>(); selectedFields.add("BuyerAddress"); selectedFields.add("BuyerName"); selectedFields.add("BuyerId"); assertEquals(EXPECTED_STR_9, ODataExpressionParser.parseToJPASelectExpression(TABLE_ALIAS, selectedFields)); assertEquals(TABLE_ALIAS, ODataExpressionParser.parseToJPASelectExpression( TABLE_ALIAS, null)); selectedFields.clear(); assertEquals(TABLE_ALIAS, ODataExpressionParser.parseToJPASelectExpression( TABLE_ALIAS, selectedFields)); }
public static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields) { if ((selectedFields == null) || (selectedFields.size() == 0)) { return tableAlias; } String selectClause = EMPTY; Iterator<String> itr = selectedFields.iterator(); int count = 0; while (itr.hasNext()) { selectClause = selectClause + tableAlias + JPQLStatement.DELIMITER.PERIOD + itr.next(); count++; if (count < selectedFields.size()) { selectClause = selectClause + JPQLStatement.DELIMITER.COMMA + JPQLStatement.DELIMITER.SPACE; } } return selectClause; }
ODataExpressionParser { public static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields) { if ((selectedFields == null) || (selectedFields.size() == 0)) { return tableAlias; } String selectClause = EMPTY; Iterator<String> itr = selectedFields.iterator(); int count = 0; while (itr.hasNext()) { selectClause = selectClause + tableAlias + JPQLStatement.DELIMITER.PERIOD + itr.next(); count++; if (count < selectedFields.size()) { selectClause = selectClause + JPQLStatement.DELIMITER.COMMA + JPQLStatement.DELIMITER.SPACE; } } return selectClause; } }
ODataExpressionParser { public static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields) { if ((selectedFields == null) || (selectedFields.size() == 0)) { return tableAlias; } String selectClause = EMPTY; Iterator<String> itr = selectedFields.iterator(); int count = 0; while (itr.hasNext()) { selectClause = selectClause + tableAlias + JPQLStatement.DELIMITER.PERIOD + itr.next(); count++; if (count < selectedFields.size()) { selectClause = selectClause + JPQLStatement.DELIMITER.COMMA + JPQLStatement.DELIMITER.SPACE; } } return selectClause; } }
ODataExpressionParser { public static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields) { if ((selectedFields == null) || (selectedFields.size() == 0)) { return tableAlias; } String selectClause = EMPTY; Iterator<String> itr = selectedFields.iterator(); int count = 0; while (itr.hasNext()) { selectClause = selectClause + tableAlias + JPQLStatement.DELIMITER.PERIOD + itr.next(); count++; if (count < selectedFields.size()) { selectClause = selectClause + JPQLStatement.DELIMITER.COMMA + JPQLStatement.DELIMITER.SPACE; } } return selectClause; } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); }
ODataExpressionParser { public static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields) { if ((selectedFields == null) || (selectedFields.size() == 0)) { return tableAlias; } String selectClause = EMPTY; Iterator<String> itr = selectedFields.iterator(); int count = 0; while (itr.hasNext()) { selectClause = selectClause + tableAlias + JPQLStatement.DELIMITER.PERIOD + itr.next(); count++; if (count < selectedFields.size()) { selectClause = selectClause + JPQLStatement.DELIMITER.COMMA + JPQLStatement.DELIMITER.SPACE; } } return selectClause; } static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias); static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields); static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression, final String tableAlias); static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias); static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(final List<EdmProperty> edmPropertylist, final String tableAlias); static final String EMPTY; static Integer methodFlag; }
@Test public void testExtendedODataErrorContext() throws Exception { MultivaluedMap<String, String> value = new MultivaluedHashMap<String, String>(); value.putSingle("Accept", "AcceptValue"); value.put("AcceptMulti", Arrays.asList("AcceptValue_1", "AcceptValue_2")); when(exceptionMapper.httpHeaders.getRequestHeaders()).thenReturn(value); when(exceptionMapper.servletConfig.getInitParameter(ODataServiceFactory.FACTORY_LABEL)).thenReturn(ODataServiceFactoryImpl.class.getName()); when(exceptionMapper.servletRequest.getAttribute(ODataServiceFactory.FACTORY_CLASSLOADER_LABEL)).thenReturn(null); Response response = exceptionMapper.toResponse(new Exception()); assertNotNull(response); assertEquals(HttpStatusCodes.BAD_REQUEST.getStatusCode(), response.getStatus()); String errorMessage = (String) response.getEntity(); assertEquals("bla", errorMessage); String contentTypeHeader = response.getHeaderString(com.sap.core.odata.api.commons.HttpHeaders.CONTENT_TYPE); assertEquals("text/html", contentTypeHeader); assertEquals(uri.toASCIIString(), response.getHeaderString("RequestUri")); assertEquals("[AcceptValue]", response.getHeaderString("Accept")); assertEquals("[AcceptValue_1, AcceptValue_2]", response.getHeaderString("AcceptMulti")); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void servletRequestWithClassloader() throws Exception { MultivaluedMap<String, String> value = new MultivaluedHashMap<String, String>(); value.putSingle("Accept", "AcceptValue"); value.put("AcceptMulti", Arrays.asList("AcceptValue_1", "AcceptValue_2")); when(exceptionMapper.httpHeaders.getRequestHeaders()).thenReturn(value); when(exceptionMapper.servletConfig.getInitParameter(ODataServiceFactory.FACTORY_LABEL)).thenReturn(ODataServiceFactoryImpl.class.getName()); when(exceptionMapper.servletRequest.getAttribute(ODataServiceFactory.FACTORY_CLASSLOADER_LABEL)).thenReturn(ODataServiceFactoryImpl.class.getClassLoader()); Response response = exceptionMapper.toResponse(new Exception()); assertNotNull(response); assertEquals(HttpStatusCodes.BAD_REQUEST.getStatusCode(), response.getStatus()); String errorMessage = (String) response.getEntity(); assertEquals("bla", errorMessage); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void dollarFormatJson() throws Exception { MultivaluedMap<String, String> queryParameters = new MultivaluedHashMap<String, String>(); queryParameters.putSingle("$format", "json"); when(exceptionMapper.uriInfo.getQueryParameters()).thenReturn(queryParameters); Response response = exceptionMapper.toResponse(new Exception("text")); assertNotNull(response); String contentTypeHeader = response.getHeaderString(com.sap.core.odata.api.commons.HttpHeaders.CONTENT_TYPE); assertEquals("application/json", contentTypeHeader); String errorMessage = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertEquals("{\"error\":{\"code\":null,\"message\":{\"lang\":\"en\",\"value\":\"text\"}}}", errorMessage); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void dollarFormatXml() throws Exception { MultivaluedMap<String, String> queryParameters = new MultivaluedHashMap<String, String>(); queryParameters.putSingle("$format", "xml"); when(exceptionMapper.uriInfo.getQueryParameters()).thenReturn(queryParameters); Response response = exceptionMapper.toResponse(new Exception("text")); assertNotNull(response); String contentTypeHeader = response.getHeaderString(com.sap.core.odata.api.commons.HttpHeaders.CONTENT_TYPE); assertEquals("application/xml", contentTypeHeader); String errorMessage = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertXpathExists("/a:error/a:code", errorMessage); assertXpathEvaluatesTo("text", "/a:error/a:message", errorMessage); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void dollarFormatAtom() throws Exception { MultivaluedMap<String, String> queryParameters = new MultivaluedHashMap<String, String>(); queryParameters.putSingle("$format", "xml"); when(exceptionMapper.uriInfo.getQueryParameters()).thenReturn(queryParameters); Response response = exceptionMapper.toResponse(new Exception("text")); assertNotNull(response); String contentTypeHeader = response.getHeaderString(com.sap.core.odata.api.commons.HttpHeaders.CONTENT_TYPE); assertEquals("application/xml", contentTypeHeader); String errorMessage = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertXpathExists("/a:error/a:code", errorMessage); assertXpathEvaluatesTo("text", "/a:error/a:message", errorMessage); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void dollarFormatUnknown() throws Exception { MultivaluedMap<String, String> queryParameters = new MultivaluedHashMap<String, String>(); queryParameters.putSingle("$format", "someFormat"); when(exceptionMapper.uriInfo.getQueryParameters()).thenReturn(queryParameters); Response response = exceptionMapper.toResponse(new Exception("text")); assertNotNull(response); String contentTypeHeader = response.getHeaderString(com.sap.core.odata.api.commons.HttpHeaders.CONTENT_TYPE); assertEquals("application/xml", contentTypeHeader); String errorMessage = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertXpathExists("/a:error/a:code", errorMessage); assertXpathEvaluatesTo("text", "/a:error/a:message", errorMessage); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testODataNotFoundException() throws Exception { Exception exception = new ODataNotFoundException(ODataNotFoundException.ENTITY); Response response = exceptionMapper.toResponse(exception); verifyResponse(response, MessageService.getMessage(Locale.ENGLISH, ODataNotFoundException.ENTITY).getText(), HttpStatusCodes.NOT_FOUND); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testEntityProviderException() throws Exception { Exception exception = new EntityProviderException(EntityProviderException.INVALID_PROPERTY.addContent("unknown")); Response response = exceptionMapper.toResponse(exception); verifyResponse(response, MessageService.getMessage(Locale.ENGLISH, EntityProviderException.INVALID_PROPERTY.addContent("unknown")).getText(), HttpStatusCodes.BAD_REQUEST); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testODataNotFoundExceptionDe() throws Exception { Exception exception = new ODataNotFoundException(ODataNotFoundException.ENTITY); when(exceptionMapper.httpHeaders.getAcceptableLanguages()) .thenReturn(Arrays.asList(Locale.GERMAN)); Response response = exceptionMapper.toResponse(exception); verifyResponse(response, MessageService.getMessage(Locale.GERMAN, ODataNotFoundException.ENTITY).getText(), HttpStatusCodes.NOT_FOUND); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testProcessDeleteUriInfo() { try { Assert.assertNotNull(objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml")); Assert.assertEquals(new Address(), objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml")); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") @Override List<Object> process(final GetFunctionImportUriInfo uriParserResultView); @SuppressWarnings("unchecked") @Override List<T> process(final GetEntitySetUriInfo uriParserResultView); @Override Object process(GetEntityUriInfo uriParserResultView); @Override long process(final GetEntitySetCountUriInfo resultsView); @Override long process(final GetEntityCountUriInfo resultsView); @Override List<T> process(final PostUriInfo createView, final InputStream content, final String requestedContentType); @Override List<T> process(final PostUriInfo createView, final Map<String, Object> content); @Override Object process(final PutMergePatchUriInfo updateView, final InputStream content, final String requestContentType); @Override Object process(final PutMergePatchUriInfo updateView, final Map<String, Object> content); Object processUpdate(PutMergePatchUriInfo updateView, final InputStream content, final Map<String, Object> properties, final String requestContentType); @Override Object process(DeleteUriInfo uriParserResultView, final String contentType); @Override Object process(final GetEntityLinkUriInfo uriParserResultView); @Override List<T> process(final GetEntitySetLinksUriInfo uriParserResultView); @Override void process(final PostUriInfo uriInfo, final InputStream content, final String requestContentType, final String contentType); @Override void process(final PutMergePatchUriInfo putUriInfo, final InputStream content, final String requestContentType, final String contentType); }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") @Override List<Object> process(final GetFunctionImportUriInfo uriParserResultView); @SuppressWarnings("unchecked") @Override List<T> process(final GetEntitySetUriInfo uriParserResultView); @Override Object process(GetEntityUriInfo uriParserResultView); @Override long process(final GetEntitySetCountUriInfo resultsView); @Override long process(final GetEntityCountUriInfo resultsView); @Override List<T> process(final PostUriInfo createView, final InputStream content, final String requestedContentType); @Override List<T> process(final PostUriInfo createView, final Map<String, Object> content); @Override Object process(final PutMergePatchUriInfo updateView, final InputStream content, final String requestContentType); @Override Object process(final PutMergePatchUriInfo updateView, final Map<String, Object> content); Object processUpdate(PutMergePatchUriInfo updateView, final InputStream content, final Map<String, Object> properties, final String requestContentType); @Override Object process(DeleteUriInfo uriParserResultView, final String contentType); @Override Object process(final GetEntityLinkUriInfo uriParserResultView); @Override List<T> process(final GetEntitySetLinksUriInfo uriParserResultView); @Override void process(final PostUriInfo uriInfo, final InputStream content, final String requestContentType, final String contentType); @Override void process(final PutMergePatchUriInfo putUriInfo, final InputStream content, final String requestContentType, final String contentType); }
@Test public void testWrappedODataNotFoundException() throws Exception { Exception causeException = new ODataNotFoundException(ODataNotFoundException.ENTITY); String exceptionMessage = "Some odd exception"; Exception exception = new ODataException(exceptionMessage, causeException); Response response = exceptionMapper.toResponse(exception); verifyResponse(response, MessageService.getMessage(Locale.ENGLISH, ODataNotFoundException.ENTITY).getText(), HttpStatusCodes.NOT_FOUND); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testODataApplicationException() throws Exception { String message = "expected exception message"; Exception exception = new ODataApplicationException(message, Locale.ENGLISH); Response response = exceptionMapper.toResponse(exception); verifyResponse(response, message, HttpStatusCodes.INTERNAL_SERVER_ERROR); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testODataApplicationExceptionWrapped() throws Exception { String message = "expected exception message"; Exception exception = new ODataException(new ODataApplicationException(message, Locale.ENGLISH)); Response response = exceptionMapper.toResponse(exception); verifyResponse(response, message, HttpStatusCodes.INTERNAL_SERVER_ERROR); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testODataApplicationExceptionWithStatus() throws Exception { String message = "expected exception message"; HttpStatusCodes status = HttpStatusCodes.OK; Exception exception = new ODataApplicationException(message, Locale.ENGLISH, status); Response response = exceptionMapper.toResponse(exception); verifyResponse(response, message, status); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testODataApplicationExceptionWithStatusWrapped() throws Exception { String message = "expected exception message"; HttpStatusCodes status = HttpStatusCodes.OK; Exception exception = new ODataException(new ODataApplicationException(message, Locale.ENGLISH, status)); Response response = exceptionMapper.toResponse(exception); verifyResponse(response, message, status); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testUriParserException() throws Exception { Exception exception = new UriSyntaxException(UriSyntaxException.EMPTYSEGMENT); Response response = exceptionMapper.toResponse(exception); verifyResponse(response, MessageService.getMessage(Locale.ENGLISH, UriSyntaxException.EMPTYSEGMENT).getText(), HttpStatusCodes.BAD_REQUEST); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testUriParserExceptionWrapped() throws Exception { Exception exception = new ODataException("outer exception", new UriSyntaxException(UriSyntaxException.EMPTYSEGMENT)); Response response = exceptionMapper.toResponse(exception); verifyResponse(response, MessageService.getMessage(Locale.ENGLISH, UriSyntaxException.EMPTYSEGMENT).getText(), HttpStatusCodes.BAD_REQUEST); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testIoException() throws Exception { String message = "expected exception message"; Exception exception = new IOException(message); Response response = exceptionMapper.toResponse(exception); verifyResponse(response, message, HttpStatusCodes.INTERNAL_SERVER_ERROR); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testODataException() throws Exception { String exceptionMessage = "Some odd exception"; Exception exception = new ODataException(exceptionMessage); Response response = exceptionMapper.toResponse(exception); verifyResponse(response, exceptionMessage, HttpStatusCodes.INTERNAL_SERVER_ERROR); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testNotAllowedJaxRsException() throws Exception { String message = "The request dispatcher does not allow the HTTP method used for the request."; Exception exception = new NotAllowedException(Response.status(Response.Status.METHOD_NOT_ALLOWED).header(HttpHeaders.ALLOW, "GET").build()); Response response = exceptionMapper.toResponse(exception); verifyResponse(response, message, HttpStatusCodes.NOT_IMPLEMENTED); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testProcessDeleteUriInfoNegative() { try { Assert.assertNotNull(objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml")); Assert.assertNotSame(new Object(), objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml")); } catch (ODataJPAModelException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
@SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") @Override List<Object> process(final GetFunctionImportUriInfo uriParserResultView); @SuppressWarnings("unchecked") @Override List<T> process(final GetEntitySetUriInfo uriParserResultView); @Override Object process(GetEntityUriInfo uriParserResultView); @Override long process(final GetEntitySetCountUriInfo resultsView); @Override long process(final GetEntityCountUriInfo resultsView); @Override List<T> process(final PostUriInfo createView, final InputStream content, final String requestedContentType); @Override List<T> process(final PostUriInfo createView, final Map<String, Object> content); @Override Object process(final PutMergePatchUriInfo updateView, final InputStream content, final String requestContentType); @Override Object process(final PutMergePatchUriInfo updateView, final Map<String, Object> content); Object processUpdate(PutMergePatchUriInfo updateView, final InputStream content, final Map<String, Object> properties, final String requestContentType); @Override Object process(DeleteUriInfo uriParserResultView, final String contentType); @Override Object process(final GetEntityLinkUriInfo uriParserResultView); @Override List<T> process(final GetEntitySetLinksUriInfo uriParserResultView); @Override void process(final PostUriInfo uriInfo, final InputStream content, final String requestContentType, final String contentType); @Override void process(final PutMergePatchUriInfo putUriInfo, final InputStream content, final String requestContentType, final String contentType); }
JPAProcessorImpl implements JPAProcessor { @SuppressWarnings("unchecked") @Override public List<Object> process(final GetFunctionImportUriInfo uriParserResultView) throws ODataJPAModelException, ODataJPARuntimeException { JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder( JPQLContextType.FUNCTION, uriParserResultView).build(); List<Object> resultObj = null; try { JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList() .get(0); Method method = jpaFunction.getFunction(); Object[] args = jpaFunction.getArguments(); if (uriParserResultView.getFunctionImport().getReturnType() .getMultiplicity().equals(EdmMultiplicity.MANY)) { resultObj = (List<Object>) method.invoke( jpaMethodContext.getEnclosingObject(), args); } else { resultObj = new ArrayList<Object>(); Object result = method.invoke( jpaMethodContext.getEnclosingObject(), args); resultObj.add(result); } } catch (EdmException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalAccessException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getMessage()), e); } catch (InvocationTargetException e) { throw ODataJPARuntimeException .throwException(ODataJPARuntimeException.GENERAL .addContent(e.getTargetException().getMessage()), e.getTargetException()); } return resultObj; } JPAProcessorImpl(final ODataJPAContext oDataJPAContext); @SuppressWarnings("unchecked") @Override List<Object> process(final GetFunctionImportUriInfo uriParserResultView); @SuppressWarnings("unchecked") @Override List<T> process(final GetEntitySetUriInfo uriParserResultView); @Override Object process(GetEntityUriInfo uriParserResultView); @Override long process(final GetEntitySetCountUriInfo resultsView); @Override long process(final GetEntityCountUriInfo resultsView); @Override List<T> process(final PostUriInfo createView, final InputStream content, final String requestedContentType); @Override List<T> process(final PostUriInfo createView, final Map<String, Object> content); @Override Object process(final PutMergePatchUriInfo updateView, final InputStream content, final String requestContentType); @Override Object process(final PutMergePatchUriInfo updateView, final Map<String, Object> content); Object processUpdate(PutMergePatchUriInfo updateView, final InputStream content, final Map<String, Object> properties, final String requestContentType); @Override Object process(DeleteUriInfo uriParserResultView, final String contentType); @Override Object process(final GetEntityLinkUriInfo uriParserResultView); @Override List<T> process(final GetEntitySetLinksUriInfo uriParserResultView); @Override void process(final PostUriInfo uriInfo, final InputStream content, final String requestContentType, final String contentType); @Override void process(final PutMergePatchUriInfo putUriInfo, final InputStream content, final String requestContentType, final String contentType); }
@Test public void testODataExceptionWithoutText() throws Exception { final String text = null; final Exception exception = new ODataException(text); final Response response = exceptionMapper.toResponse(exception); assertNotNull(response); final String errorMessage = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertXpathExists("/a:error/a:message", errorMessage); assertXpathEvaluatesTo("en", "/a:error/a:message/@xml:lang", errorMessage); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testODataRuntimeException() throws Exception { String exceptionMessage = "Some odd runtime exception"; Exception exception = new ODataRuntimeException(exceptionMessage); Response response = exceptionMapper.toResponse(exception); verifyResponse(response, exceptionMessage, HttpStatusCodes.INTERNAL_SERVER_ERROR); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testErrorCodeForApplicationException() throws Exception { String errorCode = "ErrorCode"; String message = "expected exception message"; Exception exception = new ODataApplicationException(message, Locale.ENGLISH, HttpStatusCodes.INTERNAL_SERVER_ERROR, errorCode); Response response = exceptionMapper.toResponse(exception); String errorMessage = verifyResponse(response, message, HttpStatusCodes.INTERNAL_SERVER_ERROR); assertXpathEvaluatesTo(errorCode, "/a:error/a:code", errorMessage); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
@Test public void testODataNotFoundExceptionWithErrorCode() throws Exception { String errorCode = "ErrorCode"; Exception exception = new ODataNotFoundException(ODataNotFoundException.ENTITY, errorCode); Response response = exceptionMapper.toResponse(exception); String errorMessage = verifyResponse(response, MessageService.getMessage(Locale.ENGLISH, ODataNotFoundException.ENTITY).getText(), HttpStatusCodes.NOT_FOUND); assertXpathEvaluatesTo(errorCode, "/a:error/a:code", errorMessage); }
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }
ODataExceptionMapperImpl implements ExceptionMapper<Exception> { @Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } return RestUtil.convertResponse(response); } @Override Response toResponse(final Exception exception); }