Java Code Examples for org.apache.olingo.odata2.api.edm.provider.EntityType#setMapping()

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.EntityType#setMapping() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JPAEdmNameBuilder.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public static void build(final JPAEdmEntityTypeView view) {

    EntityType edmEntityType = view.getEdmEntityType();
    String jpaEntityName = view.getJPAEntityType().getName();
    JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
    String edmEntityTypeName = null;
    if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
      edmEntityTypeName = mappingModelAccess.mapJPAEntityType(jpaEntityName);
    }

    JPAEdmMapping mapping = new JPAEdmMappingImpl();
    mapping.setJPAType(view.getJPAEntityType().getJavaType());

    if (edmEntityTypeName == null) {
      edmEntityTypeName = jpaEntityName;
    }
    // Setting the mapping object
    edmEntityType.setMapping(((Mapping) mapping).setInternalName(jpaEntityName));

    edmEntityType.setName(edmEntityTypeName);

  }
 
Example 2
Source File: JPALinkTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private List<NavigationSegment> mockNavigationSegments(boolean isReverse) throws EdmException, NoSuchFieldException,
    SecurityException, IllegalArgumentException, IllegalAccessException {
  Class<?> type = null;
  String entityTypeName = null;
  String keyLiteral = null;
  EdmMultiplicity multiplicity = null;
  String navPropertyName = null;
  String toRole = null;
  String associationName = null;

  if (isReverse) {
    type = SalesOrderHeader.class;
    entityTypeName = "SalesOrder";
    keyLiteral = "1";
    multiplicity = EdmMultiplicity.ONE;
    navPropertyName = "salesOrderHeader";
    toRole = "SalesOrder";
    associationName = "Note_SalesOrder";

  } else {
    type = List.class;
    entityTypeName = "Note";
    keyLiteral = "2";
    multiplicity = EdmMultiplicity.MANY;
    navPropertyName = "NotesDetails";
    toRole = "Note";
    associationName = "Note_SalesOrder";
  }

  JPAEdmMapping mapping = new JPAEdmMappingImpl();
  mapping.setJPAType(type);

  KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
  EasyMock.expect(keyPredicate.getProperty()).andReturn(
      edm.getEntityType("SalesOrderProcessing", entityTypeName).getKeyProperties().get(0)).anyTimes();
  EasyMock.expect(keyPredicate.getLiteral()).andReturn(keyLiteral);
  EasyMock.replay(keyPredicate);
  List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
  keyPredicates.add(keyPredicate);

  NavigationSegment navigationSegment = EasyMock.createMock(NavigationSegment.class);
  EasyMock.expect(navigationSegment.getKeyPredicates()).andReturn(keyPredicates);

  EdmNavigationProperty navProperty = EasyMock.createMock(EdmNavigationProperty.class);
  EasyMock.expect(navProperty.getMapping()).andReturn((EdmMapping) mapping).anyTimes();
  EasyMock.expect(navProperty.getMultiplicity()).andReturn(multiplicity).anyTimes();
  EasyMock.expect(navProperty.getName()).andReturn(navPropertyName).anyTimes();
  EasyMock.expect(navProperty.getToRole()).andReturn(toRole).anyTimes();
  EasyMock.expect(navProperty.getRelationship()).andReturn(
      edm.getAssociation("SalesOrderProcessing", associationName));
  EasyMock.replay(navProperty);

  EdmEntityType edmEntityType =
      edm.getAssociation("SalesOrderProcessing", associationName).getEnd(toRole).getEntityType();
  Field field = EdmEntityTypeImplProv.class.getDeclaredField("entityType");
  field.setAccessible(true);

  EntityType entityType = (EntityType) field.get(edmEntityType);
  entityType.setMapping((Mapping) mapping);

  EasyMock.expect(navigationSegment.getNavigationProperty()).andReturn(navProperty).anyTimes();
  EasyMock.replay(navigationSegment);

  List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
  navigationSegments.add(navigationSegment);

  return navigationSegments;
}
 
Example 3
Source File: MapProvider.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private void buildSchema() {
  propertyRef = new PropertyRef();
  propertyRef.setName("p1");

  key = new Key();
  key.setKeys(Arrays.asList(propertyRef));

  property1 =
      new SimpleProperty().setName(mapping[P1][EDM]).setType(EdmSimpleTypeKind.String).setMapping(
          new Mapping().setObject(mapping[P1][BACKEND]));
  property2 =
      new SimpleProperty().setName(mapping[P2][EDM]).setType(EdmSimpleTypeKind.String).setMapping(
          new Mapping().setObject(mapping[P2][BACKEND]));
  property3 =
      new SimpleProperty().setName(mapping[P3][EDM]).setType(EdmSimpleTypeKind.String).setMapping(
          new Mapping().setObject(mapping[P3][BACKEND]));

  entityType = new EntityType();
  entityType.setName(mapping[ENTITYTYPE][EDM]);
  entityType.setKey(key);
  entityType.setProperties(Arrays.asList(property1, property2, property3));
  entityType.setMapping(new Mapping().setObject(mapping[ENTITYTYPE][BACKEND]));

  entitySet = new EntitySet();
  entitySet.setName(mapping[ENTITYSET][EDM]);
  entitySet.setEntityType(new FullQualifiedName(NAMESPACE, mapping[ENTITYTYPE][EDM]));
  entitySet.setMapping(new Mapping().setObject(mapping[ENTITYSET][BACKEND]));

  entityContainer = new EntityContainer();
  entityContainer.setDefaultEntityContainer(true);
  entityContainer.setName(MAPPING_CONTAINER);
  entityContainer.setEntitySets(Arrays.asList(entitySet));

  schema = new Schema();
  schema.setNamespace("mapping");
  schema.setAlias(NAMESPACE);
  schema.setEntityContainers(Arrays.asList(entityContainer));
  schema.setEntityTypes(Arrays.asList(entityType));

  schemas = Arrays.asList(schema);
}