Mikou
Mikou

Reputation: 651

Olingo Odata4 server : Multiple Primary Key

I am setting up a basic OData provider using the Olingo OData4 library.

So far, I have two simple entities made of 2 properties where a single element is defined as a key.

+--------+    +---------+
| Person |    | Project |
+--------+    +---------+
| ID     |    | CODE    |
| Name   |    | Name    |
+--------+    +---------+

I use propertyRef.setPropertyName("Code") to specify that Key element, like so:

//create EntityType properties
Property code = new Property().setName("Code").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
Property name = new Property().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());

// create PropertyRef for Key element
PropertyRef propertyRef = new PropertyRef();
propertyRef.setPropertyName("Code");

// configure EntityType
EntityType entityType = new EntityType();
entityType.setName(ET_PROJECT_NAME);
entityType.setProperties(Arrays.asList(code, name));
entityType.setKey(Arrays.asList(propertyRef));

return entityType;

Now I would like to set up a more complex entity type that has a set of attributes as its key element rather that a single Key element.

+----------+
| Activity |
+----------+
| pid      | --> FK references (Person.ID)
| pcode    | --> FK references (Project.Code)
| START    |
| END      |
| NAME     |
+----------+
Composite key : {START, END, NAME}

According to the documentation, PropertyRef only allows a single String to be passed as argument : http://olingo.apache.org/javadoc/odata4/index.html?org/apache/olingo/ext/proxy/api/annotations/CompoundKey.html

Questions :

(1) Is there another class than PropertyRef I should use to register such a composite key?

(2) How to define the two Foreign Keys?

Thanks in advance for pointing me into the right direction.

Upvotes: 2

Views: 1317

Answers (2)

Cunuu Kum
Cunuu Kum

Reputation: 183

Just in case anyone needs Olingo4 server example (integrated with MyBatis and some security is implemented). It has sqls for database too (for which it is created)

https://github.com/ousatov-ua/Olingo4-server

Upvotes: 0

chrisam
chrisam

Reputation: 543

You have to register one PropertyRef per key. So your code should look like this:

.setKey(Arrays.asList(
          new CsdlPropertyRef().setName("START"),
          new CsdlPropertyRef().setName("END"))),
          new CsdlPropertyRef().setName("NAME")))

Upvotes: 1

Related Questions