Hey all,
I played around a bit with our idea of a JPA Layer on Top of PLC4X (as I would
need one currently) and came up with a very simple first sample.
My idea is to use annotations on a POJO to give all necessary information and
have a PlcEntityManager (similar to JPAs EntityManager) which is then
responsible for everything.
Quick Note on naming, I decided to use OPM (opposed to ORM) as object-to-plc
mapping because PLCJPA or all such things sound horrible.
I implemented a “.find(Class<?> clazz)” on the PlcEntityManager which just
returns a Pojo but with all PLC Values injected.
For the Pojos I defined two Annotations:
@PlcEntity(“plc connection string”)
@PlcField(“plc address string”)
And an example Entity would look like
@PlcEntity("s7://localhost:5555/0/0")
public static class MyEntity {
@PlcField("%DB3.DBW500")
private Long counter;
@PlcField("%DB3.DBW504")
private long counter2;
public Long getCounter() {
return counter;
}
public long getCounter2() {
return counter2;
}
}
I added a minimal working example with a simple test in my repository in the
Branch “opm-plcentitymanager”
(https://github.com/JulianFeinauer/incubator-plc4x/commits/opm-plcentitymanager).
This is not meant to be the final solution but to be a basis for the first
version of this feature that I would really like to add soon.
Currently I do not use dynamic proxies but only return entities with the
requested values injected.
But it should be no problem to return “attached” proxies that sync the values
from time to time or do even forward the “setXXX” methods to Plc Writes.
What do you think? How would such a feature be used and what are the necessary
things from your perspective?
Julian