I'm trying to model a network with EMF.
The network should be made up of nodes connected to each other.
Each node should have one or many connections to the others, like a mesh network.
The model should be editable by the EMF Client Platforms (ECP) Demo Application.
When the user creates nodes, in ECPs model-explorer, he/she can set the connections to the other nodes, preferably in a list.
First try was a self-reference, but the problem is there are no bidirectional self-references. This results in, not seeing the connection from the opposite node.
My next idea was to use an intermediate connection class, which leads to another problem. I would like to create this connection automatically without a connection class appearing in the model-explorer. Which would be possible to achieve in the generated EMF viewer, but not in the ECP demo application I'm using.
Third Idea: The only way I can think of solving the last idea, is using a tableControl in the view of the node, to edit the connection class in there. But then the problem with hiding the connection class in the model-explorer remains and the connection class appears in the project folder (highest level) and not in their containing class (in my case a network class).
Doe's anyone have some ideas, how to solve any of my problems?
edit: additional information
The connections between the nodes are by definition full duplex.
And the graph should afterwards be used as input for a shortest path algorithm.
Your first try is the good one. Actually, you can model opposite in Ecore. To do so, you have to model two EReferences towards the same object (so two reflexives references), then set the property eOpposite of one of your EReference to the other one.
Here is a simple metamodel with the eOpposite set: https://repository.genmymodel.com/vincent.aranega/NodeGraph
In the Ecore-XMI, it looks like this (note the eOpposite value):
<eStructuralFeatures xsi:type="ecore:EReference" xmi:id="_pwXZhv1pEeW9zv77lynsJg"
name="references" upperBound="-1" eType="#_pwXZg_1pEeW9zv77lynsJg" eOpposite="#_pwXZiv1pEeW9zv77lynsJg"/>
<eStructuralFeatures xsi:type="ecore:EReference" xmi:id="_pwXZiv1pEeW9zv77lynsJg"
name="relatives" upperBound="-1" eType="#_pwXZg_1pEeW9zv77lynsJg" eOpposite="#_pwXZhv1pEeW9zv77lynsJg" />
With this metamodel, you are able to create a Graph that contains many Node. Each node can reference other nodes. If a Node A as a reference to another named B, the relatives collection of B is automatically updated with A.
Related
A repository pattern is there to abstract away the actual data source and I do see a lot of benefits in that, but a repository should not use IQueryable to prevent leaking DB information and it should always return domain objects, not DTO's or POCO's, and it is this last thing I have trouble with getting my head around.
If a repository pattern always has to return a domain object, doesn't that mean it fetches way too much data most of the times? Lets say it returns an employee domain object with forty properties and in the service and view layers consuming that object only five of those properties are actually used.
It means the database has fetched a lot of unnecessary data a pumped that across the network. Doing that with one object is hardly noticeable, but if millions of records are pushed across that way and a lot of of the data is thrown away every time, is that not considered bad behavior?
Yes, when adding or editing or deleting the object, you will use the entire object, but reading the entire object and pushing it to another layer which uses only a fraction of it is not utilizing the underline database and network in the most optimal way. What am I missing here?
There's nothing preventing you from having a separate read model (which could a separately stored projection of the domain or a query-time projection) and separating out the command and query concerns - CQRS.
If you then put something like GraphQL in front of your read side then the consumer can decide exactly what data they want from the full model down to individual field/property level.
Your commands still interact with the full domain model as before (except where it's a performance no-brainer to use set based operations).
I am using omnet++ to change a specific route entry for a multicast group address. Usually, a multicast route entry is added by using the best (shortest) route to the source of the message.
However what I need to do is to modify this behavior for a specific multicast address so that it does not take the shortest path to source condition but instead uses "first entry".
What I mean is that, if after flooding the multicast packet (with no multicast route entry before) received on a router via three interfaces with the time of arrival like this: 1.eth0 2.eth1 3.eth2, it automatically sets interface eth0 as the RPF and does not compute whether this is the best path.
The normal behavior was already coded into omnett but when I found the functions to add new routes I do not understand where are the conditions of adding a new route.
internalAddMulticastRoute
AddMulticastRoute
As far as I understand, the methods you posted don't actually check anything with regards to which interface is used: whenever a multicast route is added, it is simply stored and used. You might want to have a look at where addMulicastRoute is called; there might be code there that controls priorities. The code in internalAddMulticastRoute only organizes the routing table (which is kept sorted through upper_bound). If you want to control which interface is used, you'll need to modify the routing table entries. I'd recommend performing a check before calling addMulticastRoute.
I have a problem in my project i have to create orchestration and base o first node of xml file i have to decide what map will be use. Any idea how to do it?
I try to use decide shape and in decide shape use xslt query to find first node equal particular node decide shape will send it to particular map.
is that a good approach?
Here's some suggestions:
If the schema can be resolved by the XmlDisassembler, the engine will apply the matching Map on the Receive Port automatically.
If the number of different Maps is manageable, say 4 or 5, and very unlikely to change, then sure, the decide shape is a workable approach.
Be sure to carefully examine the differences in the Maps. I've had times when the planners believed the maps were significantly more different then in reality. If the difference is a handful of differing codes or conditional fields, maybe one Map can handle all cases.
Another option that would use a receive location for each type of message would be to use a Listen shape in the orchestration. Each branch of the listen would be expecting a different message type (or root node as you put it) and you could apply the appropriate map. Then, assuming you are mapping to a canonical schema, the rest of the orchestration would be the same regardless of input message type.
In the image the orchestration is using a listen shape to listen for 3 types of message. It's mostly for replay-ability for when the orchestration fails at different stages, I can inject it back into the flow after a fix is made.
I'm new to symfony2 and doctrine.
here is the problem as I see it.
i cannot use :
$repository = $this->getDoctrine()->getRepository('entity');
$my_object = $repository->findOneBy($index);
on an object that is persisted, BUT NOT FLUSHED YET !!
i think getRepository read from DB, so it will not find a not-flushed object.
my question: how to read those objects that are persisted (i think they are somewhere in a "doctrine session") to re-use them before i do flush my entire batch ?
every profile has 256 physical plumes.
every profile has 1 plumeOptions record assigned to it.
In plumeOptions, I have a cartridgeplume which is a FK for PhysicalPlume.
every plume is identified by ID (auto-generated) and an INDEX (user-generated).
rule: I say profile 1 has physical_plume_index number 3 (=index) connected to it.
now, I want to copy a profile with all its related data to another profile.
new profile is created. New 256 plumes are created and copied from older profile.
i want to link the new profile to the new plume index 3.
check here: http://pastebin.com/WFa8vkt1
I think you might want to have a look at this function:
$entityManager->getUnitOfWork()->getScheduledEntityInsertions()
Gives you back a list of entity objects which are persisting yet.
Hmm, I didn't really read your question well, with the above you will retrieve a full list (as an array) but you cannot query it like with getRepository. I will try found something for u..
I think you might look at the problem from the wrong angle. Doctrine is your persistance layer and database access layer. It is the responsibility of your domain model to provide access to objects once they are in memory. So the problem boils down to how do you get a reference to an object without the persistance layer?
Where do you create the object you need to get hold of later? Can the method/service that create the object return a reference to the controller so it can propagate it to the other place you need it? Can you dispatch an event that you listen to elsewhere in your application to get hold of the object?
In my opinion, Doctrine should be used at the startup of the application (as early as possible), to initialize the domain model, and at the shutdown of the application, to persist any changes to the domain model during the request. To use a repository to get hold of objects in the middle of a request is, in my opinion, probably a code smell and you should look at how the application flow can be refactored to remove that need.
Your is a business logic problem effectively.
Querying down the Database a findby Query on Object that are not flushed yet, means heaving much more the DB layer querying object that you have already in your function scope.
Also Keep in mind a findOneBy will retrieve also other object previously saved with same features.
If you need to find only among those new created objects, you should make f.e. them in a Session Array Variable, and iterate them with the foreach.
If you need a mix of already saved items + some new items, you should threate the 2 parts separately, one with a foreach , other one with the repository query!
Suppose you have the canonical Customer domain object. You have three different screens on which Customer is displayed: External Admin, Internal Admin, and Update Account.
Suppose further that each screen displays only a subset of all of the data contained in the Customer object.
The problem is: when the UI passes data back from each screen (e.g. through a DTO), it contains only that subset of a full Customer domain object. So when you send that DTO to the Customer Factory to re-create the Customer object, you have only part of the Customer.
Then you send this Customer to your Customer Repository to save it, and a bunch of data will get wiped out because it isn't there. Tragedy ensues.
So the question is: how would you deal with this problem?
Some of my ideas:
include an argument to the
Repository indicating which part of
the Customer to update, and ignore
others
when you load the Customer, keep it in static memory, or in the session, or wherever, and then when you receive one of the DTOs from the UI, update only the parts relevant to the DTO
IMO, both of these are kludges. Are there any other better ideas?
#chadmyers: Here is the problem.
Entity has properties A, B, C, and D.
DTO #1 contains properties for B and C.
DTO #2 contains properties for C and D.
UI asks for DTO #1, you load entity from the repository, convert it into DTO #1, filling in only B and C, and give it to the UI.
Now UI updates B and sends the DTO back. You recreate the entity and it has only B and C filled in because that is all that is contained in the DTO.
Now you want to save the entity, which has only B and C filled in, with A and D null/blank. The repository has no way of knowing if it should update A and D in persistence as blanks, or whether it should ignore them.
I would use factory to load a complete customer object from repository upon receipt of DTO. After that you can update only those fields that were specified in DTO.
That also allows you to apply some optimistic concurrency on your customer by checking last-updated timestamp, for example.
Is this a web app? Load the customer object from the repo, update it from the DTO, save it back. That doesn't seem like a kludge to me. :)
UPDATE: As per your updates (the A, B, C, D example)
So what I was thinking is that when you load the entity, it has A, B, C, and D filled in. If DTO#1 only updates B & C, that's OK. A and D are unaffected (which is the desired situation).
What the repository does with the B & C updates is up to him. If you're using Hibernate/NHibernate, for example, it will just figure it out and issue an update.
Just because DTO #1 only has B & C doesn't mean you have to also null out A & D. Just leave them alone.
I missed the point of this question at first because it is predicated on a few things that I don't think make sense from a design perspective.
Hydrating an entity from repository and then converting it to a DTO is a waste of effort. I assume that your DAL passes a DTO to your repository which then converts it to a full entity object. So converting it back to a DTO seems wasteful.
Having multiple DTOs makes sense if you have a search results page that shows a high volume of records and only displays part of your entity data. In that case it's efficient to pass that page just the data it needs. It does not make sense to pass a DTO that contains partial data to a CRUD page. Just give it a full DTO or even a full entity object. If it doesn't use all of the data, fine, no harm done.
So that main problem is that I don't think you should pass data to these pages using partial DTOs. If you used a full DTO, I would do the following 3 steps whenever the save action is performed:
Pull the full DTO from repository or db
Update the DTO with any changes made through the form
Save the full DTO back to the repository or db
This method requires an extra db hit but that's really not a significant issue on a CRUD form.
If we have an understanding that a Repository handles (almost exclusively) very rich domain Entity, then you numerous DTO's could simply map back.
i.e.
dtoUser.MapFrom<In,Out>(Entity)
or
dtoAdmin.MapFrom<In,Out>(Entity)
you would do the reverse to get the dto information back to the Entity and so on. So your repository only saves rich Entity's NOT numerous DTO's
entity.Foo = dtoUser.Foo
or
entity.Bar = dtoAdmin.Bar
entityRepsotiry.Save(entity) <-- do not pass DTO.
The whole point of DTO's is to keep things simple for the presentation or say for WCF dataTransfer, it has nothing to do with the Repository or the Entity for that matter.
Furthermore, you should never construct an Entity from DTO's... the only two ways to ever acquire an Entity is through a Factory(new) or a Repository(existing) respectively.
You mention storing the Entity somewhere, why would you do this? That is the job of your repository. It will decide where to get the Entity(db,cache,e.t.c), no need to store it somewhere else.
Hope that helps assign responsibility in your domain, it is always a challenge and there are gray area's here and there but in general, these are the typical uses of Repository, DTO e.t.c.