I'm trying to create some Java classes from my ECore Model. In this model, some classes must implement Iterable<Something>. To make this happen, I added a EClass Iterable and set its Instance Type Name to java.lang.Iterable. This prevents the ECore Code Generator from generating code for Iterable while still allowing me to use it a ESuper Types for the classes which I want to implement this interface
Is this the right way to do it?
The problem with this approach is, that all editors (I tried the "Sample Reflective eCore Editor" and the "Generic EMF Form Editor" fail to edit a instance of the Model. Both editors are unable to find the Iterable type and show a error "Class 'Iterable' is a unkown classifier".
Is there a workaround or a solution for this?
No I don't think that is right. You should use the #extends annotation to the class comment section for any place you want to add an external Java interface. That way your interface will not get blown away during generation. This is from page 308 (Section 10.11) of EMF book:
/**
* <!-- begin-user-doc -->
* A representation of the model object 'PurchaseOrder'.
* #extends Serializable
* <!-- end-user-doc -->
*
*
* #model
* #generated
*/
public interface PurchaseOrder extends EObject, Serializable
{...
Related
Without scrutinizing why I want this (it may sound like a bad approach, but I have good reason) I want to know if there is a way in the standard-framework-edition 3.1+ to create a relational association to an entity that may not exist...
Firstly I do realize this determines the schema and that's fine. So if an entity does not exist, it doesn't create a foreign key and the field is always null, or if the target entity does exist, it creates the foreign key and the field works like a normal association...
Secondly, this only changes project to project, and may change down the line as an update to which I realize a manual schema update could be necessary.
Preferably without 3rd party bundle dependencies... hoping for the standard framework to do this,
Anybody?
Thanks in advance
Edit
I am using annotations in my entities with doctrine ORM
Furthermore
The simplest version of why I am doing this is because certain bundles are optional project-to-project, and bundle A may make use of entities in bundle B only if it is present. I have considered using services and if container->has then container->get, or the XML on-invalid="null" approach, but that doesn't address property persistence. I was happy with storing a non-mapped value as a custom relational field, which is fine, just lengthier and wondered if perhaps there was a way Doctrine could ignore a missing targetEntity...
Hm, perhaps I misunderstand your question, but this sounds like a normal 'nullable' association to me?
Create your assocation via annotation:
/**
*
* #var Child
* #ORM\ManyToOne(targetEntity="Child")
*/
private $child;
and use
setChild(Child $child = null)
{
$this->child = $child;
}
as a Setter to allow nullable values.
And your getter might look like:
getChild()
{
return $this->child;
}
In case there isn't any child it will return null.
I will keep the other answer as it responds to the question for a 'nullable association target' live data.
This is the answer for a 'nullable association target' meta data which is a different thing.
OP asks to provide a targetEntity in the metadata which cannot exist in his case, e.g. is not there in a different bundle (or whatever OP's mysterious reason might be).
In that case I recommend to build upon Doctrine's TargetEntityListener which is able to resolve the targetEntity during runtime and targetEntity can be set to an Abstract Class or an Interface:
/**
* #ORM\ManyToOne(targetEntity="Acme\InvoiceBundle\Model\InvoiceSubjectInterface")
* #var InvoiceSubjectInterface
*/
protected $subject;
InvoiceSubjectInterface will then be replaced during runtime by a specific class provided by config e.g.:
# app/config/config.yml
doctrine:
# ...
orm:
# ...
resolve_target_entities:
Acme\InvoiceBundle\Model\InvoiceSubjectInterface: AppBundle\Entity\Customer
So this should be eiter an extendable behaviour for providing no class or implementing an own solution.
I need to create an like/dislike system which can be used on any entity. I'm going to create a Like entity with an 'Id', 'Entity' (can be anything), 'author' (ManyToOne with User class) and 'like' (boolean).
I just want to know if there is a good way to do it ?
I can't use the table inheritance (mappedsuperclass) because this entity will be part of a bundle (SocialBundle) which can be used on several project (It will be a vendor).
I have no code to show you because i'm still in the analysis part.
Thanks !
Create an interface for that entity and later you can map this interface to any entity using addResolveTargetEntity method. See this.
Suppose I have a UML model conforming to the org.eclipse.uml2.uml metamodel. Suppose that this model contains a Class, a Property, and an ownedAttribute relationship between them.
At the Ecore level, the Class and the Property are EObjects, while the ownedAttribute is an EReference.
My task is as follows: given an EObject, retrieve all of its EReferences. I can accomplish this using the following code snippet:
for (EReference eRef : myEObject.eClass().getEAllReferences()) {
if (eObject.eIsSet(eRef)) {
// found a relevant EReference
}
}
Going back to the UML example above, this code snippet would identify all of the following EReferences: ownedElement, ownedMember, member, feature, attribute, ownedAttribute, role.
My problem: out of the identified EReferences, I would like to keep only ownedAttribute, since this relationship subsets all of the others according to the UML standard. However, the Ecore metamodel does not specify any kind of hierarchy between EReferences. What approach could I use to filter out the more general EReferences that I am not interested in?
You can filter out 'derived' references (org.eclipse.emf.ecore.EStructuralFeature.isDerived() == false).
I'm using POCO to auto generate my entities from DAL project to Entities project. I currently have no need in creating view classes manually.
However I have one problem - When I try to return a poco object that has navigation properties from a [WebMethod] I get the following error:
Cannot serialize member Entities.City.Customers of type System.Collections.Generic.ICollection1[[Entities.Customer, Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] because it is an interface.
I tried writing context.ContextOptions.LazyLoadingEnabled = false; and
context.ContextOptions.ProxyCreationEnabled = false; to no avail.
if I add [System.Xml.Serialization.XmlIgnore] before the properties, I get no error, but then I lose those properties?
The message is clear: serialization fails because your Entities.City.Customers member is declared as an interface (ICollection).
The interface does not say anything about the implementing type, it only defines the contract that the implementation should follow. As such, the serializer does not know how to represent the implementation in a serialized format.
You might think that it's not that hard to reflect the type and serialize based on the information you get from introspection, but the problem will be when you try to deserialize from this representation. The same representation could possibly correspond to all implementation types, in which case what should the serializer choose as the concrete type?
There are a few steps to work around this limitation, as you can find in this post: XML serialization of interface property. In your particular case, the simplest way would be to make the Entities.City.Customers member of a concrete type like List<Customer> instead of ICollection<Customer>.
In the rule studio BOM editor , there is BOM to XOM mapping window and it asks for execution name and extender name. I can write java code in a separate project and import it as BOM. So what is the purpose of this extender mechanism ? As always IBM doc says how to do it. But doesn't tell why !
As far as I remember the first displayed is execution:
It is used when you create a "Virtual Member" meaning in Ilog terminology: a method or attribute or class which doesn't rely on a XOM.
Remember that you can create an empty BOM or you can add a method or attribute in a BOM class based on a XOM
The easiest example is "age" NO database will ever store such field but you could had a piece a logic in a "virtual attribute or method" in order to do the comparison between Date of birth and today.
If you create a class from scratch (not an attribute or method) a kind of "Virtual Object" you still need to tell JRules how to consider this Object at runtime.
So you use this field to tell JRules, here is a virtual class based on no XOM but at execution time use it as an java.lang.Object
I never used this field with any other Class than java.lang.Object
Does it make sense?
Second one is really like "extends" in pure java. Never used it... No need.
Hope it helps
To complete Damien answer :
The "execution name" field is also used when your bom class don't have the same name as the xom class.
From the Jrules 7.0.2 doc :
For example, in your BOM, there is a business class named ShoppingCart. You need to map this business class to an execution class called Cart in the XOM. To do the mapping, select the class ShoppingCart, and in the BOM Editor specify Cart as the Execution name.