|
|
(19 intermediate revisions by 4 users not shown) |
Line 1: |
Line 1: |
− | The MoDisco query component allows to execute model queries independently of any technology. To offer this feature, the component provides a meta-model to describe queries and a set of tools to manage the queries and them descriptions.
| + | #REDIRECT [[MoDisco/Moved To Help Center]] |
− | | + | |
− | The attached archive contains driver for Java, ATL, OCL and JXPath. Other drivers can be written to other query technologies.
| + | |
− | | + | |
− | == How to create a MoDisco query set ==
| + | |
− | Right-click on the MoDisco project and select the "New > Other ..." button.
| + | |
− | | + | |
− | Select "Query Model" and press the "Next" button
| + | |
− | | + | |
− | [[Image:NewModelQuerySet 001.png]]
| + | |
− | | + | |
− | Select "Query Model" and press the "Next" button
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_002.png]]
| + | |
− | | + | |
− | Choose a name for your model query set (My.querySet in the
| + | |
− | example) and press "Finish".
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_003.png]]
| + | |
− | | + | |
− | Open the "My.querySet" file and open the "Properties View"
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_006.png]]
| + | |
− | | + | |
− | Set the description of the query set and take care that the query
| + | |
− | set name is the same than the containing file name ("My" in the
| + | |
− | example).
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_007.png]]
| + | |
− | | + | |
− | Load the resources containing the meta-models used by the model
| + | |
− | queries that will be owned by the query set. To load a meta-model
| + | |
− | resource the user must use the "Load meta-model resource" action.
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_008.png]]
| + | |
− | | + | |
− | In this example, we choose to use the KDM meta-model.
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_009.png]]
| + | |
− | | + | |
− | Fill the "Associated Metamodels" field with the ePackages
| + | |
− | containing the meta-models used by the model queries that will be owned
| + | |
− | by the query set.
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_010.png]]
| + | |
− | | + | |
− | In this example we use the "core" package.
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_011.png]]
| + | |
− | | + | |
− | Right click on the ModelQuerySet element and choose the "New >
| + | |
− | Java Model Query" action to create a "Java Model Query".
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_012.png]] | + | |
− | | + | |
− | Set the name, the description and the return type of the query.
| + | |
− | Set the "Implementation Class Name" field with the qualified name of the
| + | |
− | class that will contain the query's Java implementation.
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_013.png]]
| + | |
− | | + | |
− | Fill the "Scope" field with meta-class on which the query will be
| + | |
− | applicable.
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_014.png]]
| + | |
− | [[Image:MoDisco_Query_newModelQuerySet_015.png]]
| + | |
− | [[Image:MoDisco_Query_newModelQuerySet_016.png]]
| + | |
− | | + | |
− | Create the query's implementation class.
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_017.png]]
| + | |
− | | + | |
− | A MoDisco project is also a "Plug-in project". To be able to
| + | |
− | refer to the API of the used meta-model, we have to add the "org.eclipse.gmt.modisco.infra.query.core" plug-in and the meta-model
| + | |
− | implementation plug-in in the plug-in dependences.
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_020_1.png]]
| + | |
− | | + | |
− | Java Query implementation class must implement
| + | |
− | org.eclipse.gmt.modisco.query.core.java.IJavaModelQuery.
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_018.png]]
| + | |
− | [[Image:MoDisco_Query_newModelQuerySet_020.png]]
| + | |
− | [[Image:MoDisco_Query_newModelQuerySet_021.png]]
| + | |
− | | + | |
− | ==How to consult the MoDisco query set catalog trough the UI==
| + | |
− | If a query set model is valid, it is registered in the model
| + | |
− | query set catalog. To consult the model query set catalog, we can use
| + | |
− | the "Model Query Set" view.
| + | |
− | | + | |
− | To get this view select "Windows > Show view > Other ..."
| + | |
− | in the menu bar and chose "Query Set" in the list.
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_022.png]]
| + | |
− | [[Image:MoDisco_Query_newModelQuerySet_023.png]]
| + | |
− | | + | |
− | The "Query set" view presents the available query sets and them
| + | |
− | queries. For each query, the description model location is point out.
| + | |
− | | + | |
− | [[Image:MoDisco_Query_newModelQuerySet_024.png]]
| + | |
− | | + | |
− | ==How to programmatically use the MoDisco query set catalog.==
| + | |
− | | + | |
− | Here a MoDisco query API example is provided. To have more
| + | |
− | informations please refer to the JavaDoc.
| + | |
− | | + | |
− | | + | |
− | import org.eclipse.emf.ecore.EObject;
| + | |
− | | + | |
− | import org.eclipse.gmt.modisco.infra.query.ModelQuery;
| + | |
− | | + | |
− | import org.eclipse.gmt.modisco.infra.query.ModelQuerySet;
| + | |
− | | + | |
− | import org.eclipse.gmt.modisco.infra.query.core.AbstractModelQuery;
| + | |
− | | + | |
− | import org.eclipse.gmt.modisco.infra.query.core.ModelQuerySetCatalog;
| + | |
− | | + | |
− | import org.eclipse.gmt.modisco.infra.query.runtime.ModelQueryResult;
| + | |
− | | + | |
− | public class Example {
| + | |
− | | + | |
− | public Integer main(EObject context) throws Exception {
| + | |
− | | + | |
− | //Get the model query set catalog.
| + | |
− | | + | |
− | ModelQuerySetCatalog catalog = ModelQuerySetCatalog.getSingleton();
| + | |
− | | + | |
− | //Get the query set named "My".
| + | |
− | | + | |
− | ModelQuerySet modelQuerySet = catalog.getModelQuerySet("My");
| + | |
− | | + | |
− | //Select into the "My" query set a query named "myQuery".
| + | |
− | | + | |
− | //modelQueryDescription is a model element.
| + | |
− | | + | |
− | ModelQuery modelQueryDescription = null;
| + | |
− | | + | |
− | for (ModelQuery modelQuery : modelQuerySet.getQueries()) {
| + | |
− | | + | |
− | if (modelQuery.getName().equals("myQuery")) {
| + | |
− | | + | |
− | modelQueryDescription = modelQuery;
| + | |
− | | + | |
− | break;
| + | |
− | }
| + | |
− | | + | |
− | }
| + | |
− | if (modelQueryDescription == null) {
| + | |
− | | + | |
− | throw new Exception();
| + | |
− | | + | |
− | }
| + | |
− | //Get a java instance of the querySet
| + | |
− | | + | |
− | AbstractModelQuery myModelQuery = catalog
| + | |
− | | + | |
− | .getModelQueryImpl(modelQueryDescription);
| + | |
− | | + | |
− | //the model query set evaluation
| + | |
− | | + | |
− | ModelQueryResult result = myModelQuery.evaluate(context);
| + | |
− | | + | |
− | if (result.getException() != null) {
| + | |
− | | + | |
− | throw new Exception();
| + | |
− | | + | |
− | }
| + | |
− | | + | |
− | return (Integer) result.getValue();
| + | |
− | | + | |
− | }
| + | |
− | | + | |
− | }
| + | |