teiid SVN: r4282 - in trunk: test-integration/common/src/test/java/org/teiid/transport and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-07-31 14:44:07 -0400 (Tue, 31 Jul 2012)
New Revision: 4282
Modified:
trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java
Log:
TEIID-2096 fix for inappropriate cast handling
Modified: trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2012-07-31 17:19:19 UTC (rev 4281)
+++ trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2012-07-31 18:44:07 UTC (rev 4282)
@@ -69,6 +69,8 @@
public class ODBCServerRemoteImpl implements ODBCServerRemote {
private static final String UNNAMED = "UNNAMED"; //$NON-NLS-1$
+ private static Pattern pgToastLiteral = Pattern.compile("'pg_toast'");//$NON-NLS-1$
+ private static Pattern pgCast = Pattern.compile("(\\s[^']+)::[A-Za-z0-9]*"); //$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$
@@ -618,8 +620,9 @@
return "SELECT 0"; //$NON-NLS-1$
}
//these are somewhat dangerous
- modified = modified.replaceAll("::[A-Za-z0-9]*", " "); //$NON-NLS-1$ //$NON-NLS-2$
- modified = modified.replaceAll("'pg_toast'", "'SYS'"); //$NON-NLS-1$ //$NON-NLS-2$
+ modified = pgCast.matcher(modified).replaceAll("$1"); //$NON-NLS-1$
+ //TODO: use an appropriate cast
+ modified = pgToastLiteral.matcher(modified).replaceAll("'SYS'"); //$NON-NLS-1$
return modified;
}
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-07-31 17:19:19 UTC (rev 4281)
+++ trunk/test-integration/common/src/test/java/org/teiid/transport/TestODBCSocketTransport.java 2012-07-31 18:44:07 UTC (rev 4282)
@@ -372,4 +372,16 @@
assertTrue(rs.next());
assertEquals("", rs.getString(1));
}
+
+ @Test public void testColons() throws Exception {
+ Statement s = conn.createStatement();
+ //make sure that we aren't mishandling the ::
+ ResultSet rs = s.executeQuery("select 'a::b'");
+ assertTrue(rs.next());
+ assertEquals("a::b", rs.getString(1));
+
+ rs = s.executeQuery("select name::varchar from tables where name = 'Columns'");
+ assertTrue(rs.next());
+ assertEquals("Columns", rs.getString(1));
+ }
}
12 years, 4 months
teiid SVN: r4281 - in trunk: runtime/src/main/java/org/teiid/deployers and 2 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-07-31 13:19:19 -0400 (Tue, 31 Jul 2012)
New Revision: 4281
Added:
trunk/runtime/src/test/java/org/teiid/deployers/TestVDBStatusChecker.java
Modified:
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidAttachments.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/TranslatorAdd.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/TranslatorDeployer.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java
trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java
trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java
trunk/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java
trunk/test-integration/common/src/test/resources/service-vdb.xml
Log:
TEIID-2121 expanding the fix and adding service cleanups
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidAttachments.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidAttachments.java 2012-07-31 16:35:27 UTC (rev 4280)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidAttachments.java 2012-07-31 17:19:19 UTC (rev 4281)
@@ -25,6 +25,7 @@
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.adminapi.impl.VDBTranslatorMetaData;
import org.teiid.deployers.UDFMetaData;
import org.teiid.metadata.index.IndexMetadataStore;
@@ -32,6 +33,7 @@
enum DeploymentType{VDB, DYNAMIC_VDB, TRANSLATOR};
+ public static final AttachmentKey<VDBTranslatorMetaData> TRANSLATOR_METADATA = AttachmentKey.create(VDBTranslatorMetaData.class);
public static final AttachmentKey<VDBMetaData> VDB_METADATA = AttachmentKey.create(VDBMetaData.class);
public static final AttachmentKey<UDFMetaData> UDF_METADATA = AttachmentKey.create(UDFMetaData.class);
public static final AttachmentKey<IndexMetadataStore> INDEX_METADATA = AttachmentKey.create(IndexMetadataStore.class);
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java 2012-07-31 16:35:27 UTC (rev 4280)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java 2012-07-31 17:19:19 UTC (rev 4281)
@@ -53,6 +53,7 @@
import org.jboss.jca.common.api.metadata.ra.ResourceAdapter1516;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
+import org.jboss.msc.service.ServiceRegistry;
import org.teiid.adminapi.Admin;
import org.teiid.adminapi.AdminException;
import org.teiid.adminapi.AdminProcessingException;
@@ -78,6 +79,7 @@
import org.teiid.deployers.RuntimeVDB;
import org.teiid.deployers.VDBRepository;
import org.teiid.deployers.VDBStatusChecker;
+import org.teiid.deployers.RuntimeVDB.ReplaceResult;
import org.teiid.dqp.internal.datamgr.TranslatorRepository;
import org.teiid.dqp.internal.process.DQPCore;
import org.teiid.dqp.internal.process.DQPWorkContext;
@@ -89,6 +91,7 @@
import org.teiid.query.metadata.DDLStringVisitor;
import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.tempdata.TempTableDataManager;
+import org.teiid.vdb.runtime.VDBKey;
abstract class TeiidOperationHandler extends BaseOperationHandler<DQPCore> {
List<TransportService> transports = new ArrayList<TransportService>();
@@ -639,7 +642,7 @@
String dsName = operation.get(OperationsConstants.DS_NAME).asString();
ServiceController<?> sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.VDB_STATUS_CHECKER);
VDBStatusChecker vsc = VDBStatusChecker.class.cast(sc.getValue());
- vsc.dataSourceAdded(dsName);
+ vsc.dataSourceAdded(dsName, null);
}
protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
@@ -1383,7 +1386,22 @@
String dsName = operation.get(OperationsConstants.DS_NAME).asString();
try {
- vdb.assignDatasource(modelName, sourceName, translatorName, dsName);
+ synchronized (vdb.getVdb()) {
+ ReplaceResult rr = vdb.assignDatasource(modelName, sourceName, translatorName, dsName);
+ if (rr.isNew) {
+ ServiceController<?> sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.VDB_STATUS_CHECKER);
+ VDBStatusChecker vsc = VDBStatusChecker.class.cast(sc.getValue());
+ VDBDeployer.addDataSourceListener(context.getServiceTarget(), new VDBKey(vdb.getVdb().getName(), vdb.getVdb().getVersion()), dsName, vsc);
+ }
+ if (rr.removedDs != null) {
+ final ServiceRegistry registry = context.getServiceRegistry(true);
+ final ServiceName serviceName = TeiidServiceNames.dsListenerServiceName(vdb.getVdb().getName(), vdb.getVdb().getVersion(), rr.removedDs);
+ final ServiceController<?> controller = registry.getService(serviceName);
+ if (controller != null) {
+ context.removeService(serviceName);
+ }
+ }
+ }
} catch (AdminProcessingException e) {
throw new OperationFailedException(new ModelNode().set(e.getMessage()));
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidServiceNames.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidServiceNames.java 2012-07-31 16:35:27 UTC (rev 4280)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidServiceNames.java 2012-07-31 17:19:19 UTC (rev 4281)
@@ -22,6 +22,7 @@
package org.teiid.jboss;
import org.jboss.msc.service.ServiceName;
+import org.teiid.deployers.VDBStatusChecker;
public class TeiidServiceNames {
public static ServiceName ENGINE = ServiceName.JBOSS.append("teiid", "query-engine"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -75,6 +76,6 @@
}
public static ServiceName dsListenerServiceName(String vdbName, int version, String name) {
- return ServiceName.of(DS_LISTENER_BASE, vdbName, String.valueOf(version), name);
+ return ServiceName.of(DS_LISTENER_BASE, vdbName, String.valueOf(version), VDBStatusChecker.stripContext(name));
}
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/TranslatorAdd.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/TranslatorAdd.java 2012-07-31 16:35:27 UTC (rev 4280)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/TranslatorAdd.java 2012-07-31 17:19:19 UTC (rev 4281)
@@ -21,11 +21,7 @@
*/
package org.teiid.jboss;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIPTION;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_NAME;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REQUEST_PROPERTIES;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.*;
import java.util.List;
import java.util.Locale;
@@ -43,13 +39,10 @@
import org.jboss.modules.ModuleIdentifier;
import org.jboss.modules.ModuleLoadException;
import org.jboss.modules.ModuleLoader;
-import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceTarget;
import org.teiid.adminapi.impl.VDBTranslatorMetaData;
import org.teiid.deployers.TranslatorUtil;
-import org.teiid.deployers.VDBStatusChecker;
-import org.teiid.dqp.internal.datamgr.TranslatorRepository;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.translator.ExecutionFactory;
@@ -117,11 +110,7 @@
if (translatorName.equalsIgnoreCase(metadata.getName())) {
LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50006, metadata.getName()));
- TranslatorService translatorService = new TranslatorService(metadata);
- ServiceBuilder<VDBTranslatorMetaData> builder = target.addService(TeiidServiceNames.translatorServiceName(metadata.getName()), translatorService);
- builder.addDependency(TeiidServiceNames.TRANSLATOR_REPO, TranslatorRepository.class, translatorService.repositoryInjector);
- builder.addDependency(TeiidServiceNames.VDB_STATUS_CHECKER, VDBStatusChecker.class, translatorService.statusCheckerInjector);
- newControllers.add(builder.setInitialMode(ServiceController.Mode.ACTIVE).install());
+ TranslatorDeployer.buildService(target, metadata);
added = true;
break;
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/TranslatorDeployer.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/TranslatorDeployer.java 2012-07-31 16:35:27 UTC (rev 4280)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/TranslatorDeployer.java 2012-07-31 17:19:19 UTC (rev 4281)
@@ -32,7 +32,10 @@
import org.jboss.modules.Module;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
+import org.jboss.msc.service.ServiceName;
+import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.service.ServiceTarget;
+import org.jboss.msc.service.ServiceController.Mode;
import org.teiid.adminapi.impl.VDBTranslatorMetaData;
import org.teiid.deployers.TranslatorUtil;
import org.teiid.deployers.VDBStatusChecker;
@@ -66,21 +69,40 @@
if (metadata == null) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50070, moduleName));
}
- metadata.addProperty(TranslatorUtil.DEPLOYMENT_NAME, deploymentUnit.getName());
+ deploymentUnit.putAttachment(TeiidAttachments.TRANSLATOR_METADATA, metadata);
+ metadata.addProperty(TranslatorUtil.DEPLOYMENT_NAME, moduleName);
metadata.addAttchment(ClassLoader.class, translatorLoader);
LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50006, metadata.getName()));
- TranslatorService translatorService = new TranslatorService(metadata);
- ServiceBuilder<VDBTranslatorMetaData> builder = target.addService(TeiidServiceNames.translatorServiceName(metadata.getName()), translatorService);
- builder.addDependency(TeiidServiceNames.TRANSLATOR_REPO, TranslatorRepository.class, translatorService.repositoryInjector);
- builder.addDependency(TeiidServiceNames.VDB_STATUS_CHECKER, VDBStatusChecker.class, translatorService.statusCheckerInjector);
- builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
+ buildService(target, metadata);
}
}
}
+ static void buildService(final ServiceTarget target,
+ VDBTranslatorMetaData metadata) {
+ TranslatorService translatorService = new TranslatorService(metadata);
+ ServiceBuilder<VDBTranslatorMetaData> builder = target.addService(TeiidServiceNames.translatorServiceName(metadata.getName()), translatorService);
+ builder.addDependency(TeiidServiceNames.TRANSLATOR_REPO, TranslatorRepository.class, translatorService.repositoryInjector);
+ builder.addDependency(TeiidServiceNames.VDB_STATUS_CHECKER, VDBStatusChecker.class, translatorService.statusCheckerInjector);
+ builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
+ }
+
@Override
public void undeploy(final DeploymentUnit context) {
+ if (!TeiidAttachments.isTranslator(context)) {
+ return;
+ }
+ VDBTranslatorMetaData metadata = context.getAttachment(TeiidAttachments.TRANSLATOR_METADATA);
+ if (metadata == null) {
+ return;
+ }
+ final ServiceRegistry registry = context.getServiceRegistry();
+ final ServiceName serviceName = TeiidServiceNames.translatorServiceName(metadata.getName());
+ final ServiceController<?> controller = registry.getService(serviceName);
+ if (controller != null) {
+ controller.setMode(Mode.REMOVE);
+ }
}
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java 2012-07-31 16:35:27 UTC (rev 4280)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java 2012-07-31 17:19:19 UTC (rev 4281)
@@ -21,8 +21,10 @@
*/
package org.teiid.jboss;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
@@ -51,6 +53,7 @@
import org.teiid.adminapi.Translator;
import org.teiid.adminapi.VDBImport;
import org.teiid.adminapi.impl.ModelMetaData;
+import org.teiid.adminapi.impl.SourceMappingMetadata;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.adminapi.impl.VDBTranslatorMetaData;
import org.teiid.common.buffer.BufferManager;
@@ -66,6 +69,7 @@
import org.teiid.metadata.index.IndexMetadataStore;
import org.teiid.query.ObjectReplicator;
import org.teiid.query.metadata.TransformationMetadata.Resource;
+import org.teiid.vdb.runtime.VDBKey;
class VDBDeployer implements DeploymentUnitProcessor {
@@ -154,15 +158,7 @@
final ServiceBuilder<RuntimeVDB> vdbService = context.getServiceTarget().addService(TeiidServiceNames.vdbServiceName(deployment.getName(), deployment.getVersion()), vdb);
// add dependencies to data-sources
- dataSourceDependencies(deployment, new DependentServices() {
- @Override
- public void dependentService(final String dsName, final ServiceName svcName) {
- DataSourceListener dsl = new DataSourceListener(dsName, svcName, vdbStatusChecker);
- ServiceBuilder<DataSourceListener> sb = context.getServiceTarget().addService(TeiidServiceNames.dsListenerServiceName(deployment.getName(), deployment.getVersion(), dsName), dsl);
- sb.addDependency(svcName);
- sb.setInitialMode(Mode.PASSIVE).install();
- }
- });
+ dataSourceDependencies(deployment, context.getServiceTarget());
for (VDBImport vdbImport : deployment.getVDBImports()) {
vdbService.addDependency(TeiidServiceNames.vdbFinishedServiceName(vdbImport.getName(), vdbImport.getVersion()));
@@ -246,8 +242,22 @@
svc.install();
}
- private void dataSourceDependencies(VDBMetaData deployment, DependentServices svcListener) {
-
+ static void addDataSourceListener(
+ final ServiceTarget serviceTarget,
+ final VDBKey vdbKey,
+ final String dsName, VDBStatusChecker vdbStatusChecker) {
+ final String jndiName = getJndiName(dsName);
+ final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
+ final ServiceName svcName = bindInfo.getBinderServiceName();
+ DataSourceListener dsl = new DataSourceListener(dsName, svcName, vdbStatusChecker, vdbKey);
+ ServiceBuilder<DataSourceListener> sb = serviceTarget.addService(TeiidServiceNames.dsListenerServiceName(vdbKey.getName(), vdbKey.getVersion(), dsName), dsl);
+ sb.addDependency(svcName);
+ sb.setInitialMode(Mode.PASSIVE).install();
+ }
+
+ private void dataSourceDependencies(VDBMetaData deployment, ServiceTarget serviceTarget) {
+ final VDBKey vdbKey = new VDBKey(deployment.getName(), deployment.getVersion());
+ Set<String> dataSources = new HashSet<String>();
for (ModelMetaData model:deployment.getModelMetaDatas().values()) {
for (String sourceName:model.getSourceNames()) {
String translatorName = model.getSourceTranslatorName(sourceName);
@@ -261,25 +271,25 @@
if (dsName == null) {
continue;
}
- final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(getJndiName(dsName));
- svcListener.dependentService(dsName, bindInfo.getBinderServiceName());
+ if (!dataSources.add(VDBStatusChecker.stripContext(dsName))) {
+ continue; //already listening
+ }
+ addDataSourceListener(serviceTarget, vdbKey, dsName, vdbStatusChecker);
}
}
}
- interface DependentServices {
- void dependentService(String dsName, ServiceName svc);
- }
-
static class DataSourceListener implements Service<DataSourceListener>{
private VDBStatusChecker vdbStatusChecker;
private String dsName;
private ServiceName svcName;
+ private VDBKey vdb;
- public DataSourceListener(String dsName, ServiceName svcName, VDBStatusChecker checker) {
+ public DataSourceListener(String dsName, ServiceName svcName, VDBStatusChecker checker, VDBKey vdb) {
this.dsName = dsName;
this.svcName = svcName;
this.vdbStatusChecker = checker;
+ this.vdb = vdb;
}
public DataSourceListener getValue() throws IllegalStateException,IllegalArgumentException {
@@ -290,7 +300,7 @@
public void start(StartContext context) throws StartException {
ServiceController<?> s = context.getController().getServiceContainer().getService(this.svcName);
if (s != null) {
- this.vdbStatusChecker.dataSourceAdded(this.dsName);
+ this.vdbStatusChecker.dataSourceAdded(this.dsName, vdb);
}
}
@@ -298,12 +308,12 @@
public void stop(StopContext context) {
ServiceController<?> s = context.getController().getServiceContainer().getService(this.svcName);
if (s.getMode().equals(Mode.REMOVE) || s.getState().equals(State.STOPPING)) {
- this.vdbStatusChecker.dataSourceRemoved(this.dsName);
+ this.vdbStatusChecker.dataSourceRemoved(this.dsName, vdb);
}
}
}
- private String getJndiName(String name) {
+ public static String getJndiName(String name) {
String jndiName = name;
if (!name.startsWith(JAVA_CONTEXT)) {
jndiName = JAVA_CONTEXT + jndiName;
@@ -330,10 +340,9 @@
}
this.vdbStatusChecker.getVDBRepository().removeVDB(deployment.getName(), deployment.getVersion());
- for (Model model:deployment.getModels()) {
- List<String> sourceNames = model.getSourceNames();
- for (String sourceName:sourceNames) {
- String dsName = model.getSourceConnectionJndiName(sourceName);
+ for (ModelMetaData model:deployment.getModelMetaDatas().values()) {
+ for (SourceMappingMetadata smm:model.getSources().values()) {
+ String dsName = smm.getConnectionJndiName();
if (dsName == null) {
continue;
}
@@ -344,5 +353,10 @@
}
}
}
+
+ final ServiceController<?> controller = deploymentUnit.getServiceRegistry().getService(TeiidServiceNames.vdbServiceName(deployment.getName(), deployment.getVersion()));
+ if (controller != null) {
+ controller.setMode(ServiceController.Mode.REMOVE);
+ }
}
}
Modified: trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2012-07-31 16:35:27 UTC (rev 4280)
+++ trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2012-07-31 17:19:19 UTC (rev 4281)
@@ -125,7 +125,7 @@
this.children = new LinkedHashMap<VDBKey, CompositeVDB>();
newMergedVDB.setImportedModels(new TreeSet<String>(String.CASE_INSENSITIVE_ORDER));
for (VDBImport vdbImport : vdb.getVDBImports()) {
- CompositeVDB importedVDB = vdbRepository.getCompositeVDB(vdbImport.getName(), vdbImport.getVersion());
+ CompositeVDB importedVDB = vdbRepository.getCompositeVDB(new VDBKey(vdbImport.getName(), vdbImport.getVersion()));
if (importedVDB == null) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40083, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40083, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion()));
}
Modified: trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java 2012-07-31 16:35:27 UTC (rev 4280)
+++ trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java 2012-07-31 17:19:19 UTC (rev 4281)
@@ -29,6 +29,8 @@
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.SourceMappingMetadata;
import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.dqp.internal.datamgr.ConnectorManager;
+import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
import org.teiid.runtime.RuntimePlugin;
public abstract class RuntimeVDB {
@@ -36,6 +38,11 @@
private VDBModificationListener listener;
private boolean restartInProgress = false;
+ public static class ReplaceResult {
+ public boolean isNew;
+ public String removedDs;
+ }
+
public interface VDBModificationListener {
void dataRoleChanged(String policyName) throws AdminProcessingException;
void connectionTypeChanged() throws AdminProcessingException;
@@ -117,7 +124,7 @@
}
}
- public void assignDatasource(String modelName, String sourceName, String translatorName, String dsName) throws AdminProcessingException{
+ public ReplaceResult assignDatasource(String modelName, String sourceName, String translatorName, String dsName) throws AdminProcessingException{
synchronized (this.vdb) {
ModelMetaData model = this.vdb.getModel(modelName);
@@ -138,7 +145,16 @@
try {
this.listener.dataSourceChanged(modelName, sourceName, translatorName, dsName);
- getVDBStatusChecker().dataSourceReplaced(vdb.getName(), vdb.getVersion(), modelName, sourceName, translatorName, dsName);
+ ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
+ ReplaceResult rr = new ReplaceResult();
+ if (dsName != null) {
+ rr.isNew = !dsExists(dsName, cmr);
+ }
+ boolean replaced = getVDBStatusChecker().dataSourceReplaced(vdb.getName(), vdb.getVersion(), modelName, sourceName, translatorName, dsName);
+ if (replaced && previousDsName != null && !dsExists(previousDsName, cmr)) {
+ rr.removedDs = previousDsName;
+ }
+ return rr;
} catch(AdminProcessingException e) {
source.setTranslatorName(previousTranslatorName);
source.setConnectionJndiName(previousDsName);
@@ -146,6 +162,16 @@
}
}
}
+
+ private boolean dsExists(String dsName, ConnectorManagerRepository cmr) {
+ String baseDsName = VDBStatusChecker.stripContext(dsName);
+ for (ConnectorManager cm : cmr.getConnectorManagers().values()) {
+ if (baseDsName.equals(VDBStatusChecker.stripContext(cm.getConnectionName()))) {
+ return true;
+ }
+ }
+ return false;
+ }
public void restart(List<String> modelNames) throws AdminProcessingException {
synchronized(this.vdb) {
@@ -168,5 +194,9 @@
return this.restartInProgress;
}
+ public VDBMetaData getVdb() {
+ return vdb;
+ }
+
protected abstract VDBStatusChecker getVDBStatusChecker();
}
Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2012-07-31 16:35:27 UTC (rev 4280)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2012-07-31 17:19:19 UTC (rev 4281)
@@ -150,8 +150,8 @@
}
}
- CompositeVDB getCompositeVDB(String name, int version) {
- return this.vdbRepo.get(new VDBKey(name, version));
+ CompositeVDB getCompositeVDB(VDBKey key) {
+ return this.vdbRepo.get(key);
}
/**
@@ -161,7 +161,7 @@
* @return
*/
public VDBMetaData getLiveVDB(String name, int version) {
- CompositeVDB v = getCompositeVDB(name, version);
+ CompositeVDB v = this.vdbRepo.get(new VDBKey(name, version));
if (v != null) {
return v.getVDB();
}
Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java 2012-07-31 16:35:27 UTC (rev 4280)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java 2012-07-31 17:19:19 UTC (rev 4281)
@@ -22,6 +22,7 @@
package org.teiid.deployers;
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Executor;
@@ -40,6 +41,7 @@
import org.teiid.logging.LogManager;
import org.teiid.runtime.RuntimePlugin;
import org.teiid.translator.ExecutionFactory;
+import org.teiid.vdb.runtime.VDBKey;
public abstract class VDBStatusChecker {
@@ -58,30 +60,84 @@
public void translatorRemoved(String translatorName) {
}
- public void dataSourceAdded(String dataSourceName) {
+ public void dataSourceAdded(String dataSourceName, VDBKey vdbKey) {
+ dataSourceName = stripContext(dataSourceName);
+ if (vdbKey == null) {
+ //scan all
+ resourceAdded(dataSourceName);
+ } else {
+ CompositeVDB cvdb = getVDBRepository().getCompositeVDB(vdbKey);
+ if (cvdb == null) {
+ return;
+ }
+ VDBMetaData vdb = cvdb.getVDB();
+ resourceAdded(dataSourceName, new LinkedList<Runnable>(), vdb);
+ }
+ }
+
+ public static String stripContext(String dataSourceName) {
+ if (dataSourceName == null) {
+ return null;
+ }
if (dataSourceName.startsWith(JAVA_CONTEXT)) {
dataSourceName = dataSourceName.substring(5);
}
- resourceAdded(dataSourceName);
+ return dataSourceName;
}
- public void dataSourceRemoved(String dataSourceName) {
- if (dataSourceName.startsWith(JAVA_CONTEXT)) {
- dataSourceName = dataSourceName.substring(5);
+ /**
+ *
+ * @param dataSourceName
+ * @param vdbKey which cannot be null
+ */
+ public void dataSourceRemoved(String dataSourceName, VDBKey vdbKey) {
+ dataSourceName = stripContext(dataSourceName);
+ CompositeVDB cvdb = getVDBRepository().getCompositeVDB(vdbKey);
+ if (cvdb == null) {
+ return;
}
- resourceRemoved(dataSourceName);
+ VDBMetaData vdb = cvdb.getVDB();
+ if (vdb.getStatus() == Status.FAILED) {
+ return;
+ }
+ synchronized (vdb) {
+ ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
+ for (ModelMetaData model:vdb.getModelMetaDatas().values()) {
+ String sourceName = getSourceName(dataSourceName, model);
+ if (sourceName == null) {
+ continue;
+ }
+ Severity severity = Severity.WARNING;
+ ConnectorManager cm = cmr.getConnectorManager(sourceName);
+ if (cm.getExecutionFactory().isSourceRequired() && vdb.getStatus() == Status.ACTIVE) {
+ severity = Severity.ERROR;
+ }
+ String msg = RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40012, vdb.getName(), vdb.getVersion(), dataSourceName);
+ model.addRuntimeMessage(severity, msg);
+ LogManager.logInfo(LogConstants.CTX_RUNTIME, msg);
+ }
+ }
}
- public void dataSourceReplaced(String vdbName, int vdbVersion,
+ /**
+ *
+ * @param vdbName
+ * @param vdbVersion
+ * @param modelName
+ * @param sourceName
+ * @param translatorName
+ * @param dsName
+ * @return true if the datasource is new to the vdb
+ * @throws AdminProcessingException
+ */
+ public boolean dataSourceReplaced(String vdbName, int vdbVersion,
String modelName, String sourceName, String translatorName,
String dsName) throws AdminProcessingException {
- if (dsName.startsWith(JAVA_CONTEXT)) {
- dsName = dsName.substring(5);
- }
+ dsName = stripContext(dsName);
VDBMetaData vdb = getVDBRepository().getLiveVDB(vdbName, vdbVersion);
- if (vdb.getStatus() == Status.FAILED) {
- return;
+ if (vdb == null || vdb.getStatus() == Status.FAILED) {
+ return false;
}
ModelMetaData model = vdb.getModel(modelName);
@@ -91,9 +147,11 @@
ExecutionFactory<Object, Object> ef = cm.getExecutionFactory();
boolean dsReplaced = false;
- if ((dsName != null && !dsName.equals(cm.getConnectionName())) || (dsName == null && cm.getConnectionName() != null)) {
+ String oldDsName = stripContext(cm.getConnectionName());
+ if ((dsName != null && !dsName.equals(oldDsName)) || (dsName == null && oldDsName != null)) {
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 = new ConnectorManager(translatorName, dsName);
+
cm.setExecutionFactory(ef);
cmr.addConnectorManager(sourceName, cm);
dsReplaced = true;
@@ -118,44 +176,49 @@
throw new AdminProcessingException(RuntimePlugin.Event.TEIID40033, e.getCause());
}
}
-
if (dsReplaced) {
ArrayList<Runnable> runnables = new ArrayList<Runnable>(1);
checkStatus(runnables, vdb, model, cm);
updateVDB(runnables, vdb);
}
+ return dsReplaced;
}
}
- public void resourceAdded(String resourceName) {
+ void resourceAdded(String resourceName) {
List<Runnable> runnables = new ArrayList<Runnable>();
for (CompositeVDB cvdb:getVDBRepository().getCompositeVDBs()) {
VDBMetaData vdb = cvdb.getVDB();
if (vdb.getStatus() == Status.FAILED) {
continue;
}
- synchronized (vdb) {
- ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
- boolean usesResourse = false;
- for (ModelMetaData model:vdb.getModelMetaDatas().values()) {
- if (!model.hasRuntimeMessages()) {
- continue;
- }
-
- String sourceName = getSourceName(resourceName, model);
- if (sourceName == null) {
- continue;
- }
+ resourceAdded(resourceName, runnables, vdb);
+ }
+ }
- usesResourse = true;
- ConnectorManager cm = cmr.getConnectorManager(sourceName);
- checkStatus(runnables, vdb, model, cm);
+ private void resourceAdded(String resourceName, List<Runnable> runnables,
+ VDBMetaData vdb) {
+ synchronized (vdb) {
+ ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
+ boolean usesResourse = false;
+ for (ModelMetaData model:vdb.getModelMetaDatas().values()) {
+ if (!model.hasRuntimeMessages()) {
+ return;
}
-
- if (usesResourse) {
- updateVDB(runnables, vdb);
+
+ String sourceName = getSourceName(resourceName, model);
+ if (sourceName == null) {
+ return;
}
+
+ usesResourse = true;
+ ConnectorManager cm = cmr.getConnectorManager(sourceName);
+ checkStatus(runnables, vdb, model, cm);
}
+
+ if (usesResourse) {
+ updateVDB(runnables, vdb);
+ }
}
}
@@ -189,41 +252,13 @@
}
}
- public void resourceRemoved(String resourceName) {
- for (CompositeVDB cvdb:getVDBRepository().getCompositeVDBs()) {
- VDBMetaData vdb = cvdb.getVDB();
- if (vdb.getStatus() == Status.FAILED) {
- continue;
- }
- synchronized (vdb) {
- ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
- for (ModelMetaData model:vdb.getModelMetaDatas().values()) {
- String sourceName = getSourceName(resourceName, model);
- if (sourceName == null) {
- continue;
- }
- Severity severity = Severity.WARNING;
- ConnectorManager cm = cmr.getConnectorManager(sourceName);
- if (cm.getExecutionFactory().isSourceRequired() && vdb.getStatus() == Status.ACTIVE) {
- severity = Severity.ERROR;
- }
- String msg = RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40012, vdb.getName(), vdb.getVersion(), resourceName);
- model.addRuntimeMessage(severity, msg);
- LogManager.logInfo(LogConstants.CTX_RUNTIME, msg);
- }
- }
- }
- }
-
private String getSourceName(String factoryName, ModelMetaData model) {
for (SourceMappingMetadata source:model.getSources().values()) {
String jndiName = source.getConnectionJndiName();
if (jndiName == null) {
continue;
}
- if (jndiName.startsWith(JAVA_CONTEXT)) {
- jndiName = jndiName.substring(5);
- }
+ jndiName = stripContext(jndiName);
if (factoryName.equals(jndiName)) {
return source.getName();
}
Modified: trunk/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java 2012-07-31 16:35:27 UTC (rev 4280)
+++ trunk/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java 2012-07-31 17:19:19 UTC (rev 4281)
@@ -65,7 +65,7 @@
return cvdb;
}
- private static VDBMetaData createVDBMetadata(MetadataStore metadataStore,
+ static VDBMetaData createVDBMetadata(MetadataStore metadataStore,
String vdbName) {
VDBMetaData vdbMetaData = new VDBMetaData();
vdbMetaData.setName(vdbName); //$NON-NLS-1$
Added: trunk/runtime/src/test/java/org/teiid/deployers/TestVDBStatusChecker.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/deployers/TestVDBStatusChecker.java (rev 0)
+++ trunk/runtime/src/test/java/org/teiid/deployers/TestVDBStatusChecker.java 2012-07-31 17:19:19 UTC (rev 4281)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.deployers;
+
+import static org.junit.Assert.*;
+
+import java.util.concurrent.Executor;
+
+import org.junit.Test;
+import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.dqp.internal.datamgr.ConnectorManager;
+import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
+import org.teiid.metadata.MetadataStore;
+import org.teiid.query.unittest.RealMetadataFactory;
+
+@SuppressWarnings("nls")
+public class TestVDBStatusChecker {
+
+ @Test public void testDataSourceReplaced() throws Exception {
+ final VDBRepository repo = new VDBRepository();
+ repo.setSystemFunctionManager(RealMetadataFactory.SFM);
+ repo.start();
+
+ VDBStatusChecker vsc = new VDBStatusChecker() {
+
+ @Override
+ public VDBRepository getVDBRepository() {
+ return repo;
+ }
+
+ @Override
+ public Executor getExecutor() {
+ return null;
+ }
+ };
+
+ assertFalse(vsc.dataSourceReplaced("x", 1, "y", "z", "t", "dsName"));
+
+ MetadataStore metadataStore = RealMetadataFactory.exampleBQTCached().getMetadataStore();
+ VDBMetaData vdb = TestCompositeVDB.createVDBMetadata(metadataStore, "bqt");
+
+ ConnectorManagerRepository cmr = new ConnectorManagerRepository();
+ cmr.addConnectorManager("BQT1", new ConnectorManager("oracle", "dsName"));
+ repo.addVDB(vdb, metadataStore, null, null, cmr);
+
+ assertTrue(vsc.dataSourceReplaced("bqt", 1, "BQT1", "BQT1", "oracle", "dsName1"));
+ assertFalse(vsc.dataSourceReplaced("bqt", 1, "BQT1", "BQT1", "oracle", "dsName1"));
+ }
+
+}
Property changes on: trunk/runtime/src/test/java/org/teiid/deployers/TestVDBStatusChecker.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/test-integration/common/src/test/resources/service-vdb.xml
===================================================================
--- trunk/test-integration/common/src/test/resources/service-vdb.xml 2012-07-31 16:35:27 UTC (rev 4280)
+++ trunk/test-integration/common/src/test/resources/service-vdb.xml 2012-07-31 17:19:19 UTC (rev 4281)
@@ -2,4 +2,7 @@
<model name="example">
<source name="jdbc-connector" translator-name="h2" connection-jndi-name="java:/ServiceDS"/>
</model>
+ <model name="example1">
+ <source name="jdbc-connector" translator-name="h2" connection-jndi-name="java:/ServiceDS"/>
+ </model>
</vdb>
\ No newline at end of file
12 years, 4 months
teiid SVN: r4280 - in trunk: test-integration/common/src/test/java/org/teiid/arquillian and 1 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2012-07-31 12:35:27 -0400 (Tue, 31 Jul 2012)
New Revision: 4280
Added:
trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestVDBSeviceCleanup.java
trunk/test-integration/common/src/test/resources/service-vdb.xml
Modified:
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java
Log:
TEIID-2121: removing the data source listener service upon undeploy of the vdb
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java 2012-07-31 13:13:50 UTC (rev 4279)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java 2012-07-31 16:35:27 UTC (rev 4280)
@@ -317,6 +317,7 @@
return;
}
+ final VDBMetaData deployment = deploymentUnit.getAttachment(TeiidAttachments.VDB_METADATA);
if (!this.shutdownListener.isShutdownInProgress()) {
final VDBMetaData vdb = deploymentUnit.getAttachment(TeiidAttachments.VDB_METADATA);
@@ -327,8 +328,21 @@
LogManager.logTrace(LogConstants.CTX_RUNTIME, "VDB "+vdb.getName()+" metadata removed"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
- final VDBMetaData deployment = deploymentUnit.getAttachment(TeiidAttachments.VDB_METADATA);
this.vdbStatusChecker.getVDBRepository().removeVDB(deployment.getName(), deployment.getVersion());
+
+ for (Model model:deployment.getModels()) {
+ List<String> sourceNames = model.getSourceNames();
+ for (String sourceName:sourceNames) {
+ String dsName = model.getSourceConnectionJndiName(sourceName);
+ if (dsName == null) {
+ continue;
+ }
+
+ final ServiceController<?> dsService = deploymentUnit.getServiceRegistry().getService(TeiidServiceNames.dsListenerServiceName(deployment.getName(), deployment.getVersion(), dsName));
+ if (dsService != null) {
+ dsService.setMode(ServiceController.Mode.REMOVE);
+ }
+ }
+ }
}
-
}
Added: trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestVDBSeviceCleanup.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestVDBSeviceCleanup.java (rev 0)
+++ trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestVDBSeviceCleanup.java 2012-07-31 16:35:27 UTC (rev 4280)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.arquillian;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.FileInputStream;
+import java.util.Properties;
+
+import org.jboss.arquillian.junit.Arquillian;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.teiid.adminapi.Admin;
+import org.teiid.adminapi.AdminException;
+import org.teiid.adminapi.AdminFactory;
+import org.teiid.core.util.UnitTestUtil;
+import org.teiid.jdbc.AbstractMMQueryTestCase;
+import org.teiid.jdbc.TeiidDriver;
+
+(a)RunWith(Arquillian.class)
+@SuppressWarnings("nls")
+public class IntegrationTestVDBSeviceCleanup extends AbstractMMQueryTestCase {
+
+ private Admin admin;
+
+ @Before
+ public void setup() throws Exception {
+ admin = AdminFactory.getInstance().createAdmin("localhost", 9999, "admin", "admin".toCharArray());
+ }
+
+ @After
+ public void teardown() throws AdminException {
+ AdminUtil.cleanUp(admin);
+ admin.close();
+ }
+
+ @Test
+ public void testServiceCleanup() throws Exception {
+ admin.deploy("service-vdb.xml",new FileInputStream(UnitTestUtil.getTestDataFile("service-vdb.xml")));
+
+ createDS("ServiceDS");
+
+ assertTrue(AdminUtil.waitForVDBLoad(admin, "service", 1, 3));
+
+ assertNotNull(TeiidDriver.getInstance().connect("jdbc:teiid:service@mm://localhost:31000;user=user;password=user", null));
+
+ admin.undeploy("service-vdb.xml");
+
+ admin.deleteDataSource("ServiceDS");
+
+ admin.deploy("service-vdb.xml",new FileInputStream(UnitTestUtil.getTestDataFile("service-vdb.xml")));
+
+ createDS("ServiceDS");
+
+ assertTrue(AdminUtil.waitForVDBLoad(admin, "service", 1, 3));
+
+ assertNotNull(TeiidDriver.getInstance().connect("jdbc:teiid:service@mm://localhost:31000;user=user;password=user", null));
+ }
+
+ private void createDS(String deployName) throws AdminException {
+ Properties props = new Properties();
+ props.setProperty("connection-url","jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
+ props.setProperty("user-name", "sa");
+ props.setProperty("password", "sa");
+ AdminUtil.createDataSource(admin, deployName, "h2", props);
+ }
+
+}
Property changes on: trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestVDBSeviceCleanup.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/test-integration/common/src/test/resources/service-vdb.xml
===================================================================
--- trunk/test-integration/common/src/test/resources/service-vdb.xml (rev 0)
+++ trunk/test-integration/common/src/test/resources/service-vdb.xml 2012-07-31 16:35:27 UTC (rev 4280)
@@ -0,0 +1,5 @@
+<vdb name="service" version= "1">
+ <model name="example">
+ <source name="jdbc-connector" translator-name="h2" connection-jndi-name="java:/ServiceDS"/>
+ </model>
+</vdb>
\ No newline at end of file
Property changes on: trunk/test-integration/common/src/test/resources/service-vdb.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
12 years, 4 months
teiid SVN: r4279 - in trunk/runtime/src: main/java/org/teiid/runtime and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-07-31 09:13:50 -0400 (Tue, 31 Jul 2012)
New Revision: 4279
Modified:
trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java
trunk/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java
Log:
TEIID-2115 fix for issue loading a document model
Modified: trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2012-07-30 23:32:11 UTC (rev 4278)
+++ trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2012-07-31 13:13:50 UTC (rev 4279)
@@ -62,8 +62,9 @@
private FunctionTree systemFunctions;
private boolean metadataloadFinished = false;
private VDBMetaData mergedVDB;
+ private VDBMetaData originalVDB;
- public CompositeVDB(VDBMetaData vdb, MetadataStore metadataStore, LinkedHashMap<String, Resource> visibilityMap, UDFMetaData udf, FunctionTree systemFunctions, ConnectorManagerRepository cmr, MetadataStore... additionalStores) {
+ public CompositeVDB(VDBMetaData vdb, MetadataStore metadataStore, LinkedHashMap<String, Resource> visibilityMap, UDFMetaData udf, FunctionTree systemFunctions, ConnectorManagerRepository cmr, VDBRepository vdbRepository, MetadataStore... additionalStores) throws VirtualDatabaseException {
this.vdb = vdb;
this.store = metadataStore;
this.visibilityMap = visibilityMap;
@@ -72,6 +73,8 @@
this.cmr = cmr;
this.additionalStores = additionalStores;
this.mergedVDB = vdb;
+ this.originalVDB = vdb;
+ buildCompositeState(vdbRepository);
}
private static TransformationMetadata buildTransformationMetaData(VDBMetaData vdb, LinkedHashMap<String, Resource> visibilityMap, MetadataStore store, UDFMetaData udf, FunctionTree systemFunctions, MetadataStore[] additionalStores) {
@@ -101,7 +104,7 @@
return this.mergedVDB;
}
- void buildCompositeState(VDBRepository vdbRepository) throws VirtualDatabaseException {
+ private void buildCompositeState(VDBRepository vdbRepository) throws VirtualDatabaseException {
if (vdb.getVDBImports().isEmpty()) {
this.vdb.addAttchment(ConnectorManagerRepository.class, this.cmr);
return;
@@ -308,7 +311,11 @@
metadataRepository.endLoadVdb(vdbName, vdbVersion);
}
- public synchronized void metadataLoadFinished() {
+ VDBMetaData getOriginalVDB() {
+ return originalVDB;
+ }
+
+ public void metadataLoadFinished() {
if (this.metadataloadFinished) {
return;
}
Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2012-07-30 23:32:11 UTC (rev 4278)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2012-07-31 13:13:50 UTC (rev 4279)
@@ -94,8 +94,7 @@
} else {
stores = new MetadataStore[] {this.systemStore, odbcStore};
}
- CompositeVDB cvdb = new CompositeVDB(vdb, metadataStore, visibilityMap, udf, this.systemFunctionManager.getSystemFunctions(), cmr, stores);
- cvdb.buildCompositeState(this);
+ CompositeVDB cvdb = new CompositeVDB(vdb, metadataStore, visibilityMap, udf, this.systemFunctionManager.getSystemFunctions(), cmr, this, stores);
lock.lock();
try {
if (vdbRepo.containsKey(key)) {
@@ -279,7 +278,10 @@
return;
}
VDBMetaData metadataAwareVDB = v.getVDB();
- if (metadataAwareVDB.getStatus() == Status.FAILED) {
+ if (v.getOriginalVDB().getStatus() == Status.FAILED) {
+ if (v.getOriginalVDB() != metadataAwareVDB && metadataAwareVDB.getStatus() == Status.LOADING) {
+ metadataAwareVDB.setStatus(Status.FAILED);
+ }
return;
}
v.metadataLoadFinished();
Modified: trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java 2012-07-30 23:32:11 UTC (rev 4278)
+++ trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java 2012-07-31 13:13:50 UTC (rev 4279)
@@ -136,9 +136,6 @@
}
else {
LogManager.logTrace(LogConstants.CTX_RUNTIME, "Model ", model.getName(), "in VDB ", vdb.getName(), " skipped being loaded because of its type ", model.getModelType()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- if (loadCount.decrementAndGet() == 0) {
- getVDBRepository().finishDeployment(vdb.getName(), vdb.getVersion());
- }
}
}
}
@@ -162,9 +159,10 @@
model.clearRuntimeMessages();
} else {
vdb.setStatus(Status.FAILED);
+ //TODO: abort the other loads
}
- if (loadCount.decrementAndGet() == 0) {
+ if (loadCount.decrementAndGet() == 0 || vdb.getStatus() == Status.FAILED) {
getVDBRepository().finishDeployment(vdb.getName(), vdb.getVersion());
}
}
Modified: trunk/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java 2012-07-30 23:32:11 UTC (rev 4278)
+++ trunk/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java 2012-07-31 13:13:50 UTC (rev 4279)
@@ -60,8 +60,7 @@
cmr.addConnectorManager("source", getConnectorManager("FakeTranslator", "FakeConnection", getFuncsOne()));
cmr.addConnectorManager("source2", getConnectorManager("FakeTranslator2", "FakeConnection2", getFuncsTwo()));
- CompositeVDB cvdb = new CompositeVDB(vdbMetaData, metadataStore, null, null, RealMetadataFactory.SFM.getSystemFunctions(),cmr);
- cvdb.buildCompositeState(null);
+ CompositeVDB cvdb = new CompositeVDB(vdbMetaData, metadataStore, null, null, RealMetadataFactory.SFM.getSystemFunctions(),cmr, null);
cvdb.metadataLoadFinished();
return cvdb;
}
12 years, 4 months
teiid SVN: r4278 - in trunk: test-integration/common/src/test/java/org/teiid/dqp/internal/process and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-07-30 19:32:11 -0400 (Mon, 30 Jul 2012)
New Revision: 4278
Modified:
trunk/engine/src/main/java/org/teiid/query/util/CommandContext.java
trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestExecutionReuse.java
Log:
TEIID-1598 fixing the isContinuous method
Modified: trunk/engine/src/main/java/org/teiid/query/util/CommandContext.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/util/CommandContext.java 2012-07-30 21:31:32 UTC (rev 4277)
+++ trunk/engine/src/main/java/org/teiid/query/util/CommandContext.java 2012-07-30 23:32:11 UTC (rev 4278)
@@ -760,7 +760,7 @@
@Override
public boolean isContinuous() {
- return globalState.reuseCount == null;
+ return globalState.reuseCount != null;
}
public void setContinuous() {
Modified: trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestExecutionReuse.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestExecutionReuse.java 2012-07-30 21:31:32 UTC (rev 4277)
+++ trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestExecutionReuse.java 2012-07-30 23:32:11 UTC (rev 4278)
@@ -99,6 +99,7 @@
@Before public void setup() throws DataNotAvailableException, TranslatorException {
execution = Mockito.mock(FakeReusableExecution.class);
+ ec = null;
OngoingStubbing stubbing = Mockito.stub(execution.next()).toReturn((List) Arrays.asList((Object)null)).toReturn(null);
for (int i = 1; i < EXEC_COUNT; i++) {
stubbing.toReturn((List<Object>) Arrays.asList((Object)null)).toReturn(null);
@@ -114,7 +115,9 @@
}
}).when(execution).dispose();
}
-
+
+ private static ExecutionContext ec;
+
@BeforeClass public static void oneTimeSetUp() throws Exception {
EmbeddedConfiguration config = new EmbeddedConfiguration();
config.setUserRequestSourceConcurrency(1);
@@ -129,6 +132,7 @@
ExecutionContext executionContext,
RuntimeMetadata metadata, Object connection)
throws TranslatorException {
+ ec = executionContext;
return execution;
};
};
@@ -187,6 +191,7 @@
}
}
assertEquals(EXEC_COUNT, result.get().intValue());
+ assertTrue(ec.getCommandContext().isContinuous());
Mockito.verify(execution, Mockito.times(1)).dispose();
Mockito.verify(execution, Mockito.times(EXEC_COUNT)).execute();
Mockito.verify(execution, Mockito.times(EXEC_COUNT)).close();
12 years, 4 months
teiid SVN: r4277 - in trunk/connectors/connector-ws/src/main: rar/META-INF and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2012-07-30 17:31:32 -0400 (Mon, 30 Jul 2012)
New Revision: 4277
Modified:
trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnectionImpl.java
trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSManagedConnectionFactory.java
trunk/connectors/connector-ws/src/main/rar/META-INF/ra.xml
Log:
TEIID-1714: adding a configuration property for timeout
Modified: trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnectionImpl.java
===================================================================
--- trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnectionImpl.java 2012-07-30 16:04:34 UTC (rev 4276)
+++ trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSConnectionImpl.java 2012-07-30 21:31:32 UTC (rev 4277)
@@ -276,6 +276,10 @@
dispatch.getRequestContext().put(Dispatch.PASSWORD_PROPERTY, mcf.getAuthPassword());
}
+ if (mcf.getRequestTimeout() != -1L){
+ dispatch.getRequestContext().put("javax.xml.ws.client.receiveTimeout", mcf.getRequestTimeout()); //$NON-NLS-1$
+ }
+
if (HTTPBinding.HTTP_BINDING.equals(binding)) {
Map<String, List<String>> httpHeaders = (Map<String, List<String>>)dispatch.getRequestContext().get(MessageContext.HTTP_REQUEST_HEADERS);
if(httpHeaders == null) {
Modified: trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSManagedConnectionFactory.java
===================================================================
--- trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSManagedConnectionFactory.java 2012-07-30 16:04:34 UTC (rev 4276)
+++ trunk/connectors/connector-ws/src/main/java/org/teiid/resource/adapter/ws/WSManagedConnectionFactory.java 2012-07-30 21:31:32 UTC (rev 4277)
@@ -54,6 +54,7 @@
private Bus bus;
private QName portQName;
private List<? extends Interceptor> outInterceptors;
+ private Long requestTimeout = -1L;
@SuppressWarnings("serial")
@Override
@@ -102,6 +103,14 @@
public void setEndPoint(String endPoint) {
this.endPoint = endPoint;
+ }
+
+ public Long getRequestTimeout() {
+ return this.requestTimeout;
+ }
+
+ public void setRequestTimeout(Long timeout) {
+ this.requestTimeout = timeout;
}
public SecurityType getAsSecurityType() {
Modified: trunk/connectors/connector-ws/src/main/rar/META-INF/ra.xml
===================================================================
--- trunk/connectors/connector-ws/src/main/rar/META-INF/ra.xml 2012-07-30 16:04:34 UTC (rev 4276)
+++ trunk/connectors/connector-ws/src/main/rar/META-INF/ra.xml 2012-07-30 21:31:32 UTC (rev 4277)
@@ -76,6 +76,12 @@
<config-property-name>ConfigName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
</config-property>
+
+ <config-property>
+ <description>{$display:"Request Timeout",$description:"Timeout for request"}</description>
+ <config-property-name>EndPoint</config-property-name>
+ <config-property-type>java.lang.Long</config-property-type>
+ </config-property>
<connectionfactory-interface>javax.resource.cci.ConnectionFactory</connectionfactory-interface>
<connectionfactory-impl-class>org.teiid.resource.spi.WrappedConnectionFactory</connectionfactory-impl-class>
12 years, 4 months
teiid SVN: r4276 - in trunk: engine/src/main/java/org/teiid/dqp/internal/datamgr and 6 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-07-30 12:04:34 -0400 (Mon, 30 Jul 2012)
New Revision: 4276
Added:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachingTupleSource.java
Modified:
trunk/api/src/main/java/org/teiid/translator/CacheDirective.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWork.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/AccessInfo.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/TupleSourceCache.java
trunk/engine/src/main/java/org/teiid/dqp/message/AtomicResultsMessage.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/MergeJoinStrategy.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/SourceState.java
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
trunk/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java
Log:
TEIID-1598 adding code support for the translator caching feature
Modified: trunk/api/src/main/java/org/teiid/translator/CacheDirective.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/CacheDirective.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/api/src/main/java/org/teiid/translator/CacheDirective.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -40,6 +40,7 @@
private Boolean prefersMemory;
private Boolean updatable;
+ private Boolean readAll;
private Long ttl;
private Scope scope;
@@ -75,6 +76,10 @@
this.ttl = ttl;
}
+ /**
+ * Get whether the result is updatable and therefore sensitive to data changes.
+ * @return
+ */
public Boolean getUpdatable() {
return updatable;
}
@@ -91,6 +96,18 @@
this.scope = scope;
}
+ /**
+ * Whether the engine should read and cache the entire results.
+ * @return
+ */
+ public Boolean getReadAll() {
+ return readAll;
+ }
+
+ public void setReadAll(Boolean readAll) {
+ this.readAll = readAll;
+ }
+
@Override
public boolean equals(Object obj) {
if (obj == this) {
@@ -100,7 +117,8 @@
return false;
}
CacheDirective other = (CacheDirective)obj;
- return EquivalenceUtil.areEqual(this.prefersMemory, other.prefersMemory)
+ return EquivalenceUtil.areEqual(this.prefersMemory, other.prefersMemory)
+ && EquivalenceUtil.areEqual(this.readAll, other.readAll)
&& EquivalenceUtil.areEqual(this.ttl, other.ttl)
&& EquivalenceUtil.areEqual(this.updatable, other.updatable)
&& EquivalenceUtil.areEqual(this.scope, other.scope);
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWork.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWork.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWork.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -49,5 +49,7 @@
boolean copyLobs();
CacheDirective getCacheDirective() throws TranslatorException;
+
+ boolean areLobsUsableAfterClose();
}
\ No newline at end of file
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-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -359,15 +359,21 @@
// if we need to keep the execution alive, then we can not support implicit close.
response.setSupportsImplicitClose(!this.securityContext.keepExecutionAlive());
- response.setTransactional(this.securityContext.isTransactional());
response.setWarnings(this.securityContext.getWarnings());
- response.setSupportsCloseWithLobs(this.connector.areLobsUsableAfterClose());
+ if (this.securityContext.getCacheDirective() != null) {
+ response.setScope(this.securityContext.getCacheDirective().getScope());
+ }
if ( lastBatch ) {
response.setFinalRow(rowCount);
}
return response;
}
+
+ @Override
+ public boolean areLobsUsableAfterClose() {
+ return this.connector.areLobsUsableAfterClose();
+ }
public static AtomicResultsMessage createResultsMessage(List<?>[] batch) {
return new AtomicResultsMessage(batch);
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/AccessInfo.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/AccessInfo.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/AccessInfo.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -91,6 +91,13 @@
return externalNames;
}
+ public void addAccessedObject(Object id) {
+ if (this.objectsAccessed == null) {
+ this.objectsAccessed = new HashSet<Object>();
+ }
+ this.objectsAccessed.add(id);
+ }
+
public Set<Object> getObjectsAccessed() {
return objectsAccessed;
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -40,7 +40,6 @@
import org.teiid.query.parser.QueryParser;
import org.teiid.query.processor.ProcessorPlan;
import org.teiid.query.resolver.QueryResolver;
-import org.teiid.query.sql.lang.CacheHint;
import org.teiid.query.sql.lang.Command;
@@ -50,7 +49,6 @@
private transient Command command;
private transient TupleBuffer results;
- private CacheHint hint;
private String uuid;
private boolean hasLobs;
private int rowLimit;
@@ -69,22 +67,15 @@
this.results = results;
this.uuid = results.getId();
this.hasLobs = results.isLobs();
- this.accessInfo.populate(plan.getContext(), true);
+ if (plan != null) {
+ this.accessInfo.populate(plan.getContext(), true);
+ }
}
public void setCommand(Command command) {
this.command = command;
- this.hint = command.getCacheHint();
}
- public void setHint(CacheHint hint) {
- this.hint = hint;
- }
-
- public CacheHint getHint() {
- return hint;
- }
-
public synchronized Command getCommand(String sql, QueryMetadataInterface metadata, ParseInfo info) throws QueryParserException, QueryResolverException, TeiidComponentException {
if (command == null) {
command = QueryParser.getQueryParser().parseCommand(sql, info);
Added: trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachingTupleSource.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachingTupleSource.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachingTupleSource.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -0,0 +1,163 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.dqp.internal.process;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.TupleBuffer;
+import org.teiid.common.buffer.TupleSource;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.dqp.internal.process.SessionAwareCache.CacheID;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.metadata.FunctionMethod.Determinism;
+import org.teiid.query.processor.RegisterRequestParameter;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.translator.CacheDirective;
+import org.teiid.translator.CacheDirective.Scope;
+
+/**
+ * A proxy {@link TupleSource} that caches a {@link DataTierTupleSource}
+ */
+final class CachingTupleSource extends
+ TupleSourceCache.BufferedTupleSource {
+ private final DataTierManagerImpl dataTierManagerImpl;
+ private final CacheID cid;
+ private final RegisterRequestParameter parameterObject;
+ private final CacheDirective cd;
+ private final Collection<GroupSymbol> accessedGroups;
+ private boolean cached = false;
+ private DataTierTupleSource dtts;
+
+ CachingTupleSource(DataTierManagerImpl dataTierManagerImpl, TupleBuffer tb, DataTierTupleSource ts, CacheID cid,
+ RegisterRequestParameter parameterObject, CacheDirective cd,
+ Collection<GroupSymbol> accessedGroups) {
+ super(tb, ts);
+ this.dataTierManagerImpl = dataTierManagerImpl;
+ this.dtts = ts;
+ this.cid = cid;
+ this.parameterObject = parameterObject;
+ this.cd = cd;
+ this.accessedGroups = accessedGroups;
+ }
+
+ @Override
+ public List<?> nextTuple() throws TeiidComponentException,
+ TeiidProcessingException {
+ if (dtts.scope == Scope.NONE || tb == null) {
+ removeTupleBuffer();
+ return ts.nextTuple();
+ }
+ //TODO: the cache directive object needs synchronized for consistency
+ List<?> tuple = super.nextTuple();
+ if (tuple == null && !cached && !dtts.errored) {
+ synchronized (cd) {
+ if (dtts.scope == Scope.NONE) {
+ removeTupleBuffer();
+ return tuple;
+ }
+ cached = true;
+ CachedResults cr = new CachedResults();
+ cr.setResults(tb, null);
+ if (!Boolean.FALSE.equals(cd.getUpdatable())) {
+ if (accessedGroups != null) {
+ for (GroupSymbol gs : accessedGroups) {
+ cr.getAccessInfo().addAccessedObject(gs.getMetadataID());
+ }
+ }
+ } else {
+ cr.getAccessInfo().setSensitiveToMetadataChanges(false);
+ }
+ if (parameterObject.limit > 0 && parameterObject.limit == rowNumber) {
+ cr.setRowLimit(rowNumber);
+ }
+ tb.setPrefersMemory(Boolean.TRUE.equals(cd.getPrefersMemory()));
+ Determinism determinismLevel = Determinism.SESSION_DETERMINISTIC;
+ if (dtts.scope != null) {
+ switch (dtts.scope) {
+ case VDB:
+ determinismLevel = Determinism.VDB_DETERMINISTIC;
+ case SESSION:
+ determinismLevel = Determinism.SESSION_DETERMINISTIC;
+ case USER:
+ determinismLevel = Determinism.USER_DETERMINISTIC;
+ }
+ }
+ this.dataTierManagerImpl.requestMgr.getRsCache().put(cid, determinismLevel, cr, cd.getTtl());
+ }
+ }
+ return tuple;
+ }
+
+ private void removeTupleBuffer() {
+ if (tb != null) {
+ tb.remove();
+ tb = null;
+ }
+ }
+
+ @Override
+ public void closeSource() {
+ try {
+ if (tb != null && !cached && !dtts.errored) {
+ boolean readAll = true;
+ synchronized (cd) {
+ readAll = !Boolean.FALSE.equals(cd.getReadAll());
+ }
+ if (readAll) {
+ //TODO that this is blocking, so it could be made faster in non-transactional scenarios
+ //we should also shut off any warnings, since the plan isn't consuming these tuples
+ //the approach would probably be to do more read-ahead
+ dtts.getAtomicRequestMessage().setSerial(true);
+ while (dtts.scope != Scope.NONE) {
+ try {
+ List<?> tuple = nextTuple();
+ if (tuple == null) {
+ break;
+ }
+ } catch (BlockedException e) {
+ //this is possible if were were already waiting for an asynch result
+ try {
+ Thread.sleep(50); //TODO: we could synch/notify in the DataTierTupleSource
+ } catch (InterruptedException e1) {
+ break;
+ }
+ } catch (TeiidException e) {
+ LogManager.logDetail(LogConstants.CTX_DQP, e, dtts.getAtomicRequestMessage().getAtomicRequestID(), "Not using full results due to error."); //$NON-NLS-1$
+ break;
+ }
+ }
+ }
+ }
+ } finally {
+ if (!cached) {
+ removeTupleBuffer();
+ }
+ ts.closeSource();
+ }
+ }
+}
\ No newline at end of file
Property changes on: trunk/engine/src/main/java/org/teiid/dqp/internal/process/CachingTupleSource.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -41,7 +41,9 @@
import org.teiid.client.RequestMessage;
import org.teiid.common.buffer.BlockedException;
import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.TupleBuffer;
import org.teiid.common.buffer.TupleSource;
+import org.teiid.common.buffer.BufferManager.TupleSourceType;
import org.teiid.core.CoreConstants;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
@@ -149,7 +151,7 @@
}
// Resources
- private DQPCore requestMgr;
+ DQPCore requestMgr;
private BufferManager bufferManager;
private EventDistributor eventDistributor;
private boolean detectChangeEvents;
@@ -172,7 +174,7 @@
return eventDistributor;
}
- public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException, TeiidProcessingException {
+ public TupleSource registerRequest(CommandContext context, Command command, String modelName, final RegisterRequestParameter parameterObject) throws TeiidComponentException, TeiidProcessingException {
RequestWorkItem workItem = requestMgr.getRequestWorkItem((RequestID)context.getProcessorID());
if(CoreConstants.SYSTEM_MODEL.equals(modelName) || CoreConstants.SYSTEM_ADMIN_MODEL.equals(modelName)) {
@@ -215,11 +217,11 @@
parameterObject.doNotCache = true;
} else {
String cmdString = command.toString();
- if (cmdString.length() < 200000) { //TODO: this check won't be needed if keys aren't exclusively held in memory
+ if (cmdString.length() < 100000) { //TODO: this check won't be needed if keys aren't exclusively held in memory
cid = new CacheID(workItem.getDqpWorkContext(), ParseInfo.DEFAULT_INSTANCE, cmdString);
cid.setParameters(cv.parameters);
CachedResults cr = workItem.getRsCache().get(cid);
- if (cr != null) {
+ if (cr != null && (cr.getRowLimit() == 0 || (parameterObject.limit > 0 && cr.getRowLimit() >= parameterObject.limit))) {
parameterObject.doNotCache = true;
LogManager.logDetail(LogConstants.CTX_DQP, "Using cache entry for", cid); //$NON-NLS-1$
work.close();
@@ -235,7 +237,12 @@
}
}
work.setRequestWorkItem(workItem);
- return new DataTierTupleSource(aqr, workItem, work, this, parameterObject.limit);
+ DataTierTupleSource dtts = new DataTierTupleSource(aqr, workItem, work, this, parameterObject.limit);
+ if (cid != null) {
+ TupleBuffer tb = getBufferManager().createTupleBuffer(aqr.getCommand().getProjectedSymbols(), aqr.getCommandContext().getConnectionId(), TupleSourceType.PROCESSOR);
+ return new CachingTupleSource(this, tb, dtts, cid, parameterObject, cd, accessedGroups);
+ }
+ return dtts;
}
/**
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -68,6 +68,7 @@
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.translator.DataNotAvailableException;
import org.teiid.translator.TranslatorException;
+import org.teiid.translator.CacheDirective.Scope;
/**
@@ -110,6 +111,9 @@
private volatile FutureWork<AtomicResultsMessage> futureResult;
private volatile boolean running;
+ boolean errored;
+ Scope scope; //this is to avoid synchronization
+
public DataTierTupleSource(AtomicRequestMessage aqr, RequestWorkItem workItem, ConnectorWork cwi, DataTierManagerImpl dtm, int limit) {
this.aqr = aqr;
this.workItem = workItem;
@@ -158,7 +162,7 @@
if (value == result && !DataTypeManager.DefaultDataClasses.OBJECT.equals(this.schema[i])) {
convertToRuntimeType[i] = false;
} else {
- if (isLob[i] && !cwi.copyLobs() && !arm.supportsCloseWithLobs() && DataTypeManager.isLOB(value.getClass())) {
+ if (isLob[i] && !cwi.copyLobs() && !cwi.areLobsUsableAfterClose() && DataTypeManager.isLOB(value.getClass())) {
explicitClose = true;
}
row.set(i, result);
@@ -224,8 +228,13 @@
public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException {
while (true) {
if (arm == null) {
+ if (isDone()) {
+ //sanity check
+ return null; //TODO: could throw an illegal state exception
+ }
boolean partial = false;
AtomicResultsMessage results = null;
+ boolean dna = false;
try {
if (futureResult != null || !aqr.isSerial()) {
results = asynchGet();
@@ -248,9 +257,11 @@
}
}
} catch (TranslatorException e) {
- results = exceptionOccurred(e, true);
+ errored = true;
+ results = exceptionOccurred(e);
partial = true;
} catch (DataNotAvailableException e) {
+ dna = true;
if (e.getRetryDelay() >= 0) {
workItem.scheduleWork(new Runnable() {
@Override
@@ -262,7 +273,11 @@
continue;
}
throw BlockedException.block(aqr.getAtomicRequestID(), "Blocking on DataNotAvailableException", aqr.getAtomicRequestID()); //$NON-NLS-1$
- }
+ } finally {
+ if (!dna && results == null) {
+ errored = true;
+ }
+ }
receiveResults(results, partial);
}
if (index < arm.getResults().length) {
@@ -412,16 +427,14 @@
}
}
- AtomicResultsMessage exceptionOccurred(TranslatorException exception, boolean removeState) throws TeiidComponentException, TeiidProcessingException {
- if (removeState) {
- fullyCloseSource();
- }
+ AtomicResultsMessage exceptionOccurred(TranslatorException exception) throws TeiidComponentException, TeiidProcessingException {
if(workItem.requestMsg.supportsPartialResults()) {
AtomicResultsMessage emptyResults = new AtomicResultsMessage(new List[0]);
emptyResults.setWarnings(Arrays.asList((Exception)exception));
emptyResults.setFinalRow(this.rowsProcessed);
return emptyResults;
}
+ fullyCloseSource();
if (exception.getCause() instanceof TeiidComponentException) {
throw (TeiidComponentException)exception.getCause();
}
@@ -433,6 +446,7 @@
void receiveResults(AtomicResultsMessage response, boolean partial) {
this.arm = response;
+ this.scope = response.getScope();
explicitClose |= !arm.supportsImplicitClose();
rowsProcessed += response.getResults().length;
index = 0;
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -566,7 +566,7 @@
if (!dqpCore.hasWaitingPlans(RequestWorkItem.this)) {
//requestMore will trigger more processing
throw BlockedException.block(requestID, "Blocking due to full results TupleBuffer", //$NON-NLS-1$
- this.getTupleBuffer().getId(), "rows", this.getTupleBuffer().getManagedRowCount(), "batch size", this.getTupleBuffer().getBatchSize()); //$NON-NLS-1$ //$NON-NLS-2$
+ this.getTupleBuffer(), "rows", this.getTupleBuffer().getManagedRowCount(), "batch size", this.getTupleBuffer().getBatchSize()); //$NON-NLS-1$ //$NON-NLS-2$
}
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
LogManager.logDetail(LogConstants.CTX_DQP, requestID, "Exceeding buffer limit since there are pending active plans."); //$NON-NLS-1$
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/TupleSourceCache.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/TupleSourceCache.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/TupleSourceCache.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -86,9 +86,9 @@
}
public abstract static class BufferedTupleSource implements TupleSource {
- private int rowNumber = 1;
- private TupleBuffer tb;
- private TupleSource ts;
+ int rowNumber = 1;
+ TupleBuffer tb;
+ TupleSource ts;
protected BufferedTupleSource(TupleBuffer tb, TupleSource ts) {
this.tb = tb;
Modified: trunk/engine/src/main/java/org/teiid/dqp/message/AtomicResultsMessage.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/message/AtomicResultsMessage.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/main/java/org/teiid/dqp/message/AtomicResultsMessage.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -24,10 +24,12 @@
import java.util.List;
+import org.teiid.translator.CacheDirective.Scope;
+
public class AtomicResultsMessage {
- private List[] results;
+ private List<?>[] results;
// Final row index in complete result set, if known
private int finalRow = -1;
@@ -35,17 +37,15 @@
// by default we support implicit close.
private boolean supportsImplicitClose = true;
- private boolean supportsCloseWithLobs;
-
- private boolean isTransactional;
-
private List<Exception> warnings;
+
+ private Scope scope;
// to honor the externalizable contract
public AtomicResultsMessage() {
}
- public AtomicResultsMessage(List[] results) {
+ public AtomicResultsMessage(List<?>[] results) {
this.results = results;
}
@@ -53,14 +53,6 @@
return this.supportsImplicitClose;
}
- public boolean supportsCloseWithLobs() {
- return supportsCloseWithLobs;
- }
-
- public void setSupportsCloseWithLobs(boolean supportsCloseWithLobs) {
- this.supportsCloseWithLobs = supportsCloseWithLobs;
- }
-
public void setSupportsImplicitClose(boolean supportsImplicitClose) {
this.supportsImplicitClose = supportsImplicitClose;
}
@@ -77,14 +69,6 @@
return results;
}
- public boolean isTransactional() {
- return isTransactional;
- }
-
- public void setTransactional(boolean isTransactional) {
- this.isTransactional = isTransactional;
- }
-
public void setWarnings(List<Exception> warnings) {
this.warnings = warnings;
}
@@ -92,4 +76,12 @@
public List<Exception> getWarnings() {
return warnings;
}
+
+ public void setScope(Scope scope) {
+ this.scope = scope;
+ }
+
+ public Scope getScope() {
+ return scope;
+ }
}
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -144,8 +144,6 @@
/**
* Create an index of the smaller size
- *
- * TODO: reuse existing temp table indexes
*/
public void createIndex(SourceState state, boolean sorted) throws TeiidComponentException, TeiidProcessingException {
int[] expressionIndexes = state.getExpressionIndexes();
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/MergeJoinStrategy.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/MergeJoinStrategy.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/MergeJoinStrategy.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -224,8 +224,8 @@
outerState = this.leftSource;
innerState = this.rightSource;
outerMatched = false;
- this.leftSource.getIterator().setPosition(this.leftSource.getMaxProbeMatch());
- this.rightSource.getIterator().setPosition(this.rightSource.getMaxProbeMatch());
+ this.leftSource.setMaxProbePosition();
+ this.rightSource.setMaxProbePosition();
this.mergeState = MergeState.SCAN;
this.matchState = MatchState.MATCH_LEFT;
break;
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/SortUtility.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -210,7 +210,7 @@
private TupleBuffer createTupleBuffer() throws TeiidComponentException {
TupleBuffer tb = bufferManager.createTupleBuffer(this.schema, this.groupName, TupleSourceType.PROCESSOR);
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
- LogManager.logDetail(LogConstants.CTX_DQP, "Created intermediate sort buffer ", tb.getId()); //$NON-NLS-1$
+ LogManager.logDetail(LogConstants.CTX_DQP, "Created intermediate sort buffer ", tb); //$NON-NLS-1$
}
tb.setForwardOnly(true);
return tb;
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/SourceState.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/SourceState.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/SourceState.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -238,5 +238,10 @@
this.currentTuple = null;
this.maxProbeMatch = 1;
}
+
+ public void setMaxProbePosition() throws TeiidComponentException {
+ this.getIterator().setPosition(this.getMaxProbeMatch());
+ this.currentTuple = null;
+ }
}
Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -269,7 +269,6 @@
TupleBuffer tb = bc.collectTuples();
CachedResults cr = new CachedResults();
cr.setResults(tb, qp.getProcessorPlan());
- cr.setHint(hint);
if (hint != null && hint.getDeterminism() != null) {
LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Cache hint modified the query determinism from ",determinismLevel, " to ", hint.getDeterminism() }); //$NON-NLS-1$ //$NON-NLS-2$
determinismLevel = hint.getDeterminism();
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -29,11 +29,15 @@
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
+import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.cache.CacheConfiguration;
import org.teiid.cache.DefaultCacheFactory;
import org.teiid.client.RequestMessage;
import org.teiid.client.SourceWarning;
import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.TupleSource;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
import org.teiid.core.types.ClobType;
import org.teiid.core.types.InputStreamFactory;
import org.teiid.core.types.InputStreamFactory.StorageMode;
@@ -46,20 +50,20 @@
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.RegisterRequestParameter;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.unittest.RealMetadataFactory;
import org.teiid.query.util.CommandContext;
+import org.teiid.translator.CacheDirective;
@SuppressWarnings("nls")
public class TestDataTierManager {
+ private VDBMetaData vdb = RealMetadataFactory.exampleBQTVDB();
private DQPCore rm;
private DataTierManagerImpl dtm;
private CommandContext context;
- private AtomicRequestMessage request;
- private Command command;
- private DataTierTupleSource info;
private AutoGenDataService connectorManager = new AutoGenDataService();
private RequestWorkItem workItem;
private int limit = -1;
@@ -75,50 +79,60 @@
return command;
}
- private void helpSetup(int nodeId) throws Exception {
- helpSetup("SELECT * FROM BQT1.SmallA", nodeId); //$NON-NLS-1$
+ private DataTierTupleSource helpSetup(int nodeId) throws Exception {
+ return helpSetup("SELECT * FROM BQT1.SmallA", nodeId); //$NON-NLS-1$
}
- private void helpSetup(String sql, int nodeId) throws Exception {
- QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
- DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(metadata, RealMetadataFactory.exampleBQTVDB());
-
- rm = new DQPCore();
- rm.setTransactionService(new FakeTransactionService());
- rm.setBufferManager(new FakeBufferService().getBufferManager());
- rm.setResultsetCache(new SessionAwareCache<CachedResults>(new DefaultCacheFactory(), SessionAwareCache.Type.RESULTSET, new CacheConfiguration()));
- rm.setPreparedPlanCache(new SessionAwareCache<PreparedPlan>(new DefaultCacheFactory(), SessionAwareCache.Type.PREPAREDPLAN, new CacheConfiguration()));
- rm.start(new DQPConfiguration());
- FakeBufferService bs = new FakeBufferService();
+ private DataTierTupleSource helpSetup(String sql, int nodeId) throws Exception {
+ helpSetupDataTierManager();
+ AtomicRequestMessage request = helpSetupRequest(sql, nodeId);
+ return new DataTierTupleSource(request, workItem, connectorManager.registerRequest(request), dtm, limit);
+ }
- ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
- Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(connectorManager);
+ private AtomicRequestMessage helpSetupRequest(String sql, int nodeId) throws Exception {
+ QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
+ DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(metadata, vdb);
+ Command command = helpGetCommand(sql, metadata);
- dtm = new DataTierManagerImpl(rm,bs.getBufferManager(), true);
- command = helpGetCommand(sql, metadata);
-
RequestMessage original = new RequestMessage();
original.setExecutionId(1);
original.setPartialResults(true);
RequestID requestID = workContext.getRequestID(original.getExecutionId());
context = new CommandContext();
+ context.setSession(workContext.getSession());
context.setProcessorID(requestID);
context.setVdbName("test"); //$NON-NLS-1$
context.setVdbVersion(1);
- context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(bs.getBufferManager(), dtm, new DefaultCapabilitiesFinder(), null, metadata));
+ context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(dtm.getBufferManager(), dtm, new DefaultCapabilitiesFinder(), null, metadata));
workItem = TestDQPCoreRequestHandling.addRequest(rm, original, requestID, null, workContext);
- request = new AtomicRequestMessage(original, workContext, nodeId);
+ AtomicRequestMessage request = new AtomicRequestMessage(original, workContext, nodeId);
request.setCommand(command);
request.setConnectorName("FakeConnectorID"); //$NON-NLS-1$
- info = new DataTierTupleSource(request, workItem, connectorManager.registerRequest(request), dtm, limit);
- }
+ return request;
+ }
+
+ private void helpSetupDataTierManager() {
+ FakeBufferService bs = new FakeBufferService();
+ rm = new DQPCore();
+ rm.setTransactionService(new FakeTransactionService());
+ rm.setBufferManager(bs.getBufferManager());
+ rm.setResultsetCache(new SessionAwareCache<CachedResults>(new DefaultCacheFactory(), SessionAwareCache.Type.RESULTSET, new CacheConfiguration()));
+ rm.setPreparedPlanCache(new SessionAwareCache<PreparedPlan>(new DefaultCacheFactory(), SessionAwareCache.Type.PREPAREDPLAN, new CacheConfiguration()));
+ rm.start(new DQPConfiguration());
+
+ ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
+ Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(connectorManager);
+ vdb.addAttchment(ConnectorManagerRepository.class, repo);
+
+ dtm = new DataTierManagerImpl(rm,bs.getBufferManager(), true);
+ }
@Test public void testCopyLobs() throws Exception {
connectorManager.copyLobs = true;
- helpSetup("SELECT cast(stringkey as clob) from bqt1.smalla", 1);
+ DataTierTupleSource info = helpSetup("SELECT cast(stringkey as clob) from bqt1.smalla", 1);
for (int i = 0; i < 10;) {
try {
List<?> tuple = info.nextTuple();
@@ -130,7 +144,7 @@
}
}
connectorManager.copyLobs = false;
- helpSetup("SELECT cast(stringkey as clob) from bqt1.smalla", 1);
+ info = helpSetup("SELECT cast(stringkey as clob) from bqt1.smalla", 1);
for (int i = 0; i < 10;) {
try {
List<?> tuple = info.nextTuple();
@@ -144,60 +158,58 @@
}
@Test public void testDataTierTupleSource() throws Exception {
- helpSetup(1);
- for (int i = 0; i < 10;) {
- try {
- info.nextTuple();
- i++;
- } catch (BlockedException e) {
- Thread.sleep(50);
- }
- }
- assertNotNull(workItem.getConnectorRequest(request.getAtomicRequestID()));
+ DataTierTupleSource info = helpSetup(1);
+ assertEquals(10, pullTuples(info, 10));
+ assertNotNull(workItem.getConnectorRequest(info.getAtomicRequestMessage().getAtomicRequestID()));
assertNull(info.nextTuple());
info.closeSource();
- assertNull(workItem.getConnectorRequest(request.getAtomicRequestID()));
+ assertNull(workItem.getConnectorRequest(info.getAtomicRequestMessage().getAtomicRequestID()));
}
@Test public void testDataTierTupleSourceWarnings() throws Exception {
- helpSetup(1);
+ DataTierTupleSource info = helpSetup(1);
connectorManager.addWarning = true;
- for (int i = 0; i < 10;) {
- try {
- info.nextTuple();
- i++;
- } catch (BlockedException e) {
- Thread.sleep(50);
- }
- }
- assertNotNull(workItem.getConnectorRequest(request.getAtomicRequestID()));
+ assertEquals(10, pullTuples(info, 10));
+ assertNotNull(workItem.getConnectorRequest(info.getAtomicRequestMessage().getAtomicRequestID()));
assertNull(info.nextTuple());
assertEquals(1, workItem.getWarnings().size());
SourceWarning warning = (SourceWarning) workItem.getWarnings().get(0);
assertFalse(warning.isPartialResultsError());
info.closeSource();
- assertNull(workItem.getConnectorRequest(request.getAtomicRequestID()));
+ assertNull(workItem.getConnectorRequest(info.getAtomicRequestMessage().getAtomicRequestID()));
}
@Test public void testDataTierTupleSourceLimit() throws Exception {
limit = 1;
- helpSetup(1);
- for (int i = 0; i < 1;) {
+ DataTierTupleSource info = helpSetup(1);
+ assertEquals(1, pullTuples(info, 1));
+ assertNotNull(workItem.getConnectorRequest(info.getAtomicRequestMessage().getAtomicRequestID()));
+ assertNull(info.nextTuple());
+ info.closeSource();
+ assertNull(workItem.getConnectorRequest(info.getAtomicRequestMessage().getAtomicRequestID()));
+ }
+
+ private int pullTuples(TupleSource info, int limit)
+ throws TeiidComponentException, TeiidProcessingException,
+ InterruptedException {
+ int i = 0;
+ while (true) {
try {
- info.nextTuple();
- i++;
+ if (info.nextTuple() == null) {
+ break;
+ }
+ if (++i == limit) {
+ break;
+ }
} catch (BlockedException e) {
Thread.sleep(50);
}
}
- assertNotNull(workItem.getConnectorRequest(request.getAtomicRequestID()));
- assertNull(info.nextTuple());
- info.closeSource();
- assertNull(workItem.getConnectorRequest(request.getAtomicRequestID()));
- }
+ return i;
+ }
@Test public void testPartialResults() throws Exception {
- helpSetup(1);
+ DataTierTupleSource info = helpSetup(1);
connectorManager.throwExceptionOnExecute = true;
for (int i = 0; i < 10; i++) {
try {
@@ -214,7 +226,7 @@
@Test public void testNoRowsException() throws Exception {
this.connectorManager.setRows(0);
- helpSetup(3);
+ DataTierTupleSource info = helpSetup(3);
while (true) {
try {
assertNull(info.nextTuple());
@@ -228,7 +240,7 @@
@Test public void testAsynch() throws Exception {
this.connectorManager.dataNotAvailable = 10;
this.connectorManager.setRows(0);
- helpSetup(3);
+ DataTierTupleSource info = helpSetup(3);
boolean blocked = false;
while (true) {
try {
@@ -242,4 +254,41 @@
assertTrue(blocked);
}
+ @Test public void testCaching() throws Exception {
+ assertEquals(0, connectorManager.getExecuteCount().get());
+
+ CacheDirective cd = new CacheDirective();
+ this.connectorManager.cacheDirective = cd;
+ helpSetupDataTierManager();
+ Command command = helpSetupRequest("SELECT stringkey from bqt1.smalla", 1).getCommand();
+ RegisterRequestParameter rrp = new RegisterRequestParameter();
+ rrp.connectorBindingId = "x";
+ TupleSource ts = dtm.registerRequest(context, command, "foo", rrp);
+ assertTrue(ts instanceof CachingTupleSource);
+ assertEquals(10, pullTuples(ts, -1));
+ assertEquals(1, connectorManager.getExecuteCount().get());
+ assertFalse(rrp.doNotCache);
+
+ //same session, should be cached
+ command = helpSetupRequest("SELECT stringkey from bqt1.smalla", 1).getCommand();
+ rrp = new RegisterRequestParameter();
+ rrp.connectorBindingId = "x";
+ ts = dtm.registerRequest(context, command, "foo", rrp);
+ assertFalse(ts instanceof CachingTupleSource);
+ assertEquals(10, pullTuples(ts, -1));
+ assertEquals(1, connectorManager.getExecuteCount().get());
+ assertTrue(rrp.doNotCache);
+
+ //switch sessions
+ command = helpSetupRequest("SELECT stringkey from bqt1.smalla", 1).getCommand();
+ this.context.getSession().setSessionId("different");
+ rrp = new RegisterRequestParameter();
+ rrp.connectorBindingId = "x";
+ ts = dtm.registerRequest(context, command, "foo", rrp);
+ assertTrue(ts instanceof CachingTupleSource);
+ assertEquals(10, pullTuples(ts, -1));
+ assertEquals(2, connectorManager.getExecuteCount().get());
+ assertFalse(rrp.doNotCache);
+ }
+
}
Modified: trunk/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java 2012-07-30 13:07:44 UTC (rev 4275)
+++ trunk/engine/src/test/java/org/teiid/dqp/service/AutoGenDataService.java 2012-07-30 16:04:34 UTC (rev 4276)
@@ -72,6 +72,7 @@
private boolean useIntCounter;
public boolean addWarning;
public boolean copyLobs;
+ public CacheDirective cacheDirective;
public AutoGenDataService() {
super("FakeConnector","FakeConnector"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -120,6 +121,11 @@
}
@Override
+ public boolean areLobsUsableAfterClose() {
+ return false;
+ }
+
+ @Override
public void setRequestWorkItem(RequestWorkItem item) {
this.item = item;
}
@@ -183,7 +189,7 @@
@Override
public CacheDirective getCacheDirective() {
- return null;
+ return cacheDirective;
}
};
12 years, 4 months
teiid SVN: r4275 - trunk/engine/src/test/java/org/teiid/query/processor.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-07-30 09:07:44 -0400 (Mon, 30 Jul 2012)
New Revision: 4275
Modified:
trunk/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java
Log:
TEIID-2120 updating unit test for batchiterator early termination
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java 2012-07-30 12:59:25 UTC (rev 4274)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java 2012-07-30 13:07:44 UTC (rev 4275)
@@ -94,16 +94,20 @@
BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] {
Arrays.asList(1),
Arrays.asList(1),
- }, 1));
+ Arrays.asList(1),
+ Arrays.asList(1),
+ }, 2));
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
bi.setBuffer(bm.createTupleBuffer(Arrays.asList(new ElementSymbol("x")), "test", TupleSourceType.PROCESSOR), true); //$NON-NLS-1$
bi.mark();
assertNotNull(bi.nextTuple());
assertNotNull(bi.nextTuple());
- assertNull(bi.nextTuple());
+ assertNotNull(bi.nextTuple());
bi.reset();
assertNotNull(bi.nextTuple());
assertNotNull(bi.nextTuple());
+ assertNotNull(bi.nextTuple());
+ assertNotNull(bi.nextTuple());
assertNull(bi.nextTuple());
}
12 years, 4 months
teiid SVN: r4274 - 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-07-30 08:59:25 -0400 (Mon, 30 Jul 2012)
New Revision: 4274
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/BatchIterator.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java
Log:
TEIID-2120 fix for batchiterator early termination
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/processor/BatchIterator.java
===================================================================
--- branches/7.4.x/engine/src/main/java/org/teiid/query/processor/BatchIterator.java 2012-07-28 01:25:33 UTC (rev 4273)
+++ branches/7.4.x/engine/src/main/java/org/teiid/query/processor/BatchIterator.java 2012-07-30 12:59:25 UTC (rev 4274)
@@ -69,7 +69,7 @@
}
batch = source.nextBatch();
done = batch.getTerminationFlag();
- if (buffer != null && !saveOnMark) {
+ if (buffer != null && (!saveOnMark || mark)) {
buffer.addTupleBatch(batch, true);
}
}
Modified: branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java
===================================================================
--- branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java 2012-07-28 01:25:33 UTC (rev 4273)
+++ branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java 2012-07-30 12:59:25 UTC (rev 4274)
@@ -32,7 +32,6 @@
import org.teiid.common.buffer.BufferManagerFactory;
import org.teiid.common.buffer.TupleBuffer;
import org.teiid.common.buffer.BufferManager.TupleSourceType;
-import org.teiid.query.processor.BatchIterator;
import org.teiid.query.processor.relational.FakeRelationalNode;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -91,4 +90,21 @@
assertEquals(1, bi.nextTuple().get(0));
}
+ @Test public void testBatchReadDuringMark() throws Exception {
+ BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] {
+ Arrays.asList(1),
+ Arrays.asList(1),
+ }, 1));
+ BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
+ bi.setBuffer(bm.createTupleBuffer(Arrays.asList(new ElementSymbol("x")), "test", TupleSourceType.PROCESSOR), true); //$NON-NLS-1$
+ bi.mark();
+ assertNotNull(bi.nextTuple());
+ assertNotNull(bi.nextTuple());
+ assertNull(bi.nextTuple());
+ bi.reset();
+ assertNotNull(bi.nextTuple());
+ assertNotNull(bi.nextTuple());
+ assertNull(bi.nextTuple());
+ }
+
}
12 years, 4 months
teiid SVN: r4273 - in trunk/engine/src: test/java/org/teiid/query/processor and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-07-27 21:25:33 -0400 (Fri, 27 Jul 2012)
New Revision: 4273
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/BatchIterator.java
trunk/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java
Log:
TEIID-2120 fix for batchiterator early termination
Modified: trunk/engine/src/main/java/org/teiid/query/processor/BatchIterator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/BatchIterator.java 2012-07-26 17:21:06 UTC (rev 4272)
+++ trunk/engine/src/main/java/org/teiid/query/processor/BatchIterator.java 2012-07-28 01:25:33 UTC (rev 4273)
@@ -69,7 +69,7 @@
}
batch = source.nextBatch();
done = batch.getTerminationFlag();
- if (buffer != null && !saveOnMark) {
+ if (buffer != null && (!saveOnMark || mark)) {
buffer.addTupleBatch(batch, true);
}
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java 2012-07-26 17:21:06 UTC (rev 4272)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestBatchIterator.java 2012-07-28 01:25:33 UTC (rev 4273)
@@ -32,7 +32,6 @@
import org.teiid.common.buffer.BufferManagerFactory;
import org.teiid.common.buffer.TupleBuffer;
import org.teiid.common.buffer.BufferManager.TupleSourceType;
-import org.teiid.query.processor.BatchIterator;
import org.teiid.query.processor.relational.FakeRelationalNode;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -91,4 +90,21 @@
assertEquals(1, bi.nextTuple().get(0));
}
+ @Test public void testBatchReadDuringMark() throws Exception {
+ BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] {
+ Arrays.asList(1),
+ Arrays.asList(1),
+ }, 1));
+ BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
+ bi.setBuffer(bm.createTupleBuffer(Arrays.asList(new ElementSymbol("x")), "test", TupleSourceType.PROCESSOR), true); //$NON-NLS-1$
+ bi.mark();
+ assertNotNull(bi.nextTuple());
+ assertNotNull(bi.nextTuple());
+ assertNull(bi.nextTuple());
+ bi.reset();
+ assertNotNull(bi.nextTuple());
+ assertNotNull(bi.nextTuple());
+ assertNull(bi.nextTuple());
+ }
+
}
12 years, 4 months