teiid SVN: r4195 - in trunk: admin/src/main/java/org/teiid/adminapi/impl and 11 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2012-06-21 15:07:57 -0400 (Thu, 21 Jun 2012)
New Revision: 4195
Modified:
trunk/admin/src/main/java/org/teiid/adminapi/Admin.java
trunk/admin/src/main/java/org/teiid/adminapi/AdminFactory.java
trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java
trunk/common-core/src/main/java/org/teiid/core/util/FileUtils.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java
trunk/engine/src/main/java/org/teiid/query/metadata/NativeMetadataRepository.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidServiceNames.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
trunk/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidConfiguration.java
trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataRepository.java
trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java
trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java
trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestDeployment.java
trunk/test-integration/common/src/test/java/org/teiid/arquillian/SampleExecutionFactory.java
Log:
TEIID-1328: adding "restart" option for the VDB, with ability to delete the cached metadata from previous deployment.
Modified: trunk/admin/src/main/java/org/teiid/adminapi/Admin.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/Admin.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/admin/src/main/java/org/teiid/adminapi/Admin.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -90,6 +90,16 @@
* @return
*/
VDB getVDB(String vdbName, int vdbVersion) throws AdminException;
+
+ /**
+ * Restart the VDB. This issues reload of the metadata.
+ * @param vdbName
+ * @param vbdVersion
+ * @param models names for which metadata needs to be reloaded, if null or not supplied all models reloaded
+ * @throws AdminException
+ * @return
+ */
+ void restartVDB(String vdbName, int vdbVersion, String... models) throws AdminException;
/**
* Get the translators that are available in the configuration
Modified: trunk/admin/src/main/java/org/teiid/adminapi/AdminFactory.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/AdminFactory.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/admin/src/main/java/org/teiid/adminapi/AdminFactory.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -1301,6 +1301,42 @@
} catch (Exception e) {
throw new AdminProcessingException(AdminPlugin.Event.TEIID70050, e);
}
- }
+ }
+
+ @Override
+ public void restartVDB(String vdbName, int vdbVersion, String... models) throws AdminException {
+ ModelNode request = null;
+ String modelNames = null;
+
+ if (models != null && models.length > 0) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < models.length-1; i++) {
+ sb.append(models[i]).append(",");
+ }
+ sb.append(models[models.length-1]);
+ modelNames = sb.toString();
+ }
+
+ if (modelNames != null) {
+ request = buildRequest("teiid", "restart-vdb",
+ "vdb-name", vdbName,
+ "vdb-version", String.valueOf(vdbVersion),
+ "model-names", modelNames);//$NON-NLS-1$ //$NON-NLS-2$
+ }
+ else {
+ request = buildRequest("teiid", "restart-vdb",
+ "vdb-name", vdbName,
+ "vdb-version", String.valueOf(vdbVersion));//$NON-NLS-1$
+ }
+
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(AdminPlugin.Event.TEIID70045, Util.getFailureDescription(outcome));
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(AdminPlugin.Event.TEIID70046, e);
+ }
+ }
}
}
Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -83,9 +83,6 @@
public synchronized void setStatus(Status s) {
this.notifyAll();
- if (this.status == Status.REMOVED) {
- return;
- }
this.status = s;
}
Modified: trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java
===================================================================
--- trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -334,6 +334,15 @@
return getAdmin().getDataSourceTemplateNames();
}
+ @Doc(text = "Restart the VDB")
+ public static void restartVDB(
+ @Doc(text = "vdb name") String vdbName,
+ @Doc(text = "vdb version") int vdbVersion,
+ @Doc(text = "models") String... models)
+ throws AdminException {
+ getAdmin().restartVDB(vdbName, vdbVersion, models);
+ }
+
@Doc(text = "Get the current org.teiid.adminapi.Admin instance for direct use. Note: Used for advanced usecases to bypass AdminShell methods")
public static Admin getAdmin() {
if (internalAdmin == null) {
Modified: trunk/common-core/src/main/java/org/teiid/core/util/FileUtils.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/FileUtils.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/common-core/src/main/java/org/teiid/core/util/FileUtils.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -766,8 +766,11 @@
}
-
-
+ public static void remove(File file) {
+ if (file.exists()) {
+ file.delete();
+ }
+ }
public static void remove(String filePath) throws IOException {
File file = new File(filePath);
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -197,8 +197,10 @@
LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] {this.requestMsg.getAtomicRequestID(), "Processing NEW request:", this.requestMsg.getCommand()}); //$NON-NLS-1$
try {
- this.connectionFactory = this.manager.getConnectionFactory();
- this.connection = this.connector.getConnection(this.connectionFactory, securityContext);
+ if (this.connector.isSourceRequired()) {
+ this.connectionFactory = this.manager.getConnectionFactory();
+ this.connection = this.connector.getConnection(this.connectionFactory, securityContext);
+ }
Object unwrapped = null;
if (connection instanceof WrappedConnection) {
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/NativeMetadataRepository.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/NativeMetadataRepository.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/NativeMetadataRepository.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -43,7 +43,7 @@
throw new TranslatorException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30591, factory.getName()));
}
- if (connectionFactory == null) {
+ if (connectionFactory == null && executionFactory.isSourceRequired()) {
throw new TranslatorException(QueryPlugin.Event.TEIID31097, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31097));
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -106,6 +106,10 @@
String dirName = baseDirectory(vdb.getName()+"_"+vdb.getVersion()); //$NON-NLS-1$
FileUtils.removeDirectoryAndChildren(new File(dirName));
}
+
+ public void removeAttachment(File file) {
+ FileUtils.remove(file);
+ }
private String baseDirectory(String fileName) {
String dirName = this.storagePath + File.separator + fileName + File.separator;
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -35,6 +35,7 @@
public static final String SOURCE_NAME = "source-name"; //$NON-NLS-1$
public static final String DS_NAME = "ds-name"; //$NON-NLS-1$
public static final String RAR_NAME = "rar-name"; //$NON-NLS-1$
+ public static final String MODEL_NAMES = "model-names"; //$NON-NLS-1$
public static final String SOURCE_VDBNAME = "source-vdb-name";//$NON-NLS-1$
public static final String SOURCE_VDBVERSION = "source-vdb-version";//$NON-NLS-1$
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -130,6 +130,7 @@
new AddDataRole().register(teiidSubsystem);
new RemoveDataRole().register(teiidSubsystem);
new AddAnyAuthenticatedDataRole().register(teiidSubsystem);
+ new RestartVDB().register(teiidSubsystem);
new AssignDataSource().register(teiidSubsystem);
new ChangeVDBConnectionType().register(teiidSubsystem);
new RemoveAnyAuthenticatedDataRole().register(teiidSubsystem);
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -1158,6 +1158,40 @@
}
}
+class RestartVDB extends VDBOperations {
+
+ public RestartVDB() {
+ super("restart-vdb"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void executeOperation(OperationContext context, RuntimeVDB vdb, ModelNode operation) throws OperationFailedException {
+ List<String> models = new ArrayList<String>();
+ if (operation.hasDefined(OperationsConstants.MODEL_NAMES)) {
+ String modelNames = operation.get(OperationsConstants.MODEL_NAMES).asString();
+ for (String model:modelNames.split(",")) { //$NON-NLS-1$
+ models.add(model.trim());
+ }
+ }
+
+ try {
+ vdb.restart(models);
+ } catch (AdminProcessingException e) {
+ throw new OperationFailedException(new ModelNode().set(e.getMessage()));
+ }
+ }
+
+ @Override
+ protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
+ super.describeParameters(operationNode, bundle);
+
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.MODEL_NAMES, TYPE).set(ModelType.STRING);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.MODEL_NAMES, REQUIRED).set(false);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.MODEL_NAMES, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.MODEL_NAMES));
+ operationNode.get(REPLY_PROPERTIES).setEmptyObject();
+ }
+}
+
class AssignDataSource extends VDBOperations {
public AssignDataSource() {
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidServiceNames.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidServiceNames.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidServiceNames.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -38,6 +38,7 @@
public static ServiceName AUTHORIZATION_VALIDATOR = ServiceName.JBOSS.append("teiid", "authorization-validator");//$NON-NLS-1$ //$NON-NLS-2$
private static ServiceName VDB_SVC_BASE = ServiceName.JBOSS.append("teiid", "vdb"); //$NON-NLS-1$ //$NON-NLS-2$
private static ServiceName VDB_FINISHED_SVC_BASE = ServiceName.JBOSS.append("teiid", "vdb-finished"); //$NON-NLS-1$ //$NON-NLS-2$
+ private static ServiceName VDB_SWITCH_SVC_BASE = ServiceName.JBOSS.append("teiid", "switch"); //$NON-NLS-1$ //$NON-NLS-2$
public static ServiceName OBJECT_SERIALIZER = ServiceName.JBOSS.append("teiid", "object-serializer"); //$NON-NLS-1$ //$NON-NLS-2$
public static ServiceName CACHE_RESULTSET = ServiceName.JBOSS.append("teiid", "cache", "resultset"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
public static ServiceName CACHE_PREPAREDPLAN = ServiceName.JBOSS.append("teiid", "cache", "prepared-plan"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -58,6 +59,10 @@
return VDB_FINISHED_SVC_BASE.append(vdbName, String.valueOf(version));
}
+ public static ServiceName vdbSwitchServiceName(String vdbName, int version) {
+ return VDB_SWITCH_SVC_BASE.append(vdbName, String.valueOf(version));
+ }
+
public static ServiceName executorServiceName(String poolName) {
return ServiceName.JBOSS.append("thread", "executor", poolName); //$NON-NLS-1$ //$NON-NLS-2$
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -23,25 +23,18 @@
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
+import java.util.concurrent.TimeUnit;
import org.jboss.as.naming.deployment.ContextNames;
-import org.jboss.as.server.deployment.Attachments;
-import org.jboss.as.server.deployment.DeploymentPhaseContext;
-import org.jboss.as.server.deployment.DeploymentUnit;
-import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
-import org.jboss.as.server.deployment.DeploymentUnitProcessor;
+import org.jboss.as.server.deployment.*;
import org.jboss.modules.Module;
-import org.jboss.msc.service.Service;
-import org.jboss.msc.service.ServiceBuilder;
-import org.jboss.msc.service.ServiceController;
-import org.jboss.msc.service.ServiceName;
-import org.jboss.msc.service.StartContext;
-import org.jboss.msc.service.StartException;
-import org.jboss.msc.service.StopContext;
+import org.jboss.msc.service.*;
import org.jboss.msc.service.ServiceBuilder.DependencyType;
import org.jboss.msc.service.ServiceController.Mode;
import org.jboss.msc.service.ServiceController.State;
+import org.jboss.msc.value.InjectedValue;
import org.teiid.adminapi.Model;
import org.teiid.adminapi.Translator;
import org.teiid.adminapi.VDBImport;
@@ -139,10 +132,11 @@
visibilityMap = indexFactory.getEntriesPlusVisibilities();
}
// build a VDB service
- VDBService vdb = new VDBService(deployment, visibilityMap);
+ final VDBService vdb = new VDBService(deployment, visibilityMap);
if (indexRepo != null) {
vdb.addMetadataRepository("index", indexRepo); //$NON-NLS-1$
}
+
final ServiceBuilder<RuntimeVDB> vdbService = context.getServiceTarget().addService(TeiidServiceNames.vdbServiceName(deployment.getName(), deployment.getVersion()), vdb);
// add dependencies to data-sources
@@ -173,17 +167,71 @@
}
}
+ ServiceName vdbSwitchServiceName = TeiidServiceNames.vdbSwitchServiceName(deployment.getName(), deployment.getVersion());
vdbService.addDependency(TeiidServiceNames.VDB_REPO, VDBRepository.class, vdb.vdbRepositoryInjector);
vdbService.addDependency(TeiidServiceNames.TRANSLATOR_REPO, TranslatorRepository.class, vdb.translatorRepositoryInjector);
vdbService.addDependency(TeiidServiceNames.executorServiceName(this.asyncThreadPoolName), Executor.class, vdb.executorInjector);
vdbService.addDependency(TeiidServiceNames.OBJECT_SERIALIZER, ObjectSerializer.class, vdb.serializerInjector);
vdbService.addDependency(TeiidServiceNames.BUFFER_MGR, BufferManager.class, vdb.bufferManagerInjector);
vdbService.addDependency(TeiidServiceNames.VDB_STATUS_CHECKER, VDBStatusChecker.class, vdb.vdbStatusCheckInjector);
+ vdbService.addDependency(vdbSwitchServiceName, CountDownLatch.class, new InjectedValue<CountDownLatch>());
+ vdbService.addDependency(DependencyType.OPTIONAL, TeiidServiceNames.OBJECT_REPLICATOR, ObjectReplicator.class, vdb.objectReplicatorInjector);
- vdbService.addDependency(DependencyType.OPTIONAL, TeiidServiceNames.OBJECT_REPLICATOR, ObjectReplicator.class, vdb.objectReplicatorInjector);
+ // VDB restart switch, control the vdbservice by adding removing the switch service. If you
+ // remove the service by setting status remove, there is no way start it back up if vdbservice used alone
+ installVDBSwitchService(context.getServiceTarget(), vdbSwitchServiceName);
+
+ vdbService.addListener(new AbstractServiceListener<Object>() {
+ @Override
+ public void transition(final ServiceController controller, final ServiceController.Transition transition) {
+ if (transition.equals(ServiceController.Transition.DOWN_to_WAITING)) {
+ RuntimeVDB runtimeVDB = RuntimeVDB.class.cast(controller.getValue());
+ if (runtimeVDB != null && runtimeVDB.isRestartInProgress()) {
+ ServiceName vdbSwitchServiceName = TeiidServiceNames.vdbSwitchServiceName(deployment.getName(), deployment.getVersion());
+ ServiceController<?> switchSvc = controller.getServiceContainer().getService(vdbSwitchServiceName);
+ if (switchSvc != null) {
+ CountDownLatch latch = CountDownLatch.class.cast(switchSvc.getValue());
+ try {
+ latch.await(5, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ // todo:log it?
+ }
+ }
+ installVDBSwitchService(controller.getServiceContainer(), vdbSwitchServiceName);
+ }
+ }
+ }
+ });
vdbService.setInitialMode(Mode.PASSIVE).install();
}
+ private void installVDBSwitchService(final ServiceTarget serviceTarget, ServiceName vdbSwitchServiceName) {
+ // install switch service now.
+ ServiceBuilder<CountDownLatch> svc = serviceTarget.addService(vdbSwitchServiceName, new Service<CountDownLatch>() {
+ private CountDownLatch latch = new CountDownLatch(1);
+ @Override
+ public CountDownLatch getValue() throws IllegalStateException,IllegalArgumentException {
+ return this.latch;
+ }
+ @Override
+ public void start(StartContext context) throws StartException {
+ }
+ @Override
+ public void stop(StopContext context) {
+ }
+ });
+ svc.addListener(new AbstractServiceListener<Object>() {
+ @Override
+ public void transition(final ServiceController controller, final ServiceController.Transition transition) {
+ if (transition.equals(ServiceController.Transition.REMOVING_to_REMOVED)) {
+ CountDownLatch latch = CountDownLatch.class.cast(controller.getValue());
+ latch.countDown();
+ }
+ }
+ });
+ svc.install();
+ }
+
private void dataSourceDependencies(VDBMetaData deployment, DependentServices svcListener) {
for (ModelMetaData model:deployment.getModelMetaDatas().values()) {
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -24,15 +24,7 @@
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.IdentityHashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceLoader;
-import java.util.Set;
+import java.util.*;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
@@ -42,13 +34,7 @@
import org.jboss.modules.ModuleIdentifier;
import org.jboss.modules.ModuleLoadException;
import org.jboss.modules.ModuleLoader;
-import org.jboss.msc.service.Service;
-import org.jboss.msc.service.ServiceBuilder;
-import org.jboss.msc.service.ServiceContainer;
-import org.jboss.msc.service.ServiceController;
-import org.jboss.msc.service.StartContext;
-import org.jboss.msc.service.StartException;
-import org.jboss.msc.service.StopContext;
+import org.jboss.msc.service.*;
import org.jboss.msc.value.InjectedValue;
import org.teiid.adminapi.AdminProcessingException;
import org.teiid.adminapi.Translator;
@@ -58,18 +44,11 @@
import org.teiid.adminapi.impl.VDBTranslatorMetaData;
import org.teiid.common.buffer.BufferManager;
import org.teiid.core.TeiidException;
-import org.teiid.deployers.CompositeVDB;
-import org.teiid.deployers.RuntimeVDB;
-import org.teiid.deployers.TranslatorUtil;
-import org.teiid.deployers.UDFMetaData;
-import org.teiid.deployers.VDBLifeCycleListener;
-import org.teiid.deployers.VDBRepository;
-import org.teiid.deployers.VDBStatusChecker;
-import org.teiid.deployers.VirtualDatabaseException;
+import org.teiid.deployers.*;
import org.teiid.dqp.internal.datamgr.ConnectorManager;
import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
+import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException;
import org.teiid.dqp.internal.datamgr.TranslatorRepository;
-import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.Datatype;
@@ -185,10 +164,10 @@
throw new StartException(e);
}
- this.runtimeVDB = buildRuntimeVDB(this.vdb);
+ this.runtimeVDB = buildRuntimeVDB(this.vdb, context.getController().getServiceContainer());
}
- private RuntimeVDB buildRuntimeVDB(VDBMetaData vdbMetadata) {
+ private RuntimeVDB buildRuntimeVDB(final VDBMetaData vdbMetadata, final ServiceContainer serviceContainer) {
RuntimeVDB.VDBModificationListener modificationListener = new RuntimeVDB.VDBModificationListener() {
@Override
public void dataRoleChanged(String policyName) throws AdminProcessingException {
@@ -202,6 +181,23 @@
public void dataSourceChanged(String modelName, String sourceName,String translatorName, String dsName) throws AdminProcessingException {
save();
}
+ @Override
+ public void onRestart(List<String> modelNames) {
+ ServiceController<?> switchSvc = serviceContainer.getService(TeiidServiceNames.vdbSwitchServiceName(vdbMetadata.getName(), vdbMetadata.getVersion()));
+ if (switchSvc != null) {
+ if (!modelNames.isEmpty()) {
+ for (String model:modelNames) {
+ deleteModelCache(model);
+ }
+ }
+ else {
+ for (String model:vdbMetadata.getModelMetaDatas().keySet()) {
+ deleteModelCache(model);
+ }
+ }
+ switchSvc.setMode(ServiceController.Mode.REMOVE);
+ }
+ }
};
return new RuntimeVDB(vdbMetadata, modificationListener) {
protected VDBStatusChecker getVDBStatusChecker() {
@@ -209,6 +205,19 @@
}
};
}
+
+ Service<Void> createVoidService() {
+ return new Service<Void>() {
+ @Override
+ public Void getValue() throws IllegalStateException, IllegalArgumentException {
+ return null;
+ }
+ @Override
+ public void start(StartContext sc)throws StartException {}
+ @Override
+ public void stop(StopContext sc) {}
+ };
+ }
private ServiceBuilder<Void> addVDBFinishedService(StartContext context) {
ServiceContainer serviceContainer = context.getController().getServiceContainer();
@@ -216,28 +225,15 @@
if (controller != null) {
controller.setMode(ServiceController.Mode.REMOVE);
}
- return serviceContainer.addService(TeiidServiceNames.vdbFinishedServiceName(vdb.getName(), vdb.getVersion()), new Service<Void>() {
- @Override
- public Void getValue() throws IllegalStateException,
- IllegalArgumentException {
- return null;
- }
-
- @Override
- public void start(StartContext sc)
- throws StartException {
-
- }
-
- @Override
- public void stop(StopContext sc) {
-
- }
- });
+ return serviceContainer.addService(TeiidServiceNames.vdbFinishedServiceName(vdb.getName(), vdb.getVersion()), createVoidService());
}
@Override
public void stop(StopContext context) {
+ ServiceController<?> switchSvc = context.getController().getServiceContainer().getService(TeiidServiceNames.vdbSwitchServiceName(vdb.getName(), vdb.getVersion()));
+ if (switchSvc != null) {
+ switchSvc.setMode(ServiceController.Mode.REMOVE);
+ }
// stop object replication
if (this.objectReplicatorInjector.getValue() != null) {
GlobalTableStore gts = vdb.getAttachment(GlobalTableStore.class);
@@ -248,7 +244,7 @@
final ServiceController<?> controller = context.getController().getServiceContainer().getService(TeiidServiceNames.vdbFinishedServiceName(vdb.getName(), vdb.getVersion()));
if (controller != null) {
controller.setMode(ServiceController.Mode.REMOVE);
- }
+ }
LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50026, this.vdb));
}
@@ -347,8 +343,12 @@
try {
ConnectorManager cm = getConnectorManager(model, cmr);
- ef = ((cm == null)?null:cm.getExecutionFactory());
- cf = ((cm == null)?null:cm.getConnectionFactory());
+ if (cm != null) {
+ ef = cm.getExecutionFactory();
+ if (ef.isSourceRequired()) {
+ cf = cm.getConnectionFactory();
+ }
+ }
} catch (TranslatorException e1) {
//ignore data source not availability, it may not be required.
}
@@ -413,6 +413,11 @@
}
}
}
+
+ private void deleteModelCache(String modelName) {
+ final File cachedFile = getSerializer().buildModelFile(vdb, modelName);
+ getSerializer().removeAttachment(cachedFile);
+ }
protected VDBRepository getVDBRepository() {
return vdbRepositoryInjector.getValue();
Modified: trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
===================================================================
--- trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties 2012-06-21 19:07:57 UTC (rev 4195)
@@ -208,6 +208,8 @@
source-name.missing=Parameter "source-name" is required
ds-name.missing=Parameter "ds-name" is required
model-name.missing=Parameter "model-name" is required
+model-names.missing=Parameter "model-names" is required
+model-names.describe=Provide the names of models that need to be reloaded.
connection-type.missing = Parameter "connection-type" is required. Must be one of [NONE, BY_VERSION, ANY]
rar-name.missing=Parameter "rar-name" is is required.
vdb-description.describe=vdb description
@@ -328,6 +330,12 @@
remove-data-role.mapped-role.describe=Security domain defined role name
remove-data-role.reply=void
+restart-vdb.describe=Restart the VDB, refresh any metadata
+restart-vdb.vdb-name.describe=VDB Name
+restart-vdb.vdb-version.describe=VDB Version
+restart-vdb.model-names.describe=comma separated names of the models for which the metadata needs to be reloaded
+restart-vdb.reply=void
+
list-requests-per-session.describe=Current active requests in progress in the query engine for a given session identifier
list-requests-per-session.session.describe=The session Identifier
list-requests-per-session.reply=requests for given session
Modified: trunk/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidConfiguration.java
===================================================================
--- trunk/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidConfiguration.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidConfiguration.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -202,7 +202,7 @@
Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
List<String> opNames = getList(result);
- assertEquals(38, opNames.size());
+ assertEquals(39, opNames.size());
String[] ops = { "add","add-anyauthenticated-role","add-data-role","assign-datasource",
"cache-statistics","cache-types","cancel-request","change-vdb-connection-type",
"clear-cache","describe","execute-query","get-plan","get-translator","get-vdb",
@@ -212,7 +212,7 @@
"read-children-names","read-children-resources","read-children-types",
"read-operation-description","read-operation-names","read-rar-description",
"read-resource","read-resource-description","remove-anyauthenticated-role",
- "remove-data-role","terminate-session","terminate-transaction",
+ "remove-data-role","restart-vdb","terminate-session","terminate-transaction",
"workerpool-statistics","write-attribute", };
assertEquals(Arrays.asList(ops), opNames);
}
Modified: trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataRepository.java
===================================================================
--- trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataRepository.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataRepository.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -40,8 +40,10 @@
public void loadMetadata(MetadataFactory factory, ExecutionFactory executionFactory, Object connectionFactory)
throws TranslatorException {
try {
- this.idxStore.load(factory.getName(), factory.getDataTypes() == null?null:factory.getDataTypes().values());
if (this.idxStore.getSchema(factory.getName()) == null) {
+ this.idxStore.load(factory.getName(), factory.getDataTypes() == null?null:factory.getDataTypes().values());
+ }
+ if (this.idxStore.getSchema(factory.getName()) == null) {
throw new TranslatorException(RuntimeMetadataPlugin.Util.gs(RuntimeMetadataPlugin.Event.TEIID80004, factory.getName()));
}
factory.setSchema(this.idxStore.getSchema(factory.getName()));
Modified: trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -34,11 +34,13 @@
public abstract class RuntimeVDB {
private VDBMetaData vdb;
private VDBModificationListener listener;
+ private boolean restartInProgress = false;
public interface VDBModificationListener {
void dataRoleChanged(String policyName) throws AdminProcessingException;
void connectionTypeChanged() throws AdminProcessingException;
void dataSourceChanged(String modelName, String sourceName, String translatorName, String dsName) throws AdminProcessingException;
+ void onRestart(List<String> modelNames) throws AdminProcessingException;
}
public RuntimeVDB(VDBMetaData vdb, VDBModificationListener listener) {
@@ -145,6 +147,13 @@
}
}
+ public void restart(List<String> modelNames) throws AdminProcessingException {
+ synchronized(this.vdb) {
+ this.restartInProgress = true;
+ this.listener.onRestart(modelNames);
+ }
+ }
+
private DataPolicyMetadata getPolicy(String policyName)
throws AdminProcessingException {
DataPolicyMetadata policy = vdb.getDataPolicy(policyName);
@@ -155,5 +164,9 @@
return policy;
}
+ public boolean isRestartInProgress() {
+ return this.restartInProgress;
+ }
+
protected abstract VDBStatusChecker getVDBStatusChecker();
}
Modified: trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -503,8 +503,12 @@
try {
ConnectorManager cm = getConnectorManager(model, cmr);
- ef = ((cm == null)?null:cm.getExecutionFactory());
- cf = ((cm == null)?null:cm.getConnectionFactory());
+ if (cm != null) {
+ ef = cm.getExecutionFactory();
+ if (ef.isSourceRequired()) {
+ cf = cm.getConnectionFactory();
+ }
+ }
} catch (TranslatorException e1) {
//ignore data source not availability, it may not be required.
}
Modified: trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestDeployment.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestDeployment.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestDeployment.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -24,15 +24,14 @@
import static org.junit.Assert.*;
+import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.sql.Statement;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
+import java.util.*;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ArchivePaths;
@@ -405,5 +404,54 @@
admin.deleteDataSource(deployedName);
}
-
+ @Test
+ public void testVDBRestart() throws Exception{
+ String vdbName = "test";
+ String testVDB = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
+ "<vdb name=\"test\" version=\"1\">\n" +
+ " <property name=\"UseConnectorMetadata\" value=\"cached\" />\n" +
+ " <model name=\"loopy\">\n" +
+ " <source name=\"loop\" translator-name=\"loopy\" />\n" +
+ " </model>\n" +
+ "</vdb>";
+
+ Collection<?> vdbs = admin.getVDBs();
+ assertTrue(vdbs.isEmpty());
+
+ JavaArchive jar = getLoopyArchive();
+ admin.deploy("loopy.jar", jar.as(ZipExporter.class).exportAsInputStream());
+
+ // normal load
+ admin.deploy("test-vdb.xml", new ByteArrayInputStream(testVDB.getBytes()));
+ AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);
+ int count = assertMetadataLoadCount(false, 1);
+
+ // 1st restart
+ admin.restartVDB(vdbName, 1);
+ AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);
+ count = assertMetadataLoadCount(true, count+1);
+
+ // 2nd restart
+ admin.restartVDB(vdbName, 1);
+ AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);
+ count = assertMetadataLoadCount(true, count+1);
+
+ admin.undeploy("loopy.jar");
+ }
+
+ private int assertMetadataLoadCount(boolean check, int expected) throws SQLException {
+ Connection conn = TeiidDriver.getInstance().connect("jdbc:teiid:test.1@mm://localhost:31000;user=user;password=user", null);
+ Statement stmt = conn.createStatement();
+ stmt.execute("SELECT execCount FROM Matadata");
+ ResultSet rs = stmt.getResultSet();
+ rs.next();
+ int execCount = rs.getInt(1);
+ if (check) {
+ assertEquals(expected, execCount);
+ }
+ rs.close();
+ stmt.close();
+ conn.close();
+ return execCount;
+ }
}
Modified: trunk/test-integration/common/src/test/java/org/teiid/arquillian/SampleExecutionFactory.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/arquillian/SampleExecutionFactory.java 2012-06-21 16:50:23 UTC (rev 4194)
+++ trunk/test-integration/common/src/test/java/org/teiid/arquillian/SampleExecutionFactory.java 2012-06-21 19:07:57 UTC (rev 4195)
@@ -22,13 +22,73 @@
package org.teiid.arquillian;
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.language.Command;
+import org.teiid.metadata.MetadataFactory;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.metadata.Table;
+import org.teiid.translator.*;
+import org.teiid.translator.loopback.LoopbackExecution;
import org.teiid.translator.loopback.LoopbackExecutionFactory;
@org.teiid.translator.Translator(name = "loopy")
+@SuppressWarnings("nls")
public class SampleExecutionFactory extends LoopbackExecutionFactory {
+ static int metadataloaded = 0; // use of static is bad, but we instantiate a separate translator for each vdb load
+
public SampleExecutionFactory() {
setSupportsSelectDistinct(true);
setWaitTime(10);
setRowCount(200);
}
+
+ @Override
+ public void getMetadata(MetadataFactory metadataFactory, Object conn) throws TranslatorException {
+ super.getMetadata(metadataFactory, conn);
+ metadataloaded++;
+
+ Table t = metadataFactory.addTable("Matadata");
+ metadataFactory.addColumn("execCount", "integer", t);
+ }
+
+ @Override
+ public boolean isSourceRequired() {
+ return false;
+ }
+
+ @Override
+ public Execution createExecution(Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection)
+ throws TranslatorException {
+ if (command.toString().equals("SELECT g_0.execCount FROM Matadata AS g_0")) { //$NON-NLS-1$
+ return new ResultSetExecution() {
+ boolean served = false;
+ @Override
+ public void execute() throws TranslatorException {
+
+ }
+
+ @Override
+ public void close() {
+
+ }
+
+ @Override
+ public void cancel() throws TranslatorException {
+ }
+
+ @Override
+ public List<?> next() throws TranslatorException, DataNotAvailableException {
+ if (!served) {
+ served = true;
+ return Arrays.asList(metadataloaded);
+ }
+ return null;
+ }
+ };
+ }
+ return new LoopbackExecution(command, this);
+ }
+
}
\ No newline at end of file
12 years, 6 months
teiid SVN: r4194 - trunk/runtime/src/main/java/org/teiid/deployers.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-06-21 12:50:23 -0400 (Thu, 21 Jun 2012)
New Revision: 4194
Modified:
trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java
Log:
TEIID-2062 corrections to the runtime error handling
Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2012-06-21 11:44:43 UTC (rev 4193)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2012-06-21 16:50:23 UTC (rev 4194)
@@ -294,6 +294,7 @@
}
}
}
+ validateDataSources(metadataAwareVDB);
metadataAwareVDB.setStatus(Status.ACTIVE);
LogManager.logInfo(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40003,name, version, metadataAwareVDB.getStatus()));
notifyFinished(name, version, v);
Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java 2012-06-21 11:44:43 UTC (rev 4193)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java 2012-06-21 16:50:23 UTC (rev 4194)
@@ -21,12 +21,12 @@
*/
package org.teiid.deployers;
-import java.util.LinkedList;
+import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.Executor;
import org.teiid.adminapi.AdminProcessingException;
import org.teiid.adminapi.Model;
-import org.teiid.adminapi.VDB;
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.adminapi.impl.VDBTranslatorMetaData;
@@ -83,8 +83,7 @@
boolean dsReplaced = false;
if (!cm.getConnectionName().equals(dsName)){
- String msg = RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40076, vdb.getName(), vdb.getVersion(), model.getSourceTranslatorName(sourceName), dsName);
- model.addRuntimeError(msg);
+ LogManager.logInfo(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40076, vdb.getName(), vdb.getVersion(), model.getSourceTranslatorName(sourceName), dsName));
cm = new ConnectorManager(translatorName, dsName);
cm.setExecutionFactory(ef);
cmr.addConnectorManager(sourceName, cm);
@@ -118,11 +117,8 @@
}
public void resourceAdded(String resourceName, boolean translator) {
+ List<Runnable> runnables = new ArrayList<Runnable>();
for (VDBMetaData vdb:getVDBRepository().getVDBs()) {
- if (vdb.getStatus() == VDB.Status.ACTIVE) {
- continue;
- }
- LinkedList<Runnable> runnables = new LinkedList<Runnable>();
synchronized (vdb) {
ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
@@ -152,19 +148,14 @@
}
}
- boolean valid = true;
- for (ModelMetaData model:vdb.getModelMetaDatas().values()) {
- if (model.hasRuntimeErrors()) {
- valid = false;
- break;
- }
- }
+ boolean valid = !vdb.hasErrors();
if (!runnables.isEmpty()) {
//the task themselves will set the status on completion/failure
for (Runnable runnable : runnables) {
getExecutor().execute(runnable);
}
+ runnables.clear();
} else if (valid) {
LogManager.logInfo(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40003,vdb.getName(), vdb.getVersion(), vdb.getStatus()));
}
12 years, 6 months
teiid SVN: r4193 - in trunk: runtime/src/main/java/org/teiid/odbc and 2 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-06-21 07:44:43 -0400 (Thu, 21 Jun 2012)
New Revision: 4193
Modified:
trunk/client/src/main/java/org/teiid/jdbc/StatementImpl.java
trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
trunk/runtime/src/main/java/org/teiid/transport/ODBCClientInstance.java
trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
Log:
TEIID-2080 fix for set statement handling
Modified: trunk/client/src/main/java/org/teiid/jdbc/StatementImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2012-06-20 19:49:33 UTC (rev 4192)
+++ trunk/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2012-06-21 11:44:43 UTC (rev 4193)
@@ -434,8 +434,8 @@
String value = match.group(3);
if (value == null) {
value = match.group(4);
+ value = value.substring(1, value.length() - 1);
value = StringUtil.replaceAll(value, "''", "'"); //$NON-NLS-1$ //$NON-NLS-2$
- value = value.substring(1, value.length() - 1);
}
if (match.group(1) != null) {
//payload case
Modified: trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2012-06-20 19:49:33 UTC (rev 4192)
+++ trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2012-06-21 11:44:43 UTC (rev 4193)
@@ -69,7 +69,7 @@
public class ODBCServerRemoteImpl implements ODBCServerRemote {
private static final String UNNAMED = "UNNAMED"; //$NON-NLS-1$
- private static Pattern setPattern = Pattern.compile("(SET|set)\\s+(\\w+)\\s+(TO|to)\\s+'(\\w+\\d*)'");//$NON-NLS-1$
+ private static Pattern setPattern = Pattern.compile("set\\s+(\\w+)\\s+to\\s+((?:'[^']*')+)", Pattern.DOTALL|Pattern.CASE_INSENSITIVE);//$NON-NLS-1$
private static Pattern pkPattern = Pattern.compile("select ta.attname, ia.attnum, ic.relname, n.nspname, tc.relname " +//$NON-NLS-1$
"from pg_catalog.pg_attribute ta, pg_catalog.pg_attribute ia, pg_catalog.pg_class tc, pg_catalog.pg_index i, " +//$NON-NLS-1$
@@ -603,7 +603,7 @@
return "select 63"; //$NON-NLS-1$
}
else if ((m = setPattern.matcher(sql)).matches()) {
- return "SET " + m.group(2) + " " + m.group(4); //$NON-NLS-1$ //$NON-NLS-2$
+ return "SET " + m.group(1) + " " + m.group(2); //$NON-NLS-1$ //$NON-NLS-2$
}
else if (modified.equalsIgnoreCase("BEGIN")) { //$NON-NLS-1$
return "START TRANSACTION"; //$NON-NLS-1$
@@ -693,7 +693,7 @@
}
}
- private void errorOccurred(Throwable error) {
+ public void errorOccurred(Throwable error) {
this.client.errorOccurred(error);
synchronized (this) {
this.errorOccurred = true;
Modified: trunk/runtime/src/main/java/org/teiid/transport/ODBCClientInstance.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/ODBCClientInstance.java 2012-06-20 19:49:33 UTC (rev 4192)
+++ trunk/runtime/src/main/java/org/teiid/transport/ODBCClientInstance.java 2012-06-21 11:44:43 UTC (rev 4193)
@@ -130,7 +130,7 @@
throw e.getCause();
}
} catch (Throwable e) {
- this.client.errorOccurred(e);
+ this.server.errorOccurred(e);
}
}
Modified: trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2012-06-20 19:49:33 UTC (rev 4192)
+++ trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2012-06-21 11:44:43 UTC (rev 4193)
@@ -363,4 +363,13 @@
String str = rs.getString(1);
assertTrue(str.startsWith("ProjectNode\n + Output Columns:expr1 (integer)\n + Statistics:\n 0: Node Output Rows: 1"));
}
+
+ @Test public void testSetEmptyLiteral() throws Exception {
+ Statement s = conn.createStatement();
+ assertFalse(s.execute("SET min_client_messages TO ''"));
+ assertTrue(s.execute("SHOW min_client_messages"));
+ ResultSet rs = s.getResultSet();
+ assertTrue(rs.next());
+ assertEquals("", rs.getString(1));
+ }
}
12 years, 6 months
teiid SVN: r4192 - in trunk: test-integration/common/src/test/java/org/teiid/systemmodel and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-06-20 15:49:33 -0400 (Wed, 20 Jun 2012)
New Revision: 4192
Modified:
trunk/client/src/main/java/org/teiid/jdbc/NonBlockingRowProcessor.java
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java
Log:
TEIID-2081 fix for continuous close on the client side
Modified: trunk/client/src/main/java/org/teiid/jdbc/NonBlockingRowProcessor.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/NonBlockingRowProcessor.java 2012-06-20 15:57:10 UTC (rev 4191)
+++ trunk/client/src/main/java/org/teiid/jdbc/NonBlockingRowProcessor.java 2012-06-20 19:49:33 UTC (rev 4192)
@@ -22,6 +22,7 @@
package org.teiid.jdbc;
+import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -56,6 +57,10 @@
public void run() {
while (true) {
try {
+ if (stmt.isClosed()) {
+ callback.onComplete(stmt);
+ break;
+ }
ResultsFuture<Boolean> hasNext = resultSet.submitNext();
synchronized (hasNext) {
if (!hasNext.isDone()) {
@@ -77,6 +82,7 @@
}
} catch (Exception e) {
onException(e);
+ break;
}
}
}
@@ -107,6 +113,12 @@
}
private void onException(Exception e) {
+ if (e instanceof ExecutionException) {
+ ExecutionException ee = (ExecutionException)e;
+ if (ee.getCause() instanceof Exception) {
+ e = (Exception)ee.getCause();
+ }
+ }
try {
callback.onException(stmt, e);
} catch (Exception e1) {
Modified: trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java 2012-06-20 15:57:10 UTC (rev 4191)
+++ trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java 2012-06-20 19:49:33 UTC (rev 4192)
@@ -32,7 +32,9 @@
import java.sql.Statement;
import java.sql.Types;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.teiid.client.util.ResultsFuture;
import org.teiid.core.util.UnitTestUtil;
@@ -50,6 +52,17 @@
@SuppressWarnings("nls")
public class TestSystemVirtualModel extends AbstractMMQueryTestCase {
private static final String VDB = "PartsSupplier"; //$NON-NLS-1$
+
+ private static FakeServer server;
+
+ @BeforeClass public static void setup() throws Exception {
+ server = new FakeServer(true);
+ server.deployVDB(VDB, UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb");
+ }
+
+ @AfterClass public static void teardown() throws Exception {
+ server.stop();
+ }
public TestSystemVirtualModel() {
// this is needed because the result files are generated
@@ -58,8 +71,6 @@
}
@Before public void setUp() throws Exception {
- FakeServer server = new FakeServer(true);
- server.deployVDB(VDB, UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb");
this.internalConnection = server.createConnection("jdbc:teiid:" + VDB); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -186,8 +197,8 @@
}
@Test public void testAsynch() throws Exception {
- Statement s = this.internalConnection.createStatement();
- TeiidStatement ts = s.unwrap(TeiidStatement.class);
+ Statement stmt = this.internalConnection.createStatement();
+ TeiidStatement ts = stmt.unwrap(TeiidStatement.class);
final ResultsFuture<Integer> result = new ResultsFuture<Integer>();
ts.submitExecute("select * from SYS.Schemas", new StatementCallback() {
int rowCount;
@@ -210,8 +221,8 @@
}
@Test public void testAsynchContinuous() throws Exception {
- Statement s = this.internalConnection.createStatement();
- TeiidStatement ts = s.unwrap(TeiidStatement.class);
+ Statement stmt = this.internalConnection.createStatement();
+ TeiidStatement ts = stmt.unwrap(TeiidStatement.class);
final ResultsFuture<Integer> result = new ResultsFuture<Integer>();
ts.submitExecute("select * from SYS.Schemas", new StatementCallback() {
int rowCount;
@@ -225,7 +236,7 @@
@Override
public void onException(Statement s, Exception e) {
- result.getResultsReceiver().receiveResults(rowCount);
+ result.getResultsReceiver().exceptionOccurred(e);
}
@Override
12 years, 6 months
teiid SVN: r4191 - in trunk: admin/src/main/java/org/teiid/adminapi/impl and 17 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-06-20 11:57:10 -0400 (Wed, 20 Jun 2012)
New Revision: 4191
Modified:
trunk/admin/src/main/java/org/teiid/adminapi/VDB.java
trunk/admin/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java
trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java
trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java
trunk/admin/src/test/resources/vdb-describe.txt
trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java
trunk/api/src/main/java/org/teiid/metadata/MetadataStore.java
trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java
trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/PlanExecutionNode.java
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/query/metadata/TestMetadataValidator.java
trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataStore.java
trunk/metadata/src/test/java/org/teiid/metadata/index/VDBMetadataFactory.java
trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
trunk/runtime/src/main/java/org/teiid/deployers/SystemVDBDeployer.java
trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java
trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java
trunk/runtime/src/main/java/org/teiid/runtime/RuntimePlugin.java
trunk/runtime/src/test/java/org/teiid/runtime/TestEmbeddedServer.java
trunk/test-integration/common/src/test/java/org/teiid/arquillian/AdminUtil.java
trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestDeployment.java
trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestCase3473.java
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestDynamicImportedMetaData.java
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestMMDatabaseMetaData.java
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestVDBMerge.java
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewAliasing.java
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestVirtualDocWithVirtualProc.java
Log:
TEIID-2062 allowing deployment to fail on metadata errors and other fixes
Modified: trunk/admin/src/main/java/org/teiid/adminapi/VDB.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/VDB.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/admin/src/main/java/org/teiid/adminapi/VDB.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -40,23 +40,18 @@
*/
public interface VDB extends AdminObject, DomainAware {
- public static enum Status{
- //loaded | valid
- INCOMPLETE(true), //f f
- LOADING(true), //f t
- INVALID(false), //t f
- ACTIVE(false), //t t
- REMOVED(false);
-
- private boolean loading;
- private Status(boolean loading) {
- this.loading = loading;
- }
-
- public boolean isLoading() {
- return loading;
- }};
-
+ public enum Status{
+ /**
+ * Initial state waiting for metadata to load
+ */
+ LOADING,
+ /**
+ * In the vdb repository and querable, but not necessarily valid
+ */
+ ACTIVE,
+ REMOVED
+ };
+
public enum ConnectionType {NONE, BY_VERSION, ANY}
/**
Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -159,8 +159,29 @@
public void addSourceMapping(SourceMappingMetadata source) {
this.addSourceMapping(source.getName(), source.getTranslatorName(), source.getConnectionJndiName());
- }
+ }
+ public synchronized boolean hasErrors() {
+ if (this.validationErrors == null && this.runtimeErrors == null) {
+ return false;
+ }
+ if (this.validationErrors != null) {
+ for (ValidationError error : this.validationErrors) {
+ if (error.getSeverity() == Severity.ERROR) {
+ return true;
+ }
+ }
+ }
+ if (this.runtimeErrors != null) {
+ for (ValidationError error : this.runtimeErrors) {
+ if (error.getSeverity() == Severity.ERROR) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
public synchronized List<ValidationError> getErrors(){
return getErrors(true);
}
@@ -180,7 +201,7 @@
}
public ValidationError addError(String severity, String message) {
- ValidationError ve = new ValidationError(severity, message);
+ ValidationError ve = new ValidationError(Severity.valueOf(severity), message);
addError(ve);
return ve;
}
@@ -190,7 +211,7 @@
}
public synchronized ValidationError addRuntimeError(String message) {
- ValidationError ve = new ValidationError(Severity.ERROR.name(), message);
+ ValidationError ve = new ValidationError(Severity.ERROR, message);
if (this.runtimeErrors == null) {
this.runtimeErrors = new LinkedList<ValidationError>();
}
@@ -221,12 +242,12 @@
public enum Severity {ERROR, WARNING};
protected String value;
- protected String severity;
+ protected Severity severity;
protected String path;
public ValidationError() {};
- public ValidationError(String severity, String msg) {
+ public ValidationError(Severity severity, String msg) {
this.severity = severity;
this.value = msg;
}
@@ -239,11 +260,11 @@
this.value = value;
}
- public String getSeverity() {
+ public Severity getSeverity() {
return severity;
}
- public void setSeverity(String severity) {
+ public void setSeverity(Severity severity) {
this.severity = severity;
}
Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -27,7 +27,6 @@
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.teiid.adminapi.DataPolicy;
@@ -35,6 +34,7 @@
import org.teiid.adminapi.Translator;
import org.teiid.adminapi.VDB;
import org.teiid.adminapi.impl.ModelMetaData.ValidationError;
+import org.teiid.adminapi.impl.ModelMetaData.ValidationError.Severity;
public class VDBMetaData extends AdminObjectImpl implements VDB {
@@ -78,7 +78,7 @@
}
public boolean isLoading() {
- return this.status.isLoading();
+ return this.status == Status.LOADING;
}
public synchronized void setStatus(Status s) {
@@ -107,7 +107,7 @@
return new ArrayList<Model>(this.models.values());
}
- public Map<String, ModelMetaData> getModelMetaDatas() {
+ public LinkedHashMap<String, ModelMetaData> getModelMetaDatas() {
return this.models;
}
@@ -160,7 +160,7 @@
List<ValidationError> errors = model.getErrors();
if (errors != null && !errors.isEmpty()) {
for (ValidationError m:errors) {
- if (ValidationError.Severity.valueOf(m.getSeverity()).equals(ValidationError.Severity.ERROR)) {
+ if (m.getSeverity() == Severity.ERROR) {
allErrors.add(m.getValue());
}
}
@@ -171,9 +171,18 @@
@Override
public boolean isValid() {
- return Status.ACTIVE.equals(this.status);
+ return status == Status.ACTIVE && !hasErrors();
}
-
+
+ public boolean hasErrors() {
+ for (ModelMetaData model : this.models.values()) {
+ if (model.hasErrors()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public String toString() {
return getName()+VERSION_DELIM+getVersion()+ models.values();
}
Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -37,6 +37,7 @@
import org.teiid.adminapi.VDB.Status;
import org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData;
import org.teiid.adminapi.impl.ModelMetaData.ValidationError;
+import org.teiid.adminapi.impl.ModelMetaData.ValidationError.Severity;
public class VDBMetadataMapper implements MetadataMapper<VDBMetaData> {
private static final String VDBNAME = "vdb-name"; //$NON-NLS-1$
@@ -213,9 +214,7 @@
ModelNode statusAllowed = new ModelNode();
statusAllowed.add(Status.ACTIVE.toString());
statusAllowed.add(Status.LOADING.toString());
- statusAllowed.add(Status.INVALID.toString());
statusAllowed.add(Status.REMOVED.toString());
- statusAllowed.add(Status.INCOMPLETE.toString());
addAttribute(node, STATUS, ModelType.STRING, true);
node.get(STATUS).get(ALLOWED).set(statusAllowed);
@@ -475,7 +474,7 @@
if (error.getPath() != null) {
node.get(ERROR_PATH).set(error.getPath());
}
- node.get(SEVERITY).set(error.getSeverity());
+ node.get(SEVERITY).set(error.getSeverity().name());
node.get(MESSAGE).set(error.getValue());
return node;
@@ -491,7 +490,7 @@
error.setPath(node.get(ERROR_PATH).asString());
}
if (node.has(SEVERITY)) {
- error.setSeverity(node.get(SEVERITY).asString());
+ error.setSeverity(Severity.valueOf(node.get(SEVERITY).asString()));
}
if(node.has(MESSAGE)) {
error.setValue(node.get(MESSAGE).asString());
Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -48,6 +48,7 @@
import org.teiid.adminapi.VDBImport;
import org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData;
import org.teiid.adminapi.impl.ModelMetaData.ValidationError;
+import org.teiid.adminapi.impl.ModelMetaData.ValidationError.Severity;
import org.teiid.core.types.XMLType;
import org.xml.sax.SAXException;
@@ -284,7 +285,7 @@
String msg = reader.getElementText();
String severity = validationProps.getProperty(Element.VALIDATION_SEVERITY_ATTR.getLocalName());
String path = validationProps.getProperty(Element.PATH.getLocalName());
- ValidationError ve = new ValidationError(severity, msg);
+ ValidationError ve = new ValidationError(Severity.valueOf(severity), msg);
ve.setPath(path);
model.addError(ve);
break;
@@ -521,7 +522,7 @@
// model validation errors
for (ValidationError ve:model.getErrors(false)) {
writer.writeStartElement(Element.VALIDATION_ERROR.getLocalName());
- writer.writeAttribute(Element.VALIDATION_SEVERITY_ATTR.getLocalName(), ve.getSeverity());
+ writer.writeAttribute(Element.VALIDATION_SEVERITY_ATTR.getLocalName(), ve.getSeverity().name());
if (ve.getPath() != null) {
writer.writeAttribute(Element.PATH.getLocalName(), ve.getPath());
}
Modified: trunk/admin/src/test/resources/vdb-describe.txt
===================================================================
--- trunk/admin/src/test/resources/vdb-describe.txt 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/admin/src/test/resources/vdb-describe.txt 2012-06-20 15:57:10 UTC (rev 4191)
@@ -27,9 +27,7 @@
"allowed" : [
"ACTIVE",
"LOADING",
- "INVALID",
- "REMOVED",
- "INCOMPLETE"
+ "REMOVED"
]
},
"vdb-version" : {
Modified: trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -342,7 +342,6 @@
public void mergeInto (MetadataStore store) {
store.addSchema(this.schema);
store.addDataTypes(this.dataTypes.values());
- store.addNamespaces(this.namespaces);
}
public MetadataStore asMetadataStore() {
Modified: trunk/api/src/main/java/org/teiid/metadata/MetadataStore.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/MetadataStore.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/api/src/main/java/org/teiid/metadata/MetadataStore.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -40,7 +40,6 @@
protected Map<String, Schema> schemas = new TreeMap<String, Schema>(String.CASE_INSENSITIVE_ORDER);
protected List<Schema> schemaList = new ArrayList<Schema>(); //used for a stable ordering
protected Map<String, Datatype> datatypes = new TreeMap<String, Datatype>();
- protected Map<String, String> namespaces = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
public Map<String, Schema> getSchemas() {
return schemas;
@@ -61,7 +60,7 @@
return schemaList;
}
- void addDataTypes(Collection<Datatype> types) {
+ public void addDataTypes(Collection<Datatype> types) {
if (types != null){
for (Datatype type:types) {
addDatatype(type);
@@ -77,18 +76,6 @@
return datatypes;
}
- public void addNamespace(String prefix, String uri) {
- this.namespaces.put(prefix, uri);
- }
-
- public Map<String, String> getNamespaces() {
- return this.namespaces;
- }
-
- void addNamespaces(Map<String, String> namespaces) {
- this.namespaces.putAll(namespaces);
- }
-
public void merge(MetadataStore store) {
if (store != null) {
for (Schema s:store.getSchemaList()) {
Modified: trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-06-20 15:57:10 UTC (rev 4191)
@@ -45,6 +45,7 @@
<li>DDL functions/procedures defined without the VIRTUAL keyword are by default VIRTUAL. Use the FOREIGN keyword to indicate that they are source specific.
<li>FunctionMethod.getFullName returns the proper schema, not category qualified name.
<li>VDB.getUrl has been removed.
+ <li>VDB.Status now has three states - LOADING, ACTIVE, REMOVED. To check for validity use the isValid method, rather than checking for the VALID state.
<ul>
<h4>from 7.x</h4>
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -27,10 +27,7 @@
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;
-import org.teiid.api.exception.query.QueryParserException;
-import org.teiid.api.exception.query.QueryResolverException;
-import org.teiid.api.exception.query.QueryValidatorException;
-import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
import org.teiid.language.SQLConstants;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
@@ -56,16 +53,16 @@
public class MetadataValidator {
interface MetadataRule {
- void execute(VDBMetaData vdb, MetadataStore vdbStore, ValidatorReport report);
+ void execute(VDBMetaData vdb, MetadataStore vdbStore, ValidatorReport report, MetadataValidator metadataValidator);
}
- public static ValidatorReport validate(VDBMetaData vdb, MetadataStore store) {
+ public ValidatorReport validate(VDBMetaData vdb, MetadataStore store) {
ValidatorReport report = new ValidatorReport();
if (store != null && !store.getSchemaList().isEmpty()) {
- new SourceModelArtifacts().execute(vdb, store, report);
- new ResolveQueryPlans().execute(vdb, store, report);
- new CrossSchemaResolver().execute(vdb, store, report);
- new MinimalMetadata().execute(vdb, store, report);
+ new SourceModelArtifacts().execute(vdb, store, report, this);
+ new ResolveQueryPlans().execute(vdb, store, report, this);
+ new CrossSchemaResolver().execute(vdb, store, report, this);
+ new MinimalMetadata().execute(vdb, store, report, this);
}
return report;
}
@@ -73,19 +70,19 @@
// At minimum the model must have table/view, procedure or function
static class MinimalMetadata implements MetadataRule {
@Override
- public void execute(VDBMetaData vdb, MetadataStore store, ValidatorReport report) {
- for (Schema schema:store.getSchemas().values()) {
+ public void execute(VDBMetaData vdb, MetadataStore store, ValidatorReport report, MetadataValidator metadataValidator) {
+ for (Schema schema:store.getSchemaList()) {
ModelMetaData model = vdb.getModel(schema.getName());
if (schema.getTables().isEmpty()
&& schema.getProcedures().isEmpty()
&& schema.getFunctions().isEmpty()) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31070, model.getName()));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31070, model.getName()));
}
for (Table t:schema.getTables().values()) {
if (t.getColumns() == null || t.getColumns().size() == 0) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31071, t.getName()));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31071, t.getName()));
}
}
@@ -95,7 +92,7 @@
ActivityReport<ReportItem> funcReport = new ActivityReport<ReportItem>("Translator metadata load " + model.getName()); //$NON-NLS-1$
FunctionMetadataValidator.validateFunctionMethods(schema.getFunctions().values(),report);
if(report.hasItems()) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31073, funcReport));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31073, funcReport));
}
}
}
@@ -105,32 +102,32 @@
// do not allow foreign tables, source functions in view model and vice versa
static class SourceModelArtifacts implements MetadataRule {
@Override
- public void execute(VDBMetaData vdb, MetadataStore store, ValidatorReport report) {
- for (Schema schema:store.getSchemas().values()) {
+ public void execute(VDBMetaData vdb, MetadataStore store, ValidatorReport report, MetadataValidator metadataValidator) {
+ for (Schema schema:store.getSchemaList()) {
ModelMetaData model = vdb.getModel(schema.getName());
for (Table t:schema.getTables().values()) {
if (t.isVirtual() && model.isSource()) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31074, t.getName(), model.getName()));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31074, t.getName(), model.getName()));
}
if (t.isPhysical() && !model.isSource()) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31075, t.getName(), model.getName()));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31075, t.getName(), model.getName()));
}
}
for (Procedure p:schema.getProcedures().values()) {
if (p.isVirtual() && model.isSource()) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31076, p.getName(), model.getName()));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31076, p.getName(), model.getName()));
}
if (!p.isVirtual() && !model.isSource()) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31077, p.getName(), model.getName()));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31077, p.getName(), model.getName()));
}
}
for (FunctionMethod func:schema.getFunctions().values()) {
if (func.getPushdown().equals(FunctionMethod.PushDown.MUST_PUSHDOWN) && !model.isSource()) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31078, func.getName(), model.getName()));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31078, func.getName(), model.getName()));
}
}
}
@@ -140,8 +137,8 @@
// Resolves metadata query plans to make sure they are accurate
static class ResolveQueryPlans implements MetadataRule {
@Override
- public void execute(VDBMetaData vdb, MetadataStore store, ValidatorReport report) {
- for (Schema schema:store.getSchemas().values()) {
+ public void execute(VDBMetaData vdb, MetadataStore store, ValidatorReport report, MetadataValidator metadataValidator) {
+ for (Schema schema:store.getSchemaList()) {
ModelMetaData model = vdb.getModel(schema.getName());
for (Table t:schema.getTables().values()) {
@@ -154,10 +151,10 @@
}
if (t.isVirtual()) {
if (t.getSelectTransformation() == null) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31079, t.getName(), model.getName()));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31079, t.getName(), model.getName()));
}
else {
- validate(vdb, model, t, store, report);
+ metadataValidator.validate(vdb, model, t, store, report);
}
}
}
@@ -165,10 +162,10 @@
for (Procedure p:schema.getProcedures().values()) {
if (p.isVirtual() && !p.isFunction()) {
if (p.getQueryPlan() == null) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31081, p.getName(), model.getName()));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31081, p.getName(), model.getName()));
}
else {
- validate(vdb, model, p, store, report);
+ metadataValidator.validate(vdb, model, p, store, report);
}
}
}
@@ -176,13 +173,13 @@
}
}
- private static void log(ValidatorReport report, ModelMetaData model, String msg) {
+ public void log(ValidatorReport report, ModelMetaData model, String msg) {
model.addRuntimeError(msg);
LogManager.logWarning(LogConstants.CTX_QUERY_RESOLVER, msg);
report.handleValidationError(msg);
}
- private static void validate(VDBMetaData vdb, ModelMetaData model, AbstractMetadataRecord record, MetadataStore store, ValidatorReport report) {
+ private void validate(VDBMetaData vdb, ModelMetaData model, AbstractMetadataRecord record, MetadataStore store, ValidatorReport report) {
QueryMetadataInterface metadata = vdb.getAttachment(QueryMetadataInterface.class);
metadata = new TempMetadataAdapter(metadata, new TempMetadataStore()); //TODO: optimize this
ValidatorReport resolverReport = null;
@@ -224,18 +221,12 @@
}
}
}
- } catch (QueryParserException e) {
+ } catch (TeiidException e) {
log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31080, record.getFullName(), e.getFullMessage()));
- } catch (QueryResolverException e) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31080, record.getFullName(), e.getFullMessage()));
- } catch (TeiidComponentException e) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31080, record.getFullName(), e.getFullMessage()));
- } catch (QueryValidatorException e) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31080, record.getFullName(), e.getFullMessage()));
}
}
- private static Datatype getDataType(Collection<Datatype> dataTypes, Class<?> clazz) {
+ private Datatype getDataType(Collection<Datatype> dataTypes, Class<?> clazz) {
for (Datatype type:dataTypes) {
if (type.getJavaClassName().equals(clazz.getName())) {
return type;
@@ -244,7 +235,7 @@
return null;
}
- private static Column addColumn(String name, Datatype type, Table table) throws TranslatorException {
+ private Column addColumn(String name, Datatype type, Table table) throws TranslatorException {
Column column = new Column();
column.setName(name);
if (table.getColumnByName(name) != null) {
@@ -286,8 +277,8 @@
}
@Override
- public void execute(VDBMetaData vdb, MetadataStore store, ValidatorReport report) {
- for (Schema schema:store.getSchemas().values()) {
+ public void execute(VDBMetaData vdb, MetadataStore store, ValidatorReport report, MetadataValidator metadataValidator) {
+ for (Schema schema:store.getSchemaList()) {
ModelMetaData model = vdb.getModel(schema.getName());
for (Table t:schema.getTables().values()) {
@@ -296,18 +287,18 @@
String matTableName = t.getMaterializedTable().getName();
int index = matTableName.indexOf(Table.NAME_DELIM_CHAR);
if (index == -1) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31088, matTableName, t.getName()));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31088, matTableName, t.getName()));
}
else {
String schemaName = matTableName.substring(0, index);
Schema matSchema = store.getSchema(schemaName);
if (matSchema == null) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31089, schemaName, matTableName, t.getName()));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31089, schemaName, matTableName, t.getName()));
}
else {
Table matTable = matSchema.getTable(matTableName.substring(index+1));
if (matTable == null) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31090, matTableName.substring(index+1), schemaName, t.getName()));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31090, matTableName.substring(index+1), schemaName, t.getName()));
}
else {
t.setMaterializedTable(matTable);
@@ -329,7 +320,7 @@
String referenceTableName = fk.getReferenceTableName();
if (referenceTableName == null){
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31091, t.getName()));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31091, t.getName()));
continue;
}
@@ -343,21 +334,21 @@
referenceSchemaName = referenceTableName.substring(0, index);
Schema referenceSchema = store.getSchema(referenceSchemaName);
if (referenceSchema == null) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31093, referenceSchemaName, t.getName()));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31093, referenceSchemaName, t.getName()));
continue;
}
referenceTable = referenceSchema.getTable(referenceTableName.substring(index+1));
}
if (referenceTable == null) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31092, t.getName(), referenceTableName.substring(index+1), referenceSchemaName));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31092, t.getName(), referenceTableName.substring(index+1), referenceSchemaName));
continue;
}
KeyRecord uniqueKey = null;
if (fk.getReferenceColumns() == null || fk.getReferenceColumns().isEmpty()) {
if (referenceTable.getPrimaryKey() == null) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31094, t.getName(), referenceTableName.substring(index+1), referenceSchemaName));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31094, t.getName(), referenceTableName.substring(index+1), referenceSchemaName));
}
else {
uniqueKey = referenceTable.getPrimaryKey();
@@ -375,7 +366,7 @@
}
}
if (uniqueKey == null) {
- log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31095, t.getName(), referenceTableName.substring(index+1), referenceSchemaName, fk.getReferenceColumns()));
+ metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31095, t.getName(), referenceTableName.substring(index+1), referenceSchemaName, fk.getReferenceColumns()));
}
else {
fk.setPrimaryKey(uniqueKey);
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -275,7 +275,11 @@
public List<Column> getElementIDsInGroupID(final Object groupID) throws TeiidComponentException, QueryMetadataException {
ArgCheck.isInstanceOf(Table.class, groupID);
- return ((Table)groupID).getColumns();
+ List<Column> columns = ((Table)groupID).getColumns();
+ if (columns == null || columns.isEmpty()) {
+ throw new QueryMetadataException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31071, ((Table)groupID).getName()));
+ }
+ return columns;
}
public Object getGroupIDForElementID(final Object elementID) throws TeiidComponentException, QueryMetadataException {
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/PlanExecutionNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/PlanExecutionNode.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/PlanExecutionNode.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -117,7 +117,7 @@
TupleBatch batch = plan.nextBatch();
- for (List tuple : batch.getTuples()) {
+ for (List<?> tuple : batch.getTuples()) {
addBatchRow(tuple);
}
@@ -132,6 +132,11 @@
return pullBatch();
}
+ /**
+ * @throws BlockedException
+ * @throws TeiidComponentException
+ * @throws TeiidProcessingException
+ */
protected boolean prepareNextCommand() throws BlockedException,
TeiidComponentException, TeiidProcessingException {
return true;
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-06-20 15:57:10 UTC (rev 4191)
@@ -988,7 +988,7 @@
TEIID31071=Invalid table; Table {0} has no columns defined
TEIID31072=Invalid Procedure {0}; No return has been defined.
TEIID31073=Invalid functions; {0}
-TEIID31074=View table {0} is only allowed in VIRTUAL Model; {0} is defined as PHYSICAL model
+TEIID31074=View table {0} is only allowed in VIRTUAL Model; {1} is defined as PHYSICAL model
TEIID31075=Foreign table {0} is only allowed to be defined on PHYSICAL model; {1} is defined as VIRTUAL model.
TEIID31076=Virtual procedure {0} is only allowed to be defined on VIRTUAL model; {1} is defined as PHYSICAL model.
TEIID31077=Source Stored procedure {0} is only allowed to be defined on PHYSICAL model; {1} is defined as VIRTUAL model.
Modified: trunk/engine/src/test/java/org/teiid/query/metadata/TestMetadataValidator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/metadata/TestMetadataValidator.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/engine/src/test/java/org/teiid/query/metadata/TestMetadataValidator.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -75,7 +75,7 @@
String ddl = "create foreign table g1(e1 integer, e2 varchar(12)); create view g2(e1 integer, e2 varchar(12)) AS select * from foo;";
buildModel("pm1", true, this.vdb, this.store, ddl);
ValidatorReport report = new ValidatorReport();
- new MetadataValidator.SourceModelArtifacts().execute(vdb, store, report);
+ new MetadataValidator.SourceModelArtifacts().execute(vdb, store, report, new MetadataValidator());
assertTrue(printError(report), report.hasItems());
}
@@ -95,7 +95,7 @@
String ddl = "create foreign table g1(e1 integer, e2 varchar(12)); create view g2(e1 integer, e2 varchar(12)) AS select * from foo;";
buildModel("vm1", false, this.vdb, this.store, ddl);
ValidatorReport report = new ValidatorReport();
- new MetadataValidator.SourceModelArtifacts().execute(vdb, store, report);
+ new MetadataValidator.SourceModelArtifacts().execute(vdb, store, report, new MetadataValidator());
assertTrue(printError(report), report.hasItems());
}
@@ -104,7 +104,7 @@
buildModel("vm1", false, this.vdb, this.store, "create view g2(e1 integer, e2 varchar(12)) AS select * from foo;");
buildModel("pm1", true, this.vdb, this.store, "create foreign table g1(e1 integer, e2 varchar(12));");
ValidatorReport report = new ValidatorReport();
- new MetadataValidator.SourceModelArtifacts().execute(vdb, store, report);
+ new MetadataValidator.SourceModelArtifacts().execute(vdb, store, report, new MetadataValidator());
assertFalse(printError(report), report.hasItems());
}
@@ -112,7 +112,7 @@
public void testMinimalDataNoColumns() throws Exception {
buildModel("pm1", true, this.vdb, this.store, "create foreign table g1;");
ValidatorReport report = new ValidatorReport();
- new MetadataValidator.MinimalMetadata().execute(vdb, store, report);
+ new MetadataValidator.MinimalMetadata().execute(vdb, store, report, new MetadataValidator());
assertTrue(printError(report), report.hasItems());
}
@@ -126,7 +126,7 @@
buildModel("vm1", false, this.vdb, this.store, ddl);
buildTransformationMetadata();
ValidatorReport report = new ValidatorReport();
- new MetadataValidator.ResolveQueryPlans().execute(vdb, store, report);
+ new MetadataValidator.ResolveQueryPlans().execute(vdb, store, report, new MetadataValidator());
assertTrue(printError(report), report.hasItems());
}
@@ -136,7 +136,7 @@
buildModel("vm1", false, this.vdb, this.store, ddl);
buildTransformationMetadata();
ValidatorReport report = new ValidatorReport();
- new MetadataValidator.ResolveQueryPlans().execute(vdb, store, report);
+ new MetadataValidator.ResolveQueryPlans().execute(vdb, store, report, new MetadataValidator());
assertFalse(printError(report), report.hasItems());
}
@@ -146,7 +146,7 @@
buildModel("vm1", false, this.vdb, this.store, ddl);
buildTransformationMetadata();
ValidatorReport report = new ValidatorReport();
- new MetadataValidator.ResolveQueryPlans().execute(vdb, store, report);
+ new MetadataValidator.ResolveQueryPlans().execute(vdb, store, report, new MetadataValidator());
assertFalse(printError(report), report.hasItems());
}
@@ -155,7 +155,7 @@
buildModel("vm1", false, this.vdb, this.store, "create view g1 (e1 integer, e2 varchar(12)) AS select * from pm1.g1; create view g2 AS select * from pm1.g1;");
buildTransformationMetadata();
ValidatorReport report = new ValidatorReport();
- new MetadataValidator.ResolveQueryPlans().execute(vdb, store, report);
+ new MetadataValidator.ResolveQueryPlans().execute(vdb, store, report, new MetadataValidator());
assertTrue(printError(report), report.hasItems());
}
@@ -170,7 +170,7 @@
buildTransformationMetadata();
ValidatorReport report = new ValidatorReport();
- report = MetadataValidator.validate(this.vdb, this.store);
+ report = new MetadataValidator().validate(this.vdb, this.store);
assertFalse(printError(report), report.hasItems());
assertNotNull(this.store.getSchema("pm2").getTable("G2").getForeignKeys().get(0).getPrimaryKey());
@@ -189,7 +189,7 @@
buildTransformationMetadata();
ValidatorReport report = new ValidatorReport();
- report = MetadataValidator.validate(this.vdb, this.store);
+ report = new MetadataValidator().validate(this.vdb, this.store);
assertFalse(printError(report), report.hasItems());
assertNotNull(this.store.getSchema("pm2").getTable("G2").getForeignKeys().get(0).getPrimaryKey());
@@ -208,7 +208,7 @@
buildTransformationMetadata();
ValidatorReport report = new ValidatorReport();
- report = MetadataValidator.validate(this.vdb, this.store);
+ report = new MetadataValidator().validate(this.vdb, this.store);
assertFalse(printError(report), report.hasItems());
assertNotNull(this.store.getSchema("pm2").getTable("G2").getForeignKeys().get(0).getPrimaryKey());
@@ -228,7 +228,7 @@
buildTransformationMetadata();
ValidatorReport report = new ValidatorReport();
- report = MetadataValidator.validate(this.vdb, this.store);
+ report = new MetadataValidator().validate(this.vdb, this.store);
assertTrue(printError(report), report.hasItems());
}
@@ -245,7 +245,7 @@
buildTransformationMetadata();
ValidatorReport report = new ValidatorReport();
- report = MetadataValidator.validate(this.vdb, this.store);
+ report = new MetadataValidator().validate(this.vdb, this.store);
assertFalse(printError(report), report.hasItems());
}
@@ -261,7 +261,7 @@
buildTransformationMetadata();
ValidatorReport report = new ValidatorReport();
- report = MetadataValidator.validate(this.vdb, this.store);
+ report = new MetadataValidator().validate(this.vdb, this.store);
assertFalse(printError(report), report.hasItems());
assertNotNull("pm1.G1", store.getSchema("vm1").getTable("G2").getMaterializedTable());
assertEquals("G1", store.getSchema("vm1").getTable("G2").getMaterializedTable().getName());
@@ -293,8 +293,7 @@
buildTransformationMetadata();
- ValidatorReport report = new ValidatorReport();
- report = MetadataValidator.validate(this.vdb, this.store);
+ ValidatorReport report = new MetadataValidator().validate(this.vdb, this.store);
assertFalse(printError(report), report.hasItems());
}
}
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -244,7 +244,7 @@
modelOne.setName("model"); //$NON-NLS-1$
vdb.addModel(modelOne);
- ValidatorReport report = MetadataValidator.validate(vdb, s.asMetadataStore());
+ ValidatorReport report = new MetadataValidator().validate(vdb, s.asMetadataStore());
assertFalse(report.hasItems());
@@ -275,7 +275,7 @@
modelOne.setName("model"); //$NON-NLS-1$
vdb.addModel(modelOne);
- ValidatorReport report = MetadataValidator.validate(vdb, s.asMetadataStore());
+ ValidatorReport report = new MetadataValidator().validate(vdb, s.asMetadataStore());
assertTrue(report.hasItems());
}
@@ -304,7 +304,7 @@
MetadataStore s = f1.asMetadataStore();
f2.mergeInto(s);
- ValidatorReport report = MetadataValidator.validate(vdb, s);
+ ValidatorReport report = new MetadataValidator().validate(vdb, s);
assertFalse(report.hasItems());
@@ -316,17 +316,13 @@
assertEquals(fk.getPrimaryKey().getColumns(), s.getSchema("model").getTable("G1").getColumns());
}
- @Test
+ @Test(expected=ParseException.class)
public void testViewWithoutPlan() throws Exception {
String ddl = "CREATE View G1( e1 integer, e2 varchar)";
- try {
- MetadataStore mds = new MetadataStore();
- MetadataFactory mf = new MetadataFactory(null, 1, "model", getDataTypes(), new Properties(), null);
- parser.parseDDL(mf,ddl);
- mf.mergeInto(mds);
- fail("should fail define a view with out a plan");
- } catch(ParseException e) {
- }
+ MetadataStore mds = new MetadataStore();
+ MetadataFactory mf = new MetadataFactory(null, 1, "model", getDataTypes(), new Properties(), null);
+ parser.parseDDL(mf,ddl);
+ mf.mergeInto(mds);
}
@Test
@@ -618,8 +614,8 @@
parser.parseDDL(mf, ddl);
mf.mergeInto(mds);
- assertTrue(mds.getNamespaces().keySet().contains("teiid"));
- assertEquals("http://teiid.org", mds.getNamespaces().get("teiid"));
+ assertTrue(mf.getNamespaces().keySet().contains("teiid"));
+ assertEquals("http://teiid.org", mf.getNamespaces().get("teiid"));
}
public static MetadataFactory helpParse(String ddl, String model) throws ParseException {
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -92,11 +92,8 @@
}
boolean preview = deployment.isPreview();
- if (!preview) {
- List<String> errors = deployment.getValidityErrors();
- if (errors != null && !errors.isEmpty()) {
- throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50074, deployment));
- }
+ if (!preview && deployment.hasErrors()) {
+ throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50074, deployment));
}
// make sure the translator defined exists in configuration; otherwise add as error
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -52,7 +52,6 @@
import org.jboss.msc.value.InjectedValue;
import org.teiid.adminapi.AdminProcessingException;
import org.teiid.adminapi.Translator;
-import org.teiid.adminapi.VDB;
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.adminapi.impl.VDBMetadataParser;
@@ -245,10 +244,7 @@
this.objectReplicatorInjector.getValue().stop(gts);
}
getVDBRepository().removeListener(this.vdbListener);
- VDBMetaData runtimeMetadata = getVDBRepository().removeVDB(this.vdb.getName(), this.vdb.getVersion());
- if (runtimeMetadata != null) {
- runtimeMetadata.setStatus(VDB.Status.REMOVED);
- }
+ getVDBRepository().removeVDB(this.vdb.getName(), this.vdb.getVersion());
final ServiceController<?> controller = context.getController().getServiceContainer().getService(TeiidServiceNames.vdbFinishedServiceName(vdb.getName(), vdb.getVersion()));
if (controller != null) {
controller.setMode(ServiceController.Mode.REMOVE);
Modified: trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataStore.java
===================================================================
--- trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataStore.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataStore.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -37,7 +37,6 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.concurrent.Semaphore;
import org.jboss.vfs.VirtualFile;
import org.jboss.vfs.VirtualFileFilter;
@@ -149,7 +148,6 @@
private HashSet<VirtualFile> indexFiles = new HashSet<VirtualFile>();
private LinkedHashMap<String, Resource> vdbEntries;
private boolean loaded = false;
- private Semaphore lock = new Semaphore(1);
public IndexMetadataStore() {
@@ -221,62 +219,57 @@
}
}
}
- public void load(Collection<Datatype> systemDatatypes) throws IOException {
- load(null, systemDatatypes);
- Collection<AbstractMetadataRecord> modelRecords = getByType(MetadataConstants.RECORD_TYPE.MODEL).values();
- for (AbstractMetadataRecord record:modelRecords) {
- Schema s = (Schema) record;
- load(s.getName(), systemDatatypes);
- }
- }
public void load(String modelName, Collection<Datatype> systemDatatypes) throws IOException {
// there are multiple threads trying to load this, since the initial index lading is not
// optimized for multi-thread loading this locking to sync will work
- try {
- this.lock.acquire();
- } catch (InterruptedException e) {
- }
-
- if (!this.loaded) {
- if (systemDatatypes == null) {
- loadSystemDatatypes(this);
- }
- ArrayList<Index> tmp = new ArrayList<Index>();
- for (VirtualFile f : indexFiles) {
- Index index = new Index(f, true);
- index.setDoCache(true);
- tmp.add(index);
- }
- this.indexes = tmp.toArray(new Index[tmp.size()]);
- loadAll();
- //force close, since we cached the index files
- for (Index index : tmp) {
- index.close();
- }
- Map<String, AbstractMetadataRecord> uuidToRecord = getByType(MetadataConstants.RECORD_TYPE.DATATYPE);
- if (systemDatatypes != null) {
- for (Datatype datatype : systemDatatypes) {
- uuidToRecord.put(datatype.getUUID(), datatype);
+ synchronized (this) {
+ if (!this.loaded) {
+ if (systemDatatypes == null) {
+ loadSystemDatatypes(this);
}
- } else {
- for (Datatype datatype : getDatatypes().values()) {
- uuidToRecord.put(datatype.getUUID(), datatype);
+ ArrayList<Index> tmp = new ArrayList<Index>();
+ for (VirtualFile f : indexFiles) {
+ Index index = new Index(f, true);
+ index.setDoCache(true);
+ tmp.add(index);
}
+ this.indexes = tmp.toArray(new Index[tmp.size()]);
+ loadAll();
+ //force close, since we cached the index files
+ for (Index index : tmp) {
+ index.close();
+ }
+ Map<String, AbstractMetadataRecord> uuidToRecord = getByType(MetadataConstants.RECORD_TYPE.DATATYPE);
+ if (systemDatatypes != null) {
+ for (Datatype datatype : systemDatatypes) {
+ uuidToRecord.put(datatype.getUUID(), datatype);
+ }
+ } else {
+ for (Datatype datatype : getDatatypes().values()) {
+ uuidToRecord.put(datatype.getUUID(), datatype);
+ }
+ }
+ for (AbstractMetadataRecord datatypeRecordImpl : uuidToRecord.values()) {
+ addDatatype((Datatype) datatypeRecordImpl);
+ }
+ this.loaded = true;
}
- for (AbstractMetadataRecord datatypeRecordImpl : uuidToRecord.values()) {
- addDatatype((Datatype) datatypeRecordImpl);
- }
- this.loaded = true;
}
- this.lock.release();
-
- if (this.loaded) {
- getModels(modelName);
- getTables(modelName);
- getProcedures(modelName);
- }
+ // the index map below is keyed by uuid not modelname, so map lookup is not possible
+ Collection<AbstractMetadataRecord> modelRecords = getByType(MetadataConstants.RECORD_TYPE.MODEL).values();
+ for (AbstractMetadataRecord modelRecord:modelRecords) {
+ Schema s = (Schema) modelRecord;
+ if (modelName == null || s.getName().equalsIgnoreCase(modelName)) {
+ addSchema(s);
+ getTables(s);
+ getProcedures(s);
+ if (modelName != null) {
+ break;
+ }
+ }
+ }
}
public static void loadSystemDatatypes(MetadataStore ms) throws IOException {
@@ -357,25 +350,24 @@
return this.vdbEntries;
}
- private void getModels(String modelName) {
- // the index map below is keyed by uuid not modelname, so map lookup is not possible
- Collection<AbstractMetadataRecord> modelRecords = getByType(MetadataConstants.RECORD_TYPE.MODEL).values();
- for (AbstractMetadataRecord modelRecord:modelRecords) {
- Schema s = (Schema) modelRecord;
- if (s.getName().equalsIgnoreCase(modelName)) {
- addSchema((Schema) modelRecord);
- }
- }
+ /**
+ * override for thread safety
+ */
+ @Override
+ public synchronized void addSchema(Schema schema) {
+ super.addSchema(schema);
}
+
+ /**
+ * override for thread safety
+ */
+ @Override
+ public synchronized Schema getSchema(String name) {
+ return super.getSchema(name);
+ }
- private void getTables(String modelName) {
- Schema model = getSchemas().get(modelName);
-
- if (model == null) {
- return;
- }
-
- Map<Character, List<AbstractMetadataRecord>> entries = schemaEntries.get(modelName);
+ private void getTables(Schema model) {
+ Map<Character, List<AbstractMetadataRecord>> entries = schemaEntries.get(model.getName());
if (entries == null) {
return;
}
@@ -495,12 +487,7 @@
return record;
}
- private void getProcedures(String modelName) {
- Schema model = getSchemas().get(modelName);
- if (model == null) {
- return;
- }
-
+ private void getProcedures(Schema model) {
Map<Character, List<AbstractMetadataRecord>> entries = schemaEntries.get(model.getName());
if (entries == null) {
return;
Modified: trunk/metadata/src/test/java/org/teiid/metadata/index/VDBMetadataFactory.java
===================================================================
--- trunk/metadata/src/test/java/org/teiid/metadata/index/VDBMetadataFactory.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/metadata/src/test/java/org/teiid/metadata/index/VDBMetadataFactory.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -112,7 +112,7 @@
// it is hard to event when the test is done, otherwise we need to elevate the VFS to top
}
IndexMetadataStore store = new IndexMetadataStore(root);
- store.load(dataTypes);
+ store.load(null, dataTypes);
return store;
}
Modified: trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -206,20 +206,26 @@
}
private MetadataStore getMetadataStore() {
- if (this.children == null || this.children.isEmpty()) {
- return this.store;
- }
-
MetadataStore mergedStore = new MetadataStore();
if (this.store != null) {
- mergedStore.merge(this.store);
+ //the order of the models is important for resolving ddl
+ //TODO we might consider not using the intermediate MetadataStore
+ for (ModelMetaData model : this.vdb.getModelMetaDatas().values()) {
+ Schema s = this.store.getSchemas().get(model.getName());
+ if (s != null) {
+ mergedStore.addSchema(s);
+ }
+ }
+ mergedStore.addDataTypes(store.getDatatypes().values());
}
- for (CompositeVDB child:this.children.values()) {
- MetadataStore childStore = child.getMetadataStore();
- if ( childStore != null) {
- mergedStore.merge(childStore);
- }
- }
+ if (this.children != null && !this.children.isEmpty()) {
+ for (CompositeVDB child:this.children.values()) {
+ MetadataStore childStore = child.getMetadataStore();
+ if ( childStore != null) {
+ mergedStore.merge(childStore);
+ }
+ }
+ }
return mergedStore;
}
Modified: trunk/runtime/src/main/java/org/teiid/deployers/SystemVDBDeployer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/SystemVDBDeployer.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/runtime/src/main/java/org/teiid/deployers/SystemVDBDeployer.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -63,7 +63,7 @@
}
IndexMetadataStore idxStore = new IndexMetadataStore(mountPoint);
- idxStore.load(null);
+ idxStore.load(null, null);
// uri conversion is only to remove the spaces in URL, note this only with above kind situation
this.vdbRepository.setSystemStore(idxStore);
Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -35,7 +35,7 @@
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
-import org.teiid.adminapi.VDB;
+import org.teiid.adminapi.VDB.Status;
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.SourceMappingMetadata;
import org.teiid.adminapi.impl.VDBMetaData;
@@ -250,10 +250,15 @@
public VDBMetaData removeVDB(String vdbName, int vdbVersion) {
VDBKey key = new VDBKey(vdbName, vdbVersion);
+ return removeVDB(key);
+ }
+
+ private VDBMetaData removeVDB(VDBKey key) {
CompositeVDB removed = this.vdbRepo.remove(key);
if (removed == null) {
return null;
}
+ removed.getVDB().setStatus(Status.REMOVED);
notifyRemove(key.getName(), key.getVersion(), removed);
return removed.getVDB();
}
@@ -270,40 +275,40 @@
}
public void finishDeployment(String name, int version) {
- CompositeVDB v = this.vdbRepo.get(new VDBKey(name, version));
+ VDBKey key = new VDBKey(name, version);
+ CompositeVDB v = this.vdbRepo.get(key);
if (v == null) {
return;
}
- boolean valid = false;
v.metadataLoadFinished();
- VDBMetaData metdataAwareVDB = v.getVDB();
- synchronized (metdataAwareVDB) {
- ValidatorReport report = MetadataValidator.validate(metdataAwareVDB, metdataAwareVDB.removeAttachment(MetadataStore.class));
-
- if (!report.hasItems()) {
- valid = true;
- }
- else {
- LogManager.logWarning(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40073, name, version));
- }
-
- // check the data sources available
- if (valid) {
- valid = hasValidDataSources(metdataAwareVDB);
- }
-
- if (valid) {
- metdataAwareVDB.setStatus(VDB.Status.ACTIVE);
- }
- else {
- metdataAwareVDB.setStatus(VDB.Status.INVALID);
- }
- LogManager.logInfo(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40003,name, version, metdataAwareVDB.getStatus()));
+ VDBMetaData metadataAwareVDB = v.getVDB();
+ synchronized (metadataAwareVDB) {
+ ValidatorReport report = new MetadataValidator().validate(metadataAwareVDB, metadataAwareVDB.removeAttachment(MetadataStore.class));
+
+ if (report.hasItems()) {
+ LogManager.logInfo(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40073, name, version));
+ if (!v.getVDB().isPreview()) {
+ processMetadataValidatorReport(key, report);
+ if (v.getVDB().getStatus() == Status.REMOVED) {
+ return;
+ }
+ }
+ }
+ metadataAwareVDB.setStatus(Status.ACTIVE);
+ LogManager.logInfo(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40003,name, version, metadataAwareVDB.getStatus()));
notifyFinished(name, version, v);
}
}
- boolean hasValidDataSources(VDBMetaData vdb) {
+ /**
+ * @param key
+ * @param report
+ */
+ protected void processMetadataValidatorReport(VDBKey key, ValidatorReport report) {
+ this.removeVDB(key);
+ }
+
+ void validateDataSources(VDBMetaData vdb) {
ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
for (ModelMetaData model:vdb.getModelMetaDatas().values()) {
@@ -321,7 +326,6 @@
}
}
}
- return vdb.getValidityErrors().isEmpty();
}
Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -27,7 +27,6 @@
import org.teiid.adminapi.AdminProcessingException;
import org.teiid.adminapi.Model;
import org.teiid.adminapi.VDB;
-import org.teiid.adminapi.VDB.Status;
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.adminapi.impl.VDBTranslatorMetaData;
@@ -84,7 +83,6 @@
boolean dsReplaced = false;
if (!cm.getConnectionName().equals(dsName)){
- markInvalid(vdb);
String msg = RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40076, vdb.getName(), vdb.getVersion(), model.getSourceTranslatorName(sourceName), dsName);
model.addRuntimeError(msg);
cm = new ConnectorManager(translatorName, dsName);
@@ -119,14 +117,6 @@
}
}
- private void markInvalid(VDBMetaData vdb) {
- if (vdb.getStatus() == Status.LOADING) {
- vdb.setStatus(Status.INCOMPLETE);
- } else if (vdb.getStatus() == Status.ACTIVE){
- vdb.setStatus(Status.INVALID);
- }
- }
-
public void resourceAdded(String resourceName, boolean translator) {
for (VDBMetaData vdb:getVDBRepository().getVDBs()) {
if (vdb.getStatus() == VDB.Status.ACTIVE) {
@@ -150,7 +140,7 @@
String status = cm.getStausMessage();
if (status != null && status.length() > 0) {
model.addRuntimeError(status);
- LogManager.logInfo(LogConstants.CTX_RUNTIME, status);
+ LogManager.logInfo(LogConstants.CTX_RUNTIME, status);
} else {
//get the pending metadata load
Runnable r = model.removeAttachment(Runnable.class);
@@ -176,11 +166,6 @@
getExecutor().execute(runnable);
}
} else if (valid) {
- if (vdb.getStatus() == Status.INVALID) {
- vdb.setStatus(VDB.Status.ACTIVE);
- } else {
- vdb.setStatus(VDB.Status.LOADING);
- }
LogManager.logInfo(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40003,vdb.getName(), vdb.getVersion(), vdb.getStatus()));
}
}
@@ -195,7 +180,6 @@
String sourceName = getSourceName(resourceName, model, translator);
if (sourceName != null) {
- markInvalid(vdb);
String msg = null;
if (translator) {
msg = RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40005, vdb.getName(), vdb.getVersion(), model.getSourceTranslatorName(sourceName));
Modified: trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -54,6 +54,7 @@
import org.teiid.common.buffer.BufferManager;
import org.teiid.common.buffer.TupleBufferCache;
import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.BundleUtil.Event;
import org.teiid.deployers.CompositeVDB;
import org.teiid.deployers.UDFMetaData;
import org.teiid.deployers.VDBLifeCycleListener;
@@ -92,6 +93,8 @@
import org.teiid.query.metadata.TransformationMetadata.Resource;
import org.teiid.query.tempdata.GlobalTableStore;
import org.teiid.query.tempdata.GlobalTableStoreImpl;
+import org.teiid.query.validator.ValidatorFailure;
+import org.teiid.query.validator.ValidatorReport;
import org.teiid.services.AbstractEventDistributorFactoryService;
import org.teiid.services.BufferServiceImpl;
import org.teiid.services.SessionServiceImpl;
@@ -102,6 +105,7 @@
import org.teiid.transport.ClientServiceRegistryImpl;
import org.teiid.transport.LocalServerConnection;
import org.teiid.transport.LogonImpl;
+import org.teiid.vdb.runtime.VDBKey;
/**
* A simplified server environment for embedded use.
@@ -189,8 +193,28 @@
}
+ private static class VDBValidationError extends TeiidRuntimeException {
+
+ private VDBValidationError(Event event, String message) {
+ super(event, message);
+ }
+ }
+
protected DQPCore dqp = new DQPCore();
- protected VDBRepository repo = new VDBRepository();
+ /**
+ * Custom vdb repository that will immediately throw exceptions for metadata validation errors
+ */
+ protected VDBRepository repo = new VDBRepository() {
+ @Override
+ protected void processMetadataValidatorReport(VDBKey key, ValidatorReport report) {
+ if (throwMetadataErrors) {
+ super.processMetadataValidatorReport(key, report); //remove
+ ValidatorFailure firstFailure = report.getItems().iterator().next();
+ throw new VDBValidationError(RuntimePlugin.Event.TEIID40095, firstFailure.getMessage());
+ }
+ }
+ };
+ protected boolean throwMetadataErrors = true;
private ConcurrentHashMap<String, ExecutionFactory<?, ?>> translators = new ConcurrentHashMap<String, ExecutionFactory<?, ?>>();
private ConcurrentHashMap<String, ConnectionFactoryProvider<?>> connectionFactoryProviders = new ConcurrentHashMap<String, ConnectionFactoryProvider<?>>();
protected SessionServiceImpl sessionService = new SessionServiceImpl();
@@ -442,20 +466,24 @@
* @throws VirtualDatabaseException
* @throws TranslatorException
*/
- public void deployVDB(String name, List<ModelMetaData> models)
+ public void deployVDB(String name, ModelMetaData... models)
throws ConnectorManagerException, VirtualDatabaseException, TranslatorException {
checkStarted();
VDBMetaData vdb = new VDBMetaData();
vdb.setDynamic(true);
vdb.setName(name);
- vdb.setModels(models);
+ vdb.setModels(Arrays.asList(models));
cmr.createConnectorManagers(vdb, this);
MetadataStore metadataStore = new MetadataStore();
UDFMetaData udfMetaData = new UDFMetaData();
udfMetaData.setFunctionClassLoader(Thread.currentThread().getContextClassLoader());
this.assignMetadataRepositories(vdb, null);
repo.addVDB(vdb, metadataStore, new LinkedHashMap<String, Resource>(), udfMetaData, cmr);
- this.loadMetadata(vdb, cmr, metadataStore);
+ try {
+ this.loadMetadata(vdb, cmr, metadataStore);
+ } catch (VDBValidationError e) {
+ throw new VirtualDatabaseException(RuntimePlugin.Event.valueOf(e.getCode()), e.getMessage());
+ }
}
/**
Modified: trunk/runtime/src/main/java/org/teiid/runtime/RuntimePlugin.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/runtime/RuntimePlugin.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/runtime/src/main/java/org/teiid/runtime/RuntimePlugin.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -107,6 +107,6 @@
TEIID40092,
TEIID40093, //no sources
TEIID40094, //invalid metadata repso
-
+ TEIID40095, //deployment failed
}
}
Modified: trunk/runtime/src/test/java/org/teiid/runtime/TestEmbeddedServer.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/runtime/TestEmbeddedServer.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/runtime/src/test/java/org/teiid/runtime/TestEmbeddedServer.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -27,7 +27,6 @@
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
-import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@@ -36,6 +35,7 @@
import org.junit.Test;
import org.teiid.adminapi.Model.Type;
import org.teiid.adminapi.impl.ModelMetaData;
+import org.teiid.deployers.VirtualDatabaseException;
import org.teiid.jdbc.TeiidDriver;
import org.teiid.language.Command;
import org.teiid.language.QueryExpression;
@@ -173,7 +173,7 @@
mmd1.setSchemaSourceType("ddl");
mmd1.setSchemaText("create view \"my-view\" OPTIONS (UPDATABLE 'true') as select * from \"my-table\"");
- es.deployVDB("test", Arrays.asList(mmd, mmd1));
+ es.deployVDB("test", mmd, mmd1);
TeiidDriver td = es.getDriver();
Connection c = td.connect("jdbc:teiid:test", null);
@@ -185,5 +185,47 @@
s.execute("update \"my-view\" set \"my-column\" = 'a'");
assertEquals(2, s.getUpdateCount());
}
+
+ @Test(expected=VirtualDatabaseException.class) public void testDeploymentError() throws Exception {
+ EmbeddedConfiguration ec = new EmbeddedConfiguration();
+ ec.setUseDisk(false);
+ es.start(ec);
+
+ ModelMetaData mmd1 = new ModelMetaData();
+ mmd1.setName("virt");
+ mmd1.setModelType(Type.VIRTUAL);
+ mmd1.setSchemaSourceType("ddl");
+ mmd1.setSchemaText("create view \"my-view\" OPTIONS (UPDATABLE 'true') as select * from \"my-table\"");
+ es.deployVDB("test", mmd1);
+ }
+
+ @Test public void testValidationOrder() throws Exception {
+ EmbeddedConfiguration ec = new EmbeddedConfiguration();
+ ec.setUseDisk(false);
+ es.start(ec);
+
+ ModelMetaData mmd1 = new ModelMetaData();
+ mmd1.setName("b");
+ mmd1.setModelType(Type.VIRTUAL);
+ mmd1.setSchemaSourceType("ddl");
+ mmd1.setSchemaText("create view v as select 1");
+
+ ModelMetaData mmd2 = new ModelMetaData();
+ mmd2.setName("a");
+ mmd2.setModelType(Type.VIRTUAL);
+ mmd2.setSchemaSourceType("ddl");
+ mmd2.setSchemaText("create view v1 as select * from v");
+
+ //We need mmd1 to validate before mmd2, reversing the order will result in an exception
+ es.deployVDB("test", mmd1, mmd2);
+
+ try {
+ es.deployVDB("test2", mmd2, mmd1);
+ fail();
+ } catch (VirtualDatabaseException e) {
+
+ }
+ }
+
}
Modified: trunk/test-integration/common/src/test/java/org/teiid/arquillian/AdminUtil.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/arquillian/AdminUtil.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/test-integration/common/src/test/java/org/teiid/arquillian/AdminUtil.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -27,6 +27,7 @@
import org.teiid.adminapi.Admin;
import org.teiid.adminapi.AdminException;
import org.teiid.adminapi.VDB;
+import org.teiid.adminapi.VDB.Status;
@SuppressWarnings("nls")
public class AdminUtil {
@@ -71,7 +72,7 @@
first = false;
}
VDB vdb = admin.getVDB(vdbName, vdbVersion);
- if (vdb != null && !vdb.getStatus().isLoading()) {
+ if (vdb != null && vdb.getStatus() != Status.LOADING) {
return true;
}
} while (System.currentTimeMillis() < waitUntil);
Modified: trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestDeployment.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestDeployment.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestDeployment.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -86,7 +86,7 @@
VDB vdb = admin.getVDB("bqt", 1);
assertFalse(vdb.isValid());
assertTrue(AdminUtil.waitForVDBLoad(admin, "bqt", 1, 3));
- assertEquals(Status.INVALID, vdb.getStatus());
+ assertFalse(vdb.isValid());
Properties props = new Properties();
props.setProperty("connection-url","jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
@@ -105,7 +105,6 @@
admin.deleteDataSource("Oracle11_PushDS");
vdb = admin.getVDB("bqt", 1);
assertFalse(vdb.isValid());
- assertEquals(Status.INVALID, vdb.getStatus());
}
@Test
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-06-19 18:50:25 UTC (rev 4190)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/FakeServer.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -30,6 +30,7 @@
import javax.transaction.TransactionManager;
import org.teiid.adminapi.VDB;
+import org.teiid.adminapi.Model.Type;
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBImportMetadata;
import org.teiid.adminapi.impl.VDBMetaData;
@@ -191,6 +192,7 @@
private ModelMetaData addModel(VDBMetaData vdbMetaData, Schema schema) {
ModelMetaData model = new ModelMetaData();
+ model.setModelType(schema.isPhysical()?Type.PHYSICAL:Type.VIRTUAL);
model.setName(schema.getName());
vdbMetaData.addModel(model);
model.addSourceMapping("source", "translator", "jndi:source");
@@ -213,4 +215,8 @@
return services;
}
+ public void setThrowMetadataErrors(boolean throwMetadataErrors) {
+ this.throwMetadataErrors = throwMetadataErrors;
+ }
+
}
Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestCase3473.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestCase3473.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestCase3473.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -26,7 +26,9 @@
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.teiid.core.util.UnitTestUtil;
@@ -37,12 +39,20 @@
public class TestCase3473 {
private DatabaseMetaData dbmd;
+ private static FakeServer server;
+
+ @BeforeClass public static void oneTimeSetup() throws Exception {
+ server = new FakeServer(true);
+ server.deployVDB("test", UnitTestUtil.getTestDataPath() + "/TestCase3473/test.vdb");
+ }
+
+ @AfterClass public static void oneTimeTeardown() throws Exception {
+ server.stop();
+ }
////////////////////Query Related Methods///////////////////////////
@Before public void setUp() throws Exception {
- FakeServer server = new FakeServer(true);
- server.deployVDB("test", UnitTestUtil.getTestDataPath() + "/TestCase3473/test.vdb");
Connection conn = server.createConnection("jdbc:teiid:test"); //$NON-NLS-1$
dbmd = conn.getMetaData();
}
Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestDynamicImportedMetaData.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestDynamicImportedMetaData.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestDynamicImportedMetaData.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -179,7 +179,7 @@
MetadataFactory m2 = createMetadataFactory("portfolio", new Properties());
QueryParser.getQueryParser().parseDDL(m2, ddl2);
-
+ m2.getSchema().setPhysical(false);
m2.mergeInto(ms);
server.deployVDB("test", ms);
Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestMMDatabaseMetaData.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestMMDatabaseMetaData.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestMMDatabaseMetaData.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -119,7 +119,7 @@
static Connection conn = null;
DatabaseMetaData dbmd;
- private Map expectedMap = new HashMap();
+ private Map<String, Object> expectedMap = new HashMap<String, Object>();
// constant
private static final int NO_LIMIT = 0;
@@ -147,6 +147,7 @@
@BeforeClass
public static void oneTimeSetUp() throws Exception {
FakeServer server = new FakeServer(true);
+ server.setThrowMetadataErrors(false); //there are invalid views due to aggregate datatype changes
server.deployVDB("QT_Ora9DS", UnitTestUtil.getTestDataPath()+"/QT_Ora9DS_1.vdb");
conn = server.createConnection("jdbc:teiid:QT_Ora9DS"); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -154,7 +155,7 @@
/** Test all the non-query methods */
@Test
public void testMethodsWithoutParams() throws Exception {
- Class dbmdClass = dbmd.getClass();
+ Class<?> dbmdClass = dbmd.getClass();
// non-query Methods return String, boolean or int
Method[] methods = dbmdClass.getDeclaredMethods();
@@ -168,9 +169,9 @@
Object expectedReturn = expectedMap.get(methods[i].getName());
Object[] params = null;
- if (expectedReturn instanceof List) {
+ if (expectedReturn instanceof List<?>) {
// has input parameters
- List returned = (List) expectedReturn;
+ List<?> returned = (List) expectedReturn;
params = (Object[]) returned.get(1);
//SYS.out.println(" params == " + params[0]);
expectedValue = returned.get(0);
@@ -191,10 +192,10 @@
/** Test all the methods that throw exception */
@Test
public void testMethodsWithExceptions() throws Exception {
- Class dbmdClass = dbmd.getClass();
+ Class<?> dbmdClass = dbmd.getClass();
Method[] methods = dbmdClass.getDeclaredMethods();
- expectedMap = new HashMap(); //none expected
+ expectedMap = new HashMap<String, Object>(); //none expected
//SYS.out.println(" -- total method == " + methods.length + ", non-query == " + expectedMap.size());
for (int i =0; i< methods.length; i++) {
if (expectedMap.containsKey(methods[i].getName())) {
@@ -768,7 +769,7 @@
}
private void helpTestMethodsWithParams(String methodName, boolean returned, Object[] params) throws Exception {
- Class dbmdClass = dbmd.getClass();
+ Class<?> dbmdClass = dbmd.getClass();
Method[] methods = dbmdClass.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
@@ -782,7 +783,7 @@
//////////////////////Expected Result//////////////////
- private Map getExpected() {
+ private Map<String, Object> getExpected() {
Map<String, Object> expected = new HashMap<String, Object>();
// return type -- boolean
expected.put("allProceduresAreCallable", Boolean.TRUE); //$NON-NLS-1$
Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestVDBMerge.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestVDBMerge.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestVDBMerge.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -3,6 +3,8 @@
import java.sql.SQLException;
import java.util.Arrays;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.teiid.adminapi.impl.VDBImportMetadata;
import org.teiid.core.util.UnitTestUtil;
@@ -14,8 +16,18 @@
private static final String VDB1 = "PartsSupplier"; //$NON-NLS-1$
private static final String VDB2 = "QT_Ora9DS"; //$NON-NLS-1$
- FakeServer server = new FakeServer(true);
-
+
+ private FakeServer server;
+
+ @Before public void setup() throws Exception {
+ server = new FakeServer(true);
+ server.setThrowMetadataErrors(false); //test vdb has errors
+ }
+
+ @After public void teardown() throws Exception {
+ server.stop();
+ }
+
@Test
public void testMerge() throws Throwable {
Modified: trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewAliasing.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewAliasing.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestMatViewAliasing.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -53,7 +53,7 @@
VDBRepository vdbRepository = new VDBRepository();
vdbRepository.setSystemStore(VDBMetadataFactory.getSystem());
MetadataFactory mf = new MetadataFactory(null, 1, "foo", vdbRepository.getBuiltinDatatypes(), new Properties(), null);
-
+ mf.getSchema().setPhysical(false);
Table mat = mf.addTable("mat");
mat.setVirtual(true);
mat.setMaterialized(true);
Modified: trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestVirtualDocWithVirtualProc.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestVirtualDocWithVirtualProc.java 2012-06-19 18:50:25 UTC (rev 4190)
+++ trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestVirtualDocWithVirtualProc.java 2012-06-20 15:57:10 UTC (rev 4191)
@@ -51,6 +51,7 @@
@BeforeClass public static void oneTimeSetup() throws Exception {
server = new FakeServer(true);
+ server.setThrowMetadataErrors(false); //this vdb has invalid update procedures
server.deployVDB(VDB, UnitTestUtil.getTestDataPath() + "/xml-vp/xmlvp_1.vdb");
}
12 years, 6 months
teiid SVN: r4190 - trunk/engine/src/main/java/org/teiid/query/metadata.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-06-19 14:50:25 -0400 (Tue, 19 Jun 2012)
New Revision: 4190
Modified:
trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java
Log:
TEIID-2076 fix for not performing implicit update
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java 2012-06-19 18:37:14 UTC (rev 4189)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java 2012-06-19 18:50:25 UTC (rev 4190)
@@ -211,7 +211,7 @@
}
}
- GroupSymbol symbol = new GroupSymbol(t.getName());
+ GroupSymbol symbol = new GroupSymbol(t.getFullName());
ResolverUtil.resolveGroup(symbol, metadata);
// this seems to parse, resolve and validate.
12 years, 6 months
teiid SVN: r4189 - trunk/runtime/src/main/java/org/teiid/deployers.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2012-06-19 14:37:14 -0400 (Tue, 19 Jun 2012)
New Revision: 4189
Modified:
trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
Log:
TEIID-2057: making sure there were no runtime errors to be valid
Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2012-06-19 17:07:47 UTC (rev 4188)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2012-06-19 18:37:14 UTC (rev 4189)
@@ -321,7 +321,7 @@
}
}
}
- return vdb.isValid();
+ return vdb.getValidityErrors().isEmpty();
}
12 years, 6 months
teiid SVN: r4188 - in branches/7.7.x/engine/src: test/java/org/teiid/query/processor and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-06-19 13:07:47 -0400 (Tue, 19 Jun 2012)
New Revision: 4188
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java
branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java
Log:
TEIID-2074 fix for npe with multi-column dep join
Modified: branches/7.7.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java 2012-06-19 14:13:44 UTC (rev 4187)
+++ branches/7.7.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java 2012-06-19 17:07:47 UTC (rev 4188)
@@ -100,24 +100,46 @@
for (SetState setState : dependentSetStates) {
setState.valueIterator = dvs.getValueIterator(setState.valueExpression);
int distinctCount = dvs.getTupleBuffer().getRowCount();
- if (setState.maxNdv > 0 && setState.maxNdv < distinctCount) {
- if (dvs.getTupleBuffer().getSchema().size() >= 1) {
- distinctCount = 0;
- ValueIterator vi = dvs.getValueIterator(setState.valueExpression);
- Comparable last = null;
+ if (setState.maxNdv <= 0 || setState.maxNdv >= distinctCount) {
+ continue;
+ }
+ if (dvs.getTupleBuffer().getSchema().size() > 1) {
+ distinctCount = 0;
+ ValueIterator vi = dvs.getValueIterator(setState.valueExpression);
+ if (dvs.getTupleBuffer().getSchema().indexOf(setState.valueExpression) == 0) {
+ Object last = null;
while (vi.hasNext()) {
- Comparable next = (Comparable) vi.next();
- if (last == null || next.compareTo(last) != 0) {
- distinctCount++;
- }
- last = next;
- }
+ Object next = vi.next();
+ if (next != null && (last == null || ((Comparable)next).compareTo(last) != 0)) {
+ distinctCount++;
+ }
+ last = next;
+ }
+ } else {
+ //secondary attributes are not in sorted order, so we use an approximate count
+ Set<Object> set = new TreeSet<Object>();
+ int maxSize = Math.min(10000, dvs.getTupleBuffer().getRowCount());
+ List<Object> buffer = Arrays.asList(new Object[maxSize]);
+ int i = 0;
+ while (vi.hasNext()) {
+ Object next = vi.next();
+ if (next == null) {
+ continue;
+ }
+ if (set.add(next)) {
+ distinctCount++;
+ }
+ Object old = buffer.set(i++%maxSize, next);
+ if (set.size() > maxSize) {
+ set.remove(old);
+ }
+ }
}
- if (!setState.overMax && distinctCount > setState.maxNdv) {
- LogManager.logWarning(LogConstants.CTX_DQP, QueryPlugin.Util.getString("DependentCriteriaProcessor.dep_join_backoff", valueSource, setState.valueExpression, setState.maxNdv)); //$NON-NLS-1$
- setState.overMax = true;
- }
- }
+ }
+ if (!setState.overMax && distinctCount > setState.maxNdv) {
+ LogManager.logWarning(LogConstants.CTX_DQP, QueryPlugin.Util.getString("DependentCriteriaProcessor.dep_join_backoff", valueSource, setState.valueExpression, setState.maxNdv)); //$NON-NLS-1$
+ setState.overMax = true;
+ }
}
}
}
Modified: branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java
===================================================================
--- branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java 2012-06-19 14:13:44 UTC (rev 4187)
+++ branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java 2012-06-19 17:07:47 UTC (rev 4188)
@@ -572,6 +572,7 @@
metadata,
"pm1.g1", new List[] {
Arrays.asList(new Object[] { "a", new Integer(0), Boolean.FALSE, new Double(2.0) }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { "q", null, Boolean.FALSE, new Double(0.0) }), //$NON-NLS-1$
Arrays.asList(new Object[] { "b", new Integer(1), Boolean.TRUE, null }), //$NON-NLS-1$
Arrays.asList(new Object[] { "c", new Integer(2), Boolean.FALSE, new Double(0.0) }), //$NON-NLS-1$
} );
@@ -579,7 +580,7 @@
dataMgr.registerTuples(
metadata,
"pm6.g1", new List[] {
- Arrays.asList(new Object[] { "b", new Integer(0) }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { "b", 1 }), //$NON-NLS-1$
Arrays.asList(new Object[] { "d", new Integer(3) }), //$NON-NLS-1$
Arrays.asList(new Object[] { "e", new Integer(1) }), //$NON-NLS-1$
} );
@@ -842,7 +843,7 @@
FakeDataManager dataManager = helpTestBackoff(true);
//note that the dependent join was not actually performed
- assertEquals(new HashSet<String>(Arrays.asList("SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm6.g1.e1 FROM pm6.g1 ORDER BY pm6.g1.e1")),
+ assertEquals(new HashSet<String>(Arrays.asList("SELECT pm6.g1.e1, pm6.g1.e2 FROM pm6.g1 ORDER BY pm6.g1.e1, pm6.g1.e2", "SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1")),
new HashSet<String>(dataManager.getQueries()));
}
@@ -897,7 +898,7 @@
QueryMetadataException, TeiidComponentException,
TeiidProcessingException {
// Create query
- String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm6.g1 WHERE pm1.g1.e1=pm6.g1.e1"; //$NON-NLS-1$
+ String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm6.g1 WHERE pm1.g1.e1=pm6.g1.e1 and pm1.g1.e2=pm6.g1.e2"; //$NON-NLS-1$
// Construct data manager with data
FakeDataManager dataManager = new FakeDataManager();
@@ -908,10 +909,12 @@
RealMetadataFactory.setCardinality("pm1.g1", 1, fakeMetadata);
if (setNdv) {
fakeMetadata.getElementID("pm1.g1.e1").setDistinctValues(1);
+ fakeMetadata.getElementID("pm1.g1.e2").setDistinctValues(1);
}
RealMetadataFactory.setCardinality("pm6.g1", 1000, fakeMetadata);
if (setNdv) {
fakeMetadata.getElementID("pm6.g1.e1").setDistinctValues(1000);
+ fakeMetadata.getElementID("pm6.g1.e2").setDistinctValues(1000);
}
// Plan query
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
@@ -931,8 +934,8 @@
new String("b")})}; //$NON-NLS-1$
ProcessorPlan plan = TestOptimizer.helpPlan(sql, fakeMetadata, new String[] {
- "SELECT pm6.g1.e1 FROM pm6.g1 WHERE pm6.g1.e1 IN (<dependent values>) ORDER BY pm6.g1.e1",
- "SELECT pm1.g1.e1 FROM pm1.g1"
+ "SELECT pm6.g1.e1, pm6.g1.e2 FROM pm6.g1 WHERE (pm6.g1.e1 IN (<dependent values>)) AND (pm6.g1.e2 IN (<dependent values>)) ORDER BY pm6.g1.e1, pm6.g1.e2",
+ "SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1"
}, capFinder, ComparisonMode.EXACT_COMMAND_STRING);
// Run query
12 years, 6 months
teiid SVN: r4187 - in branches/7.4.x/engine/src: test/java/org/teiid/query/processor and 1 other directory.
by teiid-commits@lists.jboss.org
Author: jolee
Date: 2012-06-19 10:13:44 -0400 (Tue, 19 Jun 2012)
New Revision: 4187
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java
Log:
TEIID-2074: NPE with multi-column dependent join
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java 2012-06-19 02:20:38 UTC (rev 4186)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java 2012-06-19 14:13:44 UTC (rev 4187)
@@ -27,17 +27,21 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.common.buffer.BlockedException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.DataTypeManager;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.query.QueryPlugin;
@@ -108,22 +112,47 @@
}
for (SetState setState : dependentSetStates) {
setState.valueIterator = dvs.getValueIterator(setState.valueExpression);
- if (setState.maxNdv > 0 && setState.maxNdv < dvs.getTupleBuffer().getRowCount()) {
- ValueIterator vi = dvs.getValueIterator(setState.valueExpression);
- Comparable last = null;
- int distinctCount = 0;
- while (vi.hasNext()) {
- Comparable next = (Comparable) vi.next();
- if (last == null || next.compareTo(last) != 0) {
- distinctCount++;
+ int distinctCount = dvs.getTupleBuffer().getRowCount();
+ if (setState.maxNdv <= 0 || setState.maxNdv >= distinctCount) {
+ continue;
+ }
+ if (dvs.getTupleBuffer().getSchema().size() > 1) {
+ distinctCount = 0;
+ ValueIterator vi = dvs.getValueIterator(setState.valueExpression);
+ if (dvs.getTupleBuffer().getSchema().indexOf(setState.valueExpression) == 0) {
+ Object last = null;
+ while (vi.hasNext()) {
+ Object next = vi.next();
+ if (next != null && (last == null || ((Comparable)next).compareTo(last) != 0)) {
+ distinctCount++;
+ }
+ last = next;
}
- last = next;
+ } else {
+ //secondary attributes are not in sorted order, so we use an approximate count
+ Set<Object> set = new TreeSet<Object>();
+ int maxSize = Math.min(10000, dvs.getTupleBuffer().getRowCount());
+ List<Object> buffer = Arrays.asList(new Object[maxSize]);
+ int i = 0;
+ while (vi.hasNext()) {
+ Object next = vi.next();
+ if (next == null) {
+ continue;
+ }
+ if (set.add(next)) {
+ distinctCount++;
+ }
+ Object old = buffer.set(i++%maxSize, next);
+ if (set.size() > maxSize) {
+ set.remove(old);
+ }
+ }
}
- if (!setState.overMax && distinctCount > setState.maxNdv) {
- LogManager.logWarning(LogConstants.CTX_DQP, QueryPlugin.Util.getString("DependentCriteriaProcessor.dep_join_backoff", valueSource, setState.valueExpression, setState.maxNdv)); //$NON-NLS-1$
- setState.overMax = true;
- }
- }
+ }
+ if (!setState.overMax && distinctCount > setState.maxNdv) {
+ LogManager.logWarning(LogConstants.CTX_DQP, QueryPlugin.Util.getString("DependentCriteriaProcessor.dep_join_backoff", valueSource, setState.valueExpression, setState.maxNdv)); //$NON-NLS-1$
+ setState.overMax = true;
+ }
}
}
}
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java 2012-06-19 02:20:38 UTC (rev 4186)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java 2012-06-19 14:13:44 UTC (rev 4187)
@@ -571,6 +571,7 @@
metadata,
"pm1.g1", new List[] {
Arrays.asList(new Object[] { "a", new Integer(0), Boolean.FALSE, new Double(2.0) }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { "q", null, Boolean.FALSE, new Double(0.0) }), //$NON-NLS-1$
Arrays.asList(new Object[] { "b", new Integer(1), Boolean.TRUE, null }), //$NON-NLS-1$
Arrays.asList(new Object[] { "c", new Integer(2), Boolean.FALSE, new Double(0.0) }), //$NON-NLS-1$
} );
@@ -578,7 +579,7 @@
dataMgr.registerTuples(
metadata,
"pm6.g1", new List[] {
- Arrays.asList(new Object[] { "b", new Integer(0) }), //$NON-NLS-1$
+ Arrays.asList(new Object[] { "b", 1 }), //$NON-NLS-1$
Arrays.asList(new Object[] { "d", new Integer(3) }), //$NON-NLS-1$
Arrays.asList(new Object[] { "e", new Integer(1) }), //$NON-NLS-1$
} );
@@ -837,7 +838,7 @@
FakeDataManager dataManager = helpTestBackoff(true);
//note that the dependent join was not actually performed
- assertEquals(new HashSet<String>(Arrays.asList("SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm6.g1.e1 FROM pm6.g1 ORDER BY pm6.g1.e1")),
+ assertEquals(new HashSet<String>(Arrays.asList("SELECT pm6.g1.e1, pm6.g1.e2 FROM pm6.g1 ORDER BY pm6.g1.e1, pm6.g1.e2", "SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1")),
new HashSet<String>(dataManager.getQueries()));
}
@@ -852,7 +853,7 @@
QueryMetadataException, TeiidComponentException,
TeiidProcessingException {
// Create query
- String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm6.g1 WHERE pm1.g1.e1=pm6.g1.e1"; //$NON-NLS-1$
+ String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm6.g1 WHERE pm1.g1.e1=pm6.g1.e1 and pm1.g1.e2=pm6.g1.e2"; //$NON-NLS-1$
// Construct data manager with data
FakeDataManager dataManager = new FakeDataManager();
@@ -863,10 +864,12 @@
RealMetadataFactory.setCardinality("pm1.g1", 1, fakeMetadata);
if (setNdv) {
fakeMetadata.getElementID("pm1.g1.e1").setDistinctValues(1);
+ fakeMetadata.getElementID("pm1.g1.e2").setDistinctValues(1);
}
RealMetadataFactory.setCardinality("pm6.g1", 1000, fakeMetadata);
if (setNdv) {
fakeMetadata.getElementID("pm6.g1.e1").setDistinctValues(1000);
+ fakeMetadata.getElementID("pm6.g1.e2").setDistinctValues(1000);
}
// Plan query
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
@@ -886,8 +889,8 @@
new String("b")})}; //$NON-NLS-1$
ProcessorPlan plan = TestOptimizer.helpPlan(sql, fakeMetadata, new String[] {
- "SELECT pm6.g1.e1 FROM pm6.g1 WHERE pm6.g1.e1 IN (<dependent values>) ORDER BY pm6.g1.e1",
- "SELECT pm1.g1.e1 FROM pm1.g1"
+ "SELECT pm6.g1.e1, pm6.g1.e2 FROM pm6.g1 WHERE (pm6.g1.e1 IN (<dependent values>)) AND (pm6.g1.e2 IN (<dependent values>)) ORDER BY pm6.g1.e1, pm6.g1.e2",
+ "SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1"
}, capFinder, ComparisonMode.EXACT_COMMAND_STRING);
// Run query
12 years, 6 months
teiid SVN: r4186 - in trunk: connectors/translator-jpa/src/main/java/org/teiid/translator/jpa and 6 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-06-18 22:20:38 -0400 (Mon, 18 Jun 2012)
New Revision: 4186
Modified:
trunk/api/src/main/java/org/teiid/metadata/ColumnSet.java
trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java
trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPAMetadataProcessor.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/MetadataProcessor.java
trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java
trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
trunk/runtime/src/main/java/org/teiid/deployers/EventDistributorImpl.java
trunk/runtime/src/test/java/org/teiid/runtime/TestEmbeddedServer.java
Log:
TEIID-2078 minor metadata enhancements
Modified: trunk/api/src/main/java/org/teiid/metadata/ColumnSet.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/ColumnSet.java 2012-06-19 00:14:18 UTC (rev 4185)
+++ trunk/api/src/main/java/org/teiid/metadata/ColumnSet.java 2012-06-19 02:20:38 UTC (rev 4186)
@@ -24,6 +24,8 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
public class ColumnSet<T extends AbstractMetadataRecord> extends AbstractMetadataRecord {
@@ -31,20 +33,46 @@
private List<Column> columns;
private T parent;
+ private transient Map<String, Column> columnMap;
public List<Column> getColumns() {
return columns;
}
+ /**
+ * Get the {@link Column} via a case-insensitive lookup
+ * @param name
+ * @return the {@link Column} or null if it doesn't exist
+ */
+ public Column getColumnByName(String name) {
+ if (columns == null) {
+ return null;
+ }
+ Map<String, Column> map = columnMap;
+ if (map == null) {
+ map = new TreeMap<String, Column>();
+ for (Column c : columns) {
+ map.put(c.getName(), c);
+ }
+ columnMap = map;
+ }
+ return map.get(name);
+ }
+
public void addColumn(Column column) {
if (columns == null) {
columns = new ArrayList<Column>();
}
columns.add(column);
+ Map<String, Column> map = columnMap;
+ if (map != null) {
+ map.put(column.getName(), column);
+ }
}
public void setColumns(List<Column> columns) {
this.columns = columns;
+ columnMap = null;
}
@Override
Modified: trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java 2012-06-19 00:14:18 UTC (rev 4185)
+++ trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java 2012-06-19 02:20:38 UTC (rev 4186)
@@ -115,6 +115,9 @@
//TODO: for now this is not used
throw new TranslatorException(DataPlugin.Event.TEIID60008, DataPlugin.Util.gs(DataPlugin.Event.TEIID60008, name));
}
+ if (table.getColumnByName(name) != null) {
+ throw new DuplicateRecordException(DataPlugin.Util.gs(DataPlugin.Event.TEIID60013, table.getFullName() + AbstractMetadataRecord.NAME_DELIM_CHAR + name));
+ }
Column column = new Column();
column.setName(name);
table.addColumn(column);
@@ -302,17 +305,11 @@
private void assignColumns(List<String> columnNames, Table table,
ColumnSet<?> columns) throws TranslatorException {
for (String columnName : columnNames) {
- boolean match = false;
- for (Column column : table.getColumns()) {
- if (column.getName().equals(columnName)) {
- match = true;
- columns.getColumns().add(column);
- break;
- }
+ Column column = table.getColumnByName(columnName);
+ if (column == null) {
+ throw new TranslatorException(DataPlugin.Event.TEIID60011, DataPlugin.Util.gs(DataPlugin.Event.TEIID60011, columnName));
}
- if (!match) {
- throw new TranslatorException(DataPlugin.Event.TEIID60011, DataPlugin.Util.gs(DataPlugin.Event.TEIID60011, columnName));
- }
+ columns.getColumns().add(column);
}
}
Modified: trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPAMetadataProcessor.java
===================================================================
--- trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPAMetadataProcessor.java 2012-06-19 00:14:18 UTC (rev 4185)
+++ trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPAMetadataProcessor.java 2012-06-19 02:20:38 UTC (rev 4186)
@@ -117,15 +117,7 @@
}
private boolean columnExists(String name, Table table) {
- if (table.getColumns() == null) {
- return false;
- }
- for (Column existingColumn: table.getColumns()) {
- if (existingColumn.getName().equals(name)) {
- return true;
- }
- }
- return false;
+ return table.getColumnByName(name) != null;
}
private Column addColumn(MetadataFactory mf, String name, String type, Table entityTable) throws TranslatorException {
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/MetadataProcessor.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/MetadataProcessor.java 2012-06-19 00:14:18 UTC (rev 4185)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/MetadataProcessor.java 2012-06-19 02:20:38 UTC (rev 4186)
@@ -99,8 +99,8 @@
Column col = null;
columns = child.getColumns();
- for (Iterator colIter = columns.iterator(); colIter.hasNext();) {
- Column column = (Column) colIter.next();
+ for (Iterator<Column> colIter = columns.iterator(); colIter.hasNext();) {
+ Column column = colIter.next();
if(column.getName().equals(relationship.getForeignKeyField())) {
col = column;
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java 2012-06-19 00:14:18 UTC (rev 4185)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/MetadataValidator.java 2012-06-19 02:20:38 UTC (rev 4186)
@@ -247,13 +247,10 @@
private static Column addColumn(String name, Datatype type, Table table) throws TranslatorException {
Column column = new Column();
column.setName(name);
- if (table.getColumns() != null) {
- for (Column c:table.getColumns()) {
- if (c.getName().equalsIgnoreCase(name)) {
- throw new TranslatorException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31087, name, table.getFullName()));
- }
- }
+ if (table.getColumnByName(name) != null) {
+ throw new TranslatorException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31087, name, table.getFullName()));
}
+ column.setUpdatable(table.supportsUpdate());
table.addColumn(column);
column.setPosition(table.getColumns().size()); //1 based indexing
if (type == null) {
Modified: trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2012-06-19 00:14:18 UTC (rev 4185)
+++ trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2012-06-19 02:20:38 UTC (rev 4186)
@@ -544,10 +544,9 @@
}
Column getColumn(String columnName, Table table) throws ParseException {
- for (Column col:table.getColumns()) {
- if (col.getName().equalsIgnoreCase(columnName)) {
- return col;
- }
+ Column c = table.getColumnByName(columnName);
+ if (c != null) {
+ return c;
}
throw new ParseException(QueryPlugin.Util.getString("SQLParser.no_column", columnName, table.getName())); //$NON-NLS-1$
}
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-06-19 00:14:18 UTC (rev 4185)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-06-19 02:20:38 UTC (rev 4186)
@@ -4267,6 +4267,11 @@
}
table.setSelectTransformation(query.toString());
}
+ if (!table.supportsUpdate() && table.getColumns() != null) {
+ for (Column c : table.getColumns()) {
+ c.setUpdatable(false);
+ }
+ }
}
}
@@ -4413,6 +4418,7 @@
{
try{
column = factory.addColumn(validateElementName(element), type.type, table);
+ column.setUpdatable(true);
if (type.length != null){
column.setLength(type.length);
}
@@ -4487,11 +4493,15 @@
}
{
key = id()
- ((value = stringVal())
+ (value = stringVal()
|
- (t = <INTEGERVAL>)
+ t = <INTEGERVAL>
|
- (t = <DECIMALVAL>))
+ t = <DECIMALVAL>
+ |
+ t = <TRUE>
+ |
+ t = <FALSE>)
{
if (t != null) {
value = t.image;
Modified: trunk/runtime/src/main/java/org/teiid/deployers/EventDistributorImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/EventDistributorImpl.java 2012-06-19 00:14:18 UTC (rev 4185)
+++ trunk/runtime/src/main/java/org/teiid/deployers/EventDistributorImpl.java 2012-06-19 02:20:38 UTC (rev 4186)
@@ -35,8 +35,8 @@
import org.teiid.metadata.Procedure;
import org.teiid.metadata.Schema;
import org.teiid.metadata.Table;
-import org.teiid.metadata.Table.TriggerEvent;
import org.teiid.metadata.TableStats;
+import org.teiid.metadata.Table.TriggerEvent;
import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.optimizer.relational.RelationalPlanner;
import org.teiid.query.processor.DdlPlan;
@@ -96,12 +96,10 @@
if (t == null) {
return;
}
- for (Column c : t.getColumns()) {
- if (c.getName().equalsIgnoreCase(columnName)) {
- c.setColumnStats(stats);
- t.setLastModified(System.currentTimeMillis());
- break;
- }
+ Column c = t.getColumnByName(columnName);
+ if (c != null) {
+ c.setColumnStats(stats);
+ t.setLastModified(System.currentTimeMillis());
}
}
Modified: trunk/runtime/src/test/java/org/teiid/runtime/TestEmbeddedServer.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/runtime/TestEmbeddedServer.java 2012-06-19 00:14:18 UTC (rev 4185)
+++ trunk/runtime/src/test/java/org/teiid/runtime/TestEmbeddedServer.java 2012-06-19 02:20:38 UTC (rev 4186)
@@ -171,7 +171,7 @@
mmd1.setName("virt");
mmd1.setModelType(Type.VIRTUAL);
mmd1.setSchemaSourceType("ddl");
- mmd1.setSchemaText("create view \"my-view\" (\"my-column\" string OPTIONS (UPDATABLE 'true')) OPTIONS (UPDATABLE 'true') as select * from \"my-table\"");
+ mmd1.setSchemaText("create view \"my-view\" OPTIONS (UPDATABLE 'true') as select * from \"my-table\"");
es.deployVDB("test", Arrays.asList(mmd, mmd1));
12 years, 6 months