Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dql
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Descartes Research
dql
Commits
cf3a922f
Commit
cf3a922f
authored
8 years ago
by
Simon Eismann
Browse files
Options
Downloads
Patches
Plain Diff
Graphics engine is now only called if it is actually a
PerformanceMetricQuery
parent
407bfd35
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/tools.descartes.dql.core.engine/src/tools/descartes/dql/core/engine/query/QueryExecutionEngineImpl.java
+181
-182
181 additions, 182 deletions
...artes/dql/core/engine/query/QueryExecutionEngineImpl.java
with
181 additions
and
182 deletions
core/tools.descartes.dql.core.engine/src/tools/descartes/dql/core/engine/query/QueryExecutionEngineImpl.java
+
181
−
182
View file @
cf3a922f
/**
* ==============================================
* DQL : Descartes Query Language
* ==============================================
*
* (c) Copyright 2014-2016, by Juergen Walter, Fabian Gorsler, Fabian Brosig and other contributors.
*
* Project Info: http://descartes.tools/dql
*
* All rights reserved. This software is made available under the terms of the
* Eclipse Public License (EPL) v1.0 as published by the Eclipse Foundation
* http://www.eclipse.org/legal/epl-v10.html
*
* This software is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Eclipse Public License (EPL)
* for more details.
*
* You should have received a copy of the Eclipse Public License (EPL)
* along with this software; if not visit http://www.eclipse.org or write to
* Eclipse Foundation, Inc., 308 SW First Avenue, Suite 110, Portland, 97204 USA
* Email: license (at) eclipse.org
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*/
package
tools.descartes.dql.core.engine.query
;
import
static
tools
.
descartes
.
dql
.
core
.
engine
.
util
.
QueryParserHelper
.
stringToModel
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.log4j.Logger
;
import
org.eclipse.emf.common.util.EList
;
import
org.eclipse.emf.ecore.EObject
;
import
org.eclipse.emf.ecore.resource.Resource
;
import
tools.descartes.dql.connector.QueryProgressListener
;
import
tools.descartes.dql.core.engine.interpreter.ModelStructureQueryInterpreter
;
import
tools.descartes.dql.core.engine.interpreter.PerformanceMetricsQueryInterpreter
;
import
tools.descartes.dql.core.engine.interpreter.QueryInterpreter
;
import
tools.descartes.dql.core.engine.util.DQLLogger
;
import
tools.descartes.dql.lang.descartesQL.DescartesQL
;
import
tools.descartes.dql.lang.descartesQL.ListQuery
;
import
tools.descartes.dql.lang.descartesQL.ModelStructureQuery
;
import
tools.descartes.dql.lang.descartesQL.PerformanceIssueQuery
;
import
tools.descartes.dql.lang.descartesQL.PerformanceMetricsQuery
;
import
tools.descartes.dql.lang.descartesQL.SelectQuery
;
import
tools.descartes.dql.lang.descartesQL.UsingClause
;
import
tools.descartes.dql.models.mapping.mapping.EntityMapping
;
import
tools.descartes.dql.vizualization.GraphicsEngine
;
import
tools.descartes.dql.vizualization.GraphicsEngine
;
public
class
QueryExecutionEngineImpl
implements
QueryExecutionEngine
{
private
final
Logger
log
=
DQLLogger
.
getLogger
(
this
.
getClass
().
getName
());
private
boolean
validQuery
=
false
;
private
EObject
query
=
null
;
private
ArrayList
<
EntityMapping
>
createEmptyResultList
()
{
return
new
ArrayList
<
EntityMapping
>(
0
);
}
private
List
<
EntityMapping
>
execute
(
List
<
QueryProgressListener
>
listeners
)
{
QueryInterpreter
interpreter
;
validQuery
=
false
;
if
(
query
==
null
)
{
log
.
error
(
"Query is null, aborting."
);
return
createEmptyResultList
();
}
// Pick the right query interpreter for the incoming query instance
if
(
query
instanceof
ModelStructureQuery
)
{
interpreter
=
new
ModelStructureQueryInterpreter
((
ModelStructureQuery
)
query
,
listeners
);
}
else
if
(
query
instanceof
PerformanceMetricsQuery
)
{
interpreter
=
new
PerformanceMetricsQueryInterpreter
((
PerformanceMetricsQuery
)
query
,
listeners
);
}
else
if
(
query
instanceof
PerformanceIssueQuery
)
{
log
.
error
(
"Performance Issues not yet supported, aborting."
);
return
createEmptyResultList
();
}
else
{
log
.
error
(
"No suitable QueryInterpreter found, aborting."
);
return
createEmptyResultList
();
}
// Store state
validQuery
=
interpreter
.
interpretQuery
();
// Pass back to GC
GraphicsEngine
a
=
new
GraphicsEngine
(
"Query Result Visualization"
,
interpreter
.
getResult
());
query
=
null
;
return
interpreter
.
getResults
();
}
@Override
public
List
<
EntityMapping
>
execute
(
final
DescartesQL
query
)
{
return
execute
(
query
,
new
ArrayList
<
QueryProgressListener
>());
}
@Override
public
List
<
EntityMapping
>
execute
(
final
Resource
model
)
{
return
execute
(
model
,
new
ArrayList
<
QueryProgressListener
>());
}
@Override
public
List
<
EntityMapping
>
execute
(
final
String
query
)
{
return
execute
(
query
,
new
ArrayList
<
QueryProgressListener
>());
}
@Override
public
List
<
EntityMapping
>
execute
(
final
DescartesQL
query
,
List
<
QueryProgressListener
>
listeners
)
{
setModel
(
query
);
return
execute
(
listeners
);
}
@Override
public
List
<
EntityMapping
>
execute
(
final
Resource
model
,
List
<
QueryProgressListener
>
listeners
)
{
setModel
(
model
);
return
execute
(
listeners
);
}
@Override
public
List
<
EntityMapping
>
execute
(
final
String
query
,
List
<
QueryProgressListener
>
listeners
)
{
setModel
(
query
);
return
execute
(
listeners
);
}
@Override
public
boolean
isValidQuery
()
{
return
validQuery
;
}
private
void
setModel
(
final
DescartesQL
query
)
{
this
.
query
=
query
.
getQuery
();
}
private
void
setModel
(
final
Resource
model
)
{
EList
<
EObject
>
contents
=
null
;
if
(
model
==
null
)
{
log
.
error
(
"The model instance is null, aborting."
);
return
;
}
contents
=
model
.
getContents
();
if
(
contents
.
size
()
!=
1
)
{
log
.
error
(
"Invalid model structure, more than one root element"
);
return
;
}
query
=
((
DescartesQL
)
contents
.
get
(
0
)).
getQuery
();
// relative to absolute paths
UsingClause
clause
=
null
;
if
(
query
instanceof
ListQuery
)
{
clause
=
((
ListQuery
)
query
).
getUsingClause
();
}
else
if
(
query
instanceof
SelectQuery
)
{
clause
=
((
SelectQuery
)
query
).
getUsingClause
();
}
if
(
clause
!=
null
)
{
String
location
=
clause
.
getModelReference
().
getModel
().
getLocation
();
if
(!
new
File
(
location
).
exists
())
{
location
=
(
new
File
(
model
.
getURI
().
path
())).
getParentFile
().
getAbsolutePath
()
+
File
.
separator
+
location
;
clause
.
getModelReference
().
getModel
().
setLocation
(
location
);
}
}
}
private
void
setModel
(
final
String
query
)
{
final
DescartesQL
queryModel
=
stringToModel
(
query
);
this
.
query
=
queryModel
.
getQuery
();
}
}
/**
* ==============================================
* DQL : Descartes Query Language
* ==============================================
*
* (c) Copyright 2014-2016, by Juergen Walter, Fabian Gorsler, Fabian Brosig and other contributors.
*
* Project Info: http://descartes.tools/dql
*
* All rights reserved. This software is made available under the terms of the
* Eclipse Public License (EPL) v1.0 as published by the Eclipse Foundation
* http://www.eclipse.org/legal/epl-v10.html
*
* This software is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Eclipse Public License (EPL)
* for more details.
*
* You should have received a copy of the Eclipse Public License (EPL)
* along with this software; if not visit http://www.eclipse.org or write to
* Eclipse Foundation, Inc., 308 SW First Avenue, Suite 110, Portland, 97204 USA
* Email: license (at) eclipse.org
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*/
package
tools.descartes.dql.core.engine.query
;
import
static
tools
.
descartes
.
dql
.
core
.
engine
.
util
.
QueryParserHelper
.
stringToModel
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.log4j.Logger
;
import
org.eclipse.emf.common.util.EList
;
import
org.eclipse.emf.ecore.EObject
;
import
org.eclipse.emf.ecore.resource.Resource
;
import
tools.descartes.dql.connector.QueryProgressListener
;
import
tools.descartes.dql.core.engine.interpreter.ModelStructureQueryInterpreter
;
import
tools.descartes.dql.core.engine.interpreter.PerformanceMetricsQueryInterpreter
;
import
tools.descartes.dql.core.engine.interpreter.QueryInterpreter
;
import
tools.descartes.dql.core.engine.util.DQLLogger
;
import
tools.descartes.dql.lang.descartesQL.DescartesQL
;
import
tools.descartes.dql.lang.descartesQL.ListQuery
;
import
tools.descartes.dql.lang.descartesQL.ModelStructureQuery
;
import
tools.descartes.dql.lang.descartesQL.PerformanceIssueQuery
;
import
tools.descartes.dql.lang.descartesQL.PerformanceMetricsQuery
;
import
tools.descartes.dql.lang.descartesQL.SelectQuery
;
import
tools.descartes.dql.lang.descartesQL.UsingClause
;
import
tools.descartes.dql.models.mapping.mapping.EntityMapping
;
import
tools.descartes.dql.vizualization.GraphicsEngine
;
public
class
QueryExecutionEngineImpl
implements
QueryExecutionEngine
{
private
final
Logger
log
=
DQLLogger
.
getLogger
(
this
.
getClass
().
getName
());
private
boolean
validQuery
=
false
;
private
EObject
query
=
null
;
private
ArrayList
<
EntityMapping
>
createEmptyResultList
()
{
return
new
ArrayList
<
EntityMapping
>(
0
);
}
private
List
<
EntityMapping
>
execute
(
List
<
QueryProgressListener
>
listeners
)
{
QueryInterpreter
interpreter
;
validQuery
=
false
;
if
(
query
==
null
)
{
log
.
error
(
"Query is null, aborting."
);
return
createEmptyResultList
();
}
// Pick the right query interpreter for the incoming query instance
if
(
query
instanceof
ModelStructureQuery
)
{
interpreter
=
new
ModelStructureQueryInterpreter
((
ModelStructureQuery
)
query
,
listeners
);
validQuery
=
interpreter
.
interpretQuery
();
}
else
if
(
query
instanceof
PerformanceMetricsQuery
)
{
interpreter
=
new
PerformanceMetricsQueryInterpreter
((
PerformanceMetricsQuery
)
query
,
listeners
);
validQuery
=
interpreter
.
interpretQuery
();
new
GraphicsEngine
(
"Query Result Visualization"
,
interpreter
.
getResult
());
}
else
if
(
query
instanceof
PerformanceIssueQuery
)
{
log
.
error
(
"Performance Issues not yet supported, aborting."
);
return
createEmptyResultList
();
}
else
{
log
.
error
(
"No suitable QueryInterpreter found, aborting."
);
return
createEmptyResultList
();
}
// Pass back to GC
query
=
null
;
return
interpreter
.
getResults
();
}
@Override
public
List
<
EntityMapping
>
execute
(
final
DescartesQL
query
)
{
return
execute
(
query
,
new
ArrayList
<
QueryProgressListener
>());
}
@Override
public
List
<
EntityMapping
>
execute
(
final
Resource
model
)
{
return
execute
(
model
,
new
ArrayList
<
QueryProgressListener
>());
}
@Override
public
List
<
EntityMapping
>
execute
(
final
String
query
)
{
return
execute
(
query
,
new
ArrayList
<
QueryProgressListener
>());
}
@Override
public
List
<
EntityMapping
>
execute
(
final
DescartesQL
query
,
List
<
QueryProgressListener
>
listeners
)
{
setModel
(
query
);
return
execute
(
listeners
);
}
@Override
public
List
<
EntityMapping
>
execute
(
final
Resource
model
,
List
<
QueryProgressListener
>
listeners
)
{
setModel
(
model
);
return
execute
(
listeners
);
}
@Override
public
List
<
EntityMapping
>
execute
(
final
String
query
,
List
<
QueryProgressListener
>
listeners
)
{
setModel
(
query
);
return
execute
(
listeners
);
}
@Override
public
boolean
isValidQuery
()
{
return
validQuery
;
}
private
void
setModel
(
final
DescartesQL
query
)
{
this
.
query
=
query
.
getQuery
();
}
private
void
setModel
(
final
Resource
model
)
{
EList
<
EObject
>
contents
=
null
;
if
(
model
==
null
)
{
log
.
error
(
"The model instance is null, aborting."
);
return
;
}
contents
=
model
.
getContents
();
if
(
contents
.
size
()
!=
1
)
{
log
.
error
(
"Invalid model structure, more than one root element"
);
return
;
}
query
=
((
DescartesQL
)
contents
.
get
(
0
)).
getQuery
();
// relative to absolute paths
UsingClause
clause
=
null
;
if
(
query
instanceof
ListQuery
)
{
clause
=
((
ListQuery
)
query
).
getUsingClause
();
}
else
if
(
query
instanceof
SelectQuery
)
{
clause
=
((
SelectQuery
)
query
).
getUsingClause
();
}
if
(
clause
!=
null
)
{
String
location
=
clause
.
getModelReference
().
getModel
().
getLocation
();
if
(!
new
File
(
location
).
exists
())
{
location
=
(
new
File
(
model
.
getURI
().
path
())).
getParentFile
().
getAbsolutePath
()
+
File
.
separator
+
location
;
clause
.
getModelReference
().
getModel
().
setLocation
(
location
);
}
}
}
private
void
setModel
(
final
String
query
)
{
final
DescartesQL
queryModel
=
stringToModel
(
query
);
this
.
query
=
queryModel
.
getQuery
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment