|
| 1 | +/******************************************************************************* |
| 2 | + * The MIT License (MIT) |
| 3 | + * |
| 4 | + * Copyright (c) 2011 - 2015 OpenWorm. |
| 5 | + * http://openworm.org |
| 6 | + * |
| 7 | + * All rights reserved. This program and the accompanying materials |
| 8 | + * are made available under the terms of the MIT License |
| 9 | + * which accompanies this distribution, and is available at |
| 10 | + * http://opensource.org/licenses/MIT |
| 11 | + * |
| 12 | + * Contributors: |
| 13 | + * OpenWorm - http://openworm.org/people.html |
| 14 | + * |
| 15 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 16 | + * of this software and associated documentation files (the "Software"), to deal |
| 17 | + * in the Software without restriction, including without limitation the rights |
| 18 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 19 | + * copies of the Software, and to permit persons to whom the Software is |
| 20 | + * furnished to do so, subject to the following conditions: |
| 21 | + * |
| 22 | + * The above copyright notice and this permission notice shall be included in |
| 23 | + * all copies or substantial portions of the Software. |
| 24 | + * |
| 25 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 26 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 27 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 28 | + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 29 | + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 30 | + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 31 | + * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 32 | + *******************************************************************************/ |
| 33 | +package org.geppetto.datasources; |
| 34 | + |
| 35 | +import org.geppetto.core.datasources.ADataSourceService; |
| 36 | +import org.geppetto.core.datasources.ExecuteQueryVisitor; |
| 37 | +import org.geppetto.core.datasources.GeppettoDataSourceException; |
| 38 | +import org.geppetto.core.datasources.IDataSourceService; |
| 39 | +import org.geppetto.core.datasources.IQueryListener; |
| 40 | +import org.geppetto.model.Query; |
| 41 | +import org.geppetto.model.QueryResults; |
| 42 | +import org.geppetto.model.util.GeppettoModelTraversal; |
| 43 | +import org.geppetto.model.util.GeppettoVisitingException; |
| 44 | +import org.geppetto.model.variables.Variable; |
| 45 | +import org.geppetto.model.variables.VariablesFactory; |
| 46 | + |
| 47 | +/** |
| 48 | + * @author matteocantarelli |
| 49 | + * |
| 50 | + */ |
| 51 | +public class AmberOWLDataSourceService extends ADataSourceService implements IDataSourceService |
| 52 | +{ |
| 53 | + |
| 54 | + public AmberOWLDataSourceService() |
| 55 | + { |
| 56 | + super("/templates/amberOWL/queryTemplate.vm"); |
| 57 | + } |
| 58 | + |
| 59 | + /* |
| 60 | + * (non-Javadoc) |
| 61 | + * |
| 62 | + * @see org.geppetto.core.model.QueryProvider#getNumberOfResults(org.geppetto.core.model.Query, org.geppetto.model.variables.Variable) |
| 63 | + */ |
| 64 | + @Override |
| 65 | + public int getNumberOfResults(Query query, Variable variable) throws GeppettoDataSourceException |
| 66 | + { |
| 67 | + Query fetchVariableQuery = getConfiguration().getFetchVariableQuery(); |
| 68 | + ExecuteQueryVisitor runQueryVisitor = new ExecuteQueryVisitor(this.getConfiguration(), getTemplate(), variable, getGeppettoModelAccess(), true, ConnectionType.GET); |
| 69 | + try |
| 70 | + { |
| 71 | + GeppettoModelTraversal.apply(fetchVariableQuery, runQueryVisitor); |
| 72 | + |
| 73 | + } |
| 74 | + catch(GeppettoVisitingException e) |
| 75 | + { |
| 76 | + throw new GeppettoDataSourceException(e); |
| 77 | + } |
| 78 | + |
| 79 | + return runQueryVisitor.getCount(); |
| 80 | + } |
| 81 | + |
| 82 | + /* |
| 83 | + * (non-Javadoc) |
| 84 | + * |
| 85 | + * @see org.geppetto.core.model.QueryProvider#getNumberOfResults(org.geppetto.core.model.Query, org.geppetto.model.variables.Variable, org.geppetto.core.model.QueryResults) |
| 86 | + */ |
| 87 | + @Override |
| 88 | + public int getNumberOfResults(Query query, Variable variable, QueryResults results) throws GeppettoDataSourceException |
| 89 | + { |
| 90 | + // TODO Auto-generated method stub |
| 91 | + return 0; |
| 92 | + } |
| 93 | + |
| 94 | + /* |
| 95 | + * (non-Javadoc) |
| 96 | + * |
| 97 | + * @see org.geppetto.core.model.QueryProvider#execute(org.geppetto.core.model.Query, org.geppetto.model.variables.Variable, org.geppetto.core.model.QueryListener) |
| 98 | + */ |
| 99 | + @Override |
| 100 | + public QueryResults execute(Query query, Variable variable, IQueryListener listener) throws GeppettoDataSourceException |
| 101 | + { |
| 102 | + // TODO Auto-generated method stub |
| 103 | + return null; |
| 104 | + } |
| 105 | + |
| 106 | + /* |
| 107 | + * (non-Javadoc) |
| 108 | + * |
| 109 | + * @see org.geppetto.core.model.QueryProvider#execute(org.geppetto.core.model.Query, org.geppetto.model.variables.Variable, org.geppetto.core.model.QueryResults, |
| 110 | + * org.geppetto.core.model.QueryListener) |
| 111 | + */ |
| 112 | + @Override |
| 113 | + public QueryResults execute(Query query, Variable variable, QueryResults results, IQueryListener listener) throws GeppettoDataSourceException |
| 114 | + { |
| 115 | + // TODO Auto-generated method stub |
| 116 | + return null; |
| 117 | + } |
| 118 | + |
| 119 | + /* |
| 120 | + * (non-Javadoc) |
| 121 | + * |
| 122 | + * @see org.geppetto.core.model.IDataSource#fetchVariable(java.lang.String) |
| 123 | + */ |
| 124 | + @Override |
| 125 | + public void fetchVariable(String variableId) throws GeppettoDataSourceException |
| 126 | + { |
| 127 | + Variable fetchedVariable = VariablesFactory.eINSTANCE.createVariable(); |
| 128 | + fetchedVariable.setId(variableId); |
| 129 | + getGeppettoModelAccess().addVariable(fetchedVariable); |
| 130 | + Query fetchVariableQuery = getConfiguration().getFetchVariableQuery(); |
| 131 | + ExecuteQueryVisitor runQueryVisitor = new ExecuteQueryVisitor(this.getConfiguration(), getTemplate(), fetchedVariable, getGeppettoModelAccess(), ConnectionType.GET); |
| 132 | + try |
| 133 | + { |
| 134 | + GeppettoModelTraversal.apply(fetchVariableQuery, runQueryVisitor); |
| 135 | + |
| 136 | + } |
| 137 | + catch(GeppettoVisitingException e) |
| 138 | + { |
| 139 | + throw new GeppettoDataSourceException(e); |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | +} |
0 commit comments