Skip to main content
Jump to: navigation, search

Difference between revisions of "MoDisco/Components/QueryManager/Documentation/0.8"

(Remove introduction (already exists in MoDisco/QueryManager/Presentation))
m (MoDisco/QueryManager/Documentation moved to MoDisco/QueryManager/Documentation/0.8: QueryManager does not exist in version 0.7)
Line 5: Line 5:
  
 
Right-click on the MoDisco project and select the "New > Other ..." button.
 
Right-click on the MoDisco project and select the "New > Other ..." button.
 
Select "Query Model" and press the "Next" button
 
  
 
[[Image:NewModelQuerySet 001.png]]
 
[[Image:NewModelQuerySet 001.png]]
  
Select "Query Model" and press the "Next" button
+
Select "QuerySet Model" and press the "Next" button
  
 
[[Image:MoDisco_Query_newModelQuerySet_002.png]]
 
[[Image:MoDisco_Query_newModelQuerySet_002.png]]
Line 24: Line 22:
  
 
Set the description of the query set and take care that the query
 
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
+
set name is the same as the containing file name ("My" in the
 
example).
 
example).
  
Line 31: Line 29:
 
Load the resources containing the meta-models used by the model
 
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
 
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.
+
resource use the "Load meta-model resource" action.
  
 
[[Image:MoDisco_Query_newModelQuerySet_008.png]]
 
[[Image:MoDisco_Query_newModelQuerySet_008.png]]
Line 49: Line 47:
 
[[Image:MoDisco_Query_newModelQuerySet_011.png]]
 
[[Image:MoDisco_Query_newModelQuerySet_011.png]]
  
Right click on the ModelQuerySet element and choose the "New >
+
Right click on the ModelQuerySet element and choose the "New Child >
 
Java Model Query" action to create a "Java Model Query".
 
Java Model Query" action to create a "Java Model Query".
  
Line 60: Line 58:
 
[[Image:MoDisco_Query_newModelQuerySet_013.png]]
 
[[Image:MoDisco_Query_newModelQuerySet_013.png]]
  
Fill the "Scope" field with meta-class on which the query will be
+
Fill the "Scope" field with the meta-class to which the query will be
 
applicable.
 
applicable.
  
Line 73: Line 71:
 
A MoDisco project is also a "Plug-in project". To be able to
 
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
 
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.
+
implementation plug-in in the plug-in dependencies.
  
 
[[Image:MoDisco_Query_newModelQuerySet_020_1.png]]
 
[[Image:MoDisco_Query_newModelQuerySet_020_1.png]]
  
Java Query implementation class must implement
+
The Java Query implementation class must implement
 
org.eclipse.gmt.modisco.query.core.java.IJavaModelQuery.
 
org.eclipse.gmt.modisco.query.core.java.IJavaModelQuery.
  
Line 84: Line 82:
 
[[Image:MoDisco_Query_newModelQuerySet_021.png]]
 
[[Image:MoDisco_Query_newModelQuerySet_021.png]]
  
==How to consult the MoDisco query set catalog trough the UI==
+
==How to consult the MoDisco query set catalog through the UI==
 
If a query set model is valid, it is registered in the model
 
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
 
query set catalog. To consult the model query set catalog, we can use
Line 90: Line 88:
  
 
To get this view select "Windows > Show view > Other ..."
 
To get this view select "Windows > Show view > Other ..."
in the menu bar and chose "Query Set" in the list.
+
in the menu bar and choose "Query Set" in the list.
  
 
[[Image:MoDisco_Query_newModelQuerySet_022.png]]
 
[[Image:MoDisco_Query_newModelQuerySet_022.png]]
 
[[Image:MoDisco_Query_newModelQuerySet_023.png]]
 
[[Image:MoDisco_Query_newModelQuerySet_023.png]]
  
The "Query set" view presents the available query sets and them
+
The "Query set" view presents the available query sets and their
queries. For each query, the description model location is point out.
+
queries. For each query, the description model location is pointed out.
  
 
[[Image:MoDisco_Query_newModelQuerySet_024.png]]
 
[[Image:MoDisco_Query_newModelQuerySet_024.png]]
Line 102: Line 100:
 
==How to programmatically use the MoDisco query set catalog.==
 
==How to programmatically use the MoDisco query set catalog.==
  
Here a MoDisco query API example is provided. To have more
+
Here a MoDisco query API example is provided. For more
informations please refer to the JavaDoc.
+
information please refer to the JavaDoc.
  
 
  import org.eclipse.emf.ecore.EObject;
 
  import org.eclipse.emf.ecore.EObject;
Line 147: Line 145:
 
[[Image:MoDisco_Query_Metamodel.png]]
 
[[Image:MoDisco_Query_Metamodel.png]]
  
ModelQuerySet is the root of query model. One root per query
+
ModelQuerySet is the root of the query model. One root per query
 
model is expected.
 
model is expected.
  
 
ModelQuerySet::name must be unique (in the Eclipse platform) and
 
ModelQuerySet::name must be unique (in the Eclipse platform) and
 
equal to the containing file name. We recommend to use a name prefix
 
equal to the containing file name. We recommend to use a name prefix
with a name space, for example: org.eclipse.gmt.modisco.example1.querySet1.
+
with a namespace, for example: org.eclipse.gmt.modisco.example1.querySet1.
  
 
ModelQuerySet::isEditable is true if the query can be edited. If
 
ModelQuerySet::isEditable is true if the query can be edited. If
the query is stored into a compiled file ModelQuerySet::isEditable is
+
the query is stored into a compiled file then ModelQuerySet::isEditable is
 
false.
 
false.
  
Line 171: Line 169:
 
names must be unique.
 
names must be unique.
  
<p>ModelQuery::parameters a set of ModelQueryParameter instance
+
ModelQuery::parameters a set of ModelQueryParameter instances
describing the query parameters.</p>
+
describing the query parameters.
  
 
ModelQuery::returnType is an ecore::DataType representing the
 
ModelQuery::returnType is an ecore::DataType representing the
 
query return type.
 
query return type.
  
ModelQuery::scope is the set of type on which the query is
+
ModelQuery::scope is the set of types on which the query is
 
applicable. Those types are represented by ecore::DataType instances.
 
applicable. Those types are represented by ecore::DataType instances.
  
Line 199: Line 197:
 
of org.eclipse.gmt.modisco.infra.query.core.java.IJavaModelQuery. The
 
of org.eclipse.gmt.modisco.infra.query.core.java.IJavaModelQuery. The
 
Java implementation class must be stored in the same plug-in (or plug-in
 
Java implementation class must be stored in the same plug-in (or plug-in
project) than the query model.
+
project) as the query model.
  
 
OCLModelQuery::query is the OCL query string.
 
OCLModelQuery::query is the OCL query string.
Line 208: Line 206:
 
[[Image:MoDisco_Query_jxpath_metamodel.png|JXPath Query Meta-model Extension]]
 
[[Image:MoDisco_Query_jxpath_metamodel.png|JXPath Query Meta-model Extension]]
  
An JXPathModelQuery is a ModelQuery describing a '''[http://commons.apache.org/jxpath/ JXPath]''' expression.
+
A JXPathModelQuery is a ModelQuery describing a '''[http://commons.apache.org/jxpath/ JXPath]''' expression.
  
The JXPath expression are stored into the JXPathModelQuery::query attribure.
+
The JXPath expressions are stored into the JXPathModelQuery::query attribure.
  
 
=== Example ===
 
=== Example ===
  
 
The '''[http://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.infra.query.doc/doc/resources/jxpathQueryTest.querySet jxpathQueryTest.querySet]'''
 
The '''[http://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.infra.query.doc/doc/resources/jxpathQueryTest.querySet jxpathQueryTest.querySet]'''
model provide an example of JXPath query. The JXPathQuery stored into
+
model provides an example of a JXPath query. The JXPathQuery stored into
 
'''[http://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.infra.query.doc/doc/resources/jxpathQueryTest.querySet jxpathQueryTest.querySet]''' returns the name of the EPackage passed in the query
 
'''[http://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.infra.query.doc/doc/resources/jxpathQueryTest.querySet jxpathQueryTest.querySet]''' returns the name of the EPackage passed in the query
 
context.
 
context.
  
 
[[Category:MoDisco]]
 
[[Category:MoDisco]]

Revision as of 11:29, 20 January 2010

MoDisco
Website
Download
Community
Mailing ListForums
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse SourceProject Set File

How to create a MoDisco query set

The first step is to create a MoDisco project.

Right-click on the MoDisco project and select the "New > Other ..." button.

NewModelQuerySet 001.png

Select "QuerySet Model" and press the "Next" button

MoDisco Query newModelQuerySet 002.png

Choose a name for your model query set (My.querySet in the example) and press "Finish".

MoDisco Query newModelQuerySet 003.png

Open the "My.querySet" file and open the "Properties View"

MoDisco Query newModelQuerySet 006.png

Set the description of the query set and take care that the query set name is the same as the containing file name ("My" in the example).

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 use the "Load meta-model resource" action.

MoDisco Query newModelQuerySet 008.png

In this example, we choose to use the KDM meta-model.

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.

MoDisco Query newModelQuerySet 010.png

In this example we use the "core" package.

MoDisco Query newModelQuerySet 011.png

Right click on the ModelQuerySet element and choose the "New Child > Java Model Query" action to create a "Java Model Query".

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.

MoDisco Query newModelQuerySet 013.png

Fill the "Scope" field with the meta-class to which the query will be applicable.

MoDisco Query newModelQuerySet 014.png MoDisco Query newModelQuerySet 015.png MoDisco Query newModelQuerySet 016.png

Create the query's implementation class.

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 dependencies.

MoDisco Query newModelQuerySet 020 1.png

The Java Query implementation class must implement org.eclipse.gmt.modisco.query.core.java.IJavaModelQuery.

MoDisco Query newModelQuerySet 018.png MoDisco Query newModelQuerySet 020.png MoDisco Query newModelQuerySet 021.png

How to consult the MoDisco query set catalog through 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 choose "Query Set" in the list.

MoDisco Query newModelQuerySet 022.png MoDisco Query newModelQuerySet 023.png

The "Query set" view presents the available query sets and their queries. For each query, the description model location is pointed out.

MoDisco Query newModelQuerySet 024.png

How to programmatically use the MoDisco query set catalog.

Here a MoDisco query API example is provided. For more information 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();
	}
}


Query Meta-model Description

MoDisco Query Metamodel.png

ModelQuerySet is the root of the query model. One root per query model is expected.

ModelQuerySet::name must be unique (in the Eclipse platform) and equal to the containing file name. We recommend to use a name prefix with a namespace, for example: org.eclipse.gmt.modisco.example1.querySet1.

ModelQuerySet::isEditable is true if the query can be edited. If the query is stored into a compiled file then ModelQuerySet::isEditable is false.

ModelQuerySet::getQuery(EString) returns the contained ModelQuery having the requested name.

ModelQuerySet::associatedMetamodels points to the meta-models used by the contained queries.

ModelQuerySet::queries refers to the contained queries.

ModelQuery is an abstract class representing a query.

ModelQuery::name is the query name. In each query set the query names must be unique.

ModelQuery::parameters a set of ModelQueryParameter instances describing the query parameters.

ModelQuery::returnType is an ecore::DataType representing the query return type.

ModelQuery::scope is the set of types on which the query is applicable. Those types are represented by ecore::DataType instances.

ModelQueryParameter is a class representing the query parameters.

ModelQueryParameter::type is an ecore::DataType representing the query parameter type.

ModelQueryParameter::name is the parameter name. In each query the parameter names must be unique.

ModelQuery::isExternalContextDependent must be true if two evaluations of the same query with the same context and parameters can return different results.

JavaModelQuery is a sub class of ModelQuery which points to a Java implemented query.

JavaModelQuery::implemenationClassName contains the qualified name of the class implementing the query. This class must be a sub class of org.eclipse.gmt.modisco.infra.query.core.java.IJavaModelQuery. The Java implementation class must be stored in the same plug-in (or plug-in project) as the query model.

OCLModelQuery::query is the OCL query string.


JXPath Queries

JXPath Meta-model Extension Description

JXPath Query Meta-model Extension

A JXPathModelQuery is a ModelQuery describing a JXPath expression.

The JXPath expressions are stored into the JXPathModelQuery::query attribure.

Example

The jxpathQueryTest.querySet model provides an example of a JXPath query. The JXPathQuery stored into jxpathQueryTest.querySet returns the name of the EPackage passed in the query context.

Back to the top