teiid SVN: r4499 - in trunk: engine/src/main/java/org/teiid/query/metadata and 5 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-10-02 08:26:48 -0400 (Tue, 02 Oct 2012)
New Revision: 4499
Added:
trunk/engine/src/main/java/org/teiid/query/metadata/ChainingMetadataRepository.java
Modified:
trunk/api/src/main/java/org/teiid/metadata/DefaultMetadataRepository.java
trunk/api/src/main/java/org/teiid/metadata/MetadataRepository.java
trunk/engine/src/main/java/org/teiid/query/metadata/BaseMetadataRepository.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java
trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestMetadataUpdates.java
Log:
TEIID-2235 giving MetadataRepositories a well defined scope
Modified: trunk/api/src/main/java/org/teiid/metadata/DefaultMetadataRepository.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/DefaultMetadataRepository.java 2012-10-02 02:08:01 UTC (rev 4498)
+++ trunk/api/src/main/java/org/teiid/metadata/DefaultMetadataRepository.java 2012-10-02 12:26:48 UTC (rev 4499)
@@ -21,17 +21,111 @@
*/
package org.teiid.metadata;
+import java.util.Collection;
import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import org.teiid.translator.ExecutionFactory;
+import org.teiid.translator.TranslatorException;
+
/**
* This class is being provided for sole reason to inject metadata as it used to be in previous
* teiid versions. Take a look at modified interface of the MetadataRepostiory interface.
+ *
+ * If a {@link DefaultMetadataRepository} is used, it will inject metadata onto whatever has been
+ * loaded at that point in the repository chain. Generally this means that a {@link DefaultMetadataRepository}
+ * should be last.
*/
@SuppressWarnings("unused")
-public abstract class DefaultMetadataRepository implements MetadataRepository {
+@Deprecated
+public abstract class DefaultMetadataRepository<F, C> implements MetadataRepository<F, C> {
/**
+ * Calls the specific getter methods of this class to populate metadata on schema being loaded.
+ * If this method is overriden, the super method must be called to perform the metadata injection.
+ */
+ public void loadMetadata(MetadataFactory factory, ExecutionFactory<F,C> executionFactory, F connectionFactory) throws TranslatorException {
+ String vdbName = factory.getVdbName();
+ int vdbVersion = factory.getVdbVersion();
+ Collection<AbstractMetadataRecord> records = new LinkedHashSet<AbstractMetadataRecord>();
+
+ this.startLoadVdb(vdbName, vdbVersion);
+ Schema schema = factory.getSchema();
+ records.add(schema);
+ for (Table t : schema.getTables().values()) {
+ records.add(t);
+ records.addAll(t.getColumns());
+ records.addAll(t.getAllKeys());
+ if (t.isPhysical()) {
+ TableStats stats = this.getTableStats(vdbName, vdbVersion, t);
+ if (stats != null) {
+ t.setTableStats(stats);
+ }
+ for (Column c : t.getColumns()) {
+ ColumnStats cStats = this.getColumnStats(vdbName, vdbVersion, c);
+ if (cStats != null) {
+ c.setColumnStats(cStats);
+ }
+ }
+ } else {
+ String def = this.getViewDefinition(vdbName, vdbVersion, t);
+ if (def != null) {
+ t.setSelectTransformation(def);
+ }
+ if (t.supportsUpdate()) {
+ def = this.getInsteadOfTriggerDefinition(vdbName, vdbVersion, t, Table.TriggerEvent.INSERT);
+ if (def != null) {
+ t.setInsertPlan(def);
+ }
+ Boolean enabled = this.isInsteadOfTriggerEnabled(vdbName, vdbVersion, t, Table.TriggerEvent.INSERT);
+ if (enabled != null) {
+ t.setInsertPlanEnabled(enabled);
+ }
+ def = this.getInsteadOfTriggerDefinition(vdbName, vdbVersion, t, Table.TriggerEvent.UPDATE);
+ if (def != null) {
+ t.setUpdatePlan(def);
+ }
+ enabled = this.isInsteadOfTriggerEnabled(vdbName, vdbVersion, t, Table.TriggerEvent.UPDATE);
+ if (enabled != null) {
+ t.setUpdatePlanEnabled(enabled);
+ }
+ def = this.getInsteadOfTriggerDefinition(vdbName, vdbVersion, t, Table.TriggerEvent.DELETE);
+ if (def != null) {
+ t.setDeletePlan(def);
+ }
+ enabled = this.isInsteadOfTriggerEnabled(vdbName, vdbVersion, t, Table.TriggerEvent.DELETE);
+ if (enabled != null) {
+ t.setDeletePlanEnabled(enabled);
+ }
+ }
+ }
+ }
+ for (Procedure p : schema.getProcedures().values()) {
+ records.add(p);
+ records.addAll(p.getParameters());
+ if (p.getResultSet() != null) {
+ records.addAll(p.getResultSet().getColumns());
+ }
+ if (p.isVirtual() && !p.isFunction()) {
+ String proc = this.getProcedureDefinition(vdbName, vdbVersion, p);
+ if (proc != null) {
+ p.setQueryPlan(proc);
+ }
+ }
+ }
+
+ for (AbstractMetadataRecord abstractMetadataRecord : records) {
+ LinkedHashMap<String, String> p = this.getProperties(vdbName, vdbVersion, abstractMetadataRecord);
+ if (p != null) {
+ abstractMetadataRecord.setProperties(p);
+ }
+ }
+ this.endLoadVdb(vdbName, vdbVersion);
+ }
+
+ /**
* Marks the start of vdb metadata loading
+ * Note: this is called for every schema
* @param vdbName
* @param vdbVersion
*/
@@ -40,6 +134,7 @@
/**
* Marks the end of vdb metadata loading
+ * Note: this is called for every schema
* @param vdbName
* @param vdbVersion
*/
Modified: trunk/api/src/main/java/org/teiid/metadata/MetadataRepository.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/MetadataRepository.java 2012-10-02 02:08:01 UTC (rev 4498)
+++ trunk/api/src/main/java/org/teiid/metadata/MetadataRepository.java 2012-10-02 12:26:48 UTC (rev 4499)
@@ -109,10 +109,4 @@
*/
void setProperty(String vdbName, int vdbVersion, AbstractMetadataRecord record, String name, String value);
- /**
- * Next repository in the repository chain. The implementation contract of this method dictates if this method is set then
- * Implementation class must delegete the call to 'next' instance after it is done with the processing of the call.
- * @param next
- */
- void setNext(MetadataRepository<?, ?> next);
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/BaseMetadataRepository.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/BaseMetadataRepository.java 2012-10-02 02:08:01 UTC (rev 4498)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/BaseMetadataRepository.java 2012-10-02 12:26:48 UTC (rev 4499)
@@ -34,71 +34,43 @@
import org.teiid.translator.TranslatorException;
public class BaseMetadataRepository<F, C> implements MetadataRepository<F, C> {
- protected MetadataRepository nextRepository;
@Override
public void loadMetadata(MetadataFactory factory, ExecutionFactory<F, C> executionFactory, F connectionFactory) throws TranslatorException {
- if (this.nextRepository != null) {
- this.nextRepository.loadMetadata(factory, executionFactory, connectionFactory);
- }
}
@Override
public void setViewDefinition(String vdbName, int vdbVersion, Table table,String viewDefinition) {
- if (this.nextRepository != null) {
- this.nextRepository.setViewDefinition(vdbName, vdbVersion, table, viewDefinition);
- }
}
@Override
public void setInsteadOfTriggerDefinition(String vdbName, int vdbVersion,
Table table, TriggerEvent triggerOperation, String triggerDefinition) {
- if (this.nextRepository != null) {
- this.nextRepository.setInsteadOfTriggerDefinition(vdbName, vdbVersion, table, triggerOperation, triggerDefinition);
- }
}
@Override
public void setInsteadOfTriggerEnabled(String vdbName, int vdbVersion,
Table table, TriggerEvent triggerOperation, boolean enabled) {
- if (this.nextRepository != null) {
- this.nextRepository.setInsteadOfTriggerEnabled(vdbName, vdbVersion, table, triggerOperation, enabled);
- }
}
@Override
public void setProcedureDefinition(String vdbName, int vdbVersion,
Procedure procedure, String procedureDefinition) {
- if (this.nextRepository != null) {
- this.nextRepository.setProcedureDefinition(vdbName, vdbVersion, procedure, procedureDefinition);
- }
}
@Override
public void setTableStats(String vdbName, int vdbVersion, Table table,
TableStats tableStats) {
- if (this.nextRepository != null) {
- this.nextRepository.setTableStats(vdbName, vdbVersion, table, tableStats);
- }
}
@Override
public void setColumnStats(String vdbName, int vdbVersion, Column column,
ColumnStats columnStats) {
- if (this.nextRepository != null) {
- this.nextRepository.setColumnStats(vdbName, vdbVersion, column, columnStats);
- }
}
@Override
public void setProperty(String vdbName, int vdbVersion,
AbstractMetadataRecord record, String name, String value) {
- if (this.nextRepository != null) {
- this.nextRepository.setProperty(vdbName, vdbVersion, record, name, value);
- }
}
- public void setNext(MetadataRepository next) {
- this.nextRepository = next;
- }
}
Added: trunk/engine/src/main/java/org/teiid/query/metadata/ChainingMetadataRepository.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/ChainingMetadataRepository.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/ChainingMetadataRepository.java 2012-10-02 12:26:48 UTC (rev 4499)
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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 GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.query.metadata;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.teiid.metadata.AbstractMetadataRecord;
+import org.teiid.metadata.Column;
+import org.teiid.metadata.ColumnStats;
+import org.teiid.metadata.MetadataFactory;
+import org.teiid.metadata.MetadataRepository;
+import org.teiid.metadata.Procedure;
+import org.teiid.metadata.Table;
+import org.teiid.metadata.TableStats;
+import org.teiid.metadata.Table.TriggerEvent;
+import org.teiid.translator.ExecutionFactory;
+import org.teiid.translator.TranslatorException;
+
+public class ChainingMetadataRepository implements MetadataRepository<Object, Object> {
+
+ final ArrayList<MetadataRepository<Object, Object>> repositories;
+
+ @SuppressWarnings("unchecked")
+ public ChainingMetadataRepository(List<? extends MetadataRepository> repos) {
+ this.repositories = new ArrayList<MetadataRepository<Object,Object>>((Collection<? extends MetadataRepository<Object, Object>>)repos);
+ }
+
+ @Override
+ public void loadMetadata(MetadataFactory factory,
+ ExecutionFactory<Object, Object> executionFactory,
+ Object connectionFactory) throws TranslatorException {
+ for (MetadataRepository<Object, Object> repo : repositories) {
+ repo.loadMetadata(factory, executionFactory, connectionFactory);
+ }
+ }
+
+ @Override
+ public void setColumnStats(String vdbName, int vdbVersion, Column column,
+ ColumnStats columnStats) {
+ for (MetadataRepository<Object, Object> repo : repositories) {
+ repo.setColumnStats(vdbName, vdbVersion, column, columnStats);
+ }
+ }
+
+ @Override
+ public void setInsteadOfTriggerDefinition(String vdbName, int vdbVersion,
+ Table table, TriggerEvent triggerOperation, String triggerDefinition) {
+ for (MetadataRepository<Object, Object> repo : repositories) {
+ repo.setInsteadOfTriggerDefinition(vdbName, vdbVersion, table, triggerOperation, triggerDefinition);
+ }
+ }
+
+ @Override
+ public void setInsteadOfTriggerEnabled(String vdbName, int vdbVersion,
+ Table table, TriggerEvent triggerOperation, boolean enabled) {
+ for (MetadataRepository<Object, Object> repo : repositories) {
+ repo.setInsteadOfTriggerEnabled(vdbName, vdbVersion, table, triggerOperation, enabled);
+ }
+ }
+
+ @Override
+ public void setProcedureDefinition(String vdbName, int vdbVersion,
+ Procedure procedure, String procedureDefinition) {
+ for (MetadataRepository<Object, Object> repo : repositories) {
+ repo.setProcedureDefinition(vdbName, vdbVersion, procedure, procedureDefinition);
+ }
+ }
+
+ @Override
+ public void setProperty(String vdbName, int vdbVersion,
+ AbstractMetadataRecord record, String name, String value) {
+ for (MetadataRepository<Object, Object> repo : repositories) {
+ repo.setProperty(vdbName, vdbVersion, record, name, value);
+ }
+ }
+
+ @Override
+ public void setTableStats(String vdbName, int vdbVersion, Table table,
+ TableStats tableStats) {
+ for (MetadataRepository<Object, Object> repo : repositories) {
+ repo.setTableStats(vdbName, vdbVersion, table, tableStats);
+ }
+ }
+
+ @Override
+ public void setViewDefinition(String vdbName, int vdbVersion, Table table,
+ String viewDefinition) {
+ for (MetadataRepository<Object, Object> repo : repositories) {
+ repo.setViewDefinition(vdbName, vdbVersion, table, viewDefinition);
+ }
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/query/metadata/ChainingMetadataRepository.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-10-02 02:08:01 UTC (rev 4498)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-10-02 12:26:48 UTC (rev 4499)
@@ -476,25 +476,31 @@
if (repo != null) {
return repo;
}
- final Module module;
- ClassLoader moduleLoader = this.getClass().getClassLoader();
- ModuleLoader ml = Module.getCallerModuleLoader();
- if (repoType != null && ml != null) {
- try {
- module = ml.loadModule(ModuleIdentifier.create(repoType));
- moduleLoader = module.getClassLoader();
- } catch (ModuleLoadException e) {
- throw new VirtualDatabaseException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50057, repoType));
+ synchronized (this) {
+ final Module module;
+ ClassLoader moduleLoader = this.vdb.getAttachment(ClassLoader.class);
+ if (moduleLoader == null) {
+ moduleLoader = this.getClass().getClassLoader();
}
- }
-
- final ServiceLoader<MetadataRepository> serviceLoader = ServiceLoader.load(MetadataRepository.class, moduleLoader);
- if (serviceLoader != null) {
- for (MetadataRepository loader:serviceLoader) {
- return loader;
- }
- }
- return null;
+ ModuleLoader ml = Module.getCallerModuleLoader();
+ if (repoType != null && ml != null) {
+ try {
+ module = ml.loadModule(ModuleIdentifier.create(repoType));
+ moduleLoader = module.getClassLoader();
+ } catch (ModuleLoadException e) {
+ throw new VirtualDatabaseException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50057, repoType));
+ }
+ }
+
+ final ServiceLoader<MetadataRepository> serviceLoader = ServiceLoader.load(MetadataRepository.class, moduleLoader);
+ if (serviceLoader != null) {
+ for (MetadataRepository loader:serviceLoader) {
+ this.addMetadataRepository(repoType, loader);
+ return loader;
+ }
+ }
+ return null;
+ }
}
}
Modified: trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2012-10-02 02:08:01 UTC (rev 4498)
+++ trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2012-10-02 12:26:48 UTC (rev 4499)
@@ -24,7 +24,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
@@ -38,7 +37,9 @@
import org.teiid.core.CoreConstants;
import org.teiid.dqp.internal.datamgr.ConnectorManager;
import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
-import org.teiid.metadata.*;
+import org.teiid.metadata.FunctionMethod;
+import org.teiid.metadata.MetadataStore;
+import org.teiid.metadata.Schema;
import org.teiid.query.function.FunctionTree;
import org.teiid.query.function.UDFSource;
import org.teiid.query.metadata.CompositeMetadataStore;
@@ -233,85 +234,6 @@
return mergedStore;
}
- private static void updateFromMetadataRepository(VDBMetaData vdb, Schema schema, DefaultMetadataRepository metadataRepository) {
- String vdbName = vdb.getName();
- int vdbVersion = vdb.getVersion();
- Collection<AbstractMetadataRecord> records = new LinkedHashSet<AbstractMetadataRecord>();
-
- metadataRepository.startLoadVdb(vdbName, vdbVersion);
-
- records.add(schema);
- for (Table t : schema.getTables().values()) {
- records.add(t);
- records.addAll(t.getColumns());
- records.addAll(t.getAllKeys());
- if (t.isPhysical()) {
- TableStats stats = metadataRepository.getTableStats(vdbName, vdbVersion, t);
- if (stats != null) {
- t.setTableStats(stats);
- }
- for (Column c : t.getColumns()) {
- ColumnStats cStats = metadataRepository.getColumnStats(vdbName, vdbVersion, c);
- if (cStats != null) {
- c.setColumnStats(cStats);
- }
- }
- } else {
- String def = metadataRepository.getViewDefinition(vdbName, vdbVersion, t);
- if (def != null) {
- t.setSelectTransformation(def);
- }
- if (t.supportsUpdate()) {
- def = metadataRepository.getInsteadOfTriggerDefinition(vdbName, vdbVersion, t, Table.TriggerEvent.INSERT);
- if (def != null) {
- t.setInsertPlan(def);
- }
- Boolean enabled = metadataRepository.isInsteadOfTriggerEnabled(vdbName, vdbVersion, t, Table.TriggerEvent.INSERT);
- if (enabled != null) {
- t.setInsertPlanEnabled(enabled);
- }
- def = metadataRepository.getInsteadOfTriggerDefinition(vdbName, vdbVersion, t, Table.TriggerEvent.UPDATE);
- if (def != null) {
- t.setUpdatePlan(def);
- }
- enabled = metadataRepository.isInsteadOfTriggerEnabled(vdbName, vdbVersion, t, Table.TriggerEvent.UPDATE);
- if (enabled != null) {
- t.setUpdatePlanEnabled(enabled);
- }
- def = metadataRepository.getInsteadOfTriggerDefinition(vdbName, vdbVersion, t, Table.TriggerEvent.DELETE);
- if (def != null) {
- t.setDeletePlan(def);
- }
- enabled = metadataRepository.isInsteadOfTriggerEnabled(vdbName, vdbVersion, t, Table.TriggerEvent.DELETE);
- if (enabled != null) {
- t.setDeletePlanEnabled(enabled);
- }
- }
- }
- }
- for (Procedure p : schema.getProcedures().values()) {
- records.add(p);
- records.addAll(p.getParameters());
- if (p.getResultSet() != null) {
- records.addAll(p.getResultSet().getColumns());
- }
- if (p.isVirtual() && !p.isFunction()) {
- String proc = metadataRepository.getProcedureDefinition(vdbName, vdbVersion, p);
- if (proc != null) {
- p.setQueryPlan(proc);
- }
- }
- }
-
- for (AbstractMetadataRecord abstractMetadataRecord : records) {
- LinkedHashMap<String, String> p = metadataRepository.getProperties(vdbName, vdbVersion, abstractMetadataRecord);
- if (p != null) {
- abstractMetadataRecord.setProperties(p);
- }
- }
- metadataRepository.endLoadVdb(vdbName, vdbVersion);
- }
-
VDBMetaData getOriginalVDB() {
return originalVDB;
}
@@ -324,13 +246,6 @@
MetadataStore mergedStore = getMetadataStore();
- for (ModelMetaData model:vdb.getModelMetaDatas().values()) {
- MetadataRepository repo = model.getAttachment(MetadataRepository.class);
- if (repo instanceof DefaultMetadataRepository) {
- updateFromMetadataRepository(mergedVDB, mergedStore.getSchema(model.getName()), (DefaultMetadataRepository)repo);
- }
- }
-
TransformationMetadata metadata = buildTransformationMetaData(mergedVDB, getVisibilityMap(), mergedStore, getUDF(), systemFunctions, this.additionalStores);
mergedVDB.addAttchment(QueryMetadataInterface.class, metadata);
mergedVDB.addAttchment(TransformationMetadata.class, metadata);
Modified: trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java 2012-10-02 02:08:01 UTC (rev 4498)
+++ trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java 2012-10-02 12:26:48 UTC (rev 4499)
@@ -22,6 +22,8 @@
package org.teiid.runtime;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
@@ -44,6 +46,7 @@
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.MetadataRepository;
import org.teiid.metadata.MetadataStore;
+import org.teiid.query.metadata.ChainingMetadataRepository;
import org.teiid.query.metadata.DDLMetadataRepository;
import org.teiid.query.metadata.DirectQueryMetadataRepository;
import org.teiid.query.metadata.NativeMetadataRepository;
@@ -79,47 +82,31 @@
private MetadataRepository<?, ?> getMetadataRepository(VDBMetaData vdb, ModelMetaData model, MetadataRepository<?, ?> defaultRepo) throws VirtualDatabaseException {
if (model.getSchemaSourceType() == null) {
if (!vdb.isDynamic()) {
- defaultRepo.setNext(new DirectQueryMetadataRepository());
return defaultRepo;
}
-
if (model.isSource()) {
- NativeMetadataRepository repo = new NativeMetadataRepository();
- repo.setNext(new DirectQueryMetadataRepository());
- return repo;
+ return new ChainingMetadataRepository(Arrays.asList(new NativeMetadataRepository(), new DirectQueryMetadataRepository()));
}
throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40094, model.getName(), vdb.getName(), vdb.getVersion(), null));
}
-
- MetadataRepository<?, ?> first = null;
- MetadataRepository<?, ?> current = null;
- MetadataRepository<?, ?> previous = null;
String schemaTypes = model.getSchemaSourceType();
StringTokenizer st = new StringTokenizer(schemaTypes, ","); //$NON-NLS-1$
+ List<MetadataRepository<?, ?>> repos = new ArrayList<MetadataRepository<?,?>>(st.countTokens());
while (st.hasMoreTokens()) {
String repoType = st.nextToken().trim();
- current = getMetadataRepository(repoType);
+ MetadataRepository<?, ?> current = getMetadataRepository(repoType);
if (current == null) {
throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40094, model.getName(), vdb.getName(), vdb.getVersion(), repoType));
}
-
- if (first == null) {
- first = current;
- }
-
- if (previous != null) {
- previous.setNext(current);
- }
- previous = current;
- current = null;
+ repos.add(current);
}
-
- // TODO:there is good chance that the instances of metadata factory sharing is not good between models,
- // may that be for chaining purposes, we should do metadata repository factory model here.
if (model.getModelType() == ModelMetaData.Type.PHYSICAL) {
- previous.setNext(new DirectQueryMetadataRepository());
+ repos.add(new DirectQueryMetadataRepository());
}
- return first;
+ if (repos.size() == 1) {
+ return repos.get(0);
+ }
+ return new ChainingMetadataRepository(repos);
}
protected ConnectorManager getConnectorManager(final ModelMetaData model, final ConnectorManagerRepository cmr) {
Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java 2012-10-02 02:08:01 UTC (rev 4498)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java 2012-10-02 12:26:48 UTC (rev 4499)
@@ -35,6 +35,7 @@
import org.teiid.adminapi.impl.VDBImportMetadata;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.common.queue.FakeWorkManager;
+import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.util.SimpleMock;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.deployers.UDFMetaData;
@@ -45,6 +46,7 @@
import org.teiid.dqp.service.BufferService;
import org.teiid.dqp.service.FakeBufferService;
import org.teiid.metadata.FunctionMethod;
+import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.MetadataRepository;
import org.teiid.metadata.MetadataStore;
import org.teiid.metadata.Schema;
@@ -54,6 +56,7 @@
import org.teiid.query.optimizer.capabilities.SourceCapabilities;
import org.teiid.runtime.EmbeddedConfiguration;
import org.teiid.runtime.EmbeddedServer;
+import org.teiid.translator.TranslatorException;
import org.teiid.transport.ClientServiceRegistryImpl;
@SuppressWarnings({"nls"})
@@ -158,6 +161,14 @@
ModelMetaData model = addModel(vdbMetaData, schema);
if (parameterObject.metadataRepo != null) {
model.addAttchment(MetadataRepository.class, parameterObject.metadataRepo);
+ //fakeserver does not load through the repository framework, so call load after the fact here.
+ MetadataFactory mf = createMetadataFactory(vdbMetaData, model);
+ mf.setSchema(schema);
+ try {
+ parameterObject.metadataRepo.loadMetadata(mf, null, null);
+ } catch (TranslatorException e) {
+ throw new TeiidRuntimeException(e);
+ }
}
}
Modified: trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestMetadataUpdates.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestMetadataUpdates.java 2012-10-02 02:08:01 UTC (rev 4498)
+++ trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestMetadataUpdates.java 2012-10-02 12:26:48 UTC (rev 4499)
@@ -34,15 +34,17 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.jdbc.FakeServer;
import org.teiid.jdbc.FakeServer.DeployVDBParameter;
+import org.teiid.metadata.AbstractMetadataRecord;
+import org.teiid.metadata.Column;
+import org.teiid.metadata.ColumnStats;
import org.teiid.metadata.DefaultMetadataRepository;
import org.teiid.metadata.Procedure;
import org.teiid.metadata.Table;
+import org.teiid.metadata.TableStats;
+import org.teiid.metadata.Table.TriggerEvent;
@SuppressWarnings("nls")
public class TestMetadataUpdates {
@@ -72,39 +74,82 @@
}
private static DefaultMetadataRepository getMetadataRepo() {
- DefaultMetadataRepository repo = Mockito.mock(DefaultMetadataRepository.class);
- Mockito.stub(repo.getViewDefinition(Mockito.anyString(), Mockito.anyInt(), (Table)Mockito.anyObject())).toAnswer(new Answer<String>() {
- @Override
- public String answer(InvocationOnMock invocation) throws Throwable {
- Table t = (Table)invocation.getArguments()[2];
- if (t.getName().equals("vw")) {
+ DefaultMetadataRepository repo = new DefaultMetadataRepository() {
+
+ @Override
+ public void setColumnStats(String vdbName, int vdbVersion,
+ Column column, ColumnStats columnStats) {
+
+ }
+
+ @Override
+ public void setInsteadOfTriggerDefinition(String vdbName,
+ int vdbVersion, Table table, TriggerEvent triggerOperation,
+ String triggerDefinition) {
+
+ }
+
+ @Override
+ public void setInsteadOfTriggerEnabled(String vdbName,
+ int vdbVersion, Table table, TriggerEvent triggerOperation,
+ boolean enabled) {
+
+ }
+
+ @Override
+ public void setProcedureDefinition(String vdbName, int vdbVersion,
+ Procedure procedure, String procedureDefinition) {
+
+ }
+
+ @Override
+ public void setProperty(String vdbName, int vdbVersion,
+ AbstractMetadataRecord record, String name, String value) {
+
+ }
+
+ @Override
+ public void setTableStats(String vdbName, int vdbVersion,
+ Table table, TableStats tableStats) {
+
+ }
+
+ @Override
+ public void setViewDefinition(String vdbName, int vdbVersion,
+ Table table, String viewDefinition) {
+
+ }
+
+ @Override
+ public String getViewDefinition(String vdbName, int vdbVersion,
+ Table table) {
+ if (table.getName().equals("vw")) {
return "select '2011'";
}
return null;
- }
- });
- Mockito.stub(repo.getProcedureDefinition(Mockito.anyString(), Mockito.anyInt(), (Procedure)Mockito.anyObject())).toAnswer(new Answer<String>() {
- @Override
- public String answer(InvocationOnMock invocation) throws Throwable {
- Procedure t = (Procedure)invocation.getArguments()[2];
- if (t.getName().equals("proc")) {
+ }
+
+ @Override
+ public String getProcedureDefinition(String vdbName,
+ int vdbVersion, Procedure procedure) {
+ if (procedure.getName().equals("proc")) {
return "create virtual procedure begin select '2011'; if ((call isLoggable())) call logMsg(msg=>'hello'); end";
}
return null;
- }
- });
- Mockito.stub(repo.getInsteadOfTriggerDefinition(Mockito.anyString(), Mockito.anyInt(), (Table)Mockito.anyObject(), (Table.TriggerEvent) Mockito.anyObject())).toAnswer(new Answer<String>() {
- @Override
- public String answer(InvocationOnMock invocation) throws Throwable {
+ }
+
+ @Override
+ public String getInsteadOfTriggerDefinition(String vdbName,
+ int vdbVersion, Table table, TriggerEvent triggerOperation) {
return "for each row select 1/0;";
- }
- });
- Mockito.stub(repo.isInsteadOfTriggerEnabled(Mockito.anyString(), Mockito.anyInt(), (Table)Mockito.anyObject(), (Table.TriggerEvent) Mockito.anyObject())).toAnswer(new Answer<Boolean>() {
- @Override
- public Boolean answer(InvocationOnMock invocation) throws Throwable {
+ }
+
+ @Override
+ public Boolean isInsteadOfTriggerEnabled(String vdbName,
+ int vdbVersion, Table table, TriggerEvent triggerOperation) {
return Boolean.TRUE;
- }
- });
+ }
+ };
return repo;
}
12 years, 2 months
teiid SVN: r4498 - in trunk: connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc and 2 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-10-01 22:08:01 -0400 (Mon, 01 Oct 2012)
New Revision: 4498
Modified:
trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCDirectQueryExecution.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCPlugin.java
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCDirectQueryExecution.java
trunk/engine/src/main/java/org/teiid/query/metadata/DirectQueryMetadataRepository.java
Log:
TEIID-2176 refinements to jdbc native query support
Modified: trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2012-10-02 00:34:06 UTC (rev 4497)
+++ trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2012-10-02 02:08:01 UTC (rev 4498)
@@ -272,6 +272,11 @@
public Execution createExecution(Command command, ExecutionContext executionContext, RuntimeMetadata metadata, C connection) throws TranslatorException {
if (command instanceof Call) {
Call obj = (Call)command;
+ //TODO: our extension property support in designer makes ad-hoc properties impossible, so
+ //we just match based upon name. it would be better to have the metadatarepository/tooling add a teiid property
+ //to explicitly set this proc as direct.
+ //the other approach would be to addd a native system stored procedure, but that would require
+ //special security semantics, whereas this proc can be secured on a schema basis
if (supportsNativeQueries() && obj.getMetadataObject().getName().equals(getNativeQueryProcedureName())) {
List<Argument> arguments = obj.getArguments();
return createDirectExecution(arguments, command, executionContext, metadata, connection);
@@ -1054,7 +1059,7 @@
* True, if this translator supports execution of source specific commands unaltered through 'native' procedure.
* @return
*/
- @TranslatorProperty(display="Supports Native Queries", description="True, if this translator supports execution of source specific commands unaltered through 'native' procedure", advanced=true)
+ @TranslatorProperty(display="Supports Native Queries", description="True, if this translator supports execution of source specific commands unaltered through a 'native' procedure", advanced=true)
public boolean supportsNativeQueries() {
return this.supportsNativeQueries;
}
@@ -1068,7 +1073,7 @@
* of the procedure is defined automatically.
* @return
*/
- @TranslatorProperty(display="Name of the native query", description="The name of the procedure that is considered as the name of the direct query procedure", advanced=true)
+ @TranslatorProperty(display="Name of the native query", description="The name of the direct query procedure", advanced=true)
public String getNativeQueryProcedureName() {
return this.nativeProcedureName;
}
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCDirectQueryExecution.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCDirectQueryExecution.java 2012-10-02 00:34:06 UTC (rev 4497)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCDirectQueryExecution.java 2012-10-02 02:08:01 UTC (rev 4498)
@@ -25,7 +25,6 @@
package org.teiid.translator.jdbc;
-import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@@ -61,64 +60,41 @@
List<Argument> parameters = this.arguments.subList(1, this.arguments.size());
LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Source sql", sourceSQL); //$NON-NLS-1$
- boolean prepared = (sourceSQL.indexOf('?') != -1);
- boolean callable = (sourceSQL.indexOf("call ") != -1); //$NON-NLS-1$
- int paramCount = getParamCount(sourceSQL);
+ int paramCount = parameters.size();
try {
- if (callable) {
- CallableStatement cstmt = getCallableStatement(sourceSQL);
- this.results = this.executionFactory.executeStoredProcedure(cstmt, parameters, TypeFacility.RUNTIME_TYPES.OBJECT);
- this.columnCount = this.results.getMetaData().getColumnCount();
- }
+ Statement stmt;
+ boolean hasResults = false;
+
+ if(paramCount > 0) {
+ PreparedStatement pstatement = getPreparedStatement(sourceSQL);
+ for (int i = 0; i < paramCount; i++) {
+ Argument arg = parameters.get(i);
+ //TODO: if ParameterMetadata is supported we could use that type
+ this.executionFactory.bindValue(pstatement, arg.getArgumentValue(), arg.getArgumentValue().getType(), i);
+ }
+ stmt = pstatement;
+ hasResults = pstatement.execute();
+ }
else {
- Statement stmt;
- boolean hasResults = false;
-
- if(prepared) {
- PreparedStatement pstatement = getPreparedStatement(sourceSQL);
- for (int i = 0; i < paramCount; i++) {
- if (this.arguments.size()-1 < paramCount) {
- throw new TranslatorException(JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11019, sourceSQL));
- }
- Argument arg = this.arguments.get(i+1);
- pstatement.setObject(i+1, arg.getArgumentValue().getValue());
- }
- stmt = pstatement;
- hasResults = pstatement.execute();
- }
- else {
- stmt = getStatement();
- hasResults = stmt.execute(sourceSQL);
- }
-
- if (hasResults) {
- this.results = stmt.getResultSet();
- this.columnCount = this.results.getMetaData().getColumnCount();
- }
- else {
- this.updateCount = stmt.getUpdateCount();
- }
+ //TODO: when array support becomes more robust calling like "exec native('sql', ARRAY[]) could still be prepared
+ stmt = getStatement();
+ hasResults = stmt.execute(sourceSQL);
}
+
+ if (hasResults) {
+ this.results = stmt.getResultSet();
+ this.columnCount = this.results.getMetaData().getColumnCount();
+ }
+ else {
+ this.updateCount = stmt.getUpdateCount();
+ }
addStatementWarnings();
} catch (SQLException e) {
throw new JDBCExecutionException(JDBCPlugin.Event.TEIID11008, e, sourceSQL);
}
}
- private int getParamCount(String sourceSQL) {
- int paramCount = 0;
- int idx = -1;
- while (true) {
- idx = sourceSQL.indexOf('?', idx+1);
- if (idx == -1) {
- break;
- }
- paramCount++;
- }
- return paramCount;
- }
-
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
try {
@@ -153,6 +129,6 @@
@Override
public List<?> getOutputParameterValues() throws TranslatorException {
- return null;
+ return null; //could support as an array of output values via given that the native procedure returns an array value
}
}
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCPlugin.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCPlugin.java 2012-10-02 00:34:06 UTC (rev 4497)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCPlugin.java 2012-10-02 02:08:01 UTC (rev 4498)
@@ -54,6 +54,5 @@
TEIID11016,
TEIID11017,
TEIID11018,
- TEIID11019
}
}
Modified: trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCDirectQueryExecution.java
===================================================================
--- trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCDirectQueryExecution.java 2012-10-02 00:34:06 UTC (rev 4497)
+++ trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCDirectQueryExecution.java 2012-10-02 02:08:01 UTC (rev 4498)
@@ -24,7 +24,6 @@
import static org.junit.Assert.*;
-import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
@@ -32,7 +31,6 @@
import java.sql.ResultSetMetaData;
import java.sql.Statement;
-
import org.junit.Test;
import org.mockito.Mockito;
import org.teiid.language.Command;
@@ -43,29 +41,6 @@
@SuppressWarnings("nls")
public class TestJDBCDirectQueryExecution {
- @Test public void testProcedureExecution() throws Exception {
- Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "exec native('{?=call spTest8a()}')"); //$NON-NLS-1$
- Connection connection = Mockito.mock(Connection.class);
- CallableStatement cs = Mockito.mock(CallableStatement.class);
- ResultSet rs = Mockito.mock(ResultSet.class);
- ResultSetMetaData rsm = Mockito.mock(ResultSetMetaData.class);
-
- Mockito.stub(cs.getUpdateCount()).toReturn(-1);
- Mockito.stub(cs.getResultSet()).toReturn(rs);
- Mockito.stub(rs.getMetaData()).toReturn(rsm);
- Mockito.stub(rsm.getColumnCount()).toReturn(1);
- Mockito.stub(connection.prepareCall("{?=call spTest8a()}")).toReturn(cs); //$NON-NLS-1$
- Mockito.stub(rs.next()).toReturn(true);
- Mockito.stub(rs.getObject(1)).toReturn(5);
- Mockito.stub(connection.getMetaData()).toReturn(Mockito.mock(DatabaseMetaData.class));
-
- JDBCExecutionFactory ef = new JDBCExecutionFactory();
- ef.setSupportsNativeQueries(true);
- ResultSetExecution execution = (ResultSetExecution)ef.createExecution(command, Mockito.mock(ExecutionContext.class), Mockito.mock(RuntimeMetadata.class), connection);
- execution.execute();
- assertArrayEquals(new Object[] {5}, (Object[])execution.next().get(0));
- }
-
@Test public void testSelectExecution() throws Exception {
Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "call native('select * from Source')"); //$NON-NLS-1$
Connection connection = Mockito.mock(Connection.class);
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/DirectQueryMetadataRepository.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/DirectQueryMetadataRepository.java 2012-10-02 00:34:06 UTC (rev 4497)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/DirectQueryMetadataRepository.java 2012-10-02 02:08:01 UTC (rev 4498)
@@ -40,14 +40,14 @@
if (executionFactory != null && executionFactory.supportsNativeQueries()) {
Procedure p = factory.addProcedure(executionFactory.getNativeQueryProcedureName());
- p.setAnnotation("Invokes translator with provided native query that returns result in array of values"); //$NON-NLS-1$
+ p.setAnnotation("Invokes translator with a native query that returns results in array of values"); //$NON-NLS-1$
ProcedureParameter param = factory.addProcedureParameter("request", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p); //$NON-NLS-1$
param.setAnnotation("The native query to execute"); //$NON-NLS-1$
param.setNullType(NullType.No_Nulls);
param = factory.addProcedureParameter("variable", TypeFacility.RUNTIME_NAMES.OBJECT, Type.In, p); //$NON-NLS-1$
- param.setAnnotation("Any number of varaibles, depends upon how a translator uses them individually"); //$NON-NLS-1$
+ param.setAnnotation("Any number of varaibles; usage will vary by translator"); //$NON-NLS-1$
param.setNullType(NullType.Nullable);
param.setVarArg(true);
12 years, 2 months
teiid SVN: r4497 - trunk/engine/src/main/resources/org/teiid/query.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-10-01 20:34:06 -0400 (Mon, 01 Oct 2012)
New Revision: 4497
Modified:
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
Log:
TEIID-2234 fixing function issues
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-10-01 19:23:30 UTC (rev 4496)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-10-02 00:34:06 UTC (rev 4497)
@@ -1031,7 +1031,7 @@
TEIID31120=An exception may only be chained to another exception. {0} is not valid.
TEIID31121=The expected result set of the procedure {0} does not match the result set from returnable statement {1} use WITHOUT RETURN to indicate the statement should not be returned - {2}
TEIID31122=Null exception reference.
-TEIID31123=Could not load non-FOREIGN UDF "{0}", since both invocation class and invocation method are required.
+TEIID31123=Could not load non-FOREIGN UDF "{0}", since both invocation class and invocation method are required.
SQLParser.proc_type_conflict=Result type {1} conflicts with return type {2} for procedure {0}
SQLParser.param_out=Procedure {0} RESULT param {1} must be of type OUT.
12 years, 2 months
teiid SVN: r4496 - in trunk/connectors/translator-ldap/src: test/java/org/teiid/translator/ldap and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2012-10-01 15:23:30 -0400 (Mon, 01 Oct 2012)
New Revision: 4496
Modified:
trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/IQueryToLdapSearchParser.java
trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPDirectSearchQueryExecution.java
trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPSearchDetails.java
trunk/connectors/translator-ldap/src/test/java/org/teiid/translator/ldap/TestIQueryToLdapSearchParser.java
Log:
TEIID-2177: Expanding the native query support through extension metadata is expanded to LDAP tables.
Modified: trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/IQueryToLdapSearchParser.java
===================================================================
--- trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/IQueryToLdapSearchParser.java 2012-10-01 17:55:58 UTC (rev 4495)
+++ trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/IQueryToLdapSearchParser.java 2012-10-01 19:23:30 UTC (rev 4496)
@@ -40,6 +40,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.StringTokenizer;
import javax.naming.directory.SearchControls;
import javax.naming.ldap.SortKey;
@@ -49,9 +50,12 @@
import org.teiid.language.SortSpecification.Ordering;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
+import org.teiid.metadata.AbstractMetadataRecord;
import org.teiid.metadata.Column;
+import org.teiid.metadata.Datatype;
import org.teiid.metadata.Table;
import org.teiid.translator.TranslatorException;
+import org.teiid.translator.TypeFacility;
import org.teiid.translator.ldap.LDAPExecutionFactory.SearchDefaultScope;
@@ -60,6 +64,13 @@
* Utility class which translates a SQL query into an LDAP search.
*/
public class IQueryToLdapSearchParser {
+ private static final String ATTRIBUTES = "attributes"; //$NON-NLS-1$
+ private static final String COUNT_LIMIT = "count-limit"; //$NON-NLS-1$
+ private static final String TIMEOUT = "timeout";//$NON-NLS-1$
+ private static final String SEARCH_SCOPE = "search-scope";//$NON-NLS-1$
+ private static final String CRITERIA = "filter";//$NON-NLS-1$
+ private static final String CONTEXT_NAME = "context-name";//$NON-NLS-1$
+ public static final String TEIID_NATIVE_QUERY = AbstractMetadataRecord.RELATIONAL_URI + "native-query"; //$NON-NLS-1$
LDAPExecutionFactory executionFactory;
/**
@@ -89,23 +100,31 @@
// TODO - change method for calling RESTRICT to also specify
// object class name (RESTRICT=inetOrgPerson)
public LDAPSearchDetails translateSQLQueryToLDAPSearch(Select query) throws TranslatorException {
- // Parse SELECT symbols.
- // The columns will be translated into LDAP attributes of interest.
- ArrayList<Column> elementList = getElementsFromSelectSymbols(query);
-
- // Parse FROM table.
- // Only one table is expected here.
- List<TableReference> fromList = query.getFrom();
- Iterator<TableReference> itr = fromList.iterator();
- if(!itr.hasNext()) {
- final String msg = LDAPPlugin.Util.getString("IQueryToLdapSearchParser.noTablesInFromError"); //$NON-NLS-1$
- throw new TranslatorException(msg);
- }
- TableReference fItm = itr.next();
- if(itr.hasNext()) {
- final String msg = LDAPPlugin.Util.getString("IQueryToLdapSearchParser.multiItemsInFromError"); //$NON-NLS-1$
- throw new TranslatorException(msg);
- }
+ // Parse SELECT symbols.
+ // The columns will be translated into LDAP attributes of interest.
+ ArrayList<Column> elementList = getElementsFromSelectSymbols(query);
+
+ // Parse FROM table.
+ // Only one table is expected here.
+ List<TableReference> fromList = query.getFrom();
+ Iterator<TableReference> itr = fromList.iterator();
+ if(!itr.hasNext()) {
+ final String msg = LDAPPlugin.Util.getString("IQueryToLdapSearchParser.noTablesInFromError"); //$NON-NLS-1$
+ throw new TranslatorException(msg);
+ }
+ TableReference fItm = itr.next();
+ if(itr.hasNext()) {
+ final String msg = LDAPPlugin.Util.getString("IQueryToLdapSearchParser.multiItemsInFromError"); //$NON-NLS-1$
+ throw new TranslatorException(msg);
+ }
+
+ LDAPSearchDetails sd = null;
+ Table table = ((NamedTable)fItm).getMetadataObject();
+ String nativeQuery = table.getProperty(TEIID_NATIVE_QUERY, false);
+ if (nativeQuery != null) {
+ sd = buildRequest(nativeQuery);
+ }
+ else {
String contextName = getContextNameFromFromItem(fItm);
int searchScope = getSearchScopeFromFromItem(fItm);
// GHH 20080326 - added check for RESTRICT parameter in
@@ -142,12 +161,12 @@
}
// Create Search Details
- LDAPSearchDetails sd = new LDAPSearchDetails(contextName, searchScope, filterBuilder.toString(), sortKeys, countLimit, elementList);
- // Search Details logging
- sd.printDetailsToLog();
+ sd = new LDAPSearchDetails(contextName, searchScope, filterBuilder.toString(), sortKeys, countLimit, elementList, 0);
+ }
+ // Search Details logging
+ sd.printDetailsToLog();
+ return sd;
- return sd;
-
}
/**
@@ -598,5 +617,73 @@
return expr.getMetadataObject();
}
+ public LDAPSearchDetails buildRequest(String query) {
+ ArrayList<String> attributes = new ArrayList<String>();
+ ArrayList<Column> columns = new ArrayList<Column>();
+ String contextName = null;
+ String criteria = ""; //$NON-NLS-1$
+ String searchScope = this.executionFactory.getSearchDefaultScope().name();
+ int timeLimit = 0;
+ long countLimit = 0;
+
+ StringTokenizer st = new StringTokenizer(query, ";"); //$NON-NLS-1$
+ while (st.hasMoreTokens()) {
+ String var = st.nextToken();
+ int index = var.indexOf('=');
+ if (index == -1) {
+ continue;
+ }
+ String key = var.substring(0, index).trim().toLowerCase();
+ String value = var.substring(index+1).trim();
+
+ if (key.equalsIgnoreCase(CONTEXT_NAME)) {
+ contextName = value;
+ }
+ else if (key.equalsIgnoreCase(CRITERIA)) {
+ criteria = value;
+ }
+ else if (key.equalsIgnoreCase(SEARCH_SCOPE)) {
+ searchScope = value;
+ }
+ else if (key.equalsIgnoreCase(TIMEOUT)) {
+ timeLimit = Integer.parseInt(value);
+ }
+ else if (key.equalsIgnoreCase(COUNT_LIMIT)) {
+ countLimit = Long.parseLong(value);
+ }
+ else if (key.equalsIgnoreCase(ATTRIBUTES)) {
+ StringTokenizer attrTokens = new StringTokenizer(value, ","); //$NON-NLS-1$
+ while(attrTokens.hasMoreElements()) {
+ String name = attrTokens.nextToken().trim();
+ attributes.add(name);
+
+ Column column = new Column();
+ column.setName(name);
+ Datatype type = new Datatype();
+ type.setName(TypeFacility.RUNTIME_NAMES.OBJECT);
+ type.setJavaClassName(Object.class.getCanonicalName());
+ column.setDatatype(type, true);
+ columns.add(column);
+ }
+ }
+ }
+
+ int searchScopeInt = buildSearchScope(searchScope);
+ return new LDAPSearchDetails(contextName, searchScopeInt, criteria, null, countLimit, columns, timeLimit);
+ }
+ private int buildSearchScope(String searchScope) {
+ int searchScopeInt = 0;
+ // this could be one of OBJECT_SCOPE, ONELEVEL_SCOPE, SUBTREE_SCOPE
+ if (searchScope.equalsIgnoreCase("OBJECT_SCOPE")) { //$NON-NLS-1$
+ searchScopeInt = SearchControls.OBJECT_SCOPE;
+ }
+ else if (searchScope.equalsIgnoreCase("ONELEVEL_SCOPE")) {//$NON-NLS-1$
+ searchScopeInt = SearchControls.ONELEVEL_SCOPE;
+ }
+ else if (searchScope.equalsIgnoreCase("SUBTREE_SCOPE")) {//$NON-NLS-1$
+ searchScopeInt = SearchControls.SUBTREE_SCOPE;
+ }
+ return searchScopeInt;
+ }
}
Modified: trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPDirectSearchQueryExecution.java
===================================================================
--- trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPDirectSearchQueryExecution.java 2012-10-01 17:55:58 UTC (rev 4495)
+++ trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPDirectSearchQueryExecution.java 2012-10-01 19:23:30 UTC (rev 4496)
@@ -23,28 +23,17 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.StringTokenizer;
import javax.naming.directory.SearchControls;
import javax.naming.ldap.LdapContext;
import org.teiid.language.Argument;
-import org.teiid.metadata.Column;
-import org.teiid.metadata.Datatype;
import org.teiid.translator.DataNotAvailableException;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.ProcedureExecution;
import org.teiid.translator.TranslatorException;
-import org.teiid.translator.TypeFacility;
public class LDAPDirectSearchQueryExecution extends LDAPSyncQueryExecution implements ProcedureExecution {
-
- private static final String ATTRIBUTES = "attributes"; //$NON-NLS-1$
- private static final String COUNT_LIMIT = "count-limit"; //$NON-NLS-1$
- private static final String TIMEOUT = "timeout";//$NON-NLS-1$
- private static final String SEARCH_SCOPE = "search-scope";//$NON-NLS-1$
- private static final String CRITERIA = "filter";//$NON-NLS-1$
- private static final String CONTEXT_NAME = "context-name";//$NON-NLS-1$
private List<Argument> arguments;
@@ -55,94 +44,23 @@
@Override
public void execute() throws TranslatorException {
- this.delegate = buildRequest();
- this.delegate.execute();
- }
-
- private LDAPQueryExecution buildRequest() throws TranslatorException {
String query = (String)arguments.get(0).getArgumentValue().getValue();
+ IQueryToLdapSearchParser parser = new IQueryToLdapSearchParser(this.executionFactory);
+ LDAPSearchDetails details = parser.buildRequest(query);
+ // Create and configure the new search context.
+ LdapContext context = createSearchContext(details.getContextName());
- ArrayList<String> attributes = new ArrayList<String>();
- ArrayList<Column> columns = new ArrayList<Column>();
- String contextName = null;
- String criteria = ""; //$NON-NLS-1$
- String searchScope = this.executionFactory.getSearchDefaultScope().name();
- int timeLimit = 0;
- long countLimit = 0;
-
- StringTokenizer st = new StringTokenizer(query, ";"); //$NON-NLS-1$
- while (st.hasMoreTokens()) {
- String var = st.nextToken();
- int index = var.indexOf('=');
- if (index == -1) {
- continue;
- }
- String key = var.substring(0, index).trim().toLowerCase();
- String value = var.substring(index+1).trim();
-
- if (key.equalsIgnoreCase(CONTEXT_NAME)) {
- contextName = value;
- }
- else if (key.equalsIgnoreCase(CRITERIA)) {
- criteria = value;
- }
- else if (key.equalsIgnoreCase(SEARCH_SCOPE)) {
- searchScope = value;
- }
- else if (key.equalsIgnoreCase(TIMEOUT)) {
- timeLimit = Integer.parseInt(value);
- }
- else if (key.equalsIgnoreCase(COUNT_LIMIT)) {
- countLimit = Long.parseLong(value);
- }
- else if (key.equalsIgnoreCase(ATTRIBUTES)) {
- StringTokenizer attrTokens = new StringTokenizer(value, ","); //$NON-NLS-1$
- while(attrTokens.hasMoreElements()) {
- String name = attrTokens.nextToken().trim();
- attributes.add(name);
-
- Column column = new Column();
- column.setName(name);
- Datatype type = new Datatype();
- type.setName(TypeFacility.RUNTIME_NAMES.OBJECT);
- type.setJavaClassName(Object.class.getCanonicalName());
- column.setDatatype(type, true);
- columns.add(column);
- }
- }
- }
-
- int searchScopeInt = buildSearchScope(searchScope);
-
// build search controls
SearchControls controls = new SearchControls();
- controls.setSearchScope(searchScopeInt);
- controls.setTimeLimit(timeLimit);
- controls.setCountLimit(countLimit);
- controls.setReturningAttributes(attributes.toArray(new String[attributes.size()]));
+ controls.setSearchScope(details.getSearchScope());
+ controls.setTimeLimit(details.getTimeLimit());
+ controls.setCountLimit(details.getCountLimit());
+ controls.setReturningAttributes(details.getAttributes());
- LDAPSearchDetails searchDetails = new LDAPSearchDetails(contextName, searchScopeInt, criteria, null, countLimit, columns);
-
- // Create and configure the new search context.
- LdapContext context = createSearchContext(contextName);
- return new LDAPQueryExecution(context, searchDetails, controls, this.executionFactory, this.executionContext);
+ this.delegate = new LDAPQueryExecution(context, details, controls, this.executionFactory, this.executionContext);
+ this.delegate.execute();
}
- private int buildSearchScope(String searchScope) {
- int searchScopeInt = 0;
- // this could be one of OBJECT_SCOPE, ONELEVEL_SCOPE, SUBTREE_SCOPE
- if (searchScope.equalsIgnoreCase("OBJECT_SCOPE")) { //$NON-NLS-1$
- searchScopeInt = SearchControls.OBJECT_SCOPE;
- }
- else if (searchScope.equalsIgnoreCase("ONELEVEL_SCOPE")) {//$NON-NLS-1$
- searchScopeInt = SearchControls.ONELEVEL_SCOPE;
- }
- else if (searchScope.equalsIgnoreCase("SUBTREE_SCOPE")) {//$NON-NLS-1$
- searchScopeInt = SearchControls.SUBTREE_SCOPE;
- }
- return searchScopeInt;
- }
-
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
List<?> vals = super.next();
Modified: trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPSearchDetails.java
===================================================================
--- trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPSearchDetails.java 2012-10-01 17:55:58 UTC (rev 4495)
+++ trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPSearchDetails.java 2012-10-01 19:23:30 UTC (rev 4496)
@@ -48,6 +48,7 @@
// If limit is set to -1, this means no limit (return all rows)
private long limit;
private ArrayList<Column> elementList;
+ private int timeLimit;
/**
* Constructor
@@ -59,7 +60,7 @@
* @param limit
* @param elementList
*/
- public LDAPSearchDetails(String name, int searchScope, String filter, SortKey[] keys, long limit, ArrayList elementList) {
+ public LDAPSearchDetails(String name, int searchScope, String filter, SortKey[] keys, long limit, ArrayList elementList, int timeLimit) {
this.contextName = name;
this.searchScope = searchScope;
@@ -67,6 +68,7 @@
this.keys = keys;
this.limit = limit;
this.elementList = elementList;
+ this.timeLimit = timeLimit;
}
/**
@@ -179,4 +181,16 @@
}
}
}
+
+ public int getTimeLimit() {
+ return this.timeLimit;
+ }
+
+ public String[] getAttributes() {
+ ArrayList<String> attributes = new ArrayList<String>();
+ for (Column c:elementList) {
+ attributes.add(c.getName());
+ }
+ return attributes.toArray(new String[attributes.size()]);
+ }
}
Modified: trunk/connectors/translator-ldap/src/test/java/org/teiid/translator/ldap/TestIQueryToLdapSearchParser.java
===================================================================
--- trunk/connectors/translator-ldap/src/test/java/org/teiid/translator/ldap/TestIQueryToLdapSearchParser.java 2012-10-01 17:55:58 UTC (rev 4495)
+++ trunk/connectors/translator-ldap/src/test/java/org/teiid/translator/ldap/TestIQueryToLdapSearchParser.java 2012-10-01 19:23:30 UTC (rev 4496)
@@ -21,8 +21,6 @@
*/
package org.teiid.translator.ldap;
-import static org.mockito.Mockito.mock;
-
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -34,23 +32,18 @@
import org.teiid.cdk.CommandBuilder;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl;
import org.teiid.language.Command;
import org.teiid.language.Select;
import org.teiid.metadata.Column;
+import org.teiid.metadata.Column.SearchType;
import org.teiid.metadata.MetadataStore;
-import org.teiid.metadata.RuntimeMetadata;
import org.teiid.metadata.Schema;
import org.teiid.metadata.Table;
-import org.teiid.metadata.Column.SearchType;
import org.teiid.query.metadata.CompositeMetadataStore;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.unittest.RealMetadataFactory;
import org.teiid.translator.TranslatorException;
-import org.teiid.translator.ldap.IQueryToLdapSearchParser;
-import org.teiid.translator.ldap.LDAPExecutionFactory;
-import org.teiid.translator.ldap.LDAPSearchDetails;
/**
@@ -252,16 +245,34 @@
helpTestSearchDetails(searchDetails, expectedContextName, expectedContextFilter, expectedAttrNameList,
expectedCountLimit, expectedSearchScope, expectedSortKeys);
}
+
+ public void testNativeQueryExtension() throws Exception {
+ LDAPSearchDetails searchDetails = helpGetSearchDetails("SELECT * FROM LdapModel.Employee"); //$NON-NLS-1$
+
+ String expectedContextName = "corporate"; //$NON-NLS-1$
+ String expectedContextFilter = "(objectClass=*)"; //$NON-NLS-1$
+
+ List expectedAttrNameList = new ArrayList();
+ expectedAttrNameList.add("uid"); //$NON-NLS-1$
+ expectedAttrNameList.add("cn"); //$NON-NLS-1$
+
+ long expectedCountLimit = 5;
+ int expectedSearchScope = SearchControls.ONELEVEL_SCOPE;
+ SortKey[] expectedSortKeys = null;
+
+ helpTestSearchDetails(searchDetails, expectedContextName, expectedContextFilter, expectedAttrNameList,
+ expectedCountLimit, expectedSearchScope, expectedSortKeys);
+
+ }
private LDAPSearchDetails helpGetSearchDetails(String queryString) throws TranslatorException {
QueryMetadataInterface metadata = exampleLdap();
- RuntimeMetadata rm = new RuntimeMetadataImpl(metadata);
- LDAPExecutionFactory config = mock(LDAPExecutionFactory.class);
+ Select query = (Select)getCommand(queryString, metadata);
+ LDAPExecutionFactory config = new LDAPExecutionFactory();
+
IQueryToLdapSearchParser searchParser = new IQueryToLdapSearchParser(config);
-
- Select query = (Select)getCommand(queryString, metadata);
LDAPSearchDetails searchDetails = searchParser.translateSQLQueryToLDAPSearch(query);
return searchDetails;
@@ -301,6 +312,19 @@
cols.get(i).setSearchType(SearchType.Unsearchable);
}
+ Table employees = RealMetadataFactory.createPhysicalGroup("Employee", ldapModel); //$NON-NLS-1$
+ List<Column> employeeCols = RealMetadataFactory.createElements(employees, elemNames, elemTypes);
+ for(int i=0; i<2; i++) {
+ Column obj = employeeCols.get(i);
+ obj.setNameInSource(nameInSource[i]);
+ }
+
+ // Set column-specific properties
+ for(int i=1; i<2; i++) {
+ employeeCols.get(i).setSearchType(SearchType.Unsearchable);
+ }
+ employees.setProperty(IQueryToLdapSearchParser.TEIID_NATIVE_QUERY, "context-name=corporate;filter=(objectClass=*);count-limit=5;timout=6;search-scope=ONELEVEL_SCOPE;attributes=uid,cn"); //$NON-NLS-1$
+
// Create the facade from the store
return new TransformationMetadata(null, new CompositeMetadataStore(metadataStore), null, RealMetadataFactory.SFM.getSystemFunctions(), null);
}
12 years, 2 months
teiid SVN: r4495 - in trunk/connectors/translator-salesforce/src: test/java/org/teiid/translator/salesforce/execution/visitors and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2012-10-01 13:55:58 -0400 (Mon, 01 Oct 2012)
New Revision: 4495
Modified:
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/JoinQueryVisitor.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java
trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java
Log:
TEIID-2177: Expanding the native query support through extension metadata is expanded to salesforce
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/JoinQueryVisitor.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/JoinQueryVisitor.java 2012-10-01 15:39:47 UTC (rev 4494)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/JoinQueryVisitor.java 2012-10-01 17:55:58 UTC (rev 4495)
@@ -98,15 +98,30 @@
subselect.append(SELECT).append(SPACE);
addSelect(rightTableInJoin.getNameInSource(), subselect, false);
subselect.append(SPACE);
- subselect.append(FROM).append(SPACE);
- subselect.append(rightTableInJoin.getNameInSource()).append('s');
- subselect.append(CLOSE).append(SPACE);
- select.append(subselect);
- select.append(FROM).append(SPACE);
- select.append(leftTableInJoin.getNameInSource()).append(SPACE);
- addCriteriaString(select);
- appendGroupByHaving(select);
- select.append(limitClause);
+
+ String nativeQuery = this.rightTableInJoin.getProperty(TEIID_NATIVE_QUERY, false);
+ if (nativeQuery != null) {
+ subselect.append(nativeQuery);
+ }
+ else {
+ subselect.append(FROM).append(SPACE);
+ subselect.append(rightTableInJoin.getNameInSource()).append('s');
+ }
+ subselect.append(CLOSE).append(SPACE);
+
+ select.append(subselect);
+
+ nativeQuery = this.leftTableInJoin.getProperty(TEIID_NATIVE_QUERY, false);
+ if (nativeQuery != null) {
+ select.append(nativeQuery);
+ }
+ else {
+ select.append(FROM).append(SPACE);
+ select.append(leftTableInJoin.getNameInSource()).append(SPACE);
+ addCriteriaString(select);
+ appendGroupByHaving(select);
+ select.append(limitClause);
+ }
return select.toString();
}
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java 2012-10-01 15:39:47 UTC (rev 4494)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java 2012-10-01 17:55:58 UTC (rev 4495)
@@ -21,6 +21,7 @@
*/
package org.teiid.translator.salesforce.execution.visitors;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -28,6 +29,7 @@
import java.util.Map;
import org.teiid.language.*;
+import org.teiid.metadata.AbstractMetadataRecord;
import org.teiid.metadata.Column;
import org.teiid.metadata.RuntimeMetadata;
import org.teiid.translator.TranslatorException;
@@ -36,7 +38,7 @@
public class SelectVisitor extends CriteriaVisitor implements IQueryProvidingVisitor {
-
+ public static final String TEIID_NATIVE_QUERY = AbstractMetadataRecord.RELATIONAL_URI + "native-query"; //$NON-NLS-1$
public static final String AGG_PREFIX = "expr"; //$NON-NLS-1$
private Map<Integer, Expression> selectSymbolIndexToElement = new HashMap<Integer, Expression>();
private Map<String, Integer> selectSymbolNameToIndex = new HashMap<String, Integer>();
@@ -142,16 +144,24 @@
if (!exceptions.isEmpty()) {
throw exceptions.get(0);
}
+
StringBuilder result = new StringBuilder();
result.append(SELECT).append(SPACE);
addSelectSymbols(result);
result.append(SPACE);
- result.append(FROM).append(SPACE);
- result.append(table.getNameInSource()).append(SPACE);
- addCriteriaString(result);
- appendGroupByHaving(result);
- //result.append(orderByClause).append(SPACE);
- result.append(limitClause);
+
+ String nativeQuery = this.table.getProperty(TEIID_NATIVE_QUERY, false);
+ if (nativeQuery != null) {
+ result.append(nativeQuery);
+ }
+ else {
+ result.append(FROM).append(SPACE);
+ result.append(table.getNameInSource()).append(SPACE);
+ addCriteriaString(result);
+ appendGroupByHaving(result);
+ //result.append(orderByClause).append(SPACE);
+ result.append(limitClause);
+ }
return result.toString();
}
Modified: trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java
===================================================================
--- trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java 2012-10-01 15:39:47 UTC (rev 4494)
+++ trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java 2012-10-01 17:55:58 UTC (rev 4495)
@@ -31,6 +31,7 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.teiid.cdk.api.TranslationUtility;
import org.teiid.core.types.DataTypeManager;
@@ -39,6 +40,7 @@
import org.teiid.metadata.MetadataStore;
import org.teiid.metadata.Procedure;
import org.teiid.metadata.ProcedureParameter;
+import org.teiid.metadata.RuntimeMetadata;
import org.teiid.metadata.Schema;
import org.teiid.metadata.Table;
import org.teiid.metadata.Column.SearchType;
@@ -48,12 +50,16 @@
import org.teiid.query.sql.lang.SPParameter;
import org.teiid.query.unittest.RealMetadataFactory;
import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.ResultSetExecution;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.TypeFacility;
import org.teiid.translator.salesforce.Constants;
+import org.teiid.translator.salesforce.SalesForceExecutionFactory;
import org.teiid.translator.salesforce.SalesforceConnection;
import org.teiid.translator.salesforce.execution.QueryExecutionImpl;
+import com.sforce.soap.partner.QueryResult;
+
@SuppressWarnings("nls")
public class TestVisitors {
@@ -108,8 +114,18 @@
Column obj = contactCols.get(i);
obj.setNameInSource(contactNameInSource[i]);
}
-
+ Table nativeTable = RealMetadataFactory.createPhysicalGroup("Native", salesforceModel); //$NON-NLS-1$
+ nativeTable.setNameInSource("Native"); //$NON-NLS-1$
+ nativeTable.setProperty("Supports Query", Boolean.TRUE.toString()); //$NON-NLS-1$
+ nativeTable.setProperty(SelectVisitor.TEIID_NATIVE_QUERY, "FROM MyTable WHERE Anything='goes'");
+
+ List<Column> contactCols2 = RealMetadataFactory.createElements(nativeTable, elemNames, elemTypes);
+ for(int i=0; i<2; i++) {
+ Column obj = contactCols2.get(i);
+ obj.setNameInSource(contactNameInSource[i]);
+ }
+
List<ProcedureParameter> params = new LinkedList<ProcedureParameter>();
params.add(RealMetadataFactory.createParameter("type", SPParameter.IN, TypeFacility.RUNTIME_NAMES.STRING));
params.add(RealMetadataFactory.createParameter("start", SPParameter.IN, TypeFacility.RUNTIME_NAMES.TIMESTAMP));
@@ -124,24 +140,18 @@
private static TranslationUtility translationUtility = new TranslationUtility(exampleSalesforce());
@Test public void testOr() throws Exception {
- Select command = (Select)translationUtility.parseCommand("select * from Account where Name = 'foo' or Stuff = 'bar'"); //$NON-NLS-1$
- SelectVisitor visitor = new SelectVisitor(translationUtility.createRuntimeMetadata());
- visitor.visit(command);
- assertEquals("SELECT Account.id, Account.AccountName, Account.Stuff, Account.Industry FROM Account WHERE (Account.AccountName = 'foo') OR (Account.Stuff = 'bar')", visitor.getQuery().toString().trim()); //$NON-NLS-1$
+ String sql = "select * from Account where Name = 'foo' or Stuff = 'bar'";
+ helpTest(sql, "SELECT Account.id, Account.AccountName, Account.Stuff, Account.Industry FROM Account WHERE (Account.AccountName = 'foo') OR (Account.Stuff = 'bar')");
}
@Test public void testNot() throws Exception {
- Select command = (Select)translationUtility.parseCommand("select * from Account where not (Name = 'foo' and Stuff = 'bar')"); //$NON-NLS-1$
- SelectVisitor visitor = new SelectVisitor(translationUtility.createRuntimeMetadata());
- visitor.visit(command);
- assertEquals("SELECT Account.id, Account.AccountName, Account.Stuff, Account.Industry FROM Account WHERE (Account.AccountName != 'foo') OR (Account.Stuff != 'bar')", visitor.getQuery().toString().trim()); //$NON-NLS-1$
+ String sql = "select * from Account where not (Name = 'foo' and Stuff = 'bar')"; //$NON-NLS-1$
+ helpTest(sql, "SELECT Account.id, Account.AccountName, Account.Stuff, Account.Industry FROM Account WHERE (Account.AccountName != 'foo') OR (Account.Stuff != 'bar')");
}
@Test public void testCountStar() throws Exception {
- Select command = (Select)translationUtility.parseCommand("select count(*) from Account"); //$NON-NLS-1$
- SelectVisitor visitor = new SelectVisitor(translationUtility.createRuntimeMetadata());
- visitor.visit(command);
- assertEquals("SELECT COUNT(Id) FROM Account", visitor.getQuery().toString().trim()); //$NON-NLS-1$
+ String sql = "select count(*) from Account";
+ helpTest(sql,"SELECT COUNT(Id) FROM Account");
}
@Test public void testNotLike() throws Exception {
@@ -233,13 +243,6 @@
String source = "SELECT Contact.ContactName FROM Contact WHERE Contact.InitialContact = 2003-03-11T11:42:10.500-06:00";
helpTest(sql, source);
}
-
- private void helpTest(String sql, String source) throws TranslatorException {
- Select command = (Select)translationUtility.parseCommand(sql); //$NON-NLS-1$
- SelectVisitor visitor = new SelectVisitor(translationUtility.createRuntimeMetadata());
- visitor.visit(command);
- assertEquals(source, visitor.getQuery().toString().trim()); //$NON-NLS-1$
- }
@Test public void testDateTimeFormating1() throws Exception {
String sql = "select name from contacts where initialcontact in ({ts'2003-03-11 11:42:10.506'}, {ts'2003-03-11 11:42:10.8088'})";
@@ -265,4 +268,33 @@
helpTest(sql, source);
}
+ private void helpTest(String sql, String expected) throws Exception {
+ Select command = (Select)translationUtility.parseCommand(sql);
+ SalesForceExecutionFactory factory = new SalesForceExecutionFactory();
+ ExecutionContext ec = Mockito.mock(ExecutionContext.class);
+ RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
+ SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
+
+ ArgumentCaptor<String> queryArgument = ArgumentCaptor.forClass(String.class);
+ Mockito.stub(connection.query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean())).toReturn(Mockito.mock(QueryResult.class));
+
+ ResultSetExecution execution = factory.createResultSetExecution(command, ec, rm, connection);
+ execution.execute();
+
+ Mockito.verify(connection, Mockito.times(1)).query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean());
+
+ assertEquals(expected, queryArgument.getValue().trim());
+ }
+
+ @Test public void testNativeQuery() throws Exception {
+ String sql = "select name, accountid From Native";
+ String source = "SELECT Native.ContactName, Native.AccountId FROM MyTable WHERE Anything='goes'";
+ helpTest(sql, source);
+ }
+
+ @Test public void testNativeQueryWithJoin() throws Exception {
+ String sql = "select n.name, n.accountid, a.industry From Native n left outer join Account a on n.ContactID = a.id";
+ String expected = "SELECT Native.ContactName, Native.AccountId, (SELECT Account.Industry FROM Accounts) FROM MyTable WHERE Anything='goes'";
+ helpTest(sql, expected);
+ }
}
12 years, 2 months
teiid SVN: r4494 - in trunk/connectors: translator-jpa/src/test/java/org/teiid/translator/jpa and 2 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2012-10-01 11:39:47 -0400 (Mon, 01 Oct 2012)
New Revision: 4494
Modified:
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCDirectQueryExecution.java
trunk/connectors/translator-jpa/src/test/java/org/teiid/translator/jpa/TestJPADirectQueryExecution.java
trunk/connectors/translator-ldap/src/test/java/org/teiid/translator/ldap/TestLDAPDirectQueryExecution.java
trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/TestSalesForceDirectQueryExecution.java
Log:
TEIID-2176: Fixing the unit tests
Modified: trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCDirectQueryExecution.java
===================================================================
--- trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCDirectQueryExecution.java 2012-10-01 14:47:01 UTC (rev 4493)
+++ trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestJDBCDirectQueryExecution.java 2012-10-01 15:39:47 UTC (rev 4494)
@@ -60,6 +60,7 @@
Mockito.stub(connection.getMetaData()).toReturn(Mockito.mock(DatabaseMetaData.class));
JDBCExecutionFactory ef = new JDBCExecutionFactory();
+ ef.setSupportsNativeQueries(true);
ResultSetExecution execution = (ResultSetExecution)ef.createExecution(command, Mockito.mock(ExecutionContext.class), Mockito.mock(RuntimeMetadata.class), connection);
execution.execute();
assertArrayEquals(new Object[] {5}, (Object[])execution.next().get(0));
@@ -84,6 +85,7 @@
Mockito.stub(connection.getMetaData()).toReturn(Mockito.mock(DatabaseMetaData.class));
JDBCExecutionFactory ef = new JDBCExecutionFactory();
+ ef.setSupportsNativeQueries(true);
ResultSetExecution execution = (ResultSetExecution)ef.createExecution(command, Mockito.mock(ExecutionContext.class), Mockito.mock(RuntimeMetadata.class), connection);
execution.execute();
assertArrayEquals(new Object[] {5, "five"}, (Object[])execution.next().get(0));
@@ -108,6 +110,7 @@
Mockito.stub(connection.getMetaData()).toReturn(Mockito.mock(DatabaseMetaData.class));
JDBCExecutionFactory ef = new JDBCExecutionFactory();
+ ef.setSupportsNativeQueries(true);
ResultSetExecution execution = (ResultSetExecution)ef.createExecution(command, Mockito.mock(ExecutionContext.class), Mockito.mock(RuntimeMetadata.class), connection);
execution.execute();
assertArrayEquals(new Object[] {5, "five"}, (Object[])execution.next().get(0));
@@ -129,6 +132,7 @@
Mockito.stub(connection.getMetaData()).toReturn(Mockito.mock(DatabaseMetaData.class));
JDBCExecutionFactory ef = new JDBCExecutionFactory();
+ ef.setSupportsNativeQueries(true);
ResultSetExecution execution = (ResultSetExecution)ef.createExecution(command, Mockito.mock(ExecutionContext.class), Mockito.mock(RuntimeMetadata.class), connection);
execution.execute();
assertArrayEquals(new Object[] {5}, (Object[])execution.next().get(0));
Modified: trunk/connectors/translator-jpa/src/test/java/org/teiid/translator/jpa/TestJPADirectQueryExecution.java
===================================================================
--- trunk/connectors/translator-jpa/src/test/java/org/teiid/translator/jpa/TestJPADirectQueryExecution.java 2012-10-01 14:47:01 UTC (rev 4493)
+++ trunk/connectors/translator-jpa/src/test/java/org/teiid/translator/jpa/TestJPADirectQueryExecution.java 2012-10-01 15:39:47 UTC (rev 4494)
@@ -47,6 +47,7 @@
@BeforeClass
public static void setUp() throws TranslatorException {
TRANSLATOR = new JPA2ExecutionFactory();
+ TRANSLATOR.setSupportsNativeQueries(true);
TRANSLATOR.start();
}
Modified: trunk/connectors/translator-ldap/src/test/java/org/teiid/translator/ldap/TestLDAPDirectQueryExecution.java
===================================================================
--- trunk/connectors/translator-ldap/src/test/java/org/teiid/translator/ldap/TestLDAPDirectQueryExecution.java 2012-10-01 14:47:01 UTC (rev 4493)
+++ trunk/connectors/translator-ldap/src/test/java/org/teiid/translator/ldap/TestLDAPDirectQueryExecution.java 2012-10-01 15:39:47 UTC (rev 4494)
@@ -49,6 +49,7 @@
@BeforeClass
public static void setUp() throws TranslatorException {
TRANSLATOR = new LDAPExecutionFactory();
+ TRANSLATOR.setSupportsNativeQueries(true);
TRANSLATOR.start();
}
Modified: trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/TestSalesForceDirectQueryExecution.java
===================================================================
--- trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/TestSalesForceDirectQueryExecution.java 2012-10-01 14:47:01 UTC (rev 4493)
+++ trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/TestSalesForceDirectQueryExecution.java 2012-10-01 15:39:47 UTC (rev 4494)
@@ -53,6 +53,7 @@
@BeforeClass
public static void setUp() throws TranslatorException {
TRANSLATOR = new SalesForceExecutionFactory();
+ TRANSLATOR.setSupportsNativeQueries(true);
TRANSLATOR.start();
}
12 years, 2 months
teiid SVN: r4493 - in trunk/engine/src: main/java/org/teiid/dqp/internal/process and 8 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-10-01 10:47:01 -0400 (Mon, 01 Oct 2012)
New Revision: 4493
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/AuthorizationValidationVisitor.java
trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java
trunk/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java
trunk/engine/src/main/java/org/teiid/query/function/metadata/FunctionMetadataValidator.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java
trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
trunk/engine/src/test/java/org/teiid/query/function/metadata/TestFunctionMetadataValidator.java
trunk/engine/src/test/java/org/teiid/query/processor/TestFunctionPushdown.java
Log:
TEIID-2234 fixing function issues
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java 2012-10-01 14:42:22 UTC (rev 4492)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java 2012-10-01 14:47:01 UTC (rev 4493)
@@ -120,14 +120,14 @@
Iterator<String> iter = functions.iterator();
while(iter.hasNext()) {
String func = iter.next();
- tgtCaps.setFunctionSupport(func.toLowerCase(), true);
+ tgtCaps.setFunctionSupport(func, true);
}
}
List<FunctionMethod> pushDowns = srcCaps.getPushDownFunctions();
if(pushDowns != null && pushDowns.size() > 0) {
for(FunctionMethod func:pushDowns) {
- tgtCaps.setFunctionSupport(func.getName().toLowerCase(), true);
+ tgtCaps.setFunctionSupport(func.getName(), true);
}
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2012-10-01 14:42:22 UTC (rev 4492)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2012-10-01 14:47:01 UTC (rev 4493)
@@ -44,7 +44,6 @@
import org.teiid.language.SubqueryComparison.Quantifier;
import org.teiid.metadata.Procedure;
import org.teiid.metadata.ProcedureParameter;
-import org.teiid.metadata.FunctionMethod.PushDown;
import org.teiid.query.QueryPlugin;
import org.teiid.query.function.FunctionDescriptor;
import org.teiid.query.metadata.QueryMetadataInterface;
@@ -673,9 +672,9 @@
return translate(caseExpr);
}
//check for translator pushdown functions, and use the name in source if possible
- if (function.getFunctionDescriptor().getPushdown() == PushDown.MUST_PUSHDOWN
- && function.getFunctionDescriptor().getSchema().equalsIgnoreCase(CoreConstants.SYSTEM_MODEL)
- && function.getFunctionDescriptor().getMethod().getNameInSource() != null) {
+ if (function.getFunctionDescriptor().getMethod().getNameInSource() != null &&
+ (CoreConstants.SYSTEM_MODEL.equals(function.getFunctionDescriptor().getSchema())
+ || (function.getFunctionDescriptor().getMethod().getParent() != null && function.getFunctionDescriptor().getMethod().getParent().isPhysical())) ) {
name = function.getFunctionDescriptor().getMethod().getNameInSource();
}
} else {
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/AuthorizationValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/AuthorizationValidationVisitor.java 2012-10-01 14:42:22 UTC (rev 4492)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/AuthorizationValidationVisitor.java 2012-10-01 14:47:01 UTC (rev 4493)
@@ -162,7 +162,7 @@
String schema = obj.getFunctionDescriptor().getSchema();
if (schema != null && !isSystemSchema(schema)) {
Map<String, Function> map = new HashMap<String, Function>();
- map.put(schema + '.' + obj.getFunctionDescriptor().getName(), obj);
+ map.put(obj.getFunctionDescriptor().getFullName(), obj);
validateEntitlements(PermissionType.EXECUTE, Context.FUNCTION, map);
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2012-10-01 14:42:22 UTC (rev 4492)
+++ trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2012-10-01 14:47:01 UTC (rev 4493)
@@ -938,7 +938,7 @@
if (passing.getExpression() instanceof Function) {
Function f = (Function)passing.getExpression();
//narrow optimization of json based documents to allow for lower overhead streaming
- if (f.getFunctionDescriptor().getName().equalsIgnoreCase(SourceSystemFunctions.JSONTOXML)) {
+ if (f.getName().equalsIgnoreCase(SourceSystemFunctions.JSONTOXML)) {
String rootName = (String)this.evaluate(f.getArg(0), tuple);
Object lob = this.evaluate(f.getArg(1), tuple);
if (rootName == null || lob == null) {
@@ -1050,7 +1050,7 @@
fd.checkNotPushdown();
// Check for special lookup function
- if(fd.getName().equalsIgnoreCase(FunctionLibrary.LOOKUP)) {
+ if(function.getName().equalsIgnoreCase(FunctionLibrary.LOOKUP)) {
if(dataMgr == null) {
throw new ComponentNotFoundException(QueryPlugin.Event.TEIID30342, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30342));
}
Modified: trunk/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java 2012-10-01 14:42:22 UTC (rev 4492)
+++ trunk/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java 2012-10-01 14:47:01 UTC (rev 4493)
@@ -29,12 +29,14 @@
import java.util.Arrays;
import org.teiid.api.exception.query.FunctionExecutionException;
+import org.teiid.core.CoreConstants;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.types.ArrayImpl;
import org.teiid.core.types.BinaryType;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.TransformationException;
import org.teiid.core.util.PropertiesUtils;
+import org.teiid.metadata.AbstractMetadataRecord;
import org.teiid.metadata.FunctionMethod;
import org.teiid.metadata.FunctionMethod.Determinism;
import org.teiid.metadata.FunctionMethod.PushDown;
@@ -103,6 +105,13 @@
public String getName() {
return this.method.getName();
}
+
+ public String getFullName() {
+ if (CoreConstants.SYSTEM_MODEL.equals(this.schema)) {
+ return getName();
+ }
+ return this.schema + AbstractMetadataRecord.NAME_DELIM_CHAR + getName();
+ }
public PushDown getPushdown() {
return this.method.getPushdown();
@@ -183,7 +192,7 @@
public void checkNotPushdown() throws FunctionExecutionException {
// Check for function we can't evaluate
if(getPushdown() == PushDown.MUST_PUSHDOWN) {
- throw new FunctionExecutionException(QueryPlugin.Event.TEIID30341, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30341, getName()));
+ throw new FunctionExecutionException(QueryPlugin.Event.TEIID30341, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30341, getFullName()));
}
}
@@ -209,7 +218,7 @@
// If descriptor is missing invokable method, find this VM's descriptor
// give name and types from fd
if(invocationMethod == null) {
- throw new FunctionExecutionException(QueryPlugin.Event.TEIID30382, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30382, getName()));
+ throw new FunctionExecutionException(QueryPlugin.Event.TEIID30382, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30382, getFullName()));
}
// Invoke the method and return the result
@@ -270,9 +279,9 @@
}
return importValue(result, getReturnType());
} catch(ArithmeticException e) {
- throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, getName()));
+ throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, getFullName()));
} catch(InvocationTargetException e) {
- throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e.getTargetException(), QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, getName()));
+ throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e.getTargetException(), QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, getFullName()));
} catch(IllegalAccessException e) {
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30385, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30385, method.toString()));
} catch (TransformationException e) {
@@ -317,4 +326,8 @@
this.calledWithVarArgArrayParam = calledWithVarArgArrayParam;
}
+ public boolean isSystemFunction(String name) {
+ return this.getName().equalsIgnoreCase(name) && CoreConstants.SYSTEM_MODEL.equals(this.getSchema());
+ }
+
}
Modified: trunk/engine/src/main/java/org/teiid/query/function/metadata/FunctionMetadataValidator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/metadata/FunctionMetadataValidator.java 2012-10-01 14:42:22 UTC (rev 4492)
+++ trunk/engine/src/main/java/org/teiid/query/function/metadata/FunctionMetadataValidator.java 2012-10-01 14:47:01 UTC (rev 4493)
@@ -150,7 +150,6 @@
public static final void validateName(String name) throws FunctionMetadataException {
validateIsNotNull(name, "Name"); //$NON-NLS-1$
validateLength(name, MAX_LENGTH, "Name"); //$NON-NLS-1$
- validateNameCharacters(name, "Name"); //$NON-NLS-1$
}
/**
@@ -246,19 +245,6 @@
}
/**
- * Check that specified string uses valid allowed character set. If not, an exception is thrown using
- * strName for the exception message.
- * @param name String to check
- * @param strName String to use in exception message
- * @throws FunctionMetadataException Thrown when string uses characters not in allowed character sets
- */
- private static final void validateNameCharacters(String name, String strName) throws FunctionMetadataException {
- if (name.indexOf('.') > 0) {
- throw new FunctionMetadataException(QueryPlugin.Event.TEIID30431, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30431,strName, '.'));
- }
- }
-
- /**
* Check that specified string is valid Java identifier. If not, an exception is thrown using
* strName for the exception message.
* @param identifier String to check
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java 2012-10-01 14:42:22 UTC (rev 4492)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java 2012-10-01 14:47:01 UTC (rev 4493)
@@ -279,7 +279,7 @@
markInvalid(obj, (obj.isImplicit()?"(implicit) ":"") + obj.getName() + " function not supported by source"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return;
}
- String name = obj.getFunctionDescriptor().getName();
+ String name = obj.getName();
if (CapabilitiesUtil.supports(Capability.ONLY_FORMAT_LITERALS, modelID, metadata, capFinder) && parseFormat.contains(name)) {
if (!(obj.getArg(1) instanceof Constant)) {
markInvalid(obj, obj.getName() + " non-literal parse format function not supported by source"); //$NON-NLS-1$
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java 2012-10-01 14:42:22 UTC (rev 4492)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java 2012-10-01 14:47:01 UTC (rev 4493)
@@ -558,7 +558,7 @@
fd.setCalledWithVarArgArrayParam(true);
}
- if(fd.getName().equalsIgnoreCase(FunctionLibrary.CONVERT) || fd.getName().equalsIgnoreCase(FunctionLibrary.CAST)) {
+ if(fd.isSystemFunction(FunctionLibrary.CONVERT) || fd.isSystemFunction(FunctionLibrary.CAST)) {
String dataType = (String) ((Constant)args[1]).getValue();
Class<?> dataTypeClass = DataTypeManager.getDataTypeClass(dataType);
fd = library.findTypedConversionFunction(args[0].getType(), dataTypeClass);
@@ -571,10 +571,10 @@
throw new QueryResolverException(QueryPlugin.Event.TEIID30071, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30071, new Object[] {DataTypeManager.getDataTypeName(srcTypeClass), dataType}));
}
- } else if(fd.getName().equalsIgnoreCase(FunctionLibrary.LOOKUP)) {
+ } else if(fd.isSystemFunction(FunctionLibrary.LOOKUP)) {
ResolverUtil.ResolvedLookup lookup = ResolverUtil.resolveLookup(function, metadata);
fd = library.copyFunctionChangeReturnType(fd, lookup.getReturnElement().getType());
- } else if (FunctionLibrary.ARRAY_GET.equalsIgnoreCase(fd.getName()) && args[0].getType().isArray()) {
+ } else if (fd.isSystemFunction(FunctionLibrary.ARRAY_GET) && args[0].getType().isArray()) {
//hack to use typed array values
fd = library.copyFunctionChangeReturnType(fd, args[0].getType().getComponentType());
} else if (Boolean.valueOf(fd.getMethod().getProperty(TEIID_PASS_THROUGH_TYPE, false))) {
Modified: trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2012-10-01 14:42:22 UTC (rev 4492)
+++ trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2012-10-01 14:47:01 UTC (rev 4493)
@@ -311,7 +311,7 @@
} catch (TeiidProcessingException e) {
handleException(e, obj);
}
- } else if (obj.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.CONTEXT)) {
+ } else if (obj.getName().equalsIgnoreCase(FunctionLibrary.CONTEXT)) {
if(!isXML) {
// can't use this pseudo-function in non-XML queries
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.The_context_function_cannot_be_used_in_a_non-XML_command"), obj); //$NON-NLS-1$
@@ -323,13 +323,13 @@
for (Iterator<Function> functions = FunctionCollectorVisitor.getFunctions(obj.getArg(1), false).iterator(); functions.hasNext();) {
Function function = functions.next();
- if (function.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.CONTEXT)) {
+ if (function.getName().equalsIgnoreCase(FunctionLibrary.CONTEXT)) {
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.Context_function_nested"), obj); //$NON-NLS-1$
}
}
}
- } else if (obj.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.ROWLIMIT) ||
- obj.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.ROWLIMITEXCEPTION)) {
+ } else if (obj.getName().equalsIgnoreCase(FunctionLibrary.ROWLIMIT) ||
+ obj.getName().equalsIgnoreCase(FunctionLibrary.ROWLIMITEXCEPTION)) {
if(isXML) {
if (!(obj.getArg(0) instanceof ElementSymbol)) {
// Arg must be an element symbol
@@ -339,7 +339,7 @@
// can't use this pseudo-function in non-XML queries
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.The_rowlimit_function_cannot_be_used_in_a_non-XML_command"), obj); //$NON-NLS-1$
}
- } else if(obj.getFunctionDescriptor().getName().equalsIgnoreCase(SourceSystemFunctions.XPATHVALUE)) {
+ } else if(obj.getName().equalsIgnoreCase(SourceSystemFunctions.XPATHVALUE)) {
// Validate the xpath value is valid
if(obj.getArgs()[1] instanceof Constant) {
Constant xpathConst = (Constant) obj.getArgs()[1];
@@ -349,7 +349,7 @@
handleValidationError(QueryPlugin.Util.getString("QueryResolver.invalid_xpath", e.getMessage()), obj); //$NON-NLS-1$
}
}
- } else if(obj.getFunctionDescriptor().getName().equalsIgnoreCase(SourceSystemFunctions.TO_BYTES) || obj.getFunctionDescriptor().getName().equalsIgnoreCase(SourceSystemFunctions.TO_CHARS)) {
+ } else if(obj.getName().equalsIgnoreCase(SourceSystemFunctions.TO_BYTES) || obj.getName().equalsIgnoreCase(SourceSystemFunctions.TO_CHARS)) {
try {
FunctionMethods.getCharset((String)((Constant)obj.getArg(1)).getValue());
} catch (IllegalArgumentException e) {
@@ -961,16 +961,16 @@
Expression expr = null;
if (obj.getLeftExpression() instanceof Function) {
Function leftExpr = (Function)obj.getLeftExpression();
- if (leftExpr.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.ROWLIMIT) ||
- leftExpr.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.ROWLIMITEXCEPTION)) {
+ if (leftExpr.getName().equalsIgnoreCase(FunctionLibrary.ROWLIMIT) ||
+ leftExpr.getName().equalsIgnoreCase(FunctionLibrary.ROWLIMITEXCEPTION)) {
function = leftExpr;
expr = obj.getRightExpression();
}
}
if (function == null && obj.getRightExpression() instanceof Function) {
Function rightExpr = (Function)obj.getRightExpression();
- if (rightExpr.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.ROWLIMIT) ||
- rightExpr.getFunctionDescriptor().getName().equalsIgnoreCase(FunctionLibrary.ROWLIMITEXCEPTION)) {
+ if (rightExpr.getName().equalsIgnoreCase(FunctionLibrary.ROWLIMIT) ||
+ rightExpr.getName().equalsIgnoreCase(FunctionLibrary.ROWLIMITEXCEPTION)) {
function = rightExpr;
expr = obj.getLeftExpression();
}
Modified: trunk/engine/src/test/java/org/teiid/query/function/metadata/TestFunctionMetadataValidator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/metadata/TestFunctionMetadataValidator.java 2012-10-01 14:42:22 UTC (rev 4492)
+++ trunk/engine/src/test/java/org/teiid/query/function/metadata/TestFunctionMetadataValidator.java 2012-10-01 14:47:01 UTC (rev 4493)
@@ -93,7 +93,7 @@
}
public void testValidateNameFail3() {
- helpTestValidateNameFail("a.b"); //$NON-NLS-1$
+ helpTestValidateName("a.b"); //$NON-NLS-1$
}
public void testValidateFunction1() {
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestFunctionPushdown.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestFunctionPushdown.java 2012-10-01 14:42:22 UTC (rev 4492)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestFunctionPushdown.java 2012-10-01 14:47:01 UTC (rev 4493)
@@ -143,6 +143,40 @@
new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
}
+ @Test public void testDDLMetadata1() throws Exception {
+ String ddl = "CREATE foreign FUNCTION sourceFunc(msg varchar) RETURNS varchar options (nameinsource 'a.sourcefunc') " +
+ "CREATE foreign FUNCTION b.sourceFunc(msg varchar) RETURNS varchar " +
+ "CREATE foreign table X (Y varchar);";
+
+ QueryMetadataInterface metadata = RealMetadataFactory.fromDDL(ddl, "x", "phy");
+
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+ capFinder.addCapabilities("phy", caps); //$NON-NLS-1$
+
+ ProcessorPlan plan = helpPlan("SELECT sourceFunc(g_0.Y), phy.b.sourceFunc(g_0.Y) FROM phy.X AS g_0", metadata, null, capFinder,
+ new String[] {"SELECT sourceFunc(g_0.Y), phy.b.sourceFunc(g_0.Y) FROM phy.X AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+
+ //ensure that the source query contains the function schemas
+ HardcodedDataManager dm = new HardcodedDataManager(metadata);
+ dm.addData("SELECT a.sourcefunc(g_0.Y), b.sourceFunc(g_0.Y) FROM X AS g_0", new List[0]);
+ TestProcessor.helpProcess(plan, dm, new List[0]);
+ }
+
+ @Test public void testDDLMetadataNameConflict() throws Exception {
+ String ddl = "CREATE foreign FUNCTION \"convert\"(msg integer, type varchar) RETURNS varchar " +
+ "CREATE foreign table X (Y integer);";
+
+ QueryMetadataInterface metadata = RealMetadataFactory.fromDDL(ddl, "x", "phy");
+
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+ capFinder.addCapabilities("phy", caps); //$NON-NLS-1$
+
+ helpPlan("select phy.convert(y, 'z') from x", metadata, null, capFinder,
+ new String[] {"SELECT phy.convert(g_0.Y, 'z') FROM phy.X AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+ }
+
@Test public void testConcat2() throws Exception {
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
12 years, 2 months
teiid SVN: r4492 - in trunk/engine/src: test/java/org/teiid/query/parser and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-10-01 10:42:22 -0400 (Mon, 01 Oct 2012)
New Revision: 4492
Modified:
trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java
trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
Log:
TEIID-2233 trimming to a single token chain
Modified: trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2012-09-30 12:57:02 UTC (rev 4491)
+++ trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2012-10-01 14:42:22 UTC (rev 4492)
@@ -22,19 +22,20 @@
package org.teiid.query.parser;
+import static org.teiid.query.parser.SQLParserConstants.*;
import static org.teiid.query.parser.TeiidSQLParserTokenManager.*;
import java.io.Reader;
import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
import org.teiid.api.exception.query.QueryParserException;
import org.teiid.connector.DataPlugin;
+import org.teiid.language.SQLConstants;
import org.teiid.metadata.DuplicateRecordException;
import org.teiid.metadata.FunctionMethod;
import org.teiid.metadata.MetadataFactory;
@@ -210,17 +211,23 @@
pe.currentToken = parser.token;
}
}
- QueryParserException qpe = new QueryParserException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31100, getMessage(pe, 1, 10)));
+ QueryParserException qpe = new QueryParserException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31100, getMessage(pe, 10)));
qpe.setParseException(pe);
return qpe;
}
- public String getMessage(ParseException pe, int maxTokenSequence, int maxExpansions) {
+ /**
+ * The default JavaCC message is not very good. This method produces a much more readable result.
+ * @param pe
+ * @param maxExpansions
+ * @return
+ */
+ public String getMessage(ParseException pe, int maxExpansions) {
if (!pe.specialConstructor) {
if (pe.currentToken == null) {
return pe.getMessage();
}
- StringBuilder sb = encountered(pe, 1);
+ StringBuilder sb = encountered(pe, pe.currentToken.next!=null?1:0);
if (pe.currentToken.kind == INVALID_TOKEN) {
sb.append(QueryPlugin.Util.getString("QueryParser.lexicalError", pe.currentToken.image)); //$NON-NLS-1$
} else if (pe.currentToken.next != null && pe.currentToken.next.kind == -1) {
@@ -231,99 +238,85 @@
}
return sb.toString();
}
- StringBuffer expected = new StringBuffer();
- int[][] expectedTokenSequences = pe.expectedTokenSequences;
- String[] tokenImage = pe.tokenImage;
- String eol = pe.eol;
- Token currentToken = pe.currentToken;
- HashSet<List<Integer>> expansions = new HashSet<List<Integer>>();
- Arrays.sort(expectedTokenSequences, new Comparator<int[]>() {
- @Override
- public int compare(int[] o1, int[] o2) {
- return o2.length - o1.length;
- }
- });
- int maxSize = expectedTokenSequences[0].length;
- StringBuilder retval = encountered(pe, maxSize);
+
+ Token currentToken = pe.currentToken;
+
+ //if the next token is invalid, we wan to use a lexical message, not the sequences
if (currentToken.next.kind == INVALID_TOKEN) {
+ StringBuilder retval = encountered(pe, 1);
retval.append(QueryPlugin.Util.getString("QueryParser.lexicalError", currentToken.next.image)); //$NON-NLS-1$
return retval.toString();
}
- for (int i = 0; i < expectedTokenSequences.length; i++) {
- boolean truncateStart = expectedTokenSequences[i].length == maxSize && maxSize > 1 && maxSize > maxTokenSequence;
- int start = 0;
- if (truncateStart) {
- start = expectedTokenSequences[i].length - maxTokenSequence;
+
+ //find the longest match chain an all possible end tokens
+ int[][] expectedTokenSequences = pe.expectedTokenSequences;
+ int[] ex = null;
+ Set<Integer> last = new TreeSet<Integer>();
+ outer : for (int i = 0; i < expectedTokenSequences.length; i++) {
+ if (ex == null || expectedTokenSequences[i].length > ex.length) {
+ ex = expectedTokenSequences[i];
+ last.clear();
+ } else if (expectedTokenSequences[i].length < ex.length) {
+ continue;
+ } else {
+ for (int j = 0; j < ex.length -1; j++) {
+ if (ex[j] != expectedTokenSequences[i][j]) {
+ continue outer; //TODO : not sure how to handle this case
+ }
+ }
}
- List<Integer> expansion = new ArrayList<Integer>(Math.min(maxTokenSequence, expectedTokenSequences[i].length));
- for (int j = start; j < start+maxTokenSequence; j++) {
- expansion.add(expectedTokenSequences[i][j]);
- }
- if (!expansions.add(expansion) || (!truncateStart && expectedTokenSequences[i][start] == currentToken.next.kind)) {
+ last.add(expectedTokenSequences[i][expectedTokenSequences[i].length-1]);
+ }
+ if (ex == null) {
+ return pe.getMessage(); //shouldn't happen
+ }
+
+ StringBuilder retval = encountered(pe, ex.length);
+
+ //output the expected tokens condensing the id/non-reserved
+ retval.append("Was expecting: "); //$NON-NLS-1$
+ boolean id = last.contains(SQLParserConstants.ID);
+ int count = 0;
+ for (Integer t : last) {
+ String img = tokenImage[t];
+ if (id && img.startsWith("\"") //$NON-NLS-1$
+ && Character.isLetter(img.charAt(1))
+ && !SQLConstants.isReservedWord(img.substring(1, img.length()-1))) {
continue;
}
- if (expansions.size() > maxExpansions) {
- expected.append("...").append(eol).append(" "); //$NON-NLS-1$ //$NON-NLS-2$
- break;
+ if (count > 0) {
+ retval.append(" | "); //$NON-NLS-1$
}
- if (truncateStart) {
- expected.append("... "); //$NON-NLS-1$
+ count++;
+ if (t == SQLParserConstants.ID) {
+ retval.append("id"); //$NON-NLS-1$
+ } else {
+ retval.append(img);
}
- int j = start;
- for (; j < expectedTokenSequences[i].length && j < start+maxTokenSequence; j++) {
- expected.append(tokenImage[expectedTokenSequences[i][j]])
- .append(" "); //$NON-NLS-1$
+ if (count == maxExpansions) {
+ retval.append(" ..."); //$NON-NLS-1$
+ break;
}
- if (j < expectedTokenSequences[i].length) {
- expected.append("..."); //$NON-NLS-1$
- }
- expected.append(eol).append(" "); //$NON-NLS-1$
}
- if (expansions.size() == 1) {
- retval.append("Was expecting:" + eol + " "); //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- retval.append("Was expecting one of:" + eol + " "); //$NON-NLS-1$ //$NON-NLS-2$
- }
- retval.append(expected.toString());
return retval.toString();
}
- private StringBuilder encountered(ParseException pe, int maxSize) {
+ private StringBuilder encountered(ParseException pe, int offset) {
StringBuilder retval = new StringBuilder("Encountered \""); //$NON-NLS-1$
Token currentToken = pe.currentToken;
+ for (int i = 1; i < offset; i++) {
+ //TODO: for large offsets we don't have to call findPreceeding
+ currentToken = currentToken.next;
+ }
List<Token> preceeding = findPreceeding(currentToken, 2);
- if (!preceeding.isEmpty()) {
- addTokenSequence(preceeding.size() + 1, retval, preceeding.get(0));
+ if (offset > 0 && !preceeding.isEmpty()) {
+ addTokenSequence(preceeding.size() + 1, retval, null, preceeding.get(0), false);
} else {
- addTokenSequence(1, retval, currentToken);
+ addTokenSequence(1, retval, null, currentToken, offset==0);
}
- if (currentToken.next != null) {
- boolean space = true;
- if (currentToken.next.kind == INVALID_TOKEN) {
- maxSize = 1;
- space = currentToken.endColumn + 1 != currentToken.next.beginColumn;
- }
- if (space) {
- retval.append(" "); //$NON-NLS-1$
- }
- retval.append("[*]"); //$NON-NLS-1$
- Token last = addTokenSequence(maxSize, retval, currentToken.next);
- if (last.kind != 0) {
- retval.append("[*]"); //$NON-NLS-1$
- if (last.next == null) {
- this.parser.getNextToken();
- }
- if (last.next != null) {
- if (!space) {
- space = last.endColumn + 1 != last.next.beginColumn;
- }
- if (space) {
- retval.append(" "); //$NON-NLS-1$
- }
- addTokenSequence(1, retval, last.next);
- }
- }
- currentToken = currentToken.next;
+ if (currentToken.next != null && offset>0) {
+ addTokenSequence(3, retval, currentToken, currentToken.next, true);
+ currentToken = currentToken.next; //move to the error token
}
retval.append("\" at line ").append(currentToken.beginLine).append(", column ").append(currentToken.beginColumn); //$NON-NLS-1$ //$NON-NLS-2$
retval.append(".").append(pe.eol); //$NON-NLS-1$
@@ -352,17 +345,26 @@
}
private Token addTokenSequence(int maxSize, StringBuilder retval,
- Token tok) {
- Token last = tok;
+ Token last, Token tok, boolean highlight) {
for (int i = 0; i < maxSize && tok != null; i++) {
- if (i != 0)
+ if (last != null && last.endColumn + 1 != tok.beginColumn && tok.kind != SQLParserConstants.EOF) {
retval.append(" "); //$NON-NLS-1$
- if (tok.kind == 0) {
- retval.append(SQLParserConstants.tokenImage[0]);
- return tok;
}
last = tok;
- add_escapes(tok.image, retval);
+ if (i == 0 && highlight) {
+ retval.append("[*]"); //$NON-NLS-1$
+ }
+ if (tok.image != null && !tok.image.isEmpty()) {
+ add_escapes(tok.image, retval);
+ if (i == 0 && highlight) {
+ retval.append("[*]"); //$NON-NLS-1$
+ }
+ }
+ while (tok.next == null) {
+ if (this.parser.getNextToken() == null) {
+ break;
+ }
+ }
tok = tok.next;
}
return last;
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java 2012-09-30 12:57:02 UTC (rev 4491)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java 2012-10-01 14:42:22 UTC (rev 4492)
@@ -29,7 +29,6 @@
import org.junit.Test;
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;
-import org.teiid.api.exception.query.QueryParserException;
import org.teiid.metadata.*;
import org.teiid.metadata.BaseColumn.NullType;
import org.teiid.query.metadata.MetadataValidator;
@@ -651,7 +650,7 @@
assertEquals("http://teiid.org", mf.getNamespaces().get("teiid"));
}
- public static MetadataFactory helpParse(String ddl, String model) throws QueryParserException {
+ public static MetadataFactory helpParse(String ddl, String model) {
MetadataFactory mf = new MetadataFactory(null, 1, model, getDataTypes(), new Properties(), null);
QueryParser.getQueryParser().parseDDL(mf, ddl);
return mf;
@@ -667,4 +666,13 @@
assertEquals("{http://x}z", SQLParserUtil.resolvePropertyKey(mf, "x:z"));
assertEquals("y:z", SQLParserUtil.resolvePropertyKey(mf, "y:z"));
}
+
+ @Test public void testCreateError() {
+ try {
+ helpParse("CREATE foreign FUNCTION convert(msg integer, type varchar) RETURNS varchar", "x");
+ fail();
+ } catch (org.teiid.metadata.ParseException e) {
+ assertEquals("TEIID30386 org.teiid.api.exception.query.QueryParserException: TEIID31100 Parsing error: Encountered \"CREATE foreign FUNCTION [*]convert[*](msg\" at line 1, column 25.\nWas expecting: id", e.getMessage());
+ }
+ }
}
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2012-09-30 12:57:02 UTC (rev 4491)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2012-10-01 14:42:22 UTC (rev 4492)
@@ -2649,7 +2649,7 @@
}
@Test public void testLikeWithEscapeException(){
- helpException("SELECT a from db.g where b like '#String' escape '#1'", "TEIID31100 Parsing error: Encountered \"like '#String' escape [*]'#1'[*] <EOF>\" at line 1, column 50.\nTEIID30398 LIKE/SIMILAR TO ESCAPE value must be a single character: [#1]."); //$NON-NLS-1$ //$NON-NLS-2$
+ helpException("SELECT a from db.g where b like '#String' escape '#1'", "TEIID31100 Parsing error: Encountered \"like '#String' escape [*]'#1'[*]\" at line 1, column 50.\nTEIID30398 LIKE/SIMILAR TO ESCAPE value must be a single character: [#1]."); //$NON-NLS-1$ //$NON-NLS-2$
}
/** SELECT "date"."time" from db.g */
@@ -2696,15 +2696,15 @@
/** SELECT xx.yy%.a from xx.yy */
@Test public void testFailsWildcardInSelect(){
- helpException("SELECT xx.yy%.a from xx.yy", "TEIID31100 Parsing error: Encountered \"SELECT xx.yy[*]%[*].\" at line 1, column 13.\nLexical error. Character is not a valid token: % "); //$NON-NLS-1$
+ helpException("SELECT xx.yy%.a from xx.yy", "TEIID31100 Parsing error: Encountered \"SELECT xx.yy[*]%[*].a\" at line 1, column 13.\nLexical error. Character is not a valid token: % "); //$NON-NLS-1$
}
@Test public void testFailsWildcardInSelect1(){
- helpException("SELECT % from xx.yy", "TEIID31100 Parsing error: Encountered \"SELECT [*]%[*] from\" at line 1, column 8.\nLexical error. Character is not a valid token: % "); //$NON-NLS-1$
+ helpException("SELECT % from xx.yy", "TEIID31100 Parsing error: Encountered \"SELECT [*]%[*] from xx.yy\" at line 1, column 8.\nLexical error. Character is not a valid token: % "); //$NON-NLS-1$
}
@Test public void testInvalidToken(){
- helpException("%", "");
+ helpException("%", "TEIID31100 Parsing error: Encountered \"[*]%[*]\" at line 1, column 1.\nLexical error. Character is not a valid token: % ");
}
/** SELECT a or b from g */
@@ -3244,7 +3244,7 @@
//using clause should use short names
@Test public void testDynamicCommandStatement3(){
- helpException("create virtual procedure begin execute string z as a1 string, a2 integer into #g using variables.x=variables.y; end", "TEIID31100 Parsing error: Encountered \"into #g using [*]variables.x[*] =\" at line 1, column 88.\nInvalid simple identifier format: [variables.x]"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpException("create virtual procedure begin execute string z as a1 string, a2 integer into #g using variables.x=variables.y; end", "TEIID31100 Parsing error: Encountered \"into #g using [*]variables.x[*]=variables.y\" at line 1, column 88.\nInvalid simple identifier format: [variables.x]"); //$NON-NLS-1$ //$NON-NLS-2$
}
//into clause requires as clause
@@ -4795,7 +4795,7 @@
}
@Test public void testCreateTempTable7() {
- helpException("Create local TEMPORARY table tempTable (c1.x boolean, c2 byte)" ,"TEIID31100 Parsing error: Encountered \"table tempTable ( [*]c1.x[*] boolean\" at line 1, column 41.\nInvalid simple identifier format: [c1.x]"); //$NON-NLS-1$ //$NON-NLS-2$
+ helpException("Create local TEMPORARY table tempTable (c1.x boolean, c2 byte)" ,"TEIID31100 Parsing error: Encountered \"table tempTable ([*]c1.x[*] boolean,\" at line 1, column 41.\nInvalid simple identifier format: [c1.x]"); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testCreateTempTableWithPrimaryKey() {
@@ -4841,7 +4841,7 @@
@Test public void testBadAlias() {
String sql = "select a as a.x from foo"; //$NON-NLS-1$
- helpException(sql, "TEIID31100 Parsing error: Encountered \"select a as [*]a.x[*] from\" at line 1, column 13.\nInvalid alias format: [a.x]"); //$NON-NLS-1$
+ helpException(sql, "TEIID31100 Parsing error: Encountered \"select a as [*]a.x[*] from foo\" at line 1, column 13.\nInvalid alias format: [a.x]"); //$NON-NLS-1$
}
@Test public void testNameSpacedFunctionName() {
12 years, 2 months