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;
}