teiid SVN: r537 - in trunk: common-internal/src/main/java/com/metamatrix/common/config/api and 34 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2009-03-04 18:29:07 -0500 (Wed, 04 Mar 2009)
New Revision: 537
Added:
trunk/common-internal/src/main/java/com/metamatrix/platform/vm/controller/ProcessStatistics.java
trunk/server/src/main/java/com/metamatrix/platform/registry/ProcessMonitor.java
trunk/server/src/main/java/com/metamatrix/platform/registry/ProcessRegistryBinding.java
trunk/server/src/main/java/com/metamatrix/platform/vm/api/controller/ProcessManagement.java
trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ProcessController.java
Removed:
trunk/common-internal/src/main/java/com/metamatrix/platform/vm/controller/VMControllerID.java
trunk/common-internal/src/main/java/com/metamatrix/platform/vm/controller/VMStatistics.java
trunk/server/src/main/java/com/metamatrix/platform/registry/VMMonitor.java
trunk/server/src/main/java/com/metamatrix/platform/registry/VMRegistryBinding.java
trunk/server/src/main/java/com/metamatrix/platform/vm/api/controller/VMControllerInterface.java
trunk/server/src/main/java/com/metamatrix/platform/vm/controller/VMController.java
Modified:
trunk/client/src/main/java/com/metamatrix/admin/objects/MMConnectorBinding.java
trunk/client/src/main/java/com/metamatrix/admin/objects/MMDQP.java
trunk/client/src/main/java/com/metamatrix/admin/objects/MMProcess.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/api/Configuration.java
trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicConfiguration.java
trunk/common-internal/src/main/java/com/metamatrix/common/util/VMNaming.java
trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/RuntimeStateAdminAPI.java
trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/runtime/ProcessData.java
trunk/common-internal/src/main/java/com/metamatrix/platform/service/api/ServiceID.java
trunk/console/src/main/java/com/metamatrix/console/models/RuntimeMgmtManager.java
trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/ProcessMgmtPanel.java
trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/QueueStatisticsRefreshRequestHandlerImp.java
trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/VMStatisticsDisplayHandler.java
trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/VMStatisticsPanel.java
trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/admin/BaseAdmin.java
trunk/server/src/main/java/com/metamatrix/admin/server/AbstractAdminImpl.java
trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java
trunk/server/src/main/java/com/metamatrix/admin/server/ServerRuntimeStateAdminImpl.java
trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SocketVMController.java
trunk/server/src/main/java/com/metamatrix/common/log/DbLogWriter.java
trunk/server/src/main/java/com/metamatrix/metadata/runtime/vdb/defn/VDBCreation.java
trunk/server/src/main/java/com/metamatrix/platform/admin/api/runtime/SystemStateBuilder.java
trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIHelper.java
trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIImpl.java
trunk/server/src/main/java/com/metamatrix/platform/registry/ClusteredRegistryState.java
trunk/server/src/main/java/com/metamatrix/platform/registry/ServiceRegistryBinding.java
trunk/server/src/main/java/com/metamatrix/platform/security/audit/AuditMessage.java
trunk/server/src/main/java/com/metamatrix/platform/security/audit/destination/DatabaseAuditDestination.java
trunk/server/src/main/java/com/metamatrix/platform/security/audit/destination/SingleFileAuditDestination.java
trunk/server/src/main/java/com/metamatrix/platform/security/audit/format/DelimitedAuditMessageFormat.java
trunk/server/src/main/java/com/metamatrix/platform/security/audit/format/ReadableAuditMessageFormat.java
trunk/server/src/main/java/com/metamatrix/platform/service/api/ServiceInterface.java
trunk/server/src/main/java/com/metamatrix/platform/service/controller/AbstractService.java
trunk/server/src/main/java/com/metamatrix/platform/service/proxy/ProxyManager.java
trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ServerEvents.java
trunk/server/src/main/java/com/metamatrix/server/Configuration.java
trunk/server/src/main/java/com/metamatrix/server/HostController.java
trunk/server/src/main/java/com/metamatrix/server/HostManagement.java
trunk/server/src/main/java/com/metamatrix/server/LogApplicationInfo.java
trunk/server/src/main/java/com/metamatrix/server/Main.java
trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java
trunk/server/src/main/java/com/metamatrix/server/ServiceManager.java
trunk/server/src/main/java/com/metamatrix/server/connector/service/ConnectorService.java
trunk/server/src/main/java/com/metamatrix/server/dqp/config/PlatformConfigSource.java
trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformBufferService.java
trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformTransactionService.java
trunk/server/src/main/java/com/metamatrix/server/query/service/QueryService.java
trunk/server/src/main/resources/com/metamatrix/platform/i18n.properties
trunk/server/src/test/java/com/metamatrix/admin/server/FakeCacheAdmin.java
trunk/server/src/test/java/com/metamatrix/admin/server/FakeConfiguration.java
trunk/server/src/test/java/com/metamatrix/admin/server/FakeConfigurationService.java
trunk/server/src/test/java/com/metamatrix/admin/server/FakeQueryService.java
trunk/server/src/test/java/com/metamatrix/admin/server/FakeRuntimeStateAdminAPIHelper.java
trunk/server/src/test/java/com/metamatrix/admin/server/FakeServerAdminImpl.java
trunk/server/src/test/java/com/metamatrix/admin/server/FakeServerSessionService.java
trunk/server/src/test/java/com/metamatrix/admin/server/TestServerMonitoringAdminImpl.java
trunk/server/src/test/java/com/metamatrix/admin/server/TestServerRuntimeStateAdminImpl.java
trunk/server/src/test/java/com/metamatrix/platform/registry/FakeRegistryUtil.java
trunk/server/src/test/java/com/metamatrix/platform/registry/TestClusteredRegistryState.java
trunk/server/src/test/java/com/metamatrix/platform/registry/TestServiceRegistryBinding.java
trunk/server/src/test/java/com/metamatrix/platform/service/controller/FakeService.java
trunk/server/src/test/java/com/metamatrix/platform/service/proxy/TestProxies.java
Log:
TEIID-394: VMControllerID is removed. Host Name + Process Name is used as identifier for any process identification. Also, VM name is overloaded with JVM, all the references to VMName has been changed to more consistent "Process Name".
Modified: trunk/client/src/main/java/com/metamatrix/admin/objects/MMConnectorBinding.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/admin/objects/MMConnectorBinding.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/client/src/main/java/com/metamatrix/admin/objects/MMConnectorBinding.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -42,9 +42,7 @@
private int currentState;
private Date stateChangedTime;
private long serviceID = -1;
- private long processID = -1;
-
/**
* Constructor.
@@ -200,22 +198,12 @@
* @return Returns the processID.
* @since 4.3
*/
- public long getProcessID() {
- return this.processID;
+ public String getProcessName() {
+ return identifierParts[1];
}
-
/**
- * @param processID The processID to set.
- * @since 4.3
- */
- public void setProcessID(long processID) {
- this.processID = processID;
- }
-
-
- /**
* @return Returns the hostName.
* @since 4.3
*/
Modified: trunk/client/src/main/java/com/metamatrix/admin/objects/MMDQP.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/admin/objects/MMDQP.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/client/src/main/java/com/metamatrix/admin/objects/MMDQP.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -42,9 +42,6 @@
private int currentState;
private Date stateChangedTime;
private long serviceID = -1;
- private long processID = -1;
-
-
/**
@@ -187,23 +184,11 @@
* @return Returns the processID.
* @since 4.3
*/
- public long getProcessID() {
- return this.processID;
+ public String getProcessName() {
+ return this.identifierParts[1];
}
-
-
/**
- * @param processID The processID to set.
- * @since 4.3
- */
- public void setProcessID(long processID) {
- this.processID = processID;
- }
-
-
-
- /**
* @return Returns the hostName.
* @since 4.3
*/
Modified: trunk/client/src/main/java/com/metamatrix/admin/objects/MMProcess.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/admin/objects/MMProcess.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/client/src/main/java/com/metamatrix/admin/objects/MMProcess.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -42,8 +42,6 @@
private int threadCount = 0;
private long totalMemory = 0;
- private long processID = -1;
-
private int sockets = 0;
private int maxSockets = 0;
private int virtualSockets = 0;
@@ -331,22 +329,11 @@
* @return Returns the processID.
* @since 4.3
*/
- public long getProcessID() {
- return this.processID;
+ public String getProcessName() {
+ return identifierParts[1];
}
-
-
/**
- * @param processID The processID to set.
- * @since 4.3
- */
- public void setProcessID(long processID) {
- this.processID = processID;
- }
-
-
- /**
* @return Returns the hostName.
* @since 4.3
*/
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/config/api/Configuration.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/api/Configuration.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/api/Configuration.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -207,7 +207,7 @@
* @param hostID is the host the VM was deployed to.
* @return DeployedComponent
*/
- VMComponentDefn getVMForHost(String hostname, String vmname) ;
+ VMComponentDefn getVMForHost(String hostname, String processName) ;
/**
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicConfiguration.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicConfiguration.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/config/model/BasicConfiguration.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -674,13 +674,9 @@
for (Iterator it = dcs.iterator(); it.hasNext(); ) {
dc = (VMComponentDefn) it.next();
- // is the component from the same host
+ // is the component from the same host
if (dc.getID().equals(vmID)) {
-// ComponentDefn comp = dc.getDeployedComponentDefn(this);
-// if (comp instanceof VMComponentDefn) {
-// if (dc.getName().equalsIgnoreCase(vmname)) {
- return dc;
-// }
+ return dc;
}
}
@@ -723,7 +719,7 @@
return getVMsForHost(id);
}
- public VMComponentDefn getVMForHost(String hostname, String vmname) {
+ public VMComponentDefn getVMForHost(String hostname, String processName) {
Collection dcs = getVMsForHost(hostname);
@@ -732,7 +728,7 @@
for (Iterator it = dcs.iterator(); it.hasNext(); ) {
dc = (VMComponentDefn) it.next();
// is the component from the same host
- if (dc.getID().getName().equalsIgnoreCase(vmname)) {
+ if (dc.getID().getName().equalsIgnoreCase(processName)) {
return dc;
}
}
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/util/VMNaming.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/util/VMNaming.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/util/VMNaming.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -48,17 +48,17 @@
private static String BIND_ADDRESS = "";//$NON-NLS-1$
/*
- * VMNAME refers to the name of the process that is currently running.
+ * Process Name refers to the name of the process that is currently running.
*/
- private static String VMNAME = "";//$NON-NLS-1$
+ private static String PROCESS_NAME = "";//$NON-NLS-1$
- public static String getVMName() {
- return VMNAME;
+ public static String getProcessName() {
+ return PROCESS_NAME;
}
- public static void setVMName(String vmname) {
- VMNAME = vmname;
+ public static void setProcessName(String processName) {
+ PROCESS_NAME = processName;
}
public static String getConfigName() {
@@ -106,7 +106,7 @@
public static String getHostInfo() {
StringBuffer sb = new StringBuffer("Host Information"); //$NON-NLS-1$
sb.append('\n');
- sb.append(" VM Name: " + VMNAME ); //$NON-NLS-1$
+ sb.append(" VM Name: " + PROCESS_NAME ); //$NON-NLS-1$
sb.append('\n');
sb.append(" Hostname: " + HOST_ADDRESS.getCanonicalHostName() ); //$NON-NLS-1$
sb.append('\n');
Modified: trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/RuntimeStateAdminAPI.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/RuntimeStateAdminAPI.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/RuntimeStateAdminAPI.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -36,8 +36,7 @@
import com.metamatrix.platform.admin.api.runtime.PscID;
import com.metamatrix.platform.admin.api.runtime.SystemState;
import com.metamatrix.platform.service.api.ServiceID;
-import com.metamatrix.platform.vm.controller.VMControllerID;
-import com.metamatrix.platform.vm.controller.VMStatistics;
+import com.metamatrix.platform.vm.controller.ProcessStatistics;
public interface RuntimeStateAdminAPI extends SubSystemAdminAPI {
@@ -76,23 +75,6 @@
MetaMatrixComponentException;
/**
- * Return all processes running in mm system.
- *
- * @param callerSessionID
- * ID of the caller's current session.
- * @return List of VMControllerIDs.
- * @throws AuthorizationException
- * if caller is not authorized to perform this method.
- * @throws InvalidSessionException
- * if the <code>callerSessionID</code> is not valid or is expired.
- * @throws MetaMatrixComponentException
- * if an error occurred in communicating with a component.
- */
- List getProcesses() throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException;
-
- /**
* Return all hosts running in mm system.
*
* @param callerSessionID
@@ -159,30 +141,11 @@
* @throws MetaMatrixComponentException
* if an error occurred in communicating with a component.
*/
- void stopProcess(VMControllerID processID) throws AuthorizationException,
+ void stopProcess(String hostname, String processName, boolean now) throws AuthorizationException,
InvalidSessionException,
MetaMatrixComponentException;
/**
- * Stop process now.
- *
- * @param callerSessionID
- * ID of the caller's current session.
- * @param processID
- * <code>VMControllerID</code>.
- * @throws AuthorizationException
- * if caller is not authorized to perform this method.
- * @throws InvalidSessionException
- * if the <code>callerSessionID</code> is not valid or is expired.
- * @throws MetaMatrixComponentException
- * if an error occurred in communicating with a component.
- */
- void stopProcessNow(VMControllerID processID) throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException;
-
-
- /**
* Gracefully shutdown server waiting for work to complete.
*
* @param callerSessionID
@@ -433,8 +396,7 @@
* @throws MetaMatrixComponentException
* if an error occurred in communicating with a component.
*/
- void setLoggingConfiguration(LogConfiguration logConfig,
- VMControllerID vmID) throws AuthorizationException,
+ void setLoggingConfiguration(LogConfiguration logConfig, String hostName, String processName) throws AuthorizationException,
InvalidSessionException,
MetaMatrixComponentException;
@@ -489,7 +451,7 @@
* @throws MetaMatrixComponentException
* if an error occurred in communicating with a component.
*/
- VMStatistics getVMStatistics(VMControllerID vmID) throws AuthorizationException,
+ ProcessStatistics getProcessStatistics(String hostName, String processName) throws AuthorizationException,
InvalidSessionException,
MetaMatrixComponentException;
@@ -555,36 +517,6 @@
MetaMatrixComponentException;
/**
- * Retrieve the VMControllerID by name
- *
- * @param hostName
- * name of the host of the VM
- * @param processName
- * name of the process of the VM
- * @return <code>VMControllerID</code>
- * @since 4.2.1
- */
- VMControllerID getVMControllerIDByName(String hostName,
- String processName) throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException;
-
- /**
- * Get the Process name of the VM by ID and HostName
- *
- * @param id
- * VMID of the VM Process
- * @param hostName
- * host name of the VM Process
- * @return String name of the VM Process
- * @since 4.2.1
- */
- String getVMName(long id,
- String hostName) throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException;
-
- /**
* Get the log entries that match the specified criteria.
* @param startTime
* @param endTime If null, will ignore this criterion.
Modified: trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/runtime/ProcessData.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/runtime/ProcessData.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/runtime/ProcessData.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -27,8 +27,6 @@
import com.metamatrix.common.config.api.ComponentDefnID;
import com.metamatrix.core.util.HashCodeUtil;
-import com.metamatrix.platform.vm.controller.VMControllerID;
-
/**
* This class is a container for ServiceRegistryBinding objects for
* all the services running in this VM
@@ -38,9 +36,6 @@
/** Map of ServiceID to ServiceRegistryBindings */
private Collection pscs;
- /** ID of VMControllerID */
- private VMControllerID processID;
-
/** defines vm in configuration */
private ComponentDefnID defnID;
@@ -56,10 +51,9 @@
* @param vmController VMController implementation
* @param hostName Name of host VM is running on
*/
- public ProcessData(VMControllerID processID, ComponentDefnID defnID, String hostName, Collection pscs, String processName, String port, boolean deployed, boolean registered) {
+ public ProcessData(String hostName, String processName, String port, ComponentDefnID defnID, Collection pscs, boolean deployed, boolean registered) {
super(processName, deployed, registered);
this.hostName = hostName;
- this.processID = processID;
this.defnID = defnID;
this.pscs = pscs;
this.port = port;
@@ -75,15 +69,6 @@
/**
- * Return VMControllerID that this binding represents.
- *
- * @return VMControllerID
- */
- public VMControllerID getProcessID() {
- return processID;
- }
-
- /**
* Return ComponentDefnID for VMController.
*
* @return ComponentDefnID
@@ -106,7 +91,9 @@
private void computeHashCode() {
hashCode = 0;
hashCode = HashCodeUtil.hashCode(hashCode, defnID);
- hashCode = HashCodeUtil.hashCode(hashCode, processID);
+ hashCode = HashCodeUtil.hashCode(hashCode, getName());
+ hashCode = HashCodeUtil.hashCode(hashCode, hostName);
+
}
/**
@@ -132,9 +119,7 @@
if (this.defnID == null && that.getComponentDefnID() != null) return false;
if (that.getComponentDefnID() == null && this.defnID != null) return false;
if (this.defnID == null && that.getComponentDefnID() == null) {
- if (this.processID == null && that.getProcessID() != null) return false;
- if (that.getProcessID() == null && this.processID != null) return false;
- return processID.equals(that.getProcessID());
+ return this.hostName.equals(that.hostName) && this.getName().equals(that.getName());
}
return defnID.equals(that.getComponentDefnID());
}
Modified: trunk/common-internal/src/main/java/com/metamatrix/platform/service/api/ServiceID.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/platform/service/api/ServiceID.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/common-internal/src/main/java/com/metamatrix/platform/service/api/ServiceID.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -22,29 +22,26 @@
package com.metamatrix.platform.service.api;
-import com.metamatrix.platform.vm.controller.VMControllerID;
import java.io.Serializable;
public class ServiceID implements Serializable {
private long id;
- private VMControllerID vmControllerID;
+ private String hostName;
+ private String processName;
- public ServiceID(long id, VMControllerID vmControllerID) {
+ public ServiceID(long id, String hostName, String processName) {
this.id = id;
- this.vmControllerID = vmControllerID;
+ this.hostName = hostName;
+ this.processName = processName;
}
- public VMControllerID getVMControllerID() {
- return this.vmControllerID;
- }
-
public String getHostName() {
- return vmControllerID.getHostName();
+ return this.hostName;
}
- public String toString() {
- return "ServiceID<"+id+"> " + vmControllerID; //$NON-NLS-1$ //$NON-NLS-2$
+ public String getProcessName() {
+ return this.processName;
}
public long getID() {
@@ -80,5 +77,8 @@
return (int) this.id;
}
+ public String toString() {
+ return "Service<"+id+"|"+this.hostName+"|"+processName+">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
}
Copied: trunk/common-internal/src/main/java/com/metamatrix/platform/vm/controller/ProcessStatistics.java (from rev 534, trunk/common-internal/src/main/java/com/metamatrix/platform/vm/controller/VMStatistics.java)
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/platform/vm/controller/ProcessStatistics.java (rev 0)
+++ trunk/common-internal/src/main/java/com/metamatrix/platform/vm/controller/ProcessStatistics.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -0,0 +1,44 @@
+/*
+ * 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 com.metamatrix.platform.vm.controller;
+
+import java.io.Serializable;
+
+import com.metamatrix.common.queue.WorkerPoolStats;
+
+/**
+ * VM statistics including: total memory, free memory, number of threads.
+ */
+public class ProcessStatistics implements Serializable {
+ public String name;
+ public long totalMemory = 0;
+ public long freeMemory = 0;
+ public int threadCount = 0;
+
+
+ public SocketListenerStats socketListenerStats = new SocketListenerStats();
+
+ public WorkerPoolStats processPoolStats = new WorkerPoolStats();
+}
+
+
Deleted: trunk/common-internal/src/main/java/com/metamatrix/platform/vm/controller/VMControllerID.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/platform/vm/controller/VMControllerID.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/common-internal/src/main/java/com/metamatrix/platform/vm/controller/VMControllerID.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -1,65 +0,0 @@
-/*
- * 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 com.metamatrix.platform.vm.controller;
-
-import java.io.Serializable;
-
-public class VMControllerID implements Serializable {
-
- private long id;
- private String hostName;
-
- public VMControllerID(long id, String hostName) {
- this.id = id;
- this.hostName = hostName.toUpperCase();
- }
-
- public String getHostName() {
- return hostName;
- }
-
- public long getID() {
- return id;
- }
-
- public String toString() {
- return "VMControllerID<"+id+">:"+hostName; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public boolean equals(Object obj) {
- if(this == obj) {
- return true;
- }
- if(!(obj instanceof VMControllerID)) {
- return false;
- }
- return ((VMControllerID)obj).getID() == getID();
- }
-
- public int hashCode() {
- return (int) this.id;
- }
-}
-
-
-
Deleted: trunk/common-internal/src/main/java/com/metamatrix/platform/vm/controller/VMStatistics.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/platform/vm/controller/VMStatistics.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/common-internal/src/main/java/com/metamatrix/platform/vm/controller/VMStatistics.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -1,44 +0,0 @@
-/*
- * 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 com.metamatrix.platform.vm.controller;
-
-import java.io.Serializable;
-
-import com.metamatrix.common.queue.WorkerPoolStats;
-
-/**
- * VM statistics including: total memory, free memory, number of threads.
- */
-public class VMStatistics implements Serializable {
- public String name;
- public long totalMemory = 0;
- public long freeMemory = 0;
- public int threadCount = 0;
-
-
- public SocketListenerStats socketListenerStats = new SocketListenerStats();
-
- public WorkerPoolStats processPoolStats = new WorkerPoolStats();
-}
-
-
Modified: trunk/console/src/main/java/com/metamatrix/console/models/RuntimeMgmtManager.java
===================================================================
--- trunk/console/src/main/java/com/metamatrix/console/models/RuntimeMgmtManager.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/console/src/main/java/com/metamatrix/console/models/RuntimeMgmtManager.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -349,7 +349,7 @@
throws ExternalException {
refreshImpl();
try {
- getAPI().stopProcess(theProcess.getProcessID());
+ getAPI().stopProcess(theProcess.getHostName(), theProcess.getName(), true);
}
catch (Exception theException) {
theException.printStackTrace();
@@ -361,7 +361,7 @@
throws ExternalException {
refreshImpl();
try {
- getAPI().stopProcessNow(theProcess.getProcessID());
+ getAPI().stopProcess(theProcess.getHostName(), theProcess.getName(), true);
}
catch (Exception theException) {
theException.printStackTrace();
Modified: trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/ProcessMgmtPanel.java
===================================================================
--- trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/ProcessMgmtPanel.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/ProcessMgmtPanel.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -163,9 +163,8 @@
Vector row = new Vector(HDRS.length);
row.setSize(HDRS.length);
row.setElementAt(process, PROC_COL);
- row.setElementAt(process.getProcessID(), ID_COL);
- row.setElementAt(
- new Boolean(process.isRegistered()), REGISTERED_COL);
+ row.setElementAt(process.getName(), ID_COL);
+ row.setElementAt(new Boolean(process.isRegistered()), REGISTERED_COL);
Integer[] counts = manager.getPscCounts(process);
row.setElementAt(counts[0], NUM_REG_PSC_COL);
row.setElementAt(counts[1], NUM_NOT_REG_PSC_COL);
Modified: trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/QueueStatisticsRefreshRequestHandlerImp.java
===================================================================
--- trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/QueueStatisticsRefreshRequestHandlerImp.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/QueueStatisticsRefreshRequestHandlerImp.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -42,8 +42,7 @@
import com.metamatrix.platform.admin.api.RuntimeStateAdminAPI;
import com.metamatrix.platform.admin.api.runtime.ProcessData;
import com.metamatrix.platform.admin.api.runtime.ServiceData;
-import com.metamatrix.platform.vm.controller.VMControllerID;
-import com.metamatrix.platform.vm.controller.VMStatistics;
+import com.metamatrix.platform.vm.controller.ProcessStatistics;
public class QueueStatisticsRefreshRequestHandlerImp
implements QueueStatisticsRefreshRequestHandler, ServiceStateConstants{
@@ -83,7 +82,7 @@
public void refreshProcessRequested(ProcessData pd) {
try {
if (getProcessStatistics(pd) != null) {
- VMStatistics vmstats = getProcessStatistics(pd);
+ ProcessStatistics vmstats = getProcessStatistics(pd);
vmsdh.refreshDisplayForProcess(pd.getName(), pd, vmstats);
}
} catch (Exception theException) {
@@ -185,9 +184,9 @@
return sqs;
}
- public VMStatistics getProcessStatistics(ProcessData pd) {
+ public ProcessStatistics getProcessStatistics(ProcessData pd) {
try {
- return getAdminAPI().getVMStatistics(pd.getProcessID());
+ return getAdminAPI().getProcessStatistics(pd.getHostName(), pd.getName());
} catch (Exception theException) {
displayException(theException, "QueueStatisticsRefreshRequestHandlerImp.getVMStatistics"); //$NON-NLS-1$
return null;
Modified: trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/VMStatisticsDisplayHandler.java
===================================================================
--- trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/VMStatisticsDisplayHandler.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/VMStatisticsDisplayHandler.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -40,7 +40,7 @@
import com.metamatrix.console.util.StaticUtilities;
import com.metamatrix.platform.admin.api.runtime.ProcessData;
-import com.metamatrix.platform.vm.controller.VMStatistics;
+import com.metamatrix.platform.vm.controller.ProcessStatistics;
public class VMStatisticsDisplayHandler {
public QueueStatisticsRefreshRequestHandler caller;
@@ -67,7 +67,7 @@
* The caller must subsequently call VMStatisticsFrame.show() to display the frame.
*/
public VMStatisticsFrame startDisplayForProcess(String processDisplayName, ProcessData pd,
- VMStatistics vmstatistics) {
+ ProcessStatistics vmstatistics) {
VMStatisticsPanel panel = new VMStatisticsPanel(caller, pd, vmstatistics);
statisticsFrame = new VMStatisticsFrame(this, processDisplayName, pd,
panel);
@@ -80,7 +80,7 @@
}
public void refreshDisplayForProcess(String processDisplayName, ProcessData pd,
- VMStatistics vmstatistics) {
+ ProcessStatistics vmstatistics) {
VMStatisticsFrame statisticsFrame =
(VMStatisticsFrame) currentlyShowing.get(pd);
VMStatisticsPanel panel = statisticsFrame.getPanel();
Modified: trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/VMStatisticsPanel.java
===================================================================
--- trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/VMStatisticsPanel.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/VMStatisticsPanel.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -35,7 +35,7 @@
import com.metamatrix.common.queue.WorkerPoolStats;
import com.metamatrix.platform.admin.api.runtime.ProcessData;
import com.metamatrix.platform.vm.controller.SocketListenerStats;
-import com.metamatrix.platform.vm.controller.VMStatistics;
+import com.metamatrix.platform.vm.controller.ProcessStatistics;
import com.metamatrix.toolbox.ui.widget.ButtonWidget;
import com.metamatrix.toolbox.ui.widget.LabelWidget;
import com.metamatrix.toolbox.ui.widget.TextFieldWidget;
@@ -44,14 +44,14 @@
public class VMStatisticsPanel extends JPanel{
private ProcessData processData;
private QueueStatisticsRefreshRequestHandler controller;
- private VMStatistics vmStatistics;
+ private ProcessStatistics vmStatistics;
private ProcessVMStatisticsPanel processPanel;
private QueueVMStatisticsPanel queuePanel;
private SocketVMStatisticsPanel socketPanel;
private AbstractButton closeButton;
public VMStatisticsPanel(QueueStatisticsRefreshRequestHandler ctrlr,
- ProcessData pd, VMStatistics vmStats) {
+ ProcessData pd, ProcessStatistics vmStats) {
super();
controller = ctrlr;
processData = pd;
@@ -124,7 +124,7 @@
new Insets(4, 4, 4, 4), 0, 0));
}
- public void repopulate(VMStatistics vmStat) {
+ public void repopulate(ProcessStatistics vmStat) {
vmStatistics = vmStat;
processPanel.populate(vmStatistics);
queuePanel.populate(vmStatistics);
@@ -150,7 +150,7 @@
public abstract String[] getLabelStrings();
/**Populate the displayed fields from the specified VMStatistics.*/
- public abstract void populate(VMStatistics vmStats);
+ public abstract void populate(ProcessStatistics vmStats);
public AbstractVMStatisticsPanel() {
@@ -225,7 +225,7 @@
}
/**Populate the displayed fields from the specified VMStatistics.*/
- public void populate(VMStatistics vmStats) {
+ public void populate(ProcessStatistics vmStats) {
textFieldWidgets[0].setText(Long.toString(vmStats.totalMemory));
textFieldWidgets[1].setText(Long.toString(vmStats.freeMemory));
textFieldWidgets[2].setText(Integer.toString(vmStats.threadCount));
@@ -261,7 +261,7 @@
}
/**Populate the displayed fields from the specified VMStatistics.*/
- public void populate(VMStatistics vmStats) {
+ public void populate(ProcessStatistics vmStats) {
WorkerPoolStats poolStats = vmStats.processPoolStats;
textFieldWidgets[0].setText(Integer.toString(poolStats.queued));
textFieldWidgets[1].setText(Integer.toString(0));
@@ -299,7 +299,7 @@
return labelStrings;
}
- public void populate(VMStatistics vmStats) {
+ public void populate(ProcessStatistics vmStats) {
SocketListenerStats listenerStats = vmStats.socketListenerStats;
textFieldWidgets[0].setText(Long.toString(listenerStats.objectsRead));
textFieldWidgets[1].setText(Long.toString(listenerStats.objectsWritten));
Modified: trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/admin/BaseAdmin.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/admin/BaseAdmin.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/admin/BaseAdmin.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -300,7 +300,7 @@
* @since 4.3
*/
private com.metamatrix.admin.api.objects.ConnectorBinding convertConnectorType(final com.metamatrix.common.config.api.ConnectorBinding src, final Object parent) {
- MMConnectorBinding binding = new MMConnectorBinding(new String[] {src.getDeployedName()});
+ MMConnectorBinding binding = new MMConnectorBinding(new String[] {src.getDeployedName(), "Embedded"}); //$NON-NLS-1$
binding.setConnectorTypeName(src.getComponentTypeID().getFullName());
binding.setCreated(src.getCreatedDate());
@@ -310,7 +310,6 @@
binding.setEnabled(src.isEnabled());
binding.setLastUpdated(src.getLastChangedDate());
binding.setLastUpdatedBy(src.getLastChangedBy());
- binding.setProcessID(0); // TODO:
binding.setProperties(src.getProperties());
binding.setRegistered(true);
binding.setRoutingUUID(src.getRoutingUUID());
Modified: trunk/server/src/main/java/com/metamatrix/admin/server/AbstractAdminImpl.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/admin/server/AbstractAdminImpl.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/admin/server/AbstractAdminImpl.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -83,8 +83,7 @@
import com.metamatrix.platform.security.api.service.SessionServiceInterface;
import com.metamatrix.platform.service.api.ServiceID;
import com.metamatrix.platform.service.api.exception.ServiceException;
-import com.metamatrix.platform.vm.api.controller.VMControllerInterface;
-import com.metamatrix.platform.vm.controller.VMControllerID;
+import com.metamatrix.platform.vm.api.controller.ProcessManagement;
import com.metamatrix.server.admin.apiimpl.RuntimeMetadataHelper;
import com.metamatrix.server.query.service.QueryServiceInterface;
@@ -412,19 +411,18 @@
protected void shutDownConnectorBinding(MMConnectorBinding binding, boolean stopNow) throws AdminException {
- VMControllerID vmControllerID = new VMControllerID(binding.getProcessID(), binding.getHostName());
- ServiceID serviceID = new ServiceID(binding.getServiceID(), vmControllerID);
+ ServiceID serviceID = new ServiceID(binding.getServiceID(), binding.getHostName(), binding.getProcessName());
try {
- VMControllerInterface vmController = getVMControllerInterface(serviceID.getVMControllerID());
+ ProcessManagement vmController = getProcessController(serviceID.getHostName(), serviceID.getProcessName());
vmController.stopService(serviceID, stopNow, true);
} catch (MetaMatrixComponentException e) {
throw new AdminComponentException(e);
}
}
- private VMControllerInterface getVMControllerInterface(VMControllerID id) throws MetaMatrixComponentException {
- return this.registry.getVM(id.getHostName(), id.toString()).getVMController();
+ private ProcessManagement getProcessController(String hostName, String processName) throws MetaMatrixComponentException {
+ return this.registry.getProcessBinding(hostName, processName).getProcessController();
}
/**
Modified: trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -94,8 +94,7 @@
import com.metamatrix.platform.service.api.exception.ServiceException;
import com.metamatrix.platform.util.ProductInfoConstants;
import com.metamatrix.platform.vm.controller.SocketListenerStats;
-import com.metamatrix.platform.vm.controller.VMControllerID;
-import com.metamatrix.platform.vm.controller.VMStatistics;
+import com.metamatrix.platform.vm.controller.ProcessStatistics;
import com.metamatrix.server.serverapi.RequestInfo;
/**
@@ -190,8 +189,7 @@
String name = serviceBinding.getDeployedName();
MMConnectorBinding binding;
- String[] identifierParts =
- new String[] {serviceBinding.getHostName(), deployedComponent.getVMComponentDefnID().getName(), name};
+ String[] identifierParts = new String[] {serviceBinding.getHostName(), serviceBinding.getProcessName(), name};
String key = MMAdminObject.buildIdentifier(identifierParts).toUpperCase();
if (runtimeMap.containsKey(key)) {
//reuse MMConnectorBinding from config
@@ -210,8 +208,6 @@
binding.setStateChangedTime(serviceBinding.getStateChangeTime());
binding.setRegistered(true);
binding.setServiceID(serviceBinding.getServiceID().getID());
- binding.setProcessID(serviceBinding.getServiceID().getVMControllerID().getID());
-
results.add(binding);
}
@@ -378,7 +374,7 @@
MMDQP dqp;
String[] identifierParts =
- new String[] {serviceBinding.getHostName(), deployedComponent.getVMComponentDefnID().getName(), name};
+ new String[] {serviceBinding.getHostName(), serviceBinding.getProcessName(), name};
String key = MMAdminObject.buildIdentifier(identifierParts).toUpperCase();
if (runtimeMap.containsKey(key)) {
//reuse MMDQP from config
@@ -401,7 +397,6 @@
dqp.setStateChangedTime(serviceBinding.getStateChangeTime());
dqp.setRegistered(true);
dqp.setServiceID(serviceBinding.getServiceID().getID());
- dqp.setProcessID(serviceBinding.getServiceID().getVMControllerID().getID());
results.add(dqp);
}
@@ -595,14 +590,12 @@
String[] identifierParts = new String[] {hostName, processName};
if (identifierMatches(identifier, identifierParts)) {
MMProcess process = new MMProcess(identifierParts);
- VMControllerID processID = processData.getProcessID();
process.setRunning(processData.isRegistered());
if (processData.isRegistered()) {
- process.setProcessID(processID.getID());
try {
- VMStatistics statistics = getRuntimeStateAdminAPIHelper().getVMStatistics(processID);
+ ProcessStatistics statistics = getRuntimeStateAdminAPIHelper().getVMStatistics(hostName, processName);
if (statistics != null) {
process.setFreeMemory(statistics.freeMemory);
process.setTotalMemory(statistics.totalMemory);
@@ -632,7 +625,7 @@
process.setQueueWorkerPool(workerPool);
}
}
- process.setInetAddress(getRuntimeStateAdminAPIHelper().getVMHostName(processID));
+ process.setInetAddress(getRuntimeStateAdminAPIHelper().getVMHostName(hostName, processName));
} catch (MetaMatrixComponentException e) {
//do nothing: sometimes when the process is just starting the RMI stub
//for SocketVMController is not initialized yet
@@ -1137,10 +1130,8 @@
if (iter2.hasNext()) {
ProcessData processData = (ProcessData) iter2.next();
- VMControllerID processID = processData.getProcessID();
-
try {
- byte[] logBytes = getRuntimeStateAdminAPIHelper().exportLogs(processID);
+ byte[] logBytes = getRuntimeStateAdminAPIHelper().exportLogs(processData.getHostName(), processData.getName());
FileUtils.convertByteArrayToFile(logBytes, tempDirName, hostName+".zip");//$NON-NLS-1$
} catch (MetaMatrixComponentException e) {
//do nothing: sometimes when the process is just starting the RMI stub
Modified: trunk/server/src/main/java/com/metamatrix/admin/server/ServerRuntimeStateAdminImpl.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/admin/server/ServerRuntimeStateAdminImpl.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/admin/server/ServerRuntimeStateAdminImpl.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -67,7 +67,6 @@
import com.metamatrix.platform.service.api.ServiceID;
import com.metamatrix.platform.service.api.ServiceInterface;
import com.metamatrix.platform.service.api.exception.ServiceException;
-import com.metamatrix.platform.vm.controller.VMControllerID;
/**
* @since 4.3
@@ -180,10 +179,8 @@
expectedServiceNames.addAll(getServiceNamesFromConfiguration(hostName, processName, bindingName));
- VMControllerID vmControllerID = new VMControllerID(binding.getProcessID(), hostName);
+ ServiceID serviceID = new ServiceID(binding.getServiceID(), hostName, processName);
- ServiceID serviceID = new ServiceID(binding.getServiceID(), vmControllerID);
-
getRuntimeStateAdminAPIHelper().restartService(serviceID);
}
}
@@ -290,10 +287,8 @@
String bindingName = identifierParts[2];
expectedServiceNames.addAll(getServiceNamesFromConfiguration(hostName, processName, bindingName));
+ ServiceID serviceID = new ServiceID(binding.getServiceID(), hostName, processName);
- VMControllerID vmControllerID = new VMControllerID(binding.getProcessID(), hostName);
- ServiceID serviceID = new ServiceID(binding.getServiceID(), vmControllerID);
-
getRuntimeStateAdminAPIHelper().stopService(serviceID, stopNow);
}
@@ -355,11 +350,9 @@
try {
MMProcess process = (MMProcess) processes.iterator().next();
- VMControllerID vmControllerID = new VMControllerID(process.getProcessID(), process.getHostName());
- getRuntimeStateAdminAPIHelper().stopProcess(vmControllerID, stopNow);
+ getRuntimeStateAdminAPIHelper().stopProcess(process.getHostName(), process.getProcessName(), stopNow);
-
if (waitUntilDone) {
boolean done = false;
while (! done) {
Modified: trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SocketVMController.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SocketVMController.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SocketVMController.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -45,8 +45,7 @@
import com.metamatrix.platform.util.PlatformProxyHelper;
import com.metamatrix.platform.vm.controller.ServerEvents;
import com.metamatrix.platform.vm.controller.SocketListenerStats;
-import com.metamatrix.platform.vm.controller.VMController;
-import com.metamatrix.platform.vm.controller.VMControllerID;
+import com.metamatrix.platform.vm.controller.ProcessController;
import com.metamatrix.server.Configuration;
import com.metamatrix.server.HostManagement;
import com.metamatrix.server.Main;
@@ -55,7 +54,7 @@
* Main class for a server process.
*/
@Singleton
-public class SocketVMController extends VMController {
+public class SocketVMController extends ProcessController {
public static final String SOCKET_CONTEXT = "ServerSocket"; //$NON-NLS-1$
@@ -77,8 +76,8 @@
private WorkerPool workerPool;
@Inject
- public SocketVMController((a)Named(Configuration.HOST) Host host, @Named(Configuration.VMNAME) String vmName, VMControllerID vmId, ClusteredRegistryState registry, ServerEvents serverEvents, MessageBus bus, HostManagement hostManagement) throws Exception {
- super(host, vmName, vmId, registry, serverEvents, bus, hostManagement);
+ public SocketVMController((a)Named(Configuration.HOST) Host host, @Named(Configuration.PROCESSNAME) String processName, ClusteredRegistryState registry, ServerEvents serverEvents, MessageBus bus, HostManagement hostManagement) throws Exception {
+ super(host, processName, registry, serverEvents, bus, hostManagement);
}
@Override
@@ -135,7 +134,7 @@
String bindaddress = VMNaming.getBindAddress();
final Object[] param = new Object[] {
- this.vmName, bindaddress, String.valueOf(socketPort)
+ this.processName, bindaddress, String.valueOf(socketPort)
};
logMessage(PlatformPlugin.Util.getString("SocketVMController.1", param)); //$NON-NLS-1$
@@ -175,14 +174,14 @@
return buffer.toString();
}
- public SocketListenerStats getSocketListenerStats() {
+ protected SocketListenerStats getSocketListenerStats() {
if (listener == null) {
return null;
}
return listener.getStats();
}
- public WorkerPoolStats getProcessPoolStats() {
+ protected WorkerPoolStats getProcessPoolStats() {
if (workerPool == null) {
return null;
}
Modified: trunk/server/src/main/java/com/metamatrix/common/log/DbLogWriter.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/log/DbLogWriter.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/common/log/DbLogWriter.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -312,7 +312,7 @@
stmt.setString(6, StringUtil.truncString(VMNaming.getConfigName(), maxGeneralLength));
// Message VM ID column
- stmt.setString(7, StringUtil.truncString(VMNaming.getVMName(), maxGeneralLength));
+ stmt.setString(7, StringUtil.truncString(VMNaming.getProcessName(), maxGeneralLength));
// Message thread name column
stmt.setString(8, StringUtil.truncString(message.getThreadName(), maxGeneralLength));
Modified: trunk/server/src/main/java/com/metamatrix/metadata/runtime/vdb/defn/VDBCreation.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/metadata/runtime/vdb/defn/VDBCreation.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/metadata/runtime/vdb/defn/VDBCreation.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -258,13 +258,13 @@
// still needs to stay the same
boolean beenCreated = false;
for (Iterator vmit=vmsToDeployTo.iterator(); vmit.hasNext();) {
- String vmname = (String) vmit.next();
- VMComponentDefn depVM = getDeployedVM(vmname, cmc);
+ String processName = (String) vmit.next();
+ VMComponentDefn depVM = getDeployedVM(processName, cmc);
// the VM has to be deployed (which is to have 1 or more pscs deployed to it) in order
// for the VM to be started
// *** Currently this process will not try to start a VM ***
if (depVM == null) {
- LogManager.logWarning(LogCommonConstants.CTX_CONFIG,RuntimeMetadataPlugin.Util.getString("VDBCreation.0", vmname)); //$NON-NLS-1$
+ LogManager.logWarning(LogCommonConstants.CTX_CONFIG,RuntimeMetadataPlugin.Util.getString("VDBCreation.0", processName)); //$NON-NLS-1$
continue;
}
@@ -276,7 +276,7 @@
continue;
}
}
- LogManager.logWarning(LogCommonConstants.CTX_CONFIG,RuntimeMetadataPlugin.Util.getString("VDBCreation.5", new Object[] {binding.getName(), vmname} )); //$NON-NLS-1$
+ LogManager.logWarning(LogCommonConstants.CTX_CONFIG,RuntimeMetadataPlugin.Util.getString("VDBCreation.5", new Object[] {binding.getName(), processName} )); //$NON-NLS-1$
processDeployment(depVM, cmc, (beenCreated?beenCreated:bindingExist), binding, type, createdPSC, editor);
@@ -413,11 +413,11 @@
}
}
- private VMComponentDefn getDeployedVM(String vmName,ConfigurationModelContainer cmc) throws Exception {
+ private VMComponentDefn getDeployedVM(String processName,ConfigurationModelContainer cmc) throws Exception {
Collection vms = cmc.getConfiguration().getVMComponentDefns();
for (Iterator it=vms.iterator(); it.hasNext();) {
VMComponentDefn vm = (VMComponentDefn) it.next();
- if (vm.getName().equalsIgnoreCase(vmName)) {
+ if (vm.getName().equalsIgnoreCase(processName)) {
return vm;
}
}
Modified: trunk/server/src/main/java/com/metamatrix/platform/admin/api/runtime/SystemStateBuilder.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/admin/api/runtime/SystemStateBuilder.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/admin/api/runtime/SystemStateBuilder.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -42,7 +42,7 @@
import com.metamatrix.platform.registry.ClusteredRegistryState;
import com.metamatrix.platform.registry.HostControllerRegistryBinding;
import com.metamatrix.platform.registry.ServiceRegistryBinding;
-import com.metamatrix.platform.registry.VMRegistryBinding;
+import com.metamatrix.platform.registry.ProcessRegistryBinding;
import com.metamatrix.platform.service.api.ServiceID;
import com.metamatrix.platform.service.api.ServiceState;
import com.metamatrix.platform.service.controller.ServicePropertyNames;
@@ -120,7 +120,7 @@
// loop thru all vm's for the host and create a ProcessData object for each.
while (iter.hasNext()) {
- VMRegistryBinding vmBinding = (VMRegistryBinding) iter.next();
+ ProcessRegistryBinding vmBinding = (ProcessRegistryBinding) iter.next();
processes.add(createProcessData(vmBinding));
deployedVMs.remove(vmBinding.getDeployedComponent());
}
@@ -169,23 +169,22 @@
/**
* Create a ProcessData object for the vmBinding.
*/
- private ProcessData createProcessData(VMRegistryBinding vmBinding) {
+ private ProcessData createProcessData(ProcessRegistryBinding vmBinding) {
// if this vm is not deployed (appServer VM) then
// create an empty ProcessData and return.
if (vmBinding.getDeployedComponent() == null) {
- return new ProcessData(vmBinding.getVMControllerID(),
- null, // deployed component id
- vmBinding.getHostName(),
- new ArrayList(),
- vmBinding.getVMName(),
- String.valueOf(vmBinding.getPort()),
- false, // not deployed
- true); // registered
+ return new ProcessData( vmBinding.getHostName(),
+ vmBinding.getProcessName(),
+ String.valueOf(vmBinding.getPort()),
+ null, // deployed component id
+ new ArrayList(),
+ false, // not deployed
+ true); // registered
}
// ServiceBindings for vm
- List bindings = this.registry.getServiceBindings(vmBinding.getHostName(), vmBinding.getVMControllerID().toString());
+ List bindings = this.registry.getServiceBindings(vmBinding.getHostName(), vmBinding.getProcessName());
// Map of pscIDs -> List of services
Map pscMap = new HashMap();
@@ -255,7 +254,7 @@
// create a list of psc's
List pscList = new ArrayList();
Iterator pscIter = pscMap.keySet().iterator();
- String processName = vmBinding.getVMName();
+ String processName = vmBinding.getProcessName();
while (pscIter.hasNext()) {
ProductServiceConfigID pId = (ProductServiceConfigID) pscIter.next();
@@ -271,12 +270,12 @@
deployedComponents.remove(dc);
}
- return new ProcessData(vmBinding.getVMControllerID(),
- (VMComponentDefnID) vmBinding.getDeployedComponent().getID(),
- vmBinding.getHostName(),
- pscList, vmBinding.getVMName(), vmBinding.getPort(),
- deployed, true);
-
+ return new ProcessData( vmBinding.getHostName(),
+ vmBinding.getProcessName(),
+ vmBinding.getPort(),
+ (VMComponentDefnID) vmBinding.getDeployedComponent().getID(),
+ pscList,
+ deployed, true);
}
@@ -336,12 +335,11 @@
String hostName = deployedVM.getHostID().getName();
- return new ProcessData(null,
+ return new ProcessData( hostName,
+ deployedVM.getName(), deployedVM.getPort(),
(VMComponentDefnID)deployedVM.getID(),
- hostName,
- pscList, deployedVM.getName(), deployedVM.getPort(),
+ pscList,
true, false); // deployed, not registered
-
}
/**
Modified: trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIHelper.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIHelper.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIHelper.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -57,7 +57,7 @@
import com.metamatrix.platform.registry.HostControllerRegistryBinding;
import com.metamatrix.platform.registry.ResourceNotBoundException;
import com.metamatrix.platform.registry.ServiceRegistryBinding;
-import com.metamatrix.platform.registry.VMRegistryBinding;
+import com.metamatrix.platform.registry.ProcessRegistryBinding;
import com.metamatrix.platform.security.api.service.AuthorizationServiceInterface;
import com.metamatrix.platform.security.api.service.MembershipServiceInterface;
import com.metamatrix.platform.security.api.service.SessionServiceInterface;
@@ -69,9 +69,8 @@
import com.metamatrix.platform.util.LogMessageKeys;
import com.metamatrix.platform.util.LogPlatformConstants;
import com.metamatrix.platform.util.PlatformProxyHelper;
-import com.metamatrix.platform.vm.api.controller.VMControllerInterface;
-import com.metamatrix.platform.vm.controller.VMControllerID;
-import com.metamatrix.platform.vm.controller.VMStatistics;
+import com.metamatrix.platform.vm.api.controller.ProcessManagement;
+import com.metamatrix.platform.vm.controller.ProcessStatistics;
import com.metamatrix.server.HostManagement;
@@ -119,8 +118,7 @@
SystemStateBuilder ssm = new SystemStateBuilder(this.registry, this.hostManagement);
return ssm.getSystemState();
} catch (Exception e) {
- throw new MetaMatrixComponentException(e, ErrorMessageKeys.ADMIN_0051,
- PlatformPlugin.Util.getString(ErrorMessageKeys.ADMIN_0051));
+ throw new MetaMatrixComponentException(e, ErrorMessageKeys.ADMIN_0051, PlatformPlugin.Util.getString(ErrorMessageKeys.ADMIN_0051));
}
}
@@ -167,25 +165,7 @@
return list;
}
- /**
- * Return all processes running in mm system.
- *
- * @param callerSessionID
- * ID of the caller's current session.
- * @return List of VMControllerIDs.
- * @throws MetaMatrixComponentException
- * if an error occurred in communicating with a component.
- */
- public List<VMControllerID> getProcesses() throws MetaMatrixComponentException {
- List processes = new ArrayList();
- List<VMRegistryBinding> bindings = this.registry.getVMs(null);
- for (VMRegistryBinding vmBinding:bindings) {
- processes.add(vmBinding.getVMControllerID());
- }
- return processes;
- }
-
/**
* Return VMStatistics object for Process.
*
@@ -197,15 +177,15 @@
* @throws MetaMatrixComponentException
* if an error occurred in communicating with a component.
*/
- public VMStatistics getVMStatistics(VMControllerID vmID) throws MetaMatrixComponentException {
- VMRegistryBinding vm = registry.getVM(vmID.getHostName(), vmID.toString());
- return vm.getVMController().getVMStatistics();
+ public ProcessStatistics getVMStatistics(String hostName, String processName) throws MetaMatrixComponentException {
+ ProcessRegistryBinding vm = registry.getProcessBinding(hostName, processName);
+ return vm.getProcessController().getVMStatistics();
}
- public InetAddress getVMHostName(VMControllerID vmID) throws MetaMatrixComponentException {
- VMRegistryBinding vm = registry.getVM(vmID.getHostName(), vmID.toString());
- return vm.getVMController().getAddress();
+ public InetAddress getVMHostName(String hostName, String processName) throws MetaMatrixComponentException {
+ ProcessRegistryBinding vm = registry.getProcessBinding(hostName, processName);
+ return vm.getProcessController().getAddress();
}
/**
@@ -239,7 +219,7 @@
* @return ServiceRegistryBinding
*/
public ServiceRegistryBinding getServiceBinding(ServiceID serviceID) throws ResourceNotBoundException {
- return this.registry.getServiceBinding(serviceID.getHostName(), serviceID.getVMControllerID().toString(), serviceID);
+ return this.registry.getServiceBinding(serviceID.getHostName(), serviceID.getProcessName(), serviceID);
}
/**
@@ -363,12 +343,12 @@
while (procIter.hasNext()) {
ProcessData pData = (ProcessData)procIter.next();
- VMControllerInterface vmController = null;
+ ProcessManagement vmController = null;
// if registered then get the VMController
if (pData.isRegistered()) {
try {
- VMRegistryBinding vmBinding = this.registry.getVM(pData.getProcessID().getHostName(), pData.getProcessID().toString());
- vmController = vmBinding.getVMController();
+ ProcessRegistryBinding vmBinding = this.registry.getProcessBinding(pData.getHostName(), pData.getName());
+ vmController = vmBinding.getProcessController();
} catch (Exception e) {
exceptions.add(e); // if we can't get the vmController then go to next process
// errorMsg.append(e.getMessage());
@@ -444,32 +424,11 @@
}
}
- public VMControllerInterface getVMControllerInterface(VMControllerID id) throws ResourceNotBoundException {
- return this.registry.getVM(id.getHostName(), id.toString()).getVMController();
+ public ProcessManagement getVMControllerInterface(String hostName, String processName) throws ResourceNotBoundException {
+ return this.registry.getProcessBinding(hostName, processName).getProcessController();
}
- /**
- * Start a deployed service.
- *
- * @param registry
- * The Registry.
- * @param id
- * ServiceComponentDefnID of service instance.
- * @param vmID
- * Identifies VMController to start service in.
- * @throws MetaMatrixComponentException
- * if an error occurred in communicating with a component.
- */
- public void startDeployedService(ServiceComponentDefnID serviceID, VMControllerID vmID) throws MetaMatrixComponentException {
- VMControllerInterface vmController = getVMControllerInterface(vmID);
- try {
- vmController.startDeployedService(serviceID);
- } catch (ServiceException se) {
- throw new MetaMatrixComponentException(se);
- }
- }
-
/**
* Restart a failed or stopped service.
*
@@ -482,10 +441,9 @@
*/
public void restartService(ServiceID serviceID) throws MetaMatrixComponentException {
- VMControllerID vmID = serviceID.getVMControllerID();
- VMRegistryBinding vmBinding = this.registry.getVM(vmID.getHostName(), vmID.toString());
+ ProcessRegistryBinding vmBinding = this.registry.getProcessBinding(serviceID.getHostName(), serviceID.getProcessName());
- VMControllerInterface vmController = vmBinding.getVMController();
+ ProcessManagement vmController = vmBinding.getProcessController();
try {
vmController.stopService(serviceID, false, false);
} catch (ServiceException se) {
@@ -499,7 +457,7 @@
}
/**
- * Set the Log Configuration in the database and propergate changes to other VM
+ * Set the Log Configuration in the database and propagate changes to other VM
*
* @param registry
* @param config
@@ -527,8 +485,7 @@
try {
configAdmin.executeTransaction(actions, principalName);
} catch (ModificationException e) {
- String msg = PlatformPlugin.Util.getString(ErrorMessageKeys.ADMIN_0084, config.getID());
- throw new MetaMatrixComponentException(e, ErrorMessageKeys.ADMIN_0084, msg);
+ throw new MetaMatrixComponentException(e, ErrorMessageKeys.ADMIN_0084, PlatformPlugin.Util.getString(ErrorMessageKeys.ADMIN_0084, config.getID()));
}
// Then, if the operational (current) config is effected, set logging config for
@@ -545,8 +502,8 @@
Iterator vmItr = registry.getVMs(null).iterator();
while (vmItr.hasNext()) {
- VMRegistryBinding vmBinding = (VMRegistryBinding)vmItr.next();
- VMControllerInterface vm = vmBinding.getVMController();
+ ProcessRegistryBinding vmBinding = (ProcessRegistryBinding)vmItr.next();
+ ProcessManagement vm = vmBinding.getProcessController();
vm.setCurrentLogConfiguration(logConfig);
}
if (msgs != null && msgs.length() > 0) {
@@ -569,9 +526,8 @@
*/
public void stopService(ServiceID serviceID, boolean stopNow) throws MetaMatrixComponentException {
- VMControllerID vmID = serviceID.getVMControllerID();
- VMRegistryBinding binding = registry.getVM(vmID.getHostName(), vmID.toString());
- VMControllerInterface vmController = binding.getVMController();
+ ProcessRegistryBinding binding = registry.getProcessBinding(serviceID.getHostName(), serviceID.getProcessName());
+ ProcessManagement vmController = binding.getProcessController();
try {
vmController.stopService(serviceID, stopNow, false);
} catch (ServiceException se) {
@@ -679,9 +635,9 @@
* @throws MetaMatrixComponentException
* if an error occurred in communicating with a component.
*/
- public void stopProcess(VMControllerID vmID, boolean stopNow)
+ public void stopProcess(String hostName, String processName, boolean stopNow)
throws AuthorizationException, MetaMatrixComponentException {
- this.hostManagement.killServer(vmID.getHostName(), vmID.toString(), stopNow);
+ this.hostManagement.killServer(hostName, processName, stopNow);
}
@@ -694,9 +650,9 @@
* @throws AdminException
* @since 4.3
*/
- public byte[] exportLogs(VMControllerID processID) throws MetaMatrixComponentException {
- VMRegistryBinding vmBinding = this.registry.getVM(processID.getHostName(), processID.toString());
- VMControllerInterface vmController = vmBinding.getVMController();
+ public byte[] exportLogs(String hostName, String processName) throws MetaMatrixComponentException {
+ ProcessRegistryBinding processBinding = this.registry.getProcessBinding(hostName, processName);
+ ProcessManagement vmController = processBinding.getProcessController();
return vmController.exportLogs();
}
Modified: trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIImpl.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIImpl.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIImpl.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -38,7 +38,6 @@
import com.metamatrix.api.exception.security.AuthorizationException;
import com.metamatrix.common.config.api.Configuration;
import com.metamatrix.common.config.api.ServiceComponentDefnID;
-import com.metamatrix.common.log.I18nLogManager;
import com.metamatrix.common.log.LogConfiguration;
import com.metamatrix.common.log.LogManager;
import com.metamatrix.common.log.reader.DBLogReader;
@@ -57,8 +56,9 @@
import com.metamatrix.platform.registry.ClusteredRegistryState;
import com.metamatrix.platform.registry.ResourceNotBoundException;
import com.metamatrix.platform.registry.ServiceRegistryBinding;
-import com.metamatrix.platform.registry.VMRegistryBinding;
+import com.metamatrix.platform.registry.ProcessRegistryBinding;
import com.metamatrix.platform.security.api.SessionToken;
+import com.metamatrix.platform.service.ServicePlugin;
import com.metamatrix.platform.service.api.ServiceID;
import com.metamatrix.platform.service.api.ServiceInterface;
import com.metamatrix.platform.service.api.ServiceState;
@@ -67,9 +67,8 @@
import com.metamatrix.platform.util.LogMessageKeys;
import com.metamatrix.platform.util.LogPlatformConstants;
import com.metamatrix.platform.util.PlatformProxyHelper;
-import com.metamatrix.platform.vm.api.controller.VMControllerInterface;
-import com.metamatrix.platform.vm.controller.VMControllerID;
-import com.metamatrix.platform.vm.controller.VMStatistics;
+import com.metamatrix.platform.vm.api.controller.ProcessManagement;
+import com.metamatrix.platform.vm.controller.ProcessStatistics;
import com.metamatrix.server.HostManagement;
public class RuntimeStateAdminAPIImpl extends SubSystemAdminAPIImpl implements RuntimeStateAdminAPI {
@@ -149,27 +148,7 @@
}
- /**
- * Return all processes running in mm system.
- *
- * @return List of VMControllerIDs.
- * @throws AuthorizationException
- * if caller is not authorized to perform this method.
- * @throws InvalidSessionException
- * if the <code>callerSessionID</code> is not valid or is expired.
- * @throws MetaMatrixComponentException
- * if an error occurred in communicating with a component.
- */
- public synchronized List<VMControllerID> getProcesses() throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException {
- // Validate caller's session
- AdminAPIHelper.validateSession(getSessionID());
-
- return helper.getProcesses();
- }
-
/**
* Return all hosts running in mm system.
*
@@ -209,9 +188,7 @@
// Validate caller's session
SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0003, new Object[] {
- serviceID, token.getUsername()
- });
+ LogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, ServicePlugin.Util.getString(LogMessageKeys.ADMIN_0003, new Object[] {serviceID, token.getUsername()}));
// Validate caller's role
AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.stopService(" + serviceID + ")"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -237,9 +214,7 @@
// Validate caller's session
SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0004, new Object[] {
- serviceID, token.getUsername()
- });
+ LogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, ServicePlugin.Util.getString(LogMessageKeys.ADMIN_0004, new Object[] {serviceID, token.getUsername()}));
// Validate caller's role
AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.stopServiceNow(" + serviceID + ")"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -266,9 +241,7 @@
// Validate caller's session
SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0005, new Object[] {
- host, token.getUsername()
- });
+ LogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, ServicePlugin.Util.getString(LogMessageKeys.ADMIN_0005, new Object[] {host, token.getUsername()}));
// Validate caller's role
AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.stopHost(" + host + ")"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -295,9 +268,7 @@
// Validate caller's session
SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0006, new Object[] {
- host, token.getUsername()
- });
+ LogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, ServicePlugin.Util.getString(LogMessageKeys.ADMIN_0006, new Object[] {host, token.getUsername()}));
// Validate caller's role
AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.stopHostNow(" + host + ")"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -318,50 +289,19 @@
* @throws MetaMatrixComponentException
* if an error occurred in communicating with a component.
*/
- public synchronized void stopProcess(VMControllerID processID) throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException {
+ public synchronized void stopProcess(String hostName, String processName, boolean now)
+ throws AuthorizationException,InvalidSessionException, MetaMatrixComponentException {
// Validate caller's session
SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0009, new Object[] {
- processID, token.getUsername()
- });
+ LogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, ServicePlugin.Util.getString(LogMessageKeys.ADMIN_0009, new Object[] {hostName+"."+processName, token.getUsername()})); //$NON-NLS-1$
// Validate caller's role
- AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.stopProcess(" + processID + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.stopProcess(" + hostName+","+ processName + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- helper.stopProcess(processID, false);
+ helper.stopProcess(hostName, processName, now);
}
- /**
- * Stop process now.
- *
- * @param processID
- * <code>VMControllerID</code>.
- * @throws AuthorizationException
- * if caller is not authorized to perform this method.
- * @throws InvalidSessionException
- * if the <code>callerSessionID</code> is not valid or is expired.
- * @throws MetaMatrixComponentException
- * if an error occurred in communicating with a component.
- */
- public synchronized void stopProcessNow(VMControllerID processID) throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException {
-
- // Validate caller's session
- SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0010, new Object[] {
- processID, token.getUsername()
- });
-
- // Validate caller's role
- AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.stopProcessNow(" + processID + ")"); //$NON-NLS-1$ //$NON-NLS-2$
-
- helper.stopProcess(processID, true);
- }
-
/**
* Gracefully shutdown server waiting for work to complete.
@@ -379,9 +319,7 @@
// Validate caller's session
SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0015, new Object[] {
- token.getUsername()
- });
+ LogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, ServicePlugin.Util.getString(LogMessageKeys.ADMIN_0015, new Object[] {token.getUsername()}));
// Validate caller's role
AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.shutdownServer()"); //$NON-NLS-1$
@@ -400,9 +338,7 @@
* @throws MetaMatrixComponentException
* if an error occurred in communicating with a component.
*/
- public synchronized void bounceServer() throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException {
+ public synchronized void bounceServer() throws AuthorizationException, InvalidSessionException, MetaMatrixComponentException {
// Validate caller's session
SessionToken token = AdminAPIHelper.validateSession(getSessionID());
@@ -432,9 +368,7 @@
InvalidSessionException,
MetaMatrixComponentException {
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0019, new Object[] {
- serviceID
- });
+ LogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, ServicePlugin.Util.getString(LogMessageKeys.ADMIN_0019, new Object[] {serviceID}));
// Validate caller's session
SessionToken token = AdminAPIHelper.validateSession(getSessionID());
@@ -463,9 +397,7 @@
// Validate caller's session
SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0020, new Object[] {
- host, token.getUsername()
- });
+ LogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, ServicePlugin.Util.getString(LogMessageKeys.ADMIN_0020, new Object[] {host, token.getUsername()}));
// Validate caller's role
AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.startHost(" + host + ")"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -486,16 +418,13 @@
* @throws MetaMatrixComponentException
* if an error occurred in communicating with a component.
*/
- public synchronized void startProcess(String host,
- String process) throws AuthorizationException,
+ public synchronized void startProcess(String host, String process) throws AuthorizationException,
InvalidSessionException,
MetaMatrixComponentException {
// Validate caller's session
SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0021, new Object[] {
- process, token.getUsername()
- });
+ LogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, ServicePlugin.Util.getString(LogMessageKeys.ADMIN_0021, new Object[] {process, token.getUsername()}));
// Validate caller's role
AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.startProcess(" + host + ", " + process + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -522,9 +451,8 @@
// Validate caller's session
SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0022, new Object[] {
- pscID, token.getUsername()
- });
+ LogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, ServicePlugin.Util.getString(LogMessageKeys.ADMIN_0022, new Object[] {pscID, token.getUsername()}));
+
// Validate caller's role
AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.startPSC(" + pscID + ")"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -548,31 +476,19 @@
}
// Helper method to start all services that are in a PSC
- private void startPSCServices(ProcessData processData,
- PSCData pscData) throws MetaMatrixComponentException,
- MultipleException {
+ private void startPSCServices(ProcessData processData, PSCData pscData)
+ throws MetaMatrixComponentException,MultipleException {
- // check if already running
- //if (pscData.isRegistered()) {
- // throw new MetaMatrixComponentException("PSC " + pscData.getName() + " is already running.");
- //}
-
// check that process is running
if (!processData.isRegistered()) {
- throw new MetaMatrixComponentException(ErrorMessageKeys.ADMIN_0069,
- PlatformPlugin.Util.getString(ErrorMessageKeys.ADMIN_0069,
- pscData.getName(),
- processData.getName()));
+ throw new MetaMatrixComponentException(ErrorMessageKeys.ADMIN_0069,PlatformPlugin.Util.getString(ErrorMessageKeys.ADMIN_0069,pscData.getName(),processData.getName()));
}
- VMControllerInterface vm = null;
+ ProcessManagement vm = null;
try {
- vm = helper.getVMControllerInterface(processData.getProcessID());
+ vm = helper.getVMControllerInterface(processData.getHostName(), processData.getName());
} catch (ResourceNotBoundException e) {
- throw new MetaMatrixComponentException(ErrorMessageKeys.ADMIN_0070,
- PlatformPlugin.Util.getString(ErrorMessageKeys.ADMIN_0070,
- pscData.getName(),
- processData.getName()));
+ throw new MetaMatrixComponentException(ErrorMessageKeys.ADMIN_0070,PlatformPlugin.Util.getString(ErrorMessageKeys.ADMIN_0070,pscData.getName(),processData.getName()));
}
List exceptions = new ArrayList();
@@ -649,9 +565,7 @@
// Validate caller's session
SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0023, new Object[] {
- pscID, token.getUsername()
- });
+ LogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, ServicePlugin.Util.getString(LogMessageKeys.ADMIN_0023, new Object[] {pscID, token.getUsername()}));
// Validate caller's role
AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.stopPSC(" + pscID + ", " + now + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -687,9 +601,9 @@
PlatformPlugin.Util.getString(ErrorMessageKeys.ADMIN_0056, pscData.getName()));
}
- VMControllerInterface vm = null;
+ ProcessManagement vm = null;
try {
- vm = helper.getVMControllerInterface(processData.getProcessID());
+ vm = helper.getVMControllerInterface(processData.getHostName(), processData.getName());
} catch (ResourceNotBoundException e) {
throw new MetaMatrixComponentException(ErrorMessageKeys.ADMIN_0074,
PlatformPlugin.Util.getString(ErrorMessageKeys.ADMIN_0074,
@@ -741,9 +655,7 @@
// Validate caller's session
SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0026, new Object[] {
- token.getUsername()
- });
+ LogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, ServicePlugin.Util.getString(LogMessageKeys.ADMIN_0026, new Object[] {token.getUsername()}));
// Validate caller's role
AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.synchronizeServer()"); //$NON-NLS-1$
@@ -806,8 +718,10 @@
}
+ private static String buildProcessId(String host, String process) {
+ return host+"."+process; //$NON-NLS-1$
+ }
-
/**
* Sets the <code>LogConfiguration</code> on the <code>LogManager</code> running in the given VM. If
* <code>null>/code> is passed in for vmID, set log config on the
@@ -820,30 +734,19 @@
* @throws InvalidSessionException if the <code>callerSessionID</code> is not valid or is expired.
* @throws MetaMatrixComponentException if an error occurred in communicating with a component.
*/
- public synchronized void setLoggingConfiguration(LogConfiguration logConfig,
- VMControllerID vmID) throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException {
- String theVMID = "App Server VM"; //$NON-NLS-1$
- if (vmID != null) {
- theVMID = vmID.toString();
- }
- LogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, CorePlugin.Util.getString(LogMessageKeys.ADMIN_0029, new Object[] {theVMID}));
+ public synchronized void setLoggingConfiguration(LogConfiguration logConfig, String hostName, String processName)
+ throws AuthorizationException, InvalidSessionException, MetaMatrixComponentException {
+
+ LogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, CorePlugin.Util.getString(LogMessageKeys.ADMIN_0029, new Object[] {buildProcessId(hostName, processName)}));
// Validate caller's session
SessionToken token = AdminAPIHelper.validateSession(getSessionID());
+
// Validate caller's role
- AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.setLoggingConfiguration(" + logConfig + ", " + vmID + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.setLoggingConfiguration(" + logConfig + ", " + buildProcessId(hostName, processName) + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- // Set App Server VM's log config if vmID == null.
- if (vmID == null) {
- LogManager.setLogConfiguration(logConfig);
- return;
- }
-
// Set logging config for given VM
- // VMControllerNotBoundException gets propagated (ancester is MetaMatrixComponentException)
- VMControllerInterface vm = helper.getVMControllerInterface(vmID);
+ ProcessManagement vm = helper.getVMControllerInterface(hostName, processName);
vm.setCurrentLogConfiguration(logConfig);
}
@@ -893,8 +796,7 @@
InvalidSessionException,
MetaMatrixComponentException {
- LogManager.logDetail(LogPlatformConstants.CTX_RUNTIME_ADMIN,
- "Getting queue statistics for " + queueName + " for service: " + serviceID); //$NON-NLS-1$ //$NON-NLS-2$
+ LogManager.logDetail(LogPlatformConstants.CTX_RUNTIME_ADMIN, "Getting queue statistics for " + queueName + " for service: " + serviceID); //$NON-NLS-1$ //$NON-NLS-2$
// Validate caller's session
AdminAPIHelper.validateSession(getSessionID());
@@ -917,18 +819,16 @@
* @throws MetaMatrixComponentException
* if an error occurred in communicating with a component.
*/
- public synchronized VMStatistics getVMStatistics(VMControllerID vmID) throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException {
+ public synchronized ProcessStatistics getProcessStatistics(String hostName, String processName)
+ throws AuthorizationException, InvalidSessionException, MetaMatrixComponentException {
- LogManager.logDetail(LogPlatformConstants.CTX_RUNTIME_ADMIN, "Getting vm statistics for " + vmID); //$NON-NLS-1$
+ LogManager.logDetail(LogPlatformConstants.CTX_RUNTIME_ADMIN, "Getting vm statistics for " + buildProcessId(hostName, processName)); //$NON-NLS-1$
// Validate caller's session
AdminAPIHelper.validateSession(getSessionID());
- // Any administrator may call this read-only method - no need to validate role
-
- return helper.getVMStatistics(vmID);
+ // Any administrator may call this read-only method - no need to validate role
+ return helper.getVMStatistics(hostName, processName);
}
/**
@@ -951,10 +851,10 @@
}
while (result == null && vmIter.hasNext()) {
- VMRegistryBinding vmBinding = (VMRegistryBinding)vmIter.next();
- if (vmBinding.getHostName().equalsIgnoreCase(hostName) && vmBinding.getVMName().equalsIgnoreCase(processName)) {
+ ProcessRegistryBinding processBinding = (ProcessRegistryBinding)vmIter.next();
+ if (processBinding.getHostName().equalsIgnoreCase(hostName) && processBinding.getProcessName().equalsIgnoreCase(processName)) {
- Iterator serviceIter = this.registry.getServiceBindings(hostName, vmBinding.getVMControllerID().toString()).iterator();
+ Iterator serviceIter = this.registry.getServiceBindings(hostName, processBinding.getProcessName()).iterator();
while (result == null && serviceIter.hasNext()) {
ServiceRegistryBinding binding = (ServiceRegistryBinding)serviceIter.next();
if (binding.getHostName().equalsIgnoreCase(hostName) &&
@@ -989,10 +889,10 @@
}
while (result == null && vmIter.hasNext()) {
- VMRegistryBinding vmBinding = (VMRegistryBinding)vmIter.next();
- if (vmBinding.getHostName().equalsIgnoreCase(hostName) && vmBinding.getVMName().equalsIgnoreCase(processName)) {
+ ProcessRegistryBinding processBinding = (ProcessRegistryBinding)vmIter.next();
+ if (processBinding.getHostName().equalsIgnoreCase(hostName) && processBinding.getProcessName().equalsIgnoreCase(processName)) {
- Iterator serviceIter = this.registry.getServiceBindings(hostName, vmBinding.getVMControllerID().toString()).iterator();
+ Iterator serviceIter = this.registry.getServiceBindings(hostName, processBinding.getProcessName()).iterator();
while (result == null && serviceIter.hasNext()) {
ServiceRegistryBinding binding = (ServiceRegistryBinding)serviceIter.next();
if (binding.getHostName().equalsIgnoreCase(hostName) &&
@@ -1010,63 +910,14 @@
* @see com.metamatrix.platform.admin.apiimpl.RuntimeStateAdminAPI#getVMControllerBindings()
* @since 4.2.1
*/
- public List<VMRegistryBinding> getVMControllerBindings() throws InvalidSessionException,
+ public List<ProcessRegistryBinding> getVMControllerBindings() throws InvalidSessionException,
AuthorizationException,
MetaMatrixComponentException {
AdminAPIHelper.validateSession(getSessionID());
return registry.getVMs(null);
}
- /**
- * @see com.metamatrix.platform.admin.apiimpl.RuntimeStateAdminAPI#getVMControllerIDByName(
- * java.lang.String, java.lang.String)
- * @since 4.2.1
- */
- public VMControllerID getVMControllerIDByName(String hostName,
- String processName) throws AuthorizationException,
- InvalidSessionException,
- ResourceNotBoundException,
- MetaMatrixComponentException {
- AdminAPIHelper.validateSession(getSessionID());
- VMControllerID result = null;
- Iterator vmIter = getVMControllerBindings().iterator();
- if (!vmIter.hasNext()) {
- return result;
- }
- while (vmIter.hasNext()) {
- VMRegistryBinding vmBinding = (VMRegistryBinding)vmIter.next();
- if (vmBinding.getHostName().equalsIgnoreCase(hostName) && vmBinding.getVMName().equalsIgnoreCase(processName)) {
- result = vmBinding.getVMControllerID();
- }
- }
- return result;
- }
-
- /**
- * @see com.metamatrix.platform.admin.apiimpl.RuntimeStateAdminAPI#getVMName(
- * long, java.lang.String)
- * @since 4.2.1
- */
- public String getVMName(long id, String hostName)
- throws AuthorizationException,InvalidSessionException, MetaMatrixComponentException {
-
- AdminAPIHelper.validateSession(getSessionID());
- VMControllerID vmID = new VMControllerID(id, hostName);
- String result = null;
- Iterator vmIter = getVMControllerBindings().iterator();
- while (vmIter.hasNext()) {
- VMRegistryBinding vmBinding = (VMRegistryBinding)vmIter.next();
- VMControllerID vmIDtemp = vmBinding.getVMController().getID();
- if (vmIDtemp.equals(vmID)) {
- result = vmBinding.getVMName();
- break;
- }
-
- }
- return result;
- }
-
/**
* @see com.metamatrix.platform.admin.api.RuntimeStateAdminAPI#getLogEntries(java.util.Date, java.util.Date, java.util.List, java.util.List, int)
* @since 4.3
Modified: trunk/server/src/main/java/com/metamatrix/platform/registry/ClusteredRegistryState.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/registry/ClusteredRegistryState.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/registry/ClusteredRegistryState.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -62,22 +62,22 @@
return node;
}
- private Cache addVMNode(String hostName, String vmName) throws CacheNodeNotFoundException {
+ private Cache addProcessNode(String hostName, String processName) throws CacheNodeNotFoundException {
Cache hostNode = getHostNode(hostName);
- Cache n = hostNode.addChild(vmName.toUpperCase());
- n.put(NAME, vmName);
+ Cache n = hostNode.addChild(processName.toUpperCase());
+ n.put(NAME, processName);
return n;
}
- private Cache getVMNode(String hostName, String vmName) throws CacheNodeNotFoundException {
+ private Cache getProcessNode(String hostName, String processName) throws CacheNodeNotFoundException {
Cache hostNode = getHostNode(hostName);
- Cache vmNode = hostNode.getChild(vmName.toUpperCase());
+ Cache vmNode = hostNode.getChild(processName.toUpperCase());
if (vmNode == null) {
- throw new CacheNodeNotFoundException("VM Node not found="+vmName); //$NON-NLS-1$
+ throw new CacheNodeNotFoundException("VM Node not found="+processName); //$NON-NLS-1$
}
// only return the active vms
- VMRegistryBinding binding = (VMRegistryBinding)vmNode.get(VM_CONTROLLER);
+ ProcessRegistryBinding binding = (ProcessRegistryBinding)vmNode.get(VM_CONTROLLER);
if (binding == null || !binding.isAlive()) {
throw new CacheNodeNotFoundException("VM Node's binding not found or not active"); //$NON-NLS-1$
}
@@ -95,23 +95,23 @@
this.cache.removeChild(hostName.toUpperCase());
}
- protected synchronized void addVM(String hostName, String vmName, VMRegistryBinding vmBinding) throws CacheNodeNotFoundException {
- Cache vmNode = addVMNode(hostName, vmName);
+ protected synchronized void addProcess(String hostName, String processName, ProcessRegistryBinding vmBinding) throws CacheNodeNotFoundException {
+ Cache vmNode = addProcessNode(hostName, processName);
vmNode.put(VM_CONTROLLER, vmBinding);
}
- protected void updateVM(String hostName, String vmName, VMRegistryBinding binding) throws ResourceNotBoundException, CacheNodeNotFoundException {
- Cache vmNode = getVMNode(hostName, vmName);
+ protected void updateProcess(String hostName, String processName, ProcessRegistryBinding binding) throws ResourceNotBoundException, CacheNodeNotFoundException {
+ Cache vmNode = getProcessNode(hostName, processName);
if (vmNode.get(VM_CONTROLLER) == null) {
- throw new ResourceNotBoundException(ServicePlugin.Util.getString(ServiceMessages.REGISTRY_0012, hostName+"/"+vmName )); //$NON-NLS-1$
+ throw new ResourceNotBoundException(ServicePlugin.Util.getString(ServiceMessages.REGISTRY_0012, hostName+"/"+processName )); //$NON-NLS-1$
}
vmNode.put(VM_CONTROLLER, binding);
}
- protected void removeVM(String hostName, String vmName) {
+ protected void removeProcess(String hostName, String processName) {
try {
Cache hostNode = getHostNode(hostName);
- hostNode.removeChild(vmName.toUpperCase());
+ hostNode.removeChild(processName.toUpperCase());
} catch (CacheNodeNotFoundException e) {
// this is OK, this is already gone.
}
@@ -146,11 +146,11 @@
* @param hostName
* @return
*/
- public List<VMRegistryBinding> getVMs(String hostName){
+ public List<ProcessRegistryBinding> getVMs(String hostName){
return getVMs(hostName, new ArrayList());
}
- private List<VMRegistryBinding> getVMs(String hostName, ArrayList list){
+ private List<ProcessRegistryBinding> getVMs(String hostName, ArrayList list){
if (hostName == null) {
Collection<Cache> hostNodes = this.cache.getChildren();
@@ -172,22 +172,22 @@
return list;
}
- public VMRegistryBinding getVM(String hostName, String vmName) throws ResourceNotBoundException {
+ public ProcessRegistryBinding getProcessBinding(String hostName, String processName) throws ResourceNotBoundException {
try {
- Cache vmNode = getVMNode(hostName, vmName);
- VMRegistryBinding binding = (VMRegistryBinding)vmNode.get(VM_CONTROLLER);
+ Cache vmNode = getProcessNode(hostName, processName);
+ ProcessRegistryBinding binding = (ProcessRegistryBinding)vmNode.get(VM_CONTROLLER);
if (binding == null) {
- throw new ResourceNotBoundException(ServicePlugin.Util.getString(ServiceMessages.REGISTRY_0012, hostName+"/"+vmName )); //$NON-NLS-1$
+ throw new ResourceNotBoundException(ServicePlugin.Util.getString(ServiceMessages.REGISTRY_0012, hostName+"/"+processName )); //$NON-NLS-1$
}
return binding;
} catch (CacheNodeNotFoundException e) {
- throw new ResourceNotBoundException(ServicePlugin.Util.getString(ServiceMessages.REGISTRY_0012, hostName+"/"+vmName )); //$NON-NLS-1$
+ throw new ResourceNotBoundException(ServicePlugin.Util.getString(ServiceMessages.REGISTRY_0012, hostName+"/"+processName )); //$NON-NLS-1$
}
}
- protected synchronized void addServiceBinding(String hostName, String vmName, ServiceRegistryBinding binding) throws ResourceAlreadyBoundException, CacheNodeNotFoundException {
- Cache services = getServices(hostName, vmName);
+ protected synchronized void addServiceBinding(String hostName, String processName, ServiceRegistryBinding binding) throws ResourceAlreadyBoundException, CacheNodeNotFoundException {
+ Cache services = getServices(hostName, processName);
// check if this service already exists
ServiceRegistryBinding existing = (ServiceRegistryBinding)services.get(binding.getServiceID());
@@ -198,8 +198,8 @@
services.put(binding.getServiceID(), binding);
}
- protected void updateServiceBinding(String hostName, String vmName, ServiceRegistryBinding binding) throws ResourceNotBoundException, CacheNodeNotFoundException {
- Cache services = getServices(hostName, vmName);
+ protected void updateServiceBinding(String hostName, String processName, ServiceRegistryBinding binding) throws ResourceNotBoundException, CacheNodeNotFoundException {
+ Cache services = getServices(hostName, processName);
// check if this service already exists
ServiceRegistryBinding existing = (ServiceRegistryBinding)services.get(binding.getServiceID());
@@ -210,10 +210,10 @@
services.put(binding.getServiceID(), binding);
}
- public ServiceRegistryBinding getServiceBinding(String hostName, String vmName, ServiceID serviceId ) throws ResourceNotBoundException {
+ public ServiceRegistryBinding getServiceBinding(String hostName, String processName, ServiceID serviceId ) throws ResourceNotBoundException {
ServiceRegistryBinding binding;
try {
- Cache services = getServices(hostName, vmName);
+ Cache services = getServices(hostName, processName);
binding = (ServiceRegistryBinding)services.get(serviceId);
if (binding == null) {
throw new ResourceNotBoundException(ServicePlugin.Util.getString(ServiceMessages.REGISTRY_0011, serviceId ));
@@ -225,21 +225,21 @@
}
- public List<ServiceRegistryBinding> getActiveServiceBindings(String hostName, String vmName, String serviceType) {
- return getServiceBindings(hostName, vmName, serviceType);
+ public List<ServiceRegistryBinding> getActiveServiceBindings(String hostName, String processName, String serviceType) {
+ return getServiceBindings(hostName, processName, serviceType);
}
public List<ServiceRegistryBinding> getServiceBindings(String serviceType) {
return getServiceBindings(null, null, serviceType);
}
- public List<ServiceRegistryBinding> getServiceBindings(String hostName, String vmName, String serviceType) {
- return getServiceBindings(hostName, vmName, serviceType, false);
+ public List<ServiceRegistryBinding> getServiceBindings(String hostName, String processName, String serviceType) {
+ return getServiceBindings(hostName, processName, serviceType, false);
}
- private List<ServiceRegistryBinding> getServiceBindings(String hostName, String vmName, String serviceType, boolean active) {
+ private List<ServiceRegistryBinding> getServiceBindings(String hostName, String processName, String serviceType, boolean active) {
List services = new ArrayList();
- List<ServiceRegistryBinding> bindings = getServiceBindings(hostName, vmName);
+ List<ServiceRegistryBinding> bindings = getServiceBindings(hostName, processName);
for (ServiceRegistryBinding binding:bindings) {
if (binding.getServiceType().equals(serviceType)) {
if (!active || (active && binding.isActive())) {
@@ -250,27 +250,27 @@
return services;
}
- public List<ServiceRegistryBinding> getServiceBindings(String hostName, String vmName) {
- return getServiceBindings(hostName, vmName, new ArrayList());
+ public List<ServiceRegistryBinding> getServiceBindings(String hostName, String processName) {
+ return getServiceBindings(hostName, processName, new ArrayList());
}
- private List<ServiceRegistryBinding> getServiceBindings(String hostName, String vmName, ArrayList list) {
+ private List<ServiceRegistryBinding> getServiceBindings(String hostName, String processName, ArrayList list) {
try {
- if (hostName == null && vmName == null) {
+ if (hostName == null && processName == null) {
Collection<Cache> hostNodes = this.cache.getChildren();
for(Cache host:hostNodes) {
getServiceBindings((String)host.get(NAME), null, list);
}
}
- else if (hostName != null && vmName == null) {
+ else if (hostName != null && processName == null) {
Collection<Cache> vmNodes = getHostNode(hostName).getChildren();
for(Cache vm:vmNodes) {
getServiceBindings(hostName, (String)vm.get(NAME), list);
}
}
- else if (hostName != null && vmName != null) {
- Cache services = getServices(hostName, vmName);
+ else if (hostName != null && processName != null) {
+ Cache services = getServices(hostName, processName);
list.addAll(services.values());
}
} catch (CacheNodeNotFoundException e) {
@@ -279,8 +279,8 @@
return list;
}
- private Cache getServices(String hostName, String vmName) throws CacheNodeNotFoundException {
- Cache vmNode = getVMNode(hostName, vmName);
+ private Cache getServices(String hostName, String processName) throws CacheNodeNotFoundException {
+ Cache vmNode = getProcessNode(hostName, processName);
Cache services = vmNode.getChild(SERVICES);
if (services == null) {
services = vmNode.addChild(SERVICES);
@@ -288,9 +288,9 @@
return services;
}
- protected void removeServiceBinding(String hostName, String vmName, ServiceID serviceId) {
+ protected void removeServiceBinding(String hostName, String processName, ServiceID serviceId) {
try {
- Cache services = getServices(hostName, vmName);
+ Cache services = getServices(hostName, processName);
services.remove(serviceId);
} catch (CacheNodeNotFoundException e) {
// OK, this already gone.
Copied: trunk/server/src/main/java/com/metamatrix/platform/registry/ProcessMonitor.java (from rev 534, trunk/server/src/main/java/com/metamatrix/platform/registry/VMMonitor.java)
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/registry/ProcessMonitor.java (rev 0)
+++ trunk/server/src/main/java/com/metamatrix/platform/registry/ProcessMonitor.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -0,0 +1,198 @@
+/*
+ * 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 com.metamatrix.platform.registry;
+
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.google.inject.name.Named;
+import com.metamatrix.common.log.LogManager;
+import com.metamatrix.common.util.LogCommonConstants;
+import com.metamatrix.core.MetaMatrixRuntimeException;
+import com.metamatrix.platform.registry.ClusteredRegistryState.CacheNodeNotFoundException;
+import com.metamatrix.platform.service.api.ServiceID;
+import com.metamatrix.platform.service.api.ServiceInterface;
+import com.metamatrix.platform.service.api.exception.ServiceException;
+import com.metamatrix.platform.service.api.exception.ServiceStateException;
+import com.metamatrix.platform.vm.api.controller.ProcessManagement;
+import com.metamatrix.platform.vm.controller.ServerEvents;
+import com.metamatrix.server.Configuration;
+
+/**
+ * This really needs to be the part of/ or be the VMController.
+ *
+ */
+@Singleton
+public class ProcessMonitor implements ServerEvents {
+
+ private static final int POLLING_INTERVAL_DEFAULT = 1000*15;
+
+ @Named("metamatrix.server.serviceMonitorInterval") // what is good usage of these kind ??
+ int pollingIntervel = POLLING_INTERVAL_DEFAULT;
+
+ ClusteredRegistryState registry;
+ String hostName;
+ String processName;
+
+ // Monitors remote vm's to detect when they go down.
+ private Timer vmPollingThread = new Timer("VMPollingThread", true); //$NON-NLS-1$
+ private Timer servicePollingThread = new Timer("ServiceMonitoringThread", true); //$NON-NLS-1$
+
+ @Inject
+ public ProcessMonitor (@Named(Configuration.HOSTNAME)String hostName, @Named(Configuration.PROCESSNAME)String processname, ClusteredRegistryState registry) {
+
+ this.hostName = hostName;
+ this.processName = processname;
+ this.registry = registry;
+
+ // check the health of the other VMS
+ startVMPollingThread();
+
+ // check health of the local services
+ startServicePollingThread();
+ }
+
+ /**
+ * Should be called when the local VM is going down.
+ */
+ public void shutdown() {
+ this.registry.removeProcess(this.hostName, this.processName);
+ }
+
+ private void startVMPollingThread() {
+ // Poll vm's to detect when a vm crashes
+ vmPollingThread.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ List<ProcessRegistryBinding> vmBindings = ProcessMonitor.this.registry.getVMs(null);
+
+ for (ProcessRegistryBinding binding: vmBindings) {
+ ProcessManagement vm = binding.getProcessController();
+ boolean alive = binding.isAlive();
+
+ try {
+ vm.ping();
+ binding.setAlive(true);
+ } catch (ServiceException e) {
+ // mark as not alive, then no services will be pinged from this vm
+ binding.setAlive(false);
+ }
+
+ // if the vmstate changed then, update the registry.
+ if (alive != binding.isAlive()) {
+ processUpdated(binding);
+ }
+ }
+ }
+ }, POLLING_INTERVAL_DEFAULT, POLLING_INTERVAL_DEFAULT);
+ }
+
+ private void startServicePollingThread() {
+ servicePollingThread.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ List<ServiceRegistryBinding> bindings = registry.getServiceBindings(hostName, processName);
+ for (ServiceRegistryBinding binding:bindings) {
+
+ ServiceInterface si = binding.getService();
+ try {
+ // when service in stopped state; this will be null
+ // if shut down there will not be a binding for it.
+ if(si != null) {
+ binding.getService().checkState();
+ }
+ } catch (ServiceStateException e) {
+ // OK to throw up, service will capture the error to logs.
+ }
+
+ // the state of the service changed, then update the cache.
+ if (binding.isDirty()) {
+ serviceUpdated(binding);
+ binding.setDirty(false);
+ }
+ }
+ }
+ }, pollingIntervel, pollingIntervel);
+ }
+
+ public void serviceAdded(ServiceRegistryBinding binding) {
+ try {
+ this.registry.addServiceBinding(hostName, processName, binding);
+ LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "Service Added:"+binding.getServiceID()); //$NON-NLS-1$
+ } catch (ResourceAlreadyBoundException e) {
+ LogManager.logWarning(LogCommonConstants.CTX_CONTROLLER, "Service already exists:"+binding.getServiceID()); //$NON-NLS-1$
+ } catch(CacheNodeNotFoundException e) {
+ LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, "Failed to add service:"+binding.getServiceID()); //$NON-NLS-1$
+ }
+ }
+
+ public void serviceRemoved(ServiceID id) {
+ this.registry.removeServiceBinding(hostName, processName, id);
+ LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "Service removed:"+id); //$NON-NLS-1$
+ }
+
+ public void processAdded(ProcessRegistryBinding binding) {
+ binding.setAlive(true);
+ try {
+ this.registry.addProcess(binding.getHostName(), binding.getProcessName(), binding);
+ LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "VM Added:"+binding); //$NON-NLS-1$
+ } catch (CacheNodeNotFoundException e) {
+ LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, "Failed to add VM:"+binding); //$NON-NLS-1$
+ throw new MetaMatrixRuntimeException("Failed to add VM:"+binding); //$NON-NLS-1$
+ }
+
+ }
+
+ public void processRemoved(String hostName, String processName) {
+ this.registry.removeProcess(hostName, processName);
+ LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "VM Removed:<"+hostName+"."+processName+">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ @Override
+ public void serviceUpdated(ServiceRegistryBinding binding) {
+ try {
+ this.registry.updateServiceBinding(binding.getHostName(), binding.getServiceID().getProcessName(), binding);
+ LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "Service updated:"+binding.getServiceID()); //$NON-NLS-1$
+ } catch(CacheNodeNotFoundException e) {
+ LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, "Failed to add service:"+binding.getServiceID()); //$NON-NLS-1$
+ } catch (ResourceNotBoundException e) {
+ LogManager.logWarning(LogCommonConstants.CTX_CONTROLLER, "Service not exist:"+binding.getServiceID()); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ public void processUpdated(ProcessRegistryBinding binding) {
+ try {
+ this.registry.updateProcess(binding.getHostName(), binding.getProcessName(), binding);
+ LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "VM Added:" + binding); //$NON-NLS-1$
+ } catch (CacheNodeNotFoundException e) {
+ LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, "Failed to add VM:"+ binding); //$NON-NLS-1$
+ throw new MetaMatrixRuntimeException("Failed to add VM:" + binding); //$NON-NLS-1$
+ } catch(ResourceNotBoundException e) {
+ LogManager.logWarning(LogCommonConstants.CTX_CONTROLLER, "VM does not exist:"+binding); //$NON-NLS-1$
+ }
+ }
+}
Copied: trunk/server/src/main/java/com/metamatrix/platform/registry/ProcessRegistryBinding.java (from rev 534, trunk/server/src/main/java/com/metamatrix/platform/registry/VMRegistryBinding.java)
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/registry/ProcessRegistryBinding.java (rev 0)
+++ trunk/server/src/main/java/com/metamatrix/platform/registry/ProcessRegistryBinding.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -0,0 +1,130 @@
+/*
+ * 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 com.metamatrix.platform.registry;
+
+import java.io.Serializable;
+
+import com.metamatrix.common.config.api.VMComponentDefn;
+import com.metamatrix.common.messaging.MessageBus;
+import com.metamatrix.platform.vm.api.controller.ProcessManagement;
+import com.metamatrix.server.ResourceFinder;
+
+/**
+ * This class is a container for ServiceRegistryBinding objects for
+ * all the services running in this VM
+ */
+public class ProcessRegistryBinding implements Serializable {
+
+ /** Host that this VM belongs to. */
+ private String hostName;
+
+ /** Name of vm */
+ private String processName;
+
+ private boolean alive;
+
+ /**
+ * Local reference to VMController, this is transient to prevent it from
+ * being sent to other vm's. Remote vm's must use the stub to access vmController
+ */
+ private transient ProcessManagement processController;
+
+ /** Remote reference to VMController */
+ private Object vmControllerStub;
+
+ /** defines vm in configuration */
+ // TODO: this is part of configuration, this should be removed from here..
+ private VMComponentDefn vmComponent;
+
+ private transient MessageBus messageBus;
+
+ public ProcessRegistryBinding(String hostName, String processName, VMComponentDefn deployedComponent, ProcessManagement vmController, MessageBus bus) {
+ this.hostName = hostName;
+ this.processName = processName;
+ this.vmComponent = deployedComponent;
+ this.processController = vmController;
+ this.messageBus = bus;
+ this.vmControllerStub = getStub(vmController);
+ }
+
+ private Object getStub(ProcessManagement controller) {
+ if (controller == null) {
+ return null;
+ }
+ return this.messageBus.export(controller, new Class[] {ProcessManagement.class});
+ }
+
+ /**
+ * Return reference for VMController.
+ * If VMController is running in this VM then return local reference.
+ * Else return remote reference.
+ *
+ * @return VMController reference
+ */
+ public synchronized ProcessManagement getProcessController() {
+
+ // if vmController is null then this must be a remote vm so return the stub.
+ if (this.processController != null) {
+ return processController;
+ }
+ if (this.vmControllerStub == null) {
+ return null;
+ }
+ // when exported to the remote, use remote's message bus instance.
+ MessageBus bus = this.messageBus;
+ if(bus == null) {
+ bus = ResourceFinder.getMessageBus();
+ }
+ processController = (ProcessManagement)bus.getRPCProxy(this.vmControllerStub);
+ return processController;
+ }
+
+ public VMComponentDefn getDeployedComponent() {
+ return this.vmComponent;
+ }
+
+ public String getHostName() {
+ return hostName;
+ }
+
+ public String getProcessName() {
+ return processName;
+ }
+
+ public String getPort() {
+ return vmComponent.getPort();
+ }
+
+ public boolean isAlive() {
+ return this.alive;
+ }
+
+ public void setAlive(boolean flag) {
+ this.alive = flag;
+ }
+
+ public String toString() {
+ return "Process<" +this.hostName+"|"+ this.processName + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+}
+
Modified: trunk/server/src/main/java/com/metamatrix/platform/registry/ServiceRegistryBinding.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/registry/ServiceRegistryBinding.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/registry/ServiceRegistryBinding.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -205,6 +205,10 @@
public String getHostName() {
return this.hostName;
}
+
+ public String getProcessName() {
+ return this.serviceID.getProcessName();
+ }
public int getCurrentState() {
return this.currentState;
Deleted: trunk/server/src/main/java/com/metamatrix/platform/registry/VMMonitor.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/registry/VMMonitor.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/registry/VMMonitor.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -1,201 +0,0 @@
-/*
- * 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 com.metamatrix.platform.registry;
-
-import java.util.List;
-import java.util.Timer;
-import java.util.TimerTask;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.google.inject.name.Named;
-import com.metamatrix.common.log.LogManager;
-import com.metamatrix.common.util.LogCommonConstants;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.platform.registry.ClusteredRegistryState.CacheNodeNotFoundException;
-import com.metamatrix.platform.service.api.ServiceID;
-import com.metamatrix.platform.service.api.ServiceInterface;
-import com.metamatrix.platform.service.api.exception.ServiceException;
-import com.metamatrix.platform.service.api.exception.ServiceStateException;
-import com.metamatrix.platform.vm.api.controller.VMControllerInterface;
-import com.metamatrix.platform.vm.controller.ServerEvents;
-import com.metamatrix.platform.vm.controller.VMControllerID;
-import com.metamatrix.server.Configuration;
-
-/**
- * This really needs to be the part of/ or be the VMController.
- *
- */
-@Singleton
-public class VMMonitor implements ServerEvents {
-
- private static final int POLLING_INTERVAL_DEFAULT = 1000*15;
-
- @Named("metamatrix.server.serviceMonitorInterval") // what is good usage of these kind ??
- int pollingIntervel = POLLING_INTERVAL_DEFAULT;
-
- ClusteredRegistryState registry;
- String hostName;
- String vmName;
- VMControllerID vmId;
-
- // Monitors remote vm's to detect when they go down.
- private Timer vmPollingThread = new Timer("VMPollingThread", true); //$NON-NLS-1$
- private Timer servicePollingThread = new Timer("ServiceMonitoringThread", true); //$NON-NLS-1$
-
- @Inject
- public VMMonitor (@Named(Configuration.HOSTNAME)String hostName, @Named(Configuration.VMNAME)String vmName, VMControllerID vmId, ClusteredRegistryState registry) {
-
- this.hostName = hostName;
- this.vmName = vmName;
- this.vmId = vmId;
- this.registry = registry;
-
- // check the health of the other VMS
- startVMPollingThread();
-
- // check health of the local services
- startServicePollingThread();
- }
-
- /**
- * Should be called when the local VM is going down.
- */
- public void shutdown() {
- this.registry.removeVM(this.hostName, this.vmId.toString());
- }
-
- private void startVMPollingThread() {
- // Poll vm's to detect when a vm crashes
- vmPollingThread.schedule(new TimerTask() {
- @Override
- public void run() {
- List<VMRegistryBinding> vmBindings = VMMonitor.this.registry.getVMs(null);
-
- for (VMRegistryBinding binding: vmBindings) {
- VMControllerInterface vm = binding.getVMController();
- boolean alive = binding.isAlive();
-
- try {
- vm.ping();
- binding.setAlive(true);
- } catch (ServiceException e) {
- // mark as not alive, then no services will be pinged from this vm
- binding.setAlive(false);
- }
-
- // if the vmstate changed then, update the registry.
- if (alive != binding.isAlive()) {
- vmUpdated(binding);
- }
- }
- }
- }, POLLING_INTERVAL_DEFAULT, POLLING_INTERVAL_DEFAULT);
- }
-
- private void startServicePollingThread() {
- servicePollingThread.schedule(new TimerTask() {
- @Override
- public void run() {
- List<ServiceRegistryBinding> bindings = registry.getServiceBindings(hostName, vmId.toString());
- for (ServiceRegistryBinding binding:bindings) {
-
- ServiceInterface si = binding.getService();
- try {
- // when service in stopped state; this will be null
- // if shut down there will not be a binding for it.
- if(si != null) {
- binding.getService().checkState();
- }
- } catch (ServiceStateException e) {
- // OK to throw up, service will capture the error to logs.
- }
-
- // the state of the service changed, then update the cache.
- if (binding.isDirty()) {
- serviceUpdated(binding);
- binding.setDirty(false);
- }
- }
- }
- }, pollingIntervel, pollingIntervel);
- }
-
- public void serviceAdded(ServiceRegistryBinding binding) {
- try {
- this.registry.addServiceBinding(hostName, vmId.toString(), binding);
- LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "Service Added:"+binding.getServiceID()); //$NON-NLS-1$
- } catch (ResourceAlreadyBoundException e) {
- LogManager.logWarning(LogCommonConstants.CTX_CONTROLLER, "Service already exists:"+binding.getServiceID()); //$NON-NLS-1$
- } catch(CacheNodeNotFoundException e) {
- LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, "Failed to add service:"+binding.getServiceID()); //$NON-NLS-1$
- }
- }
-
- public void serviceRemoved(ServiceID id) {
- this.registry.removeServiceBinding(hostName, vmId.toString(), id);
- LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "Service removed:"+id); //$NON-NLS-1$
- }
-
- public void vmAdded(VMRegistryBinding binding) {
- binding.setAlive(true);
- try {
- this.registry.addVM(hostName, vmId.toString(), binding);
- LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "VM Added:"+binding.getVMControllerID()); //$NON-NLS-1$
- } catch (CacheNodeNotFoundException e) {
- LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, "Failed to add VM:"+binding.getVMControllerID()); //$NON-NLS-1$
- throw new MetaMatrixRuntimeException("Failed to add VM:"+binding.getVMControllerID()); //$NON-NLS-1$
- }
-
- }
-
- public void vmRemoved(VMControllerID id) {
- this.registry.removeVM(hostName, vmId.toString());
- LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "VM Removed:"+id); //$NON-NLS-1$
- }
-
- @Override
- public void serviceUpdated(ServiceRegistryBinding binding) {
- try {
- this.registry.updateServiceBinding(binding.getHostName(), binding.getServiceID().getVMControllerID().toString(), binding);
- LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "Service updated:"+binding.getServiceID()); //$NON-NLS-1$
- } catch(CacheNodeNotFoundException e) {
- LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, "Failed to add service:"+binding.getServiceID()); //$NON-NLS-1$
- } catch (ResourceNotBoundException e) {
- LogManager.logWarning(LogCommonConstants.CTX_CONTROLLER, "Service not exist:"+binding.getServiceID()); //$NON-NLS-1$
- }
- }
-
- @Override
- public void vmUpdated(VMRegistryBinding binding) {
- try {
- this.registry.updateVM(binding.getHostName(), binding.getVMControllerID().toString(), binding);
- LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "VM Added:"+binding.getVMControllerID()); //$NON-NLS-1$
- } catch (CacheNodeNotFoundException e) {
- LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, "Failed to add VM:"+binding.getVMControllerID()); //$NON-NLS-1$
- throw new MetaMatrixRuntimeException("Failed to add VM:"+binding.getVMControllerID()); //$NON-NLS-1$
- } catch(ResourceNotBoundException e) {
- LogManager.logWarning(LogCommonConstants.CTX_CONTROLLER, "VM does not exist:"+binding.getVMControllerID()); //$NON-NLS-1$
- }
- }
-}
Deleted: trunk/server/src/main/java/com/metamatrix/platform/registry/VMRegistryBinding.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/registry/VMRegistryBinding.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/registry/VMRegistryBinding.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -1,152 +0,0 @@
-/*
- * 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 com.metamatrix.platform.registry;
-
-import java.io.Serializable;
-
-import com.metamatrix.common.config.api.VMComponentDefn;
-import com.metamatrix.common.messaging.MessageBus;
-import com.metamatrix.server.ResourceFinder;
-import com.metamatrix.platform.vm.api.controller.VMControllerInterface;
-import com.metamatrix.platform.vm.controller.VMControllerID;
-
-/**
- * This class is a container for ServiceRegistryBinding objects for
- * all the services running in this VM
- */
-public class VMRegistryBinding implements Serializable {
-
- /** ID of VMControllerID */
- private VMControllerID vmID;
-
- /** Host that this VM belongs to. */
- private String hostName;
-
- /** Name of vm */
- private String vmName;
-
- private boolean alive;
-
- /**
- * Local reference to VMController, this is transient to prevent it from
- * being sent to other vm's. Remote vm's must use the stub to access vmController
- */
- private transient VMControllerInterface vmController;
-
- /** Remote reference to VMController */
- private Object vmControllerStub;
-
- /** defines vm in configuration */
- // TODO: this is part of configuration, this should be removed from here..
- private VMComponentDefn vmComponent;
-
- private transient MessageBus messageBus;
-
- public VMRegistryBinding(String hostName, VMControllerID vmID, VMComponentDefn deployedComponent, VMControllerInterface vmController, MessageBus bus) {
- this.hostName = hostName;
- this.vmID = vmID;
- this.vmComponent = deployedComponent;
- this.vmController = vmController;
- this.messageBus = bus;
- try {
- this.vmName = vmController.getName();
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- this.vmControllerStub = getStub(vmController);
-
- }
-
- private Object getStub(VMControllerInterface controller) {
- if (controller == null) {
- return null;
- }
- return this.messageBus.export(controller, new Class[] {VMControllerInterface.class});
- }
-
-
- /**
- * Return VMControllerID that this binding represents.
- *
- * @return VMControllerID
- */
- public VMControllerID getVMControllerID() {
- return vmID;
- }
-
-
- /**
- * Return reference for VMController.
- * If VMController is running in this VM then return local reference.
- * Else return remote reference.
- *
- * @return VMController reference
- */
- public synchronized VMControllerInterface getVMController() {
-
- // if vmController is null then this must be a remote vm so return the stub.
- if (this.vmController != null) {
- return vmController;
- }
- if (this.vmControllerStub == null) {
- return null;
- }
- // when exported to the remote, use remote's message bus instance.
- MessageBus bus = this.messageBus;
- if(bus == null) {
- bus = ResourceFinder.getMessageBus();
- }
- vmController = (VMControllerInterface)bus.getRPCProxy(this.vmControllerStub);
- return vmController;
- }
-
- public VMComponentDefn getDeployedComponent() {
- return this.vmComponent;
- }
-
- public String getHostName() {
- return hostName;
- }
-
- public String getVMName() {
- return vmName;
- }
-
- public String getPort() {
- return vmComponent.getPort();
- }
-
- public boolean isAlive() {
- return this.alive;
- }
-
- public void setAlive(boolean flag) {
- this.alive = flag;
- }
-
- public String toString() {
- return "VMRegistryBinding: " + this.vmName + " <" + this.vmID + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-}
-
Modified: trunk/server/src/main/java/com/metamatrix/platform/security/audit/AuditMessage.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/security/audit/AuditMessage.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/security/audit/AuditMessage.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -30,7 +30,7 @@
import com.metamatrix.common.util.VMNaming;
public class AuditMessage implements Externalizable {
- public static final String VM_NAME = VMNaming.getVMName();
+ public static final String PROCESS_NAME = VMNaming.getProcessName();
public static final String HOST_NAME = VMNaming.getConfigName();
private static final String RESOURCE_DELIMITER = ", "; //$NON-NLS-1$
@@ -43,7 +43,7 @@
private long timestamp;
//private String threadName;
private String hostName;
- private String vmName;
+ private String processName;
public AuditMessage() {
}
@@ -57,7 +57,7 @@
this.timestamp = System.currentTimeMillis();
//this.threadName = Thread.currentThread().getName();
this.hostName = HOST_NAME;
- this.vmName = VM_NAME;
+ this.processName = PROCESS_NAME;
}
public String getContext() {
@@ -72,20 +72,8 @@
return this.principal;
}
- //public int getLevel() {
- // return this.level;
- //}
-
- //public String getLabel() {
- // return AuditLevel.getLabelForLevel(level);
- //}
-
- //public String getThreadName() {
- // return this.threadName;
- //}
-
- public String getVMName() {
- return this.vmName;
+ public String getProcessName() {
+ return this.processName;
}
public String getHostName() {
@@ -161,7 +149,7 @@
out.writeObject(resources);
out.writeLong(timestamp);
// out.writeObject(threadName);
- out.writeObject(vmName);
+ out.writeObject(processName);
}
// implements Externalizable
@@ -173,7 +161,7 @@
this.resources = (Object[]) in.readObject();
this.timestamp = in.readLong();
// this.threadName = (String) in.readObject();
- this.vmName = (String) in.readObject();
+ this.processName = (String) in.readObject();
}
}
Modified: trunk/server/src/main/java/com/metamatrix/platform/security/audit/destination/DatabaseAuditDestination.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/security/audit/destination/DatabaseAuditDestination.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/security/audit/destination/DatabaseAuditDestination.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -229,7 +229,7 @@
maxGeneralLength));
// Message VM ID column
- stmt.setString(7, StringUtil.truncString(message.getVMName(),
+ stmt.setString(7, StringUtil.truncString(message.getProcessName(),
maxGeneralLength));
// Insert the row into the table
Modified: trunk/server/src/main/java/com/metamatrix/platform/security/audit/destination/SingleFileAuditDestination.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/security/audit/destination/SingleFileAuditDestination.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/security/audit/destination/SingleFileAuditDestination.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -119,11 +119,11 @@
int index = fileName.indexOf(VM_NAME_TOKEN);
if ( index != -1 ) {
StringBuffer tempFileName = new StringBuffer(fileName);
- String vmName = VMNaming.getVMName();
- if ( vmName == null || vmName.trim().length() == 0 ) {
- vmName = VMNaming.getConfigName();
+ String processName = VMNaming.getProcessName();
+ if ( processName == null || processName.trim().length() == 0 ) {
+ processName = VMNaming.getConfigName();
}
- tempFileName.replace(index,index+VM_NAME_TOKEN.length(),vmName);
+ tempFileName.replace(index,index+VM_NAME_TOKEN.length(),processName);
fileName = tempFileName.toString();
}
Modified: trunk/server/src/main/java/com/metamatrix/platform/security/audit/format/DelimitedAuditMessageFormat.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/security/audit/format/DelimitedAuditMessageFormat.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/security/audit/format/DelimitedAuditMessageFormat.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -54,7 +54,7 @@
msg.append( DELIMITER_CHAR );
msg.append( message.getHostName() );
msg.append( DELIMITER_CHAR );
- msg.append( message.getVMName() );
+ msg.append( message.getProcessName() );
msg.append( DELIMITER_CHAR );
msg.append( message.getPrincipal() );
msg.append( DELIMITER_CHAR );
Modified: trunk/server/src/main/java/com/metamatrix/platform/security/audit/format/ReadableAuditMessageFormat.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/security/audit/format/ReadableAuditMessageFormat.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/security/audit/format/ReadableAuditMessageFormat.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -50,7 +50,7 @@
msg.append(" ["); //$NON-NLS-1$
msg.append( message.getHostName() );
msg.append( '|' );
- msg.append( message.getVMName() );
+ msg.append( message.getProcessName() );
msg.append( '|' );
msg.append( message.getPrincipal() );
msg.append("] <"); //$NON-NLS-1$
Modified: trunk/server/src/main/java/com/metamatrix/platform/service/api/ServiceInterface.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/service/api/ServiceInterface.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/service/api/ServiceInterface.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -29,7 +29,6 @@
import com.metamatrix.common.comm.ClientServiceRegistry;
import com.metamatrix.common.config.api.DeployedComponentID;
import com.metamatrix.common.queue.WorkerPoolStats;
-import com.metamatrix.platform.vm.controller.VMControllerID;
public interface ServiceInterface {
@@ -77,17 +76,18 @@
*/
Date getStartTime();
- /*
+ /**
* Determine which host the service instance is running on.
* @return Host the service is running on
*/
String getHostname();
/**
- * Get the id of the VM that the service is running in.
+ * Get process name on which this service is running on
+ * @return
*/
- VMControllerID getVMID();
-
+ String getProcessName();
+
/**
* Determine if the service is alive and well.
*/
Modified: trunk/server/src/main/java/com/metamatrix/platform/service/controller/AbstractService.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/service/controller/AbstractService.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/service/controller/AbstractService.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -39,7 +39,6 @@
import com.metamatrix.common.queue.WorkerPoolStats;
import com.metamatrix.common.util.LogCommonConstants;
import com.metamatrix.common.util.PasswordMaskUtil;
-import com.metamatrix.common.util.VMNaming;
import com.metamatrix.core.event.EventObjectListener;
import com.metamatrix.core.log.MessageLevel;
import com.metamatrix.platform.service.ServiceMessages;
@@ -52,7 +51,6 @@
import com.metamatrix.platform.service.api.exception.ServiceNotInitializedException;
import com.metamatrix.platform.service.api.exception.ServiceStateException;
import com.metamatrix.platform.service.api.exception.ServiceSuspendedException;
-import com.metamatrix.platform.vm.controller.VMControllerID;
/**
* Base class for all services.
@@ -270,24 +268,22 @@
}
/**
- * Return VMControllerID for vm service is running in.
- *
- * @return VMControllerID
- */
- public VMControllerID getVMID() {
- return id.getVMControllerID();
- }
-
- /**
* Return name of the host service is running on.
*
* @return String Host name
*/
public final String getHostname() {
- return VMNaming.getConfigName();
+ return this.id.getHostName();
}
/**
+ * @see com.metamatrix.platform.service.api.ServiceInterface#getProcessName()
+ */
+ public final String getProcessName(){
+ return this.id.getProcessName();
+ }
+
+ /**
* Return instance name of this service.
*
* @return String instance name
Modified: trunk/server/src/main/java/com/metamatrix/platform/service/proxy/ProxyManager.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/service/proxy/ProxyManager.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/service/proxy/ProxyManager.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -40,7 +40,6 @@
import com.metamatrix.platform.service.ServicePlugin;
import com.metamatrix.platform.service.api.ServiceInterface;
import com.metamatrix.platform.util.PlatformProxyHelper;
-import com.metamatrix.platform.vm.controller.VMControllerID;
import com.metamatrix.server.Configuration;
/**
@@ -62,16 +61,13 @@
String hostName;
- String vmName;
+ String processName;
- VMControllerID vmID;
-
@Inject
- public ProxyManager((a)Named(Configuration.HOSTNAME)String hostName, @Named(Configuration.VMNAME)String vmName, VMControllerID vmID, ClusteredRegistryState registry) {
+ public ProxyManager((a)Named(Configuration.HOSTNAME)String hostName, @Named(Configuration.PROCESSNAME)String processName, ClusteredRegistryState registry) {
this.hostName = hostName;
- this.vmName = vmName;
+ this.processName = processName;
this.registry = registry;
- this.vmID = vmID;
this.registry.addListener(this);
}
@@ -218,7 +214,7 @@
* @param serviceType The type of the service of interest.
*/
private void setServiceInstances(ServiceSelectionPolicy policy, String serviceType) {
- List localServiceBindings = this.registry.getActiveServiceBindings(this.hostName, this.vmID.toString(), serviceType);
+ List localServiceBindings = this.registry.getActiveServiceBindings(this.hostName, this.processName, serviceType);
List serviceBindings = this.registry.getActiveServiceBindings(null, null, serviceType);
serviceBindings.removeAll(localServiceBindings);
policy.updateServices(localServiceBindings, serviceBindings);
Copied: trunk/server/src/main/java/com/metamatrix/platform/vm/api/controller/ProcessManagement.java (from rev 535, trunk/server/src/main/java/com/metamatrix/platform/vm/api/controller/VMControllerInterface.java)
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/vm/api/controller/ProcessManagement.java (rev 0)
+++ trunk/server/src/main/java/com/metamatrix/platform/vm/api/controller/ProcessManagement.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -0,0 +1,122 @@
+/*
+ * 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 com.metamatrix.platform.vm.api.controller;
+
+import java.net.InetAddress;
+import java.util.Date;
+
+import com.metamatrix.admin.api.exception.AdminException;
+import com.metamatrix.common.config.api.ServiceComponentDefnID;
+import com.metamatrix.common.log.LogConfiguration;
+import com.metamatrix.platform.service.api.ServiceID;
+import com.metamatrix.platform.vm.controller.ProcessStatistics;
+
+public interface ProcessManagement {
+
+ /**
+ * Starts the VM by invoking all the deployed services
+ */
+ public void start();
+
+
+ /**
+ * Shut down all services waiting for work to complete.
+ * Essential services will also be shutdown.
+ */
+ void shutdown(boolean now);
+
+ /**
+ * Start the service identified by the ServiceComponentID
+ * If synch is true then wait for service to start before returning.
+ * Any exceptions will then be thrown to the caller.
+ * If synch is false then start service asynchronously.
+ */
+ public void startDeployedService(ServiceComponentDefnID id);
+
+ /**
+ * Start a previously stopped service
+ */
+ void startService(ServiceID serviceID);
+
+
+ /**
+ * Kill service once work is complete
+ */
+ void stopService(ServiceID id, boolean now, boolean shutdown);
+
+ /**
+ * Check the state of a service
+ */
+ void checkService(ServiceID serviceID);
+
+ /**
+ * Set the current log configuration.
+ */
+ void setCurrentLogConfiguration(LogConfiguration logConfiguration);
+
+ /**
+ * Get the time the VM was initialized.
+ */
+ Date getStartTime();
+
+ /**
+ * Get the address of the host this VM is running on.
+ */
+ InetAddress getAddress();
+
+ /**
+ * Get the name for this controller.
+ */
+ String getName();
+
+ /**
+ * Method called from registries to determine if VMController is alive.
+ */
+ void ping();
+
+ /**
+ * Returns true if system is being shutdown.
+ */
+ boolean isShuttingDown();
+
+ /**
+ * Return information about VM.
+ * totalMemory, freeMemory, threadCount
+ */
+ ProcessStatistics getVMStatistics();
+
+ /**
+ * dumps stack trace to log file.
+ */
+ void dumpThreads();
+
+ /**
+ * Export the server logs to a byte[]. The bytes contain the contents of a .zip file containing the logs.
+ * This will export all logs on the host that contains this VMController.
+ * @return the logs, as a byte[].
+ * @throws AdminException
+ * @since 4.3
+ */
+ byte[] exportLogs();
+}
+
Deleted: trunk/server/src/main/java/com/metamatrix/platform/vm/api/controller/VMControllerInterface.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/vm/api/controller/VMControllerInterface.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/vm/api/controller/VMControllerInterface.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -1,128 +0,0 @@
-/*
- * 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 com.metamatrix.platform.vm.api.controller;
-
-import java.net.InetAddress;
-import java.util.Date;
-
-import com.metamatrix.admin.api.exception.AdminException;
-import com.metamatrix.common.config.api.ServiceComponentDefnID;
-import com.metamatrix.common.log.LogConfiguration;
-import com.metamatrix.platform.service.api.ServiceID;
-import com.metamatrix.platform.vm.controller.VMControllerID;
-import com.metamatrix.platform.vm.controller.VMStatistics;
-
-public interface VMControllerInterface {
-
- /**
- * Starts the VM by invoking all the deployed services
- */
- public void start();
-
-
- /**
- * Shut down all services waiting for work to complete.
- * Essential services will also be shutdown.
- */
- void shutdown(boolean now);
-
- /**
- * Start the service identified by the ServiceComponentID
- * If synch is true then wait for service to start before returning.
- * Any exceptions will then be thrown to the caller.
- * If synch is false then start service asynchronously.
- */
- public void startDeployedService(ServiceComponentDefnID id);
-
- /**
- * Start a previously stopped service
- */
- void startService(ServiceID serviceID);
-
-
- /**
- * Kill service once work is complete
- */
- void stopService(ServiceID id, boolean now, boolean shutdown);
-
- /**
- * Check the state of a service
- */
- void checkService(ServiceID serviceID);
-
- /**
- * Set the current log configuration.
- */
- void setCurrentLogConfiguration(LogConfiguration logConfiguration);
-
- /**
- * Get the time the VM was initialized.
- */
- Date getStartTime();
-
- /**
- * Get the address of the host this VM is running on.
- */
- InetAddress getAddress();
-
- /**
- * Get the ID for this controller.
- */
- VMControllerID getID() ;
-
- /**
- * Get the name for this controller.
- */
- String getName();
-
- /**
- * Method called from registries to determine if VMController is alive.
- */
- void ping();
-
- /**
- * Returns true if system is being shutdown.
- */
- boolean isShuttingDown();
-
- /**
- * Return information about VM.
- * totalMemory, freeMemory, threadCount
- */
- VMStatistics getVMStatistics();
-
- /**
- * dumps stack trace to log file.
- */
- void dumpThreads();
-
- /**
- * Export the server logs to a byte[]. The bytes contain the contents of a .zip file containing the logs.
- * This will export all logs on the host that contains this VMController.
- * @return the logs, as a byte[].
- * @throws AdminException
- * @since 4.3
- */
- byte[] exportLogs();
-}
-
Copied: trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ProcessController.java (from rev 535, trunk/server/src/main/java/com/metamatrix/platform/vm/controller/VMController.java)
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ProcessController.java (rev 0)
+++ trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ProcessController.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -0,0 +1,944 @@
+/*
+ * 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 com.metamatrix.platform.vm.controller;
+
+import java.io.File;
+import java.lang.reflect.Proxy;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import com.metamatrix.admin.api.exception.AdminException;
+import com.metamatrix.admin.api.server.ServerAdmin;
+import com.metamatrix.admin.server.ServerAdminImpl;
+import com.metamatrix.admin.util.AdminMethodRoleResolver;
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MultipleException;
+import com.metamatrix.common.comm.ClientServiceRegistry;
+import com.metamatrix.common.comm.platform.socket.server.AdminAuthorizationInterceptor;
+import com.metamatrix.common.comm.platform.socket.server.LogonImpl;
+import com.metamatrix.common.config.CurrentConfiguration;
+import com.metamatrix.common.config.JDBCConnectionPoolHelper;
+import com.metamatrix.common.config.api.ComponentTypeID;
+import com.metamatrix.common.config.api.ConfigurationModelContainer;
+import com.metamatrix.common.config.api.DeployedComponent;
+import com.metamatrix.common.config.api.DeployedComponentID;
+import com.metamatrix.common.config.api.Host;
+import com.metamatrix.common.config.api.HostID;
+import com.metamatrix.common.config.api.HostType;
+import com.metamatrix.common.config.api.ProductServiceConfigID;
+import com.metamatrix.common.config.api.ServiceComponentDefn;
+import com.metamatrix.common.config.api.ServiceComponentDefnID;
+import com.metamatrix.common.config.api.VMComponentDefn;
+import com.metamatrix.common.config.api.VMComponentDefnID;
+import com.metamatrix.common.config.api.VMComponentDefnType;
+import com.metamatrix.common.config.api.exceptions.ConfigurationException;
+import com.metamatrix.common.id.dbid.DBIDGenerator;
+import com.metamatrix.common.id.dbid.DBIDGeneratorException;
+import com.metamatrix.common.log.LogConfiguration;
+import com.metamatrix.common.log.LogManager;
+import com.metamatrix.common.messaging.MessageBus;
+import com.metamatrix.common.queue.WorkerPool;
+import com.metamatrix.common.queue.WorkerPoolFactory;
+import com.metamatrix.common.queue.WorkerPoolStats;
+import com.metamatrix.common.util.LogCommonConstants;
+import com.metamatrix.common.util.PropertiesUtils;
+import com.metamatrix.common.util.VMNaming;
+import com.metamatrix.common.util.LogContextsUtil.PlatformAdminConstants;
+import com.metamatrix.core.util.FileUtil;
+import com.metamatrix.core.util.ZipFileUtil;
+import com.metamatrix.metadata.runtime.RuntimeMetadataCatalog;
+import com.metamatrix.platform.PlatformPlugin;
+import com.metamatrix.platform.admin.api.AuthorizationAdminAPI;
+import com.metamatrix.platform.admin.api.ConfigurationAdminAPI;
+import com.metamatrix.platform.admin.api.ExtensionSourceAdminAPI;
+import com.metamatrix.platform.admin.api.MembershipAdminAPI;
+import com.metamatrix.platform.admin.api.RuntimeStateAdminAPI;
+import com.metamatrix.platform.admin.api.SessionAdminAPI;
+import com.metamatrix.platform.admin.apiimpl.AdminHelper;
+import com.metamatrix.platform.admin.apiimpl.AuthorizationAdminAPIImpl;
+import com.metamatrix.platform.admin.apiimpl.ConfigurationAdminAPIImpl;
+import com.metamatrix.platform.admin.apiimpl.ExtensionSourceAdminAPIImpl;
+import com.metamatrix.platform.admin.apiimpl.MembershipAdminAPIImpl;
+import com.metamatrix.platform.admin.apiimpl.RuntimeStateAdminAPIImpl;
+import com.metamatrix.platform.admin.apiimpl.SessionAdminAPIImpl;
+import com.metamatrix.platform.config.api.service.ConfigurationServiceInterface;
+import com.metamatrix.platform.registry.ClusteredRegistryState;
+import com.metamatrix.platform.registry.ResourceNotBoundException;
+import com.metamatrix.platform.registry.ServiceRegistryBinding;
+import com.metamatrix.platform.registry.ProcessRegistryBinding;
+import com.metamatrix.platform.security.api.ILogon;
+import com.metamatrix.platform.security.api.service.AuthorizationServiceInterface;
+import com.metamatrix.platform.security.api.service.MembershipServiceInterface;
+import com.metamatrix.platform.security.api.service.SessionServiceInterface;
+import com.metamatrix.platform.service.api.ServiceID;
+import com.metamatrix.platform.service.api.ServiceInterface;
+import com.metamatrix.platform.service.api.ServiceState;
+import com.metamatrix.platform.service.api.exception.ServiceException;
+import com.metamatrix.platform.service.controller.ServicePropertyNames;
+import com.metamatrix.platform.util.ErrorMessageKeys;
+import com.metamatrix.platform.util.LogMessageKeys;
+import com.metamatrix.platform.util.LogPlatformConstants;
+import com.metamatrix.platform.util.PlatformProxyHelper;
+import com.metamatrix.platform.vm.api.controller.ProcessManagement;
+import com.metamatrix.server.HostManagement;
+import com.metamatrix.server.ResourceFinder;
+import com.metamatrix.server.admin.api.QueryAdminAPI;
+import com.metamatrix.server.admin.api.RuntimeMetadataAdminAPI;
+import com.metamatrix.server.admin.api.TransactionAdminAPI;
+import com.metamatrix.server.admin.apiimpl.QueryAdminAPIImpl;
+import com.metamatrix.server.admin.apiimpl.RuntimeMetadataAdminAPIImpl;
+import com.metamatrix.server.admin.apiimpl.TransactionAdminAPIImpl;
+
+/**
+ * This class is used to start up a server process and start all services that are
+ * configured under this server
+ */
+public abstract class ProcessController implements ProcessManagement {
+
+ public static final String STARTER_MAX_THREADS = "vm.starter.maxThreads"; //$NON-NLS-1$
+ /**Time-to-live for threads used to start services (ms)*/
+ public static final String STARTER_TIMETOLIVE = "vm.starter.timetolive"; //$NON-NLS-1$
+ /**Interval to check the state of services (ms)*/
+ public static final String SERVICE_MONITOR_INTERVAL = "metamatrix.server.serviceMonitorInterval"; //$NON-NLS-1$
+
+ // this is a 4.2.2 property used for command line setting
+ private static final String STOP_DELAY_TIME = "metamatrix.vm.stop.delay.sec"; //$NON-NLS-1$
+
+ private static final int DEFAULT_FORCE_SHUTDOWN_TIME = 30;
+ public static final int DEFAULT_STARTER_MAX_THREADS = 15;
+ public static final int DEFAULT_STARTER_TIMETOLIVE = 15000;
+
+ protected Host host;
+ protected String processName;
+
+ private Date startTime;
+ private Properties vmProps;
+ VMComponentDefn vmComponentDefn;
+
+ private boolean shuttingDown = false;
+
+ //WorkerPool used for starting services asynchronously
+ private WorkerPool startServicePool;
+
+ protected ClusteredRegistryState registry;
+
+ private MessageBus messageBus;
+
+ // Server events that are being generated
+ ServerEvents events;
+
+ protected ClientServiceRegistry clientServices;
+ private Map<ComponentTypeID, Properties> defaultPropertiesCache = new HashMap<ComponentTypeID, Properties>();
+ private Properties hostProperties;
+
+ private int force_shutdown_time = DEFAULT_FORCE_SHUTDOWN_TIME;
+
+ /**
+ * Create a new instance of VMController.
+ *
+ * @param processName Name of Process
+ * @param startDeployedServices If true all services that are deployed to this vm are started.
+ * @param standalone If true indicates that VMController is running in its own vm.
+ * @throws Exception if an error occurs initializing vmController
+ */
+ public ProcessController(Host host, String processname, ClusteredRegistryState registry, ServerEvents serverEvents, MessageBus bus, HostManagement hostManagement) throws Exception {
+ this.host = host;
+ this.processName = processname;
+
+ this.registry = registry;
+ this.events = serverEvents;
+ this.messageBus = bus;
+
+ Properties configProps = CurrentConfiguration.getInstance().getProperties();
+ int maxThreads = PropertiesUtils.getIntProperty(configProps, STARTER_MAX_THREADS, DEFAULT_STARTER_MAX_THREADS);
+ int timeToLive = PropertiesUtils.getIntProperty(configProps, STARTER_TIMETOLIVE, DEFAULT_STARTER_TIMETOLIVE);
+
+ this.startServicePool = WorkerPoolFactory.newWorkerPool("StartServiceQueue", maxThreads, timeToLive); //$NON-NLS-1$
+
+ initVMProperties(host.getFullName(), processname);
+
+ this.startTime = new Date();
+
+ this.clientServices = new ClientServiceRegistry();
+
+ RuntimeMetadataCatalog.getInstance().init(CurrentConfiguration.getInstance().getProperties(), ResourceFinder.getMessageBus(), ResourceFinder.getCacheFactory());
+
+ this.registerILogonAPI();
+ this.registerAdmin(hostManagement);
+
+ this.registerSubSystemAdminAPIs(hostManagement);
+
+ addShutdownHook();
+ }
+
+
+ /**
+ * Register the ServiceInterceptors for the SubSystemAdminAPIs
+ * @throws MetaMatrixComponentException
+ */
+ private void registerSubSystemAdminAPIs(HostManagement hostManagement) throws MetaMatrixComponentException {
+ this.clientServices.registerClientService(ConfigurationAdminAPI.class, ConfigurationAdminAPIImpl.getInstance(this.registry), PlatformAdminConstants.CTX_CONFIGURATION_ADMIN_API);
+ this.clientServices.registerClientService(RuntimeStateAdminAPI.class, RuntimeStateAdminAPIImpl.getInstance(this.registry, hostManagement), PlatformAdminConstants.CTX_RUNTIME_STATE_ADMIN_API);
+ this.clientServices.registerClientService(MembershipAdminAPI.class, MembershipAdminAPIImpl.getInstance(), PlatformAdminConstants.CTX_ADMIN_API);
+ this.clientServices.registerClientService(SessionAdminAPI.class, SessionAdminAPIImpl.getInstance(), PlatformAdminConstants.CTX_ADMIN_API);
+ this.clientServices.registerClientService(AuthorizationAdminAPI.class, AuthorizationAdminAPIImpl.getInstance(), PlatformAdminConstants.CTX_AUTHORIZATION_ADMIN_API);
+ this.clientServices.registerClientService(ExtensionSourceAdminAPI.class, ExtensionSourceAdminAPIImpl.getInstance(), PlatformAdminConstants.CTX_ADMIN_API);
+ this.clientServices.registerClientService(QueryAdminAPI.class, QueryAdminAPIImpl.getInstance(), PlatformAdminConstants.CTX_ADMIN_API);
+ this.clientServices.registerClientService(RuntimeMetadataAdminAPI.class, RuntimeMetadataAdminAPIImpl.getInstance(), PlatformAdminConstants.CTX_RUNTIME_METADATA_ADMIN_API);
+ this.clientServices.registerClientService(TransactionAdminAPI.class, TransactionAdminAPIImpl.getInstance(), PlatformAdminConstants.CTX_ADMIN_API);
+ }
+
+
+ /**
+ * Register a ServiceInterceptor for the new Admin API, so that the client can access it via messaging.
+ * @throws AdminException
+ *
+ * @throws MetaMatrixComponentException
+ */
+ private void registerAdmin(HostManagement hostManagement) throws AdminException {
+ ServerAdminImpl serverAdminImpl = new ServerAdminImpl(this.registry, hostManagement);
+ AdminMethodRoleResolver adminMethodRoleResolver = new AdminMethodRoleResolver();
+ adminMethodRoleResolver.init();
+ ServerAdmin roleCheckedServerAdmin = (ServerAdmin)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] {ServerAdmin.class}, new AdminAuthorizationInterceptor(new AdminHelper(), adminMethodRoleResolver, serverAdminImpl));
+ this.clientServices.registerClientService(ServerAdmin.class, roleCheckedServerAdmin, PlatformAdminConstants.CTX_ADMIN);
+ }
+
+ /**
+ * Register ILogonAPI's ServiceInterceptor
+ * @throws ServiceException
+ * @throws ConfigurationException
+ */
+ private void registerILogonAPI() throws ConfigurationException, ServiceException {
+ this.clientServices.registerClientService(ILogon.class, new LogonImpl(PlatformProxyHelper.getSessionServiceProxy(PlatformProxyHelper.ROUND_ROBIN_LOCAL), CurrentConfiguration.getInstance().getClusterName()), LogCommonConstants.CTX_LOGON);
+ }
+
+ private void addShutdownHook() {
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ try {
+ shutdown(false);
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ });
+ }
+
+ /**
+ * Lazily get Current Configuration
+ */
+ ConfigurationModelContainer getConfigurationModel() throws ConfigurationException {
+ return CurrentConfiguration.getInstance().getConfigurationModel();
+ }
+
+ /**
+ * Initialize vm properties.
+ * This method initializes the following global attributes.
+ *
+ * - hostID
+ * - vmComponentDefnID
+ * - vmProps
+ */
+ private void initVMProperties(String hostname, String processName) throws Exception {
+ ConfigurationModelContainer config = getConfigurationModel();
+
+ VMComponentDefn deployedVM = config.getConfiguration().getVMForHost(hostname, processName);
+
+ if (deployedVM != null) {
+ this.vmComponentDefn = deployedVM;
+
+ vmProps = config.getDefaultPropertyValues(deployedVM.getComponentTypeID());
+ Properties props = config.getConfiguration().getAllPropertiesForComponent(deployedVM.getID());
+ vmProps.putAll(props);
+
+ // this system property setting will override the setting in the VM
+ // this is done because the command line argument
+ force_shutdown_time = PropertiesUtils.getIntProperty(System.getProperties(), STOP_DELAY_TIME, DEFAULT_FORCE_SHUTDOWN_TIME);
+ if (DEFAULT_FORCE_SHUTDOWN_TIME == force_shutdown_time) {
+ force_shutdown_time = PropertiesUtils.getIntProperty(vmProps, VMComponentDefnType.FORCED_SHUTDOWN_TIME, DEFAULT_FORCE_SHUTDOWN_TIME);
+ }
+
+ Properties allProps = new Properties();
+ allProps.putAll(System.getProperties());
+ allProps.putAll(config.getConfiguration().getProperties());
+ allProps.putAll(host.getProperties());
+ allProps.putAll(props);
+ System.setProperties(allProps);
+
+ logMessage(PlatformPlugin.Util.getString("VMController.VM_Force_Shutdown_Time", force_shutdown_time)); //$NON-NLS-1$
+
+ // add the vm to registry
+ ProcessRegistryBinding binding = new ProcessRegistryBinding(host.getFullName(), this.processName, deployedVM, this, this.messageBus);
+ this.events.processAdded(binding);
+ }
+ }
+
+ protected void logMessage(String s) {
+ LogManager.logInfo(LogCommonConstants.CTX_CONTROLLER, s);
+ }
+
+ public void start() {
+
+ logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0013));
+ VMComponentDefnID vmComponentDefnID = (VMComponentDefnID)this.vmComponentDefn.getID();
+
+ try {
+ ConfigurationModelContainer configuration = getConfigurationModel();
+
+ Collection deployedServices = configuration.getConfiguration().getDeployedServicesForVM(this.vmComponentDefn);
+
+ logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0014, new Integer(deployedServices.size()), vmComponentDefnID.getName()));
+
+ ArrayList essentialServices = new ArrayList();
+ ArrayList otherServices = new ArrayList();
+
+ // create a list of platform services and other services
+ Iterator servicesIterator = deployedServices.iterator();
+ while (servicesIterator.hasNext()) {
+ DeployedComponent depComp = (DeployedComponent) servicesIterator.next();
+
+ ServiceComponentDefn scd = (ServiceComponentDefn) depComp.getDeployedComponentDefn(configuration.getConfiguration());
+
+ if (scd.isEssential()) {
+ essentialServices.add(depComp);
+ } else {
+ otherServices.add(depComp);
+ }
+ }
+
+ // start platform services first (synchronously)
+ boolean errored = false;
+ servicesIterator = essentialServices.iterator();
+ while (servicesIterator.hasNext()) {
+ DeployedComponent depComp = (DeployedComponent) servicesIterator.next();
+ try {
+ startDeployedService(depComp, null, configuration, true);
+ } catch (Exception e) {
+ errored = true;
+ // error already logged from startDeployedService method.
+ // continue starting services.
+ }
+ }
+
+ if (errored) return;
+
+
+ // now start the rest of the services asynchronously
+ servicesIterator = otherServices.iterator();
+ while (servicesIterator.hasNext()) {
+ DeployedComponent depComp = (DeployedComponent) servicesIterator.next();
+ try {
+ startDeployedService(depComp, null, configuration, false);
+ } catch (Exception e) {
+ // error already logged from startDeployedService method.
+ // continue starting services.
+ }
+ }
+ logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0016, new Integer(deployedServices.size()), vmComponentDefnID.getName()));
+
+ } catch (ConfigurationException e) {
+ logException(e, PlatformPlugin.Util.getString(LogMessageKeys.VM_0017, vmComponentDefnID.getName(), host.getID().getName()));
+ }
+ }
+
+
+ public void startService(ServiceID serviceID) {
+ logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0018, serviceID));
+
+ ServiceRegistryBinding binding = null;
+
+ try {
+ binding = this.registry.getServiceBinding(serviceID.getHostName(), serviceID.getProcessName(), serviceID);
+ } catch (ResourceNotBoundException e) {
+ String msg = PlatformPlugin.Util.getString(LogMessageKeys.VM_0019, serviceID);
+ throw new ServiceException(e, msg);
+ } catch (Exception e) {
+ String msg = PlatformPlugin.Util.getString(LogMessageKeys.VM_0020, serviceID);
+ throw new ServiceException(e, msg);
+ }
+
+ if (!binding.isServiceBad()) {
+ throw new ServiceException(PlatformPlugin.Util.getString(LogMessageKeys.VM_0021, serviceID));
+ }
+
+ try {
+ ConfigurationModelContainer configuration = getConfigurationModel();
+ startDeployedService(binding.getDeployedComponent(), serviceID, configuration, true);
+
+ } catch (Exception e) {
+ throw new ServiceException(e, PlatformPlugin.Util.getString(LogMessageKeys.VM_0022, serviceID));
+ }
+ }
+
+ public void startDeployedService(ServiceComponentDefnID id) {
+ logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0023, id));
+ startDeployedService(id, null);
+ }
+
+ private void startDeployedService(ServiceComponentDefnID defnID, ServiceID serviceID) {
+ try {
+ ConfigurationModelContainer configuration = getConfigurationModel();
+ VMComponentDefnID vmComponentDefnID = (VMComponentDefnID)this.vmComponentDefn.getID();
+ DeployedComponent deployedService = configuration.getConfiguration().getDeployedServiceForVM(defnID, vmComponentDefnID, (HostID) getConfigHost().getID());
+ startDeployedService(deployedService, serviceID, configuration, true);
+ } catch (Exception e) {
+ String msg = PlatformPlugin.Util.getString(LogMessageKeys.VM_0024, defnID);
+ throw new ServiceException(e, msg);
+ }
+ }
+
+ /**
+ * Start the service identified by the DeployedComponentID
+ * If synch is true then wait for service to start before returning.
+ * Any exceptions will then be thrown to the caller.
+ * If synch is false then start service asynchronously.
+ * @throws ConfigurationException
+ */
+ private void startDeployedService(DeployedComponent deployedService, ServiceID serviceID, ConfigurationModelContainer configModel, boolean synch) throws ConfigurationException {
+ Properties defaultProps = null;
+ synchronized (this) {
+ defaultProps = defaultPropertiesCache.get(deployedService.getComponentTypeID());
+
+ if (defaultProps == null) {
+ if (hostProperties == null) {
+ hostProperties = CurrentConfiguration.getInstance().getSystemBootStrapProperties();
+ hostProperties = new Properties(hostProperties);
+ PropertiesUtils.putAll(hostProperties, host.getProperties());
+ }
+ defaultProps = new Properties(hostProperties);
+ defaultProps.putAll(configModel.getDefaultPropertyValues(deployedService.getComponentTypeID()));
+ defaultPropertiesCache.put(deployedService.getComponentTypeID(), defaultProps);
+ }
+ }
+ Properties serviceProps = new Properties(defaultProps);
+ Properties props = configModel.getConfiguration().getAllPropertiesForComponent(deployedService.getID());
+ serviceProps.putAll(props);
+ PropertiesUtils.setOverrideProperies(serviceProps, hostProperties);
+
+ ProductServiceConfigID pscID = deployedService.getProductServiceConfigID();
+ String serviceClassName = serviceProps.getProperty( ServicePropertyNames.SERVICE_CLASS_NAME );
+
+ if (serviceClassName != null && serviceClassName.length() > 0) {
+ logMessage( PlatformPlugin.Util.getString(LogMessageKeys.VM_0025, deployedService.getServiceComponentDefnID().getName(), processName, host.getID().getName()));
+
+ serviceProps.put(ServicePropertyNames.INSTANCE_NAME, deployedService.getName());
+ serviceProps.put(ServicePropertyNames.SERVICE_NAME, deployedService.getServiceComponentDefnID().getName());
+ serviceProps.put(ServicePropertyNames.COMPONENT_TYPE_NAME, deployedService.getComponentTypeID().getFullName());
+
+ // get routing id.
+ if (!deployedService.isDeployedConnector()) {
+ serviceProps.put(ServicePropertyNames.SERVICE_ROUTING_ID, deployedService.getComponentTypeID().getFullName());
+ } else {
+ ServiceComponentDefn scd = (ServiceComponentDefn) deployedService.getDeployedComponentDefn(configModel.getConfiguration());
+ String routingID = scd.getRoutingUUID();
+ serviceProps.put(ServicePropertyNames.SERVICE_ROUTING_ID, routingID);
+ }
+ startService(this.clientServices, serviceClassName, serviceID, deployedService, pscID, serviceProps, synch );
+
+ } else {
+ String msg = PlatformPlugin.Util.getString(LogMessageKeys.VM_0026, new Object[] {ServicePropertyNames.SERVICE_CLASS_NAME, deployedService.getServiceComponentDefnID().getName(), processName, host.getID().getName()});
+ throw new ServiceException(msg);
+ }
+
+ }
+
+ /**
+ * Shut down all services waiting for work to complete.
+ * Essential services will also be shutdown.
+ */
+ public synchronized void shutdown(boolean now) {
+ logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0041));
+
+ try {
+ stopServices(now, true);
+ } catch (MultipleException e) {
+ logException(e, e.getMessage());
+ } catch (ServiceException e) {
+ logException(e, e.getMessage());
+ }
+
+ JDBCConnectionPoolHelper.getInstance().shutDown();
+
+ // unregister VMController
+ events.processRemoved(host.getFullName(), this.processName);
+
+ this.shuttingDown = true;
+
+ notifyAll();
+
+ this.startServicePool.execute(new Runnable() {
+ public void run() {
+ // Wait before killing the VM.
+ try {
+ Thread.sleep(force_shutdown_time * 1000);
+ } catch (Exception e) {}
+ // And exit.
+ System.exit(1);
+ }
+ });
+ }
+
+
+ /**
+ * Kill service once work is complete
+ */
+ public void stopService(ServiceID id, boolean now, boolean shutdown) {
+ try {
+ logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0035, id));
+ validateServiceID(id);
+ ServiceRegistryBinding binding = this.registry.getServiceBinding(id.getHostName(), id.getProcessName(), id);
+ stopService(binding, now, shutdown);
+ } catch (ResourceNotBoundException e) {
+ throw new ServiceException(e);
+ }
+ }
+
+ /**
+ * Set the current log configuration for this vm.
+ */
+ public void setCurrentLogConfiguration(LogConfiguration logConfiguration) {
+ logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0046, logConfiguration));
+ LogManager.setLogConfiguration(logConfiguration);
+ }
+
+ /**
+ * Get the time the VM was initialized.
+ */
+ public Date getStartTime() {
+ return this.startTime;
+ }
+
+
+ public Host getConfigHost() {
+ return this.host;
+ }
+
+ /**
+ * Method called from registries to determine if VMController is alive.
+ */
+ public void ping() {
+ }
+
+ public synchronized boolean isShuttingDown() {
+ return shuttingDown;
+ }
+
+ /**
+ * Return information about VM. totalMemory, freeMemory, threadCount
+ */
+ public ProcessStatistics getVMStatistics() {
+ ProcessStatistics vmStats = new ProcessStatistics();
+ Runtime rt = Runtime.getRuntime();
+ vmStats.freeMemory = rt.freeMemory();
+ vmStats.totalMemory = rt.totalMemory();
+
+ // get total thread count.
+ ThreadGroup root, tg;
+ root = Thread.currentThread().getThreadGroup();
+ while ((tg = root.getParent()) != null) {
+ root = tg;
+ }
+ vmStats.threadCount = root.activeCount();
+ vmStats.name = processName;
+
+
+ vmStats.processPoolStats = getProcessPoolStats();
+ vmStats.socketListenerStats = getSocketListenerStats();
+
+ return vmStats;
+ }
+
+ /**
+ * Prints thread information to a log file.
+ * Does not include the stacktrace - that is not available in 1.4.
+ */
+ public void dumpThreads() {
+
+ ThreadGroup root, tg;
+ root = Thread.currentThread().getThreadGroup();
+ while ((tg = root.getParent()) != null) {
+ root = tg;
+ }
+ listThreads(root, 0);
+ }
+
+ /**
+ * Print information about the specified thread group.
+ */
+ private void listThreads(ThreadGroup tg, int indent) {
+
+ for (int i = 0; i < indent; i++) {
+ System.out.print(" "); //$NON-NLS-1$
+ }
+ System.out.println(tg);
+ indent++;
+
+ //Recursively print information threads in this group
+ int cnt = tg.activeCount();
+ Thread[] threads = new Thread[cnt];
+ tg.enumerate(threads, false);
+ for (int i = 0; i < cnt; i++) {
+ if (threads[i] != null) {
+ for (int j = 0; j < indent; j++) {
+ System.out.print(" "); //$NON-NLS-1$
+ }
+ System.out.println(threads[i]);
+ }
+ }
+
+ //Recursively print information about child thread groups
+ cnt = tg.activeGroupCount();
+ ThreadGroup[] groups = new ThreadGroup[cnt];
+ tg.enumerate(groups);
+ for (int i = 0; i < cnt; i++) {
+ listThreads(groups[i], indent);
+ }
+ }
+
+ /**
+ * Private helper method that verifies service belongs to this vm
+ */
+ private void validateServiceID(ServiceID serviceID) {
+ if (!(serviceID.getHostName().equalsIgnoreCase(this.host.getFullName()) && serviceID.getProcessName().equalsIgnoreCase(this.processName))) {
+ throw new ServiceException(PlatformPlugin.Util.getString(LogMessageKeys.VM_0047, serviceID, this.host.getFullName(), this.processName));
+ }
+ }
+
+ /**
+ * @see com.metamatrix.platform.vm.api.controller.ProcessManagement#exportLogs()
+ * @since 4.3
+ */
+ public byte[] exportLogs() {
+ File tmpFile = null;
+ try {
+ tmpFile = File.createTempFile("logs", ".zip"); //$NON-NLS-1$ //$NON-NLS-2$
+ tmpFile.deleteOnExit();
+
+ String mainLogDirectory = host.getLogDirectory();
+ ZipFileUtil.addAll(tmpFile, mainLogDirectory, "log"); //$NON-NLS-1$
+
+ String hostLogDirectory = host.getProperty(HostType.HOST_DIRECTORY) + File.separator + "log"; //$NON-NLS-1$
+ ZipFileUtil.addAll(tmpFile, hostLogDirectory, "hosts_"+host.getName()+"_log"); //$NON-NLS-1$//$NON-NLS-2$
+
+ String servletLogDirectory = host.getProperty(HostType.HOST_DIRECTORY) + File.separator + "servletengine" + File.separator + "logs"; //$NON-NLS-1$ //$NON-NLS-2$
+ ZipFileUtil.addAll(tmpFile, servletLogDirectory, "hosts_"+host.getName()+"_servletengine_log"); //$NON-NLS-1$//$NON-NLS-2$
+
+ return new FileUtil(tmpFile.getAbsolutePath()).readBytes();
+
+ } catch (Exception e) {
+ throw new ServiceException(e);
+ } finally {
+ try {
+ tmpFile.delete();
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ protected abstract SocketListenerStats getSocketListenerStats();
+ protected abstract WorkerPoolStats getProcessPoolStats();
+
+
+ /**
+ * Start a service in this VM. If synch flag is true then what for the service to start
+ * before returning. Starting a service in this manner is typically done from the console so
+ * any errors can be reported. Starting a service asynchronously (synch == false) is intended for
+ * starting up the server. This prevents any race conditions due to service dependencies.
+ *
+ * @param ClientServiceRegistry Class to registry ServerListener
+ * @param serviceClassName Class to instantiate as a service.
+ * @param serviceID - null if a new service, if non-null then we are re-starting a service.
+ * @param serviceProps Properties required to start service.
+ * @param synch Flag to indicate if service should be started synchronously are asynchronously.
+ */
+ private void startService(final ClientServiceRegistry clientServiceRegistry, final String serviceClassName, final ServiceID serviceID, final DeployedComponent deployedComponent, final ProductServiceConfigID pscID, final Properties serviceProps, boolean synch) {
+
+ if (!synch) {
+ //add work to the pool
+ startServicePool.execute( new Runnable() {
+ public void run() {
+ startService(clientServiceRegistry, serviceID, deployedComponent,serviceClassName, pscID, serviceProps);
+ }
+ });
+ } else {
+ //start synchronously
+ try {
+ startService(clientServiceRegistry, serviceID, deployedComponent,serviceClassName, pscID, serviceProps);
+ } catch (Exception e) {
+ throw new ServiceException(e);
+ }
+ }
+ }
+
+ private void startService(ClientServiceRegistry serverListenerRegistry, ServiceID serviceID, DeployedComponent deployedComponent,final String serviceClass,ProductServiceConfigID pscID,Properties serviceProps) {
+ String serviceInstanceName = null;
+
+ try {
+ if (serviceID == null) {
+ serviceID = this.createServiceID();
+ }
+
+ serviceInstanceName = serviceProps.getProperty(ServicePropertyNames.INSTANCE_NAME);
+ String componentType = serviceProps.getProperty(ServicePropertyNames.COMPONENT_TYPE_NAME);
+ String serviceType = serviceProps.getProperty(ServicePropertyNames.SERVICE_NAME);
+ String routingID = serviceProps.getProperty(ServicePropertyNames.SERVICE_ROUTING_ID);
+ String essentialStr = serviceProps.getProperty(ServicePropertyNames.SERVICE_ESSENTIAL);
+
+
+ boolean essential = false;
+ if (essentialStr != null && essentialStr.trim().length() != 0) {
+ essential = Boolean.valueOf(essentialStr).booleanValue();
+ }
+
+ // Create an instance of serviceClass
+ final ServiceInterface service = (ServiceInterface) Class.forName(serviceClass).newInstance();
+
+ // Create ServiceRegistryBinding and register
+ final ServiceRegistryBinding binding = new ServiceRegistryBinding(serviceID, service, routingID,serviceInstanceName, componentType, serviceInstanceName,host.getFullName(), deployedComponent, pscID, service.getCurrentState(), service.getStateChangeTime(),essential, this.messageBus);
+
+ logMessage(PlatformPlugin.Util.getString("ServiceController.0",serviceInstanceName)); //$NON-NLS-1$
+
+ events.serviceAdded(binding);
+
+ // Initialize service
+ final Object[] param1 = new Object[] { serviceID };
+ DeployedComponentID deployedComponentID = (DeployedComponentID) deployedComponent.getID();
+ logMessage(PlatformPlugin.Util.getString("ServiceController.1",param1)); //$NON-NLS-1$
+ binding.getService().init(serviceID, deployedComponentID, serviceProps, serverListenerRegistry);
+ logMessage(PlatformPlugin.Util.getString("ServiceController.2",param1)); //$NON-NLS-1$
+ logMessage(PlatformPlugin.Util.getString("ServiceController.3",param1)); //$NON-NLS-1$
+
+ logMessage(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0009, serviceType, serviceInstanceName));
+
+ } catch (Exception e) {
+ throw new ServiceException(e, PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0028, serviceInstanceName));
+ }
+ }
+
+
+ /**
+ * Stop all the services in this vm.
+ *
+ * @param now If true do not wait for work to complete in services.
+ * @throws ServiceException if an error occurs stopping 1 or more services.
+ */
+ private void stopServices(boolean now, boolean shutdown) throws MultipleException {
+
+ MultipleException multipleException = new MultipleException();
+
+ List<ServiceRegistryBinding> bindings = this.registry.getServiceBindings(host.getFullName(), this.processName);
+
+ for (ServiceRegistryBinding binding:bindings) {
+ try {
+ stopService(binding, now, shutdown);
+ } catch (ServiceException se) {
+ multipleException.getExceptions().add(se);
+ }
+ }
+
+ int numExceptions = multipleException.getExceptions().size();
+ if (numExceptions == 1) {
+ //if there is one ServiceException, throw it
+ throw (ServiceException) multipleException.getExceptions().get(0);
+ } else if (numExceptions > 1) {
+ //if there are many, throw the MultipleException containing all of them
+ throw multipleException;
+ }
+ }
+
+ /**
+ * Stop service, if now flag is true then stop service immediately, do not wait for work to complete.
+ *
+ * @param serviceID Identifies service to be stopped
+ * @param now If true, stop service without waiting for work to complete
+ * @throws ServiceException if an error occurs while stopping service or if attempting shutdown the last essential service.
+ */
+ private synchronized void stopService(ServiceRegistryBinding binding, boolean now, boolean shutdown) {
+ ServiceInterface service = null;
+ int currentState;
+
+ if (!shutdown && !canServiceBeShutdown(binding)) {
+ throw new ServiceException(ErrorMessageKeys.SERVICE_0017, PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0017, binding.getServiceID()));
+ }
+
+ try {
+ service = binding.getService();
+ // check for null service in case the service was stopped. When servcie is stopped,
+ // the binding service reference is nulled out.
+ if (service == null) {
+ return;
+ }
+ currentState = binding.getCurrentState();
+ } catch (Exception e) {
+ throw new ServiceException(e, ErrorMessageKeys.SERVICE_0018, PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0018, binding.getServiceID()));
+ }
+
+ // Do not kill a service that was not intialized. May throw meaningless exception
+ if (currentState != ServiceState.STATE_INIT_FAILED &&
+ currentState != ServiceState.STATE_CLOSED) {
+ if (!now) {
+ service.die(); // throws ServiceException
+ } else {
+ service.dieNow(); // do not wait for work to complete.
+ }
+ }
+
+ // Leave binding in registry but remove service instance.
+ if (shutdown) {
+ events.serviceRemoved(binding.getServiceID());
+ }
+ else {
+ events.serviceUpdated(binding);
+ }
+ }
+
+
+ /**
+ * Check a service, and updates the state in some cases.
+ * Catches any ServiceExceptions, so that the caller doesn't have to deal with them.
+ * @param serviceID Identifies service to be stopped
+ */
+ public void checkService(ServiceID serviceID) {
+ logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0054, serviceID));
+ validateServiceID(serviceID);
+
+ ServiceInterface service = null;
+ int currentState = 0;
+
+ try {
+ ServiceRegistryBinding binding = this.registry.getServiceBinding(serviceID.getHostName(), serviceID.getProcessName(), serviceID);
+ service = binding.getService();
+ // check for null service in case the service was stopped. When service is stopped,
+ // the binding service reference is nulled out.
+
+ if (service != null) {
+ currentState = binding.getCurrentState();
+ } else {
+ return;
+ }
+ } catch (Exception e) {
+ logException(e, PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0068, serviceID));
+ return;
+ }
+
+ try {
+ //Only check state of OPEN and DATA_SOURCE_UNAVAILABLE services
+ if (currentState == ServiceState.STATE_OPEN ||
+ currentState == ServiceState.STATE_DATA_SOURCE_UNAVAILABLE) {
+ service.checkState(); // throws ServiceException
+ }
+ } catch (ServiceException e) {
+ logException(e, PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0068, serviceID));
+ }
+ }
+
+ protected Properties getProperties() {
+ return this.vmProps;
+ }
+
+ /**
+ * Return TRUE if the system's services are started; i.e. at least one of every essential services
+ * in a product is running. Authorization, Configuration, Membership and Session
+ * services are considered to be essential.
+ *
+ * @param callerSessionID ID of the caller's current session.
+ * @return Boolean - TRUE if system is started, FALSE if not.
+ * @throws MetaMatrixComponentException if an error occurred in communicating with a component.
+ */
+ protected boolean isStarted() {
+
+ boolean servicesStarted = false;
+ List authServices = this.registry.getActiveServiceBindings(null, null, AuthorizationServiceInterface.NAME);
+ List sessionServices = this.registry.getActiveServiceBindings(null, null,SessionServiceInterface.NAME);
+ List membershipServices = this.registry.getActiveServiceBindings(null, null,MembershipServiceInterface.NAME);
+ List configurationServices = this.registry.getActiveServiceBindings(null, null,ConfigurationServiceInterface.NAME);
+
+ if ( (authServices.size() > 0) &&
+ (sessionServices.size()) > 0 &&
+ (membershipServices.size() > 0) &&
+ (configurationServices.size() > 0)
+ ) {
+
+ servicesStarted = true;
+ }
+ return servicesStarted;
+ }
+
+ /**
+ * Create a globally unique ServiceID
+ *
+ * @return ServiceID
+ */
+ private ServiceID createServiceID() {
+ try {
+ return new ServiceID(DBIDGenerator.getInstance().getID(DBIDGenerator.SERVICE_ID), host.getFullName(), this.processName);
+ } catch (DBIDGeneratorException e) {
+ throw new ServiceException(e, ErrorMessageKeys.SERVICE_0025, PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0025));
+ }
+ }
+
+ /**
+ * True indicates service can be
+ */
+ private boolean canServiceBeShutdown(ServiceRegistryBinding binding) {
+
+ boolean shutdown = true;
+ try {
+ if (binding.isEssential()) {
+ List services = this.registry.getActiveServiceBindings(null, null, binding.getServiceType());
+ if (services.size() < 2) {
+ shutdown = false;
+ }
+ }
+ } catch (Exception e) {
+ logException(e, PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0026, binding.getServiceID()));
+ }
+ return shutdown;
+ }
+
+ // ---------------------------------------------------------------------
+ // Logging helpers
+ // ---------------------------------------------------------------------
+
+ private void logException(Throwable e, String msg) {
+ LogManager.logError(LogPlatformConstants.CTX_SERVICE_CONTROLLER, e, msg);
+ }
+
+
+ public InetAddress getAddress() {
+ return VMNaming.getHostAddress();
+ }
+
+
+ public String getName() {
+ return processName;
+ }
+
+}
Modified: trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ServerEvents.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ServerEvents.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ServerEvents.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -23,16 +23,16 @@
package com.metamatrix.platform.vm.controller;
import com.metamatrix.platform.registry.ServiceRegistryBinding;
-import com.metamatrix.platform.registry.VMRegistryBinding;
+import com.metamatrix.platform.registry.ProcessRegistryBinding;
import com.metamatrix.platform.service.api.ServiceID;
public interface ServerEvents {
- void vmAdded(VMRegistryBinding binding);
+ void processAdded(ProcessRegistryBinding binding);
- void vmRemoved(VMControllerID id);
+ void processRemoved(String hostName, String processName);
- void vmUpdated(VMRegistryBinding binding);
+ void processUpdated(ProcessRegistryBinding binding);
void serviceAdded(ServiceRegistryBinding binding);
Deleted: trunk/server/src/main/java/com/metamatrix/platform/vm/controller/VMController.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/vm/controller/VMController.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/platform/vm/controller/VMController.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -1,973 +0,0 @@
-/*
- * 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 com.metamatrix.platform.vm.controller;
-
-import java.io.File;
-import java.lang.reflect.Proxy;
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import com.metamatrix.admin.api.exception.AdminException;
-import com.metamatrix.admin.api.server.ServerAdmin;
-import com.metamatrix.admin.server.ServerAdminImpl;
-import com.metamatrix.admin.util.AdminMethodRoleResolver;
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.MultipleException;
-import com.metamatrix.common.comm.ClientServiceRegistry;
-import com.metamatrix.common.comm.platform.socket.server.AdminAuthorizationInterceptor;
-import com.metamatrix.common.comm.platform.socket.server.LogonImpl;
-import com.metamatrix.common.config.CurrentConfiguration;
-import com.metamatrix.common.config.JDBCConnectionPoolHelper;
-import com.metamatrix.common.config.api.ComponentTypeID;
-import com.metamatrix.common.config.api.ConfigurationModelContainer;
-import com.metamatrix.common.config.api.DeployedComponent;
-import com.metamatrix.common.config.api.DeployedComponentID;
-import com.metamatrix.common.config.api.Host;
-import com.metamatrix.common.config.api.HostID;
-import com.metamatrix.common.config.api.HostType;
-import com.metamatrix.common.config.api.ProductServiceConfigID;
-import com.metamatrix.common.config.api.ServiceComponentDefn;
-import com.metamatrix.common.config.api.ServiceComponentDefnID;
-import com.metamatrix.common.config.api.VMComponentDefn;
-import com.metamatrix.common.config.api.VMComponentDefnID;
-import com.metamatrix.common.config.api.VMComponentDefnType;
-import com.metamatrix.common.config.api.exceptions.ConfigurationException;
-import com.metamatrix.common.id.dbid.DBIDGenerator;
-import com.metamatrix.common.id.dbid.DBIDGeneratorException;
-import com.metamatrix.common.log.LogConfiguration;
-import com.metamatrix.common.log.LogManager;
-import com.metamatrix.common.messaging.MessageBus;
-import com.metamatrix.common.queue.WorkerPool;
-import com.metamatrix.common.queue.WorkerPoolFactory;
-import com.metamatrix.common.queue.WorkerPoolStats;
-import com.metamatrix.common.util.CommonPropertyNames;
-import com.metamatrix.common.util.LogCommonConstants;
-import com.metamatrix.common.util.PropertiesUtils;
-import com.metamatrix.common.util.VMNaming;
-import com.metamatrix.common.util.LogContextsUtil.PlatformAdminConstants;
-import com.metamatrix.core.util.FileUtil;
-import com.metamatrix.core.util.ZipFileUtil;
-import com.metamatrix.metadata.runtime.RuntimeMetadataCatalog;
-import com.metamatrix.platform.PlatformPlugin;
-import com.metamatrix.platform.admin.api.AuthorizationAdminAPI;
-import com.metamatrix.platform.admin.api.ConfigurationAdminAPI;
-import com.metamatrix.platform.admin.api.ExtensionSourceAdminAPI;
-import com.metamatrix.platform.admin.api.MembershipAdminAPI;
-import com.metamatrix.platform.admin.api.RuntimeStateAdminAPI;
-import com.metamatrix.platform.admin.api.SessionAdminAPI;
-import com.metamatrix.platform.admin.apiimpl.AdminHelper;
-import com.metamatrix.platform.admin.apiimpl.AuthorizationAdminAPIImpl;
-import com.metamatrix.platform.admin.apiimpl.ConfigurationAdminAPIImpl;
-import com.metamatrix.platform.admin.apiimpl.ExtensionSourceAdminAPIImpl;
-import com.metamatrix.platform.admin.apiimpl.MembershipAdminAPIImpl;
-import com.metamatrix.platform.admin.apiimpl.RuntimeStateAdminAPIImpl;
-import com.metamatrix.platform.admin.apiimpl.SessionAdminAPIImpl;
-import com.metamatrix.platform.config.api.service.ConfigurationServiceInterface;
-import com.metamatrix.platform.registry.ClusteredRegistryState;
-import com.metamatrix.platform.registry.ResourceNotBoundException;
-import com.metamatrix.platform.registry.ServiceRegistryBinding;
-import com.metamatrix.platform.registry.VMRegistryBinding;
-import com.metamatrix.platform.security.api.ILogon;
-import com.metamatrix.platform.security.api.service.AuthorizationServiceInterface;
-import com.metamatrix.platform.security.api.service.MembershipServiceInterface;
-import com.metamatrix.platform.security.api.service.SessionServiceInterface;
-import com.metamatrix.platform.service.api.ServiceID;
-import com.metamatrix.platform.service.api.ServiceInterface;
-import com.metamatrix.platform.service.api.ServiceState;
-import com.metamatrix.platform.service.api.exception.ServiceException;
-import com.metamatrix.platform.service.controller.ServicePropertyNames;
-import com.metamatrix.platform.util.ErrorMessageKeys;
-import com.metamatrix.platform.util.LogMessageKeys;
-import com.metamatrix.platform.util.LogPlatformConstants;
-import com.metamatrix.platform.util.PlatformProxyHelper;
-import com.metamatrix.platform.vm.api.controller.VMControllerInterface;
-import com.metamatrix.server.HostManagement;
-import com.metamatrix.server.ResourceFinder;
-import com.metamatrix.server.admin.api.QueryAdminAPI;
-import com.metamatrix.server.admin.api.RuntimeMetadataAdminAPI;
-import com.metamatrix.server.admin.api.TransactionAdminAPI;
-import com.metamatrix.server.admin.apiimpl.QueryAdminAPIImpl;
-import com.metamatrix.server.admin.apiimpl.RuntimeMetadataAdminAPIImpl;
-import com.metamatrix.server.admin.apiimpl.TransactionAdminAPIImpl;
-
-/**
- * This class is used to start up and bind VM's to the naming server.
- *
- * The following command will startup a standalone vm with no services.
- * <p><blockquote><pre>
- * java com.metamatrix.framework.vm.controller.VMController <VM_Name> false log.txt
- * </pre></blockquote>
- *
- * The following command will startup a vm and start services as defined in the deployment model.
- * The vmName must exist in the property service.
- *
- * <p><blockquote><pre>
- * java com.metamatrix.framework.vm.controller.VMController vmName true log.txt
- * </pre></blockquote>
- *
- *
- */
-public abstract class VMController implements VMControllerInterface {
-
- public static final String STARTER_MAX_THREADS = "vm.starter.maxThreads"; //$NON-NLS-1$
- /**Time-to-live for threads used to start services (ms)*/
- public static final String STARTER_TIMETOLIVE = "vm.starter.timetolive"; //$NON-NLS-1$
- /**Interval to check the state of services (ms)*/
- public static final String SERVICE_MONITOR_INTERVAL = "metamatrix.server.serviceMonitorInterval"; //$NON-NLS-1$
-
- // this is a 4.2.2 property used for command line setting
- private static final String STOP_DELAY_TIME = "metamatrix.vm.stop.delay.sec"; //$NON-NLS-1$
-
- private static final int DEFAULT_FORCE_SHUTDOWN_TIME = 30;
- public static final int DEFAULT_STARTER_MAX_THREADS = 15;
- public static final int DEFAULT_STARTER_TIMETOLIVE = 15000;
-
- protected Host host;
- protected String vmName;
- protected VMControllerID id;
-
- private Date startTime;
- private Properties vmProps;
- VMComponentDefn vmComponentDefn;
-
- private boolean shuttingDown = false;
-
- //WorkerPool used for starting services asynchronously
- private WorkerPool startServicePool;
-
- protected ClusteredRegistryState registry;
-
- private MessageBus messageBus;
-
- // Server events that are being generated
- ServerEvents events;
-
- protected ClientServiceRegistry clientServices;
- private Map<ComponentTypeID, Properties> defaultPropertiesCache = new HashMap<ComponentTypeID, Properties>();
- private Properties hostProperties;
-
- private int force_shutdown_time = DEFAULT_FORCE_SHUTDOWN_TIME;
-
- /**
- * Create a new instance of VMController.
- *
- * @param vmName Name of VM
- * @param startDeployedServices If true all services that are deployed to this vm are started.
- * @param standalone If true indicates that VMController is running in its own vm.
- * @throws Exception if an error occurs initializing vmController
- */
- public VMController(Host host, String vmName, VMControllerID vmId, ClusteredRegistryState registry, ServerEvents serverEvents, MessageBus bus, HostManagement hostManagement) throws Exception {
- this.host = host;
- this.vmName = vmName;
-
- this.registry = registry;
- this.events = serverEvents;
- this.messageBus = bus;
-
- Properties configProps = CurrentConfiguration.getInstance().getProperties();
- int maxThreads = PropertiesUtils.getIntProperty(configProps, STARTER_MAX_THREADS, DEFAULT_STARTER_MAX_THREADS);
- int timeToLive = PropertiesUtils.getIntProperty(configProps, STARTER_TIMETOLIVE, DEFAULT_STARTER_TIMETOLIVE);
-
- this.startServicePool = WorkerPoolFactory.newWorkerPool("StartServiceQueue", maxThreads, timeToLive); //$NON-NLS-1$
-
- this.id = vmId;
-
- initVMProperties(host.getFullName(), vmName);
-
- this.startTime = new Date();
-
- //Register with registry
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0006, id));
-
- this.clientServices = new ClientServiceRegistry();
-
- RuntimeMetadataCatalog.getInstance().init(CurrentConfiguration.getInstance().getProperties(), ResourceFinder.getMessageBus(), ResourceFinder.getCacheFactory());
-
- this.registerILogonAPI();
- this.registerAdmin(hostManagement);
-
- this.registerSubSystemAdminAPIs(hostManagement);
-
- addShutdownHook();
- }
-
-
- /**
- * Register the ServiceInterceptors for the SubSystemAdminAPIs
- * @throws MetaMatrixComponentException
- */
- private void registerSubSystemAdminAPIs(HostManagement hostManagement) throws MetaMatrixComponentException {
- this.clientServices.registerClientService(ConfigurationAdminAPI.class, ConfigurationAdminAPIImpl.getInstance(this.registry), PlatformAdminConstants.CTX_CONFIGURATION_ADMIN_API);
- this.clientServices.registerClientService(RuntimeStateAdminAPI.class, RuntimeStateAdminAPIImpl.getInstance(this.registry, hostManagement), PlatformAdminConstants.CTX_RUNTIME_STATE_ADMIN_API);
- this.clientServices.registerClientService(MembershipAdminAPI.class, MembershipAdminAPIImpl.getInstance(), PlatformAdminConstants.CTX_ADMIN_API);
- this.clientServices.registerClientService(SessionAdminAPI.class, SessionAdminAPIImpl.getInstance(), PlatformAdminConstants.CTX_ADMIN_API);
- this.clientServices.registerClientService(AuthorizationAdminAPI.class, AuthorizationAdminAPIImpl.getInstance(), PlatformAdminConstants.CTX_AUTHORIZATION_ADMIN_API);
- this.clientServices.registerClientService(ExtensionSourceAdminAPI.class, ExtensionSourceAdminAPIImpl.getInstance(), PlatformAdminConstants.CTX_ADMIN_API);
- this.clientServices.registerClientService(QueryAdminAPI.class, QueryAdminAPIImpl.getInstance(), PlatformAdminConstants.CTX_ADMIN_API);
- this.clientServices.registerClientService(RuntimeMetadataAdminAPI.class, RuntimeMetadataAdminAPIImpl.getInstance(), PlatformAdminConstants.CTX_RUNTIME_METADATA_ADMIN_API);
- this.clientServices.registerClientService(TransactionAdminAPI.class, TransactionAdminAPIImpl.getInstance(), PlatformAdminConstants.CTX_ADMIN_API);
- }
-
-
- /**
- * Register a ServiceInterceptor for the new Admin API, so that the client can access it via messaging.
- * @throws AdminException
- *
- * @throws MetaMatrixComponentException
- */
- private void registerAdmin(HostManagement hostManagement) throws AdminException {
- ServerAdminImpl serverAdminImpl = new ServerAdminImpl(this.registry, hostManagement);
- AdminMethodRoleResolver adminMethodRoleResolver = new AdminMethodRoleResolver();
- adminMethodRoleResolver.init();
- ServerAdmin roleCheckedServerAdmin = (ServerAdmin)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] {ServerAdmin.class}, new AdminAuthorizationInterceptor(new AdminHelper(), adminMethodRoleResolver, serverAdminImpl));
- this.clientServices.registerClientService(ServerAdmin.class, roleCheckedServerAdmin, PlatformAdminConstants.CTX_ADMIN);
- }
-
- /**
- * Register ILogonAPI's ServiceInterceptor
- * @throws ServiceException
- * @throws ConfigurationException
- */
- private void registerILogonAPI() throws ConfigurationException, ServiceException {
- this.clientServices.registerClientService(ILogon.class, new LogonImpl(PlatformProxyHelper.getSessionServiceProxy(PlatformProxyHelper.ROUND_ROBIN_LOCAL), CurrentConfiguration.getInstance().getClusterName()), LogCommonConstants.CTX_LOGON);
- }
-
- private void addShutdownHook() {
- Runtime.getRuntime().addShutdownHook(new Thread() {
- public void run() {
- try {
- shutdown(false);
- } catch (Exception e) {
- // ignore
- }
- }
- });
- }
-
- /**
- * Lazily get Current Configuration
- */
- ConfigurationModelContainer getConfigurationModel() throws ConfigurationException {
- return CurrentConfiguration.getInstance().getConfigurationModel();
- }
-
- /**
- * Initialize vm properties.
- * This method initializes the following global attributes.
- *
- * - hostID
- * - vmComponentDefnID
- * - vmProps
- */
- private void initVMProperties(String hostname, String vmName) throws Exception {
- ConfigurationModelContainer config = getConfigurationModel();
-
- VMComponentDefn deployedVM = config.getConfiguration().getVMForHost(hostname, vmName);
-
- if (deployedVM != null) {
- this.vmComponentDefn = deployedVM;
-
- vmProps = config.getDefaultPropertyValues(deployedVM.getComponentTypeID());
- Properties props = config.getConfiguration().getAllPropertiesForComponent(deployedVM.getID());
- vmProps.putAll(props);
-
- // this system property setting will override the setting in the VM
- // this is done because the command line argument
- force_shutdown_time = PropertiesUtils.getIntProperty(System.getProperties(), STOP_DELAY_TIME, DEFAULT_FORCE_SHUTDOWN_TIME);
- if (DEFAULT_FORCE_SHUTDOWN_TIME == force_shutdown_time) {
- force_shutdown_time = PropertiesUtils.getIntProperty(vmProps, VMComponentDefnType.FORCED_SHUTDOWN_TIME, DEFAULT_FORCE_SHUTDOWN_TIME);
- }
-
- Properties allProps = new Properties();
- allProps.putAll(System.getProperties());
- allProps.putAll(config.getConfiguration().getProperties());
- allProps.putAll(host.getProperties());
- allProps.putAll(props);
- System.setProperties(allProps);
-
- logMessage(PlatformPlugin.Util.getString("VMController.VM_Force_Shutdown_Time", force_shutdown_time)); //$NON-NLS-1$
-
- // add the vm to registry
- VMRegistryBinding binding = new VMRegistryBinding(host.getFullName(), id, deployedVM, this, this.messageBus);
- this.events.vmAdded(binding);
- }
- }
-
- protected void logMessage(String s) {
- LogManager.logInfo(LogCommonConstants.CTX_CONTROLLER, s);
- }
-
- protected static void doUsage() {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.VM_0010));
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.VM_0011));
- }
-
- public VMControllerID getID() {
- return id;
- }
-
- public void start() {
-
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0013));
- VMComponentDefnID vmComponentDefnID = (VMComponentDefnID)this.vmComponentDefn.getID();
-
- try {
- ConfigurationModelContainer configuration = getConfigurationModel();
-
- Collection deployedServices = configuration.getConfiguration().getDeployedServicesForVM(this.vmComponentDefn);
-
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0014, new Integer(deployedServices.size()), vmComponentDefnID.getName()));
-
- ArrayList essentialServices = new ArrayList();
- ArrayList otherServices = new ArrayList();
-
- // create a list of platform services and other services
- Iterator servicesIterator = deployedServices.iterator();
- while (servicesIterator.hasNext()) {
- DeployedComponent depComp = (DeployedComponent) servicesIterator.next();
-
- ServiceComponentDefn scd = (ServiceComponentDefn) depComp.getDeployedComponentDefn(configuration.getConfiguration());
-
- if (scd.isEssential()) {
- essentialServices.add(depComp);
- } else {
- otherServices.add(depComp);
- }
- }
-
- // start platform services first (synchronously)
- boolean errored = false;
- servicesIterator = essentialServices.iterator();
- while (servicesIterator.hasNext()) {
- DeployedComponent depComp = (DeployedComponent) servicesIterator.next();
- try {
- startDeployedService(depComp, null, configuration, true);
- } catch (Exception e) {
- errored = true;
- // error already logged from startDeployedService method.
- // continue starting services.
- }
- }
-
- if (errored) return;
-
-
- // now start the rest of the services asynchronously
- servicesIterator = otherServices.iterator();
- while (servicesIterator.hasNext()) {
- DeployedComponent depComp = (DeployedComponent) servicesIterator.next();
- try {
- startDeployedService(depComp, null, configuration, false);
- } catch (Exception e) {
- // error already logged from startDeployedService method.
- // continue starting services.
- }
- }
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0016, new Integer(deployedServices.size()), vmComponentDefnID.getName()));
-
- } catch (ConfigurationException e) {
- logException(e, PlatformPlugin.Util.getString(LogMessageKeys.VM_0017, vmComponentDefnID.getName(), host.getID().getName()));
- }
- }
-
-
- public void startService(ServiceID serviceID) {
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0018, serviceID));
-
- ServiceRegistryBinding binding = null;
-
- try {
- binding = this.registry.getServiceBinding(serviceID.getHostName(), serviceID.getVMControllerID().toString(), serviceID);
- } catch (ResourceNotBoundException e) {
- String msg = PlatformPlugin.Util.getString(LogMessageKeys.VM_0019, serviceID);
- throw new ServiceException(e, msg);
- } catch (Exception e) {
- String msg = PlatformPlugin.Util.getString(LogMessageKeys.VM_0020, serviceID);
- throw new ServiceException(e, msg);
- }
-
- if (!binding.isServiceBad()) {
- throw new ServiceException(PlatformPlugin.Util.getString(LogMessageKeys.VM_0021, serviceID));
- }
-
- try {
- ConfigurationModelContainer configuration = getConfigurationModel();
- startDeployedService(binding.getDeployedComponent(), serviceID, configuration, true);
-
- } catch (Exception e) {
- throw new ServiceException(e, PlatformPlugin.Util.getString(LogMessageKeys.VM_0022, serviceID));
- }
- }
-
- public void startDeployedService(ServiceComponentDefnID id) {
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0023, id));
- startDeployedService(id, null);
- }
-
- private void startDeployedService(ServiceComponentDefnID defnID, ServiceID serviceID) {
- try {
- ConfigurationModelContainer configuration = getConfigurationModel();
- VMComponentDefnID vmComponentDefnID = (VMComponentDefnID)this.vmComponentDefn.getID();
- DeployedComponent deployedService = configuration.getConfiguration().getDeployedServiceForVM(defnID, vmComponentDefnID, (HostID) getConfigHost().getID());
- startDeployedService(deployedService, serviceID, configuration, true);
- } catch (Exception e) {
- String msg = PlatformPlugin.Util.getString(LogMessageKeys.VM_0024, defnID);
- throw new ServiceException(e, msg);
- }
- }
-
- /**
- * Start the service identified by the DeployedComponentID
- * If synch is true then wait for service to start before returning.
- * Any exceptions will then be thrown to the caller.
- * If synch is false then start service asynchronously.
- * @throws ConfigurationException
- */
- private void startDeployedService(DeployedComponent deployedService, ServiceID serviceID, ConfigurationModelContainer configModel, boolean synch) throws ConfigurationException {
- Properties defaultProps = null;
- synchronized (this) {
- defaultProps = defaultPropertiesCache.get(deployedService.getComponentTypeID());
-
- if (defaultProps == null) {
- if (hostProperties == null) {
- hostProperties = CurrentConfiguration.getInstance().getSystemBootStrapProperties();
- hostProperties = new Properties(hostProperties);
- PropertiesUtils.putAll(hostProperties, host.getProperties());
- }
- defaultProps = new Properties(hostProperties);
- defaultProps.putAll(configModel.getDefaultPropertyValues(deployedService.getComponentTypeID()));
- defaultPropertiesCache.put(deployedService.getComponentTypeID(), defaultProps);
- }
- }
- Properties serviceProps = new Properties(defaultProps);
- Properties props = configModel.getConfiguration().getAllPropertiesForComponent(deployedService.getID());
- serviceProps.putAll(props);
- PropertiesUtils.setOverrideProperies(serviceProps, hostProperties);
-
- ProductServiceConfigID pscID = deployedService.getProductServiceConfigID();
- String serviceClassName = serviceProps.getProperty( ServicePropertyNames.SERVICE_CLASS_NAME );
-
- if (serviceClassName != null && serviceClassName.length() > 0) {
- logMessage( PlatformPlugin.Util.getString(LogMessageKeys.VM_0025, deployedService.getServiceComponentDefnID().getName(), vmName, host.getID().getName()));
-
- serviceProps.put(ServicePropertyNames.INSTANCE_NAME, deployedService.getName());
- serviceProps.put(ServicePropertyNames.SERVICE_NAME, deployedService.getServiceComponentDefnID().getName());
- serviceProps.put(ServicePropertyNames.COMPONENT_TYPE_NAME, deployedService.getComponentTypeID().getFullName());
-
- // get routing id.
- if (!deployedService.isDeployedConnector()) {
- serviceProps.put(ServicePropertyNames.SERVICE_ROUTING_ID, deployedService.getComponentTypeID().getFullName());
- } else {
- ServiceComponentDefn scd = (ServiceComponentDefn) deployedService.getDeployedComponentDefn(configModel.getConfiguration());
- String routingID = scd.getRoutingUUID();
- serviceProps.put(ServicePropertyNames.SERVICE_ROUTING_ID, routingID);
- }
- startService(this.clientServices, serviceClassName, serviceID, deployedService, pscID, serviceProps, synch );
-
- } else {
- String msg = PlatformPlugin.Util.getString(LogMessageKeys.VM_0026, new Object[] {ServicePropertyNames.SERVICE_CLASS_NAME, deployedService.getServiceComponentDefnID().getName(), vmName, host.getID().getName()});
- throw new ServiceException(msg);
- }
-
- }
-
- /**
- * Shut down all services waiting for work to complete.
- * Essential services will also be shutdown.
- */
- public synchronized void shutdown(boolean now) {
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0041));
-
- try {
- stopServices(now, true);
- } catch (MultipleException e) {
- logException(e, e.getMessage());
- } catch (ServiceException e) {
- logException(e, e.getMessage());
- }
-
- JDBCConnectionPoolHelper.getInstance().shutDown();
-
- // unregister VMController
- events.vmRemoved(id);
-
- this.shuttingDown = true;
-
- notifyAll();
-
- this.startServicePool.execute(new Runnable() {
- public void run() {
- // Wait before killing the VM.
- try {
- Thread.sleep(force_shutdown_time * 1000);
- } catch (Exception e) {}
- // And exit.
- System.exit(1);
- }
- });
- }
-
-
- /**
- * Kill service once work is complete
- */
- public void stopService(ServiceID id, boolean now, boolean shutdown) {
- try {
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0035, id));
- validateServiceID(id);
- ServiceRegistryBinding binding = this.registry.getServiceBinding(id.getHostName(), id.getVMControllerID().toString(), id);
- stopService(binding, now, shutdown);
- } catch (ResourceNotBoundException e) {
- throw new ServiceException(e);
- }
- }
-
- /**
- * Set the current log configuration for this vm.
- */
- public void setCurrentLogConfiguration(LogConfiguration logConfiguration) {
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0046, logConfiguration));
- LogManager.setLogConfiguration(logConfiguration);
- }
-
- /**
- * Get the time the VM was initialized.
- */
- public Date getStartTime() {
- return this.startTime;
- }
-
-
- public Host getConfigHost() {
- return this.host;
- }
-
- /**
- * Method called from registries to determine if VMController is alive.
- */
- public void ping() {
- }
-
- public synchronized boolean isShuttingDown() {
- return shuttingDown;
- }
-
- /**
- * Return information about VM. totalMemory, freeMemory, threadCount
- */
- public VMStatistics getVMStatistics() {
- VMStatistics vmStats = new VMStatistics();
- Runtime rt = Runtime.getRuntime();
- vmStats.freeMemory = rt.freeMemory();
- vmStats.totalMemory = rt.totalMemory();
-
- // get total thread count.
- ThreadGroup root, tg;
- root = Thread.currentThread().getThreadGroup();
- while ((tg = root.getParent()) != null) {
- root = tg;
- }
- vmStats.threadCount = root.activeCount();
- vmStats.name = vmName;
-
-
- vmStats.processPoolStats = getProcessPoolStats();
- vmStats.socketListenerStats = getSocketListenerStats();
-
- return vmStats;
- }
-
- /**
- * Prints thread information to a log file.
- * Does not include the stacktrace - that is not available in 1.4.
- */
- public void dumpThreads() {
-
- ThreadGroup root, tg;
- root = Thread.currentThread().getThreadGroup();
- while ((tg = root.getParent()) != null) {
- root = tg;
- }
- listThreads(root, 0);
- }
-
- /**
- * Print information about the specified thread group.
- */
- private void listThreads(ThreadGroup tg, int indent) {
-
- for (int i = 0; i < indent; i++) {
- System.out.print(" "); //$NON-NLS-1$
- }
- System.out.println(tg);
- indent++;
-
- //Recursively print information threads in this group
- int cnt = tg.activeCount();
- Thread[] threads = new Thread[cnt];
- tg.enumerate(threads, false);
- for (int i = 0; i < cnt; i++) {
- if (threads[i] != null) {
- for (int j = 0; j < indent; j++) {
- System.out.print(" "); //$NON-NLS-1$
- }
- System.out.println(threads[i]);
- }
- }
-
- //Recursively print information about child thread groups
- cnt = tg.activeGroupCount();
- ThreadGroup[] groups = new ThreadGroup[cnt];
- tg.enumerate(groups);
- for (int i = 0; i < cnt; i++) {
- listThreads(groups[i], indent);
- }
- }
-
- /**
- * Private helper method that verifies service belongs to this vm
- */
- private void validateServiceID(ServiceID serviceID) {
- if (!serviceID.getVMControllerID().equals(getID())) {
- throw new ServiceException(PlatformPlugin.Util.getString(LogMessageKeys.VM_0047, serviceID, this.id));
- }
- }
-
- /**
- * @see com.metamatrix.platform.vm.api.controller.VMControllerInterface#exportLogs()
- * @since 4.3
- */
- public byte[] exportLogs() {
- File tmpFile = null;
- try {
- tmpFile = File.createTempFile("logs", ".zip"); //$NON-NLS-1$ //$NON-NLS-2$
- tmpFile.deleteOnExit();
-
- String mainLogDirectory = host.getLogDirectory();
- ZipFileUtil.addAll(tmpFile, mainLogDirectory, "log"); //$NON-NLS-1$
-
- String hostLogDirectory = host.getProperty(HostType.HOST_DIRECTORY) + File.separator + "log"; //$NON-NLS-1$
- ZipFileUtil.addAll(tmpFile, hostLogDirectory, "hosts_"+host.getName()+"_log"); //$NON-NLS-1$//$NON-NLS-2$
-
- String servletLogDirectory = host.getProperty(HostType.HOST_DIRECTORY) + File.separator + "servletengine" + File.separator + "logs"; //$NON-NLS-1$ //$NON-NLS-2$
- ZipFileUtil.addAll(tmpFile, servletLogDirectory, "hosts_"+host.getName()+"_servletengine_log"); //$NON-NLS-1$//$NON-NLS-2$
-
- return new FileUtil(tmpFile.getAbsolutePath()).readBytes();
-
- } catch (Exception e) {
- throw new ServiceException(e);
- } finally {
- try {
- tmpFile.delete();
- } catch (Exception e) {
- }
- }
- }
-
- public abstract SocketListenerStats getSocketListenerStats();
- public abstract WorkerPoolStats getProcessPoolStats();
-
-
- /**
- * Start a service in this VM. If synch flag is true then what for the service to start
- * before returning. Starting a service in this manner is typically done from the console so
- * any errors can be reported. Starting a service asynchronously (synch == false) is intended for
- * starting up the server. This prevents any race conditions due to service dependencies.
- *
- * @param ClientServiceRegistry Class to registry ServerListener
- * @param serviceClassName Class to instantiate as a service.
- * @param serviceID - null if a new service, if non-null then we are re-starting a service.
- * @param serviceProps Properties required to start service.
- * @param synch Flag to indicate if service should be started synchronously are asynchronously.
- */
- private void startService(final ClientServiceRegistry clientServiceRegistry, final String serviceClassName, final ServiceID serviceID, final DeployedComponent deployedComponent, final ProductServiceConfigID pscID, final Properties serviceProps, boolean synch) {
-
- if (!synch) {
- //add work to the pool
- startServicePool.execute( new Runnable() {
- public void run() {
- startService(clientServiceRegistry, serviceID, deployedComponent,serviceClassName, pscID, serviceProps);
- }
- });
- } else {
- //start synchronously
- try {
- startService(clientServiceRegistry, serviceID, deployedComponent,serviceClassName, pscID, serviceProps);
- } catch (Exception e) {
- throw new ServiceException(e);
- }
- }
- }
-
- private void startService(ClientServiceRegistry serverListenerRegistry, ServiceID serviceID, DeployedComponent deployedComponent,final String serviceClass,ProductServiceConfigID pscID,Properties serviceProps) {
- String serviceInstanceName = null;
-
- try {
- if (serviceID == null) {
- serviceID = this.createServiceID();
- }
-
- serviceInstanceName = serviceProps.getProperty(ServicePropertyNames.INSTANCE_NAME);
- String componentType = serviceProps.getProperty(ServicePropertyNames.COMPONENT_TYPE_NAME);
- String serviceType = serviceProps.getProperty(ServicePropertyNames.SERVICE_NAME);
- String routingID = serviceProps.getProperty(ServicePropertyNames.SERVICE_ROUTING_ID);
- String essentialStr = serviceProps.getProperty(ServicePropertyNames.SERVICE_ESSENTIAL);
-
-
- boolean essential = false;
- if (essentialStr != null && essentialStr.trim().length() != 0) {
- essential = Boolean.valueOf(essentialStr).booleanValue();
- }
-
- // Create an instance of serviceClass
- final ServiceInterface service = (ServiceInterface) Class.forName(serviceClass).newInstance();
-
- // Create ServiceRegistryBinding and register
- final ServiceRegistryBinding binding = new ServiceRegistryBinding(serviceID, service, routingID,serviceInstanceName, componentType, serviceInstanceName,host.getFullName(), deployedComponent, pscID, service.getCurrentState(), service.getStateChangeTime(),essential, this.messageBus);
-
- logMessage(PlatformPlugin.Util.getString("ServiceController.0",serviceInstanceName)); //$NON-NLS-1$
-
- events.serviceAdded(binding);
-
- // Initialize service
- final Object[] param1 = new Object[] { serviceID };
- DeployedComponentID deployedComponentID = (DeployedComponentID) deployedComponent.getID();
- logMessage(PlatformPlugin.Util.getString("ServiceController.1",param1)); //$NON-NLS-1$
- binding.getService().init(serviceID, deployedComponentID, serviceProps, serverListenerRegistry);
- logMessage(PlatformPlugin.Util.getString("ServiceController.2",param1)); //$NON-NLS-1$
- logMessage(PlatformPlugin.Util.getString("ServiceController.3",param1)); //$NON-NLS-1$
-
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0009, serviceType, serviceInstanceName));
-
- } catch (Exception e) {
- throw new ServiceException(e, PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0028, serviceInstanceName));
- }
- }
-
-
- /**
- * Stop all the services in this vm.
- *
- * @param now If true do not wait for work to complete in services.
- * @throws ServiceException if an error occurs stopping 1 or more services.
- */
- private void stopServices(boolean now, boolean shutdown) throws MultipleException {
-
- MultipleException multipleException = new MultipleException();
-
- List<ServiceRegistryBinding> bindings = this.registry.getServiceBindings(host.getFullName(), id.toString());
-
- for (ServiceRegistryBinding binding:bindings) {
- try {
- stopService(binding, now, shutdown);
- } catch (ServiceException se) {
- multipleException.getExceptions().add(se);
- }
- }
-
- int numExceptions = multipleException.getExceptions().size();
- if (numExceptions == 1) {
- //if there is one ServiceException, throw it
- throw (ServiceException) multipleException.getExceptions().get(0);
- } else if (numExceptions > 1) {
- //if there are many, throw the MultipleException containing all of them
- throw multipleException;
- }
- }
-
- /**
- * Stop service, if now flag is true then stop service immediately, do not wait for work to complete.
- *
- * @param serviceID Identifies service to be stopped
- * @param now If true, stop service without waiting for work to complete
- * @throws ServiceException if an error occurs while stopping service or if attempting shutdown the last essential service.
- */
- private synchronized void stopService(ServiceRegistryBinding binding, boolean now, boolean shutdown) {
- ServiceInterface service = null;
- int currentState;
-
- if (!shutdown && !canServiceBeShutdown(binding)) {
- throw new ServiceException(ErrorMessageKeys.SERVICE_0017, PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0017, binding.getServiceID()));
- }
-
- try {
- service = binding.getService();
- // check for null service in case the service was stopped. When servcie is stopped,
- // the binding service reference is nulled out.
- if (service == null) {
- return;
- }
- currentState = binding.getCurrentState();
- } catch (Exception e) {
- throw new ServiceException(e, ErrorMessageKeys.SERVICE_0018, PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0018, binding.getServiceID()));
- }
-
- // Do not kill a service that was not intialized. May throw meaningless exception
- if (currentState != ServiceState.STATE_INIT_FAILED &&
- currentState != ServiceState.STATE_CLOSED) {
- if (!now) {
- service.die(); // throws ServiceException
- } else {
- service.dieNow(); // do not wait for work to complete.
- }
- }
-
- // Leave binding in registry but remove service instance.
- if (shutdown) {
- events.serviceRemoved(binding.getServiceID());
- }
- else {
- events.serviceUpdated(binding);
- }
- }
-
-
- /**
- * Check a service, and updates the state in some cases.
- * Catches any ServiceExceptions, so that the caller doesn't have to deal with them.
- * @param serviceID Identifies service to be stopped
- */
- public void checkService(ServiceID serviceID) {
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0054, serviceID));
- validateServiceID(serviceID);
-
- ServiceInterface service = null;
- int currentState = 0;
-
- try {
- ServiceRegistryBinding binding = this.registry.getServiceBinding(serviceID.getHostName(), serviceID.getVMControllerID().toString(), serviceID);
- service = binding.getService();
- // check for null service in case the service was stopped. When service is stopped,
- // the binding service reference is nulled out.
-
- if (service != null) {
- currentState = binding.getCurrentState();
- } else {
- return;
- }
- } catch (Exception e) {
- logException(e, PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0068, serviceID));
- return;
- }
-
- try {
- //Only check state of OPEN and DATA_SOURCE_UNAVAILABLE services
- if (currentState == ServiceState.STATE_OPEN ||
- currentState == ServiceState.STATE_DATA_SOURCE_UNAVAILABLE) {
- service.checkState(); // throws ServiceException
- }
- } catch (ServiceException e) {
- logException(e, PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0068, serviceID));
- }
- }
-
- protected Properties getProperties() {
- return this.vmProps;
- }
-
- /**
- * Return TRUE if the system's services are started; i.e. at least one of every essential services
- * in a product is running. Authorization, Configuration, Membership and Session
- * services are considered to be essential.
- *
- * @param callerSessionID ID of the caller's current session.
- * @return Boolean - TRUE if system is started, FALSE if not.
- * @throws MetaMatrixComponentException if an error occurred in communicating with a component.
- */
- protected boolean isStarted() {
-
- boolean servicesStarted = false;
- List authServices = this.registry.getActiveServiceBindings(null, null, AuthorizationServiceInterface.NAME);
- List sessionServices = this.registry.getActiveServiceBindings(null, null,SessionServiceInterface.NAME);
- List membershipServices = this.registry.getActiveServiceBindings(null, null,MembershipServiceInterface.NAME);
- List configurationServices = this.registry.getActiveServiceBindings(null, null,ConfigurationServiceInterface.NAME);
-
- if ( (authServices.size() > 0) &&
- (sessionServices.size()) > 0 &&
- (membershipServices.size() > 0) &&
- (configurationServices.size() > 0)
- ) {
-
- servicesStarted = true;
- }
- return servicesStarted;
- }
-
- /**
- * Create a globally unique ServiceID
- *
- * @return ServiceID
- */
- private ServiceID createServiceID() {
- try {
- return new ServiceID(DBIDGenerator.getInstance().getID(DBIDGenerator.SERVICE_ID), id);
- } catch (DBIDGeneratorException e) {
- throw new ServiceException(e, ErrorMessageKeys.SERVICE_0025, PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0025));
- }
- }
-
- /**
- * True indicates service can be
- */
- private boolean canServiceBeShutdown(ServiceRegistryBinding binding) {
-
- boolean shutdown = true;
- try {
- if (binding.isEssential()) {
- List services = this.registry.getActiveServiceBindings(null, null, binding.getServiceType());
- if (services.size() < 2) {
- shutdown = false;
- }
- }
- } catch (Exception e) {
- logException(e, PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0026, binding.getServiceID()));
- }
- return shutdown;
- }
-
- // ---------------------------------------------------------------------
- // Logging helpers
- // ---------------------------------------------------------------------
-
- private void logException(Throwable e, String msg) {
- LogManager.logError(LogPlatformConstants.CTX_SERVICE_CONTROLLER, e, msg);
- }
-
-
- public InetAddress getAddress() {
- return VMNaming.getHostAddress();
- }
-
-
- public String getName() {
- return vmName;
- }
-
-}
Modified: trunk/server/src/main/java/com/metamatrix/server/Configuration.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/Configuration.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/server/Configuration.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -25,8 +25,7 @@
public interface Configuration {
final String HOST = "Host"; //$NON-NLS-1$
final String HOSTNAME = "HostName"; //$NON-NLS-1$
- final String VMNAME = "VMName"; //$NON-NLS-1$
- final String VMID = "VMId"; //$NON-NLS-1$
+ final String PROCESSNAME = "ProcessName"; //$NON-NLS-1$
final String CLUSTERNAME = "ClusterName"; //$NON-NLS-1$
final String LOGFILE = "LogFile"; //$NON-NLS-1$
final String LOGDIR = "LogDir"; //$NON-NLS-1$
Modified: trunk/server/src/main/java/com/metamatrix/server/HostController.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/HostController.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/server/HostController.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -53,7 +53,7 @@
import com.metamatrix.platform.registry.ClusteredRegistryState;
import com.metamatrix.platform.registry.HostControllerRegistryBinding;
import com.metamatrix.platform.registry.HostMonitor;
-import com.metamatrix.platform.registry.VMRegistryBinding;
+import com.metamatrix.platform.registry.ProcessRegistryBinding;
import com.metamatrix.platform.util.ErrorMessageKeys;
import com.metamatrix.platform.util.LogMessageKeys;
@@ -178,23 +178,23 @@
vmPropsAndConfigProps.putAll(props);
vmPropsAndConfigProps.putAll(this.host.getProperties());
vmPropsAndConfigProps.putAll(vmProps);
- String vmName = deployedVM.getID().getName();
+ String processName = deployedVM.getID().getName();
// pass the instance name and its properties
- String name = vmName.toUpperCase();
+ String name = processName.toUpperCase();
if (processMap.containsKey(name)) {
- LogManager.logInfo(LogCommonConstants.CTX_CONTROLLER, PlatformPlugin.Util.getString(LogMessageKeys.HOST_0011,vmName));
+ LogManager.logInfo(LogCommonConstants.CTX_CONTROLLER, PlatformPlugin.Util.getString(LogMessageKeys.HOST_0011,processName));
try {
- killServer(hostname, vmName, true);
+ killServer(hostname, processName, true);
} catch (MetaMatrixComponentException e) {
LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, e.getMessage());
}
}
if (deployedVM.isEnabled()) {
- processMap.put(name, startDeployVM(vmName, hostname, vmPropsAndConfigProps));
+ processMap.put(name, startDeployVM(processName, hostname, vmPropsAndConfigProps));
} else {
- LogManager.logInfo(LogCommonConstants.CTX_CONTROLLER, PlatformPlugin.Util.getString("HostController.VM_is_not_enabled_to_start", vmName));//$NON-NLS-1$
+ LogManager.logInfo(LogCommonConstants.CTX_CONTROLLER, PlatformPlugin.Util.getString("HostController.VM_is_not_enabled_to_start", processName));//$NON-NLS-1$
}
}
@@ -290,13 +290,13 @@
return injector.getInstance(HostController.class);
}
- private Process startDeployVM( String vmName, String hostName, Properties vmprops) {
- LogManager.logInfo(LogCommonConstants.CTX_CONTROLLER, "Start deploy VM = " + vmName + " on host = "+ hostName); //$NON-NLS-1$ //$NON-NLS-2$
- String command = buildVMCommand(vmName, vmprops);
+ private Process startDeployVM( String processName, String hostName, Properties vmprops) {
+ LogManager.logInfo(LogCommonConstants.CTX_CONTROLLER, "Start deploy VM = " + processName + " on host = "+ hostName); //$NON-NLS-1$ //$NON-NLS-2$
+ String command = buildVMCommand(processName, vmprops);
return execCommand(command);
}
- private String buildVMCommand(String vmName, Properties vmprops) {
+ private String buildVMCommand(String processName, Properties vmprops) {
String java = null;
String java_home = System.getProperty("java.home"); //$NON-NLS-1$
if (java_home != null) {
@@ -310,7 +310,7 @@
java = replaceToken(java, vmprops);
java_opts = replaceToken(java_opts, vmprops);
- String cmd = java + " " +java_opts+ " " + DEFAULT_JAVA_MAIN + " " + vmName; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ String cmd = java + " " +java_opts+ " " + DEFAULT_JAVA_MAIN + " " + processName; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return cmd;
}
@@ -352,18 +352,18 @@
}
@Override
- public void killServer(String hostName, String vmName, boolean stopNow) throws MetaMatrixComponentException {
+ public void killServer(String hostName, String processName, boolean stopNow) throws MetaMatrixComponentException {
if (isRootHost(hostName)) {
- LogManager.logInfo(LogCommonConstants.CTX_CONTROLLER, "KillVM " + vmName); //$NON-NLS-1$
+ LogManager.logInfo(LogCommonConstants.CTX_CONTROLLER, "KillVM " + processName); //$NON-NLS-1$
// find the vm and shut it down.
- List<VMRegistryBinding> vms = HostController.this.registry.getVMs(null);
- for (VMRegistryBinding vm:vms) {
+ List<ProcessRegistryBinding> vms = HostController.this.registry.getVMs(null);
+ for (ProcessRegistryBinding vm:vms) {
if (vm.getHostName().equalsIgnoreCase(this.host.getFullName())) {
- if (vm.getVMName().equalsIgnoreCase(vmName)) {
+ if (vm.getProcessName().equalsIgnoreCase(processName)) {
try {
- vm.getVMController().shutdown(stopNow);
+ vm.getProcessController().shutdown(stopNow);
} catch (Exception e) {
// ignore
}
@@ -372,16 +372,16 @@
}
}
- Process process = (Process) processMap.get(vmName.toUpperCase());
+ Process process = (Process) processMap.get(processName.toUpperCase());
if (process != null) {
- processMap.remove(vmName.toUpperCase());
+ processMap.remove(processName.toUpperCase());
process.destroy();
}
}
else {
HostManagement remoteHost = getRemoteHost(hostName);
if (remoteHost != null) {
- remoteHost.killServer(hostName, vmName, stopNow);
+ remoteHost.killServer(hostName, processName, stopNow);
}
else {
throw new MetaMatrixComponentException("HostController for host = " + hostName + " can not be reached"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -403,8 +403,8 @@
Iterator processes = copyMap.keySet().iterator();
while (processes.hasNext()) {
- String vmName = (String) processes.next();
- killServer(hostName, vmName, stopNow);
+ String processName = (String) processes.next();
+ killServer(hostName, processName, stopNow);
}
processMap.clear();
}
@@ -448,7 +448,7 @@
@Override
- public boolean pingServer(String hostName, String vmName) {
+ public boolean pingServer(String hostName, String processName) {
return true;
}
@@ -487,26 +487,26 @@
}
@Override
- public void startServer(String hostName, String vmName) throws MetaMatrixComponentException {
+ public void startServer(String hostName, String processName) throws MetaMatrixComponentException {
if (isRootHost(hostName)) {
try {
- LogManager.logInfo(LogCommonConstants.CTX_CONTROLLER, "StartVM " + vmName); //$NON-NLS-1$
+ LogManager.logInfo(LogCommonConstants.CTX_CONTROLLER, "StartVM " + processName); //$NON-NLS-1$
CurrentConfiguration.getInstance().verifyBootstrapProperties();
ConfigurationModelContainer currentConfig = CurrentConfiguration.getInstance().getConfigurationModel();
- VMComponentDefn deployedVM = currentConfig.getConfiguration().getVMForHost(this.host.getFullName(), vmName);
+ VMComponentDefn deployedVM = currentConfig.getConfiguration().getVMForHost(this.host.getFullName(), processName);
if (deployedVM != null) {
startVM(deployedVM, this.host.getFullName(), currentConfig);
}
} catch (ConfigurationException e) {
- LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, "Error starting the vm = "+vmName); //$NON-NLS-1$
+ LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, "Error starting the vm = "+processName); //$NON-NLS-1$
}
}
else {
HostManagement remoteHost = getRemoteHost(hostName);
if (remoteHost != null) {
- remoteHost.startServer(hostName, vmName);
+ remoteHost.startServer(hostName, processName);
}
else {
throw new MetaMatrixComponentException("HostController for host = " + hostName + " can not be reached"); //$NON-NLS-1$ //$NON-NLS-2$
Modified: trunk/server/src/main/java/com/metamatrix/server/HostManagement.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/HostManagement.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/server/HostManagement.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -64,26 +64,26 @@
void bounceServers(String hostName) throws MetaMatrixComponentException;
/**
- * Start a server process on this host with specified vmName
+ * Start a server process on this host with specified processName
* @param hostName - name of the host; can not be null
- * @param vmName - virtual machine name
+ * @param processName - virtual machine name
*/
- void startServer(String hostName, String vmName) throws MetaMatrixComponentException ;
+ void startServer(String hostName, String processName) throws MetaMatrixComponentException ;
/**
- * Kill the server process on this host with specified vmName
+ * Kill the server process on this host with specified processName
* @param hostName - name of the host; can not be null
- * @param vmName
+ * @param processName
*/
- void killServer(String hostName, String vmName, boolean stopNow) throws MetaMatrixComponentException;
+ void killServer(String hostName, String processName, boolean stopNow) throws MetaMatrixComponentException;
/**
- * Ping the server process on this host with given vmName.
+ * Ping the server process on this host with given processName.
* @param hostName - name of the host; can not be null
- * @param vmName
+ * @param processName
* @return true if available; false otherwise
*/
- boolean pingServer(String hostName, String vmName);
+ boolean pingServer(String hostName, String processName);
/**
* Ping the local host controller
Modified: trunk/server/src/main/java/com/metamatrix/server/LogApplicationInfo.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/LogApplicationInfo.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/server/LogApplicationInfo.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -54,13 +54,13 @@
String applFileName = null;
String logPath = null;
String hostName;
- String vmName;
+ String processName;
- public LogApplicationInfo(String hostName, String vmName, String path, String fileName) {
+ public LogApplicationInfo(String hostName, String processName, String path, String fileName) {
applFileName = fileName;
logPath = path;
this.hostName = hostName;
- this.vmName = vmName;
+ this.processName = processName;
}
public void run() {
@@ -68,7 +68,7 @@
try {
ConfigurationModelContainer configmodel = CurrentConfiguration.getInstance().getConfigurationModel();
- VMComponentDefn deployedVM = configmodel.getConfiguration().getVMForHost(this.hostName, this.vmName);
+ VMComponentDefn deployedVM = configmodel.getConfiguration().getVMForHost(this.hostName, this.processName);
Properties configprops = null;
Modified: trunk/server/src/main/java/com/metamatrix/server/Main.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/Main.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/server/Main.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -39,7 +39,7 @@
import com.metamatrix.core.util.StringUtil;
import com.metamatrix.dqp.ResourceFinder;
import com.metamatrix.platform.PlatformPlugin;
-import com.metamatrix.platform.vm.api.controller.VMControllerInterface;
+import com.metamatrix.platform.vm.api.controller.ProcessManagement;
/**
* This is main server starter class.
@@ -50,7 +50,7 @@
MessageBus messageBus;
@Inject
- VMControllerInterface vmController;
+ ProcessManagement vmController;
@Inject
LogListener logListener;
@@ -63,7 +63,7 @@
System.exit(1);
}
- String vmName = args[0];
+ String processName = args[0];
Host host = null;
try {
@@ -76,19 +76,19 @@
System.exit(-1);
}
- VMComponentDefn deployedVM = CurrentConfiguration.getInstance().getConfiguration().getVMForHost(host.getName(), vmName);
+ VMComponentDefn deployedVM = CurrentConfiguration.getInstance().getConfiguration().getVMForHost(host.getName(), processName);
String bindAddress = deployedVM.getBindAddress();
- VMNaming.setVMName(vmName);
+ VMNaming.setProcessName(processName);
VMNaming.setup(host.getFullName(), host.getHostAddress(), bindAddress);
// write info log
- writeInfoLog(host, vmName);
+ writeInfoLog(host, processName);
createTempDirectory();
// wire up guice modules
- Main main = loadMain(host, vmName);
+ Main main = loadMain(host, processName);
// launch the server
@@ -100,8 +100,8 @@
}
- private static Main loadMain(Host host, String vmName) {
- Injector injector = Guice.createInjector(new ServerGuiceModule(host, vmName));
+ private static Main loadMain(Host host, String processName) {
+ Injector injector = Guice.createInjector(new ServerGuiceModule(host, processName));
// Until we get the all the DI working we have to resort to this kind of stuff..
ResourceFinder.setInjector(injector);
return injector.getInstance(Main.class);
@@ -144,15 +144,15 @@
}
}
- private static String buildPrefix(String hostName, String vmName){
+ private static String buildPrefix(String hostName, String processName){
String hostFileName = StringUtil.replaceAll(hostName, ".", "_"); //$NON-NLS-1$ //$NON-NLS-2$
- return hostFileName + "_" + vmName; //$NON-NLS-1$
+ return hostFileName + "_" + processName; //$NON-NLS-1$
}
- private static void writeInfoLog(Host host, String vmName) {
+ private static void writeInfoLog(Host host, String processName) {
// trigger the logging of the current application info to a log file for debugging
- LogApplicationInfo logApplInfo = new LogApplicationInfo(host.getFullName(), vmName, host.getLogDirectory(), buildPrefix(host.getFullName(), vmName) + "_info.log"); //$NON-NLS-1$
+ LogApplicationInfo logApplInfo = new LogApplicationInfo(host.getFullName(), processName, host.getLogDirectory(), buildPrefix(host.getFullName(), processName) + "_info.log"); //$NON-NLS-1$
logApplInfo.start();
}
Modified: trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -34,42 +34,31 @@
import com.metamatrix.common.config.CurrentConfiguration;
import com.metamatrix.common.config.api.Host;
import com.metamatrix.common.config.api.exceptions.ConfigurationException;
-import com.metamatrix.common.id.dbid.DBIDGenerator;
-import com.metamatrix.common.id.dbid.DBIDGeneratorException;
import com.metamatrix.common.log.LogConfiguration;
import com.metamatrix.common.log.LogManager;
import com.metamatrix.common.messaging.MessageBus;
import com.metamatrix.common.messaging.VMMessageBus;
-import com.metamatrix.core.MetaMatrixRuntimeException;
import com.metamatrix.core.log.LogListener;
import com.metamatrix.core.util.StringUtil;
import com.metamatrix.platform.registry.ClusteredRegistryState;
-import com.metamatrix.platform.registry.VMMonitor;
+import com.metamatrix.platform.registry.ProcessMonitor;
import com.metamatrix.platform.service.proxy.ProxyManager;
import com.metamatrix.platform.util.PlatformProxyHelper;
-import com.metamatrix.platform.vm.api.controller.VMControllerInterface;
+import com.metamatrix.platform.vm.api.controller.ProcessManagement;
import com.metamatrix.platform.vm.controller.ServerEvents;
-import com.metamatrix.platform.vm.controller.VMControllerID;
class ServerGuiceModule extends AbstractModule {
Host host;
- String vmName;
+ String processName;
- public ServerGuiceModule(Host host, String vmName) {
+ public ServerGuiceModule(Host host, String processName) {
this.host = host;
- this.vmName = vmName;
+ this.processName = processName;
}
@Override
protected void configure() {
-
- long vmID = 1;
- try {
- vmID = DBIDGenerator.getInstance().getID(DBIDGenerator.VM_ID);
- } catch (DBIDGeneratorException e1) {
- throw new MetaMatrixRuntimeException(e1);
- }
String systemName = null;
try {
@@ -79,16 +68,14 @@
}
bindConstant().annotatedWith(Names.named(Configuration.HOSTNAME)).to(host.getFullName());
- bindConstant().annotatedWith(Names.named(Configuration.VMNAME)).to(vmName);
- bindConstant().annotatedWith(Names.named(Configuration.VMID)).to(vmID);
+ bindConstant().annotatedWith(Names.named(Configuration.PROCESSNAME)).to(processName);
bind(Host.class).annotatedWith(Names.named(Configuration.HOST)).toInstance(host);
bindConstant().annotatedWith(Names.named(Configuration.CLUSTERNAME)).to(systemName);
- bindConstant().annotatedWith(Names.named(Configuration.LOGFILE)).to(StringUtil.replaceAll(host.getFullName(), ".", "_")+"_"+this.vmName+".log"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ bindConstant().annotatedWith(Names.named(Configuration.LOGFILE)).to(StringUtil.replaceAll(host.getFullName(), ".", "_")+"_"+this.processName+".log"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
bindConstant().annotatedWith(Names.named(Configuration.LOGDIR)).to(host.getLogDirectory());
Names.bindProperties(binder(), CurrentConfiguration.getInstance().getProperties());
- bind(VMControllerID.class).toInstance(new VMControllerID(vmID, host.getFullName()));
bind(Multiplexer.class).toProvider(JGroupsProvider.class).in(Scopes.SINGLETON);
bind(ChannelProvider.class).in(Scopes.SINGLETON);
bind(Cache.class).toProvider(CacheProvider.class).in(Scopes.SINGLETON);
@@ -96,8 +83,8 @@
bind(ClusteredRegistryState.class).in(Scopes.SINGLETON);
bind(ProxyManager.class).in(Scopes.SINGLETON);
bind(MessageBus.class).to(VMMessageBus.class).in(Scopes.SINGLETON); // VM Message bus is in common-internal
- bind(VMControllerInterface.class).to(SocketVMController.class).in(Scopes.SINGLETON);
- bind(ServerEvents.class).to(VMMonitor.class).in(Scopes.SINGLETON);
+ bind(ProcessManagement.class).to(SocketVMController.class).in(Scopes.SINGLETON);
+ bind(ServerEvents.class).to(ProcessMonitor.class).in(Scopes.SINGLETON);
bind(HostManagement.class).toProvider(HostManagementProvider.class).in(Scopes.SINGLETON);
// this needs to be removed.
Modified: trunk/server/src/main/java/com/metamatrix/server/ServiceManager.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/ServiceManager.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/server/ServiceManager.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -31,6 +31,7 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.StringTokenizer;
import com.google.inject.Guice;
import com.google.inject.Inject;
@@ -57,14 +58,14 @@
import com.metamatrix.platform.registry.ClusteredRegistryState;
import com.metamatrix.platform.registry.HostControllerRegistryBinding;
import com.metamatrix.platform.registry.ServiceRegistryBinding;
-import com.metamatrix.platform.registry.VMRegistryBinding;
+import com.metamatrix.platform.registry.ProcessRegistryBinding;
import com.metamatrix.platform.service.api.CacheAdmin;
import com.metamatrix.platform.service.api.ServiceID;
import com.metamatrix.platform.service.api.ServiceInterface;
import com.metamatrix.platform.util.ErrorMessageKeys;
import com.metamatrix.platform.util.LogMessageKeys;
-import com.metamatrix.platform.vm.api.controller.VMControllerInterface;
-import com.metamatrix.platform.vm.controller.VMStatistics;
+import com.metamatrix.platform.vm.api.controller.ProcessManagement;
+import com.metamatrix.platform.vm.controller.ProcessStatistics;
/**
* Utility class that allows users to view the state of the services.
@@ -305,8 +306,8 @@
if (numTokens < 2) {
System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0013));
} else {
- String vmName = (String) parsedCommand.get(1);
- doStartVM(vmName);
+ String processName = (String) parsedCommand.get(1);
+ doStartVM(processName);
}
break;
@@ -314,8 +315,8 @@
if (numTokens < 2) {
System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0013));
} else {
- String vmName = (String) parsedCommand.get(1);
- doStopVM(vmName);
+ String processName = (String) parsedCommand.get(1);
+ doStopVM(processName);
}
break;
@@ -341,59 +342,34 @@
break;
case COMMAND_STOP_SERVICE:
- if (numTokens < 2) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0015));
- } else {
- String id = (String) parsedCommand.get(1);
- long value;
- try {
- value = Long.parseLong(id);
- } catch (Exception e) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0016));
- break;
- }
- doStopService(new ServiceID(value, null));
- }
+ ServiceID id = parseServiceID(parsedCommand);
+ if (id != null) {
+ doStopService(id);
+ }
break;
case COMMAND_GET_SERVICE_STATUS:
- if (numTokens < 2) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0015));
- } else {
- String id = (String) parsedCommand.get(1);
- long value;
- try {
- value = Long.parseLong(id);
- } catch (Exception e) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0016));
- break;
- }
- doGetServiceStatus(new ServiceID(value, null));
- }
+ {
+ ServiceID service = parseServiceID(parsedCommand);
+ if (service != null) {
+ doGetServiceStatus(service);
+ }
break;
-
+ }
case COMMAND_MARK_SERVICE_AS_BAD:
- if (numTokens < 2) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0015));
- } else {
- String id = (String) parsedCommand.get(1);
- long value;
- try {
- value = Long.parseLong(id);
- } catch (Exception e) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0016));
- break;
- }
- doMarkServiceAsBad(new ServiceID(value, null));
- }
+ {
+ ServiceID service = parseServiceID(parsedCommand);
+ if (service != null) {
+ doMarkServiceAsBad(service);
+ }
break;
-
+ }
case COMMAND_LIST_VM_PROPERTIES:
if (numTokens < 2) {
System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0013));
} else {
- String vmName = (String) parsedCommand.get(1);
- doListVMProps(vmName);
+ String processName = (String) parsedCommand.get(1);
+ doListVMProps(processName);
}
break;
@@ -410,8 +386,8 @@
if (numTokens < 2) {
System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0013));
} else {
- String vmName = (String) parsedCommand.get(1);
- doShutdownVM(vmName, false);
+ String processName = (String) parsedCommand.get(1);
+ doShutdownVM(processName, false);
}
break;
@@ -442,8 +418,8 @@
if (numTokens < 2) {
System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0013));
} else {
- String vmName = (String) parsedCommand.get(1);
- doGetVMStats(vmName);
+ String processName = (String) parsedCommand.get(1);
+ doGetVMStats(processName);
}
break;
@@ -451,31 +427,23 @@
if (numTokens < 2) {
System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0013));
} else {
- String vmName = (String) parsedCommand.get(1);
- doDumpThreads(vmName);
+ String processName = (String) parsedCommand.get(1);
+ doDumpThreads(processName);
}
break;
case COMMAND_GET_SERVICE_QUEUES:
- if (numTokens < 2) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0015));
- } else {
- String id = (String) parsedCommand.get(1);
- long value;
- try {
- value = Long.parseLong(id);
- } catch (Exception e) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0016));
- break;
- }
+ {
+ ServiceID id1 = parseServiceID(parsedCommand);
+ if (id1 != null) {
String queueName = null;
if (numTokens > 2) {
queueName = (String) parsedCommand.get(2);
}
- doGetServiceQueues(new ServiceID(value, null), queueName);
- }
+ doGetServiceQueues(id1, queueName);
+ }
break;
-
+ }
case COMMAND_SYNCH_SERVER:
this.doSynchronize();
break;
@@ -502,23 +470,38 @@
break;
case COMMAND_START_SERVICE:
- if (numTokens < 2) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0015));
- } else {
- String id = (String) parsedCommand.get(1);
- long value;
- try {
- value = Long.parseLong(id);
- } catch (Exception e) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0016));
- break;
- }
- doStartService(new ServiceID(value, null));
- }
+ {
+ ServiceID id1 = parseServiceID(parsedCommand);
+ if (id1 != null) {
+ doStartService(id1);
+ }
break;
+ }
}
}
+ private ServiceID parseServiceID(List parsedCommand) {
+ if (parsedCommand.size() < 2) {
+ System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0015));
+ return null;
+ } else {
+ String id = (String) parsedCommand.get(1);
+ StringTokenizer st = new StringTokenizer(id, "|"); //$NON-NLS-1$
+ if (st.countTokens() != 3) {
+ System.out.println("Service id must be in the format <id|hostname|processname>"); //$NON-NLS-1$
+ return null;
+ }
+ long value;
+ try {
+ value = Long.parseLong(st.nextToken());
+ } catch (Exception e) {
+ System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0016));
+ return null;
+ }
+ return new ServiceID(value, st.nextToken(), st.nextToken());
+ }
+ }
+
public void doBounceService(String name) {
@@ -542,9 +525,9 @@
se.printStackTrace();
}
try {
- VMRegistryBinding vmBinding = registry.getVM(binding.getHostName(), binding.getServiceID().getVMControllerID().toString());
+ ProcessRegistryBinding vmBinding = registry.getProcessBinding(binding.getHostName(), binding.getServiceID().getProcessName());
if (vmBinding != null) {
- vmBinding.getVMController().startService(binding.getServiceID());
+ vmBinding.getProcessController().startService(binding.getServiceID());
System.out.println("Starting " + binding.getServiceID()); //$NON-NLS-1$
}
else {
@@ -707,50 +690,50 @@
}
}
- private void doGetVMStats(String vmName) {
- VMControllerInterface vm = getVMController(vmName);
+ private void doGetVMStats(String processName) {
+ ProcessManagement vm = getVMController(processName);
if (vm != null) {
try {
- VMStatistics stats = vm.getVMStatistics();
+ ProcessStatistics stats = vm.getVMStatistics();
System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0019, stats.name));
System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0020, stats.totalMemory));
System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0021, stats.freeMemory));
System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0022, stats.threadCount));
} catch (Exception e) {
- System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0031, vmName));
+ System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0031, processName));
e.printStackTrace();
}
} else {
- System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0030, vmName));
+ System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0030, processName));
}
}
- private void doDumpThreads(String vmName) {
- VMControllerInterface vm = getVMController(vmName);
+ private void doDumpThreads(String processName) {
+ ProcessManagement vm = getVMController(processName);
if (vm != null) {
try {
System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0023));
vm.dumpThreads();
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0024, vmName));
+ System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0024, processName));
} catch (Exception e) {
- System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0031, vmName));
+ System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0031, processName));
e.printStackTrace();
}
} else {
- System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0030, vmName));
+ System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0030, processName));
}
}
- private VMControllerInterface getVMController(String vmName) {
+ private ProcessManagement getVMController(String processName) {
// find vm
try {
Iterator vmIter = registry.getVMs(null).iterator();
while (vmIter.hasNext()) {
- VMRegistryBinding vmBinding = (VMRegistryBinding) vmIter.next();
- if (vmBinding.getVMName().equalsIgnoreCase(vmName)) {
- return vmBinding.getVMController();
+ ProcessRegistryBinding vmBinding = (ProcessRegistryBinding) vmIter.next();
+ if (vmBinding.getProcessName().equalsIgnoreCase(processName)) {
+ return vmBinding.getProcessController();
}
}
return null;
@@ -778,7 +761,7 @@
}
}
- private void doStartVM(String vmName) {
+ private void doStartVM(String processName) {
String host = null;
// get host to connect to.
@@ -786,7 +769,7 @@
Iterator vmIter = getDeployedVMs().iterator();
while (vmIter.hasNext()) {
VMComponentDefn vmDefn = (VMComponentDefn) vmIter.next();
- if (vmDefn.getName().equalsIgnoreCase(vmName)) {
+ if (vmDefn.getName().equalsIgnoreCase(processName)) {
host = vmDefn.getHostID().getName();
break;
}
@@ -801,14 +784,14 @@
}
try {
- this.hostManager.startServer(host, vmName);
+ this.hostManager.startServer(host, processName);
} catch (Exception e) {
e.printStackTrace();
}
}
- public void doListVMProps(String vmName) {
+ public void doListVMProps(String processName) {
String host = null;
// get host to connect to.
@@ -816,10 +799,10 @@
Iterator vmIter = getDeployedVMs().iterator();
while (vmIter.hasNext()) {
VMComponentDefn vmDefn = (VMComponentDefn) vmIter.next();
- if (vmDefn.getName().equalsIgnoreCase(vmName)) {
+ if (vmDefn.getName().equalsIgnoreCase(processName)) {
host = vmDefn.getHostID().getName();
Properties vmPropsAndConfigProps = currentConfig.getAllPropertiesForComponent(vmDefn.getID());
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0025, vmName));
+ System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0025, processName));
Iterator iter = vmPropsAndConfigProps.keySet().iterator();
while (iter.hasNext()) {
String key = (String) iter.next();
@@ -873,27 +856,27 @@
}
}
- public void doStopVM(String vmName) {
+ public void doStopVM(String processName) {
// find vm
try {
Iterator vmIter = registry.getVMs(null).iterator();
- VMRegistryBinding vmBinding = null;
+ ProcessRegistryBinding vmBinding = null;
while (vmIter.hasNext()) {
- vmBinding = (VMRegistryBinding) vmIter.next();
- if (vmBinding.getVMName().equalsIgnoreCase(vmName)) {
- this.hostManager.killServer(vmBinding.getHostName(),vmBinding.getVMName(), false);
+ vmBinding = (ProcessRegistryBinding) vmIter.next();
+ if (vmBinding.getProcessName().equalsIgnoreCase(processName)) {
+ this.hostManager.killServer(vmBinding.getHostName(),vmBinding.getProcessName(), false);
break;
}
}
} catch (Exception e) {
- System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0034, vmName));
+ System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0034, processName));
System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0028));
- killVM(vmName);
+ killVM(processName);
}
}
- private void killVM(String vmName) {
+ private void killVM(String processName) {
String host = null;
// get host to connect to.
@@ -901,7 +884,7 @@
Iterator vmIter = getDeployedVMs().iterator();
while (vmIter.hasNext()) {
VMComponentDefn vmDefn = (VMComponentDefn) vmIter.next();
- if (vmDefn.getName().equalsIgnoreCase(vmName)) {
+ if (vmDefn.getName().equalsIgnoreCase(processName)) {
host = vmDefn.getHostID().getName();
break;
}
@@ -916,24 +899,24 @@
}
try {
- this.hostManager.killServer(host, vmName, false);
+ this.hostManager.killServer(host, processName, false);
} catch (Exception e) {
e.printStackTrace();
}
}
- public void doShutdownVM(String vmName, boolean now) {
+ public void doShutdownVM(String processName, boolean now) {
try {
Iterator vmIter = registry.getVMs(null).iterator();
while (vmIter.hasNext()) {
- VMRegistryBinding vmBinding = (VMRegistryBinding) vmIter.next();
- if (vmBinding.getVMName().equalsIgnoreCase(vmName)) {
- this.hostManager.killServer(vmBinding.getHostName(), vmName, now);
+ ProcessRegistryBinding vmBinding = (ProcessRegistryBinding) vmIter.next();
+ if (vmBinding.getProcessName().equalsIgnoreCase(processName)) {
+ this.hostManager.killServer(vmBinding.getHostName(), processName, now);
return;
}
}
} catch (Exception e) {
- System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0034, vmName));
+ System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0034, processName));
e.printStackTrace();
}
}
@@ -1040,12 +1023,12 @@
System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0039));
return;
}
- VMRegistryBinding vmBinding = registry.getVM(id.getHostName(), id.getVMControllerID().toString());
+ ProcessRegistryBinding vmBinding = registry.getProcessBinding(id.getHostName(), id.getProcessName());
if (vmBinding != null) {
- vmBinding.getVMController().stopService(id, false, false);
+ vmBinding.getProcessController().stopService(id, false, false);
}
else {
- System.out.println("No VM found on host="+id.getHostName()+" with id="+id.getVMControllerID().toString()); //$NON-NLS-1$ //$NON-NLS-2$
+ System.out.println("No VM found on host="+id.getHostName()+" with process name ="+id.getProcessName()); //$NON-NLS-1$ //$NON-NLS-2$
}
} catch (Exception e) {
System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0015, id));
@@ -1086,7 +1069,7 @@
System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0039));
return;
}
- System.out.println(registry.getServiceBinding(id.getHostName(), id.getVMControllerID().toString(), id));
+ System.out.println(registry.getServiceBinding(id.getHostName(), id.getProcessName(), id));
} catch (Exception e) {
System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0043));
e.printStackTrace();
@@ -1102,7 +1085,7 @@
System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0039));
return;
}
- ServiceRegistryBinding serviceBinding = this.registry.getServiceBinding(id.getHostName(), id.getVMControllerID().toString(), id);
+ ServiceRegistryBinding serviceBinding = this.registry.getServiceBinding(id.getHostName(), id.getProcessName(), id);
ServiceInterface service = null;
if (serviceBinding != null) {
@@ -1154,12 +1137,12 @@
System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0039));
return;
}
- VMRegistryBinding vmBinding = registry.getVM(id.getHostName(), id.getVMControllerID().toString());
+ ProcessRegistryBinding vmBinding = registry.getProcessBinding(id.getHostName(), id.getProcessName());
if (vmBinding != null) {
- vmBinding.getVMController().startService(id);
+ vmBinding.getProcessController().startService(id);
}
else {
- System.out.println("No VM found on host="+id.getHostName()+" with id="+id.getVMControllerID().toString()); //$NON-NLS-1$ //$NON-NLS-2$
+ System.out.println("No VM found on host="+id.getHostName()+" with process name ="+id.getProcessName()); //$NON-NLS-1$ //$NON-NLS-2$
}
} catch (Exception e) {
System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0047));
@@ -1175,7 +1158,7 @@
System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0039));
return;
}
- ServiceRegistryBinding binding = this.registry.getServiceBinding(serviceID.getHostName(), serviceID.getVMControllerID().toString(), serviceID);
+ ServiceRegistryBinding binding = this.registry.getServiceBinding(serviceID.getHostName(), serviceID.getProcessName(), serviceID);
if (binding != null) {
binding.markServiceAsBad();
}
Modified: trunk/server/src/main/java/com/metamatrix/server/connector/service/ConnectorService.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/connector/service/ConnectorService.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/server/connector/service/ConnectorService.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -243,10 +243,10 @@
// Create a stringified connector ID from the serviceID
ServiceID id = this.getID();
- String connID = id.getVMControllerID().getID() + "|" + id.getID(); //$NON-NLS-1$
+ String connID = id.getHostName()+"|"+ id.getProcessName() + "|" + id.getID(); //$NON-NLS-1$ //$NON-NLS-2$
deMaskedProps.put(ConnectorPropertyNames.CONNECTOR_ID, connID);
deMaskedProps.put(ConnectorPropertyNames.CONNECTOR_BINDING_NAME, getInstanceName());
- deMaskedProps.put(ConnectorPropertyNames.CONNECTOR_VM_NAME, VMNaming.getVMName());
+ deMaskedProps.put(ConnectorPropertyNames.CONNECTOR_VM_NAME, VMNaming.getProcessName());
connectorManager.setClassloader(loader);
connectorManager.initialize(deMaskedProps);
return connectorManager;
Modified: trunk/server/src/main/java/com/metamatrix/server/dqp/config/PlatformConfigSource.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/dqp/config/PlatformConfigSource.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/server/dqp/config/PlatformConfigSource.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -59,9 +59,9 @@
private Properties dqpProps;
private Host host;
- private String vmName;
+ private String processName;
- public PlatformConfigSource(Properties queryServiceProps, Properties currentConfiguration, Object clientId, Host host, String vmName) {
+ public PlatformConfigSource(Properties queryServiceProps, Properties currentConfiguration, Object clientId, Host host, String processName) {
dqpProps = PropertiesUtils.clone(queryServiceProps, currentConfiguration, true);
dqpProps.setProperty(DQPConfigSource.PROCESS_POOL_MAX_THREADS, queryServiceProps.getProperty(QueryServicePropertyNames.PROCESS_POOL_MAX_THREADS));
dqpProps.setProperty(DQPConfigSource.PROCESS_POOL_THREAD_TTL, queryServiceProps.getProperty(QueryServicePropertyNames.PROCESS_POOL_THREAD_TTL));
@@ -93,7 +93,7 @@
}
this.host = host;
- this.vmName = vmName;
+ this.processName = processName;
}
/*
@@ -125,7 +125,7 @@
} catch (VirtualDatabaseException e) {
throw new MetaMatrixRuntimeException(e);
}
- binder.bindConstant().annotatedWith(Names.named(Configuration.VMNAME)).to(vmName);
+ binder.bindConstant().annotatedWith(Names.named(Configuration.PROCESSNAME)).to(processName);
binder.bind(Host.class).annotatedWith(Names.named(Configuration.HOST)).toInstance(host);
}
Modified: trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformBufferService.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformBufferService.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformBufferService.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -47,13 +47,13 @@
private BufferManager bufferMgr;
private Properties props;
- private String vmName;
+ private String processName;
private Host host;
@Inject
- public PlatformBufferService((a)Named(Configuration.HOST) Host host, @Named(Configuration.VMNAME) String vmName) {
+ public PlatformBufferService((a)Named(Configuration.HOST) Host host, @Named(Configuration.PROCESSNAME) String processName) {
this.host = host;
- this.vmName = vmName;
+ this.processName = processName;
}
/*
@@ -83,7 +83,7 @@
props.setProperty(BufferManagerPropertyNames.BUFFER_STORAGE_DIRECTORY, dir);
try {
- bufferMgr = BufferManagerFactory.getServerBufferManager(host.getFullName()+"-"+vmName, props); //$NON-NLS-1$
+ bufferMgr = BufferManagerFactory.getServerBufferManager(host.getFullName()+"-"+processName, props); //$NON-NLS-1$
} catch (MetaMatrixComponentException e) {
throw new ApplicationLifecycleException(e);
}
Modified: trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformTransactionService.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformTransactionService.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/server/dqp/service/PlatformTransactionService.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -80,7 +80,7 @@
props.putAll(env);
props.setProperty(TransactionService.TXN_MGR_LOG_DIR, logDir);
props.setProperty(TransactionService.HOSTNAME, host.getFullName());
- props.setProperty(TransactionService.VMNAME, VMNaming.getVMName());
+ props.setProperty(TransactionService.VMNAME, VMNaming.getProcessName());
props.setProperty(TransactionService.TXN_STORE_DIR, host.getDataDirectory());
arjunaTs.init(ArjunaTransactionProvider.getInstance(props));
Modified: trunk/server/src/main/java/com/metamatrix/server/query/service/QueryService.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/query/service/QueryService.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/java/com/metamatrix/server/query/service/QueryService.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -95,7 +95,7 @@
LogManager.logError(LogConstants.CTX_QUERY_SERVICE, t, ServerPlugin.Util.getString("QueryService.Unable_to_register_user-defined_function_source__{0}_1", udfSource)); //$NON-NLS-1$
}
- DQPConfigSource configSource = new PlatformConfigSource(props, CurrentConfiguration.getInstance().getProperties(), new Long(getID().getID()), CurrentConfiguration.getInstance().getDefaultHost(), VMNaming.getVMName());
+ DQPConfigSource configSource = new PlatformConfigSource(props, CurrentConfiguration.getInstance().getProperties(), new Long(getID().getID()), CurrentConfiguration.getInstance().getDefaultHost(), VMNaming.getProcessName());
dqp = new DQPCore();
dqp.start(configSource);
}
Modified: trunk/server/src/main/resources/com/metamatrix/platform/i18n.properties
===================================================================
--- trunk/server/src/main/resources/com/metamatrix/platform/i18n.properties 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/main/resources/com/metamatrix/platform/i18n.properties 2009-03-04 23:29:07 UTC (rev 537)
@@ -1132,7 +1132,7 @@
MSG.014.010.0044 = Error removing {0} from registry.
MSG.014.010.0045 = Resuming service: {0}
MSG.014.010.0046 = Setting log config: {0}
-MSG.014.010.0047 = Service {0} does not belong to this VM: {1}
+MSG.014.010.0047 = Service {0} does not belong to this VM: <{1}.{2}>
MSG.014.010.0048 = Property "{0}" not defined. Using default command "{1}"
MSG.014.010.0049 = Starting command " {0} "
MSG.014.010.0050 = Command started.
Modified: trunk/server/src/test/java/com/metamatrix/admin/server/FakeCacheAdmin.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/admin/server/FakeCacheAdmin.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/test/java/com/metamatrix/admin/server/FakeCacheAdmin.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -40,7 +40,6 @@
import com.metamatrix.platform.service.api.CacheAdmin;
import com.metamatrix.platform.service.api.ServiceID;
import com.metamatrix.platform.service.api.ServiceInterface;
-import com.metamatrix.platform.vm.controller.VMControllerID;
public class FakeCacheAdmin implements CacheAdmin, ServiceInterface {
@@ -126,7 +125,7 @@
return null;
}
- public VMControllerID getVMID(){
+ public String getProcessName(){
return null;
}
Modified: trunk/server/src/test/java/com/metamatrix/admin/server/FakeConfiguration.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/admin/server/FakeConfiguration.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/test/java/com/metamatrix/admin/server/FakeConfiguration.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -272,7 +272,7 @@
}
public VMComponentDefn getVMForHost(String hostname,
- String vmname) {
+ String processName) {
return null;
}
Modified: trunk/server/src/test/java/com/metamatrix/admin/server/FakeConfigurationService.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/admin/server/FakeConfigurationService.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/test/java/com/metamatrix/admin/server/FakeConfigurationService.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -76,7 +76,6 @@
import com.metamatrix.platform.PlatformPlugin;
import com.metamatrix.platform.config.api.service.ConfigurationServiceInterface;
import com.metamatrix.platform.service.api.ServiceID;
-import com.metamatrix.platform.vm.controller.VMControllerID;
public class FakeConfigurationService implements ConfigurationServiceInterface {
@@ -713,7 +712,7 @@
/**
* @see com.metamatrix.platform.service.api.ServiceInterface#getVMID()
*/
- public VMControllerID getVMID() {
+ public String getProcessName() {
return null;
}
Modified: trunk/server/src/test/java/com/metamatrix/admin/server/FakeQueryService.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/admin/server/FakeQueryService.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/test/java/com/metamatrix/admin/server/FakeQueryService.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -42,7 +42,6 @@
import com.metamatrix.platform.security.api.MetaMatrixSessionID;
import com.metamatrix.platform.security.api.SessionToken;
import com.metamatrix.platform.service.api.ServiceID;
-import com.metamatrix.platform.vm.controller.VMControllerID;
import com.metamatrix.server.query.service.QueryServiceInterface;
import com.metamatrix.server.serverapi.RequestInfo;
@@ -71,32 +70,32 @@
public Collection getAllQueries() {
List results = new ArrayList();
- RequestInfo info1 = new RequestInfo(new RequestID("1", 1L), "sql1", new Date(), new Date()); //$NON-NLS-1$
- SessionToken token1 = new SessionToken(new MetaMatrixSessionID(1), "user1"); //$NON-NLS-1$ //$NON-NLS-2$
+ RequestInfo info1 = new RequestInfo(new RequestID("1", 1L), "sql1", new Date(), new Date()); //$NON-NLS-1$ //$NON-NLS-2$
+ SessionToken token1 = new SessionToken(new MetaMatrixSessionID(1), "user1"); //$NON-NLS-1$
info1.setSessionToken(token1);
results.add(info1);
- RequestInfo info2 = new RequestInfo(new RequestID("2", 2), "sql2", new Date(), new Date()); //$NON-NLS-1$
- SessionToken token2 = new SessionToken(new MetaMatrixSessionID(2), "user2"); //$NON-NLS-1$ //$NON-NLS-2$
+ RequestInfo info2 = new RequestInfo(new RequestID("2", 2), "sql2", new Date(), new Date()); //$NON-NLS-1$ //$NON-NLS-2$
+ SessionToken token2 = new SessionToken(new MetaMatrixSessionID(2), "user2"); //$NON-NLS-1$
info2.setSessionToken(token2);
results.add(info2);
//SourceRequests
- RequestInfo info1A = new RequestInfo(new RequestID("1", 1), "sql1", new Date(), new Date()); //$NON-NLS-1$
- SessionToken token1A = new SessionToken(new MetaMatrixSessionID(1), "user1"); //$NON-NLS-1$ //$NON-NLS-2$
+ RequestInfo info1A = new RequestInfo(new RequestID("1", 1), "sql1", new Date(), new Date()); //$NON-NLS-1$ //$NON-NLS-2$
+ SessionToken token1A = new SessionToken(new MetaMatrixSessionID(1), "user1"); //$NON-NLS-1$
info1A.setSessionToken(token1A);
- info1A.setConnectorBindingUUID("connectorBinding1");
+ info1A.setConnectorBindingUUID("connectorBinding1");//$NON-NLS-1$
info1A.setNodeID(1);
results.add(info1A);
- RequestInfo info2A = new RequestInfo(new RequestID("2", 2), "sql2", new Date(), new Date()); //$NON-NLS-1$
- SessionToken token2A = new SessionToken(new MetaMatrixSessionID(2), "user2"); //$NON-NLS-1$ //$NON-NLS-2$
+ RequestInfo info2A = new RequestInfo(new RequestID("2", 2), "sql2", new Date(), new Date()); //$NON-NLS-1$ //$NON-NLS-2$
+ SessionToken token2A = new SessionToken(new MetaMatrixSessionID(2), "user2"); //$NON-NLS-1$
info2A.setSessionToken(token2A);
- info2A.setConnectorBindingUUID("connectorBinding2");
+ info2A.setConnectorBindingUUID("connectorBinding2");//$NON-NLS-1$
info2A.setNodeID(2);
results.add(info2A);
@@ -181,7 +180,7 @@
/**
* @see com.metamatrix.platform.service.api.ServiceInterface#getVMID()
*/
- public VMControllerID getVMID(){
+ public String getProcessName(){
return null;
}
Modified: trunk/server/src/test/java/com/metamatrix/admin/server/FakeRuntimeStateAdminAPIHelper.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/admin/server/FakeRuntimeStateAdminAPIHelper.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/test/java/com/metamatrix/admin/server/FakeRuntimeStateAdminAPIHelper.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -37,7 +37,6 @@
import com.metamatrix.common.config.api.Configuration;
import com.metamatrix.common.config.api.ConnectorBindingType;
import com.metamatrix.common.config.api.DeployedComponent;
-import com.metamatrix.common.config.api.ServiceComponentDefnID;
import com.metamatrix.common.config.api.exceptions.ConfigurationException;
import com.metamatrix.common.config.api.exceptions.ConfigurationLockException;
import com.metamatrix.common.log.LogConfiguration;
@@ -53,8 +52,7 @@
import com.metamatrix.platform.service.api.ServiceID;
import com.metamatrix.platform.service.api.ServiceState;
import com.metamatrix.platform.service.api.exception.ServiceException;
-import com.metamatrix.platform.vm.controller.VMControllerID;
-import com.metamatrix.platform.vm.controller.VMStatistics;
+import com.metamatrix.platform.vm.controller.ProcessStatistics;
import com.metamatrix.server.connector.service.ConnectorService;
import com.metamatrix.server.query.service.QueryService;
@@ -207,19 +205,17 @@
public List getServices() throws MetaMatrixComponentException {
List results = new ArrayList();
- VMControllerID vmControllerID2 = new VMControllerID(2, "2.2.2.2"); //$NON-NLS-1$
- ServiceID serviceID2 = new ServiceID(2, vmControllerID2);
+ ServiceID serviceID2 = new ServiceID(2, "2.2.2.2", "process2"); //$NON-NLS-1$ //$NON-NLS-2$
results.add(serviceID2);
- VMControllerID vmControllerID3 = new VMControllerID(3, "3.3.3.3"); //$NON-NLS-1$
- ServiceID serviceID3 = new ServiceID(3, vmControllerID3);
+ ServiceID serviceID3 = new ServiceID(3, "3.3.3.3", "process3");//$NON-NLS-1$ //$NON-NLS-2$
results.add(serviceID3);
- ServiceID serviceID2A = new ServiceID(5, vmControllerID2);
+ ServiceID serviceID2A = new ServiceID(5, "2.2.2.2", "process2"); //$NON-NLS-1$ //$NON-NLS-2$
results.add(serviceID2A);
- ServiceID serviceID3A = new ServiceID(6, vmControllerID3);
+ ServiceID serviceID3A = new ServiceID(6, "3.3.3.3", "process3");//$NON-NLS-1$ //$NON-NLS-2$
results.add(serviceID3A);
@@ -238,15 +234,13 @@
List hosts = new ArrayList();
List processes2 = new ArrayList();
- VMControllerID vmControllerID1 = new VMControllerID(2, "2.2.2.2"); //$NON-NLS-1$
- ProcessData process2 = new ProcessData(vmControllerID1, null, "2.2.2.2", new ArrayList(), "process2", "31000", true, true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ProcessData process2 = new ProcessData("2.2.2.2", "process2", "31000", null, new ArrayList(), true, true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
processes2.add(process2);
HostData host2 = new HostData("2.2.2.2", processes2, true, true, new Properties()); //$NON-NLS-1$
hosts.add(host2);
List processes3 = new ArrayList();
- VMControllerID vmControllerID3 = new VMControllerID(3, "3.3.3.3"); //$NON-NLS-1$
- ProcessData process3 = new ProcessData(vmControllerID3, null, "3.3.3.3", new ArrayList(), "process3", "31001", true, true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ProcessData process3 = new ProcessData("3.3.3.3", "process3", "31001", null, new ArrayList(), true, true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
processes3.add(process3);
HostData host3 = new HostData("3.3.3.3", processes3, true, true, new Properties()); //$NON-NLS-1$
hosts.add(host3);
@@ -263,10 +257,10 @@
* @see com.metamatrix.platform.admin.apiimpl.RuntimeStateAdminAPIHelper#getSystemState()
* @since 4.3
*/
- public VMStatistics getVMStatistics(VMControllerID vmID) throws MetaMatrixComponentException {
+ public ProcessStatistics getVMStatistics(String hostName, String processName) throws MetaMatrixComponentException {
- if (vmID.getID() == 2) {
- VMStatistics statistics = new VMStatistics();
+ if (processName.equals("process2")) { //$NON-NLS-1$
+ ProcessStatistics statistics = new ProcessStatistics();
statistics.freeMemory = 2;
statistics.threadCount = 2;
statistics.socketListenerStats.sockets = 2;
@@ -274,8 +268,8 @@
statistics.processPoolStats.queued = 2;
return statistics;
- } else if (vmID.getID() == 3) {
- VMStatistics statistics = new VMStatistics();
+ } else if (processName.equals("process3")) { //$NON-NLS-1$
+ ProcessStatistics statistics = new ProcessStatistics();
statistics.freeMemory = 3;
statistics.threadCount = 3;
statistics.socketListenerStats.sockets = 3;
@@ -313,10 +307,6 @@
shutdownSystem = true;
}
- public void startDeployedService(ServiceComponentDefnID serviceID,
- VMControllerID vmID) throws MetaMatrixComponentException {
- }
-
public void startHost(String host) throws MetaMatrixComponentException {
startedHosts.add(host);
}
@@ -332,10 +322,10 @@
stoppedHosts.add(host);
}
- public void stopProcess(VMControllerID processID,
+ public void stopProcess(String hostName, String processName,
boolean stopNow) throws AuthorizationException,
MetaMatrixComponentException {
- stoppedProcesses.add(processID.toString());
+ stoppedProcesses.add(hostName+"|"+processName); //$NON-NLS-1$
}
public void stopService(ServiceID serviceID,
Modified: trunk/server/src/test/java/com/metamatrix/admin/server/FakeServerAdminImpl.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/admin/server/FakeServerAdminImpl.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/test/java/com/metamatrix/admin/server/FakeServerAdminImpl.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -37,7 +37,6 @@
import com.metamatrix.platform.security.api.service.SessionServiceInterface;
import com.metamatrix.platform.service.api.ServiceID;
import com.metamatrix.platform.service.api.exception.ServiceException;
-import com.metamatrix.platform.vm.controller.VMControllerID;
import com.metamatrix.server.query.service.QueryServiceInterface;
@@ -61,7 +60,7 @@
public FakeServerAdminImpl(ClusteredRegistryState registry) {
super(registry,null);
DQPWorkContext.setWorkContext(new DQPWorkContext());
- DQPWorkContext.getWorkContext().setSessionToken(new SessionToken(new MetaMatrixSessionID(1), "fakeadminuser"));
+ DQPWorkContext.getWorkContext().setSessionToken(new SessionToken(new MetaMatrixSessionID(1), "fakeadminuser")); //$NON-NLS-1$
}
public void close() {
@@ -90,7 +89,7 @@
protected synchronized QueryServiceInterface getQueryServiceProxy() throws ServiceException {
if (fqs == null) {
- fqs = new FakeQueryService(new ServiceID(1, new VMControllerID(2, "dummy"))); //$NON-NLS-1$
+ fqs = new FakeQueryService(new ServiceID(1, "dummy", "2")); //$NON-NLS-1$ //$NON-NLS-2$
}
return fqs;
}
Modified: trunk/server/src/test/java/com/metamatrix/admin/server/FakeServerSessionService.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/admin/server/FakeServerSessionService.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/test/java/com/metamatrix/admin/server/FakeServerSessionService.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -45,7 +45,6 @@
import com.metamatrix.platform.security.api.service.SessionServiceInterface;
import com.metamatrix.platform.service.api.ServiceID;
import com.metamatrix.platform.util.ProductInfoConstants;
-import com.metamatrix.platform.vm.controller.VMControllerID;
public class FakeServerSessionService implements SessionServiceInterface {
@@ -186,7 +185,7 @@
/**
* @see com.metamatrix.platform.service.api.ServiceInterface#getVMID()
*/
- public VMControllerID getVMID() {
+ public String getProcessName() {
return null;
}
Modified: trunk/server/src/test/java/com/metamatrix/admin/server/TestServerMonitoringAdminImpl.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/admin/server/TestServerMonitoringAdminImpl.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/test/java/com/metamatrix/admin/server/TestServerMonitoringAdminImpl.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -51,7 +51,6 @@
import com.metamatrix.platform.registry.ResourceNotBoundException;
import com.metamatrix.platform.registry.ServiceRegistryBinding;
import com.metamatrix.platform.service.api.ServiceID;
-import com.metamatrix.platform.vm.controller.VMControllerID;
/**
@@ -100,9 +99,8 @@
*/
public void testGetConnectorBindings() throws AdminException {
- VMControllerID vmId = new VMControllerID(3, "3.3.3.3"); //$NON-NLS-1$
try {
- ServiceRegistryBinding binding = admin.registry.getServiceBinding(vmId.getHostName(), vmId.toString(), new ServiceID(3,vmId));
+ ServiceRegistryBinding binding = admin.registry.getServiceBinding("3.3.3.3","3", new ServiceID(3, "3.3.3.3", "3")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
binding.updateState(ConnectorBinding.STATE_CLOSED);
} catch (ResourceNotBoundException e1) {
}
Modified: trunk/server/src/test/java/com/metamatrix/admin/server/TestServerRuntimeStateAdminImpl.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/admin/server/TestServerRuntimeStateAdminImpl.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/test/java/com/metamatrix/admin/server/TestServerRuntimeStateAdminImpl.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -35,7 +35,6 @@
import com.metamatrix.platform.registry.ResourceNotBoundException;
import com.metamatrix.platform.registry.ServiceRegistryBinding;
import com.metamatrix.platform.service.api.ServiceID;
-import com.metamatrix.platform.vm.controller.VMControllerID;
/**
@@ -189,15 +188,17 @@
//positive case
assertTrue(FakeRuntimeStateAdminAPIHelper.restartedServices.isEmpty());
- VMControllerID vmId = new VMControllerID(2, "2.2.2.2"); //$NON-NLS-1$
+ String host = "2.2.2.2"; //$NON-NLS-1$
+ String process = "process2"; //$NON-NLS-1$
+
try {
- ServiceRegistryBinding binding = admin.registry.getServiceBinding(vmId.getHostName(), vmId.toString(), new ServiceID(2,vmId));
+ ServiceRegistryBinding binding = admin.registry.getServiceBinding(host, process, new ServiceID(2,host,process));
binding.updateState(ConnectorBinding.STATE_CLOSED);
} catch (ResourceNotBoundException e1) {
}
admin.startConnectorBinding(AdminObject.WILDCARD + "connectorBinding2"); //$NON-NLS-1$
- assertTrue(FakeRuntimeStateAdminAPIHelper.restartedServices.contains("ServiceID<2> VMControllerID<2>:2.2.2.2")); //$NON-NLS-1$
+ assertTrue(FakeRuntimeStateAdminAPIHelper.restartedServices.contains("Service<2|2.2.2.2|process2>")); //$NON-NLS-1$
//failure case: unknown connectorBinding
@@ -281,7 +282,7 @@
assertTrue(FakeRuntimeStateAdminAPIHelper.stoppedServices.isEmpty());
admin.stopConnectorBinding(AdminObject.WILDCARD + "connectorBinding2", true); //$NON-NLS-1$
- assertTrue(FakeRuntimeStateAdminAPIHelper.stoppedServices.contains("ServiceID<2> VMControllerID<2>:2.2.2.2")); //$NON-NLS-1$
+ assertTrue(FakeRuntimeStateAdminAPIHelper.stoppedServices.contains("Service<2|2.2.2.2|process2>")); //$NON-NLS-1$
//failure case: unknown connectorBinding
@@ -336,7 +337,7 @@
assertTrue(FakeRuntimeStateAdminAPIHelper.stoppedProcesses.isEmpty());
admin.stopProcess(AdminObject.WILDCARD + "process2", true, false); //$NON-NLS-1$
- assertTrue(FakeRuntimeStateAdminAPIHelper.stoppedProcesses.contains("VMControllerID<2>:2.2.2.2")); //$NON-NLS-1$
+ assertTrue(FakeRuntimeStateAdminAPIHelper.stoppedProcesses.contains("2.2.2.2|process2")); //$NON-NLS-1$
//failure case: unknown process
Modified: trunk/server/src/test/java/com/metamatrix/platform/registry/FakeRegistryUtil.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/platform/registry/FakeRegistryUtil.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/test/java/com/metamatrix/platform/registry/FakeRegistryUtil.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -49,8 +49,7 @@
import com.metamatrix.common.messaging.NoOpMessageBus;
import com.metamatrix.platform.service.api.ServiceID;
import com.metamatrix.platform.service.api.ServiceState;
-import com.metamatrix.platform.vm.api.controller.VMControllerInterface;
-import com.metamatrix.platform.vm.controller.VMControllerID;
+import com.metamatrix.platform.vm.api.controller.ProcessManagement;
import com.metamatrix.server.query.service.QueryService;
@CacheListener
@@ -71,31 +70,31 @@
registry.addHost(host1);
registry.addHost(host2);
- VMRegistryBinding vmBinding2 = buildVMRegistryBinding("2.2.2.2", 2, "process2"); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessRegistryBinding vmBinding2 = buildVMRegistryBinding("2.2.2.2", "process2"); //$NON-NLS-1$ //$NON-NLS-2$
ServiceRegistryBinding serviceBinding2 = buildServiceRegistryBinding("connectorBinding2", 2, vmBinding2, "Cache","psc2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- registry.addVM(vmBinding2.getHostName(), vmBinding2.getVMControllerID().toString(), vmBinding2);
- registry.addServiceBinding(vmBinding2.getHostName(), vmBinding2.getVMControllerID().toString(), serviceBinding2);
+ registry.addProcess(vmBinding2.getHostName(), vmBinding2.getProcessName(), vmBinding2);
+ registry.addServiceBinding(vmBinding2.getHostName(), vmBinding2.getProcessName(), serviceBinding2);
- VMRegistryBinding vmBinding3 = buildVMRegistryBinding("3.3.3.3", 3, "process3"); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessRegistryBinding vmBinding3 = buildVMRegistryBinding("3.3.3.3", "process3"); //$NON-NLS-1$ //$NON-NLS-2$
ServiceRegistryBinding serviceBinding3 = buildServiceRegistryBinding("connectorBinding3", 3, vmBinding3, "Cache", "psc3"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- registry.addVM(vmBinding3.getHostName(), vmBinding3.getVMControllerID().toString(), vmBinding3);
- registry.addServiceBinding(vmBinding3.getHostName(), vmBinding3.getVMControllerID().toString(), serviceBinding3);
+ registry.addProcess(vmBinding3.getHostName(), vmBinding3.getProcessName(), vmBinding3);
+ registry.addServiceBinding(vmBinding3.getHostName(), vmBinding3.getProcessName(), serviceBinding3);
// dqps
- ServiceID sid1 = new ServiceID(5, vmBinding2.getVMControllerID());
- registry.addServiceBinding(vmBinding2.getHostName(), vmBinding2.getVMControllerID().toString(), new ServiceRegistryBinding(sid1, new FakeQueryService(sid1), QueryService.SERVICE_NAME,
+ ServiceID sid1 = new ServiceID(5, vmBinding2.getHostName(),vmBinding2.getProcessName());
+ registry.addServiceBinding(vmBinding2.getHostName(), vmBinding2.getProcessName(), new ServiceRegistryBinding(sid1, new FakeQueryService(sid1), QueryService.SERVICE_NAME,
"dqp2", "QueryService", //$NON-NLS-1$ //$NON-NLS-2$
"dqp2", "2.2.2.2",(DeployedComponent)new FakeConfiguration().deployedComponents.get(4), null, //$NON-NLS-1$ //$NON-NLS-2$
ServiceState.STATE_CLOSED,
new Date(),
false, new NoOpMessageBus()));
- ServiceID sid2 = new ServiceID(6, vmBinding3.getVMControllerID());
- registry.addServiceBinding(vmBinding3.getHostName(), vmBinding3.getVMControllerID().toString(), new ServiceRegistryBinding(sid2, new FakeQueryService(sid2), QueryService.SERVICE_NAME,
+ ServiceID sid2 = new ServiceID(6, vmBinding3.getHostName(),vmBinding3.getProcessName());
+ registry.addServiceBinding(vmBinding3.getHostName(), vmBinding3.getProcessName(), new ServiceRegistryBinding(sid2, new FakeQueryService(sid2), QueryService.SERVICE_NAME,
"dqp3", "QueryService", //$NON-NLS-1$ //$NON-NLS-2$
"dqp3", "3.3.3.3", (DeployedComponent)new FakeConfiguration().deployedComponents.get(5), null, //$NON-NLS-1$ //$NON-NLS-2$
ServiceState.STATE_CLOSED,
@@ -107,22 +106,21 @@
}
- public static VMRegistryBinding buildVMRegistryBinding(String hostName, int vmID, String process) throws Exception {
- VMControllerID vmID1 = new VMControllerID(vmID, hostName);
+ public static ProcessRegistryBinding buildVMRegistryBinding(String hostName, String processName) throws Exception {
HostID hostID1 = new HostID(hostName);
- VMComponentDefnID defnID1 = new VMComponentDefnID(Configuration.NEXT_STARTUP_ID, hostID1, process);
+ VMComponentDefnID defnID1 = new VMComponentDefnID(Configuration.NEXT_STARTUP_ID, hostID1, processName);
VMComponentDefn defn1 = new BasicVMComponentDefn(Configuration.NEXT_STARTUP_ID, hostID1, defnID1, new ComponentTypeID(VMComponentDefnType.COMPONENT_TYPE_NAME));
- VMControllerInterface vmInterface1 = Mockito.mock(VMControllerInterface.class);
+ ProcessManagement vmInterface1 = Mockito.mock(ProcessManagement.class);
Mockito.stub(vmInterface1.getAddress()).toReturn(InetAddress.getLocalHost());
- VMRegistryBinding binding = new VMRegistryBinding(hostName, vmID1, defn1, vmInterface1, new NoOpMessageBus());
+ ProcessRegistryBinding binding = new ProcessRegistryBinding(hostName, processName, defn1, vmInterface1, new NoOpMessageBus());
binding.setAlive(true);
return binding;
}
- public static ServiceRegistryBinding buildServiceRegistryBinding(String name, int id, VMRegistryBinding vm, String type, String psc) {
- ServiceID sid = new ServiceID(id, vm.getVMControllerID());
+ public static ServiceRegistryBinding buildServiceRegistryBinding(String name, int id, ProcessRegistryBinding vm, String type, String psc) {
+ ServiceID sid = new ServiceID(id, vm.getHostName(), vm.getProcessName());
DeployedComponentID deployedComponentID1 = new DeployedComponentID(name, Configuration.NEXT_STARTUP_ID, vm.getDeployedComponent().getHostID(), (VMComponentDefnID)vm.getDeployedComponent().getID());
ConnectorBindingID connectorBindingID1 = new ConnectorBindingID(Configuration.NEXT_STARTUP_ID, name);
Modified: trunk/server/src/test/java/com/metamatrix/platform/registry/TestClusteredRegistryState.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/platform/registry/TestClusteredRegistryState.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/test/java/com/metamatrix/platform/registry/TestClusteredRegistryState.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -43,8 +43,7 @@
import com.metamatrix.platform.registry.ClusteredRegistryState.CacheNodeNotFoundException;
import com.metamatrix.platform.service.api.ServiceID;
import com.metamatrix.platform.service.api.ServiceState;
-import com.metamatrix.platform.vm.api.controller.VMControllerInterface;
-import com.metamatrix.platform.vm.controller.VMControllerID;
+import com.metamatrix.platform.vm.api.controller.ProcessManagement;
public class TestClusteredRegistryState extends TestCase {
CacheFactory factory = new FakeCacheFactory();
@@ -62,13 +61,13 @@
state.addHost(host1);
state.addHost(host2);
- VMRegistryBinding vm1 = buildVMRegistryBinding("host-1", 1); //$NON-NLS-1$
- VMRegistryBinding vm2 = buildVMRegistryBinding("host-1", 2); //$NON-NLS-1$
- VMRegistryBinding vm3 = buildVMRegistryBinding("host-1", 3); //$NON-NLS-1$
+ ProcessRegistryBinding vm1 = buildVMRegistryBinding("host-1", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessRegistryBinding vm2 = buildVMRegistryBinding("host-1", "2"); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessRegistryBinding vm3 = buildVMRegistryBinding("host-1", "3"); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-1", "vm-1", vm1); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-1", "vm-2", vm2); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-2", "vm-1", vm3); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-1", "vm-1", vm1); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-1", "vm-2", vm2); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-2", "vm-1", vm3); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals(rootNode.getChildren().size(), 2);
assertNotNull(rootNode.getChild(key("host-1"))); //$NON-NLS-1$
@@ -88,17 +87,17 @@
state.addHost(host1);
state.addHost(host2);
- VMRegistryBinding vm1 = buildVMRegistryBinding("host-1", 1); //$NON-NLS-1$
- VMRegistryBinding vm2 = buildVMRegistryBinding("host-1", 2); //$NON-NLS-1$
- VMRegistryBinding vm3 = buildVMRegistryBinding("host-1", 3); //$NON-NLS-1$
+ ProcessRegistryBinding vm1 = buildVMRegistryBinding("host-1", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessRegistryBinding vm2 = buildVMRegistryBinding("host-1", "2"); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessRegistryBinding vm3 = buildVMRegistryBinding("host-1", "3"); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-1", "vm-1", vm1); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-1", "vm-2", vm2); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-2", "vm-1", vm3); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-1", "vm-1", vm1); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-1", "vm-2", vm2); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-2", "vm-1", vm3); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals(rootNode.getChildren().size(), 2);
- state.removeVM("host-1", "vm-1"); //$NON-NLS-1$ //$NON-NLS-2$
+ state.removeProcess("host-1", "vm-1"); //$NON-NLS-1$ //$NON-NLS-2$
assertNull(rootNode.getChild(key("host-1")).getChild(key("vm-1"))); //$NON-NLS-1$ //$NON-NLS-2$
assertNotNull(rootNode.getChild(key("host-1")).getChild(key("vm-2"))); //$NON-NLS-1$ //$NON-NLS-2$
@@ -113,20 +112,20 @@
state.addHost(host1);
state.addHost(host2);
- VMRegistryBinding vm1 = buildVMRegistryBinding("host-1", 1); //$NON-NLS-1$
- VMRegistryBinding vm2 = buildVMRegistryBinding("host-1", 2); //$NON-NLS-1$
- VMRegistryBinding vm3 = buildVMRegistryBinding("host-1", 3); //$NON-NLS-1$
+ ProcessRegistryBinding vm1 = buildVMRegistryBinding("host-1", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessRegistryBinding vm2 = buildVMRegistryBinding("host-1", "2"); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessRegistryBinding vm3 = buildVMRegistryBinding("host-1", "3"); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-1", "vm-1", vm1); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-1", "vm-2", vm2); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-2", "vm-1", vm3); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-1", "vm-1", vm1); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-1", "vm-2", vm2); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-2", "vm-1", vm3); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals(0, state.getVMs("unknown").size()); //$NON-NLS-1$
assertEquals(2, state.getVMs("host-1").size()); //$NON-NLS-1$
assertEquals(1, state.getVMs("host-2").size()); //$NON-NLS-1$
assertEquals(3, state.getVMs(null).size());
- assertEquals(vm2, state.getVM("host-1", "vm-2")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(vm2, state.getProcessBinding("host-1", "vm-2")); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testHosts() throws Exception {
@@ -137,13 +136,13 @@
state.addHost(host1);
state.addHost(host2);
- VMRegistryBinding vm1 = buildVMRegistryBinding("host-1", 1); //$NON-NLS-1$
- VMRegistryBinding vm2 = buildVMRegistryBinding("host-1", 2); //$NON-NLS-1$
- VMRegistryBinding vm3 = buildVMRegistryBinding("host-1", 3); //$NON-NLS-1$
+ ProcessRegistryBinding vm1 = buildVMRegistryBinding("host-1", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessRegistryBinding vm2 = buildVMRegistryBinding("host-1", "2"); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessRegistryBinding vm3 = buildVMRegistryBinding("host-1", "3"); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-1", "vm-1", vm1); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-1", "vm-2", vm2); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-2", "vm-1", vm3); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-1", "vm-1", vm1); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-1", "vm-2", vm2); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-2", "vm-1", vm3); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals(2, state.getHosts().size());
@@ -168,20 +167,20 @@
state.addHost(host1);
state.addHost(host2);
- VMRegistryBinding vm1 = buildVMRegistryBinding("host-1", 1); //$NON-NLS-1$
- VMRegistryBinding vm2 = buildVMRegistryBinding("host-1", 2); //$NON-NLS-1$
- VMRegistryBinding vm3 = buildVMRegistryBinding("host-1", 3); //$NON-NLS-1$
+ ProcessRegistryBinding vm1 = buildVMRegistryBinding("host-1", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessRegistryBinding vm2 = buildVMRegistryBinding("host-1", "2"); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessRegistryBinding vm3 = buildVMRegistryBinding("host-1", "3"); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-1", "vm-1", vm1); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-1", "vm-2", vm2); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-2", "vm-1", vm3); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-1", "vm-1", vm1); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-1", "vm-2", vm2); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-2", "vm-1", vm3); //$NON-NLS-1$ //$NON-NLS-2$
- ServiceRegistryBinding s1 = buildServiceRegistryBinding(1, vm1.getVMControllerID(), "Query"); //$NON-NLS-1$
- ServiceRegistryBinding s2 = buildServiceRegistryBinding(2, vm2.getVMControllerID(), "Query"); //$NON-NLS-1$
- ServiceRegistryBinding s3 = buildServiceRegistryBinding(3, vm1.getVMControllerID(), "Index"); //$NON-NLS-1$
- ServiceRegistryBinding s4 = buildServiceRegistryBinding(4, vm3.getVMControllerID(), "Query"); //$NON-NLS-1$
- ServiceRegistryBinding s5 = buildServiceRegistryBinding(5, vm3.getVMControllerID(), "Session"); //$NON-NLS-1$
- ServiceRegistryBinding s6 = buildServiceRegistryBinding(6, vm3.getVMControllerID(), "Auth"); //$NON-NLS-1$
+ ServiceRegistryBinding s1 = buildServiceRegistryBinding(1, vm1, "Query"); //$NON-NLS-1$
+ ServiceRegistryBinding s2 = buildServiceRegistryBinding(2, vm2, "Query"); //$NON-NLS-1$
+ ServiceRegistryBinding s3 = buildServiceRegistryBinding(3, vm1, "Index"); //$NON-NLS-1$
+ ServiceRegistryBinding s4 = buildServiceRegistryBinding(4, vm3, "Query"); //$NON-NLS-1$
+ ServiceRegistryBinding s5 = buildServiceRegistryBinding(5, vm3, "Session"); //$NON-NLS-1$
+ ServiceRegistryBinding s6 = buildServiceRegistryBinding(6, vm3, "Auth"); //$NON-NLS-1$
state.addServiceBinding("host-1", "vm-1", s1); //$NON-NLS-1$ //$NON-NLS-2$
state.addServiceBinding("host-1", "vm-1", s3); //$NON-NLS-1$ //$NON-NLS-2$
@@ -225,20 +224,20 @@
state.addHost(host1);
state.addHost(host2);
- VMRegistryBinding vm1 = buildVMRegistryBinding("host-1", 1); //$NON-NLS-1$
- VMRegistryBinding vm2 = buildVMRegistryBinding("host-1", 2); //$NON-NLS-1$
- VMRegistryBinding vm3 = buildVMRegistryBinding("host-1", 3); //$NON-NLS-1$
+ ProcessRegistryBinding vm1 = buildVMRegistryBinding("host-1", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessRegistryBinding vm2 = buildVMRegistryBinding("host-1", "2"); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessRegistryBinding vm3 = buildVMRegistryBinding("host-1", "3"); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-1", "vm-1", vm1); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-1", "vm-2", vm2); //$NON-NLS-1$ //$NON-NLS-2$
- state.addVM("host-2", "vm-1", vm3); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-1", "vm-1", vm1); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-1", "vm-2", vm2); //$NON-NLS-1$ //$NON-NLS-2$
+ state.addProcess("host-2", "vm-1", vm3); //$NON-NLS-1$ //$NON-NLS-2$
- ServiceRegistryBinding s1 = buildServiceRegistryBinding(1, vm1.getVMControllerID(), "Query"); //$NON-NLS-1$
- ServiceRegistryBinding s2 = buildServiceRegistryBinding(2, vm2.getVMControllerID(), "Query"); //$NON-NLS-1$
- ServiceRegistryBinding s3 = buildServiceRegistryBinding(3, vm1.getVMControllerID(), "Index"); //$NON-NLS-1$
- ServiceRegistryBinding s4 = buildServiceRegistryBinding(4, vm3.getVMControllerID(), "Query"); //$NON-NLS-1$
- ServiceRegistryBinding s5 = buildServiceRegistryBinding(5, vm3.getVMControllerID(), "Session"); //$NON-NLS-1$
- ServiceRegistryBinding s6 = buildServiceRegistryBinding(6, vm3.getVMControllerID(), "Auth"); //$NON-NLS-1$
+ ServiceRegistryBinding s1 = buildServiceRegistryBinding(1, vm1, "Query"); //$NON-NLS-1$
+ ServiceRegistryBinding s2 = buildServiceRegistryBinding(2, vm2, "Query"); //$NON-NLS-1$
+ ServiceRegistryBinding s3 = buildServiceRegistryBinding(3, vm1, "Index"); //$NON-NLS-1$
+ ServiceRegistryBinding s4 = buildServiceRegistryBinding(4, vm3, "Query"); //$NON-NLS-1$
+ ServiceRegistryBinding s5 = buildServiceRegistryBinding(5, vm3, "Session"); //$NON-NLS-1$
+ ServiceRegistryBinding s6 = buildServiceRegistryBinding(6, vm3, "Auth"); //$NON-NLS-1$
state.addServiceBinding("host-1", "vm-1", s1); //$NON-NLS-1$ //$NON-NLS-2$
state.addServiceBinding("host-1", "vm-1", s3); //$NON-NLS-1$ //$NON-NLS-2$
@@ -291,21 +290,20 @@
}
- static VMRegistryBinding buildVMRegistryBinding(String hostName, int vmID) {
- VMControllerID vmID1 = new VMControllerID(vmID, hostName);
+ static ProcessRegistryBinding buildVMRegistryBinding(String hostName, String vmID) {
HostID hostID1 = new HostID(hostName);
VMComponentDefnID defnID1 = new VMComponentDefnID(Configuration.NEXT_STARTUP_ID, hostID1, "process1"); //$NON-NLS-1$
VMComponentDefn defn1 = new BasicVMComponentDefn(Configuration.NEXT_STARTUP_ID, hostID1, defnID1, new ComponentTypeID(VMComponentDefnType.COMPONENT_TYPE_NAME));
- VMControllerInterface vmInterface1 = SimpleMock.createSimpleMock(VMControllerInterface.class);
- VMRegistryBinding binding = new VMRegistryBinding(hostName, vmID1, defn1,vmInterface1, new NoOpMessageBus());
+ ProcessManagement vmInterface1 = SimpleMock.createSimpleMock(ProcessManagement.class);
+ ProcessRegistryBinding binding = new ProcessRegistryBinding(hostName, vmID, defn1,vmInterface1, new NoOpMessageBus());
binding.setAlive(true);
return binding;
}
- static ServiceRegistryBinding buildServiceRegistryBinding(int id, VMControllerID vmId, String type) {
- ServiceID sid = new ServiceID(id, vmId);
+ static ServiceRegistryBinding buildServiceRegistryBinding(int id, ProcessRegistryBinding process, String type) {
+ ServiceID sid = new ServiceID(id, process.getHostName(), process.getProcessName());
//ServiceInterface si = SimpleMock.createSimpleMock(ServiceInterface.class);
- return new ServiceRegistryBinding(sid, null, type,"instance-"+id, null,"deployed-"+id, vmId.getHostName(), null, null, ServiceState.STATE_OPEN,new Date(), false, new NoOpMessageBus()); //$NON-NLS-1$ //$NON-NLS-2$
+ return new ServiceRegistryBinding(sid, null, type,"instance-"+id, null,"deployed-"+id, process.getHostName(), null, null, ServiceState.STATE_OPEN,new Date(), false, new NoOpMessageBus()); //$NON-NLS-1$ //$NON-NLS-2$
}
static HostControllerRegistryBinding buildHostRegistryBinding(String name) {
Modified: trunk/server/src/test/java/com/metamatrix/platform/registry/TestServiceRegistryBinding.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/platform/registry/TestServiceRegistryBinding.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/test/java/com/metamatrix/platform/registry/TestServiceRegistryBinding.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -76,8 +76,8 @@
System.setProperty(MessageBusConstants.MESSAGE_BUS_TYPE, MessageBusConstants.TYPE_NOOP);
FakeServiceImpl service = new FakeServiceImpl();
- VMRegistryBinding vmBinding2 = FakeRegistryUtil.buildVMRegistryBinding("2.2.2.2", 2, "process2"); //$NON-NLS-1$ //$NON-NLS-2$
- ServiceID sid1 = new ServiceID(5, vmBinding2.getVMControllerID());
+ ProcessRegistryBinding vmBinding2 = FakeRegistryUtil.buildVMRegistryBinding("2.2.2.2", "process2"); //$NON-NLS-1$ //$NON-NLS-2$
+ ServiceID sid1 = new ServiceID(5, vmBinding2.getHostName(), vmBinding2.getProcessName());
ServiceRegistryBinding binding = new ServiceRegistryBinding(sid1, service, QueryService.SERVICE_NAME,
"dqp2", "QueryService", //$NON-NLS-1$ //$NON-NLS-2$
"dqp2", "2.2.2.2",(DeployedComponent)new FakeConfiguration().deployedComponents.get(4), null, //$NON-NLS-1$ //$NON-NLS-2$
Modified: trunk/server/src/test/java/com/metamatrix/platform/service/controller/FakeService.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/platform/service/controller/FakeService.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/test/java/com/metamatrix/platform/service/controller/FakeService.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -32,7 +32,6 @@
import com.metamatrix.common.config.api.DeployedComponentID;
import com.metamatrix.common.queue.WorkerPoolStats;
import com.metamatrix.platform.service.api.ServiceID;
-import com.metamatrix.platform.vm.controller.VMControllerID;
public class FakeService implements FakeServiceInterface {
@@ -71,7 +70,7 @@
public Date getStateChangeTime() {
return null;
}
- public VMControllerID getVMID() {
+ public String getProcessName() {
return null;
}
public boolean isAlive() {
Modified: trunk/server/src/test/java/com/metamatrix/platform/service/proxy/TestProxies.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/platform/service/proxy/TestProxies.java 2009-03-03 23:48:40 UTC (rev 536)
+++ trunk/server/src/test/java/com/metamatrix/platform/service/proxy/TestProxies.java 2009-03-04 23:29:07 UTC (rev 537)
@@ -36,7 +36,7 @@
import com.metamatrix.common.messaging.NoOpMessageBus;
import com.metamatrix.platform.registry.FakeRegistryUtil;
import com.metamatrix.platform.registry.ServiceRegistryBinding;
-import com.metamatrix.platform.registry.VMRegistryBinding;
+import com.metamatrix.platform.registry.ProcessRegistryBinding;
import com.metamatrix.platform.service.api.ServiceID;
import com.metamatrix.platform.service.api.ServiceState;
import com.metamatrix.platform.service.api.exception.ServiceNotFoundException;
@@ -76,8 +76,6 @@
@Override
public void updateServices(List<ServiceRegistryBinding> localServices,
List<ServiceRegistryBinding> remoteServices) {
- // rameshTODO Auto-generated method stub
-
}
}
@@ -92,8 +90,8 @@
final List serviceBindings = new ArrayList();
for (int i = 0; i < fakeServices.length; i++) {
- VMRegistryBinding vmBinding2 = FakeRegistryUtil.buildVMRegistryBinding("2.2.2.2", 2, "process2"); //$NON-NLS-1$ //$NON-NLS-2$
- ServiceID sid1 = new ServiceID(i, vmBinding2.getVMControllerID());
+ ProcessRegistryBinding vmBinding2 = FakeRegistryUtil.buildVMRegistryBinding("2.2.2.2", "process2"); //$NON-NLS-1$ //$NON-NLS-2$
+ ServiceID sid1 = new ServiceID(i, vmBinding2.getHostName(), vmBinding2.getProcessName());
ServiceRegistryBinding binding = new ServiceRegistryBinding(sid1, fakeServices[i], QueryService.SERVICE_NAME,
"dqp2", "QueryService", //$NON-NLS-1$ //$NON-NLS-2$
"dqp2", "2.2.2.2",(DeployedComponent)new FakeConfiguration().deployedComponents.get(4), null, //$NON-NLS-1$ //$NON-NLS-2$
@@ -146,8 +144,8 @@
for (int i = 0; i < fakeServices.length; i++) {
- VMRegistryBinding vmBinding2 = FakeRegistryUtil.buildVMRegistryBinding("2.2.2.2", 2, "process2"); //$NON-NLS-1$ //$NON-NLS-2$
- ServiceID sid1 = new ServiceID(i, vmBinding2.getVMControllerID());
+ ProcessRegistryBinding vmBinding2 = FakeRegistryUtil.buildVMRegistryBinding("2.2.2.2", "process2"); //$NON-NLS-1$ //$NON-NLS-2$
+ ServiceID sid1 = new ServiceID(i, vmBinding2.getHostName(), vmBinding2.getProcessName());
ServiceRegistryBinding binding = new ServiceRegistryBinding(sid1, fakeServices[i], QueryService.SERVICE_NAME,
"dqp2", "QueryService", //$NON-NLS-1$ //$NON-NLS-2$
"dqp2", "2.2.2.2",(DeployedComponent)new FakeConfiguration().deployedComponents.get(4), null, //$NON-NLS-1$ //$NON-NLS-2$
16 years, 7 months
teiid SVN: r536 - in trunk: server/src/main/java/com/metamatrix/platform/admin/apiimpl and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2009-03-03 18:48:40 -0500 (Tue, 03 Mar 2009)
New Revision: 536
Modified:
trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/RuntimeStateAdminAPI.java
trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIImpl.java
Log:
TEIID-394
Modified: trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/RuntimeStateAdminAPI.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/RuntimeStateAdminAPI.java 2009-03-03 23:23:06 UTC (rev 535)
+++ trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/RuntimeStateAdminAPI.java 2009-03-03 23:48:40 UTC (rev 536)
@@ -31,7 +31,6 @@
import com.metamatrix.api.exception.MultipleException;
import com.metamatrix.api.exception.security.AuthorizationException;
import com.metamatrix.common.config.api.Configuration;
-import com.metamatrix.common.config.api.ServiceComponentDefnID;
import com.metamatrix.common.log.LogConfiguration;
import com.metamatrix.common.queue.WorkerPoolStats;
import com.metamatrix.platform.admin.api.runtime.PscID;
@@ -247,25 +246,6 @@
MetaMatrixComponentException;
/**
- * Start a deployed service.
- *
- * @param id
- * ServiceComponentDefnID of service instance.
- * @param vmID
- * Identifies VMController to start service in.
- * @throws AuthorizationException
- * if caller is not authorized to perform this method.
- * @throws InvalidSessionException
- * if the <code>callerSessionID</code> is not valid or is expired.
- * @throws MetaMatrixComponentException
- * if an error occurred in communicating with a component.
- */
- void startDeployedService(ServiceComponentDefnID id,
- VMControllerID vmID) throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException;
-
- /**
* Start up all processes and services for the host.
*
* @param host
Modified: trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIImpl.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIImpl.java 2009-03-03 23:23:06 UTC (rev 535)
+++ trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIImpl.java 2009-03-03 23:48:40 UTC (rev 536)
@@ -446,37 +446,6 @@
}
/**
- * Start a deployed service.
- *
- * @param id
- * ServiceComponentDefnID of service instance.
- * @param vmID
- * Identifies VMController to start service in.
- * @throws AuthorizationException
- * if caller is not authorized to perform this method.
- * @throws InvalidSessionException
- * if the <code>callerSessionID</code> is not valid or is expired.
- * @throws MetaMatrixComponentException
- * if an error occurred in communicating with a component.
- */
- public synchronized void startDeployedService(ServiceComponentDefnID serviceID,
- VMControllerID vmID) throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException {
-
- // Validate caller's session
- SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0019, new Object[] {
- serviceID
- });
-
- // Validate caller's role
- AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.startDeployedService(" + serviceID + ", " + vmID + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- helper.startDeployedService(serviceID, vmID);
- }
-
- /**
* Start Host and all processes/services for host.
*
* @param host
16 years, 7 months
teiid SVN: r535 - in trunk: console/src/main/java/com/metamatrix/console/ui/views/runtime and 6 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2009-03-03 18:23:06 -0500 (Tue, 03 Mar 2009)
New Revision: 535
Modified:
trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/RuntimeStateAdminAPI.java
trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/QueueStatisticsRefreshRequestHandlerImp.java
trunk/server/src/main/java/com/metamatrix/admin/server/AbstractAdminImpl.java
trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SocketVMController.java
trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIHelper.java
trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIImpl.java
trunk/server/src/main/java/com/metamatrix/platform/vm/api/controller/VMControllerInterface.java
trunk/server/src/main/java/com/metamatrix/platform/vm/controller/VMController.java
trunk/server/src/main/java/com/metamatrix/server/HostController.java
trunk/server/src/main/java/com/metamatrix/server/Main.java
trunk/server/src/main/java/com/metamatrix/server/ServiceManager.java
Log:
TEIID-394: removed verbose methods on the VMControllerInterface. Functionality wise we only lost runGC, but that be done using jmx bean
Modified: trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/RuntimeStateAdminAPI.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/RuntimeStateAdminAPI.java 2009-03-03 23:05:42 UTC (rev 534)
+++ trunk/common-internal/src/main/java/com/metamatrix/platform/admin/api/RuntimeStateAdminAPI.java 2009-03-03 23:23:06 UTC (rev 535)
@@ -182,43 +182,8 @@
InvalidSessionException,
MetaMatrixComponentException;
- /**
- * Stop all services, in a process, once work is complete.
- *
- * @param callerSessionID
- * ID of the caller's current session.
- * @param serviceID
- * ID of service instance.
- * @throws AuthorizationException
- * if caller is not authorized to perform this method.
- * @throws InvalidSessionException
- * if the <code>callerSessionID</code> is not valid or is expired.
- * @throws MetaMatrixComponentException
- * if an error occurred in communicating with a component.
- */
- void stopAllServicesInAProcess(VMControllerID processID) throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException;
/**
- * Stop all services, in a process, now.
- *
- * @param callerSessionID
- * ID of the caller's current session.
- * @param serviceID
- * ID of service instance.
- * @throws AuthorizationException
- * if caller is not authorized to perform this method.
- * @throws InvalidSessionException
- * if the <code>callerSessionID</code> is not valid or is expired.
- * @throws MetaMatrixComponentException
- * if an error occurred in communicating with a component.
- */
- void stopAllServicesInAProcessNow(VMControllerID processID) throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException;
-
- /**
* Gracefully shutdown server waiting for work to complete.
*
* @param callerSessionID
@@ -549,22 +514,6 @@
MetaMatrixComponentException;
/**
- * Run Garbage collection on process.
- *
- * @param VMControllerID
- * ID of the process.
- * @throws AuthorizationException
- * if caller is not authorized to perform this method.
- * @throws InvalidSessionException
- * if the <code>callerSessionID</code> is not valid or is expired.
- * @throws MetaMatrixComponentException
- * if an error occurred in communicating with a component.
- */
- void runGC(VMControllerID vmID) throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException;
-
- /**
* Return the PscID by Name
*
* @param hostName
Modified: trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/QueueStatisticsRefreshRequestHandlerImp.java
===================================================================
--- trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/QueueStatisticsRefreshRequestHandlerImp.java 2009-03-03 23:05:42 UTC (rev 534)
+++ trunk/console/src/main/java/com/metamatrix/console/ui/views/runtime/QueueStatisticsRefreshRequestHandlerImp.java 2009-03-03 23:23:06 UTC (rev 535)
@@ -92,13 +92,7 @@
}
public void runGarbageCollection(ProcessData pd) {
- try {
- //api = getAdminAPI();
- VMControllerID cntrlrID = pd.getProcessID();
- getAdminAPI().runGC(cntrlrID);
- } catch (Exception theException) {
- displayException(theException, "QueueStatisticsRefreshRequestHandlerImp.runGarbageCollection"); //$NON-NLS-1$
- }
+ // we no longer support this.
}
private RuntimeStateAdminAPI getAdminAPI() {
Modified: trunk/server/src/main/java/com/metamatrix/admin/server/AbstractAdminImpl.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/admin/server/AbstractAdminImpl.java 2009-03-03 23:05:42 UTC (rev 534)
+++ trunk/server/src/main/java/com/metamatrix/admin/server/AbstractAdminImpl.java 2009-03-03 23:23:06 UTC (rev 535)
@@ -417,11 +417,7 @@
try {
VMControllerInterface vmController = getVMControllerInterface(serviceID.getVMControllerID());
- if (stopNow) {
- vmController.shutdownServiceNow(serviceID);
- } else {
- vmController.shutdownService(serviceID);
- }
+ vmController.stopService(serviceID, stopNow, true);
} catch (MetaMatrixComponentException e) {
throw new AdminComponentException(e);
}
Modified: trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SocketVMController.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SocketVMController.java 2009-03-03 23:05:42 UTC (rev 534)
+++ trunk/server/src/main/java/com/metamatrix/common/comm/platform/socket/SocketVMController.java 2009-03-03 23:23:06 UTC (rev 535)
@@ -81,8 +81,9 @@
super(host, vmName, vmId, registry, serverEvents, bus, hostManagement);
}
- public void startVM() {
- super.startVM();
+ @Override
+ public void start() {
+ super.start();
waitForServices();
@@ -92,7 +93,8 @@
// extend the VMController method to close the socket at the start of the stop process
// so that the port can be made available sooner on bounces.
- protected void doStopVM(boolean now, boolean shutdown) {
+ @Override
+ public void shutdown(boolean now) {
if (workerPool != null) {
try {
workerPool.shutdownNow();
@@ -113,9 +115,9 @@
listener = null;
}
}
-
- super.doStopVM(now, shutdown);
+ // call the base class.
+ super.shutdown(now);
}
/**
Modified: trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIHelper.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIHelper.java 2009-03-03 23:05:42 UTC (rev 534)
+++ trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIHelper.java 2009-03-03 23:23:06 UTC (rev 535)
@@ -401,7 +401,7 @@
// if not deployed but running then kill, kill, kill
if (!sData.isDeployed() && sData.isRegistered()) {
try {
- vmController.shutdownService(sData.getServiceID());
+ vmController.stopService(sData.getServiceID(), false, true);
} catch (Exception e) {
exceptions.add(e);
}
@@ -487,7 +487,7 @@
VMControllerInterface vmController = vmBinding.getVMController();
try {
- vmController.stopService(serviceID);
+ vmController.stopService(serviceID, false, false);
} catch (ServiceException se) {
LogManager.logDetail(LogPlatformConstants.CTX_RUNTIME_ADMIN, se, "Service exception stopping service during restart"); //$NON-NLS-1$
}
@@ -573,11 +573,7 @@
VMRegistryBinding binding = registry.getVM(vmID.getHostName(), vmID.toString());
VMControllerInterface vmController = binding.getVMController();
try {
- if (stopNow) {
- vmController.stopServiceNow(serviceID);
- } else {
- vmController.stopService(serviceID);
- }
+ vmController.stopService(serviceID, stopNow, false);
} catch (ServiceException se) {
throw new MetaMatrixComponentException(se);
}
Modified: trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIImpl.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIImpl.java 2009-03-03 23:05:42 UTC (rev 534)
+++ trunk/server/src/main/java/com/metamatrix/platform/admin/apiimpl/RuntimeStateAdminAPIImpl.java 2009-03-03 23:23:06 UTC (rev 535)
@@ -364,76 +364,6 @@
/**
- * Stop all services, in a process, once work is complete.
- *
- * @param serviceID
- * ID of service instance.
- * @throws AuthorizationException
- * if caller is not authorized to perform this method.
- * @throws InvalidSessionException
- * if the <code>callerSessionID</code> is not valid or is expired.
- * @throws MetaMatrixComponentException
- * if an error occurred in communicating with a component.
- */
- public synchronized void stopAllServicesInAProcess(VMControllerID processID) throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException {
-
- // Validate caller's session
- SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0013, new Object[] {
- processID, token.getUsername()
- });
-
- // Validate caller's role
- AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.stopAllServicesInAProcess(" + processID + ")"); //$NON-NLS-1$ //$NON-NLS-2$
-
- VMControllerInterface vmController = helper.getVMControllerInterface(processID);
- try {
- vmController.stopAllServices();
- } catch (ServiceException se) {
- throw new MetaMatrixComponentException(se);
- } catch (MultipleException se) {
- throw new MetaMatrixComponentException(se);
- }
- }
-
- /**
- * Stop all services, in a process, now.
- *
- * @param serviceID
- * ID of service instance.
- * @throws AuthorizationException
- * if caller is not authorized to perform this method.
- * @throws InvalidSessionException
- * if the <code>callerSessionID</code> is not valid or is expired.
- * @throws MetaMatrixComponentException
- * if an error occurred in communicating with a component.
- */
- public synchronized void stopAllServicesInAProcessNow(VMControllerID processID) throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException {
-
- // Validate caller's session
- SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- I18nLogManager.logInfo(LogPlatformConstants.CTX_RUNTIME_ADMIN, LogMessageKeys.ADMIN_0014, new Object[] {
- processID, token.getUsername()
- });
-
- // Validate caller's role
- AdminAPIHelper.checkForRequiredRole(token, AdminRoles.RoleName.ADMIN_PRODUCT, "RuntimeStateAdminAPIImpl.stopAllServicesInAProcessNow(" + processID + ")"); //$NON-NLS-1$ //$NON-NLS-2$
-
- VMControllerInterface vmController = helper.getVMControllerInterface(processID);
- try {
- vmController.stopAllServicesNow();
- } catch (ServiceException se) {
- throw new MetaMatrixComponentException(se);
- } catch (MultipleException me) {
- throw new MetaMatrixComponentException(me);
- }
- }
-
- /**
* Gracefully shutdown server waiting for work to complete.
*
* @throws AuthorizationException
@@ -807,11 +737,7 @@
try {
ServiceID serviceID = serviceData.getServiceID();
if (serviceID != null) {
- if (now) {
- vm.stopServiceNow(serviceID);
- } else {
- vm.stopService(serviceID);
- }
+ vm.stopService(serviceID, now, false);
}
} catch (ServiceException se) {
exceptions.add(se);
@@ -1037,31 +963,6 @@
}
/**
- * Run Garbage Collection on Process.
- *
- * @param VMControllerID
- * ID of the process.
- * @throws AuthorizationException
- * if caller is not authorized to perform this method.
- * @throws InvalidSessionException
- * if the <code>callerSessionID</code> is not valid or is expired.
- * @throws MetaMatrixComponentException
- * if an error occurred in communicating with a component.
- */
- public synchronized void runGC(VMControllerID vmID) throws AuthorizationException,
- InvalidSessionException,
- MetaMatrixComponentException {
-
- // Validate caller's session
- SessionToken token = AdminAPIHelper.validateSession(getSessionID());
- LogManager.logDetail(LogPlatformConstants.CTX_RUNTIME_ADMIN, "Running GarbageCollector on " + vmID + " user = " + token.getUsername()); //$NON-NLS-1$ //$NON-NLS-2$
-
- // Any administrator may call this read-only method - no need to validate role
- VMControllerInterface vm = helper.getVMControllerInterface(vmID);
- vm.runGC();
- }
-
- /**
* @see com.metamatrix.platform.admin.apiimpl.RuntimeStateAdminAPI#getServiceIDByName(java.lang.String,
* java.lang.String, java.lang.String)
* @since 4.2.1
Modified: trunk/server/src/main/java/com/metamatrix/platform/vm/api/controller/VMControllerInterface.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/vm/api/controller/VMControllerInterface.java 2009-03-03 23:05:42 UTC (rev 534)
+++ trunk/server/src/main/java/com/metamatrix/platform/vm/api/controller/VMControllerInterface.java 2009-03-03 23:23:06 UTC (rev 535)
@@ -26,7 +26,6 @@
import java.util.Date;
import com.metamatrix.admin.api.exception.AdminException;
-import com.metamatrix.api.exception.MultipleException;
import com.metamatrix.common.config.api.ServiceComponentDefnID;
import com.metamatrix.common.log.LogConfiguration;
import com.metamatrix.platform.service.api.ServiceID;
@@ -38,8 +37,15 @@
/**
* Starts the VM by invoking all the deployed services
*/
- public void startVM();
+ public void start();
+
+ /**
+ * Shut down all services waiting for work to complete.
+ * Essential services will also be shutdown.
+ */
+ void shutdown(boolean now);
+
/**
* Start the service identified by the ServiceComponentID
* If synch is true then wait for service to start before returning.
@@ -53,37 +59,13 @@
*/
void startService(ServiceID serviceID);
- /**
- * Kill all services (waiting for work to complete) and then kill the vm.
- */
- void stopVM();
/**
- * Kill all services now, do not wait for work to complete
- */
- void stopVMNow();
-
- /**
* Kill service once work is complete
*/
- void stopService(ServiceID id);
+ void stopService(ServiceID id, boolean now, boolean shutdown);
- /**
- * Kill service now!!!
- */
- void stopServiceNow(ServiceID id);
-
/**
- * Kill all services once work is complete
- */
- void stopAllServices() throws MultipleException;
-
- /**
- * Kill all services now
- */
- void stopAllServicesNow() throws MultipleException;
-
- /**
* Check the state of a service
*/
void checkService(ServiceID serviceID);
@@ -119,30 +101,6 @@
void ping();
/**
- * Shut down all services waiting for work to complete.
- * Essential services will also be shutdown.
- */
- void shutdown();
-
- /**
- * Shut down all services without waiting for work to complete.
- * Essential services will also be shutdown.
- */
- void shutdownNow();
-
- /**
- * Shut down service waiting for work to complete.
- * Essential services will also be shutdown.
- */
- void shutdownService(ServiceID serviceID) ;
-
- /**
- * Shut down all services without waiting for work to complete.
- * Essential services will also be shutdown.
- */
- void shutdownServiceNow(ServiceID serviceID);
-
- /**
* Returns true if system is being shutdown.
*/
boolean isShuttingDown();
@@ -159,12 +117,6 @@
void dumpThreads();
/**
- * Run GC on vm.
- */
- void runGC() ;
-
-
- /**
* Export the server logs to a byte[]. The bytes contain the contents of a .zip file containing the logs.
* This will export all logs on the host that contains this VMController.
* @return the logs, as a byte[].
Modified: trunk/server/src/main/java/com/metamatrix/platform/vm/controller/VMController.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/vm/controller/VMController.java 2009-03-03 23:05:42 UTC (rev 534)
+++ trunk/server/src/main/java/com/metamatrix/platform/vm/controller/VMController.java 2009-03-03 23:23:06 UTC (rev 535)
@@ -263,7 +263,7 @@
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
try {
- shutdown();
+ shutdown(false);
} catch (Exception e) {
// ignore
}
@@ -333,7 +333,7 @@
return id;
}
- public void startVM() {
+ public void start() {
logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0013));
VMComponentDefnID vmComponentDefnID = (VMComponentDefnID)this.vmComponentDefn.getID();
@@ -497,26 +497,31 @@
}
}
+
+ /**
+ * Shut down all services waiting for work to complete.
+ * Essential services will also be shutdown.
+ */
+ public synchronized void shutdown(boolean now) {
+ logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0041));
+
+ try {
+ stopServices(now, true);
+ } catch (MultipleException e) {
+ logException(e, e.getMessage());
+ } catch (ServiceException e) {
+ logException(e, e.getMessage());
+ }
- /**
- * Kill all services (waiting for work to complete) and then kill the vm.
- */
- public void stopVM() {
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0029));
- doStopVM(false, false);
- }
+ JDBCConnectionPoolHelper.getInstance().shutDown();
-
- protected void doStopVM(boolean now, boolean shutdown) {
-
- stop(now, shutdown);
+ // unregister VMController
+ events.vmRemoved(id);
- // If running inside an app server then get a defaul context.
- String propVal = System.getProperty(CommonPropertyNames.APP_SERVER_VM);
- if (propVal != null && propVal.equalsIgnoreCase("true")) { //$NON-NLS-1$
- return;
- }
+ this.shuttingDown = true;
+ notifyAll();
+
this.startServicePool.execute(new Runnable() {
public void run() {
// Wait before killing the VM.
@@ -529,135 +534,22 @@
});
}
- private synchronized void stop(boolean now, boolean shutdown) {
- try {
- stopServices(now, shutdown);
- } catch (MultipleException e) {
- logException(e, e.getMessage());
- } catch (ServiceException e) {
- logException(e, e.getMessage());
- }
- JDBCConnectionPoolHelper.getInstance().shutDown();
-
- // unregister VMController
- events.vmRemoved(id);
- }
-
/**
- * Kill all services now, do not wait for work to complete, do not collect $200
- */
- public void stopVMNow() {
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0034));
- doStopVM(true, false);
- }
-
- /**
* Kill service once work is complete
*/
- public void stopService(ServiceID id) {
+ public void stopService(ServiceID id, boolean now, boolean shutdown) {
try {
logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0035, id));
validateServiceID(id);
ServiceRegistryBinding binding = this.registry.getServiceBinding(id.getHostName(), id.getVMControllerID().toString(), id);
- stopService(binding, false, false);
+ stopService(binding, now, shutdown);
} catch (ResourceNotBoundException e) {
throw new ServiceException(e);
}
}
- /**
- * Kill service now!!!
- */
- public void stopServiceNow(ServiceID id) {
- try {
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0036, id));
- validateServiceID(id);
- ServiceRegistryBinding binding = this.registry.getServiceBinding(id.getHostName(), id.getVMControllerID().toString(), id);
- stopService(binding, true, false);
- } catch (ResourceNotBoundException e) {
- throw new ServiceException(e);
- }
- }
-
- /**
- * Kill services now!!!
- */
- public void stopAllServicesNow() throws MultipleException {
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0037));
- stopServices(true, false);
- }
-
- /**
- * Kill services
- */
- public void stopAllServices() throws MultipleException {
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0038));
- stopServices(false, false);
- }
-
-
/**
- * Shut down all services waiting for work to complete.
- * Essential services will also be shutdown.
- */
- public void shutdown(){
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0040));
- doStopVM(false, true);
- }
-
- /**
- * Shut down all services without waiting for work to complete.
- * Essential services will also be shutdown.
- */
- public synchronized void shutdownNow() {
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0041));
- doStopVM(true, true);
- this.shuttingDown = true;
- notifyAll();
- }
-
- public void shutdownService(ServiceID serviceID) {
- shutdownService(serviceID, false);
- }
-
- /**
- * Shut down service without waiting for work to complete.
- * Essential services will also be shutdown.
- */
- public void shutdownServiceNow(ServiceID serviceID) {
- shutdownService(serviceID, true);
- }
-
- /**
- * Shut down service waiting for work to complete.
- * Essential services will also be shutdown.
- */
- private void shutdownService(ServiceID serviceID, boolean now) {
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0042, serviceID));
-
- ServiceRegistryBinding serviceBinding = null;
- try {
- serviceBinding = this.registry.getServiceBinding(serviceID.getHostName(), serviceID.getVMControllerID().toString(), serviceID);
- } catch (ResourceNotBoundException e) {
- throw new ServiceException(e, PlatformPlugin.Util.getString(LogMessageKeys.VM_0043, serviceID));
- }
-
- validateServiceID(serviceID);
-
- // if service is not running then don't try to stop.
- if (serviceBinding.getService() != null && serviceBinding.getCurrentState() != ServiceState.STATE_INIT_FAILED) {
- stopService(serviceBinding, now, true);
- }
-
- try {
- events.serviceRemoved(serviceID);
- } catch (Exception e) {
- throw new ServiceException(e, PlatformPlugin.Util.getString(LogMessageKeys.VM_0044, serviceID));
- }
- }
-
- /**
* Set the current log configuration for this vm.
*/
public void setCurrentLogConfiguration(LogConfiguration logConfiguration) {
@@ -760,14 +652,6 @@
}
/**
- * Run GC on vm.
- */
- public void runGC() {
- logMessage(PlatformPlugin.Util.getString(LogMessageKeys.VM_0005));
- System.gc();
- }
-
- /**
* Private helper method that verifies service belongs to this vm
*/
private void validateServiceID(ServiceID serviceID) {
@@ -959,6 +843,9 @@
if (shutdown) {
events.serviceRemoved(binding.getServiceID());
}
+ else {
+ events.serviceUpdated(binding);
+ }
}
Modified: trunk/server/src/main/java/com/metamatrix/server/HostController.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/HostController.java 2009-03-03 23:05:42 UTC (rev 534)
+++ trunk/server/src/main/java/com/metamatrix/server/HostController.java 2009-03-03 23:23:06 UTC (rev 535)
@@ -363,10 +363,7 @@
if (vm.getHostName().equalsIgnoreCase(this.host.getFullName())) {
if (vm.getVMName().equalsIgnoreCase(vmName)) {
try {
- if (stopNow)
- vm.getVMController().shutdownNow();
- else
- vm.getVMController().shutdown();
+ vm.getVMController().shutdown(stopNow);
} catch (Exception e) {
// ignore
}
Modified: trunk/server/src/main/java/com/metamatrix/server/Main.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/Main.java 2009-03-03 23:05:42 UTC (rev 534)
+++ trunk/server/src/main/java/com/metamatrix/server/Main.java 2009-03-03 23:23:06 UTC (rev 535)
@@ -114,7 +114,7 @@
Runtime.getRuntime().addShutdownHook(new ShutdownWork());
// start the VM
- this.vmController.startVM();
+ this.vmController.start();
synchronized (this.vmController) {
while(!this.vmController.isShuttingDown()) {
Modified: trunk/server/src/main/java/com/metamatrix/server/ServiceManager.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/ServiceManager.java 2009-03-03 23:05:42 UTC (rev 534)
+++ trunk/server/src/main/java/com/metamatrix/server/ServiceManager.java 2009-03-03 23:23:06 UTC (rev 535)
@@ -32,9 +32,6 @@
import java.util.Map;
import java.util.Properties;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
@@ -89,15 +86,11 @@
private final static int COMMAND_LIST_VM_PROPERTIES = 12;
private final static int COMMAND_LIST_SERVICE_PROPERTIES = 13;
private final static int COMMAND_SHUTDOWN_SERVER = 14;
- private final static int COMMAND_SHUTDOWN_SERVICE = 15;
- private final static int COMMAND_SHUTDOWN_SERVICE_NOW = 16;
private final static int COMMAND_SHUTDOWN_VM = 17;
- private final static int COMMAND_SHUTDOWN_VM_NOW = 18;
private final static int COMMAND_START_SERVICE = 19;
private final static int COMMAND_EXPERT_MODE_ON = 20;
private final static int COMMAND_EXPERT_MODE_OFF = 21;
private final static int COMMAND_GET_SERVICE_QUEUES = 22;
- private final static int COMMAND_RUN_GC = 23;
private final static int COMMAND_GET_VM_STATS = 24;
private final static int COMMAND_DUMP_THREADS = 25;
private final static int COMMAND_SYNCH_SERVER = 26;
@@ -106,7 +99,6 @@
private final static int COMMAND_BOUNCE_SERVICE = 29;
private final static int COMMAND_CLEAR_CODE_TABLE_CACHES = 30;
private final static int COMMAND_CLEAR_PREPARED_STMT_CACHES = 31;
- private final static int COMMAND_DUMP_JNDI = 32;
private final static int COMMAND_EXIT = 33;
private final static int COMMAND_HELP = 34;
private final static int COMMAND_INVALID = 35;
@@ -127,15 +119,11 @@
"ListProcessProps", //$NON-NLS-1$
"ListServiceProps", //$NON-NLS-1$
"ShutdownServer", //$NON-NLS-1$
- "ShutdownService", //$NON-NLS-1$
- "ShutdownServiceNow", //$NON-NLS-1$
"ShutdownProcess", //$NON-NLS-1$
- "ShutdownProcessNow", //$NON-NLS-1$
"RestartService", //$NON-NLS-1$
"ExpertModeOn", //$NON-NLS-1$
"ExpertModeOff", //$NON-NLS-1$
"GetServiceQueues", //$NON-NLS-1$
- "RunGC", //$NON-NLS-1$
"GetProcessStats", //$NON-NLS-1$
"DumpThreads", //$NON-NLS-1$
"Synch", //$NON-NLS-1$
@@ -144,7 +132,6 @@
"BounceService", //$NON-NLS-1$
"ClearCodeTableCaches", //$NON-NLS-1$
"ClearPreparedStatementCaches", //$NON-NLS-1$
- "DumpJNDI", //$NON-NLS-1$
"Exit", //$NON-NLS-1$
"Help" }; //$NON-NLS-1$
@@ -163,15 +150,11 @@
"ListProcessProps", //$NON-NLS-1$
"ListServiceProps", //$NON-NLS-1$
"ShutdownServer", //$NON-NLS-1$
- "ShutdownService", //$NON-NLS-1$
- "ShutdownServiceNow", //$NON-NLS-1$
"ShutdownProcess", //$NON-NLS-1$
- "ShutdownProcessNow", //$NON-NLS-1$
"RestartService", //$NON-NLS-1$
"ExpertModeOn", //$NON-NLS-1$
"ExpertModeOff", //$NON-NLS-1$
"GetServiceQueues", //$NON-NLS-1$
- "RunGC", //$NON-NLS-1$
"GetProcessStats", //$NON-NLS-1$
"DumpThreads", //$NON-NLS-1$
"Synch", //$NON-NLS-1$
@@ -180,7 +163,6 @@
"BounceService", //$NON-NLS-1$
"ClearCodeTableCaches", //$NON-NLS-1$
"ClearPreparedStatementCaches", //$NON-NLS-1$
- "DumpJNDI", //$NON-NLS-1$
"Exit", //$NON-NLS-1$
"Help" }; //$NON-NLS-1$
@@ -433,31 +415,6 @@
}
break;
- case COMMAND_SHUTDOWN_VM_NOW:
- if (numTokens < 2) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0013));
- } else {
- String vmName = (String) parsedCommand.get(1);
- doShutdownVM(vmName, true);
- }
- break;
-
- case COMMAND_SHUTDOWN_SERVICE:
- if (numTokens < 2) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0015));
- } else {
- String id = (String) parsedCommand.get(1);
- long value;
- try {
- value = Long.parseLong(id);
- } catch (Exception e) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0016));
- break;
- }
- doShutdownService(new ServiceID(value, null), false);
- }
- break;
-
case COMMAND_BOUNCE_SERVICE:
if (numTokens < 2) {
System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0031));
@@ -471,22 +428,6 @@
doShutdownServer();
break;
- case COMMAND_SHUTDOWN_SERVICE_NOW:
- if (numTokens < 2) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0015));
- } else {
- String id = (String) parsedCommand.get(1);
- long value;
- try {
- value = Long.parseLong(id);
- } catch (Exception e) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0016));
- break;
- }
- doShutdownService(new ServiceID(value, null), true);
- }
- break;
-
case COMMAND_EXPERT_MODE_ON:
this.expertMode = true;
printUsage();
@@ -497,15 +438,6 @@
printUsage();
break;
- case COMMAND_RUN_GC:
- if (numTokens < 2) {
- System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0013));
- } else {
- String vmName = (String) parsedCommand.get(1);
- doRunGC(vmName);
- }
- break;
-
case COMMAND_GET_VM_STATS:
if (numTokens < 2) {
System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0013));
@@ -569,10 +501,6 @@
doClearPreparedStatementCaches();
break;
- case COMMAND_DUMP_JNDI:
- doDumpJNDI();
- break;
-
case COMMAND_START_SERVICE:
if (numTokens < 2) {
System.out.println(PlatformPlugin.Util.getString(LogMessageKeys.SERVICE_0015));
@@ -591,15 +519,6 @@
}
}
- private void doDumpJNDI() {
- try {
- Context ctx = new InitialContext();
- System.out.println("JDNI:"); //$NON-NLS-1$
- System.out.println(ctx.list("")); //$NON-NLS-1$
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
public void doBounceService(String name) {
@@ -788,20 +707,6 @@
}
}
- private void doRunGC(String vmName) {
- VMControllerInterface vm = getVMController(vmName);
- if (vm != null) {
- try {
- vm.runGC();
- } catch (Exception e) {
- System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0029, vmName));
- e.printStackTrace();
- }
- } else {
- System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0030, vmName));
- }
- }
-
private void doGetVMStats(String vmName) {
VMControllerInterface vm = getVMController(vmName);
if (vm != null) {
@@ -844,7 +749,7 @@
Iterator vmIter = registry.getVMs(null).iterator();
while (vmIter.hasNext()) {
VMRegistryBinding vmBinding = (VMRegistryBinding) vmIter.next();
- if (vmBinding.getVMController().getName().equalsIgnoreCase(vmName)) {
+ if (vmBinding.getVMName().equalsIgnoreCase(vmName)) {
return vmBinding.getVMController();
}
}
@@ -976,8 +881,7 @@
VMRegistryBinding vmBinding = null;
while (vmIter.hasNext()) {
vmBinding = (VMRegistryBinding) vmIter.next();
- if (vmBinding.getVMController().getName().equalsIgnoreCase(vmName)) {
- vmBinding.getVMController().stopVM();
+ if (vmBinding.getVMName().equalsIgnoreCase(vmName)) {
this.hostManager.killServer(vmBinding.getHostName(),vmBinding.getVMName(), false);
break;
}
@@ -1019,19 +923,12 @@
}
public void doShutdownVM(String vmName, boolean now) {
-
- // find vm
try {
Iterator vmIter = registry.getVMs(null).iterator();
while (vmIter.hasNext()) {
VMRegistryBinding vmBinding = (VMRegistryBinding) vmIter.next();
- if (vmBinding.getVMController().getName().equalsIgnoreCase(vmName)) {
- if (now) {
- vmBinding.getVMController().shutdownNow();
- } else {
- vmBinding.getVMController().shutdown();
- }
- this.hostManager.killServer(vmBinding.getHostName(), vmName, false);
+ if (vmBinding.getVMName().equalsIgnoreCase(vmName)) {
+ this.hostManager.killServer(vmBinding.getHostName(), vmName, now);
return;
}
}
@@ -1145,7 +1042,7 @@
}
VMRegistryBinding vmBinding = registry.getVM(id.getHostName(), id.getVMControllerID().toString());
if (vmBinding != null) {
- vmBinding.getVMController().stopService(id);
+ vmBinding.getVMController().stopService(id, false, false);
}
else {
System.out.println("No VM found on host="+id.getHostName()+" with id="+id.getVMControllerID().toString()); //$NON-NLS-1$ //$NON-NLS-2$
@@ -1156,33 +1053,6 @@
}
}
- public void doShutdownService(ServiceID serviceID, boolean now) {
-
- ServiceID id = null;
- try {
- id = getServiceID(serviceID);
- if (id == null) {
- System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0039));
- return;
- }
- VMRegistryBinding vmBinding = registry.getVM(id.getHostName(), id.getVMControllerID().toString());
- if (vmBinding != null) {
- if (now) {
- vmBinding.getVMController().shutdownServiceNow(id);
- } else {
- vmBinding.getVMController().shutdownService(id);
- }
- }
- else {
- System.out.println("No VM found on host="+id.getHostName()+" with id="+id.getVMControllerID().toString());//$NON-NLS-1$ //$NON-NLS-2$
- }
-
- } catch (Exception e) {
- System.out.println(PlatformPlugin.Util.getString(ErrorMessageKeys.SERVICE_0015, id));
- e.printStackTrace();
- }
- }
-
public void doShutdownAllHCs() {
System.out.println("Cluster is being shutdown"); //$NON-NLS-1$
try {
16 years, 7 months
teiid SVN: r534 - in branches/symbol_refactoring_61/engine/src: main/java/com/metamatrix/query/processor and 13 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-03-03 18:05:42 -0500 (Tue, 03 Mar 2009)
New Revision: 534
Modified:
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/ProcessorPlan.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/DupRemoveNode.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Select.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Aggregate.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/DerivedColumn.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/UpdateValidationVisitor.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/parser/TestOptionsAndHints.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestAliasSymbol.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestBatchedUpdateCommand.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestQuery.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/proc/TestAssignmentStatement.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestAggregateSymbolCollectorVisitor.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestSQLStringVisitor.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestStaticSymbolMappingVisitor.java
Log:
basic rewrite tests are passing
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -81,7 +81,6 @@
import com.metamatrix.query.sql.lang.Option;
import com.metamatrix.query.sql.lang.SPParameter;
import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.symbol.Symbol;
public class RequestWorkItem extends AbstractWorkItem {
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/ProcessorPlan.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/ProcessorPlan.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/ProcessorPlan.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -28,6 +28,7 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.common.buffer.*;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.util.CommandContext;
/**
@@ -75,7 +76,7 @@
* Get list of resolved elements describing output columns for this plan.
* @return List of SingleElementSymbol
*/
- List getOutputElements();
+ List<DerivedColumn> getOutputElements();
/**
* Get the processor context, which can be modified.
@@ -121,5 +122,5 @@
* @return List of ProcessorPlan
* @since 4.2
*/
- Collection getChildPlans();
+ Collection<ProcessorPlan> getChildPlans();
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/DupRemoveNode.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/DupRemoveNode.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/DupRemoveNode.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -36,10 +36,6 @@
super(nodeID);
}
- public void reset() {
- super.reset();
- }
-
public void open()
throws MetaMatrixComponentException, MetaMatrixProcessingException {
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/SortUtility.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -40,7 +40,6 @@
import com.metamatrix.common.buffer.BufferManager.TupleSourceStatus;
import com.metamatrix.common.buffer.BufferManager.TupleSourceType;
import com.metamatrix.core.util.Assertion;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.util.TypeRetrievalUtil;
/**
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -261,6 +261,7 @@
// Walk through elements of order by
for (OrderByItem orderByItem : elements) {
Collection<ElementSymbol> symbols = ElementCollectorVisitor.getElements(orderByItem.getSortKey(), false);
+ //check for unsigned int
if (symbols.isEmpty()) {
if (orderByItem.getSortKey() instanceof Constant) {
Constant c = (Constant)orderByItem.getSortKey();
@@ -269,13 +270,15 @@
if (value < 1 || value > knownElements.size()) {
throw new QueryResolverException("Invalid order by ordinal");
}
- orderByItem.setOrdinalPosition(value);
+ orderByItem.setOrdinalPosition(value - 1);
orderByItem.setType(knownElements.get(value - 1).getType());
continue;
}
}
throw new QueryResolverException("Invalid order by expression");
}
+ //resolve each of the symbols present - they must come from the select clause
+ //TODO: SQL 2008 allows for ordering outside of the select clause...
for (ElementSymbol elementSymbol : symbols) {
DerivedColumn matchedSymbol = null;
String symbolName = elementSymbol.getName();
@@ -346,7 +349,7 @@
}
}
- private static void resolveOrderByItem(int position,
+ public static void resolveOrderByItem(int position,
ElementSymbol elementSymbol, DerivedColumn matchedSymbol) {
TempMetadataID tempMetadataID = new TempMetadataID(matchedSymbol.getName(), matchedSymbol.getType());
tempMetadataID.setPosition(position);
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -96,6 +96,7 @@
import com.metamatrix.query.sql.lang.NotCriteria;
import com.metamatrix.query.sql.lang.Option;
import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.lang.ProcedureContainer;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.QueryCommand;
@@ -134,11 +135,12 @@
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.ScalarSubquery;
import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
-import com.metamatrix.query.sql.util.SymbolMap;
+import com.metamatrix.query.sql.symbol.TypedLanguageObject;
import com.metamatrix.query.sql.visitor.AggregateSymbolCollectorVisitor;
import com.metamatrix.query.sql.visitor.CorrelatedVariableSubstitutionVisitor;
import com.metamatrix.query.sql.visitor.CriteriaTranslatorVisitor;
import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
+import com.metamatrix.query.sql.visitor.EvaluatableVisitor;
import com.metamatrix.query.sql.visitor.EvaluateExpressionVisitor;
import com.metamatrix.query.sql.visitor.ExpressionMappingVisitor;
import com.metamatrix.query.sql.visitor.PredicateCollectorVisitor;
@@ -163,12 +165,12 @@
private static final Map<String, String> ALIASED_FUNCTIONS = new HashMap<String, String>();
static {
- ALIASED_FUNCTIONS.put("lower", SourceSystemFunctions.LCASE);
- ALIASED_FUNCTIONS.put("upper", SourceSystemFunctions.UCASE);
- ALIASED_FUNCTIONS.put("cast", SourceSystemFunctions.CONVERT);
- ALIASED_FUNCTIONS.put("nvl", SourceSystemFunctions.IFNULL);
- ALIASED_FUNCTIONS.put("||", SourceSystemFunctions.CONCAT);
- ALIASED_FUNCTIONS.put("chr", SourceSystemFunctions.CHAR);
+ ALIASED_FUNCTIONS.put("lower", SourceSystemFunctions.LCASE); //$NON-NLS-1$
+ ALIASED_FUNCTIONS.put("upper", SourceSystemFunctions.UCASE); //$NON-NLS-1$
+ ALIASED_FUNCTIONS.put("cast", SourceSystemFunctions.CONVERT); //$NON-NLS-1$
+ ALIASED_FUNCTIONS.put("nvl", SourceSystemFunctions.IFNULL); //$NON-NLS-1$
+ ALIASED_FUNCTIONS.put("||", SourceSystemFunctions.CONCAT); //$NON-NLS-1$
+ ALIASED_FUNCTIONS.put("chr", SourceSystemFunctions.CHAR); //$NON-NLS-1$
}
private QueryRewriter() { }
@@ -693,79 +695,7 @@
}
}
- if (query.getGroupBy() != null) {
- // we check for group by expressions here to create an ANSI SQL plan
- boolean hasExpression = false;
- for (final Iterator iterator = query.getGroupBy().getSymbols().iterator(); !hasExpression && iterator.hasNext();) {
- hasExpression = iterator.next() instanceof DerivedColumn;
- }
- if (hasExpression) {
- Select select = query.getSelect();
- GroupBy groupBy = query.getGroupBy();
- query.setGroupBy(null);
- Criteria having = query.getHaving();
- query.setHaving(null);
- OrderBy orderBy = query.getOrderBy();
- query.setOrderBy(null);
- Limit limit = query.getLimit();
- query.setLimit(null);
- Into into = query.getInto();
- query.setInto(null);
- Set<Expression> newSelectColumns = new HashSet<Expression>();
- for (final Iterator iterator = groupBy.getSymbols().iterator(); iterator.hasNext();) {
- newSelectColumns.add(SymbolMap.getExpression((SingleElementSymbol)iterator.next()));
- }
- Set<Aggregate> aggs = new HashSet<Aggregate>();
- aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(select, true));
- if (having != null) {
- aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(having, true));
- }
- for (Aggregate aggregateSymbol : aggs) {
- if (aggregateSymbol.getExpression() != null) {
- Expression expr = aggregateSymbol.getExpression();
- newSelectColumns.add(SymbolMap.getExpression(expr));
- }
- }
- Select innerSelect = new Select();
- int index = 0;
- for (Expression expr : newSelectColumns) {
- if (expr instanceof SingleElementSymbol) {
- innerSelect.addSymbol((SingleElementSymbol)expr);
- } else {
- innerSelect.addSymbol(new DerivedColumn("EXPR" + index++ , expr)); //$NON-NLS-1$
- }
- }
- query.setSelect(innerSelect);
- Query outerQuery = null;
- try {
- outerQuery = QueryRewriter.createInlineViewQuery(new GroupSymbol("X"), query, metadata, query.getSelect().getProjectedSymbols()); //$NON-NLS-1$
- } catch (QueryMetadataException err) {
- throw new QueryValidatorException(err, err.getMessage());
- } catch (QueryResolverException err) {
- throw new QueryValidatorException(err, err.getMessage());
- } catch (MetaMatrixComponentException err) {
- throw new QueryValidatorException(err, err.getMessage());
- }
- Iterator iter = outerQuery.getSelect().getProjectedSymbols().iterator();
- HashMap<Expression, SingleElementSymbol> expressionMap = new HashMap<Expression, SingleElementSymbol>();
- for (SingleElementSymbol symbol : (List<SingleElementSymbol>)query.getSelect().getProjectedSymbols()) {
- expressionMap.put((Expression)SymbolMap.getExpression(symbol).clone(), (SingleElementSymbol)iter.next());
- }
- ExpressionMappingVisitor.mapExpressions(groupBy, expressionMap, true);
- outerQuery.setGroupBy(groupBy);
- ExpressionMappingVisitor.mapExpressions(having, expressionMap, true);
- outerQuery.setHaving(having);
- ExpressionMappingVisitor.mapExpressions(orderBy, expressionMap, true);
- outerQuery.setOrderBy(orderBy);
- outerQuery.setLimit(limit);
- ExpressionMappingVisitor.mapExpressions(select, expressionMap, true);
- outerQuery.setSelect(select);
- outerQuery.setInto(into);
- outerQuery.setOption(query.getOption());
- query = outerQuery;
- rewriteExpressions(innerSelect, procCommand, metadata, context);
- }
- }
+ query = rewriteGroupBy(query, procCommand, metadata, context);
// Rewrite having
Criteria having = query.getHaving();
@@ -776,7 +706,7 @@
rewriteExpressions(query.getSelect(), procCommand, metadata, context);
if (query.getOrderBy() != null && !query.getIsXML()) {
- makeSelectUnique(query, true);
+ makeSelectUnique(query);
rewriteOrderBy(query, procCommand, metadata, context);
}
@@ -790,6 +720,87 @@
return query;
}
+
+ private static Query rewriteGroupBy(Query query, final Command procCommand,
+ final QueryMetadataInterface metadata, final CommandContext context)
+ throws QueryValidatorException {
+ if (query.getGroupBy() == null) {
+ return query;
+ }
+ GroupBy groupBy = query.getGroupBy();
+ // we check for group by expressions here to create an ANSI SQL plan
+ boolean hasExpression = false;
+ Set<Expression> newSelectColumns = new HashSet<Expression>();
+ for (Expression expression : groupBy.getSymbols()) {
+ newSelectColumns.add(expression);
+ hasExpression |= !(expression instanceof ElementSymbol);
+ }
+ if (!hasExpression) {
+ return query;
+ }
+ //create an inline view to represent the group by expressions
+ Select select = query.getSelect();
+ query.setGroupBy(null);
+ Criteria having = query.getHaving();
+ query.setHaving(null);
+ OrderBy orderBy = query.getOrderBy();
+ query.setOrderBy(null);
+ Limit limit = query.getLimit();
+ query.setLimit(null);
+ Into into = query.getInto();
+ query.setInto(null);
+ Set<Aggregate> aggs = new HashSet<Aggregate>();
+ aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(select, true));
+ if (having != null) {
+ aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(having, true));
+ }
+ for (Aggregate aggregateSymbol : aggs) {
+ if (aggregateSymbol.getExpression() != null) {
+ newSelectColumns.add(aggregateSymbol.getExpression());
+ }
+ }
+ Select innerSelect = new Select();
+ int index = 0;
+ for (Expression expr : newSelectColumns) {
+ if (expr instanceof ElementSymbol) {
+ innerSelect.addSymbol(new DerivedColumn((ElementSymbol)expr));
+ } else {
+ innerSelect.addSymbol(new DerivedColumn("EXPR" + index++ , expr)); //$NON-NLS-1$
+ }
+ }
+ query.setSelect(innerSelect);
+ Query outerQuery = null;
+ try {
+ outerQuery = QueryRewriter.createInlineViewQuery(new GroupSymbol("X"), query, metadata, query.getSelect().getProjectedSymbols()); //$NON-NLS-1$
+ } catch (QueryMetadataException err) {
+ throw new QueryValidatorException(err, err.getMessage());
+ } catch (QueryResolverException err) {
+ throw new QueryValidatorException(err, err.getMessage());
+ } catch (MetaMatrixComponentException err) {
+ throw new QueryValidatorException(err, err.getMessage());
+ }
+ Iterator<DerivedColumn> iter = outerQuery.getSelect().getProjectedSymbols().iterator();
+ HashMap<Expression, Expression> expressionMap = new HashMap<Expression, Expression>();
+ for (DerivedColumn symbol : query.getProjectedSymbols()) {
+ Expression expr = iter.next().getExpression();
+ Assertion.assertTrue(expr instanceof ElementSymbol);
+ expressionMap.put((Expression)symbol.getExpression().clone(), expr);
+ }
+ ExpressionMappingVisitor.mapExpressions(groupBy, expressionMap, true);
+ outerQuery.setGroupBy(groupBy);
+ ExpressionMappingVisitor.mapExpressions(having, expressionMap, true);
+ outerQuery.setHaving(having);
+ ExpressionMappingVisitor.mapExpressions(orderBy, expressionMap, true);
+ outerQuery.setOrderBy(orderBy);
+ outerQuery.setLimit(limit);
+ ExpressionMappingVisitor.mapExpressions(select, expressionMap, true);
+ outerQuery.setSelect(select);
+ outerQuery.setInto(into);
+ outerQuery.setOption(query.getOption());
+ query = outerQuery;
+ rewriteExpressions(innerSelect, procCommand, metadata, context);
+ return query;
+ }
private static void rewriteExpressions(LanguageObject obj,
final Command procCommand,
@@ -832,7 +843,7 @@
if (orderBy == null) {
return;
}
- List projectedSymbols = null;
+ final List<DerivedColumn> projectedSymbols;
if (query instanceof Query) {
if (((Query)query).getIsXML()) {
return;
@@ -841,35 +852,57 @@
} else {
projectedSymbols = query.getProjectedSymbols();
}
- if (orderBy.isInPlanForm()) {
- rewriteExpressions(orderBy, procCommand, metadata, context);
- }
+ rewriteExpressions(orderBy, procCommand, metadata, context);
OrderBy newOrderBy = new OrderBy();
HashSet<Expression> previousExpressions = new HashSet<Expression>();
- for (int i = 0; i < orderBy.getVariableCount(); i++) {
- SingleElementSymbol querySymbol = orderBy.getVariable(i);
- if (!orderBy.isInPlanForm()) {
- //get the order by item from the select clause, the variable must be an element symbol
- int index = ((TempMetadataID)((ElementSymbol)querySymbol).getMetadataID()).getPosition();
- querySymbol = (SingleElementSymbol)((SingleElementSymbol)projectedSymbols.get(index)).clone();
- }
- Expression expr = SymbolMap.getExpression(querySymbol);
+ for (OrderByItem orderByItem : orderBy.getSortOrder()) {
+ /*
+ * we are now assured that the derived column names are unique
+ * so we can switch to using them
+ */
+ if (orderByItem.getOrdinalPosition() >= 0) {
+ DerivedColumn column = projectedSymbols.get(orderByItem.getOrdinalPosition());
+ ElementSymbol expression = new ElementSymbol(column.getName());
+ ResolverUtil.resolveOrderByItem(orderByItem.getOrdinalPosition(), expression, column);
+ orderByItem.setSortKey(expression);
+ orderByItem.setOrdinalPosition(-1);
+ }
+ for (ElementSymbol symbol : ElementCollectorVisitor.getElements(orderByItem.getSortKey(), false)) {
+ TempMetadataID tid = (TempMetadataID)symbol.getMetadataID();
+ symbol.setName(projectedSymbols.get(tid.getPosition()).getName());
+ }
+
+ Expression expr = orderByItem.getSortKey();
+
+ //ensure we have a unique set of order by expressions
if (!previousExpressions.add(expr)) {
continue;
}
- if (query instanceof Query && EvaluateExpressionVisitor.isFullyEvaluatable(expr, true)) {
- continue;
+ //check for constant order by expressions
+ if (query instanceof Query) {
+ EvaluatableVisitor visitor = new EvaluatableVisitor(false, false) {
+ @Override
+ public void visit(ElementSymbol obj) {
+ DerivedColumn dc = projectedSymbols.get(((TempMetadataID)obj.getMetadataID()).getPosition());
+ if (!EvaluateExpressionVisitor.willBecomeConstant(dc.getExpression())) {
+ evaluationNotPossible();
+ }
+ }
+ };
+ PreOrderNavigator.doVisit(expr, visitor);
+ if (visitor.isEvaluationPossible()) {
+ continue;
+ }
}
- newOrderBy.addVariable((SingleElementSymbol)querySymbol.clone(), orderBy.getOrderType(i).booleanValue());
+ newOrderBy.addItem(orderByItem);
}
if (newOrderBy.getVariableCount() == 0) {
query.setOrderBy(null);
} else {
- newOrderBy.setInPlanForm(true);
query.setOrderBy(newOrderBy);
}
}
@@ -887,12 +920,12 @@
Into into = query.getInto();
try {
- List allIntoElements = ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata);
+ List<ElementSymbol> allIntoElements = ResolverUtil.resolveElementsInGroup(into.getGroup(), metadata);
boolean needsView = false;
-
+ List<DerivedColumn> projectedIntoSymbols = query.getSelect().getProjectedSymbols();
for (int i = 0; !needsView && i < allIntoElements.size(); i++) {
- SingleElementSymbol ses = (SingleElementSymbol)allIntoElements.get(i);
- if (ses.getType() != ((SingleElementSymbol)query.getSelect().getProjectedSymbols().get(i)).getType()) {
+ ElementSymbol ses = allIntoElements.get(i);
+ if (ses.getType() != projectedIntoSymbols.get(i).getType()) {
needsView = true;
}
}
@@ -914,16 +947,6 @@
}
- private static void correctProjectedTypes(List actualSymbolTypes,
- Query query) throws QueryValidatorException {
-
- List symbols = query.getSelect().getProjectedSymbols();
-
- List newSymbols = SetQuery.getTypedProjectedSymbols(symbols, actualSymbolTypes);
-
- query.getSelect().setSymbols(newSymbols);
- }
-
private static SetQuery rewriteSetQuery(SetQuery setQuery, Command procCommand, QueryMetadataInterface metadata, CommandContext context)
throws QueryValidatorException {
@@ -932,7 +955,13 @@
if (!(command instanceof Query)) {
continue;
}
- correctProjectedTypes(setQuery.getProjectedTypes(), (Query)command);
+ Query query = (Query)command;
+ List<DerivedColumn> symbols = query.getSelect().getProjectedSymbols();
+
+ List<DerivedColumn> newSymbols = SetQuery.getTypedProjectedSymbols(symbols, setQuery.getProjectedTypes());
+
+ query.getSelect().setSymbols(newSymbols);
+
}
setQuery.setProjectedTypes(null);
}
@@ -941,7 +970,7 @@
setQuery.setRightQuery((QueryCommand)rewriteCommand(setQuery.getRightQuery(), procCommand, metadata, context));
if (setQuery.getOrderBy() != null) {
- makeSelectUnique(setQuery.getProjectedQuery(), true);
+ makeSelectUnique(setQuery.getProjectedQuery());
rewriteOrderBy(setQuery, procCommand, metadata, context);
}
@@ -2013,7 +2042,7 @@
if (function.getName().equalsIgnoreCase(FunctionLibrary.SPACE)) {
//change the function into timestampadd
Function result = new Function(SourceSystemFunctions.REPEAT,
- new Expression[] {new Constant(" "), function.getArg(0)});
+ new Expression[] {new Constant(" "), function.getArg(0)}); //$NON-NLS-1$
//resolve the function
FunctionDescriptor descriptor =
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.REPEAT, new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.INTEGER});
@@ -2381,14 +2410,14 @@
private static Query createInlineViewQuery(GroupSymbol group,
QueryCommand nested,
QueryMetadataInterface metadata) throws QueryMetadataException, QueryResolverException, MetaMatrixComponentException {
- List actualSymbols = ResolverUtil.resolveElementsInGroup(group, metadata);
+ List<ElementSymbol> actualSymbols = ResolverUtil.resolveElementsInGroup(group, metadata);
return createInlineViewQuery(group, nested, metadata, actualSymbols);
}
public static Query createInlineViewQuery(GroupSymbol group,
QueryCommand nested,
QueryMetadataInterface metadata,
- List actualSymbols) throws QueryMetadataException,
+ List<? extends TypedLanguageObject> actualSymbols) throws QueryMetadataException,
QueryResolverException,
MetaMatrixComponentException {
Query query = new Query();
@@ -2400,20 +2429,19 @@
TempMetadataStore store = new TempMetadataStore();
TempMetadataAdapter tma = new TempMetadataAdapter(metadata, store);
Query firstProject = nested.getProjectedQuery();
- makeSelectUnique(firstProject, false);
+ makeSelectUnique(firstProject);
store.addTempGroup(inlineGroup.getName(), nested.getProjectedSymbols());
inlineGroup.setMetadataID(store.getTempGroupID(inlineGroup.getName()));
- List actualTypes = new ArrayList(nested.getProjectedSymbols().size());
+ List<Class<?>> actualTypes = new ArrayList(nested.getProjectedSymbols().size());
- for (Iterator i = actualSymbols.iterator(); i.hasNext();) {
- SingleElementSymbol ses = (SingleElementSymbol)i.next();
- actualTypes.add(ses.getType());
+ for (TypedLanguageObject tlo : actualSymbols) {
+ actualTypes.add(tlo.getType());
}
- List selectSymbols = SetQuery.getTypedProjectedSymbols(ResolverUtil.resolveElementsInGroup(inlineGroup, tma), actualTypes);
- for (final Iterator iterator = selectSymbols.iterator(); iterator.hasNext();) {
- select.addSymbol((SingleElementSymbol)((SingleElementSymbol)iterator.next()).clone());
+ List<DerivedColumn> selectSymbols = SetQuery.getTypedProjectedSymbols(ResolverUtil.convertToDerivedColumns(ResolverUtil.resolveElementsInGroup(inlineGroup, tma)), actualTypes);
+ for (DerivedColumn derivedColumn : selectSymbols) {
+ select.addSymbol((DerivedColumn)derivedColumn.clone());
}
query.setFrom(from);
QueryResolver.resolveCommand(query, tma);
@@ -2428,18 +2456,15 @@
return query;
}
- public static void makeSelectUnique(Query query, boolean expressionSymbolsOnly) {
+ public static void makeSelectUnique(Query query) {
- query.getSelect().setSymbols(query.getSelect().getProjectedSymbols());
+ List<DerivedColumn> columns = query.getSelect().getProjectedSymbols();
+
+ query.getSelect().setSymbols(columns);
- List symbols = query.getSelect().getSymbols();
-
HashSet<String> uniqueNames = new HashSet<String>();
- for(int i = 0; i < symbols.size(); i++) {
-
- SingleElementSymbol symbol = (SingleElementSymbol)symbols.get(i);
-
+ for (DerivedColumn symbol : columns) {
String baseName = symbol.getShortCanonicalName();
String name = baseName;
@@ -2451,20 +2476,12 @@
name = baseName + '_' + (exprID++);
}
- if (expressionSymbolsOnly && !(symbol instanceof DerivedColumn)) {
- continue;
+ if (exprID == 0) {
+ continue;
}
- boolean hasAlias = false;
- // Strip alias if it exists
- if(symbol instanceof AliasSymbol) {
- symbol = ((AliasSymbol)symbol).getSymbol();
- hasAlias = true;
- }
-
- if (((symbol instanceof DerivedColumn) && !hasAlias) || !name.equalsIgnoreCase(baseName)) {
- symbols.set(i, new AliasSymbol(name, symbol));
- }
+ symbol.setAlias(true);
+ symbol.setName(name);
}
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -37,7 +37,7 @@
private Expression sortKey;
private OrderSpecification orderingSpecification;
//set after resolving is this is a SQL-92 unsigned int
- private int ordinalPosition;
+ private int ordinalPosition = -1;
//set after resolving
private Class<?> type;
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Select.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Select.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Select.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -100,8 +100,8 @@
* Sets an ordered list of the symbols in the select.
* @param symbols list of SelectSymbol in SELECT
*/
- public void setSymbols(List<SelectSymbol> symbols) {
- this.symbols = symbols;
+ public void setSymbols(List<? extends SelectSymbol> symbols) {
+ this.symbols = new ArrayList<SelectSymbol>(symbols);
}
/**
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -126,11 +126,11 @@
return projectedSymbols;
}
- public static List<DerivedColumn> getTypedProjectedSymbols(List<DerivedColumn> acutal, List projectedTypes) {
+ public static List<DerivedColumn> getTypedProjectedSymbols(List<DerivedColumn> acutal, List<Class<?>> projectedTypes) {
List<DerivedColumn> newProject = new ArrayList<DerivedColumn>();
for (int i = 0; i < acutal.size(); i++) {
DerivedColumn symbol = acutal.get(i);
- Class type = (Class)projectedTypes.get(i);
+ Class<?> type = projectedTypes.get(i);
if (symbol.getType() != type) {
Expression expr = symbol.getExpression();
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Aggregate.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Aggregate.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Aggregate.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -33,6 +33,7 @@
import com.metamatrix.query.QueryPlugin;
import com.metamatrix.query.sql.LanguageVisitor;
import com.metamatrix.query.sql.ReservedWords;
+import com.metamatrix.query.sql.visitor.SQLStringVisitor;
import com.metamatrix.query.util.ErrorMessageKeys;
/**
@@ -213,5 +214,10 @@
&& this.distinct == other.distinct
&& EquivalenceUtil.areEqual(this.getExpression(), other.getExpression());
}
+
+ @Override
+ public String toString() {
+ return SQLStringVisitor.getSQLString(this);
+ }
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/DerivedColumn.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/DerivedColumn.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/DerivedColumn.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -108,6 +108,7 @@
}
DerivedColumn copy = new DerivedColumn(getName(), getCanonical(), clonedExpr);
copy.setAlias(this.alias);
+ copy.setOutputName(this.getOutputName());
return copy;
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -86,7 +86,7 @@
}
}
- private boolean evaluationNotPossible() {
+ protected boolean evaluationNotPossible() {
evaluationPossible = false;
setAbort(true);
return evaluationPossible;
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -72,16 +72,8 @@
this.symbolMap = symbolMap;
}
- protected boolean createAliases() {
- return true;
- }
-
public void visit(DerivedColumn expr) {
- Expression expression = expr.getExpression();
expr.setExpression(replaceExpression(expr.getExpression()));
- if (createAliases() && expr.getExpression() != expression) {
- expr.setAlias(true);
- }
}
/**
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/UpdateValidationVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/UpdateValidationVisitor.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/UpdateValidationVisitor.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -31,8 +31,20 @@
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.metadata.SupportConstants;
import com.metamatrix.query.metadata.TempMetadataID;
-import com.metamatrix.query.sql.lang.*;
-import com.metamatrix.query.sql.symbol.*;
+import com.metamatrix.query.sql.lang.Delete;
+import com.metamatrix.query.sql.lang.From;
+import com.metamatrix.query.sql.lang.Insert;
+import com.metamatrix.query.sql.lang.Query;
+import com.metamatrix.query.sql.lang.Select;
+import com.metamatrix.query.sql.lang.SetQuery;
+import com.metamatrix.query.sql.lang.StoredProcedure;
+import com.metamatrix.query.sql.lang.Update;
+import com.metamatrix.query.sql.symbol.Aggregate;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.Expression;
+import com.metamatrix.query.sql.symbol.Function;
+import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
import com.metamatrix.query.util.ErrorMessageKeys;
@@ -136,22 +148,13 @@
*/
public void visit(Select obj) {
- Iterator elementIter = obj.getProjectedSymbols().iterator();
-
- while(elementIter.hasNext()) {
- SingleElementSymbol symbol = (SingleElementSymbol) elementIter.next();
- if(symbol instanceof AliasSymbol) {
- symbol = ((AliasSymbol)symbol).getSymbol();
+ for (DerivedColumn symbol : obj.getProjectedSymbols()) {
+ Expression expr = symbol.getExpression();
+ if(expr instanceof Function) {
+ handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0008, symbol));
+ } else if (expr instanceof Aggregate) {
+ handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0007, symbol));
}
-
- if(symbol instanceof DerivedColumn) {
- Expression expr = ((DerivedColumn)symbol).getExpression();
- if(expr instanceof Function) {
- handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0008, symbol));
- } else if (expr instanceof Aggregate) {
- handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0007, symbol));
- }
- }
}
elementsInSelect = ElementCollectorVisitor.getElements(obj, false);
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/parser/TestOptionsAndHints.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/parser/TestOptionsAndHints.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/parser/TestOptionsAndHints.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -26,6 +26,7 @@
import java.util.Arrays;
import java.util.List;
+import com.metamatrix.query.resolver.util.ResolverUtil;
import com.metamatrix.query.sql.lang.AbstractCompareCriteria;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.CompareCriteria;
@@ -304,7 +305,7 @@
From from = new From(Arrays.asList(new Object[] {predicate}));
predicate.getLeftClause().setMakeNotDep(true);
predicate.getRightClause().setMakeDep(true);
- Select select = new Select(Arrays.asList(new Object[] {x, y}));
+ Select select = new Select(ResolverUtil.convertToDerivedColumns(Arrays.asList(x, y)));
Query query = new Query(select, from, null, null, null, null, null);
TestParser.helpTest("Select a.x, b.y From a MAKENOTDEP INNER JOIN b MAKEDEP ON a.x = function(b.y)", //$NON-NLS-1$
@@ -1040,7 +1041,7 @@
option.addDependentGroup("a"); //$NON-NLS-1$
option.addNotDependentGroup("b"); //$NON-NLS-1$
- Select select = new Select(Arrays.asList(new Object[] {x, y}));
+ Select select = new Select(ResolverUtil.convertToDerivedColumns(Arrays.asList(x, y)));
Criteria criteria = new CompareCriteria(x, CompareCriteria.EQ, y);
Query query = new Query(select, from, criteria, null, null, null, option);
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/FakeDataManager.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -42,11 +42,9 @@
import com.metamatrix.query.sql.lang.ProcedureContainer;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.SetQuery;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
-import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.ReferenceCollectorVisitor;
import com.metamatrix.query.util.CommandContext;
@@ -84,7 +82,7 @@
return this.queries;
}
- public void registerTuples(Object groupID, List elements, List[] data) {
+ public void registerTuples(Object groupID, List<ElementSymbol> elements, List[] data) {
tuples.put(groupID, new Object[] { elements, data });
}
@@ -115,10 +113,10 @@
Object groupID = group.getMetadataID();
Object[] tupleInfo = (Object[]) tuples.get(groupID);
- List elements = (List) tupleInfo[0];
+ List<ElementSymbol> elements = (List<ElementSymbol>) tupleInfo[0];
List[] tuples = (List[]) tupleInfo[1];
- List projectedSymbols = command.getProjectedSymbols();
+ List<DerivedColumn> projectedSymbols = command.getProjectedSymbols();
int[] columnMap = getColumnMap(elements, projectedSymbols);
// Apply query criteria to tuples
@@ -128,13 +126,9 @@
// Build lookupMap from BOTH all the elements and the projected symbols - both may be needed here
Map lookupMap = new HashMap();
for(int i=0; i<elements.size(); i++) {
- Object element = elements.get(i);
+ ElementSymbol element = elements.get(i);
mapElementToIndex(lookupMap, element, new Integer(i), group);
}
- for(int i=0; i<projectedSymbols.size(); i++) {
- Object element = projectedSymbols.get(i);
- mapElementToIndex(lookupMap, element, new Integer(columnMap[i]), group);
- }
List filteredTuples = new ArrayList();
for(int i=0; i<tuples.length; i++) {
@@ -192,10 +186,9 @@
* @param integer
* @param group
*/
- private void mapElementToIndex(Map lookupMap, Object element, Integer index, GroupSymbol group) {
+ private void mapElementToIndex(Map lookupMap, ElementSymbol elementSymbol, Integer index, GroupSymbol group) {
if (group.getDefinition() != null){
String groupAlias = group.getCanonicalName();
- ElementSymbol elementSymbol = (ElementSymbol)SymbolMap.getExpression((SingleElementSymbol)element);
String newName = groupAlias + "." + elementSymbol.getShortName(); //$NON-NLS-1$
ElementSymbol aliasedElement = new ElementSymbol(newName, elementSymbol.getDisplayFullyQualified());
aliasedElement.setGroupSymbol(elementSymbol.getGroupSymbol());
@@ -203,28 +196,22 @@
aliasedElement.setType(elementSymbol.getType());
lookupMap.put(aliasedElement, index);
} else {
- lookupMap.put(element, index);
+ lookupMap.put(elementSymbol, index);
}
}
// columnMap[expectedElementIndex] = allElementIndex
- private int[] getColumnMap(List allElements, List expectedElements) {
+ private int[] getColumnMap(List<ElementSymbol> allElements, List<DerivedColumn> expectedElements) {
int[] map = new int[expectedElements.size()];
for(int i=0; i<expectedElements.size(); i++) {
- SingleElementSymbol symbol = (SingleElementSymbol) expectedElements.get(i);
+ DerivedColumn symbol = expectedElements.get(i);
- if (symbol instanceof AliasSymbol) {
- symbol = ((AliasSymbol)symbol).getSymbol();
- }
-
- String shortName = symbol.getShortName();
-
// Find matching short name in all elements
boolean foundMatch = false;
for(int j=0; j<allElements.size(); j++) {
- SingleElementSymbol tupleSymbol = (SingleElementSymbol) allElements.get(j);
- if(tupleSymbol.getShortName().equalsIgnoreCase(shortName)) {
+ ElementSymbol tupleSymbol = allElements.get(j);
+ if(tupleSymbol.equals(symbol.getExpression())) {
map[i] = j;
foundMatch = true;
break;
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -60,11 +60,10 @@
import com.metamatrix.query.sql.lang.StoredProcedure;
import com.metamatrix.query.sql.lang.Update;
import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.DerivedColumn;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.visitor.CorrelatedReferenceCollectorVisitor;
import com.metamatrix.query.unittest.FakeMetadataFacade;
import com.metamatrix.query.unittest.FakeMetadataFactory;
@@ -2001,9 +2000,9 @@
union = (SetQuery)QueryRewriter.rewrite(union, null, FakeMetadataFactory.example1Cached(), null);
for (QueryCommand query : union.getQueryCommands()) {
- List projSymbols = query.getProjectedSymbols();
- for(int i=0; i<projSymbols.size(); i++) {
- assertEquals("Found type mismatch at column " + i, types[i], ((SingleElementSymbol) projSymbols.get(i)).getType()); //$NON-NLS-1$
+ int i = 0;
+ for (DerivedColumn column : query.getProjectedSymbols()) {
+ assertEquals("Found type mismatch at column " + i, types[i++], column.getType()); //$NON-NLS-1$
}
}
}
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestAliasSymbol.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestAliasSymbol.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestAliasSymbol.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -24,16 +24,15 @@
import junit.framework.TestCase;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.DerivedColumn;
public class TestAliasSymbol extends TestCase {
public void testAliasEquals() {
- AliasSymbol a1 = new AliasSymbol("X", new DerivedColumn("x", new Constant(1))); //$NON-NLS-1$ //$NON-NLS-2$
- AliasSymbol a2 = new AliasSymbol("X", new DerivedColumn("x", new Constant(2))); //$NON-NLS-1$ //$NON-NLS-2$
- AliasSymbol a3 = new AliasSymbol("x", new DerivedColumn("x", new Constant(1))); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn a1 = new DerivedColumn("X", new Constant(1)); //$NON-NLS-1$
+ DerivedColumn a2 = new DerivedColumn("X", new Constant(2)); //$NON-NLS-1$
+ DerivedColumn a3 = new DerivedColumn("x", new Constant(1)); //$NON-NLS-1$
assertEquals(a1, a3); //just a different case for the alias
@@ -41,9 +40,9 @@
}
public void testClone() {
- AliasSymbol a1 = new AliasSymbol("X", new DerivedColumn("x", new Constant(1))); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn a1 = new DerivedColumn("x", new Constant(1)); //$NON-NLS-1$
a1.setOutputName("foo"); //$NON-NLS-1$
- AliasSymbol clone = (AliasSymbol)a1.clone();
+ DerivedColumn clone = (DerivedColumn)a1.clone();
assertEquals(a1, clone);
assertEquals(a1.getOutputName(), clone.getOutputName());
}
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestBatchedUpdateCommand.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestBatchedUpdateCommand.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestBatchedUpdateCommand.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -28,7 +28,7 @@
import junit.framework.TestCase;
import com.metamatrix.query.metadata.BasicQueryMetadata;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
@@ -84,7 +84,7 @@
From from = new From();
from.addGroup(g);
- AliasSymbol as = new AliasSymbol("myA", new ElementSymbol("a")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn as = new DerivedColumn("myA", new ElementSymbol("a"), true); //$NON-NLS-1$ //$NON-NLS-2$
Select select = new Select();
select.addSymbol(as);
select.addSymbol(new ElementSymbol("b")); //$NON-NLS-1$
@@ -103,7 +103,7 @@
Into into = new Into();
into.setGroup(new GroupSymbol("intoGroup"));//$NON-NLS-1$
- AliasSymbol as = new AliasSymbol("myA", new ElementSymbol("a")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn as = new DerivedColumn("myA", new ElementSymbol("a"), true); //$NON-NLS-1$ //$NON-NLS-2$
Select select = new Select();
select.addSymbol(as);
select.addSymbol(new ElementSymbol("b")); //$NON-NLS-1$
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestQuery.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestQuery.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestQuery.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -30,6 +30,7 @@
import com.metamatrix.common.types.ClobType;
import com.metamatrix.common.types.XMLType;
import com.metamatrix.core.util.UnitTestUtil;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
@@ -148,8 +149,8 @@
public void testClone2() {
Query q = sample2();
- List projectedSymbols = q.getProjectedSymbols();
- assertTrue(projectedSymbols == q.getProjectedSymbols());
+ List<DerivedColumn> projectedSymbols = q.getProjectedSymbols();
+ assertEquals(projectedSymbols, q.getProjectedSymbols());
Query qclone = (Query)q.clone();
int equals = 0;
UnitTestUtil.helpTestEquivalence(equals, q, qclone);
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/proc/TestAssignmentStatement.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/proc/TestAssignmentStatement.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/proc/TestAssignmentStatement.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -33,6 +33,7 @@
import com.metamatrix.query.sql.lang.Select;
import com.metamatrix.query.sql.lang.UnaryFromClause;
import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
@@ -57,7 +58,7 @@
public static final AssignmentStatement sample2() {
Query query = new Query();
- query.setSelect(new Select(Arrays.asList(new ElementSymbol("x")))); //$NON-NLS-1$
+ query.setSelect(new Select(Arrays.asList(new DerivedColumn(new ElementSymbol("x"))))); //$NON-NLS-1$
query.setFrom(new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("y"))))); //$NON-NLS-1$
return new AssignmentStatement(new ElementSymbol("b"), query); //$NON-NLS-1$
}
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestAggregateSymbolCollectorVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestAggregateSymbolCollectorVisitor.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestAggregateSymbolCollectorVisitor.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -30,7 +30,7 @@
import com.metamatrix.api.exception.query.QueryParserException;
import com.metamatrix.query.parser.QueryParser;
import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.Expression;
public class TestAggregateSymbolCollectorVisitor extends TestCase {
@@ -44,8 +44,8 @@
Command command = QueryParser.getQueryParser().parseCommand(sql);
// Find aggregates
- List<SingleElementSymbol> foundAggs = new ArrayList<SingleElementSymbol>();
- List<SingleElementSymbol> foundElements = new ArrayList<SingleElementSymbol>();
+ List<Expression> foundAggs = new ArrayList<Expression>();
+ List<Expression> foundElements = new ArrayList<Expression>();
AggregateSymbolCollectorVisitor.getAggregates(command, foundAggs, foundElements);
// Compare
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestSQLStringVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestSQLStringVisitor.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestSQLStringVisitor.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -66,6 +66,7 @@
import com.metamatrix.query.sql.lang.UnaryFromClause;
import com.metamatrix.query.sql.lang.Update;
import com.metamatrix.query.sql.lang.XQuery;
+import com.metamatrix.query.sql.lang.OrderByItem.OrderSpecification;
import com.metamatrix.query.sql.lang.SetQuery.Operation;
import com.metamatrix.query.sql.proc.AssignmentStatement;
import com.metamatrix.query.sql.proc.Block;
@@ -598,8 +599,8 @@
public void testOrderBy3() {
OrderBy ob = new OrderBy();
- ob.addVariable(new ElementSymbol("e1"), OrderBy.DESC); //$NON-NLS-1$
- ob.addVariable(new ElementSymbol("x"), OrderBy.DESC); //$NON-NLS-1$
+ ob.addVariable(new ElementSymbol("e1"), OrderSpecification.DESC); //$NON-NLS-1$
+ ob.addVariable(new ElementSymbol("x"), OrderSpecification.DESC); //$NON-NLS-1$
helpTest(ob, "ORDER BY e1 DESC, x DESC"); //$NON-NLS-1$
}
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestStaticSymbolMappingVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestStaticSymbolMappingVisitor.java 2009-03-03 19:50:13 UTC (rev 533)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestStaticSymbolMappingVisitor.java 2009-03-03 23:05:42 UTC (rev 534)
@@ -192,7 +192,7 @@
OrderBy ob = new OrderBy();
ob.addVariable(exampleElement(true, 0));
ob.addVariable(exampleElement(true, 1));
- ob.addVariable(new DerivedColumn("abc", exampleElement(true, 2), true)); //$NON-NLS-1$
+ ob.addVariable(exampleElement(true, 2));
helpTest(ob, getSymbolMap());
}
16 years, 7 months
teiid SVN: r533 - in branches/symbol_refactoring_61/engine/src: main/java/com/metamatrix/query/metadata and 11 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-03-03 14:50:13 -0500 (Tue, 03 Mar 2009)
New Revision: 533
Added:
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/TypedLanguageObject.java
Modified:
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/metadata/TempMetadataStore.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/xml/SourceNodePlannerVisitor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/ProcedureContainerResolver.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/QueryResolver.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/DynamicCommandResolver.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/InsertResolver.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/TempTableResolver.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Create.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/DynamicCommand.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Insert.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/StoredProcedure.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/DerivedColumn.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Expression.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/ScalarSubquery.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/AggregateSymbolCollectorVisitor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/AggregateValidationVisitor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
branches/symbol_refactoring_61/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
Log:
basic validation tests are now passing
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -58,7 +58,7 @@
import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.DerivedColumn;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.Reference;
@@ -480,7 +480,7 @@
private Object internalEvaluate(Expression expression, List tuple)
throws ExpressionEvaluationException, BlockedException, MetaMatrixComponentException {
- if(expression instanceof SingleElementSymbol) {
+ if(expression instanceof Aggregate || expression instanceof ElementSymbol) {
// Case 5155: elements must be non-null
Assertion.isNotNull( elements );
@@ -489,12 +489,6 @@
if(index != null) {
return tuple.get(index.intValue());
}
- // Otherwise this should be an ExpressionSymbol and we just need to dive in and evaluate the expression itself
- if (expression instanceof DerivedColumn && !(expression instanceof Aggregate)) {
- DerivedColumn exprSyb = (DerivedColumn) expression;
- Expression expr = exprSyb.getExpression();
- return internalEvaluate(expr, tuple);
- }
// instead of assuming null, throw an exception. a problem in planning has occurred
throw new MetaMatrixComponentException(ErrorMessageKeys.PROCESSOR_0033, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0033, expression, "No value was available")); //$NON-NLS-1$
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/metadata/TempMetadataStore.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/metadata/TempMetadataStore.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/metadata/TempMetadataStore.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -76,7 +76,7 @@
* @param tempGroup Name of temp group
* @param tempSymbols List of ElementSymbol in position order
*/
- public TempMetadataID addTempGroup(String tempGroup, List tempSymbols) {
+ public TempMetadataID addTempGroup(String tempGroup, List<DerivedColumn> tempSymbols) {
return addTempGroup(tempGroup, tempSymbols, true);
}
@@ -86,7 +86,7 @@
* @param tempSymbols List of ElementSymbol in position order
* @param isVirtual whether or not the group is a virtual group
*/
- public TempMetadataID addTempGroup(String tempGroup, List tempSymbols, boolean isVirtual) {
+ public TempMetadataID addTempGroup(String tempGroup, List<DerivedColumn> tempSymbols, boolean isVirtual) {
return addTempGroup(tempGroup, tempSymbols, isVirtual, false);
}
@@ -103,12 +103,10 @@
// Add the temporary group
String tempName = tempGroup.toUpperCase();
- List elementIDs = new ArrayList(tempSymbols.size());
+ List<TempMetadataID> elementIDs = new ArrayList<TempMetadataID>(tempSymbols.size());
for (DerivedColumn symbol : tempSymbols) {
- TempMetadataID elementID = createElementSymbol(tempName, symbol, isTempTable);
-
- elementIDs.add(elementID);
+ elementIDs.add(createElementSymbol(tempName, symbol, isTempTable));
}
// Create group ID
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/xml/SourceNodePlannerVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/xml/SourceNodePlannerVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/xml/SourceNodePlannerVisitor.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -230,14 +230,14 @@
throws QueryMetadataException, MetaMatrixComponentException, QueryResolverException, QueryPlannerException {
// get elements in the old group
- List elements = ResolverUtil.resolveElementsInGroup(oldSymbol, planEnv.getGlobalMetadata());
+ List<ElementSymbol> elements = ResolverUtil.resolveElementsInGroup(oldSymbol, planEnv.getGlobalMetadata());
TempMetadataStore store = planEnv.getGlobalMetadata().getMetadataStore();
// create a new group name and to the temp store
String newGroup = getNewName(oldSymbol.getName(), store);
GroupSymbol newGroupSymbol = new GroupSymbol(newGroup);
- newGroupSymbol.setMetadataID(store.addTempGroup(newGroup, elements));
+ newGroupSymbol.setMetadataID(store.addTempGroup(newGroup, ResolverUtil.convertToDerivedColumns(elements)));
// create a symbol map; so that all the others who refer by the old name can use this map
// to convert to new group.
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/ProcedureContainerResolver.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/ProcedureContainerResolver.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/ProcedureContainerResolver.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -45,6 +45,7 @@
import com.metamatrix.query.sql.lang.GroupContext;
import com.metamatrix.query.sql.lang.ProcedureContainer;
import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.util.ErrorMessageKeys;
@@ -141,25 +142,25 @@
procCmd.setUserCommand(container);
//Look up elements for the virtual group
- List elements = ResolverUtil.resolveElementsInGroup(group, metadata);
+ List<ElementSymbol> elements = ResolverUtil.resolveElementsInGroup(group, metadata);
// Create the INPUT variables
- List inputElments = new ArrayList(elements.size());
+ List<DerivedColumn> inputElments = new ArrayList<DerivedColumn>(elements.size());
for(int i=0; i<elements.size(); i++) {
- ElementSymbol virtualElmnt = (ElementSymbol)elements.get(i);
+ ElementSymbol virtualElmnt = elements.get(i);
ElementSymbol inputElement = (ElementSymbol)virtualElmnt.clone();
- inputElments.add(inputElement);
+ inputElments.add(new DerivedColumn(inputElement));
}
addScalarGroup(ProcedureReservedWords.INPUT, discoveredMetadata, externalGroups, inputElments);
// Switch type to be boolean for all CHANGING variables
- List changingElements = new ArrayList(elements.size());
+ List<DerivedColumn> changingElements = new ArrayList<DerivedColumn>(elements.size());
for(int i=0; i<elements.size(); i++) {
- ElementSymbol virtualElmnt = (ElementSymbol)elements.get(i);
+ ElementSymbol virtualElmnt = elements.get(i);
ElementSymbol changeElement = (ElementSymbol)virtualElmnt.clone();
changeElement.setType(DataTypeManager.DefaultDataClasses.BOOLEAN);
- changingElements.add(changeElement);
+ changingElements.add(new DerivedColumn(changeElement));
}
addScalarGroup(ProcedureReservedWords.CHANGING, discoveredMetadata, externalGroups, changingElements);
@@ -222,7 +223,7 @@
ResolverVisitorUtil.resolveGroup(group, metadata);
}
- public static GroupSymbol addScalarGroup(String name, TempMetadataStore metadata, GroupContext externalGroups, List symbols) {
+ public static GroupSymbol addScalarGroup(String name, TempMetadataStore metadata, GroupContext externalGroups, List<DerivedColumn> symbols) {
GroupSymbol variables = new GroupSymbol(name);
externalGroups.addGroup(variables);
TempMetadataID tid = metadata.addTempGroup(name, symbols);
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/QueryResolver.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/QueryResolver.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/QueryResolver.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -51,6 +51,7 @@
import com.metamatrix.query.resolver.command.UpdateResolver;
import com.metamatrix.query.resolver.command.XMLQueryResolver;
import com.metamatrix.query.resolver.command.XQueryResolver;
+import com.metamatrix.query.resolver.util.ResolverUtil;
import com.metamatrix.query.resolver.util.ResolverVisitor;
import com.metamatrix.query.resolver.util.ResolverVisitorUtil;
import com.metamatrix.query.sql.lang.Command;
@@ -60,6 +61,7 @@
import com.metamatrix.query.sql.lang.GroupContext;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.UnaryFromClause;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.util.ErrorMessageKeys;
import com.metamatrix.query.util.LogConstants;
@@ -139,8 +141,8 @@
for(Iterator iter = externalMetadata.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry)iter.next();
GroupSymbol group = (GroupSymbol) entry.getKey();
- List elements = (List) entry.getValue();
- rootExternalStore.addTempGroup(group.getName(), elements);
+ List<ElementSymbol> elements = (List<ElementSymbol>) entry.getValue();
+ rootExternalStore.addTempGroup(group.getName(), ResolverUtil.convertToDerivedColumns(elements));
currentCommand.addExternalGroupToContext(group);
}
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/DynamicCommandResolver.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/DynamicCommandResolver.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/DynamicCommandResolver.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -98,8 +98,8 @@
if (!intoSymbol.isImplicitTempGroupSymbol()) {
ResolverVisitorUtil.resolveGroup(intoSymbol, metadata);
} else {
- List symbols = dynamicCmd.getAsColumns();
- ResolverUtil.resolveImplicitTempGroup(metadata, intoSymbol, symbols);
+ List<ElementSymbol> symbols = dynamicCmd.getAsColumns();
+ ResolverUtil.resolveImplicitTempGroup(metadata, intoSymbol, ResolverUtil.convertToDerivedColumns(symbols));
}
}
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -54,6 +54,7 @@
import com.metamatrix.query.sql.lang.StoredProcedure;
import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
@@ -218,7 +219,7 @@
// Create temporary metadata that defines a group based on either the stored proc
// name or the stored query name - this will be used later during planning
String procName = storedProcedureCommand.getProcedureName();
- List tempElements = storedProcedureCommand.getProjectedSymbols();
+ List<DerivedColumn> tempElements = storedProcedureCommand.getProjectedSymbols();
boolean isVirtual = storedProcedureInfo.getQueryPlan() != null;
discoveredMetadata.addTempGroup(procName, tempElements, isVirtual);
@@ -247,13 +248,13 @@
GroupContext context = new GroupContext();
// Look through parameters to find input elements - these become child metadata
- List tempElements = new ArrayList();
+ List<DerivedColumn> tempElements = new ArrayList<DerivedColumn>();
Iterator iter = storedProcedureCommand.getParameters().iterator();
while(iter.hasNext()) {
SPParameter param = (SPParameter) iter.next();
if(param.getParameterType() == ParameterInfo.IN || param.getParameterType() == ParameterInfo.INOUT) {
ElementSymbol symbol = param.getParameterSymbol();
- tempElements.add(symbol);
+ tempElements.add(new DerivedColumn(symbol));
}
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/InsertResolver.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/InsertResolver.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/InsertResolver.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -52,6 +52,7 @@
import com.metamatrix.query.sql.lang.Insert;
import com.metamatrix.query.sql.lang.ProcedureContainer;
import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
@@ -108,7 +109,7 @@
if(insert.getQueryExpression() != null) {
ResolverUtil.resolveImplicitTempGroup(metadata, insert.getGroup(), insert.getQueryExpression().getProjectedSymbols());
}else {
- ResolverUtil.resolveImplicitTempGroup(metadata, insert.getGroup(), insert.getVariables());
+ ResolverUtil.resolveImplicitTempGroup(metadata, insert.getGroup(), ResolverUtil.convertToDerivedColumns(insert.getVariables()));
}
resolveVariables(metadata, insert, groups);
@@ -145,15 +146,29 @@
boolean usingQuery = insert.getQueryExpression() != null;
- // resolve any functions in the values
- List values = insert.getValues();
-
if (usingQuery) {
- values = insert.getQueryExpression().getProjectedSymbols();
+ List<DerivedColumn> columns = insert.getQueryExpression().getProjectedSymbols();
+ // check that # of variables == # of values
+ if(columns.size() != insert.getVariables().size()) {
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0010, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0010, new Object[] {new Integer(insert.getVariables().size()), new Integer(insert.getValues().size())}));
+ }
+ Iterator<ElementSymbol> iterator = insert.getVariables().iterator();
+ for (DerivedColumn column : columns) {
+ ElementSymbol element = iterator.next();
+ if (element.getType() != column.getType()
+ && !DataTypeManager.isImplicitConversion(DataTypeManager.getDataTypeName(column.getType()),
+ DataTypeManager.getDataTypeName(element.getType()))) {
+ //TODO: a special case here is a projected literal
+ throw new QueryResolverException(QueryPlugin.Util.getString("InsertResolver.cant_convert_query_type", new Object[] {column, column.getType().getName(), element, element.getType().getName()})); //$NON-NLS-1$
+ }
+ }
+ return;
}
+
+ // resolve any functions in the values
+ List<Expression> values = insert.getValues();
+ List<Expression> newValues = new ArrayList<Expression>(values.size());
- List newValues = new ArrayList(values.size());
-
// check that # of variables == # of values
if(values.size() != insert.getVariables().size()) {
throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0010, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0010, new Object[] {new Integer(insert.getVariables().size()), new Integer(insert.getValues().size())}));
@@ -168,20 +183,13 @@
if(element.getType() != null && expression.getType() != null) {
String elementTypeName = DataTypeManager.getDataTypeName(element.getType());
- if (!usingQuery) {
- newValues.add(ResolverUtil.convertExpression(expression, elementTypeName));
- } else if (element.getType() != expression.getType()
- && !DataTypeManager.isImplicitConversion(DataTypeManager.getDataTypeName(expression.getType()),
- DataTypeManager.getDataTypeName(element.getType()))) {
- //TODO: a special case here is a projected literal
- throw new QueryResolverException(QueryPlugin.Util.getString("InsertResolver.cant_convert_query_type", new Object[] {expression, expression.getType().getName(), element, element.getType().getName()})); //$NON-NLS-1$
- }
+ newValues.add(ResolverUtil.convertExpression(expression, elementTypeName));
} else if(element.getType() != null && expression.getType() == null && expression instanceof Reference){
Reference ref = (Reference)expression;
//set the type of reference to be the same as variable
ref.setExpression(new Constant(null, element.getType()));
newValues.add(ref);
- } else if (element.getType() == null && expression.getType() != null && !usingQuery) {
+ } else if (element.getType() == null && expression.getType() != null) {
element.setType(expression.getType());
newValues.add(expression);
} else {
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/TempTableResolver.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/TempTableResolver.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/TempTableResolver.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -77,7 +77,7 @@
//if we get here then either the group does not exist or has already been defined as a temp table
//if it has been defined as a temp table, that's ok we'll use this as the new definition and throw an
//exception at runtime if the user has not dropped the previous table yet
- ResolverUtil.addTempTable(metadata, group, create.getColumns());
+ ResolverUtil.addTempTable(metadata, group, ResolverUtil.convertToDerivedColumns(create.getColumns()));
ResolverVisitorUtil.resolveGroup(((Create)command).getTable(), metadata);
Set groups = new HashSet();
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -66,6 +66,7 @@
import com.metamatrix.query.sql.proc.LoopStatement;
import com.metamatrix.query.sql.proc.Statement;
import com.metamatrix.query.sql.proc.WhileStatement;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
@@ -151,7 +152,7 @@
//by creating a new group context here it means that variables will resolve with a higher precedence than input/changing
GroupContext externalGroups = command.getExternalGroupContexts();
- List symbols = new LinkedList();
+ List<DerivedColumn> symbols = new LinkedList<DerivedColumn>();
// virtual group elements in HAS and TRANSLATE criteria have to be resolved
if(procCommand.isUpdateProcedure()){
@@ -161,7 +162,7 @@
String countVar = ProcedureReservedWords.VARIABLES + ElementSymbol.SEPARATOR + ProcedureReservedWords.ROWS_UPDATED;
ElementSymbol updateCount = new ElementSymbol(countVar);
updateCount.setType(DataTypeManager.DefaultDataClasses.INTEGER);
- symbols.add(updateCount);
+ symbols.add(new DerivedColumn(updateCount));
ProcedureContainerResolver.addScalarGroup(ProcedureReservedWords.VARIABLES, metadata.getMetadataStore(), externalGroups, symbols);
}
@@ -300,7 +301,7 @@
}
Command cmd = loopStmt.getCommand();
resolveEmbeddedCommand(metadata, externalGroups, cmd, expandCommand, analysis);
- List symbols = cmd.getProjectedSymbols();
+ List<DerivedColumn> symbols = cmd.getProjectedSymbols();
//add the loop cursor group into its own context
TempMetadataStore store = new TempMetadataStore(new HashMap(metadata.getMetadataStore().getData()));
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -266,12 +266,11 @@
Constant c = (Constant)orderByItem.getSortKey();
if (DataTypeManager.DefaultDataClasses.INTEGER == c.getType()) {
int value = (Integer)c.getValue();
- if (value < 0 || value > knownElements.size() -1) {
+ if (value < 1 || value > knownElements.size()) {
throw new QueryResolverException("Invalid order by ordinal");
}
- DerivedColumn matchedSymbol = knownElements.get(value);
- ElementSymbol symbol = new ElementSymbol(matchedSymbol.getName());
- resolveOrderByItem(value, symbol, matchedSymbol);
+ orderByItem.setOrdinalPosition(value);
+ orderByItem.setType(knownElements.get(value - 1).getType());
continue;
}
}
@@ -299,7 +298,7 @@
Expression expr = knownSymbol.getExpression();
//special check for uuid element symbols
- if (expr instanceof ElementSymbol && knownSymbol.getShortName().equalsIgnoreCase(knownSymbol.getName())) {
+ if (!knownSymbol.isAlias() && expr instanceof ElementSymbol && knownSymbol.getShortName().equalsIgnoreCase(knownSymbol.getName())) {
name = metadata.getShortElementName(metadata.getFullName((((ElementSymbol)expr).getMetadataID())));
}
@@ -446,9 +445,9 @@
* The resolved elements may not contain non-selectable columns depending on the metadata first used for resolving.
*
*/
- public static List resolveElementsInGroup(GroupSymbol group, QueryMetadataInterface metadata)
+ public static List<ElementSymbol> resolveElementsInGroup(GroupSymbol group, QueryMetadataInterface metadata)
throws QueryMetadataException, MetaMatrixComponentException {
- return new ArrayList(getGroupInfo(group, metadata).getSymbolList());
+ return new ArrayList<ElementSymbol>(getGroupInfo(group, metadata).getSymbolList());
}
static GroupInfo getGroupInfo(GroupSymbol group,
@@ -549,7 +548,7 @@
setTypeIfReference(limit.getRowLimit(), DataTypeManager.DefaultDataClasses.INTEGER, limit);
}
- public static void resolveImplicitTempGroup(TempMetadataAdapter metadata, GroupSymbol symbol, List symbols)
+ public static void resolveImplicitTempGroup(TempMetadataAdapter metadata, GroupSymbol symbol, List<DerivedColumn> symbols)
throws MetaMatrixComponentException, QueryResolverException {
if (symbol.isImplicitTempGroupSymbol()) {
@@ -563,11 +562,10 @@
public static void addTempGroup(TempMetadataAdapter metadata,
GroupSymbol symbol,
List<DerivedColumn> symbols, boolean tempTable) throws QueryResolverException {
- HashSet names = new HashSet();
- for (Iterator i = symbols.iterator(); i.hasNext();) {
- DerivedColumn ses = (DerivedColumn)i.next();
- if (!names.add(ses.getShortCanonicalName())) {
- throw new QueryResolverException(QueryPlugin.Util.getString("ResolverUtil.duplicateName", symbol, ses.getShortName())); //$NON-NLS-1$
+ HashSet<String> names = new HashSet<String>();
+ for (DerivedColumn derivedColumn : symbols) {
+ if (!names.add(derivedColumn.getShortCanonicalName())) {
+ throw new QueryResolverException(QueryPlugin.Util.getString("ResolverUtil.duplicateName", symbol, derivedColumn.getShortName())); //$NON-NLS-1$
}
}
@@ -580,7 +578,7 @@
public static void addTempTable(TempMetadataAdapter metadata,
GroupSymbol symbol,
- List symbols) throws QueryResolverException {
+ List<DerivedColumn> symbols) throws QueryResolverException {
addTempGroup(metadata, symbol, symbols, true);
}
@@ -718,4 +716,13 @@
//return false;
}
+ public static List<DerivedColumn> convertToDerivedColumns(List<ElementSymbol> symbols) {
+ List<DerivedColumn> result = new ArrayList<DerivedColumn>();
+ //add result set columns
+ for (ElementSymbol elementSymbol : symbols) {
+ result.add(new DerivedColumn(elementSymbol));
+ }
+ return result;
+ }
+
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -55,6 +55,7 @@
import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.Function;
@@ -375,11 +376,11 @@
}
String exprTypeName = DataTypeManager.getDataTypeName(exprType);
- Collection projectedSymbols = crit.getCommand().getProjectedSymbols();
+ List<DerivedColumn> projectedSymbols = crit.getCommand().getProjectedSymbols();
if (projectedSymbols.size() != 1){
throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0032, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0032, crit.getCommand()));
}
- Class subqueryType = ((Expression)projectedSymbols.iterator().next()).getType();
+ Class subqueryType = projectedSymbols.get(0).getType();
String subqueryTypeName = DataTypeManager.getDataTypeName(subqueryType);
Expression result = null;
try {
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Create.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Create.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Create.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -30,6 +30,8 @@
import com.metamatrix.core.util.HashCodeUtil;
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.visitor.SQLStringVisitor;
@@ -40,7 +42,7 @@
/** Identifies the table to be created. */
private GroupSymbol table;
- private List columns = new ArrayList();
+ private List<ElementSymbol> columns = new ArrayList<ElementSymbol>();
public GroupSymbol getTable() {
return table;
@@ -50,7 +52,7 @@
this.table = table;
}
- public List getColumns() {
+ public List<ElementSymbol> getColumns() {
return columns;
}
@@ -79,7 +81,7 @@
* @see com.metamatrix.query.sql.lang.Command#getProjectedSymbols()
* @since 5.5
*/
- public List getProjectedSymbols() {
+ public List<DerivedColumn> getProjectedSymbols() {
return Command.getUpdateCommandSymbol();
}
@@ -107,7 +109,7 @@
visitor.visit(this);
}
- public void setColumns(List columns) {
+ public void setColumns(List<ElementSymbol> columns) {
this.columns = columns;
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/DynamicCommand.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/DynamicCommand.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/DynamicCommand.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -41,7 +41,7 @@
private Expression sql;
- private List asColumns;
+ private List<ElementSymbol> asColumns;
private GroupSymbol intoGroup;
@@ -55,7 +55,7 @@
super();
}
- public DynamicCommand(Expression sql, List columns, GroupSymbol intoGroup, SetClauseList using) {
+ public DynamicCommand(Expression sql, List<ElementSymbol> columns, GroupSymbol intoGroup, SetClauseList using) {
super();
this.sql = sql;
this.asColumns = columns;
@@ -156,9 +156,9 @@
/**
* @return Returns the columns.
*/
- public List getAsColumns() {
+ public List<ElementSymbol> getAsColumns() {
if (this.asColumns == null) {
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
return this.asColumns;
}
@@ -166,7 +166,7 @@
/**
* @param columns The columns to set.
*/
- public void setAsColumns(List columns) {
+ public void setAsColumns(List<ElementSymbol> columns) {
this.asColumns = columns;
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Insert.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Insert.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Insert.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -48,10 +48,10 @@
private GroupSymbol group;
/** list of column variables, null = all columns */
- private List variables = new LinkedList();
+ private List<ElementSymbol> variables = new LinkedList<ElementSymbol>();
/** List of Expressions, required */
- private List values = new LinkedList();
+ private List<Expression> values = new LinkedList<Expression>();
private QueryCommand queryExpression;
@@ -109,7 +109,7 @@
* Return an ordered List of variables, may be null if no columns were specified
* @return List of {@link com.metamatrix.query.sql.symbol.ElementSymbol}
*/
- public List getVariables() {
+ public List<ElementSymbol> getVariables() {
return variables;
}
@@ -134,7 +134,7 @@
* to be inserted.
* @return List of {@link com.metamatrix.query.sql.symbol.Expression}s
*/
- public List getValues() {
+ public List<Expression> getValues() {
return this.values;
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -1,11 +1,33 @@
package com.metamatrix.query.sql.lang;
-import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.LanguageVisitor;
import com.metamatrix.query.sql.symbol.Expression;
+import com.metamatrix.query.sql.symbol.TypedLanguageObject;
import com.metamatrix.query.sql.visitor.SQLStringVisitor;
-public class OrderByItem implements LanguageObject {
+/*
+ * 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.
+ */
+
+public class OrderByItem implements TypedLanguageObject {
public enum OrderSpecification {
ASC,
@@ -14,6 +36,10 @@
private Expression sortKey;
private OrderSpecification orderingSpecification;
+ //set after resolving is this is a SQL-92 unsigned int
+ private int ordinalPosition;
+ //set after resolving
+ private Class<?> type;
public OrderByItem(Expression sortKey, OrderSpecification orderingSpecification) {
this.orderingSpecification = orderingSpecification;
@@ -40,14 +66,37 @@
this.orderingSpecification = orderingSpecification;
}
+ public int getOrdinalPosition() {
+ return ordinalPosition;
+ }
+
+ public void setOrdinalPosition(int ordinalPosition) {
+ this.ordinalPosition = ordinalPosition;
+ }
+
@Override
+ public Class<?> getType() {
+ if (type == null) {
+ type = this.sortKey.getType();
+ }
+ return type;
+ }
+
+ public void setType(Class<?> type) {
+ this.type = type;
+ }
+
+ @Override
public void acceptVisitor(LanguageVisitor visitor) {
visitor.visit(this);
}
@Override
public Object clone() {
- return new OrderByItem((Expression)sortKey.clone(), orderingSpecification);
+ OrderByItem clone = new OrderByItem((Expression)sortKey.clone(), orderingSpecification);
+ clone.ordinalPosition = this.ordinalPosition;
+ clone.type = this.type;
+ return clone;
}
@Override
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/StoredProcedure.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/StoredProcedure.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/StoredProcedure.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -33,7 +33,9 @@
import com.metamatrix.dqp.message.ParameterInfo;
import com.metamatrix.query.QueryPlugin;
+import com.metamatrix.query.resolver.util.ResolverUtil;
import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
@@ -188,10 +190,10 @@
return null;
}
- public List getResultSetColumns(){
+ public List<ElementSymbol> getResultSetColumns(){
SPParameter resultSetParameter = getResultSetParameter();
if(resultSetParameter != null){
- List result = new LinkedList();
+ List<ElementSymbol> result = new LinkedList<ElementSymbol>();
for (Iterator i = resultSetParameter.getResultSetColumns().iterator(); i.hasNext();) {
ElementSymbol symbol = (ElementSymbol)((ElementSymbol)i.next()).clone();
symbol.setGroupSymbol(getGroup());
@@ -199,7 +201,7 @@
}
return result;
}
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
public void acceptVisitor(LanguageVisitor visitor) {
@@ -253,11 +255,8 @@
* single column.
* @return Ordered list of SingleElementSymbol
*/
- public List getProjectedSymbols(){
- List result = new ArrayList();
- //add result set columns
- List rsColumns = getResultSetColumns();
- result.addAll(rsColumns);
+ public List<DerivedColumn> getProjectedSymbols(){
+ List<DerivedColumn> result = ResolverUtil.convertToDerivedColumns(getResultSetColumns());
if (!returnParameters()) {
return result;
}
@@ -268,7 +267,7 @@
if(parameter.getParameterType() == ParameterInfo.INOUT || parameter.getParameterType() == ParameterInfo.OUT){
ElementSymbol symbol = parameter.getParameterSymbol();
symbol.setGroupSymbol(getGroup());
- result.add(symbol);
+ result.add(new DerivedColumn(symbol));
}
}
//add return parameter
@@ -278,7 +277,7 @@
if(parameter.getParameterType() == ParameterInfo.RETURN_VALUE){
ElementSymbol symbol = parameter.getParameterSymbol();
symbol.setGroupSymbol(getGroup());
- result.add(symbol);
+ result.add(new DerivedColumn(symbol));
break;
}
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/DerivedColumn.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/DerivedColumn.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/DerivedColumn.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -28,7 +28,7 @@
* <p>This is a subclass of Symbol representing an expression in the SELECT clause. The
* expression may be a constant, function, or scalar subquery.</p>
*/
-public class DerivedColumn extends SelectSymbol {
+public class DerivedColumn extends SelectSymbol implements TypedLanguageObject {
private Expression expression;
private boolean alias;
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Expression.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Expression.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Expression.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -22,14 +22,13 @@
package com.metamatrix.query.sql.symbol;
-import com.metamatrix.query.sql.LanguageObject;
/**
* This is the interface for an expression in a SQL string. Expressions can be of several
* types (see subclasses), but all expressions have a type. These types are used for
* type checking.
*/
-public interface Expression extends LanguageObject {
+public interface Expression extends TypedLanguageObject {
/**
* Return true if expression has been fully resolved. Typically the QueryResolver component
@@ -37,12 +36,5 @@
* @return True if resolved
*/
boolean isResolved();
-
- /**
- * Get the return type of this expression. This method will not necessarily work right
- * before resolution ({@link #isResolved()} returns true).
- * @return Java class name
- */
- Class getType();
-
+
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/ScalarSubquery.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/ScalarSubquery.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/ScalarSubquery.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -102,8 +102,7 @@
*/
public Class getType() {
if (this.type == null){
- Expression symbol = (Expression)this.command.getProjectedSymbols().iterator().next();
- this.type = symbol.getType();
+ this.type = this.command.getProjectedSymbols().get(0).getType();
}
//may still be null if this.command wasn't resolved
return this.type;
Added: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/TypedLanguageObject.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/TypedLanguageObject.java (rev 0)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/TypedLanguageObject.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -0,0 +1,9 @@
+package com.metamatrix.query.sql.symbol;
+
+import com.metamatrix.query.sql.LanguageObject;
+
+public interface TypedLanguageObject extends LanguageObject {
+
+ Class<?> getType();
+
+}
Property changes on: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/TypedLanguageObject.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/AggregateSymbolCollectorVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/AggregateSymbolCollectorVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/AggregateSymbolCollectorVisitor.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -30,7 +30,6 @@
import com.metamatrix.query.sql.LanguageVisitor;
import com.metamatrix.query.sql.navigator.PreOrPostOrderNavigator;
import com.metamatrix.query.sql.symbol.Aggregate;
-import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
@@ -47,20 +46,6 @@
preVisitVisitor(obj);
postVisitVisitor(obj);
}
-
- /**
- * @see com.metamatrix.query.sql.navigator.PreOrPostOrderNavigator#visit(com.metamatrix.query.sql.symbol.DerivedColumn)
- */
- @Override
- public void visit(DerivedColumn obj) {
- if (obj.isDerivedExpression()) {
- preVisitVisitor(obj);
- postVisitVisitor(obj);
- } else {
- super.visit(obj);
- }
- }
-
}
private Collection<Aggregate> aggregates;
@@ -77,12 +62,6 @@
}
}
- public void visit(DerivedColumn obj) {
- if (this.groupingSymbols != null && obj.isDerivedExpression()) {
- this.groupingSymbols.add(obj.getExpression());
- }
- }
-
public void visit(ElementSymbol obj) {
if (this.groupingSymbols != null) {
this.groupingSymbols.add(obj);
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/AggregateValidationVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/AggregateValidationVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/AggregateValidationVisitor.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -84,7 +84,7 @@
}
public void visit(DerivedColumn obj) {
- validateExpression(obj);
+ validateExpression(obj.getExpression());
}
public void visit(CaseExpression obj) {
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -63,7 +63,7 @@
import com.metamatrix.query.sql.lang.MatchCriteria;
import com.metamatrix.query.sql.lang.NotCriteria;
import com.metamatrix.query.sql.lang.Option;
-import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.QueryCommand;
import com.metamatrix.query.sql.lang.Select;
@@ -88,14 +88,13 @@
import com.metamatrix.query.sql.symbol.AbstractCaseExpression;
import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
-import com.metamatrix.query.sql.util.SymbolMap;
+import com.metamatrix.query.sql.symbol.TypedLanguageObject;
import com.metamatrix.query.sql.visitor.AggregateSymbolCollectorVisitor;
import com.metamatrix.query.sql.visitor.CommandCollectorVisitor;
import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
@@ -158,18 +157,12 @@
public void visit(GroupBy obj) {
// Get list of all group by IDs
- List groupBySymbols = obj.getSymbols();
+ List<Expression> groupBySymbols = obj.getSymbols();
validateSortable(groupBySymbols);
- Iterator symbolIter = groupBySymbols.iterator();
- while(symbolIter.hasNext()) {
- SingleElementSymbol symbol = (SingleElementSymbol)symbolIter.next();
- if(symbol instanceof DerivedColumn) {
- DerivedColumn exprSymbol = (DerivedColumn) symbol;
- Expression expr = exprSymbol.getExpression();
- if(! (expr instanceof Function || expr instanceof AbstractCaseExpression)) {
- handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.Expr_in_GROUP_BY_must_be_elem_func_case", expr), expr); //$NON-NLS-1$
- }
- }
+ for (Expression expr : groupBySymbols) {
+ if(! (expr instanceof ElementSymbol || expr instanceof Function || expr instanceof AbstractCaseExpression)) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.Expr_in_GROUP_BY_must_be_elem_func_case", expr), expr); //$NON-NLS-1$
+ }
}
}
@@ -193,8 +186,9 @@
validateInsert(obj);
}
- public void visit(OrderBy obj) {
- validateSortable(obj.getVariables());
+ @Override
+ public void visit(OrderByItem obj) {
+ validateSortable(obj.getSortKey());
}
public void visit(Query obj) {
@@ -339,14 +333,14 @@
// set state command on this may contain translate criteria
this.transCommand = obj.getCommand();
- Collection projSymbols = transCommand.getProjectedSymbols();
+ List<DerivedColumn> projSymbols = transCommand.getProjectedSymbols();
//The command execution should result is a value that is assigned to the variable
// there cannot be more than one column in its results
if(projSymbols.size() != 1) {
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0013), obj);
} else {
- SingleElementSymbol value = (SingleElementSymbol) projSymbols.iterator().next();
+ DerivedColumn value = projSymbols.get(0);
Class valueType = value.getType();
Class varType = variable.getType();
if(!varType.equals(valueType)) {
@@ -617,17 +611,19 @@
* and ORDER BY.
* @param symbols List of SingleElementSymbol
*/
- protected void validateSortable(List symbols) {
- Iterator iter = symbols.iterator();
- while(iter.hasNext()) {
- SingleElementSymbol symbol = (SingleElementSymbol) iter.next();
- if (isNonComparable(symbol)) {
- handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0026, symbol), symbol);
- }
+ protected void validateSortable(List<? extends TypedLanguageObject> symbols) {
+ for (TypedLanguageObject typedLanguageObject : symbols) {
+ validateSortable(typedLanguageObject);
}
}
- public static boolean isNonComparable(Expression symbol) {
+ private void validateSortable(TypedLanguageObject symbol) {
+ if (isNonComparable(symbol)) {
+ handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0026, symbol), symbol);
+ }
+ }
+
+ public static boolean isNonComparable(TypedLanguageObject symbol) {
return DataTypeManager.isNonComparable(DataTypeManager.getDataTypeName(symbol.getType()));
}
@@ -704,10 +700,9 @@
Set<Expression> groupSymbols = null;
if(groupBy != null) {
groupSymbols = new HashSet<Expression>();
- for (final Iterator iterator = groupBy.getSymbols().iterator(); iterator.hasNext();) {
- final SingleElementSymbol element = (SingleElementSymbol)iterator.next();
- groupSymbols.add(SymbolMap.getExpression(element));
- }
+ for (Expression expression : groupBy.getSymbols()) {
+ groupSymbols.add(expression);
+ }
}
// Validate HAVING, if it exists
@@ -717,11 +712,8 @@
}
// Validate SELECT
- List projectedSymbols = select.getProjectedSymbols();
- Iterator symbolIter = projectedSymbols.iterator();
- while(symbolIter.hasNext()) {
- SingleElementSymbol symbol = (SingleElementSymbol) symbolIter.next();
- AggregateValidationVisitor.validate(symbol, visitor);
+ for (DerivedColumn column : select.getProjectedSymbols()) {
+ AggregateValidationVisitor.validate(column, visitor);
}
// Move items to this report
@@ -874,13 +866,13 @@
* @since 4.2
*/
protected void validateSelectInto(Query query) {
- List symbols = query.getSelect().getProjectedSymbols();
+ List<DerivedColumn> symbols = query.getSelect().getProjectedSymbols();
GroupSymbol intoGroup = query.getInto().getGroup();
validateInto(query, symbols, intoGroup);
}
private void validateInto(LanguageObject query,
- List symbols,
+ List<DerivedColumn> symbols,
GroupSymbol intoGroup) {
try {
List elementIDs = getMetadata().getElementIDsInGroupID(intoGroup.getMetadataID());
@@ -892,7 +884,7 @@
}
for (int symbolNum = 0; symbolNum < symbols.size(); symbolNum++) {
- SingleElementSymbol symbol = (SingleElementSymbol)symbols.get(symbolNum);
+ DerivedColumn symbol = symbols.get(symbolNum);
Object elementID = elementIDs.get(symbolNum);
// Check if supports updates
if (!getMetadata().elementSupports(elementID, SupportConstants.Element.UPDATE)) {
@@ -1037,7 +1029,7 @@
*/
public void visit(DynamicCommand obj) {
if (obj.getIntoGroup() != null) {
- validateInto(obj, obj.getAsColumns(), obj.getIntoGroup());
+ validateInto(obj, ResolverUtil.convertToDerivedColumns(obj.getAsColumns()), obj.getIntoGroup());
}
if (!CommandCollectorVisitor.getCommands(obj).isEmpty()) {
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.assignment_subquery"), obj); //$NON-NLS-1$
Modified: branches/symbol_refactoring_61/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj 2009-03-03 19:50:13 UTC (rev 533)
@@ -1485,9 +1485,14 @@
String name = null;
if (aliasToken == null) {
if(expression instanceof ElementSymbol) {
- name = ((ElementSymbol)expression).getShortName();
+ name = ((ElementSymbol)expression).getName();
} else {
- name = generateFunctionName(info, null);
+ String aggName = null;
+ if (expression instanceof Aggregate) {
+ Aggregate agg = (Aggregate)expression;
+ aggName = agg.getAggregateFunction();
+ }
+ name = generateFunctionName(info, aggName);
}
} else {
name = validateAlias(aliasToken.image);
@@ -2224,42 +2229,32 @@
*/
OrderBy orderby(ParseInfo info) :
{
- Token id = null;
+ Expression id = null;
Token type = null;
OrderBy orderby = new OrderBy();
boolean ascending = true;
}
{
<ORDER> <BY>
- (id=<VARIABLE> | id=<STRINGVAL> | id=<INTEGERVAL>) [<ASC> | type=<DESC>]
+ id=expression(info) [<ASC> | type=<DESC>]
{
ascending = true;
if(type != null) {
ascending = false;
type=null;
}
- if (StringUtil.isDigits(id.image)){
- orderby.addVariable(new ElementSymbol(id.image), ascending);
- }
- else{
- orderby.addVariable(new ElementSymbol(validateMetadataID(id.image)), ascending);
- }
+ orderby.addVariable(id, ascending);
}
(<COMMA>
- (id=<VARIABLE> | id=<STRINGVAL> | id=<INTEGERVAL>) [<ASC> | type=<DESC>]
+ id=expression(info) [<ASC> | type=<DESC>]
{
- ascending = true;
- if(type != null) {
- ascending = false;
- type=null;
- }
- if (StringUtil.isDigits(id.image)){
- orderby.addVariable(new ElementSymbol(id.image), ascending);
- }
- else{
- orderby.addVariable(new ElementSymbol(validateMetadataID(id.image)), ascending);
- }
- }
+ ascending = true;
+ if(type != null) {
+ ascending = false;
+ type=null;
+ }
+ orderby.addVariable(id, ascending);
+ }
)*
{
return orderby;
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -454,7 +454,7 @@
String sql = "SELECT pm1.g1.e1, e2, pm1.g1.e3 AS a, e4 AS b FROM pm1.g1"; //$NON-NLS-1$
Query resolvedQuery = (Query) helpResolve(sql);
helpCheckFrom(resolvedQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
- helpCheckSelect(resolvedQuery, new String[] { "pm1.g1.e1", "pm1.g1.e2", "a", "b" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ helpCheckSelect(resolvedQuery, new String[] { "pm1.g1.e1", "e2", "a", "b" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "pm1.g1.e1", "pm1.g1.e2", "pm1.g1.e3", "pm1.g1.e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "pm1.g1.e1", "pm1.g1.e2", "pm1.g1.e3", "pm1.g1.e4" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
@@ -465,7 +465,7 @@
String sql = "SELECT x.e1, e2, x.e3 AS a, e4 AS b FROM pm1.g1 AS x"; //$NON-NLS-1$
Query resolvedQuery = (Query) helpResolve(sql);
helpCheckFrom(resolvedQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
- helpCheckSelect(resolvedQuery, new String[] { "x.e1", "x.e2", "a", "b" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ helpCheckSelect(resolvedQuery, new String[] { "x.e1", "e2", "a", "b" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "x.e1", "x.e2", "x.e3", "x.e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "pm1.g1.e1", "pm1.g1.e2", "pm1.g1.e3", "pm1.g1.e4" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
@@ -553,7 +553,8 @@
metadata = FakeMetadataFactory.example3();
String sql = "SELECT cat2.cat3.g1.e1 FROM cat2.cat3.g1"; //$NON-NLS-1$
Query resolvedQuery = (Query) helpResolve(sql);
- helpCheckSelect(resolvedQuery, new String[] { "pm1.cat1.cat2.cat3.g1.e1" }); //$NON-NLS-1$
+ helpCheckSelect(resolvedQuery, new String[] { "cat2.cat3.g1.e1" }); //$NON-NLS-1$
+ helpCheckElements(resolvedQuery.getSelect(), new String[] {"pm1.cat1.cat2.cat3.g1.e1"}, new String[] {"pm1.cat1.cat2.cat3.g1.e1"}); //$NON-NLS-1$ //$NON-NLS-2$
}
/** defect 12536 */
@@ -561,7 +562,7 @@
metadata = FakeMetadataFactory.example3();
String sql = "SELECT cat3.g1.e1 FROM cat2.cat3.g1"; //$NON-NLS-1$
Query resolvedQuery = (Query) helpResolve(sql);
- helpCheckSelect(resolvedQuery, new String[] { "pm1.cat1.cat2.cat3.g1.e1" }); //$NON-NLS-1$
+ helpCheckSelect(resolvedQuery, new String[] { "cat3.g1.e1" }); //$NON-NLS-1$
}
/** defect 12536 */
@@ -569,7 +570,7 @@
metadata = FakeMetadataFactory.example3();
String sql = "SELECT cat3.g1.e1 FROM cat2.cat3.g1, cat1.g2"; //$NON-NLS-1$
Query resolvedQuery = (Query) helpResolve(sql);
- helpCheckSelect(resolvedQuery, new String[] { "pm1.cat1.cat2.cat3.g1.e1" }); //$NON-NLS-1$
+ helpCheckSelect(resolvedQuery, new String[] { "cat3.g1.e1" }); //$NON-NLS-1$
}
/** defect 12536 */
@@ -577,14 +578,14 @@
metadata = FakeMetadataFactory.example3();
String sql = "SELECT cat3.g1.e1, cat1.g2.e1 FROM cat2.cat3.g1, cat1.g2"; //$NON-NLS-1$
Query resolvedQuery = (Query) helpResolve(sql);
- helpCheckSelect(resolvedQuery, new String[] { "pm1.cat1.cat2.cat3.g1.e1", "pm1.cat1.g2.e1" }); //$NON-NLS-1$ //$NON-NLS-2$
+ helpCheckSelect(resolvedQuery, new String[] { "cat3.g1.e1", "cat1.g2.e1" }); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testPartiallyQualifiedElement5() {
metadata = FakeMetadataFactory.example3();
String sql = "SELECT cat3.g1.e1, cat1.g2.e1 FROM myvdb.pm1.cat1.cat2.cat3.g1, pm1.cat1.g2"; //$NON-NLS-1$
Query resolvedQuery = (Query) helpResolve(sql);
- helpCheckSelect(resolvedQuery, new String[] { "pm1.cat1.cat2.cat3.g1.e1", "pm1.cat1.g2.e1" }); //$NON-NLS-1$ //$NON-NLS-2$
+ helpCheckSelect(resolvedQuery, new String[] { "cat3.g1.e1", "cat1.g2.e1" }); //$NON-NLS-1$ //$NON-NLS-2$
}
/** defect 12536 */
@@ -592,14 +593,16 @@
metadata = FakeMetadataFactory.example3();
String sql = "SELECT cat3.g1.e1, e2 FROM cat2.cat3.g1"; //$NON-NLS-1$
Query resolvedQuery = (Query) helpResolve(sql);
- helpCheckSelect(resolvedQuery, new String[] { "pm1.cat1.cat2.cat3.g1.e1", "pm1.cat1.cat2.cat3.g1.e2" }); //$NON-NLS-1$ //$NON-NLS-2$
+ helpCheckSelect(resolvedQuery, new String[] { "cat3.g1.e1", "e2" }); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testPartiallyQualifiedElement7() {
metadata = FakeMetadataFactory.example3();
String sql = "SELECT cat3.g1.e1, cat2.cat3.g1.e2, g1.e3 FROM pm1.cat1.cat2.cat3.g1"; //$NON-NLS-1$
Query resolvedQuery = (Query) helpResolve(sql);
- helpCheckSelect(resolvedQuery, new String[] { "pm1.cat1.cat2.cat3.g1.e1", "pm1.cat1.cat2.cat3.g1.e2", "pm1.cat1.cat2.cat3.g1.e3" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ helpCheckSelect(resolvedQuery, new String[] { "cat3.g1.e1", "cat2.cat3.g1.e2", "g1.e3" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ helpCheckElements(resolvedQuery.getSelect(), new String[] { "pm1.cat1.cat2.cat3.g1.e1", "pm1.cat1.cat2.cat3.g1.e2", "pm1.cat1.cat2.cat3.g1.e3" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new String[] { "pm1.cat1.cat2.cat3.g1.e1", "pm1.cat1.cat2.cat3.g1.e2", "pm1.cat1.cat2.cat3.g1.e3" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public void testFailPartiallyQualifiedGroup1() {
@@ -655,7 +658,7 @@
public void testElementWithVDB() {
String sql = "SELECT myvdb.pm1.g1.e1 FROM pm1.g1"; //$NON-NLS-1$
Query resolvedQuery = (Query) helpResolve(sql);
- helpCheckSelect(resolvedQuery, new String[] { "pm1.g1.e1" }); //$NON-NLS-1$
+ helpCheckSelect(resolvedQuery, new String[] { "myvdb.pm1.g1.e1" }); //$NON-NLS-1$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "pm1.g1.e1" }, //$NON-NLS-1$
new String[] { "pm1.g1.e1" } ); //$NON-NLS-1$
@@ -736,7 +739,7 @@
public void testSelectExpressions() {
Query resolvedQuery = (Query) helpResolve("SELECT e1, concat(e1, 's'), concat(e1, 's') as c FROM pm1.g1"); //$NON-NLS-1$
helpCheckFrom(resolvedQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
- helpCheckSelect(resolvedQuery, new String[] { "pm1.g1.e1", "expr", "c" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ helpCheckSelect(resolvedQuery, new String[] { "e1", "expr", "c" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "pm1.g1.e1", "pm1.g1.e1", "pm1.g1.e1" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new String[] { "pm1.g1.e1", "pm1.g1.e1", "pm1.g1.e1" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -752,7 +755,7 @@
public void testMultipleIdenticalElements() {
Query resolvedQuery = (Query) helpResolve("SELECT e1, e1 FROM pm1.g1"); //$NON-NLS-1$
helpCheckFrom(resolvedQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
- helpCheckSelect(resolvedQuery, new String[] { "pm1.g1.e1", "pm1.g1.e1" }); //$NON-NLS-1$ //$NON-NLS-2$
+ helpCheckSelect(resolvedQuery, new String[] { "e1", "e1" }); //$NON-NLS-1$ //$NON-NLS-2$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "pm1.g1.e1", "pm1.g1.e1" }, //$NON-NLS-1$ //$NON-NLS-2$
new String[] { "pm1.g1.e1", "pm1.g1.e1" }); //$NON-NLS-1$ //$NON-NLS-2$
@@ -761,7 +764,7 @@
public void testMultipleIdenticalElements2() {
Query resolvedQuery = (Query) helpResolve("SELECT e1, pm1.g1.e1 FROM pm1.g1"); //$NON-NLS-1$
helpCheckFrom(resolvedQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
- helpCheckSelect(resolvedQuery, new String[] { "pm1.g1.e1", "pm1.g1.e1" }); //$NON-NLS-1$ //$NON-NLS-2$
+ helpCheckSelect(resolvedQuery, new String[] { "e1", "pm1.g1.e1" }); //$NON-NLS-1$ //$NON-NLS-2$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "pm1.g1.e1", "pm1.g1.e1" }, //$NON-NLS-1$ //$NON-NLS-2$
new String[] { "pm1.g1.e1", "pm1.g1.e1" }); //$NON-NLS-1$ //$NON-NLS-2$
@@ -770,7 +773,7 @@
public void testMultipleIdenticalElements3() {
Query resolvedQuery = (Query) helpResolve("SELECT e1, e1 as x FROM pm1.g1"); //$NON-NLS-1$
helpCheckFrom(resolvedQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
- helpCheckSelect(resolvedQuery, new String[] { "pm1.g1.e1", "x" }); //$NON-NLS-1$ //$NON-NLS-2$
+ helpCheckSelect(resolvedQuery, new String[] { "e1", "x" }); //$NON-NLS-1$ //$NON-NLS-2$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "pm1.g1.e1", "pm1.g1.e1" }, //$NON-NLS-1$ //$NON-NLS-2$
new String[] { "pm1.g1.e1", "pm1.g1.e1" }); //$NON-NLS-1$ //$NON-NLS-2$
@@ -957,7 +960,7 @@
public void testSubquery1() {
Query resolvedQuery = (Query) helpResolve("SELECT e1 FROM pm1.g1, (SELECT pm1.g2.e1 AS x FROM pm1.g2) AS y WHERE e1 = x"); //$NON-NLS-1$
helpCheckFrom(resolvedQuery, new String[] { "pm1.g1", "y" }); //$NON-NLS-1$ //$NON-NLS-2$
- helpCheckSelect(resolvedQuery, new String[] { "pm1.g1.e1" }); //$NON-NLS-1$
+ helpCheckSelect(resolvedQuery, new String[] { "e1" }); //$NON-NLS-1$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "pm1.g1.e1" }, //$NON-NLS-1$
new String[] { "pm1.g1.e1" } ); //$NON-NLS-1$
@@ -1287,8 +1290,8 @@
helpCheckFrom(outerQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
helpCheckFrom(innerQuery, new String[] { "pm4.g1" }); //$NON-NLS-1$
- helpCheckSelect(outerQuery, new String[] { "pm1.g1.e1" }); //$NON-NLS-1$
- helpCheckSelect(innerQuery, new String[] { "pm4.g1.e2" }); //$NON-NLS-1$
+ helpCheckSelect(outerQuery, new String[] { "e1" }); //$NON-NLS-1$
+ helpCheckSelect(innerQuery, new String[] { "e2" }); //$NON-NLS-1$
helpCheckElements(outerQuery.getSelect(),
new String[] { "pm1.g1.e1" }, //$NON-NLS-1$
new String[] { "pm1.g1.e1" } ); //$NON-NLS-1$
@@ -1338,8 +1341,8 @@
helpCheckFrom(outerQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
helpCheckFrom(innerQuery, new String[] { "pm4.g1" }); //$NON-NLS-1$
- helpCheckSelect(outerQuery, new String[] { "pm1.g1.e1" }); //$NON-NLS-1$
- helpCheckSelect(innerQuery, new String[] { "pm4.g1.e1" }); //$NON-NLS-1$
+ helpCheckSelect(outerQuery, new String[] { "e1" }); //$NON-NLS-1$
+ helpCheckSelect(innerQuery, new String[] { "e1" }); //$NON-NLS-1$
helpCheckElements(outerQuery.getSelect(),
new String[] { "pm1.g1.e1" }, //$NON-NLS-1$
new String[] { "pm1.g1.e1" } ); //$NON-NLS-1$
@@ -2713,7 +2716,7 @@
Query outerQuery = (Query) this.helpResolveSubquery(sql, new String[0]);
helpCheckFrom(outerQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
- helpCheckSelect(outerQuery, new String[] { "pm1.g1.e1" }); //$NON-NLS-1$
+ helpCheckSelect(outerQuery, new String[] { "e1" }); //$NON-NLS-1$
helpCheckElements(outerQuery.getSelect(),
new String[] { "pm1.g1.e1" }, //$NON-NLS-1$
new String[] { "pm1.g1.e1" } ); //$NON-NLS-1$
@@ -3737,20 +3740,18 @@
public void testDefect18832() {
String sql = "SELECT * from (SELECT null as a, e1 FROM pm1.g1) b"; //$NON-NLS-1$
Command c = helpResolve(sql);
- List projectedSymbols = c.getProjectedSymbols();
+ List<DerivedColumn> projectedSymbols = c.getProjectedSymbols();
for(int i=0; i< projectedSymbols.size(); i++) {
- ElementSymbol symbol = (ElementSymbol)projectedSymbols.get(i);
- assertTrue(!symbol.getType().equals(DataTypeManager.DefaultDataClasses.NULL));
+ assertTrue(!projectedSymbols.get(i).getType().equals(DataTypeManager.DefaultDataClasses.NULL));
}
}
public void testDefect18832_2() {
String sql = "SELECT a.*, b.* from (SELECT null as a, e1 FROM pm1.g1) a, (SELECT e1 FROM pm1.g1) b"; //$NON-NLS-1$
Command c = helpResolve(sql);
- List projectedSymbols = c.getProjectedSymbols();
+ List<DerivedColumn> projectedSymbols = c.getProjectedSymbols();
for(int i=0; i< projectedSymbols.size(); i++) {
- ElementSymbol symbol = (ElementSymbol)projectedSymbols.get(i);
- assertTrue(!symbol.getType().equals(DataTypeManager.DefaultDataClasses.NULL));
+ assertTrue(!projectedSymbols.get(i).getType().equals(DataTypeManager.DefaultDataClasses.NULL));
}
}
@@ -4362,12 +4363,12 @@
StoredProcedure proc = (StoredProcedure)helpResolve(query);
- List projected = proc.getProjectedSymbols();
+ List<DerivedColumn> projected = proc.getProjectedSymbols();
assertEquals(2, projected.size());
- for (Iterator i = projected.iterator(); i.hasNext();) {
- ElementSymbol symbol = (ElementSymbol)i.next();
+ for (DerivedColumn derivedColumn : projected) {
+ ElementSymbol symbol = (ElementSymbol)derivedColumn.getExpression();
assertNotNull(symbol.getGroupSymbol());
}
}
@@ -4648,7 +4649,7 @@
private void helpTestOrderBy(OrderBy orderBy, int[] expectedPositions) {
assertEquals(expectedPositions.length, orderBy.getVariableCount());
for (int i = 0; i < expectedPositions.length; i++) {
- ElementSymbol symbol = (ElementSymbol)orderBy.getSortOrder().get(0).getSortKey();
+ ElementSymbol symbol = (ElementSymbol)orderBy.getSortOrder().get(i).getSortKey();
TempMetadataID tid = (TempMetadataID)symbol.getMetadataID();
assertEquals(expectedPositions[i], tid.getPosition());
}
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-03-03 17:26:43 UTC (rev 532)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-03-03 19:50:13 UTC (rev 533)
@@ -55,6 +55,7 @@
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.SPParameter;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.visitor.SQLStringVisitor;
@@ -1952,7 +1953,7 @@
ElementSymbol e1 = new ElementSymbol("#temp.e1");//$NON-NLS-1$
e1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
- store.addTempGroup("#temp", Arrays.asList(e1), false, true); //$NON-NLS-1$
+ store.addTempGroup("#temp", Arrays.asList(new DerivedColumn(e1)), false, true); //$NON-NLS-1$
QueryMetadataInterface metadata = new TempMetadataAdapter(fakeMetadata, store);
16 years, 7 months
teiid SVN: r532 - in branches/symbol_refactoring_61/engine/src: main/java/com/metamatrix/dqp/internal/datamgr/language and 31 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-03-03 12:26:43 -0500 (Tue, 03 Mar 2009)
New Revision: 532
Added:
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Aggregate.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/DerivedColumn.java
Removed:
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/AggregateSymbol.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/AliasSymbol.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/ExpressionSymbol.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/SingleElementSymbol.java
Modified:
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/impl/ConnectorWorkItem.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/LanguageBridgeFactory.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/process/MetaDataProcessor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/metadata/GroupInfo.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/metadata/TempMetadataStore.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/AliasGenerator.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CapabilitiesUtil.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleChooseJoinStrategy.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseNull.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/xml/SourceNodePlannerVisitor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/DynamicCommandResolver.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/SetQueryResolver.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/SimpleQueryResolver.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/XMLQueryResolver.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/LanguageVisitor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/GroupBy.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Insert.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderBy.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Select.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Update.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/navigator/PreOrPostOrderNavigator.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/ElementSymbol.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/MultipleElementSymbol.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Symbol.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/util/SymbolMap.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/util/UpdateProcedureGenerator.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/AggregateSymbolCollectorVisitor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/CriteriaTranslatorVisitor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionSymbolCollector.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/AggregateValidationVisitor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/UpdateValidationVisitor.java
branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
branches/symbol_refactoring_61/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestAggregateImpl.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinWithFunction.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestCapabilitiesUtil.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/parser/TestParser.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/relational/TestGroupingNode.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectNode.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestAliasSymbol.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestExpressionSymbol.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestSelect.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/symbol/TestAggregateSymbol.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestSQLStringVisitor.java
branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestStaticSymbolMappingVisitor.java
Log:
initial commit, passing parsing
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/impl/ConnectorWorkItem.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/impl/ConnectorWorkItem.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/impl/ConnectorWorkItem.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -63,7 +63,6 @@
import com.metamatrix.query.metadata.TempMetadataStore;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
public abstract class ConnectorWorkItem extends AbstractWorkItem {
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/LanguageBridgeFactory.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/LanguageBridgeFactory.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/language/LanguageBridgeFactory.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -111,13 +111,13 @@
import com.metamatrix.query.sql.lang.SubquerySetCriteria;
import com.metamatrix.query.sql.lang.UnaryFromClause;
import com.metamatrix.query.sql.lang.Update;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
@@ -209,10 +209,8 @@
IExpression iExp = null;
if(symbol instanceof ElementSymbol) {
iExp = translate((ElementSymbol)symbol);
- } else if(symbol instanceof AggregateSymbol) {
- iExp = translate((AggregateSymbol)symbol);
- } else if(symbol instanceof ExpressionSymbol) {
- iExp = translate(((ExpressionSymbol)symbol).getExpression());
+ } else if(symbol instanceof DerivedColumn) {
+ iExp = translate(((DerivedColumn)symbol).getExpression());
}
SelectSymbolImpl selectSymbol = new SelectSymbolImpl(alias, iExp);
@@ -466,7 +464,7 @@
IExpression translate(Expression expr) throws MetaMatrixComponentException {
if (expr == null) return null;
if (expr instanceof CaseExpression) {
- return translate((CaseExpression)expr);
+ throw new AssertionError("CaseExpression push down is not expected"); //$NON-NLS-1$
} else if (expr instanceof Constant) {
return translate((Constant)expr);
} else if (expr instanceof Function) {
@@ -479,6 +477,8 @@
return translate((SearchedCaseExpression)expr);
} else if (expr instanceof SingleElementSymbol) {
return translate((SingleElementSymbol)expr);
+ } else if (expr instanceof Aggregate) {
+ return translate((Aggregate)expr);
}
return null;
}
@@ -525,10 +525,8 @@
return translate((AliasSymbol)symbol);
} else if (symbol instanceof ElementSymbol) {
return translate((ElementSymbol)symbol);
- } else if (symbol instanceof AggregateSymbol) {
- return translate((AggregateSymbol)symbol);
- } else if (symbol instanceof ExpressionSymbol) {
- return translate((ExpressionSymbol)symbol);
+ } else if (symbol instanceof DerivedColumn) {
+ return translate((DerivedColumn)symbol);
}
return null;
}
@@ -553,14 +551,14 @@
return element;
}
- IAggregate translate(AggregateSymbol symbol) throws MetaMatrixComponentException {
+ IAggregate translate(Aggregate symbol) throws MetaMatrixComponentException {
return new AggregateImpl(symbol.getAggregateFunction(),
symbol.isDistinct(),
translate(symbol.getExpression()),
symbol.getType());
}
- IExpression translate(ExpressionSymbol symbol) throws MetaMatrixComponentException {
+ IExpression translate(DerivedColumn symbol) throws MetaMatrixComponentException {
return translate(symbol.getExpression());
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/process/MetaDataProcessor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/process/MetaDataProcessor.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/process/MetaDataProcessor.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -25,7 +25,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -57,12 +56,12 @@
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.XQuery;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.Symbol;
import com.metamatrix.query.sql.visitor.ReferenceCollectorVisitor;
import com.metamatrix.query.tempdata.TempTableStore;
@@ -184,18 +183,14 @@
this.metadata = tempFacade;
}
- List projectedSymbols = originalCommand.getProjectedSymbols();
+ List<DerivedColumn> projectedSymbols = originalCommand.getProjectedSymbols();
columnMetadata = new Map[projectedSymbols.size()];
- Iterator symbolIter = projectedSymbols.iterator();
- for(int i=0; symbolIter.hasNext(); i++) {
- SingleElementSymbol symbol = (SingleElementSymbol) symbolIter.next();
- String shortColumnName = SingleElementSymbol.getShortName(symbol.getOutputName());
- if(symbol instanceof AliasSymbol) {
- symbol = ((AliasSymbol)symbol).getSymbol();
- }
+ for (int i = 0; i < projectedSymbols.size(); i++) {
+ DerivedColumn symbol = projectedSymbols.get(i);
+ String shortColumnName = Symbol.getShortName(symbol.getOutputName());
try {
- columnMetadata[i] = createColumnMetadata(shortColumnName, symbol);
+ columnMetadata[i] = createColumnMetadata(shortColumnName, symbol.getExpression());
} catch(QueryMetadataException e) {
throw new MetaMatrixComponentException(e);
}
@@ -239,11 +234,11 @@
return xqueryMetadata;
}
- private Map createColumnMetadata(String shortColumnName, SingleElementSymbol symbol) throws QueryMetadataException, MetaMatrixComponentException {
+ private Map createColumnMetadata(String shortColumnName, Expression symbol) throws QueryMetadataException, MetaMatrixComponentException {
if(symbol instanceof ElementSymbol) {
return createElementMetadata(shortColumnName, (ElementSymbol) symbol);
- } else if(symbol instanceof AggregateSymbol) {
- return createAggregateMetadata(shortColumnName, (AggregateSymbol) symbol);
+ } else if (symbol instanceof Aggregate) {
+ return createAggregateMetadata(shortColumnName, (Aggregate) symbol);
}
return createTypedMetadata(shortColumnName, symbol);
}
@@ -315,19 +310,19 @@
}
private Map createAggregateMetadata(String shortColumnName,
- AggregateSymbol symbol) throws QueryMetadataException, MetaMatrixComponentException {
+ Aggregate symbol) throws QueryMetadataException, MetaMatrixComponentException {
Expression expression = symbol.getExpression();
String function = symbol.getAggregateFunction();
if(function.equals(ReservedWords.MIN) || function.equals(ReservedWords.MAX)){
if(expression instanceof ElementSymbol) {
- return createColumnMetadata(shortColumnName, (ElementSymbol)expression);
+ return createColumnMetadata(shortColumnName, expression);
}
}
return createTypedMetadata(shortColumnName, symbol);
}
- private Map createTypedMetadata(String shortColumnName, SingleElementSymbol symbol) {
+ private Map createTypedMetadata(String shortColumnName, Expression symbol) {
return getDefaultColumn(vdbName, vdbVersion, null, shortColumnName, symbol.getType());
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -82,6 +82,7 @@
import com.metamatrix.query.sql.lang.SPParameter;
import com.metamatrix.query.sql.lang.StoredProcedure;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.Symbol;
public class RequestWorkItem extends AbstractWorkItem {
@@ -501,7 +502,7 @@
for(int i=0; i<columnSymbols.size(); i++) {
SingleElementSymbol symbol = (SingleElementSymbol) columnSymbols.get(i);
- columnNames[i] = SingleElementSymbol.getShortName(symbol.getOutputName());
+ columnNames[i] = Symbol.getShortName(symbol.getOutputName());
dataTypes[i] = DataTypeManager.getDataTypeName(symbol.getType());
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/eval/Evaluator.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -55,16 +55,15 @@
import com.metamatrix.query.sql.lang.MatchCriteria;
import com.metamatrix.query.sql.lang.NotCriteria;
import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.symbol.ScalarSubquery;
import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.ValueIterator;
import com.metamatrix.query.util.CommandContext;
import com.metamatrix.query.util.ErrorMessageKeys;
@@ -491,8 +490,8 @@
return tuple.get(index.intValue());
}
// Otherwise this should be an ExpressionSymbol and we just need to dive in and evaluate the expression itself
- if (expression instanceof ExpressionSymbol && !(expression instanceof AggregateSymbol)) {
- ExpressionSymbol exprSyb = (ExpressionSymbol) expression;
+ if (expression instanceof DerivedColumn && !(expression instanceof Aggregate)) {
+ DerivedColumn exprSyb = (DerivedColumn) expression;
Expression expr = exprSyb.getExpression();
return internalEvaluate(expr, tuple);
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/metadata/GroupInfo.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/metadata/GroupInfo.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/metadata/GroupInfo.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -44,7 +44,7 @@
public GroupInfo(LinkedHashMap<Object, ElementSymbol> symbols) {
this.idToSymbolMap = symbols;
- this.symbolList = Collections.unmodifiableList(new ArrayList(symbols.values()));
+ this.symbolList = Collections.unmodifiableList(new ArrayList<ElementSymbol>(symbols.values()));
this.shortNameToSymbolMap = new HashMap<String, ElementSymbol>(symbolList.size());
for (ElementSymbol symbol : symbolList) {
shortNameToSymbolMap.put(symbol.getShortCanonicalName(), symbol);
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/metadata/TempMetadataStore.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/metadata/TempMetadataStore.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/metadata/TempMetadataStore.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -29,13 +29,11 @@
import java.util.List;
import java.util.Map;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.Symbol;
/**
* Store for temporary metadata discovering while resolving a query.
@@ -101,13 +99,13 @@
* @param isVirtual whether or not the group is a virtual group
* @param isTempTable whether or not the group is a temporary table
*/
- public TempMetadataID addTempGroup(String tempGroup, List<? extends SingleElementSymbol> tempSymbols, boolean isVirtual, boolean isTempTable) {
+ public TempMetadataID addTempGroup(String tempGroup, List<DerivedColumn> tempSymbols, boolean isVirtual, boolean isTempTable) {
// Add the temporary group
String tempName = tempGroup.toUpperCase();
List elementIDs = new ArrayList(tempSymbols.size());
- for (SingleElementSymbol symbol : tempSymbols) {
+ for (DerivedColumn symbol : tempSymbols) {
TempMetadataID elementID = createElementSymbol(tempName, symbol, isTempTable);
elementIDs.add(elementID);
@@ -119,30 +117,20 @@
return groupID;
}
- private TempMetadataID createElementSymbol(String tempName, SingleElementSymbol symbol, boolean isTempTable) {
+ private TempMetadataID createElementSymbol(String tempName, DerivedColumn symbol, boolean isTempTable) {
// Create new element name
- String elementName = tempName + SingleElementSymbol.SEPARATOR + symbol.getShortCanonicalName();
+ String elementName = tempName + Symbol.SEPARATOR + symbol.getShortCanonicalName();
Object metadataID = null;
- if (symbol instanceof AliasSymbol) {
- AliasSymbol as = (AliasSymbol)symbol;
- symbol = as.getSymbol();
- }
-
//the following allows for orginal metadata ids to be determined for proc inputs
- if (symbol instanceof ExpressionSymbol && !(symbol instanceof AggregateSymbol)) {
- Expression expr = ((ExpressionSymbol)symbol).getExpression();
- if (expr instanceof Reference) {
- expr = ((Reference)expr).getExpression();
- }
- if (expr instanceof ElementSymbol) {
- symbol = (ElementSymbol)expr;
- }
- }
+ Expression expr = symbol.getExpression();
+ if (expr instanceof Reference) {
+ expr = ((Reference)expr).getExpression();
+ }
- if (symbol instanceof ElementSymbol) {
- metadataID = ((ElementSymbol)symbol).getMetadataID();
+ if (expr instanceof ElementSymbol) {
+ metadataID = ((ElementSymbol)expr).getMetadataID();
}
while (metadataID != null && metadataID instanceof TempMetadataID) {
@@ -161,7 +149,7 @@
* @param symbol - element to be added
* @return metadata id.
*/
- public TempMetadataID addElementSymbolToTempGroup(String tempGroup, SingleElementSymbol symbol) {
+ public TempMetadataID addElementSymbolToTempGroup(String tempGroup, DerivedColumn symbol) {
String tempName = tempGroup.toUpperCase();
TempMetadataID groupID = (TempMetadataID)this.tempGroups.get(tempName);
@@ -207,7 +195,7 @@
* @return Metadata ID or null if not found
*/
public TempMetadataID getTempElementID(String tempElement) {
- int index = tempElement.lastIndexOf(SingleElementSymbol.SEPARATOR);
+ int index = tempElement.lastIndexOf(Symbol.SEPARATOR);
if(index < 0) {
return null;
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/AliasGenerator.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/AliasGenerator.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/AliasGenerator.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -39,14 +39,13 @@
import com.metamatrix.query.sql.lang.SubquerySetCriteria;
import com.metamatrix.query.sql.lang.UnaryFromClause;
import com.metamatrix.query.sql.navigator.PreOrderNavigator;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.symbol.ScalarSubquery;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.Symbol;
import com.metamatrix.query.sql.util.SymbolMap;
/**
@@ -66,7 +65,7 @@
Map<String, Map<String, String>> elementMap = new HashMap<String, Map<String, String>>();
Map<String, String> groupNames = new HashMap<String, String>();
- Map<SingleElementSymbol, String> currentSymbols;
+ Map<DerivedColumn, String> currentSymbols;
boolean aliasColumns = false;
@@ -74,27 +73,23 @@
this.parent = parent;
}
- public String getElementName(SingleElementSymbol symbol, boolean renameGroup) {
+ public String getElementName(ElementSymbol symbol, boolean renameGroup) {
String name = null;
if (currentSymbols != null) {
name = currentSymbols.get(symbol);
if (name != null) {
- if (renameGroup && symbol instanceof ElementSymbol) {
- renameGroup(((ElementSymbol)symbol).getGroupSymbol());
+ if (renameGroup) {
+ renameGroup(symbol.getGroupSymbol());
}
return name;
}
}
- if (!(symbol instanceof ElementSymbol)) {
- return null;
- }
- ElementSymbol element = (ElementSymbol)symbol;
- Map<String, String> elements = this.elementMap.get(element.getGroupSymbol().getCanonicalName());
+ Map<String, String> elements = this.elementMap.get(symbol.getGroupSymbol().getCanonicalName());
if (elements != null) {
- name = elements.get(element.getShortCanonicalName());
+ name = elements.get(symbol.getShortCanonicalName());
if (name != null) {
if (renameGroup) {
- renameGroup(element.getGroupSymbol());
+ renameGroup(symbol.getGroupSymbol());
}
return name;
}
@@ -106,7 +101,7 @@
}
}
if (renameGroup) {
- renameGroup(element.getGroupSymbol());
+ renameGroup(symbol.getGroupSymbol());
}
return null;
}
@@ -221,7 +216,7 @@
SingleElementSymbol newSymbol = symbol;
if (!(expr instanceof SingleElementSymbol)) {
- newSymbol = new ExpressionSymbol(newSymbol.getShortName(), expr);
+ newSymbol = new DerivedColumn(newSymbol.getShortName(), expr);
} else if (expr instanceof ElementSymbol) {
if (!needsAlias(newAlias, (ElementSymbol)expr)) {
needsAlias = false;
@@ -335,7 +330,7 @@
Expression expr = SymbolMap.getExpression(element);
if (!(expr instanceof SingleElementSymbol)) {
- expr = new ExpressionSymbol(element.getShortName(), expr);
+ expr = new DerivedColumn(element.getShortName(), expr);
} else if (expr instanceof ElementSymbol) {
needsAlias = needsAlias(name, (ElementSymbol)expr);
}
@@ -353,7 +348,7 @@
for (int i = 0; i < obj.getVariableCount(); i++) {
SingleElementSymbol element = obj.getVariable(i);
if (element instanceof ElementSymbol) {
- element.setOutputName(SingleElementSymbol.getShortName(element.getOutputName()));
+ element.setOutputName(Symbol.getShortName(element.getOutputName()));
}
}
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/GenerateCanonical.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -442,8 +442,7 @@
private static PlanNode attachSorting(PlanNode plan, OrderBy orderBy) {
PlanNode sortNode = NodeFactory.getNewNode(NodeConstants.Types.SORT);
- sortNode.setProperty(NodeConstants.Info.SORT_ORDER, orderBy.getVariables());
- sortNode.setProperty(NodeConstants.Info.ORDER_TYPES, orderBy.getTypes());
+ sortNode.setProperty(NodeConstants.Info.SORT_ORDER, orderBy.getSortOrder());
sortNode.addGroups(GroupsUsedByElementsVisitor.getGroups(orderBy));
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/PlanToProcessConverter.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -73,6 +73,7 @@
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.JoinType;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.StoredProcedure;
import com.metamatrix.query.sql.lang.SetQuery.Operation;
@@ -356,10 +357,9 @@
case NodeConstants.Types.SORT:
SortNode sortNode = new SortNode(getID());
- List elements = (List) node.getProperty(NodeConstants.Info.SORT_ORDER);
- List sortTypes = (List) node.getProperty(NodeConstants.Info.ORDER_TYPES);
+ List<OrderByItem> elements = (List<OrderByItem>) node.getProperty(NodeConstants.Info.SORT_ORDER);
- sortNode.setSortElements(elements, sortTypes);
+ sortNode.setSortElements(elements);
processNode = sortNode;
break;
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/RelationalPlanner.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -52,9 +52,9 @@
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.SubqueryContainer;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.visitor.CorrelatedReferenceCollectorVisitor;
import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
import com.metamatrix.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
@@ -129,12 +129,10 @@
}
// Set top column information on top node
- List projectCols = command.getProjectedSymbols();
- List<SingleElementSymbol> topCols = new ArrayList<SingleElementSymbol>(projectCols.size());
- Iterator projectIter = projectCols.iterator();
- while(projectIter.hasNext()) {
- SingleElementSymbol symbol = (SingleElementSymbol) projectIter.next();
- topCols.add( (SingleElementSymbol)symbol.clone() );
+ List<DerivedColumn> projectCols = command.getProjectedSymbols();
+ List<DerivedColumn> topCols = new ArrayList<DerivedColumn>(projectCols.size());
+ for (DerivedColumn derivedColumn : projectCols) {
+ topCols.add( (DerivedColumn)derivedColumn.clone() );
}
// Build rule set based on hints
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/plantree/NodeConstants.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -108,7 +108,6 @@
IS_DEPENDENT_SET, // Boolean - only used with dependent joins
// Sort node properties
- ORDER_TYPES, // List <Boolean>
SORT_ORDER, // List <SingleElementSymbol>
SORT_CONTROLLER, // Boolean
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CapabilitiesUtil.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CapabilitiesUtil.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CapabilitiesUtil.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -38,7 +38,7 @@
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.JoinType;
import com.metamatrix.query.sql.lang.SetQuery.Operation;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
@@ -157,7 +157,7 @@
return true;
}
- public static boolean supportsAggregateFunction(Object modelID, AggregateSymbol aggregate, QueryMetadataInterface metadata, CapabilitiesFinder capFinder)
+ public static boolean supportsAggregateFunction(Object modelID, Aggregate aggregate, QueryMetadataInterface metadata, CapabilitiesFinder capFinder)
throws QueryMetadataException, MetaMatrixComponentException {
if (metadata.isVirtualModel(modelID)){
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -48,7 +48,7 @@
import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
import com.metamatrix.query.sql.lang.SubquerySetCriteria;
import com.metamatrix.query.sql.navigator.PreOrderNavigator;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Function;
@@ -99,7 +99,7 @@
}
}
- public void visit(AggregateSymbol obj) {
+ public void visit(Aggregate obj) {
if(this.caps == null) {
return;
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/FrameUtil.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -54,15 +54,13 @@
import com.metamatrix.query.sql.lang.StoredProcedure;
import com.metamatrix.query.sql.navigator.PostOrderNavigator;
import com.metamatrix.query.sql.navigator.PreOrderNavigator;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
import com.metamatrix.query.sql.visitor.ExpressionMappingVisitor;
@@ -295,13 +293,13 @@
SingleElementSymbol mappedSymbol = null;
if(!(mappedExpression instanceof SingleElementSymbol)) {
- mappedSymbol = new ExpressionSymbol(name, mappedExpression);
+ mappedSymbol = new DerivedColumn(name, mappedExpression);
} else {
mappedSymbol = (SingleElementSymbol)mappedExpression;
}
// Re-alias to maintain name if necessary
- if(shouldAlias && (mappedSymbol instanceof ExpressionSymbol || !mappedSymbol.getShortCanonicalName().equals(name.toUpperCase()))) {
+ if(shouldAlias && (mappedSymbol instanceof DerivedColumn || !mappedSymbol.getShortCanonicalName().equals(name.toUpperCase()))) {
mappedSymbol = new AliasSymbol(name, mappedSymbol);
}
@@ -322,8 +320,8 @@
return expression;
}
- if(expression instanceof AggregateSymbol) {
- AggregateSymbol aggSymbol = (AggregateSymbol) expression;
+ if(expression instanceof Aggregate) {
+ Aggregate aggSymbol = (Aggregate) expression;
// First try to replace the entire aggregate
SingleElementSymbol replacement = (SingleElementSymbol) symbolMap.get(aggSymbol);
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -48,11 +48,11 @@
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.StoredProcedure;
import com.metamatrix.query.sql.lang.SetQuery.Operation;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
@@ -373,8 +373,8 @@
ss = ((AliasSymbol)ss).getSymbol();
}
- if (ss instanceof ExpressionSymbol && !(ss instanceof AggregateSymbol)) {
- ExpressionSymbol exprSymbol = (ExpressionSymbol)ss;
+ if (ss instanceof DerivedColumn) {
+ DerivedColumn exprSymbol = (DerivedColumn)ss;
if (!exprSymbol.isDerivedExpression()) {
createdSymbols.add(ss);
@@ -402,10 +402,10 @@
List<SingleElementSymbol> groupCols = (List<SingleElementSymbol>) node.getProperty(NodeConstants.Info.GROUP_COLS);
if(groupCols != null) {
for (SingleElementSymbol expression : groupCols) {
- if(expression instanceof ElementSymbol || expression instanceof AggregateSymbol) {
+ if(expression instanceof ElementSymbol || expression instanceof Aggregate) {
requiredSymbols.add(expression);
} else {
- ExpressionSymbol exprSymbol = (ExpressionSymbol) expression;
+ DerivedColumn exprSymbol = (DerivedColumn) expression;
Expression expr = exprSymbol.getExpression();
AggregateSymbolCollectorVisitor.getAggregates(expr, requiredSymbols, requiredSymbols);
createdSymbols.add(exprSymbol);
@@ -415,8 +415,8 @@
// Take credit for creating any aggregates that are needed above
for (SingleElementSymbol outputSymbol : outputCols) {
- if(outputSymbol instanceof AggregateSymbol) {
- AggregateSymbol agg = (AggregateSymbol)outputSymbol;
+ if(outputSymbol instanceof Aggregate) {
+ Aggregate agg = (Aggregate)outputSymbol;
createdSymbols.add(outputSymbol);
Expression aggExpr = agg.getExpression();
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleChooseJoinStrategy.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleChooseJoinStrategy.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleChooseJoinStrategy.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -44,7 +44,7 @@
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.JoinType;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.visitor.GroupsUsedByElementsVisitor;
@@ -151,16 +151,16 @@
private static AtomicInteger EXPRESSION_INDEX = new AtomicInteger(0);
private static List<SingleElementSymbol> createExpressionSymbols(List<Expression> expressions) {
- HashMap<Expression, ExpressionSymbol> uniqueExpressions = new HashMap<Expression, ExpressionSymbol>();
+ HashMap<Expression, DerivedColumn> uniqueExpressions = new HashMap<Expression, DerivedColumn>();
List<SingleElementSymbol> result = new ArrayList<SingleElementSymbol>();
for (Expression expression : expressions) {
if (expression instanceof SingleElementSymbol) {
result.add((SingleElementSymbol)expression);
continue;
}
- ExpressionSymbol expressionSymbol = uniqueExpressions.get(expression);
+ DerivedColumn expressionSymbol = uniqueExpressions.get(expression);
if (expressionSymbol == null) {
- expressionSymbol = new ExpressionSymbol("$" + EXPRESSION_INDEX.getAndIncrement(), expression); //$NON-NLS-1$
+ expressionSymbol = new DerivedColumn("$" + EXPRESSION_INDEX.getAndIncrement(), expression); //$NON-NLS-1$
expressionSymbol.setDerivedExpression(true);
uniqueExpressions.put(expression, expressionSymbol);
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -57,7 +57,7 @@
import com.metamatrix.query.sql.lang.JoinType;
import com.metamatrix.query.sql.lang.OrderBy;
import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
@@ -101,7 +101,7 @@
}
List<SingleElementSymbol> groupingExpressions = (List<SingleElementSymbol>)groupNode.getProperty(NodeConstants.Info.GROUP_COLS);
- Set<AggregateSymbol> aggregates = collectAggregates(groupNode);
+ Set<Aggregate> aggregates = collectAggregates(groupNode);
pushGroupNode(groupNode, groupingExpressions, aggregates, metadata, capFinder);
}
@@ -117,8 +117,8 @@
* @return the set of aggregate symbols found
* @since 4.2
*/
- static Set<AggregateSymbol> collectAggregates(PlanNode groupNode) {
- Set<AggregateSymbol> aggregates = new HashSet<AggregateSymbol>();
+ static Set<Aggregate> collectAggregates(PlanNode groupNode) {
+ Set<Aggregate> aggregates = new HashSet<Aggregate>();
PlanNode currentNode = groupNode.getParent();
while (currentNode != null) {
if (currentNode.getType() == NodeConstants.Types.PROJECT) {
@@ -146,7 +146,7 @@
*/
private void pushGroupNode(PlanNode groupNode,
List<SingleElementSymbol> groupingExpressions,
- Set<AggregateSymbol> allAggregates,
+ Set<Aggregate> allAggregates,
QueryMetadataInterface metadata,
CapabilitiesFinder capFinder) throws MetaMatrixComponentException,
QueryMetadataException {
@@ -198,7 +198,7 @@
} else {
// if the source has no rows we need to insert a select node with criteria count(*)>0
PlanNode selectNode = NodeFactory.getNewNode(NodeConstants.Types.SELECT);
- AggregateSymbol count = new AggregateSymbol("stagedAgg", ReservedWords.COUNT, false, null); //$NON-NLS-1$
+ Aggregate count = new Aggregate(ReservedWords.COUNT, false, null); //$NON-NLS-1$
aggregates.add(count); //consider the count aggregate for the push down call below
selectNode.setProperty(NodeConstants.Info.SELECT_CRITERIA, new CompareCriteria(count, CompareCriteria.GT,
new Constant(new Integer(0))));
@@ -228,7 +228,7 @@
}
for (final Iterator<SingleElementSymbol> iterator = aggregates.iterator(); iterator.hasNext();) {
- final AggregateSymbol symbol = (AggregateSymbol)iterator.next();
+ final Aggregate symbol = (Aggregate)iterator.next();
Expression expr = symbol.getExpression();
if (expr == null) {
continue;
@@ -241,8 +241,8 @@
if (!aggregates.isEmpty()) {
// Fix any aggregate expressions so they correctly recombine the staged aggregates
try {
- Set<AggregateSymbol> newAggs = new HashSet<AggregateSymbol>();
- Map<AggregateSymbol, Expression> aggMap = buildAggregateMap(aggregates, metadata, newAggs);
+ Set<Aggregate> newAggs = new HashSet<Aggregate>();
+ Map<Aggregate, Expression> aggMap = buildAggregateMap(aggregates, metadata, newAggs);
mapExpressions(groupNode.getParent(), aggMap);
aggregates.clear();
aggregates.addAll(newAggs);
@@ -252,18 +252,18 @@
}
}
- private void collectSymbolsFromOtherAggregates(Collection<AggregateSymbol> allAggregates,
+ private void collectSymbolsFromOtherAggregates(Collection<Aggregate> allAggregates,
Collection<SingleElementSymbol> aggregates,
PlanNode current,
Set<SingleElementSymbol> stagedGroupingSymbols) {
- Set<AggregateSymbol> otherAggs = new HashSet<AggregateSymbol>(allAggregates);
+ Set<Aggregate> otherAggs = new HashSet<Aggregate>(allAggregates);
if (aggregates != null) {
otherAggs.removeAll(aggregates);
}
PlanNode source = FrameUtil.findJoinSourceNode(current);
- for (AggregateSymbol aggregateSymbol : otherAggs) {
+ for (Aggregate aggregateSymbol : otherAggs) {
for (ElementSymbol symbol : ElementCollectorVisitor.getElements(aggregateSymbol, true)) {
if (source.getGroups().contains(symbol.getGroupSymbol())) {
stagedGroupingSymbols.add(symbol);
@@ -326,8 +326,8 @@
return result;
}
for (SingleElementSymbol aggregateSymbol : expressions) {
- if (aggregateSymbol instanceof AggregateSymbol) {
- AggregateSymbol partitionAgg = (AggregateSymbol)aggregateSymbol;
+ if (aggregateSymbol instanceof Aggregate) {
+ Aggregate partitionAgg = (Aggregate)aggregateSymbol;
if (partitionAgg.isDistinct()) {
continue; //currently we cann't consider distinct aggs
}
@@ -365,19 +365,19 @@
return result;
}
- private Map<AggregateSymbol, Expression> buildAggregateMap(Collection<SingleElementSymbol> aggregateExpressions,
- QueryMetadataInterface metadata, Set<AggregateSymbol> nestedAggregates) throws QueryResolverException,
+ private Map<Aggregate, Expression> buildAggregateMap(Collection<SingleElementSymbol> aggregateExpressions,
+ QueryMetadataInterface metadata, Set<Aggregate> nestedAggregates) throws QueryResolverException,
MetaMatrixComponentException {
- Map<AggregateSymbol, Expression> aggMap = new HashMap<AggregateSymbol, Expression>();
+ Map<Aggregate, Expression> aggMap = new HashMap<Aggregate, Expression>();
for (SingleElementSymbol symbol : aggregateExpressions) {
- AggregateSymbol partitionAgg = (AggregateSymbol)symbol;
+ Aggregate partitionAgg = (Aggregate)symbol;
Expression newExpression = null;
String aggFunction = partitionAgg.getAggregateFunction();
if (aggFunction.equals(ReservedWords.COUNT)) {
//COUNT(x) -> CONVERT(SUM(COUNT(x)), INTEGER)
- AggregateSymbol newAgg = new AggregateSymbol("stagedAgg", ReservedWords.SUM, false, partitionAgg); //$NON-NLS-1$
+ Aggregate newAgg = new Aggregate(ReservedWords.SUM, false, partitionAgg); //$NON-NLS-1$
// Build conversion function to convert SUM (which returns LONG) back to INTEGER
Constant convertTargetType = new Constant(DataTypeManager.getDataTypeName(partitionAgg.getType()),
@@ -391,11 +391,11 @@
nestedAggregates.add(partitionAgg);
} else if (aggFunction.equals(ReservedWords.AVG)) {
//AVG(x) -> SUM(SUM(x)) / SUM(COUNT(x))
- AggregateSymbol countAgg = new AggregateSymbol("stagedAgg", ReservedWords.COUNT, false, partitionAgg.getExpression()); //$NON-NLS-1$
- AggregateSymbol sumAgg = new AggregateSymbol("stagedAgg", ReservedWords.SUM, false, partitionAgg.getExpression()); //$NON-NLS-1$
+ Aggregate countAgg = new Aggregate(ReservedWords.COUNT, false, partitionAgg.getExpression()); //$NON-NLS-1$
+ Aggregate sumAgg = new Aggregate(ReservedWords.SUM, false, partitionAgg.getExpression()); //$NON-NLS-1$
- AggregateSymbol sumSumAgg = new AggregateSymbol("stagedAgg", ReservedWords.SUM, false, sumAgg); //$NON-NLS-1$
- AggregateSymbol sumCountAgg = new AggregateSymbol("stagedAgg", ReservedWords.SUM, false, countAgg); //$NON-NLS-1$
+ Aggregate sumSumAgg = new Aggregate(ReservedWords.SUM, false, sumAgg); //$NON-NLS-1$
+ Aggregate sumCountAgg = new Aggregate(ReservedWords.SUM, false, countAgg); //$NON-NLS-1$
Function divideFunc = new Function("/", new Expression[] {sumSumAgg, sumCountAgg}); //$NON-NLS-1$
ResolverVisitorUtil.resolveFunction(divideFunc, metadata);
@@ -405,7 +405,7 @@
nestedAggregates.add(sumAgg);
} else {
//AGG(X) -> AGG(AGG(X))
- newExpression = new AggregateSymbol("stagedAgg", aggFunction, false, partitionAgg); //$NON-NLS-1$
+ newExpression = new Aggregate(aggFunction, false, partitionAgg); //$NON-NLS-1$
nestedAggregates.add(partitionAgg);
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseAccess.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -51,7 +51,7 @@
import com.metamatrix.query.sql.lang.JoinType;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.SetQuery.Operation;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
@@ -146,7 +146,7 @@
}
case NodeConstants.Types.GROUP:
{
- Set<AggregateSymbol> aggregates = RulePushAggregates.collectAggregates(parentNode);
+ Set<Aggregate> aggregates = RulePushAggregates.collectAggregates(parentNode);
if (canRaiseOverGroupBy(parentNode, accessNode, aggregates, metadata, capFinder)) {
return performRaise(rootNode, accessNode, parentNode);
}
@@ -216,7 +216,7 @@
static boolean canRaiseOverGroupBy(PlanNode groupNode,
PlanNode accessNode,
- Collection<? extends SingleElementSymbol> aggregates,
+ Set<Aggregate> aggregates,
QueryMetadataInterface metadata,
CapabilitiesFinder capFinder) throws QueryMetadataException,
MetaMatrixComponentException {
@@ -236,7 +236,7 @@
}
}
if (aggregates != null) {
- for (SingleElementSymbol aggregateSymbol : aggregates) {
+ for (Aggregate aggregateSymbol : aggregates) {
if(! CriteriaCapabilityValidatorVisitor.canPushLanguageObject(aggregateSymbol, modelID, metadata, capFinder)) {
return false;
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseNull.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseNull.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRaiseNull.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -42,7 +42,7 @@
import com.metamatrix.query.sql.lang.JoinType;
import com.metamatrix.query.sql.lang.SetQuery;
import com.metamatrix.query.sql.symbol.AliasSymbol;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
@@ -148,7 +148,7 @@
for (int i = 0; i < newProjectSymbols.size(); i++) {
SingleElementSymbol newSes = newProjectSymbols.get(i);
SingleElementSymbol oldSes = oldProjectSymbols.get(i);
- if (newSes instanceof ExpressionSymbol || !newSes.getShortCanonicalName().equals(oldSes.getShortCanonicalName())) {
+ if (newSes instanceof DerivedColumn || !newSes.getShortCanonicalName().equals(oldSes.getShortCanonicalName())) {
if (newSes instanceof AliasSymbol) {
newSes = ((AliasSymbol)newSes).getSymbol();
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -47,7 +47,7 @@
import com.metamatrix.query.sql.ReservedWords;
import com.metamatrix.query.sql.lang.Criteria;
import com.metamatrix.query.sql.lang.JoinType;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
@@ -267,8 +267,8 @@
break;
}
case NodeConstants.Types.GROUP: {
- Set<AggregateSymbol> aggs = RulePushAggregates.collectAggregates(parent);
- for (AggregateSymbol aggregateSymbol : aggs) {
+ Set<Aggregate> aggs = RulePushAggregates.collectAggregates(parent);
+ for (Aggregate aggregateSymbol : aggs) {
if (aggregateSymbol.getAggregateFunction().equalsIgnoreCase(ReservedWords.COUNT) ||
aggregateSymbol.getAggregateFunction().equalsIgnoreCase(ReservedWords.AVG)) {
return false;
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/xml/SourceNodePlannerVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/xml/SourceNodePlannerVisitor.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/optimizer/xml/SourceNodePlannerVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -53,6 +53,7 @@
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.Symbol;
import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
import com.metamatrix.query.sql.visitor.ExpressionMappingVisitor;
import com.metamatrix.query.sql.visitor.ReferenceCollectorVisitor;
@@ -112,7 +113,7 @@
baseQuery.getSelect().clearSymbols();
for (Iterator i = ResolverUtil.resolveElementsInGroup(groupSymbol, planEnv.getGlobalMetadata()).iterator(); i.hasNext();) {
SingleElementSymbol ses = (SingleElementSymbol)i.next();
- baseQuery.getSelect().addSymbol(new ElementSymbol(newGroup + SingleElementSymbol.SEPARATOR + ses.getShortName()));
+ baseQuery.getSelect().addSymbol(new ElementSymbol(newGroup + Symbol.SEPARATOR + ses.getShortName()));
}
rsInfo.setCommand(baseQuery);
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/proc/ExecDynamicSqlInstruction.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -73,9 +73,10 @@
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.Symbol;
import com.metamatrix.query.sql.util.VariableContext;
import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
import com.metamatrix.query.sql.visitor.ReferenceCollectorVisitor;
@@ -318,13 +319,13 @@
}
SingleElementSymbol wrappedSymbol = new ElementSymbol(groupSymbol
.getCanonicalName()
- + SingleElementSymbol.SEPARATOR
+ + Symbol.SEPARATOR
+ actualName);
Expression result = ResolverUtil.convertExpression(wrappedSymbol, DataTypeManager.getDataTypeName(projectedSymbolType), DataTypeManager.getDataTypeName(expectedSymbol.getType()));
if (!(result instanceof SingleElementSymbol)) {
- wrappedSymbol = new ExpressionSymbol(expectedName, result);
+ wrappedSymbol = new DerivedColumn(expectedName, result);
shouldAlias = true;
}
if (shouldAlias) {
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/GroupingNode.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -49,7 +49,7 @@
import com.metamatrix.query.function.aggregate.Sum;
import com.metamatrix.query.sql.ReservedWords;
import com.metamatrix.query.sql.lang.OrderBy;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.util.TypeRetrievalUtil;
@@ -168,8 +168,8 @@
Iterator outputIter = getElements().iterator();
while(outputIter.hasNext()) {
Object outputSymbol = outputIter.next();
- if(outputSymbol instanceof AggregateSymbol) {
- AggregateSymbol agg = (AggregateSymbol) outputSymbol;
+ if(outputSymbol instanceof Aggregate) {
+ Aggregate agg = (Aggregate) outputSymbol;
Expression expr = agg.getExpression();
if(expr != null && ! this.collectedExpressions.contains(expr)) {
this.collectedExpressions.add(expr);
@@ -186,8 +186,8 @@
functions = new AggregateFunction[getElements().size()];
for(int i=0; i<getElements().size(); i++) {
Object symbol = getElements().get(i);
- if(symbol instanceof AggregateSymbol) {
- AggregateSymbol aggSymbol = (AggregateSymbol) symbol;
+ if(symbol instanceof Aggregate) {
+ Aggregate aggSymbol = (Aggregate) symbol;
if(aggSymbol.getExpression() == null) {
functions[i] = new Count();
@@ -406,8 +406,8 @@
for(int i=0; i<functions.length; i++) {
Expression expression = (SingleElementSymbol) getElements().get(i);
- if(expression instanceof AggregateSymbol) {
- expression = ((AggregateSymbol)expression).getExpression();
+ if(expression instanceof Aggregate) {
+ expression = ((Aggregate)expression).getExpression();
}
Object value = null;
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/ProjectNode.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -36,11 +36,11 @@
import com.metamatrix.core.util.Assertion;
import com.metamatrix.query.eval.Evaluator;
import com.metamatrix.query.execution.QueryExecPlugin;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.SelectSymbol;
import com.metamatrix.query.util.ErrorMessageKeys;
@@ -125,7 +125,7 @@
symbol = ((AliasSymbol)symbol).getSymbol();
}
- if(symbol instanceof ElementSymbol || symbol instanceof AggregateSymbol) {
+ if(symbol instanceof ElementSymbol || symbol instanceof Aggregate) {
Integer index = (Integer) elementMap.get(symbol);
if(index == null || index.intValue() != i) {
// input / output element order is not the same
@@ -266,8 +266,8 @@
Integer index = (Integer) elementMap.get(symbol);
if(index != null) {
tuple.add(values.get(index.intValue()));
- } else if(symbol instanceof ExpressionSymbol) {
- Expression expression = ((ExpressionSymbol)symbol).getExpression();
+ } else if(symbol instanceof DerivedColumn) {
+ Expression expression = ((DerivedColumn)symbol).getExpression();
tuple.add(new Evaluator(elementMap, getDataManager(), getContext()).evaluate(expression, values));
} else {
Assertion.failed(QueryExecPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0034, symbol.getClass().getName()));
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/processor/relational/SortNode.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -36,6 +36,7 @@
import com.metamatrix.common.buffer.TupleSourceID;
import com.metamatrix.common.buffer.TupleSourceNotFoundException;
import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
public class SortNode extends RelationalNode {
@@ -68,7 +69,7 @@
this.collector = null;
}
- public void setSortElements(List sortElements, List sortTypes) {
+ public void setSortElements(List<OrderByItem> sortElements) {
this.sortElements = sortElements;
this.sortTypes = sortTypes;
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/DynamicCommandResolver.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/DynamicCommandResolver.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/DynamicCommandResolver.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -20,87 +20,87 @@
* 02110-1301 USA.
*/
-package com.metamatrix.query.resolver.command;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryResolverException;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.query.QueryPlugin;
-import com.metamatrix.query.analysis.AnalysisRecord;
-import com.metamatrix.query.metadata.TempMetadataAdapter;
-import com.metamatrix.query.metadata.TempMetadataID;
-import com.metamatrix.query.resolver.CommandResolver;
-import com.metamatrix.query.resolver.util.ResolverUtil;
-import com.metamatrix.query.resolver.util.ResolverVisitor;
-import com.metamatrix.query.resolver.util.ResolverVisitorUtil;
-import com.metamatrix.query.sql.ProcedureReservedWords;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.DynamicCommand;
-import com.metamatrix.query.sql.lang.SetClause;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
-
-public class DynamicCommandResolver implements CommandResolver {
-
- /**
- * @see com.metamatrix.query.resolver.CommandResolver#resolveCommand(com.metamatrix.query.sql.lang.Command, boolean, TempMetadataAdapter, AnalysisRecord, boolean)
- */
- public void resolveCommand(Command command, boolean useMetadataCommands, TempMetadataAdapter metadata, AnalysisRecord analysis, boolean resolveNullLiterals)
- throws QueryMetadataException, QueryResolverException, MetaMatrixComponentException {
-
- DynamicCommand dynamicCmd = (DynamicCommand)command;
-
- Iterator columns = dynamicCmd.getAsColumns().iterator();
-
- Set groups = new HashSet();
-
- //if there is no into group, just create temp metadata ids
- if (dynamicCmd.getIntoGroup() == null) {
- while (columns.hasNext()) {
- ElementSymbol column = (ElementSymbol)columns.next();
- column.setMetadataID(new TempMetadataID(column.getShortCanonicalName(), column.getType()));
- }
- } else if (dynamicCmd.getIntoGroup().isTempGroupSymbol()) {
- while (columns.hasNext()) {
- ElementSymbol column = (ElementSymbol)columns.next();
- column.setName(dynamicCmd.getIntoGroup().getCanonicalName() + SingleElementSymbol.SEPARATOR + column.getShortName());
- }
- }
-
- ResolverVisitor.resolveLanguageObject(dynamicCmd, groups, dynamicCmd.getExternalGroupContexts(), metadata);
-
- String sqlType = DataTypeManager.getDataTypeName(dynamicCmd.getSql().getType());
- String targetType = DataTypeManager.DefaultDataTypes.STRING;
-
- if (!targetType.equals(sqlType) && !DataTypeManager.isImplicitConversion(sqlType, targetType)) {
- throw new QueryResolverException(QueryPlugin.Util.getString("DynamicCommandResolver.SQL_String", sqlType)); //$NON-NLS-1$
- }
-
- if (dynamicCmd.getUsing() != null && !dynamicCmd.getUsing().isEmpty()) {
- for (SetClause clause : dynamicCmd.getUsing().getClauses()) {
- ElementSymbol id = clause.getSymbol();
- id.setName(ProcedureReservedWords.USING + SingleElementSymbol.SEPARATOR + id.getShortName());
- id.setGroupSymbol(new GroupSymbol(ProcedureReservedWords.USING));
- id.setType(clause.getValue().getType());
- id.setMetadataID(new TempMetadataID(id.getCanonicalName(), id.getType()));
- }
- }
-
- GroupSymbol intoSymbol = dynamicCmd.getIntoGroup();
- if (intoSymbol != null) {
- if (!intoSymbol.isImplicitTempGroupSymbol()) {
- ResolverVisitorUtil.resolveGroup(intoSymbol, metadata);
- } else {
- List symbols = dynamicCmd.getAsColumns();
- ResolverUtil.resolveImplicitTempGroup(metadata, intoSymbol, symbols);
- }
- }
- }
-}
+package com.metamatrix.query.resolver.command;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.query.QueryMetadataException;
+import com.metamatrix.api.exception.query.QueryResolverException;
+import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.query.QueryPlugin;
+import com.metamatrix.query.analysis.AnalysisRecord;
+import com.metamatrix.query.metadata.TempMetadataAdapter;
+import com.metamatrix.query.metadata.TempMetadataID;
+import com.metamatrix.query.resolver.CommandResolver;
+import com.metamatrix.query.resolver.util.ResolverUtil;
+import com.metamatrix.query.resolver.util.ResolverVisitor;
+import com.metamatrix.query.resolver.util.ResolverVisitorUtil;
+import com.metamatrix.query.sql.ProcedureReservedWords;
+import com.metamatrix.query.sql.lang.Command;
+import com.metamatrix.query.sql.lang.DynamicCommand;
+import com.metamatrix.query.sql.lang.SetClause;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.GroupSymbol;
+import com.metamatrix.query.sql.symbol.Symbol;
+
+public class DynamicCommandResolver implements CommandResolver {
+
+ /**
+ * @see com.metamatrix.query.resolver.CommandResolver#resolveCommand(com.metamatrix.query.sql.lang.Command, boolean, TempMetadataAdapter, AnalysisRecord, boolean)
+ */
+ public void resolveCommand(Command command, boolean useMetadataCommands, TempMetadataAdapter metadata, AnalysisRecord analysis, boolean resolveNullLiterals)
+ throws QueryMetadataException, QueryResolverException, MetaMatrixComponentException {
+
+ DynamicCommand dynamicCmd = (DynamicCommand)command;
+
+ Iterator columns = dynamicCmd.getAsColumns().iterator();
+
+ Set groups = new HashSet();
+
+ //if there is no into group, just create temp metadata ids
+ if (dynamicCmd.getIntoGroup() == null) {
+ while (columns.hasNext()) {
+ ElementSymbol column = (ElementSymbol)columns.next();
+ column.setMetadataID(new TempMetadataID(column.getShortCanonicalName(), column.getType()));
+ }
+ } else if (dynamicCmd.getIntoGroup().isTempGroupSymbol()) {
+ while (columns.hasNext()) {
+ ElementSymbol column = (ElementSymbol)columns.next();
+ column.setName(dynamicCmd.getIntoGroup().getCanonicalName() + Symbol.SEPARATOR + column.getShortName());
+ }
+ }
+
+ ResolverVisitor.resolveLanguageObject(dynamicCmd, groups, dynamicCmd.getExternalGroupContexts(), metadata);
+
+ String sqlType = DataTypeManager.getDataTypeName(dynamicCmd.getSql().getType());
+ String targetType = DataTypeManager.DefaultDataTypes.STRING;
+
+ if (!targetType.equals(sqlType) && !DataTypeManager.isImplicitConversion(sqlType, targetType)) {
+ throw new QueryResolverException(QueryPlugin.Util.getString("DynamicCommandResolver.SQL_String", sqlType)); //$NON-NLS-1$
+ }
+
+ if (dynamicCmd.getUsing() != null && !dynamicCmd.getUsing().isEmpty()) {
+ for (SetClause clause : dynamicCmd.getUsing().getClauses()) {
+ ElementSymbol id = clause.getSymbol();
+ id.setName(ProcedureReservedWords.USING + Symbol.SEPARATOR + id.getShortName());
+ id.setGroupSymbol(new GroupSymbol(ProcedureReservedWords.USING));
+ id.setType(clause.getValue().getType());
+ id.setMetadataID(new TempMetadataID(id.getCanonicalName(), id.getType()));
+ }
+ }
+
+ GroupSymbol intoSymbol = dynamicCmd.getIntoGroup();
+ if (intoSymbol != null) {
+ if (!intoSymbol.isImplicitTempGroupSymbol()) {
+ ResolverVisitorUtil.resolveGroup(intoSymbol, metadata);
+ } else {
+ List symbols = dynamicCmd.getAsColumns();
+ ResolverUtil.resolveImplicitTempGroup(metadata, intoSymbol, symbols);
+ }
+ }
+ }
+}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/SetQueryResolver.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/SetQueryResolver.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/SetQueryResolver.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -41,7 +41,7 @@
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.QueryCommand;
import com.metamatrix.query.sql.lang.SetQuery;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.util.ErrorMessageKeys;
public class SetQueryResolver implements CommandResolver {
@@ -59,10 +59,9 @@
QueryResolver.setChildMetadata(firstCommand, setQuery);
QueryResolver.resolveCommand(firstCommand, Collections.EMPTY_MAP, useMetadataCommands, metadata.getMetadata(), analysis, false);
- List firstProject = firstCommand.getProjectedSymbols();
+ List<DerivedColumn> firstProject = firstCommand.getProjectedSymbols();
List<Class<?>> firstProjectTypes = new ArrayList<Class<?>>();
- for (Iterator j = firstProject.iterator(); j.hasNext();) {
- SingleElementSymbol symbol = (SingleElementSymbol)j.next();
+ for (DerivedColumn symbol : firstProject) {
firstProjectTypes.add(symbol.getType());
}
@@ -111,10 +110,10 @@
continue;
}
SetQuery child = (SetQuery)subCommand;
- List projectedSymbols = child.getProjectedSymbols();
+ List<DerivedColumn> projectedSymbols = child.getProjectedSymbols();
if (child.getOrderBy() != null) {
for (int j = 0; j < projectedSymbols.size(); j++) {
- SingleElementSymbol ses = (SingleElementSymbol)projectedSymbols.get(j);
+ DerivedColumn ses = projectedSymbols.get(j);
Class targetType = (Class)firstProjectTypes.get(j);
if (ses.getType() != targetType && ResolverUtil.orderByContainsVariable(child.getOrderBy(), ses, j)) {
String sourceTypeName = DataTypeManager.getDataTypeName(ses.getType());
@@ -129,10 +128,10 @@
}
}
- static void checkSymbolTypes(List firstProjectTypes, List projSymbols) {
+ static void checkSymbolTypes(List firstProjectTypes, List<DerivedColumn> projSymbols) {
for(int j=0; j<projSymbols.size(); j++){
Class firstProjType = (Class)firstProjectTypes.get(j);
- SingleElementSymbol projSymbol = (SingleElementSymbol)projSymbols.get(j);
+ DerivedColumn projSymbol = projSymbols.get(j);
Class projType = projSymbol.getType();
if(firstProjType.equals(projType)){
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/SimpleQueryResolver.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/SimpleQueryResolver.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/SimpleQueryResolver.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -75,15 +75,13 @@
import com.metamatrix.query.sql.lang.SubquerySetCriteria;
import com.metamatrix.query.sql.lang.UnaryFromClause;
import com.metamatrix.query.sql.navigator.PostOrderNavigator;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.AllInGroupSymbol;
import com.metamatrix.query.sql.symbol.AllSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.symbol.ScalarSubquery;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.util.ErrorMessageKeys;
import com.metamatrix.query.util.LogConstants;
@@ -556,7 +554,7 @@
aliasName += "_IN"; //$NON-NLS-1$
}
- SingleElementSymbol newSymbol = new AliasSymbol(aliasName, new ExpressionSymbol(paramSymbol.getShortName(), ref));
+ DerivedColumn newSymbol = new DerivedColumn(aliasName, ref, true);
select.addSymbol(newSymbol);
accessPatternElementNames.add(queryName + ElementSymbol.SEPARATOR + aliasName);
@@ -565,12 +563,11 @@
QueryResolver.resolveCommand(procQuery, Collections.EMPTY_MAP, expandCommand, metadata.getMetadata(), analysis);
- List projectedSymbols = procQuery.getProjectedSymbols();
+ List<DerivedColumn> projectedSymbols = procQuery.getProjectedSymbols();
- HashSet foundNames = new HashSet();
+ HashSet<String> foundNames = new HashSet<String>();
- for (Iterator i = projectedSymbols.iterator(); i.hasNext();) {
- SingleElementSymbol ses = (SingleElementSymbol)i.next();
+ for (DerivedColumn ses : projectedSymbols) {
if (!foundNames.add(ses.getShortCanonicalName())) {
throw new QueryResolverException(QueryPlugin.Util.getString("SimpleQueryResolver.Proc_Relational_Name_conflict", fullName)); //$NON-NLS-1$
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/UpdateProcedureResolver.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -69,7 +69,6 @@
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.util.ErrorMessageKeys;
import com.metamatrix.query.util.LogConstants;
@@ -115,7 +114,7 @@
// then in the query transformation, this info is used in evaluating/validating
// has criteria/trnaslate criteria clauses
Command transformCmd = getQueryTransformCmd(virtualGroup, metadata);
- Map symbolMap = SymbolMap.createSymbolMap(virtualGroup, (List<SingleElementSymbol>)transformCmd.getProjectedSymbols()).asMap();
+ Map symbolMap = SymbolMap.createSymbolMap(virtualGroup, transformCmd.getProjectedSymbols()).asMap();
// set the symbolMap on the procedure
procCommand.setSymbolMap(symbolMap);
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/XMLQueryResolver.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/XMLQueryResolver.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/command/XMLQueryResolver.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -47,11 +47,10 @@
import com.metamatrix.query.sql.lang.OrderBy;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.AllInGroupSymbol;
import com.metamatrix.query.sql.symbol.AllSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.SelectSymbol;
import com.metamatrix.query.sql.visitor.CommandCollectorVisitor;
@@ -145,7 +144,13 @@
for (int i = 0; i < elements.size(); i++) {
SelectSymbol ss = (SelectSymbol) elements.get(i);
- if (ss instanceof ElementSymbol) {
+ if (ss instanceof DerivedColumn) {
+ DerivedColumn dc = (DerivedColumn)ss;
+ if (!(dc.getExpression() instanceof ElementSymbol)) {
+ throw new QueryResolverException(QueryPlugin.Util.getString("XMLQueryResolver.no_expressions_in_select")); //$NON-NLS-1$
+ } else if (dc.isAlias()) {
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0070, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0070));
+ }
// Here we make an assumption that: all elements named with "xml" must use qualified name
// rather than a simple "xml" in order to distinguish it from "SELECT xml" and
// "SELECT model.document.xml" case, both of whom stand for selecting the whole document.
@@ -169,7 +174,7 @@
return;
}
// normal elements
- resolveElement((ElementSymbol)ss, validElements, externalGroups, metadata);
+ resolveElement((ElementSymbol)dc.getExpression(), validElements, externalGroups, metadata);
} else if (ss instanceof AllInGroupSymbol) {
// Resolve the element with "*" case. such as "A.*"
// by stripping off the ".*" part,
@@ -197,12 +202,7 @@
AllSymbol all = (AllSymbol)ss;
all.setElementSymbols(validElements);
return;
- } else if (ss instanceof ExpressionSymbol) {
- throw new QueryResolverException(QueryPlugin.Util.getString("XMLQueryResolver.no_expressions_in_select")); //$NON-NLS-1$
- } else if (ss instanceof AliasSymbol) {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0070, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0070));
- }
-
+ }
}
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -37,7 +37,6 @@
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.common.types.TransformationException;
import com.metamatrix.common.types.DataTypeManager.DefaultDataTypes;
-import com.metamatrix.core.util.StringUtil;
import com.metamatrix.query.QueryPlugin;
import com.metamatrix.query.function.FunctionDescriptor;
import com.metamatrix.query.function.FunctionLibrary;
@@ -51,19 +50,18 @@
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.lang.Limit;
import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.symbol.AbstractCaseExpression;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.symbol.ScalarSubquery;
import com.metamatrix.query.sql.symbol.SelectSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
import com.metamatrix.query.util.ErrorMessageKeys;
/**
@@ -251,118 +249,118 @@
* ones allowed to be in ORDER BY
* @param metadata QueryMetadataInterface
*/
- public static void resolveOrderBy(OrderBy orderBy, List fromClauseGroups, List knownElements, QueryMetadataInterface metadata)
+ public static void resolveOrderBy(OrderBy orderBy, List<GroupSymbol> fromClauseGroups, List<DerivedColumn> knownElements, QueryMetadataInterface metadata)
throws QueryResolverException, QueryMetadataException, MetaMatrixComponentException {
- orderBy.setInPlanForm(false);
-
// Cached state, if needed
String[] knownShortNames = null;
// Collect all elements from order by
- List elements = orderBy.getVariables();
- Iterator elementIter = elements.iterator();
+ List<OrderByItem> elements = orderBy.getSortOrder();
// Walk through elements of order by
- while(elementIter.hasNext()){
- ElementSymbol symbol = (ElementSymbol) elementIter.next();
- SingleElementSymbol matchedSymbol = null;
- String symbolName = symbol.getName();
- String groupPart = metadata.getGroupName(symbolName);
- String shortName = symbol.getShortName();
-
- //check for union order by (allow uuids to skip this check)
- if (fromClauseGroups.isEmpty() && groupPart != null && !shortName.equals(symbolName)) {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0043, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0043, symbolName));
- }
-
- // construct the array of short names of the SELECT columns (once only)
- if(knownShortNames == null) {
- knownShortNames = new String[knownElements.size()];
-
- for(int i=0; i<knownElements.size(); i++) {
- SingleElementSymbol knownSymbol = (SingleElementSymbol) knownElements.get(i);
- if (knownSymbol instanceof ExpressionSymbol) {
- continue;
- }
-
- String name = knownSymbol.getShortName();
- //special check for uuid element symbols
- if (knownSymbol instanceof ElementSymbol && knownSymbol.getShortName().equalsIgnoreCase(knownSymbol.getName())) {
- name = metadata.getShortElementName(metadata.getFullName((((ElementSymbol)knownSymbol).getMetadataID())));
- }
-
- knownShortNames[i] = name;
- }
- }
- // walk the SELECT col short names, looking for a match on the current ORDER BY 'short name'
- for(int i=0; i<knownShortNames.length; i++) {
- if( shortName.equalsIgnoreCase( knownShortNames[i] )) {
- if (groupPart != null) {
- Object knownSymbol = knownElements.get(i);
- if(knownSymbol instanceof ElementSymbol) {
- ElementSymbol knownElement = (ElementSymbol) knownSymbol;
- GroupSymbol group = knownElement.getGroupSymbol();
-
- // skip this one if the two short names are not from the same group
- if (!nameMatchesGroup(groupPart.toUpperCase(), group.getCanonicalName())) {
- continue;
- }
- }
- }
-
- // if we already have a matched symbol, matching again here means it is duplicate/ambiguous
- if(matchedSymbol != null) {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0042, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0042, symbolName));
- }
- matchedSymbol = (SingleElementSymbol)knownElements.get(i);
- }
- }
-
- // this clause handles the order by clause like
- // select foo from bar order by "1"; where 1 is foo.
- if (matchedSymbol == null && StringUtil.isDigits(symbolName)) {
- int elementOrder = Integer.valueOf(symbolName).intValue() - 1;
- // adjust for the 1 based index.
- if (elementOrder < knownElements.size() && elementOrder >= 0) {
- matchedSymbol = (SingleElementSymbol)knownElements.get(elementOrder);
-
- for(int i=0; i<knownShortNames.length; i++) {
- if (i == elementOrder) {
- continue;
- }
- if (matchedSymbol.getShortCanonicalName().equalsIgnoreCase(knownShortNames[i])) {
- throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0042, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0042, knownShortNames[i]));
- }
- }
- }
- }
-
- if(matchedSymbol == null) {
- // Didn't find it by full name or short name, so try resolving
- // and retrying by full name - this will work for uuid case
- try {
- ResolverVisitor.resolveLanguageObject(symbol, fromClauseGroups, metadata);
- } catch(QueryResolverException e) {
- throw new QueryResolverException(e, ErrorMessageKeys.RESOLVER_0043, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0043, symbol.getName()) );
- }
-
- matchedSymbol = findMatchingElementByID(symbol, knownElements);
- }
-
- TempMetadataID tempMetadataID = new TempMetadataID(symbol.getName(), matchedSymbol.getType());
- tempMetadataID.setPosition(knownElements.indexOf(matchedSymbol));
- symbol.setMetadataID(tempMetadataID);
- symbol.setType(matchedSymbol.getType());
+ for (OrderByItem orderByItem : elements) {
+ Collection<ElementSymbol> symbols = ElementCollectorVisitor.getElements(orderByItem.getSortKey(), false);
+ if (symbols.isEmpty()) {
+ if (orderByItem.getSortKey() instanceof Constant) {
+ Constant c = (Constant)orderByItem.getSortKey();
+ if (DataTypeManager.DefaultDataClasses.INTEGER == c.getType()) {
+ int value = (Integer)c.getValue();
+ if (value < 0 || value > knownElements.size() -1) {
+ throw new QueryResolverException("Invalid order by ordinal");
+ }
+ DerivedColumn matchedSymbol = knownElements.get(value);
+ ElementSymbol symbol = new ElementSymbol(matchedSymbol.getName());
+ resolveOrderByItem(value, symbol, matchedSymbol);
+ continue;
+ }
+ }
+ throw new QueryResolverException("Invalid order by expression");
+ }
+ for (ElementSymbol elementSymbol : symbols) {
+ DerivedColumn matchedSymbol = null;
+ String symbolName = elementSymbol.getName();
+ String groupPart = metadata.getGroupName(symbolName);
+ String shortName = elementSymbol.getShortName();
+
+ //check for union order by (allow uuids to skip this check)
+ if (fromClauseGroups.isEmpty() && groupPart != null && !shortName.equals(symbolName)) {
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0043, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0043, symbolName));
+ }
+
+ // construct the array of short names of the SELECT columns (once only)
+ if(knownShortNames == null) {
+ knownShortNames = new String[knownElements.size()];
+
+ for(int i=0; i<knownElements.size(); i++) {
+ DerivedColumn knownSymbol = knownElements.get(i);
+
+ String name = knownSymbol.getShortName();
+
+ Expression expr = knownSymbol.getExpression();
+ //special check for uuid element symbols
+ if (expr instanceof ElementSymbol && knownSymbol.getShortName().equalsIgnoreCase(knownSymbol.getName())) {
+ name = metadata.getShortElementName(metadata.getFullName((((ElementSymbol)expr).getMetadataID())));
+ }
+
+ knownShortNames[i] = name;
+ }
+ }
+ // walk the SELECT col short names, looking for a match on the current ORDER BY 'short name'
+ for(int i=0; i<knownShortNames.length; i++) {
+ if( shortName.equalsIgnoreCase( knownShortNames[i] )) {
+ if (groupPart != null) {
+ Object knownSymbol = knownElements.get(i);
+ if(knownSymbol instanceof ElementSymbol) {
+ ElementSymbol knownElement = (ElementSymbol) knownSymbol;
+ GroupSymbol group = knownElement.getGroupSymbol();
+
+ // skip this one if the two short names are not from the same group
+ if (!nameMatchesGroup(groupPart.toUpperCase(), group.getCanonicalName())) {
+ continue;
+ }
+ }
+ }
+
+ // if we already have a matched symbol, matching again here means it is duplicate/ambiguous
+ if(matchedSymbol != null) {
+ throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0042, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0042, symbolName));
+ }
+ matchedSymbol = knownElements.get(i);
+ resolveOrderByItem(i, elementSymbol, matchedSymbol);
+ }
+ }
+
+ if(matchedSymbol == null) {
+ // Didn't find it by full name or short name, so try resolving
+ // and retrying by full name - this will work for uuid case
+ try {
+ ResolverVisitor.resolveLanguageObject(elementSymbol, fromClauseGroups, metadata);
+ } catch(QueryResolverException e) {
+ throw new QueryResolverException(e, ErrorMessageKeys.RESOLVER_0043, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0043, elementSymbol.getName()) );
+ }
+
+ findMatchingElementByID(elementSymbol, knownElements);
+ }
+ }
+ ResolverVisitor.resolveLanguageObject(orderByItem.getSortKey(), metadata);
}
}
+ private static void resolveOrderByItem(int position,
+ ElementSymbol elementSymbol, DerivedColumn matchedSymbol) {
+ TempMetadataID tempMetadataID = new TempMetadataID(matchedSymbol.getName(), matchedSymbol.getType());
+ tempMetadataID.setPosition(position);
+ elementSymbol.setMetadataID(tempMetadataID);
+ elementSymbol.setType(matchedSymbol.getType());
+ }
+
/**
* Helper for resolveOrderBy to find a matching fully-qualified element in a list of
* projected SELECT symbols.
* @throws QueryResolverException
*/
- private static SingleElementSymbol findMatchingElementByID(ElementSymbol symbol, List knownElements) throws QueryResolverException {
+ private static void findMatchingElementByID(ElementSymbol symbol, List<DerivedColumn> knownElements) throws QueryResolverException {
Object elementID = symbol.getMetadataID();
if(elementID == null) {
@@ -372,20 +370,17 @@
Object groupID = symbol.getGroupSymbol().getMetadataID();
for(int i=0; i<knownElements.size(); i++) {
- SingleElementSymbol selectSymbol = (SingleElementSymbol)knownElements.get(i);
- SingleElementSymbol knownSymbol = null;
- if(selectSymbol instanceof AliasSymbol) {
- knownSymbol = ((AliasSymbol)selectSymbol).getSymbol();
- }
+ DerivedColumn selectSymbol = knownElements.get(i);
- if(knownSymbol instanceof ElementSymbol) {
- ElementSymbol knownElement = (ElementSymbol) knownSymbol;
+ if(selectSymbol.getExpression() instanceof ElementSymbol) {
+ ElementSymbol knownElement = (ElementSymbol) selectSymbol.getExpression();
Object knownElementID = knownElement.getMetadataID();
if(elementID.equals(knownElementID)) {
Object knownGroupID = knownElement.getGroupSymbol().getMetadataID();
if(groupID.equals(knownGroupID)) {
- return selectSymbol;
+ resolveOrderByItem(i, symbol, selectSymbol);
+ return;
}
}
}
@@ -567,10 +562,10 @@
public static void addTempGroup(TempMetadataAdapter metadata,
GroupSymbol symbol,
- List symbols, boolean tempTable) throws QueryResolverException {
+ List<DerivedColumn> symbols, boolean tempTable) throws QueryResolverException {
HashSet names = new HashSet();
for (Iterator i = symbols.iterator(); i.hasNext();) {
- SingleElementSymbol ses = (SingleElementSymbol)i.next();
+ DerivedColumn ses = (DerivedColumn)i.next();
if (!names.add(ses.getShortCanonicalName())) {
throw new QueryResolverException(QueryPlugin.Util.getString("ResolverUtil.duplicateName", symbol, ses.getShortName())); //$NON-NLS-1$
}
@@ -597,48 +592,40 @@
* @param select The select clause
* @since 4.2
*/
- public static void resolveNullLiterals(List symbols) {
- for (int i = 0; i < symbols.size(); i++) {
- SelectSymbol selectSymbol = (SelectSymbol) symbols.get(i);
-
- if (!(selectSymbol instanceof SingleElementSymbol)) {
+ public static void resolveNullLiterals(List<? extends SelectSymbol> symbols) {
+ for (SelectSymbol selectSymbol : symbols) {
+ if (!(selectSymbol instanceof DerivedColumn)) {
continue;
}
- SingleElementSymbol symbol = (SingleElementSymbol)selectSymbol;
+ DerivedColumn symbol = (DerivedColumn)selectSymbol;
if(!DataTypeManager.DefaultDataClasses.NULL.equals(symbol.getType()) && symbol.getType() != null) {
continue;
}
- if(symbol instanceof AliasSymbol) {
- symbol = ((AliasSymbol)symbol).getSymbol();
- }
+
+ Expression expr = symbol.getExpression();
Class replacement = DataTypeManager.DefaultDataClasses.STRING;
-
- if(symbol instanceof ExpressionSymbol && !(symbol instanceof AggregateSymbol)) {
- ExpressionSymbol exprSymbol = (ExpressionSymbol) symbol;
- Expression expr = exprSymbol.getExpression();
-
- if(expr instanceof Constant) {
- exprSymbol.setExpression(new Constant(null, replacement));
- } else if (expr instanceof AbstractCaseExpression) {
- ((AbstractCaseExpression)expr).setType(replacement);
- } else if (expr instanceof ScalarSubquery) {
- ((ScalarSubquery)expr).setType(replacement);
- } else {
- try {
- ResolverUtil.setTypeIfReference(expr, replacement, symbol);
- } catch (QueryResolverException e) {
- //cannot happen
- }
- }
- } else if(symbol instanceof ElementSymbol) {
- ElementSymbol elementSymbol = (ElementSymbol)symbol;
+
+ if(expr instanceof ElementSymbol) {
+ ElementSymbol elementSymbol = (ElementSymbol)expr;
Class elementType = elementSymbol.getType();
if(elementType != null && elementType.equals(DataTypeManager.DefaultDataClasses.NULL)) {
elementSymbol.setType(replacement);
}
+ } else if(expr instanceof Constant) {
+ symbol.setExpression(new Constant(null, replacement));
+ } else if (expr instanceof AbstractCaseExpression) {
+ ((AbstractCaseExpression)expr).setType(replacement);
+ } else if (expr instanceof ScalarSubquery) {
+ ((ScalarSubquery)expr).setType(replacement);
+ } else {
+ try {
+ ResolverUtil.setTypeIfReference(expr, replacement, symbol);
+ } catch (QueryResolverException e) {
+ //cannot happen
+ }
}
}
}
@@ -726,18 +713,9 @@
* @param position 0-based index of the variable
* @return True if the ORDER BY contains the element
*/
- public static boolean orderByContainsVariable(OrderBy orderBy, SingleElementSymbol ses, int position) {
- if (!orderBy.isInPlanForm()) {
- for (final Iterator iterator = orderBy.getVariables().iterator(); iterator.hasNext();) {
- final ElementSymbol element = (ElementSymbol)iterator.next();
- if (position == ((TempMetadataID)element.getMetadataID()).getPosition()) {
- return true;
- }
- }
- } else {
- return orderBy.getVariables().contains(ses);
- }
- return false;
+ public static boolean orderByContainsVariable(OrderBy orderBy, DerivedColumn ses, int position) {
+ throw new UnsupportedOperationException();
+ //return false;
}
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverVisitorUtil.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -52,7 +52,7 @@
import com.metamatrix.query.sql.lang.MatchCriteria;
import com.metamatrix.query.sql.lang.SetCriteria;
import com.metamatrix.query.sql.lang.SubqueryContainer;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
@@ -146,8 +146,8 @@
Expression leftExpression = ccrit.getLeftExpression();
Expression rightExpression = ccrit.getRightExpression();
- boolean leftIsAggregate = (leftExpression instanceof AggregateSymbol);
- boolean rightIsAggregate = (rightExpression instanceof AggregateSymbol);
+ boolean leftIsAggregate = (leftExpression instanceof Aggregate);
+ boolean rightIsAggregate = (rightExpression instanceof Aggregate);
// Check typing between expressions
ResolverUtil.setTypeIfReference(leftExpression, rightExpression.getType(), ccrit);
@@ -205,7 +205,7 @@
// both are aggs of differing types - can't reconcile
throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0064, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0064));
}
- AggregateSymbol aggRight = (AggregateSymbol) rightExpression;
+ Aggregate aggRight = (Aggregate) rightExpression;
String aggFunc = aggRight.getAggregateFunction();
// Convert expression inside MIN/MAX function rather than converting aggregate
if((aggFunc.equals(ReservedWords.MIN) || aggFunc.equals(ReservedWords.MAX)) &&
@@ -215,7 +215,7 @@
throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0028, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0028));
}
} else if(leftIsAggregate) {
- AggregateSymbol aggLeft = (AggregateSymbol) leftExpression;
+ Aggregate aggLeft = (Aggregate) leftExpression;
String aggFunc = aggLeft.getAggregateFunction();
// Convert expression inside MIN/MAX function rather than converting aggregate
if((aggFunc.equals(ReservedWords.MIN) || aggFunc.equals(ReservedWords.MAX)) &&
@@ -264,12 +264,12 @@
if (! type.equals(DataTypeManager.DefaultDataTypes.STRING) &&
! type.equals(DataTypeManager.DefaultDataTypes.CLOB)) {
- if(!(expr instanceof AggregateSymbol) &&
+ if(!(expr instanceof Aggregate) &&
ResolverUtil.canImplicitlyConvert(type, DataTypeManager.DefaultDataTypes.STRING)) {
result = ResolverUtil.convertExpression(expr, type, DataTypeManager.DefaultDataTypes.STRING);
- } else if (!(expr instanceof AggregateSymbol) &&
+ } else if (!(expr instanceof Aggregate) &&
ResolverUtil.canImplicitlyConvert(type, DataTypeManager.DefaultDataTypes.CLOB)){
result = ResolverUtil.convertExpression(expr, type, DataTypeManager.DefaultDataTypes.CLOB);
@@ -303,7 +303,7 @@
Expression value = (Expression) valIter.next();
ResolverUtil.setTypeIfReference(value, exprType, scrit);
if(! value.getType().equals(exprType)) {
- if(value instanceof AggregateSymbol) {
+ if(value instanceof Aggregate) {
throw new QueryResolverException(ErrorMessageKeys.RESOLVER_0031, QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0031, scrit));
}
// try to apply cast
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -124,18 +124,16 @@
import com.metamatrix.query.sql.proc.Statement;
import com.metamatrix.query.sql.proc.TranslateCriteria;
import com.metamatrix.query.sql.proc.WhileStatement;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.ScalarSubquery;
import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.util.SymbolMap;
import com.metamatrix.query.sql.visitor.AggregateSymbolCollectorVisitor;
import com.metamatrix.query.sql.visitor.CorrelatedVariableSubstitutionVisitor;
@@ -699,7 +697,7 @@
// we check for group by expressions here to create an ANSI SQL plan
boolean hasExpression = false;
for (final Iterator iterator = query.getGroupBy().getSymbols().iterator(); !hasExpression && iterator.hasNext();) {
- hasExpression = iterator.next() instanceof ExpressionSymbol;
+ hasExpression = iterator.next() instanceof DerivedColumn;
}
if (hasExpression) {
Select select = query.getSelect();
@@ -717,12 +715,12 @@
for (final Iterator iterator = groupBy.getSymbols().iterator(); iterator.hasNext();) {
newSelectColumns.add(SymbolMap.getExpression((SingleElementSymbol)iterator.next()));
}
- Set<AggregateSymbol> aggs = new HashSet<AggregateSymbol>();
+ Set<Aggregate> aggs = new HashSet<Aggregate>();
aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(select, true));
if (having != null) {
aggs.addAll(AggregateSymbolCollectorVisitor.getAggregates(having, true));
}
- for (AggregateSymbol aggregateSymbol : aggs) {
+ for (Aggregate aggregateSymbol : aggs) {
if (aggregateSymbol.getExpression() != null) {
Expression expr = aggregateSymbol.getExpression();
newSelectColumns.add(SymbolMap.getExpression(expr));
@@ -734,7 +732,7 @@
if (expr instanceof SingleElementSymbol) {
innerSelect.addSymbol((SingleElementSymbol)expr);
} else {
- innerSelect.addSymbol(new ExpressionSymbol("EXPR" + index++ , expr)); //$NON-NLS-1$
+ innerSelect.addSymbol(new DerivedColumn("EXPR" + index++ , expr)); //$NON-NLS-1$
}
}
query.setSelect(innerSelect);
@@ -1982,21 +1980,20 @@
} else if (expression instanceof ScalarSubquery) {
rewriteSubqueryContainer((ScalarSubquery)expression, procCommand, context, metadata);
return expression;
- } else if (expression instanceof ExpressionSymbol && !(expression instanceof AggregateSymbol)) {
- return rewriteExpression(((ExpressionSymbol)expression).getExpression(), procCommand, context, metadata);
- } else if(expression instanceof AggregateSymbol){
- return rewriteExpression((AggregateSymbol)expression);
+ } else if (expression instanceof DerivedColumn && !(expression instanceof Aggregate)) {
+ return rewriteExpression(((DerivedColumn)expression).getExpression(), procCommand, context, metadata);
+ } else if(expression instanceof Aggregate){
+ return rewriteExpression((Aggregate)expression);
}
return expression;
}
- private static Expression rewriteExpression(AggregateSymbol expression) {
+ private static Expression rewriteExpression(Aggregate expression) {
if (!expression.getAggregateFunction().equals(ReservedWords.COUNT)
&& !expression.getAggregateFunction().equals(ReservedWords.SUM)
&& EvaluateExpressionVisitor.willBecomeConstant(expression.getExpression())) {
try {
- return new ExpressionSymbol(expression.getName(), ResolverUtil
- .convertExpression(expression.getExpression(),DataTypeManager.getDataTypeName(expression.getType())));
+ return ResolverUtil.convertExpression(expression.getExpression(),DataTypeManager.getDataTypeName(expression.getType()));
} catch (QueryResolverException e) {
//should not happen, so throw as a runtime
throw new MetaMatrixRuntimeException(e);
@@ -2454,7 +2451,7 @@
name = baseName + '_' + (exprID++);
}
- if (expressionSymbolsOnly && !(symbol instanceof ExpressionSymbol)) {
+ if (expressionSymbolsOnly && !(symbol instanceof DerivedColumn)) {
continue;
}
@@ -2465,7 +2462,7 @@
hasAlias = true;
}
- if (((symbol instanceof ExpressionSymbol) && !hasAlias) || !name.equalsIgnoreCase(baseName)) {
+ if (((symbol instanceof DerivedColumn) && !hasAlias) || !name.equalsIgnoreCase(baseName)) {
symbols.set(i, new AliasSymbol(name, symbol));
}
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/LanguageVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/LanguageVisitor.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/LanguageVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -22,9 +22,70 @@
package com.metamatrix.query.sql;
-import com.metamatrix.query.sql.lang.*;
-import com.metamatrix.query.sql.symbol.*;
-import com.metamatrix.query.sql.proc.*;
+import com.metamatrix.query.sql.lang.BatchedUpdateCommand;
+import com.metamatrix.query.sql.lang.BetweenCriteria;
+import com.metamatrix.query.sql.lang.BulkInsert;
+import com.metamatrix.query.sql.lang.CompareCriteria;
+import com.metamatrix.query.sql.lang.CompoundCriteria;
+import com.metamatrix.query.sql.lang.Create;
+import com.metamatrix.query.sql.lang.Delete;
+import com.metamatrix.query.sql.lang.DependentSetCriteria;
+import com.metamatrix.query.sql.lang.Drop;
+import com.metamatrix.query.sql.lang.DynamicCommand;
+import com.metamatrix.query.sql.lang.ExistsCriteria;
+import com.metamatrix.query.sql.lang.From;
+import com.metamatrix.query.sql.lang.GroupBy;
+import com.metamatrix.query.sql.lang.Insert;
+import com.metamatrix.query.sql.lang.Into;
+import com.metamatrix.query.sql.lang.IsNullCriteria;
+import com.metamatrix.query.sql.lang.JoinPredicate;
+import com.metamatrix.query.sql.lang.JoinType;
+import com.metamatrix.query.sql.lang.Limit;
+import com.metamatrix.query.sql.lang.MatchCriteria;
+import com.metamatrix.query.sql.lang.NotCriteria;
+import com.metamatrix.query.sql.lang.Option;
+import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
+import com.metamatrix.query.sql.lang.ProcedureContainer;
+import com.metamatrix.query.sql.lang.Query;
+import com.metamatrix.query.sql.lang.Select;
+import com.metamatrix.query.sql.lang.SetClause;
+import com.metamatrix.query.sql.lang.SetClauseList;
+import com.metamatrix.query.sql.lang.SetCriteria;
+import com.metamatrix.query.sql.lang.SetQuery;
+import com.metamatrix.query.sql.lang.StoredProcedure;
+import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
+import com.metamatrix.query.sql.lang.SubqueryFromClause;
+import com.metamatrix.query.sql.lang.SubquerySetCriteria;
+import com.metamatrix.query.sql.lang.UnaryFromClause;
+import com.metamatrix.query.sql.lang.Update;
+import com.metamatrix.query.sql.lang.XQuery;
+import com.metamatrix.query.sql.proc.AssignmentStatement;
+import com.metamatrix.query.sql.proc.Block;
+import com.metamatrix.query.sql.proc.BreakStatement;
+import com.metamatrix.query.sql.proc.CommandStatement;
+import com.metamatrix.query.sql.proc.ContinueStatement;
+import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
+import com.metamatrix.query.sql.proc.CriteriaSelector;
+import com.metamatrix.query.sql.proc.DeclareStatement;
+import com.metamatrix.query.sql.proc.HasCriteria;
+import com.metamatrix.query.sql.proc.IfStatement;
+import com.metamatrix.query.sql.proc.LoopStatement;
+import com.metamatrix.query.sql.proc.RaiseErrorStatement;
+import com.metamatrix.query.sql.proc.TranslateCriteria;
+import com.metamatrix.query.sql.proc.WhileStatement;
+import com.metamatrix.query.sql.symbol.Aggregate;
+import com.metamatrix.query.sql.symbol.AllInGroupSymbol;
+import com.metamatrix.query.sql.symbol.AllSymbol;
+import com.metamatrix.query.sql.symbol.CaseExpression;
+import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.Function;
+import com.metamatrix.query.sql.symbol.GroupSymbol;
+import com.metamatrix.query.sql.symbol.Reference;
+import com.metamatrix.query.sql.symbol.ScalarSubquery;
+import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
/**
* <p>The LanguageVisitor can be used to visit a LanguageObject as if it were a tree
@@ -91,13 +152,12 @@
public void visit(Drop obj) {}
// Visitor methods for symbol objects
- public void visit(AggregateSymbol obj) {}
- public void visit(AliasSymbol obj) {}
+ public void visit(Aggregate obj) {}
public void visit(AllInGroupSymbol obj) {}
public void visit(AllSymbol obj) {}
public void visit(Constant obj) {}
public void visit(ElementSymbol obj) {}
- public void visit(ExpressionSymbol obj) {}
+ public void visit(DerivedColumn obj) {}
public void visit(Function obj) {}
public void visit(GroupSymbol obj) {}
public void visit(Reference obj) {}
@@ -126,4 +186,5 @@
public void visit(ProcedureContainer obj) {}
public void visit(SetClauseList obj) {}
public void visit(SetClause obj) {}
+ public void visit(OrderByItem obj) {}
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -22,15 +22,22 @@
package com.metamatrix.query.sql.lang;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.sql.LanguageObject;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.visitor.CommandCollectorVisitor;
import com.metamatrix.query.sql.visitor.SQLStringVisitor;
@@ -98,7 +105,7 @@
public static final int TYPE_DROP = 12;
- private static List updateCommandSymbol = null;
+ private static List<DerivedColumn> updateCommandSymbol = null;
private static List updatesCommandSymbol = null;
@@ -280,7 +287,7 @@
* single column.
* @return Ordered list of SingleElementSymbol
*/
- public abstract List<SingleElementSymbol> getProjectedSymbols();
+ public abstract List<DerivedColumn> getProjectedSymbols();
/**
* Whether the results are cachable.
@@ -288,11 +295,11 @@
*/
public abstract boolean areResultsCachable();
- public static List getUpdateCommandSymbol() {
+ public static List<DerivedColumn> getUpdateCommandSymbol() {
if (updateCommandSymbol == null ) {
ElementSymbol symbol = new ElementSymbol("Count"); //$NON-NLS-1$
symbol.setType(DataTypeManager.DefaultDataClasses.INTEGER);
- updateCommandSymbol = Arrays.asList(new ElementSymbol[] {symbol});
+ updateCommandSymbol = Arrays.asList(new DerivedColumn(symbol));
}
return updateCommandSymbol;
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/GroupBy.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/GroupBy.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/GroupBy.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -46,7 +46,7 @@
public class GroupBy implements LanguageObject {
/** The set of expressions for the data elements to be group. */
- private List symbols; // List<Expression>
+ private List<Expression> symbols; // List<Expression>
// =========================================================================
// C O N S T R U C T O R S
@@ -56,15 +56,15 @@
* Constructs a default instance of this class.
*/
public GroupBy() {
- symbols = new ArrayList();
+ symbols = new ArrayList<Expression>();
}
/**
* Constructs an instance of this class from an ordered set of symbols.
* @param symbols The ordered list of {@link com.metamatrix.query.sql.symbol.ElementSymbol}s
*/
- public GroupBy( List symbols ) {
- this.symbols = new ArrayList( symbols );
+ public GroupBy( List<? extends Expression> symbols ) {
+ this.symbols = new ArrayList<Expression>( symbols );
}
// =========================================================================
@@ -83,7 +83,7 @@
* Returns an ordered list of the symbols in the GROUP BY
* @return List of {@link com.metamatrix.query.sql.symbol.ElementSymbol}s
*/
- public List getSymbols() {
+ public List<Expression> getSymbols() {
return symbols;
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Insert.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Insert.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Insert.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -36,7 +36,7 @@
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.Symbol;
/**
* Represents a SQL Insert statement of the form:
@@ -226,7 +226,7 @@
for (int j = 0; j < iSize; j++) {
ElementSymbol symbol = (ElementSymbol)((ElementSymbol)variables.get( j )).clone();
- symbol.setName(ProcedureReservedWords.INPUT + SingleElementSymbol.SEPARATOR + symbol.getShortCanonicalName());
+ symbol.setName(ProcedureReservedWords.INPUT + Symbol.SEPARATOR + symbol.getShortCanonicalName());
map.put(symbol, values.get( j ) );
} // for
return map;
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderBy.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderBy.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderBy.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -23,18 +23,15 @@
package com.metamatrix.query.sql.lang;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
import com.metamatrix.core.util.EquivalenceUtil;
import com.metamatrix.core.util.HashCodeUtil;
-import com.metamatrix.query.QueryPlugin;
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.LanguageVisitor;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.lang.OrderByItem.OrderSpecification;
+import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.visitor.SQLStringVisitor;
-import com.metamatrix.query.util.ErrorMessageKeys;
/**
* Represents the ORDER BY clause of a query. The ORDER BY clause states
@@ -45,46 +42,26 @@
*/
public class OrderBy implements LanguageObject {
- /** Constant for the ascending value */
- public static final boolean ASC = Boolean.TRUE.booleanValue();
+ private List<OrderByItem> sortOrder;
- /** Constant for the descending value */
- public static final boolean DESC = Boolean.FALSE.booleanValue();
-
- private List sortOrder;
- private List orderTypes;
- private boolean inPlanForm = true;
-
/**
* Constructs a default instance of this class.
*/
public OrderBy() {
- sortOrder = new ArrayList();
- orderTypes = new ArrayList();
+ sortOrder = new ArrayList<OrderByItem>();
}
/**
* Constructs an instance of this class from an ordered set of elements.
* @param parameters The ordered list of SingleElementSymbol
*/
- public OrderBy( List parameters ) {
- sortOrder = new ArrayList( parameters );
- orderTypes = new ArrayList(parameters.size());
+ public OrderBy( List<Expression> parameters ) {
+ sortOrder = new ArrayList<OrderByItem>( );
for( int i=0; i< parameters.size(); i++) {
- orderTypes.add(Boolean.TRUE);
+ sortOrder.add(new OrderByItem(parameters.get(i), OrderSpecification.ASC));
}
}
- /**
- * Constructs an instance of this class from an ordered set of elements.
- * @param parameters The ordered list of SingleElementSymbol
- * @param types The list of directions by which the results are ordered (Boolean, true=ascending)
- */
- public OrderBy( List parameters, List types ) {
- sortOrder = new ArrayList( parameters );
- orderTypes = new ArrayList( types );
- }
-
// =========================================================================
// M E T H O D S
// =========================================================================
@@ -96,49 +73,26 @@
return sortOrder.size();
}
- /**
- * Returns an ordered list of the symbols in ORDER BY
- * @param List of SingleElementSymbol in ORDER BY
- */
- public List getVariables() {
- return sortOrder;
- }
+ public List<OrderByItem> getSortOrder() {
+ return sortOrder;
+ }
/**
- * Returns an ordered list of sort direction for each order.
- * @param List of Boolean, Boolean.TRUE represents ascending
+ * Adds a new variable to the list of order by elements.
+ * @param element Element to add
*/
- public List getTypes() {
- return orderTypes;
+ public void addVariable( Expression element ) {
+ addVariable(element, null);
}
-
+
/**
- * Returns the ORDER BY element at the specified index.
- * @param index Index to get
- * @return The element at the index
- */
- public SingleElementSymbol getVariable( int index ) {
- return (SingleElementSymbol)sortOrder.get(index);
- }
-
- /**
- * Returns the sort order at the specified index
- * @param index Index to get
- * @return The sort order at the index
- */
- public Boolean getOrderType( int index ) {
- return (Boolean)orderTypes.get(index);
- }
-
- /**
- * Adds a new variable to the list of order by elements.
+ * Adds a new variable to the list of order by elements with the
+ * specified sort order
* @param element Element to add
+ * @param type True for ascending, false for descending
*/
- public void addVariable( SingleElementSymbol element ) {
- if(element != null) {
- sortOrder.add(element);
- orderTypes.add(Boolean.valueOf(ASC));
- }
+ public void addVariable( Expression element, boolean type ) {
+ addVariable(element, type?OrderSpecification.ASC:OrderSpecification.DESC);
}
/**
@@ -147,30 +101,16 @@
* @param element Element to add
* @param type True for ascending, false for descending
*/
- public void addVariable( SingleElementSymbol element, boolean type ) {
+ public void addVariable( Expression element, OrderSpecification type ) {
if(element != null) {
- sortOrder.add(element);
- orderTypes.add(Boolean.valueOf(type));
+ sortOrder.add(new OrderByItem(element, type));
}
}
- /**
- * Sets a new collection of variables to be used. The replacement
- * set must be of the same size as the previous set.
- * @param elements Collection of SingleElementSymbol
- * @throws IllegalArgumentException if element is null or size of elements != size of existing elements
- */
- public void replaceVariables( Collection elements ) {
- if(elements == null) {
- throw new IllegalArgumentException(QueryPlugin.Util.getString(ErrorMessageKeys.SQL_0004));
- }
- if(elements.size() != sortOrder.size()) {
- throw new IllegalArgumentException(QueryPlugin.Util.getString(ErrorMessageKeys.SQL_0005));
- }
-
- sortOrder = new ArrayList(elements);
+ public void addItem(OrderByItem item) {
+ this.sortOrder.add(item);
}
-
+
public void acceptVisitor(LanguageVisitor visitor) {
visitor.visit(this);
}
@@ -183,15 +123,10 @@
* Return deep copy of this ORDER BY clause.
*/
public Object clone() {
- List thisSymbols = getVariables();
- List copySymbols = new ArrayList(thisSymbols.size());
- Iterator iter = thisSymbols.iterator();
- while(iter.hasNext()) {
- SingleElementSymbol ses = (SingleElementSymbol) iter.next();
- copySymbols.add(ses.clone());
- }
- OrderBy result = new OrderBy(copySymbols, getTypes());
- result.setInPlanForm(this.inPlanForm);
+ OrderBy result = new OrderBy();
+ for (OrderByItem item : sortOrder) {
+ result.addItem((OrderByItem)item.clone());
+ }
return result;
}
@@ -211,8 +146,7 @@
}
OrderBy other = (OrderBy) obj;
- return EquivalenceUtil.areEqual(getVariables(), other.getVariables()) &&
- EquivalenceUtil.areEqual(getTypes(), other.getTypes());
+ return EquivalenceUtil.areEqual(getSortOrder(), other.getSortOrder());
}
/**
@@ -223,10 +157,7 @@
* @return Hash code
*/
public int hashCode() {
- int hc = 0;
- hc = HashCodeUtil.hashCode(0, getVariables());
- hc = HashCodeUtil.hashCode(hc, getTypes());
- return hc;
+ return HashCodeUtil.hashCode(0, getSortOrder());
}
/**
@@ -237,12 +168,4 @@
return SQLStringVisitor.getSQLString(this);
}
- public boolean isInPlanForm() {
- return this.inPlanForm;
- }
-
- public void setInPlanForm(boolean inPlanForm) {
- this.inPlanForm = inPlanForm;
- }
-
}
Added: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java (rev 0)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -0,0 +1,74 @@
+package com.metamatrix.query.sql.lang;
+
+import com.metamatrix.query.sql.LanguageObject;
+import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.symbol.Expression;
+import com.metamatrix.query.sql.visitor.SQLStringVisitor;
+
+public class OrderByItem implements LanguageObject {
+
+ public enum OrderSpecification {
+ ASC,
+ DESC
+ }
+
+ private Expression sortKey;
+ private OrderSpecification orderingSpecification;
+
+ public OrderByItem(Expression sortKey, OrderSpecification orderingSpecification) {
+ this.orderingSpecification = orderingSpecification;
+ this.sortKey = sortKey;
+ }
+
+ public Expression getSortKey() {
+ return sortKey;
+ }
+
+ public void setSortKey(Expression sortKey) {
+ this.sortKey = sortKey;
+ }
+
+ public OrderSpecification getOrderingSpecification() {
+ if (orderingSpecification == null) {
+ return OrderSpecification.ASC;
+ }
+ return orderingSpecification;
+ }
+
+ public void setOrderingSpecification(
+ OrderSpecification orderingSpecification) {
+ this.orderingSpecification = orderingSpecification;
+ }
+
+ @Override
+ public void acceptVisitor(LanguageVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ public Object clone() {
+ return new OrderByItem((Expression)sortKey.clone(), orderingSpecification);
+ }
+
+ @Override
+ public int hashCode() {
+ return sortKey.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof OrderByItem)) {
+ return false;
+ }
+ OrderByItem other = (OrderByItem)obj;
+ return sortKey.equals(other.sortKey) && (this.getOrderingSpecification() == other.getOrderingSpecification());
+ }
+
+ @Override
+ public String toString() {
+ return SQLStringVisitor.getSQLString(this);
+ }
+}
Property changes on: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/OrderByItem.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Query.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -24,7 +24,6 @@
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import com.metamatrix.api.exception.MetaMatrixComponentException;
@@ -33,9 +32,8 @@
import com.metamatrix.core.util.HashCodeUtil;
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.SelectSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
/**
* A representation of a data query. A query consists of various parts,
* referred to as clauses. The following list the types of clauses
@@ -75,9 +73,6 @@
/** The into clause. */
private Into into;
- /** xml projected symbols */
- private List selectList;
-
// =========================================================================
// C O N S T R U C T O R S
// =========================================================================
@@ -292,7 +287,7 @@
* single column.
* @return Ordered list of SingleElementSymbol
*/
- public List getProjectedSymbols() {
+ public List<DerivedColumn> getProjectedSymbols() {
if (!getIsXML()) {
if(getSelect() != null) {
if(getInto() != null){
@@ -301,14 +296,12 @@
}
return getSelect().getProjectedSymbols();
}
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
- if(selectList == null){
- selectList = new ArrayList(1);
- ElementSymbol xmlElement = new ElementSymbol("xml"); //$NON-NLS-1$
- xmlElement.setType(DataTypeManager.DefaultDataClasses.XML);
- selectList.add(xmlElement);
- }
+ List<DerivedColumn> selectList = new ArrayList<DerivedColumn>(1);
+ ElementSymbol xmlElement = new ElementSymbol("xml"); //$NON-NLS-1$
+ xmlElement.setType(DataTypeManager.DefaultDataClasses.XML);
+ selectList.add(new DerivedColumn(xmlElement));
return selectList;
}
@@ -358,14 +351,6 @@
// Defect 13751: should clone isXML state.
copy.setIsXML(getIsXML());
- if(selectList != null){
- copy.selectList = new ArrayList();
- Iterator iter = selectList.iterator();
- while(iter.hasNext()) {
- copy.selectList.add(((SelectSymbol)iter.next()).clone());
- }
- }
-
copyMetadataState(copy);
return copy;
@@ -425,10 +410,8 @@
if(this.getInto() != null){
return false;
}
- List projectedSymbols = getProjectedSymbols();
- for(int i=0; i<projectedSymbols.size(); i++){
- SingleElementSymbol projectedSymbol = (SingleElementSymbol)projectedSymbols.get(i);
- if(DataTypeManager.isLOB(projectedSymbol.getType())) {
+ for (DerivedColumn column : getProjectedSymbols()) {
+ if(DataTypeManager.isLOB(column.getType())) {
return false;
}
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Select.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Select.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Select.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -22,12 +22,20 @@
package com.metamatrix.query.sql.lang;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
-import com.metamatrix.core.util.HashCodeUtil;
-import com.metamatrix.query.sql.symbol.*;
-import com.metamatrix.query.sql.*;
import com.metamatrix.core.util.EquivalenceUtil;
+import com.metamatrix.core.util.HashCodeUtil;
+import com.metamatrix.query.sql.LanguageObject;
+import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.symbol.AllSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
+import com.metamatrix.query.sql.symbol.ElementSymbol;
+import com.metamatrix.query.sql.symbol.MultipleElementSymbol;
+import com.metamatrix.query.sql.symbol.SelectSymbol;
import com.metamatrix.query.sql.visitor.SQLStringVisitor;
/**
@@ -37,7 +45,7 @@
public class Select implements LanguageObject {
/** The set of symbols for the data elements to be selected. */
- private List symbols; // List<SelectSymbols>
+ private List<SelectSymbol> symbols;
/** Flag for whether duplicate removal should be performed on the results */
private boolean distinct;
@@ -50,15 +58,15 @@
* Constructs a default instance of this class.
*/
public Select() {
- symbols = new ArrayList();
+ symbols = new ArrayList<SelectSymbol>();
}
/**
* Constructs an instance of this class from an ordered set of symbols.
* @param symbols The ordered list of symbols
*/
- public Select( List symbols ) {
- this.symbols = new ArrayList( symbols );
+ public Select( List<? extends SelectSymbol> symbols ) {
+ this.symbols = new ArrayList<SelectSymbol>( symbols );
}
// =========================================================================
@@ -84,7 +92,7 @@
* Returns an ordered list of the symbols in the select.
* @param Get list of SelectSymbol in SELECT
*/
- public List getSymbols() {
+ public List<SelectSymbol> getSymbols() {
return symbols;
}
@@ -92,7 +100,7 @@
* Sets an ordered list of the symbols in the select.
* @param symbols list of SelectSymbol in SELECT
*/
- public void setSymbols(List symbols) {
+ public void setSymbols(List<SelectSymbol> symbols) {
this.symbols = symbols;
}
@@ -102,7 +110,7 @@
* @return The variable identifier at the index
*/
public SelectSymbol getSymbol( int index ) {
- return (SelectSymbol) symbols.get(index);
+ return symbols.get(index);
}
/**
@@ -114,12 +122,18 @@
symbols.add(symbol);
}
}
+
+ public void addSymbol(ElementSymbol symbol) {
+ if (symbol != null) {
+ symbols.add(new DerivedColumn(symbol));
+ }
+ }
/**
* Adds a new collection of symbols to the list of symbols.
* @param symbols Collection of SelectSymbols
*/
- public void addSymbols( Collection symbols) {
+ public void addSymbols( Collection<SelectSymbol> symbols) {
if(symbols != null) {
this.symbols.addAll(symbols);
}
@@ -141,38 +155,6 @@
return symbols.contains(symbol);
}
- /**
- * Check is the element symbol is being selected by this
- * select clause. This includes checking for select start
- * and select group.star for the group of this element symbol.
- * ElementSymbol is assumed to be fully resolved.
- * @param elementSymbol fully resolved ElementSymbol
- * @return whether this select will select the element symbol
- */
- public boolean isElementBeingSelected(ElementSymbol elementSymbol){
- boolean isBeingSelected = this.containsSymbol(elementSymbol);
- if (!isBeingSelected){
- GroupSymbol g = elementSymbol.getGroupSymbol();
- String groupDotStarName = g.getName() + ".*"; //$NON-NLS-1$
- Iterator i = this.getSymbols().iterator();
- while (i.hasNext()) {
- Object selectSymbol = i.next();
- if (selectSymbol instanceof AllSymbol){
- isBeingSelected = true;
- break;
- } else if (selectSymbol instanceof AllInGroupSymbol){
- AllInGroupSymbol aigSymbol = (AllInGroupSymbol)selectSymbol;
- if (aigSymbol.getName().equalsIgnoreCase(groupDotStarName)){
- isBeingSelected = true;
- break;
- }
- }
- }
- }
- return isBeingSelected;
- }
-
-
/**
* Set whether select is distinct.
* @param isDistinct True if SELECT is distinct
@@ -199,17 +181,17 @@
* single column.
* @return Ordered list of SingleElementSymbol
*/
- public List getProjectedSymbols() {
- ArrayList projectedSymbols = new ArrayList();
- Iterator iter = symbols.iterator();
- while(iter.hasNext()) {
- SelectSymbol symbol = (SelectSymbol) iter.next();
- if(symbol instanceof SingleElementSymbol) {
- projectedSymbols.add(symbol);
+ public List<DerivedColumn> getProjectedSymbols() {
+ ArrayList<DerivedColumn> projectedSymbols = new ArrayList<DerivedColumn>();
+ for (SelectSymbol symbol : symbols) {
+ if(symbol instanceof DerivedColumn) {
+ projectedSymbols.add((DerivedColumn)symbol);
} else {
- List multiSymbols = ((MultipleElementSymbol)symbol).getElementSymbols();
+ List<ElementSymbol> multiSymbols = ((MultipleElementSymbol)symbol).getElementSymbols();
if(multiSymbols != null) {
- projectedSymbols.addAll(multiSymbols);
+ for (ElementSymbol elementSymbol : multiSymbols) {
+ projectedSymbols.add(new DerivedColumn(elementSymbol));
+ }
}
}
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/SetQuery.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -36,10 +36,8 @@
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.resolver.util.ResolverUtil;
import com.metamatrix.query.sql.LanguageVisitor;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
/**
* This object acts as a Set operator on multiple Queries - UNION,
@@ -119,40 +117,28 @@
* single column.
* @return Ordered list of SingleElementSymbol
*/
- public List getProjectedSymbols() {
+ public List<DerivedColumn> getProjectedSymbols() {
Query query = getProjectedQuery();
- List projectedSymbols = query.getProjectedSymbols();
+ List<DerivedColumn> projectedSymbols = query.getProjectedSymbols();
if (projectedTypes != null) {
return getTypedProjectedSymbols(projectedSymbols, projectedTypes);
}
return projectedSymbols;
}
- public static List getTypedProjectedSymbols(List acutal, List projectedTypes) {
- List newProject = new ArrayList();
+ public static List<DerivedColumn> getTypedProjectedSymbols(List<DerivedColumn> acutal, List projectedTypes) {
+ List<DerivedColumn> newProject = new ArrayList<DerivedColumn>();
for (int i = 0; i < acutal.size(); i++) {
- SingleElementSymbol originalSymbol = (SingleElementSymbol)acutal.get(i);
- SingleElementSymbol symbol = originalSymbol;
+ DerivedColumn symbol = acutal.get(i);
Class type = (Class)projectedTypes.get(i);
if (symbol.getType() != type) {
- if (symbol instanceof AliasSymbol) {
- symbol = ((AliasSymbol)symbol).getSymbol();
- }
-
- Expression expr = symbol;
- if (symbol instanceof ExpressionSymbol) {
- expr = ((ExpressionSymbol)symbol).getExpression();
- }
+ Expression expr = symbol.getExpression();
try {
- symbol = new ExpressionSymbol(originalSymbol.getShortName(), ResolverUtil.convertExpression(expr, DataTypeManager.getDataTypeName(type)));
+ symbol = new DerivedColumn(symbol.getShortName(), ResolverUtil.convertExpression(expr, DataTypeManager.getDataTypeName(type)), true);
} catch (QueryResolverException err) {
throw new MetaMatrixRuntimeException(err);
}
-
- if (!(originalSymbol instanceof ExpressionSymbol)) {
- symbol = new AliasSymbol(originalSymbol.getShortName(), symbol);
- }
}
newProject.add(symbol);
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Update.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Update.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/lang/Update.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -34,7 +34,7 @@
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.Symbol;
import com.metamatrix.query.sql.visitor.SQLStringVisitor;
/**
@@ -266,7 +266,7 @@
for (Iterator iter = getChangeList().getClauses().iterator(); iter.hasNext();) {
SetClause setClause = (SetClause)iter.next();
ElementSymbol symbol = (ElementSymbol)(setClause.getSymbol()).clone();
- symbol.setName(ProcedureReservedWords.INPUT + SingleElementSymbol.SEPARATOR + symbol.getShortCanonicalName());
+ symbol.setName(ProcedureReservedWords.INPUT + Symbol.SEPARATOR + symbol.getShortCanonicalName());
map.put( symbol, setClause.getValue() );
} // for
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/navigator/PreOrPostOrderNavigator.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/navigator/PreOrPostOrderNavigator.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/navigator/PreOrPostOrderNavigator.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -50,6 +50,7 @@
import com.metamatrix.query.sql.lang.NotCriteria;
import com.metamatrix.query.sql.lang.Option;
import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.SPParameter;
import com.metamatrix.query.sql.lang.Select;
@@ -78,15 +79,14 @@
import com.metamatrix.query.sql.proc.RaiseErrorStatement;
import com.metamatrix.query.sql.proc.TranslateCriteria;
import com.metamatrix.query.sql.proc.WhileStatement;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.AllInGroupSymbol;
import com.metamatrix.query.sql.symbol.AllSymbol;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
@@ -122,16 +122,11 @@
}
- public void visit(AggregateSymbol obj) {
+ public void visit(Aggregate obj) {
preVisitVisitor(obj);
visitNode(obj.getExpression());
postVisitVisitor(obj);
}
- public void visit(AliasSymbol obj) {
- preVisitVisitor(obj);
- visitNode(obj.getSymbol());
- postVisitVisitor(obj);
- }
public void visit(AllInGroupSymbol obj) {
preVisitVisitor(obj);
postVisitVisitor(obj);
@@ -237,7 +232,7 @@
preVisitVisitor(obj);
postVisitVisitor(obj);
}
- public void visit(ExpressionSymbol obj) {
+ public void visit(DerivedColumn obj) {
preVisitVisitor(obj);
visitNode(obj.getExpression());
postVisitVisitor(obj);
@@ -360,9 +355,15 @@
}
public void visit(OrderBy obj) {
preVisitVisitor(obj);
- visitNodes(obj.getVariables());
+ visitNodes(obj.getSortOrder());
postVisitVisitor(obj);
}
+ @Override
+ public void visit(OrderByItem obj) {
+ preVisitVisitor(obj);
+ visitNode(obj.getSortKey());
+ postVisitVisitor(obj);
+ }
public void visit(Query obj) {
preVisitVisitor(obj);
visitNode(obj.getSelect());
Copied: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Aggregate.java (from rev 529, branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/AggregateSymbol.java)
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Aggregate.java (rev 0)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Aggregate.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -0,0 +1,217 @@
+/*
+ * 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 com.metamatrix.query.sql.symbol;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.core.util.EquivalenceUtil;
+import com.metamatrix.core.util.HashCodeUtil;
+import com.metamatrix.query.QueryPlugin;
+import com.metamatrix.query.sql.LanguageVisitor;
+import com.metamatrix.query.sql.ReservedWords;
+import com.metamatrix.query.util.ErrorMessageKeys;
+
+/**
+ * <p>An aggregate represents an aggregate function in the SELECT or HAVING clauses,
+ * typically something like <code>SUM(stock.quantity * 2)</code>. There are five supported
+ * aggregate functions: COUNT, SUM, AVG, MIN, and MAX. Aggregate functions may also
+ * specify a DISTINCT flag to indicate that duplicates should be ignored. The DISTINCT flag
+ * may be set for all five aggregate functions but is ignored for the computation of MIN and MAX.
+ * One special use of an aggregate is for <code>COUNT(*)</code>. The * expression
+ * is encoded by setting the expression to null. This may ONLY be used with the COUNT function.</p>
+ *
+ * <p>The type of an aggregate depends on the function and the type of the underlying
+ * expression. The type of a COUNT function is ALWAYS integer. MIN and MAX functions take the
+ * type of their contained expression. AVG and SUM vary depending on the type of the expression.
+ * If the expression is of a type other than biginteger, the aggregate function returns type long.
+ * For the case of biginteger, the aggregate function returns type biginteger. Similarly, all
+ * floating point expressions not of type bigdecimal return type double and bigdecimal maps to
+ * bigdecimal.</p>
+ */
+public class Aggregate implements Expression {
+
+ private Expression expression;
+ private String aggregate;
+ private boolean distinct;
+
+ private static final Class COUNT_TYPE = DataTypeManager.getDataTypeClass(DataTypeManager.DefaultDataTypes.INTEGER);
+ private static final Set AGGREGATE_FUNCTIONS;
+ private static final Map SUM_TYPES;
+ private static final Map AVG_TYPES;
+
+ static {
+ AGGREGATE_FUNCTIONS = new HashSet();
+ AGGREGATE_FUNCTIONS.add(ReservedWords.COUNT);
+ AGGREGATE_FUNCTIONS.add(ReservedWords.SUM);
+ AGGREGATE_FUNCTIONS.add(ReservedWords.AVG);
+ AGGREGATE_FUNCTIONS.add(ReservedWords.MIN);
+ AGGREGATE_FUNCTIONS.add(ReservedWords.MAX);
+
+ SUM_TYPES = new HashMap();
+ SUM_TYPES.put(DataTypeManager.DefaultDataClasses.BYTE, DataTypeManager.DefaultDataClasses.LONG);
+ SUM_TYPES.put(DataTypeManager.DefaultDataClasses.SHORT, DataTypeManager.DefaultDataClasses.LONG);
+ SUM_TYPES.put(DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.LONG);
+ SUM_TYPES.put(DataTypeManager.DefaultDataClasses.LONG, DataTypeManager.DefaultDataClasses.LONG);
+ SUM_TYPES.put(DataTypeManager.DefaultDataClasses.BIG_INTEGER, DataTypeManager.DefaultDataClasses.BIG_INTEGER);
+ SUM_TYPES.put(DataTypeManager.DefaultDataClasses.FLOAT, DataTypeManager.DefaultDataClasses.DOUBLE);
+ SUM_TYPES.put(DataTypeManager.DefaultDataClasses.DOUBLE, DataTypeManager.DefaultDataClasses.DOUBLE);
+ SUM_TYPES.put(DataTypeManager.DefaultDataClasses.BIG_DECIMAL, DataTypeManager.DefaultDataClasses.BIG_DECIMAL);
+
+ AVG_TYPES = new HashMap();
+ AVG_TYPES.put(DataTypeManager.DefaultDataClasses.BYTE, DataTypeManager.DefaultDataClasses.DOUBLE);
+ AVG_TYPES.put(DataTypeManager.DefaultDataClasses.SHORT, DataTypeManager.DefaultDataClasses.DOUBLE);
+ AVG_TYPES.put(DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.DOUBLE);
+ AVG_TYPES.put(DataTypeManager.DefaultDataClasses.LONG, DataTypeManager.DefaultDataClasses.DOUBLE);
+ AVG_TYPES.put(DataTypeManager.DefaultDataClasses.BIG_INTEGER, DataTypeManager.DefaultDataClasses.BIG_DECIMAL);
+ AVG_TYPES.put(DataTypeManager.DefaultDataClasses.FLOAT, DataTypeManager.DefaultDataClasses.DOUBLE);
+ AVG_TYPES.put(DataTypeManager.DefaultDataClasses.DOUBLE, DataTypeManager.DefaultDataClasses.DOUBLE);
+ AVG_TYPES.put(DataTypeManager.DefaultDataClasses.BIG_DECIMAL, DataTypeManager.DefaultDataClasses.BIG_DECIMAL);
+ }
+
+ /**
+ * Construct an aggregate with all given data.
+ * @param aggregateFunction Aggregate function type ({@link com.metamatrix.query.sql.ReservedWords#COUNT}, etc)
+ * @param isDistinct True if DISTINCT flag is set
+ * @param expression Contained expression
+ */
+ public Aggregate(String aggregateFunction, boolean isDistinct, Expression expression) {
+ this.expression = expression;
+ setAggregateFunction(aggregateFunction);
+ this.distinct = isDistinct;
+ }
+
+ /**
+ * Set the aggregate function. If the aggregate function is an invalid value, an
+ * IllegalArgumentException is thrown.
+ * @param aggregateFunction Aggregate function type
+ * @see com.metamatrix.query.sql.ReservedWords#COUNT
+ * @see com.metamatrix.query.sql.ReservedWords#SUM
+ * @see com.metamatrix.query.sql.ReservedWords#AVG
+ * @see com.metamatrix.query.sql.ReservedWords#MIN
+ * @see com.metamatrix.query.sql.ReservedWords#MAX
+ */
+ private void setAggregateFunction(String aggregateFunction) {
+ // Validate aggregate
+ if(! AGGREGATE_FUNCTIONS.contains(aggregateFunction)) {
+ throw new IllegalArgumentException(QueryPlugin.Util.getString(ErrorMessageKeys.SQL_0013, new Object[] {aggregateFunction, AGGREGATE_FUNCTIONS}));
+ }
+ this.aggregate = aggregateFunction;
+ }
+
+ /**
+ * Get the aggregate function type - this will map to one of the reserved words
+ * for the aggregate functions.
+ * @return Aggregate function type
+ * @see com.metamatrix.query.sql.ReservedWords#COUNT
+ * @see com.metamatrix.query.sql.ReservedWords#SUM
+ * @see com.metamatrix.query.sql.ReservedWords#AVG
+ * @see com.metamatrix.query.sql.ReservedWords#MIN
+ * @see com.metamatrix.query.sql.ReservedWords#MAX
+ */
+ public String getAggregateFunction() {
+ return this.aggregate;
+ }
+
+ /**
+ * Get the distinct flag. If true, aggregate will remove duplicates during
+ * computation.
+ * @return True if duplicates should be removed during computation
+ */
+ public boolean isDistinct() {
+ return this.distinct;
+ }
+
+ /**
+ * Get the type of the aggregate, which depends on the aggregate function and the
+ * type of the contained expression
+ */
+ public Class getType() {
+ if(this.aggregate.equals(ReservedWords.COUNT)) {
+ return COUNT_TYPE;
+ } else if(this.aggregate.equals(ReservedWords.SUM) ) {
+ Class expressionType = this.getExpression().getType();
+ return (Class) SUM_TYPES.get(expressionType);
+ } else if (this.aggregate.equals(ReservedWords.AVG)) {
+ Class expressionType = this.getExpression().getType();
+ return (Class) AVG_TYPES.get(expressionType);
+ } else {
+ return this.getExpression().getType();
+ }
+ }
+
+ public void acceptVisitor(LanguageVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ /**
+ * Return a deep copy of this object
+ */
+ public Object clone() {
+ Aggregate copy = null;
+ if(getExpression() != null) {
+ copy = new Aggregate(getAggregateFunction(), isDistinct(), (Expression) getExpression().clone());
+ } else {
+ copy = new Aggregate(getAggregateFunction(), isDistinct(), null);
+ }
+
+ return copy;
+ }
+
+ public Expression getExpression() {
+ return expression;
+ }
+
+ public void setExpression(Expression expression) {
+ this.expression = expression;
+ }
+
+ @Override
+ public boolean isResolved() {
+ if (this.expression != null) {
+ return this.expression.isResolved();
+ }
+ return true;
+ }
+
+ public int hashCode() {
+ int hasCode = HashCodeUtil.hashCode(aggregate.hashCode(), distinct);
+ return HashCodeUtil.hashCode(hasCode, this.getExpression());
+ }
+
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Aggregate)) {
+ return false;
+ }
+
+ Aggregate other = (Aggregate)obj;
+
+ return this.aggregate.equals(other.aggregate)
+ && this.distinct == other.distinct
+ && EquivalenceUtil.areEqual(this.getExpression(), other.getExpression());
+ }
+
+}
Property changes on: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Aggregate.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/AggregateSymbol.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/AggregateSymbol.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/AggregateSymbol.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -1,224 +0,0 @@
-/*
- * 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 com.metamatrix.query.sql.symbol;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.core.util.EquivalenceUtil;
-import com.metamatrix.core.util.HashCodeUtil;
-import com.metamatrix.query.QueryPlugin;
-import com.metamatrix.query.sql.LanguageVisitor;
-import com.metamatrix.query.sql.ReservedWords;
-import com.metamatrix.query.util.ErrorMessageKeys;
-
-/**
- * <p>An aggregate symbol represents an aggregate function in the SELECT or HAVING clauses. It
- * extends ExpressionSymbol as they have many things in common. The aggregate symbol is
- * typically something like <code>SUM(stock.quantity * 2)</code>. There are five supported
- * aggregate functions: COUNT, SUM, AVG, MIN, and MAX. Aggregate functions contain an expression -
- * this data is managed by the super class, ExpressionSymbol. Aggregate functions may also
- * specify a DISTINCT flag to indicate that duplicates should be ignored. The DISTINCT flag
- * may be set for all five aggregate functions but is ignored for the computation of MIN and MAX.
- * One special use of an aggregate symbol is for the symbol <code>COUNT(*)</code>. The * expression
- * is encoded by setting the expression to null. This may ONLY be used with the COUNT function.</p>
- *
- * <p>The type of an aggregate symbol depends on the function and the type of the underlying
- * expression. The type of a COUNT function is ALWAYS integer. MIN and MAX functions take the
- * type of their contained expression. AVG and SUM vary depending on the type of the expression.
- * If the expression is of a type other than biginteger, the aggregate function returns type long.
- * For the case of biginteger, the aggregate function returns type biginteger. Similarly, all
- * floating point expressions not of type bigdecimal return type double and bigdecimal maps to
- * bigdecimal.</p>
- */
-public class AggregateSymbol extends ExpressionSymbol {
-
- private String aggregate;
- private boolean distinct;
-
- private static final Class COUNT_TYPE = DataTypeManager.getDataTypeClass(DataTypeManager.DefaultDataTypes.INTEGER);
- private static final Set AGGREGATE_FUNCTIONS;
- private static final Map SUM_TYPES;
- private static final Map AVG_TYPES;
-
- static {
- AGGREGATE_FUNCTIONS = new HashSet();
- AGGREGATE_FUNCTIONS.add(ReservedWords.COUNT);
- AGGREGATE_FUNCTIONS.add(ReservedWords.SUM);
- AGGREGATE_FUNCTIONS.add(ReservedWords.AVG);
- AGGREGATE_FUNCTIONS.add(ReservedWords.MIN);
- AGGREGATE_FUNCTIONS.add(ReservedWords.MAX);
-
- SUM_TYPES = new HashMap();
- SUM_TYPES.put(DataTypeManager.DefaultDataClasses.BYTE, DataTypeManager.DefaultDataClasses.LONG);
- SUM_TYPES.put(DataTypeManager.DefaultDataClasses.SHORT, DataTypeManager.DefaultDataClasses.LONG);
- SUM_TYPES.put(DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.LONG);
- SUM_TYPES.put(DataTypeManager.DefaultDataClasses.LONG, DataTypeManager.DefaultDataClasses.LONG);
- SUM_TYPES.put(DataTypeManager.DefaultDataClasses.BIG_INTEGER, DataTypeManager.DefaultDataClasses.BIG_INTEGER);
- SUM_TYPES.put(DataTypeManager.DefaultDataClasses.FLOAT, DataTypeManager.DefaultDataClasses.DOUBLE);
- SUM_TYPES.put(DataTypeManager.DefaultDataClasses.DOUBLE, DataTypeManager.DefaultDataClasses.DOUBLE);
- SUM_TYPES.put(DataTypeManager.DefaultDataClasses.BIG_DECIMAL, DataTypeManager.DefaultDataClasses.BIG_DECIMAL);
-
- AVG_TYPES = new HashMap();
- AVG_TYPES.put(DataTypeManager.DefaultDataClasses.BYTE, DataTypeManager.DefaultDataClasses.DOUBLE);
- AVG_TYPES.put(DataTypeManager.DefaultDataClasses.SHORT, DataTypeManager.DefaultDataClasses.DOUBLE);
- AVG_TYPES.put(DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.DOUBLE);
- AVG_TYPES.put(DataTypeManager.DefaultDataClasses.LONG, DataTypeManager.DefaultDataClasses.DOUBLE);
- AVG_TYPES.put(DataTypeManager.DefaultDataClasses.BIG_INTEGER, DataTypeManager.DefaultDataClasses.BIG_DECIMAL);
- AVG_TYPES.put(DataTypeManager.DefaultDataClasses.FLOAT, DataTypeManager.DefaultDataClasses.DOUBLE);
- AVG_TYPES.put(DataTypeManager.DefaultDataClasses.DOUBLE, DataTypeManager.DefaultDataClasses.DOUBLE);
- AVG_TYPES.put(DataTypeManager.DefaultDataClasses.BIG_DECIMAL, DataTypeManager.DefaultDataClasses.BIG_DECIMAL);
- }
-
- /**
- * Constructor used for cloning
- * @param name
- * @param canonicalName
- * @since 4.3
- */
- protected AggregateSymbol(String name, String canonicalName, String aggregateFunction, boolean isDistinct, Expression expression) {
- super(name, canonicalName, expression);
-
- setAggregateFunction(aggregateFunction);
- this.distinct = isDistinct;
- }
-
- /**
- * Construct an aggregate symbol with all given data.
- * @param name Name of the function
- * @param aggregateFunction Aggregate function type ({@link com.metamatrix.query.sql.ReservedWords#COUNT}, etc)
- * @param isDistinct True if DISTINCT flag is set
- * @param expression Contained expression
- */
- public AggregateSymbol(String name, String aggregateFunction, boolean isDistinct, Expression expression) {
- super(name, expression);
-
- setAggregateFunction(aggregateFunction);
- this.distinct = isDistinct;
- }
-
- /**
- * Set the aggregate function. If the aggregate function is an invalid value, an
- * IllegalArgumentException is thrown.
- * @param aggregateFunction Aggregate function type
- * @see com.metamatrix.query.sql.ReservedWords#COUNT
- * @see com.metamatrix.query.sql.ReservedWords#SUM
- * @see com.metamatrix.query.sql.ReservedWords#AVG
- * @see com.metamatrix.query.sql.ReservedWords#MIN
- * @see com.metamatrix.query.sql.ReservedWords#MAX
- */
- private void setAggregateFunction(String aggregateFunction) {
- // Validate aggregate
- if(! AGGREGATE_FUNCTIONS.contains(aggregateFunction)) {
- throw new IllegalArgumentException(QueryPlugin.Util.getString(ErrorMessageKeys.SQL_0013, new Object[] {aggregateFunction, AGGREGATE_FUNCTIONS}));
- }
- this.aggregate = aggregateFunction;
- }
-
- /**
- * Get the aggregate function type - this will map to one of the reserved words
- * for the aggregate functions.
- * @return Aggregate function type
- * @see com.metamatrix.query.sql.ReservedWords#COUNT
- * @see com.metamatrix.query.sql.ReservedWords#SUM
- * @see com.metamatrix.query.sql.ReservedWords#AVG
- * @see com.metamatrix.query.sql.ReservedWords#MIN
- * @see com.metamatrix.query.sql.ReservedWords#MAX
- */
- public String getAggregateFunction() {
- return this.aggregate;
- }
-
- /**
- * Get the distinct flag. If true, aggregate symbol will remove duplicates during
- * computation.
- * @return True if duplicates should be removed during computation
- */
- public boolean isDistinct() {
- return this.distinct;
- }
-
- /**
- * Get the type of the symbol, which depends on the aggregate function and the
- * type of the contained expression
- * @return Type of the symbol
- */
- public Class getType() {
- if(this.aggregate.equals(ReservedWords.COUNT)) {
- return COUNT_TYPE;
- } else if(this.aggregate.equals(ReservedWords.SUM) ) {
- Class expressionType = this.getExpression().getType();
- return (Class) SUM_TYPES.get(expressionType);
- } else if (this.aggregate.equals(ReservedWords.AVG)) {
- Class expressionType = this.getExpression().getType();
- return (Class) AVG_TYPES.get(expressionType);
- } else {
- return this.getExpression().getType();
- }
- }
-
- public void acceptVisitor(LanguageVisitor visitor) {
- visitor.visit(this);
- }
-
- /**
- * Return a deep copy of this object
- */
- public Object clone() {
- AggregateSymbol copy = null;
- if(getExpression() != null) {
- copy = new AggregateSymbol(getName(), getCanonical(), getAggregateFunction(), isDistinct(), (Expression) getExpression().clone());
- } else {
- copy = new AggregateSymbol(getName(), getCanonical(), getAggregateFunction(), isDistinct(), null);
- }
-
- return copy;
- }
-
- /**
- * @see com.metamatrix.query.sql.symbol.ExpressionSymbol#hashCode()
- */
- public int hashCode() {
- int hasCode = HashCodeUtil.hashCode(aggregate.hashCode(), distinct);
- return HashCodeUtil.hashCode(hasCode, this.getExpression());
- }
-
- /**
- * @see com.metamatrix.query.sql.symbol.ExpressionSymbol#equals(java.lang.Object)
- */
- public boolean equals(Object obj) {
- if (!(obj instanceof AggregateSymbol)) {
- return false;
- }
-
- AggregateSymbol other = (AggregateSymbol)obj;
-
- return this.aggregate.equals(other.aggregate)
- && this.distinct == other.distinct
- && EquivalenceUtil.areEqual(this.getExpression(), other.getExpression());
- }
-
-}
Deleted: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/AliasSymbol.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/AliasSymbol.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/AliasSymbol.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -1,131 +0,0 @@
-/*
- * 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 com.metamatrix.query.sql.symbol;
-
-import com.metamatrix.core.util.Assertion;
-import com.metamatrix.query.QueryPlugin;
-import com.metamatrix.query.sql.LanguageVisitor;
-import com.metamatrix.query.util.ErrorMessageKeys;
-
-/**
- * An AliasSymbol wraps a SingleElementSymbol and changes it's name. AliasSymbols
- * should be used to perform the aliasing of elements in a SELECT clause. They
- * should typically NOT be used elsewhere in a query. The alias symbol takes on
- * the type of it's underlying SingleElementSymbol. AliasSymbols are typically
- * applied to ElementSymbol, ExpressionSymbol, and AggregateSymbol.
- */
-public class AliasSymbol extends SingleElementSymbol {
-
- private SingleElementSymbol symbol;
-
- /**
- * Constructor used for cloning
- * @param name
- * @param canonicalName
- * @since 4.3
- */
- private AliasSymbol(String name, String canonicalName, SingleElementSymbol symbol) {
- super(name, canonicalName);
- setSymbol(symbol);
- }
-
- /**
- * Construct an AliasSymbol given the alias name and the underlying symbol.
- * @param name Name of the alias
- * @param symbol Underlying symbol
- */
- public AliasSymbol(String name, SingleElementSymbol symbol) {
- super(name);
- setSymbol(symbol);
- }
-
- /**
- * Get the underlying symbol
- * @return Underlying symbol
- */
- public SingleElementSymbol getSymbol() {
- return this.symbol;
- }
-
- /**
- * Set the underlying symbol
- * @param symbol New symbol
- */
- public void setSymbol(SingleElementSymbol symbol) {
- if(symbol instanceof AliasSymbol || symbol == null){
- Assertion.failed(QueryPlugin.Util.getString(ErrorMessageKeys.SQL_0029));
- }
- this.symbol = symbol;
- }
-
- /**
- * Get the type of the symbol
- * @return Type of the symbol
- */
- public Class getType() {
- return this.symbol.getType();
- }
-
- /**
- * Returns true if this symbol has been completely resolved with respect
- * to actual runtime metadata. A resolved symbol has been validated that
- * it refers to actual metadata and will have references to the real metadata
- * IDs if necessary. Different types of symbols determine their resolution
- * in different ways, so this method is abstract and must be implemented
- * by subclasses.
- * @return True if resolved with runtime metadata
- */
- public boolean isResolved() {
- return this.symbol.isResolved();
- }
-
- public void acceptVisitor(LanguageVisitor visitor) {
- visitor.visit(this);
- }
-
- /**
- * Return a copy of this object.
- */
- public Object clone() {
- SingleElementSymbol symbolCopy = (SingleElementSymbol) this.symbol.clone();
- AliasSymbol result = new AliasSymbol(getName(), getCanonical(), symbolCopy);
- result.setOutputName(this.getOutputName());
- return result;
- }
-
- /**
- * @see com.metamatrix.query.sql.symbol.Symbol#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof AliasSymbol)) {
- return false;
- }
- AliasSymbol other = (AliasSymbol)obj;
- return this.getCanonicalName().equals(other.getCanonicalName()) && this.symbol.equals(other.symbol);
- }
-
-}
Copied: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/DerivedColumn.java (from rev 529, branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/ExpressionSymbol.java)
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/DerivedColumn.java (rev 0)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/DerivedColumn.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -0,0 +1,155 @@
+/*
+ * 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 com.metamatrix.query.sql.symbol;
+
+import com.metamatrix.query.sql.LanguageVisitor;
+
+/**
+ * <p>This is a subclass of Symbol representing an expression in the SELECT clause. The
+ * expression may be a constant, function, or scalar subquery.</p>
+ */
+public class DerivedColumn extends SelectSymbol {
+ private Expression expression;
+ private boolean alias;
+
+ /**
+ * Constructor used for cloning
+ * @param name
+ * @param canonicalName
+ * @since 4.3
+ */
+ protected DerivedColumn(String name, String canonicalName, Expression expression) {
+ super(name, canonicalName);
+ this.expression = expression;
+ }
+
+ public DerivedColumn(ElementSymbol symbol) {
+ this(symbol.getName(), symbol.getCanonical(), symbol);
+ }
+
+ /**
+ * Construct an ExpressionSymbol with name and expression.
+ */
+ public DerivedColumn(String name, Expression expression) {
+ this(name, expression, false);
+ }
+
+ public DerivedColumn(String name, Expression expression, boolean alias) {
+ super(name);
+ this.expression = expression;
+ this.alias = alias;
+ }
+
+
+ /**
+ * Get the expression for this symbol
+ * @return Expression for this symbol
+ */
+ public Expression getExpression() {
+ return this.expression;
+ }
+
+ /**
+ * Set the expression represented by this symbol.
+ * @param expression Expression for this expression symbol
+ */
+ public void setExpression(Expression expression) {
+ this.expression = expression;
+ }
+
+ /**
+ * Get the type of the symbol
+ * @return Type of the symbol, may be null before resolution
+ */
+ public Class getType() {
+ return this.expression.getType();
+ }
+
+ public void acceptVisitor(LanguageVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ /**
+ * If elementSymbols is not null return true, else return false
+ * @return boolean True if expression symbol has been resolved to element symbols
+ */
+ public boolean isResolved() {
+ return true;
+ }
+
+ /**
+ * Return a deep copy of this object
+ * @return Deep copy of this object
+ */
+ public Object clone() {
+ Expression clonedExpr = null;
+ if(getExpression() != null) {
+ clonedExpr = (Expression) getExpression().clone();
+ }
+ DerivedColumn copy = new DerivedColumn(getName(), getCanonical(), clonedExpr);
+ copy.setAlias(this.alias);
+ return copy;
+ }
+
+ public boolean isAlias() {
+ return alias;
+ }
+
+ public void setAlias(boolean alias) {
+ this.alias = alias;
+ }
+
+ /**
+ * @see com.metamatrix.query.sql.symbol.Symbol#hashCode()
+ */
+ public int hashCode() {
+ if (expression != null) {
+ return expression.hashCode();
+ }
+ return super.hashCode();
+ }
+
+ /**
+ * ExpressionSymbol matching is not based upon the name
+ *
+ * @see com.metamatrix.query.sql.symbol.Symbol#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (!(obj instanceof DerivedColumn)) {
+ return false;
+ }
+
+ DerivedColumn exprSymbol = (DerivedColumn)obj;
+
+ if (expression == null ) {
+ return exprSymbol.getExpression() == null;
+ }
+
+ return expression.equals(exprSymbol.getExpression());
+ }
+
+}
Property changes on: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/DerivedColumn.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/ElementSymbol.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/ElementSymbol.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/ElementSymbol.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -35,7 +35,7 @@
* is set to false. Common uses when this is set to true are for variables used
* within a command, correlated elements within a command, etc. </p>
*/
-public class ElementSymbol extends SingleElementSymbol {
+public class ElementSymbol extends Symbol implements Expression {
public enum DisplayMode {
FULLY_QUALIFIED, // symbol name
Deleted: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/ExpressionSymbol.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/ExpressionSymbol.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/ExpressionSymbol.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -1,150 +0,0 @@
-/*
- * 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 com.metamatrix.query.sql.symbol;
-
-import com.metamatrix.query.sql.*;
-
-/**
- * <p>This is a subclass of Symbol representing an expression in the SELECT clause. The
- * expression may be a constant, function, or scalar subquery. The name of this symbol is always generated
- * and typically should not be displayed. If necessary, the ExpressionSymbol may be
- * wrapped by an AliasSymbol to register the name in a query. The definition of the
- * symbol is the functional expression. Resolution will produce a list of groups and
- * elements used by the expression.</p>
- */
-public class ExpressionSymbol extends SingleElementSymbol {
- private Expression expression;
- private boolean derivedExpression;
-
- /**
- * Constructor used for cloning
- * @param name
- * @param canonicalName
- * @since 4.3
- */
- protected ExpressionSymbol(String name, String canonicalName, Expression expression) {
- super(name, canonicalName);
- this.expression = expression;
- }
-
- /**
- * Construct an ExpressionSymbol with name and expression.
- */
- public ExpressionSymbol(String name, Expression expression) {
- super(name);
- this.expression = expression;
- }
-
- /**
- * Get the expression for this symbol
- * @return Expression for this symbol
- */
- public Expression getExpression() {
- return this.expression;
- }
-
- /**
- * Set the expression represented by this symbol.
- * @param expression Expression for this expression symbol
- */
- public void setExpression(Expression expression) {
- this.expression = expression;
- }
-
- /**
- * Get the type of the symbol
- * @return Type of the symbol, may be null before resolution
- */
- public Class getType() {
- return this.expression.getType();
- }
-
- public void acceptVisitor(LanguageVisitor visitor) {
- visitor.visit(this);
- }
-
- /**
- * If elementSymbols is not null return true, else return false
- * @return boolean True if expression symbol has been resolved to element symbols
- */
- public boolean isResolved() {
- return true;
- }
-
- /**
- * Return a deep copy of this object
- * @return Deep copy of this object
- */
- public Object clone() {
- Expression clonedExpr = null;
- if(getExpression() != null) {
- clonedExpr = (Expression) getExpression().clone();
- }
- ExpressionSymbol copy = new ExpressionSymbol(getName(), getCanonical(), clonedExpr);
- copy.setDerivedExpression(this.derivedExpression);
- return copy;
- }
-
- public boolean isDerivedExpression() {
- return this.derivedExpression;
- }
-
- public void setDerivedExpression(boolean derivedExpression) {
- this.derivedExpression = derivedExpression;
- }
-
-
- /**
- * @see com.metamatrix.query.sql.symbol.Symbol#hashCode()
- */
- public int hashCode() {
- if (expression != null) {
- return expression.hashCode();
- }
- return super.hashCode();
- }
-
- /**
- * ExpressionSymbol matching is not based upon the name
- *
- * @see com.metamatrix.query.sql.symbol.Symbol#equals(java.lang.Object)
- */
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
-
- if (!(obj instanceof ExpressionSymbol)) {
- return false;
- }
-
- ExpressionSymbol exprSymbol = (ExpressionSymbol)obj;
-
- if (expression == null ) {
- return exprSymbol.getExpression() == null;
- }
-
- return expression.equals(exprSymbol.getExpression());
- }
-
-}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/MultipleElementSymbol.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/MultipleElementSymbol.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/MultipleElementSymbol.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -28,7 +28,7 @@
* <p>This is a subclass of Symbol representing multiple output columns.</p>
*/
public abstract class MultipleElementSymbol extends SelectSymbol {
- private List elementSymbols;
+ private List<ElementSymbol> elementSymbols;
/**
* Passthrough constructor used for cloning
@@ -52,7 +52,7 @@
* Set the {@link ElementSymbol}s that this symbol refers to
* @param elementSymbols List of {@link ElementSymbol}
*/
- public void setElementSymbols(List elementSymbols){
+ public void setElementSymbols(List<ElementSymbol> elementSymbols){
this.elementSymbols = elementSymbols;
}
@@ -60,7 +60,7 @@
* Get the element symbols referred to by this multiple element symbol
* @return List of {@link ElementSymbol}s, may be null
*/
- public List getElementSymbols(){
+ public List<ElementSymbol> getElementSymbols(){
return this.elementSymbols;
}
@@ -70,7 +70,7 @@
*/
public void addElementSymbol(ElementSymbol symbol) {
if(getElementSymbols() == null) {
- setElementSymbols(new LinkedList());
+ setElementSymbols(new LinkedList<ElementSymbol>());
}
getElementSymbols().add(symbol);
}
Deleted: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/SingleElementSymbol.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/SingleElementSymbol.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/SingleElementSymbol.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -1,81 +0,0 @@
-/*
- * 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 com.metamatrix.query.sql.symbol;
-
-
-
-/**
- * <p>This is a subclass of Symbol representing a single output column.</p>
- */
-public abstract class SingleElementSymbol extends SelectSymbol implements Expression {
-
- /**
- * Character used to delimit name components in a symbol
- */
- public static final String SEPARATOR = "."; //$NON-NLS-1$
-
- /**
- * Passthrough constructor used for cloning
- * @param name
- * @param canonicalName
- * @param hashcode
- * @since 4.3
- */
- protected SingleElementSymbol(String name, String canonicalName) {
- super(name, canonicalName);
- }
-
- /**
- * Construct a symbol with a name
- * @param name Name of symbol
- */
- public SingleElementSymbol(String name){
- super(name);
- }
-
- /**
- * Get the short name of the element
- * @return Short name of the symbol (un-dotted)
- */
- public String getShortName() {
- String name = getName();
- return getShortName(name);
- }
-
- public static String getShortName(String name) {
- int index = name.lastIndexOf(SEPARATOR);
- if(index >= 0) {
- return name.substring(index+1);
- }
- return name;
- }
-
- /**
- * Get the short name of the element
- * @return Short name of the symbol (un-dotted)
- */
- public String getShortCanonicalName() {
- String name = getCanonicalName();
- return getShortName(name);
- }
-}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Symbol.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Symbol.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/symbol/Symbol.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -59,6 +59,11 @@
* The AliasGenerator can also set this value as necessary for the data tier.
*/
private String outputName;
+
+ /**
+ * Character used to delimit name components in a symbol
+ */
+ public static final String SEPARATOR = "."; //$NON-NLS-1$
/**
* Constructor to be used for cloning instances. Calls to String.toUpperCase() to generate the canonical names
@@ -81,7 +86,23 @@
public Symbol(String name) {
setName(name);
}
+
+ /**
+ * Get the short name of the element
+ * @return Short name of the symbol (un-dotted)
+ */
+ public String getShortName() {
+ return Symbol.getShortName(name);
+ }
+ /**
+ * Get the short name of the element
+ * @return Short name of the symbol (un-dotted)
+ */
+ public String getShortCanonicalName() {
+ return Symbol.getShortName(getCanonicalName());
+ }
+
/**
* Change the symbol's name. This will change the symbol's hash code
* and canonical name!!!!!!!!!!!!!!!!! If this symbol is in a hashed
@@ -188,4 +209,12 @@
this.outputName =outputName;
}
+ public static String getShortName(String name) {
+ int index = name.lastIndexOf(Symbol.SEPARATOR);
+ if(index >= 0) {
+ return name.substring(index+1);
+ }
+ return name;
+ }
+
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/util/SymbolMap.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/util/SymbolMap.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/util/SymbolMap.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -31,13 +31,10 @@
import java.util.Map;
import com.metamatrix.core.util.Assertion;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
public class SymbolMap {
@@ -49,25 +46,9 @@
*/
public boolean addMapping(ElementSymbol symbol,
Expression expression) {
- return map.put(symbol, getExpression(expression)) == null;
+ return map.put(symbol, expression) == null;
}
- public static final Expression getExpression(Expression symbol) {
- if (!(symbol instanceof SingleElementSymbol)) {
- return symbol;
- }
- if (symbol instanceof AliasSymbol) {
- symbol = ((AliasSymbol)symbol).getSymbol();
- }
-
- if (symbol instanceof ExpressionSymbol && !(symbol instanceof AggregateSymbol)) {
- ExpressionSymbol exprSymbol = (ExpressionSymbol)symbol;
- return exprSymbol.getExpression();
- }
-
- return symbol;
- }
-
public Expression getMappedExpression(ElementSymbol symbol) {
return map.get(symbol);
}
@@ -85,16 +66,20 @@
}
public static final SymbolMap createSymbolMap(GroupSymbol virtualGroup,
- List<? extends SingleElementSymbol> projectCols) {
- return createSymbolMap(virtualGroup, projectCols, projectCols);
+ List<DerivedColumn> projectCols) {
+ List<Expression> mappedExpressions = new ArrayList<Expression>(projectCols.size());
+ for (DerivedColumn dc : projectCols) {
+ mappedExpressions.add(dc.getExpression());
+ }
+ return createSymbolMap(virtualGroup, projectCols, mappedExpressions);
}
public static final SymbolMap createSymbolMap(GroupSymbol virtualGroup,
- List<? extends SingleElementSymbol> projectCols,
- List<? extends SingleElementSymbol> mappedCols) {
+ List<DerivedColumn> projectCols,
+ List<? extends Expression> mappedCols) {
String virtualGroupName = virtualGroup.getName();
List<ElementSymbol> virtualElements = new LinkedList<ElementSymbol>();
- for (SingleElementSymbol symbol : projectCols) {
+ for (DerivedColumn symbol : projectCols) {
String name = symbol.getShortName();
String virtualElementName = virtualGroupName + ElementSymbol.SEPARATOR + name;
ElementSymbol virtualElement = new ElementSymbol(virtualElementName);
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/util/UpdateProcedureGenerator.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/util/UpdateProcedureGenerator.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/util/UpdateProcedureGenerator.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -75,7 +75,7 @@
//the command should be a query
Query query = (Query)queryTransformation;
//get a list of symbols in select statement
- List selectSymbols = query.getProjectedSymbols();
+ List<DerivedColumn> selectSymbols = query.getProjectedSymbols();
if(query.getFrom() == null) {
return null;
@@ -159,7 +159,7 @@
* @param variables Collect each variable (physical element being updated)
* @param values Collect each value (INPUT value for respective virtual element)
*/
- private static void mapElements(List physicalElements, List virtualElements, String physicalGroup, QueryMetadataInterface metadata, List variables, List values)
+ private static void mapElements(List<DerivedColumn> physicalElements, List virtualElements, String physicalGroup, QueryMetadataInterface metadata, List variables, List values)
throws MetaMatrixComponentException, QueryMetadataException{
if(physicalElements.size()!= virtualElements.size()) {
@@ -169,13 +169,10 @@
//match the physical group elements to the virtual group elements
for(int i=0; i<physicalElements.size(); i++) {
// Strip alias if necessary to get physical element
- SingleElementSymbol pSymbol = (SingleElementSymbol)physicalElements.get(i);
- if(pSymbol instanceof AliasSymbol) {
- pSymbol = ((AliasSymbol) pSymbol).getSymbol();
- }
+ DerivedColumn pSymbol = physicalElements.get(i);
- if(pSymbol instanceof ElementSymbol) {
- final Object mid = ((ElementSymbol)pSymbol).getMetadataID();
+ if(pSymbol.getExpression() instanceof ElementSymbol) {
+ final Object mid = ((ElementSymbol)pSymbol.getExpression()).getMetadataID();
final boolean supportsUpdate = metadata.elementSupports(mid, SupportConstants.Element.UPDATE);
//Only include elements that are updateable.
if(supportsUpdate) {
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/AggregateSymbolCollectorVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/AggregateSymbolCollectorVisitor.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/AggregateSymbolCollectorVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -29,10 +29,10 @@
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.LanguageVisitor;
import com.metamatrix.query.sql.navigator.PreOrPostOrderNavigator;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.Expression;
public class AggregateSymbolCollectorVisitor extends LanguageVisitor {
@@ -42,17 +42,17 @@
super(visitor, PreOrPostOrderNavigator.POST_ORDER);
}
- public void visit(AggregateSymbol obj) {
+ public void visit(Aggregate obj) {
// Visit aggregate symbol but do not dive into it's expression
preVisitVisitor(obj);
postVisitVisitor(obj);
}
/**
- * @see com.metamatrix.query.sql.navigator.PreOrPostOrderNavigator#visit(com.metamatrix.query.sql.symbol.ExpressionSymbol)
+ * @see com.metamatrix.query.sql.navigator.PreOrPostOrderNavigator#visit(com.metamatrix.query.sql.symbol.DerivedColumn)
*/
@Override
- public void visit(ExpressionSymbol obj) {
+ public void visit(DerivedColumn obj) {
if (obj.isDerivedExpression()) {
preVisitVisitor(obj);
postVisitVisitor(obj);
@@ -63,23 +63,23 @@
}
- private Collection<AggregateSymbol> aggregates;
- private Collection<SingleElementSymbol> groupingSymbols;
+ private Collection<Aggregate> aggregates;
+ private Collection<Expression> groupingSymbols;
- public AggregateSymbolCollectorVisitor(Collection<AggregateSymbol> aggregates, Collection<SingleElementSymbol> elements) {
+ public AggregateSymbolCollectorVisitor(Collection<Aggregate> aggregates, Collection<Expression> elements) {
this.aggregates = aggregates;
this.groupingSymbols = elements;
}
- public void visit(AggregateSymbol obj) {
+ public void visit(Aggregate obj) {
if (aggregates != null) {
this.aggregates.add(obj);
}
}
- public void visit(ExpressionSymbol obj) {
+ public void visit(DerivedColumn obj) {
if (this.groupingSymbols != null && obj.isDerivedExpression()) {
- this.groupingSymbols.add(obj);
+ this.groupingSymbols.add(obj.getExpression());
}
}
@@ -89,19 +89,19 @@
}
}
- public static final void getAggregates(LanguageObject obj, Collection<SingleElementSymbol> aggregates, Collection<SingleElementSymbol> elements) {
- AggregateSymbolCollectorVisitor visitor = new AggregateSymbolCollectorVisitor(new ArrayList<AggregateSymbol>(), elements);
+ public static final void getAggregates(LanguageObject obj, Collection<Expression> aggregates, Collection<Expression> elements) {
+ AggregateSymbolCollectorVisitor visitor = new AggregateSymbolCollectorVisitor(new ArrayList<Aggregate>(), elements);
AggregateStopNavigator asn = new AggregateStopNavigator(visitor);
obj.acceptVisitor(asn);
aggregates.addAll(visitor.aggregates);
}
- public static final Collection<AggregateSymbol> getAggregates(LanguageObject obj, boolean removeDuplicates) {
- Collection<AggregateSymbol> aggregates = null;
+ public static final Collection<Aggregate> getAggregates(LanguageObject obj, boolean removeDuplicates) {
+ Collection<Aggregate> aggregates = null;
if (removeDuplicates) {
- aggregates = new HashSet<AggregateSymbol>();
+ aggregates = new HashSet<Aggregate>();
} else {
- aggregates = new ArrayList<AggregateSymbol>();
+ aggregates = new ArrayList<Aggregate>();
}
AggregateSymbolCollectorVisitor visitor = new AggregateSymbolCollectorVisitor(aggregates, null);
AggregateStopNavigator asn = new AggregateStopNavigator(visitor);
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/CriteriaTranslatorVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/CriteriaTranslatorVisitor.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/CriteriaTranslatorVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -309,9 +309,6 @@
* translated. Otherwise, the same expression.
*/
private Expression replaceExpression(Expression exp) {
- if(exp instanceof AliasSymbol) {
- exp = ((AliasSymbol)exp).getSymbol();
- }
if(exp instanceof ElementSymbol) {
exp = getTranslatedExpression((ElementSymbol)exp);
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/EvaluatableVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -38,9 +38,9 @@
import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
import com.metamatrix.query.sql.lang.SubquerySetCriteria;
import com.metamatrix.query.sql.navigator.PreOrderNavigator;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.symbol.ScalarSubquery;
@@ -108,11 +108,11 @@
}
}
- public void visit(ExpressionSymbol obj) {
+ public void visit(DerivedColumn obj) {
evaluationNotPossible();
}
- public void visit(AggregateSymbol obj) {
+ public void visit(Aggregate obj) {
evaluationNotPossible();
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionMappingVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -39,9 +39,8 @@
import com.metamatrix.query.sql.lang.IsNullCriteria;
import com.metamatrix.query.sql.lang.Limit;
import com.metamatrix.query.sql.lang.MatchCriteria;
-import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.lang.SPParameter;
-import com.metamatrix.query.sql.lang.Select;
import com.metamatrix.query.sql.lang.SetClause;
import com.metamatrix.query.sql.lang.SetCriteria;
import com.metamatrix.query.sql.lang.StoredProcedure;
@@ -50,14 +49,12 @@
import com.metamatrix.query.sql.navigator.PostOrderNavigator;
import com.metamatrix.query.sql.navigator.PreOrderNavigator;
import com.metamatrix.query.sql.proc.AssignmentStatement;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.CaseExpression;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
/**
* It is important to use a Post Navigator with this class,
@@ -79,57 +76,14 @@
return true;
}
- public void visit(Select obj) {
- replaceSymbols(obj.getSymbols(), true);
- }
-
- private void replaceSymbols(List symbols, boolean alias) {
- for (int i = 0; i < symbols.size(); i++) {
- Object symbol = symbols.get(i);
-
- if (symbol instanceof SingleElementSymbol) {
- SingleElementSymbol ses = (SingleElementSymbol)symbol;
- SingleElementSymbol replacmentSymbol = null;
-
- Expression expr = ses;
- if (ses instanceof ExpressionSymbol && !(ses instanceof AggregateSymbol)) {
- expr = ((ExpressionSymbol)ses).getExpression();
- }
-
- Expression replacement = replaceExpression(expr);
-
- if (replacement instanceof SingleElementSymbol) {
- replacmentSymbol = (SingleElementSymbol)replacement;
- } else {
- replacmentSymbol = new ExpressionSymbol(ses.getName(), replacement);
- }
-
- if (alias && createAliases() && !replacmentSymbol.getShortName().equals(ses.getShortName())) {
- replacmentSymbol = new AliasSymbol(ses.getShortName(), replacmentSymbol);
- }
-
- symbols.set(i, replacmentSymbol);
- }
+ public void visit(DerivedColumn expr) {
+ Expression expression = expr.getExpression();
+ expr.setExpression(replaceExpression(expr.getExpression()));
+ if (createAliases() && expr.getExpression() != expression) {
+ expr.setAlias(true);
}
}
- /**
- * @see com.metamatrix.query.sql.LanguageVisitor#visit(com.metamatrix.query.sql.symbol.AliasSymbol)
- */
- public void visit(AliasSymbol obj) {
- Expression replacement = replaceExpression(obj.getSymbol());
-
- if (replacement instanceof SingleElementSymbol) {
- obj.setSymbol((SingleElementSymbol)replacement);
- } else {
- obj.setSymbol(new ExpressionSymbol(obj.getName(), replacement));
- }
- }
-
- public void visit(ExpressionSymbol expr) {
- expr.setExpression(replaceExpression(expr.getExpression()));
- }
-
/**
* @see com.metamatrix.query.sql.LanguageVisitor#visit(BetweenCriteria)
*/
@@ -250,26 +204,22 @@
}
}
- public void visit(AggregateSymbol obj) {
+ public void visit(Aggregate obj) {
if (obj.getExpression() != null) { //account for count(*) - TODO: clean this up
obj.setExpression(replaceExpression(obj.getExpression()));
}
}
- /**
- * Swap each ElementSymbol in GroupBy (other symbols are ignored).
- * @param obj Object to remap
- */
- public void visit(GroupBy obj) {
- replaceSymbols(obj.getSymbols(), false);
+ public void visit(GroupBy obj) {
+ List<Expression> expr = obj.getSymbols();
+ for (int i = 0; i < expr.size(); i++) {
+ expr.set(i, replaceExpression(expr.get(i)));
+ }
}
- /**
- * Swap each SingleElementSymbol in OrderBy (other symbols are ignored).
- * @param obj Object to remap
- */
- public void visit(OrderBy obj) {
- replaceSymbols(obj.getVariables(), true);
+ @Override
+ public void visit(OrderByItem obj) {
+ obj.setSortKey(replaceExpression(obj.getSortKey()));
}
public void visit(Limit obj) {
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionSymbolCollector.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionSymbolCollector.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/ExpressionSymbolCollector.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -28,8 +28,8 @@
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.LanguageVisitor;
import com.metamatrix.query.sql.navigator.PreOrderNavigator;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.util.ErrorMessageKeys;
/**
@@ -72,7 +72,7 @@
* called directly.
* @param obj Language object
*/
- public void visit(ExpressionSymbol obj) {
+ public void visit(DerivedColumn obj) {
this.symbols.add(obj);
}
@@ -81,7 +81,7 @@
* called directly.
* @param obj Language object
*/
- public void visit(AggregateSymbol obj) {
+ public void visit(Aggregate obj) {
this.symbols.add(obj);
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/sql/visitor/SQLStringVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -59,6 +59,7 @@
import com.metamatrix.query.sql.lang.NotCriteria;
import com.metamatrix.query.sql.lang.Option;
import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.lang.PredicateCriteria;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.QueryCommand;
@@ -75,6 +76,7 @@
import com.metamatrix.query.sql.lang.UnaryFromClause;
import com.metamatrix.query.sql.lang.Update;
import com.metamatrix.query.sql.lang.XQuery;
+import com.metamatrix.query.sql.lang.OrderByItem.OrderSpecification;
import com.metamatrix.query.sql.proc.AssignmentStatement;
import com.metamatrix.query.sql.proc.Block;
import com.metamatrix.query.sql.proc.BreakStatement;
@@ -90,22 +92,21 @@
import com.metamatrix.query.sql.proc.Statement;
import com.metamatrix.query.sql.proc.TranslateCriteria;
import com.metamatrix.query.sql.proc.WhileStatement;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.AllInGroupSymbol;
import com.metamatrix.query.sql.symbol.AllSymbol;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.symbol.ScalarSubquery;
import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
import com.metamatrix.query.sql.symbol.SelectSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
+import com.metamatrix.query.sql.symbol.Symbol;
import com.metamatrix.query.util.ErrorMessageKeys;
/**
@@ -730,30 +731,26 @@
parts.add(SPACE);
parts.add(ReservedWords.BY);
parts.add(SPACE);
-
- List variables = obj.getVariables();
- List types = obj.getTypes();
- Iterator iter = variables.iterator();
- Iterator typeIter = types.iterator();
- while ( iter.hasNext() ) {
- SingleElementSymbol ses = (SingleElementSymbol)iter.next();
- if (ses instanceof ElementSymbol && ((ElementSymbol)ses).getDisplayMode().equals(ElementSymbol.DisplayMode.SHORT_OUTPUT_NAME)) {
- parts.add(registerNode(ses));
- } else {
- outputDisplayName(ses.getOutputName());
- }
- Boolean type = (Boolean) typeIter.next();
- if( type.booleanValue() == OrderBy.DESC ) {
- parts.add(SPACE);
- parts.add(ReservedWords.DESC);
- } // Don't print default "ASC"
-
- if (iter.hasNext()) {
- parts.add( ", " ); //$NON-NLS-1$
- }
- }
+ List<OrderByItem> items = obj.getSortOrder();
+ for (Iterator<OrderByItem> iterator = items.iterator(); iterator.hasNext();) {
+ OrderByItem orderByItem = iterator.next();
+ parts.add(registerNode(orderByItem));
+ if (iterator.hasNext()) {
+ parts.add(", "); //$NON-NLS-1$
+ }
+ }
}
+ @Override
+ public void visit(OrderByItem obj) {
+ Expression ses = obj.getSortKey();
+ parts.add(registerNode(ses));
+ if(obj.getOrderingSpecification() == OrderSpecification.DESC) {
+ parts.add(SPACE);
+ parts.add(ReservedWords.DESC);
+ }
+ }
+
public void visit(DynamicCommand obj) {
parts.add(ReservedWords.EXECUTE);
parts.add(SPACE);
@@ -1118,7 +1115,7 @@
// ############ Visitor methods for symbol objects ####################
- public void visit(AggregateSymbol obj) {
+ public void visit(Aggregate obj) {
parts.add(obj.getAggregateFunction());
parts.add("("); //$NON-NLS-1$
@@ -1135,12 +1132,14 @@
parts.add(")"); //$NON-NLS-1$
}
- public void visit(AliasSymbol obj) {
- parts.add(registerNode(obj.getSymbol()));
- parts.add(SPACE);
- parts.add(ReservedWords.AS);
- parts.add(SPACE);
- parts.add(escapeSinglePart(obj.getOutputName()));
+ public void visit(DerivedColumn obj) {
+ parts.add(registerNode(obj.getExpression()));
+ if (obj.isAlias()) {
+ parts.add(SPACE);
+ parts.add(ReservedWords.AS);
+ parts.add(SPACE);
+ parts.add(escapeSinglePart(obj.getOutputName()));
+ }
}
public void visit(AllInGroupSymbol obj) {
@@ -1231,7 +1230,7 @@
if (obj.getDisplayMode().equals(ElementSymbol.DisplayMode.FULLY_QUALIFIED)) {
name = obj.getName();
} else if (obj.getDisplayMode().equals(ElementSymbol.DisplayMode.SHORT_OUTPUT_NAME)) {
- String shortName = SingleElementSymbol.getShortName(name);
+ String shortName = Symbol.getShortName(name);
//TODO: this is a hack - since we default to not supporting double quoted identifiers, we need to fully qualify reserved
if (!isReservedWord(shortName)) {
name = shortName;
@@ -1251,10 +1250,6 @@
}
}
- public void visit(ExpressionSymbol obj) {
- parts.add(registerNode(obj.getExpression()));
- }
-
public void visit(Function obj) {
String name = obj.getName();
Expression[] args = obj.getArgs();
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/AggregateValidationVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/AggregateValidationVisitor.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/AggregateValidationVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -29,11 +29,11 @@
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.ReservedWords;
import com.metamatrix.query.sql.navigator.PreOrderNavigator;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
import com.metamatrix.query.sql.visitor.AggregateSymbolCollectorVisitor;
@@ -58,12 +58,12 @@
this.groupExpressions = groupExpressions;
}
- public void visit(AggregateSymbol obj) {
+ public void visit(Aggregate obj) {
Expression aggExp = obj.getExpression();
// Check for any nested aggregates (which are not allowed)
if(aggExp != null) {
- Collection<AggregateSymbol> nestedAggs = AggregateSymbolCollectorVisitor.getAggregates(aggExp, true);
+ Collection<Aggregate> nestedAggs = AggregateSymbolCollectorVisitor.getAggregates(aggExp, true);
if(nestedAggs.size() > 0) {
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0039, nestedAggs), nestedAggs);
}
@@ -83,7 +83,7 @@
validateExpression(obj);
}
- public void visit(ExpressionSymbol obj) {
+ public void visit(DerivedColumn obj) {
validateExpression(obj);
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/UpdateValidationVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/UpdateValidationVisitor.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/UpdateValidationVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -144,12 +144,12 @@
symbol = ((AliasSymbol)symbol).getSymbol();
}
- if(symbol instanceof AggregateSymbol) {
- handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0007, symbol));
- } else if(symbol instanceof ExpressionSymbol) {
- Expression expr = ((ExpressionSymbol)symbol).getExpression();
- if(expr == null || expr instanceof Function) {
+ if(symbol instanceof DerivedColumn) {
+ Expression expr = ((DerivedColumn)symbol).getExpression();
+ if(expr instanceof Function) {
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0008, symbol));
+ } else if (expr instanceof Aggregate) {
+ handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0007, symbol));
}
}
}
Modified: branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -86,11 +86,11 @@
import com.metamatrix.query.sql.proc.TranslateCriteria;
import com.metamatrix.query.sql.proc.WhileStatement;
import com.metamatrix.query.sql.symbol.AbstractCaseExpression;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
@@ -163,8 +163,8 @@
Iterator symbolIter = groupBySymbols.iterator();
while(symbolIter.hasNext()) {
SingleElementSymbol symbol = (SingleElementSymbol)symbolIter.next();
- if(symbol instanceof ExpressionSymbol) {
- ExpressionSymbol exprSymbol = (ExpressionSymbol) symbol;
+ if(symbol instanceof DerivedColumn) {
+ DerivedColumn exprSymbol = (DerivedColumn) symbol;
Expression expr = exprSymbol.getExpression();
if(! (expr instanceof Function || expr instanceof AbstractCaseExpression)) {
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.Expr_in_GROUP_BY_must_be_elem_func_case", expr), expr); //$NON-NLS-1$
@@ -569,7 +569,7 @@
ElementSymbol criteriaElement = (ElementSymbol) critEmlntIter.next();
if(transleElmnts.contains(criteriaElement)) {
Expression mappedExpr = (Expression) symbolMap.get(criteriaElement);
- if(mappedExpr instanceof AggregateSymbol) {
+ if(mappedExpr instanceof Aggregate) {
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0022, criteriaElement), criteriaElement);
}
Modified: branches/symbol_refactoring_61/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj
===================================================================
--- branches/symbol_refactoring_61/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj 2009-03-03 17:26:43 UTC (rev 532)
@@ -1478,52 +1478,29 @@
]
)
{
- // Validate alias
- String alias = null;
- if(aliasToken != null) {
- alias = validateAlias(aliasToken.image);
- }
-
if(allInGroupToken != null) {
- if(aliasToken == null) {
- // Group.*
- return new AllInGroupSymbol(validateMetadataID(allInGroupToken.image));
+ // Group.*
+ return new AllInGroupSymbol(validateMetadataID(allInGroupToken.image));
+ } else {
+ String name = null;
+ if (aliasToken == null) {
+ if(expression instanceof ElementSymbol) {
+ name = ((ElementSymbol)expression).getShortName();
+ } else {
+ name = generateFunctionName(info, null);
+ }
} else {
- Object[] params = new Object[] { allInGroupToken.image };
- throw new ParseException(QueryPlugin.Util.getString("SQLParser.Cant_alias_star", params)); //$NON-NLS-1$
+ name = validateAlias(aliasToken.image);
}
- } else if(expression instanceof ElementSymbol) {
- SingleElementSymbol es = (ElementSymbol) expression;
- if(aliasToken != null) {
- // Aliased element
- es = new AliasSymbol(alias, es);
- }
- return es;
- } else if(expression instanceof AggregateSymbol) {
- // This can happen if the aggregate symbol is surrounded by ( ), which
- // can happen when queries are generated in ODBC
- AggregateSymbol aggSymbol = (AggregateSymbol) expression;
- if(aliasToken != null) {
- return new AliasSymbol(alias, aggSymbol);
- } else {
- return aggSymbol;
- }
- } else {
- String functionName = generateFunctionName(info, null);
- SingleElementSymbol expSymbol = new ExpressionSymbol(functionName, expression);
- if(aliasToken != null) {
- expSymbol = new AliasSymbol(alias, expSymbol);
- }
- return expSymbol;
- }
+ return new DerivedColumn(name, expression, aliasToken != null);
+ }
}
}
-AggregateSymbol aggregateSymbol(ParseInfo info) :
+Aggregate aggregate(ParseInfo info) :
{
Token functionToken = null;
Token starToken = null;
- AggregateSymbol agg = null;
boolean isDistinct = false;
Expression expression = null;
}
@@ -1556,16 +1533,7 @@
}
String func = functionToken.image.toUpperCase();
- String name = generateFunctionName(info, func);
- if(starToken == null) {
- // Aggregate
- agg = new AggregateSymbol(name, func, isDistinct, expression);
- } else {
- // COUNT(*)
- agg = new AggregateSymbol(name, func, false, null);
- }
-
- return agg;
+ return new Aggregate(func, isDistinct, expression);
}
}
@@ -2207,18 +2175,19 @@
GroupBy groupBy(ParseInfo info) :
{
GroupBy groupBy = new GroupBy();
- SingleElementSymbol symbol = null;
+ Expression expr = null;
}
{
<GROUP> <BY>
- ( symbol = groupByItem(info)
+ (expr = expression(info)
+
{
- groupBy.addSymbol(symbol);
+ groupBy.addSymbol(expr);
}
- (<COMMA> symbol = groupByItem(info)
+ (<COMMA> expr = expression(info)
{
- groupBy.addSymbol(symbol);
+ groupBy.addSymbol(expr);
}
)*
)
@@ -2228,31 +2197,6 @@
}
/**
- * <p>Parse a GROUP BY list item. </p>
- * @return Parsed group by item
- * @throws ParseException if parsing failed
- */
-SingleElementSymbol groupByItem(ParseInfo info) :
-{
- Expression expr = null;
- SingleElementSymbol symbol = null;
-}
-{
- expr = expression(info)
- {
- if(expr instanceof ElementSymbol) {
- symbol = (ElementSymbol) expr;
- } else {
- String exprName = generateFunctionName(info, null);
- symbol = new ExpressionSymbol(exprName, expr);
- }
- }
- {
- return symbol;
- }
-}
-
-/**
* <p>Parse a HAVING clause. </p>
* @return Parsed having
* @throws ParseException if parsing failed
@@ -2590,7 +2534,7 @@
)
|
// Aggregate function
- (expression=aggregateSymbol(info))
+ (expression=aggregate(info))
|
// Function
LOOKAHEAD(2) (expression=function(info))
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestAggregateImpl.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestAggregateImpl.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/dqp/internal/datamgr/language/TestAggregateImpl.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -26,7 +26,7 @@
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.query.sql.ReservedWords;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.Constant;
import junit.framework.TestCase;
@@ -42,10 +42,9 @@
}
public static AggregateImpl example(String name, String functionName, boolean distinct, int value) throws Exception {
- AggregateSymbol symbol = new AggregateSymbol(name,
- functionName,
+ Aggregate symbol = new Aggregate(functionName,
distinct,
- new Constant(new Integer(value)));
+ new Constant(new Integer(value)));
return (AggregateImpl)TstLanguageBridgeFactory.factory.translate(symbol);
}
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinWithFunction.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinWithFunction.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/optimizer/TestJoinWithFunction.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -35,7 +35,7 @@
import com.metamatrix.query.processor.relational.RelationalPlan;
import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
/**
* <p><code>TestCase</code> to cover planning and optimization of JOINs which
@@ -289,7 +289,7 @@
Constant expectedConst = new Constant(new Double(10.0));
assertEquals("Did not get expected constant value for SqrtTop in root node of plan: ", //$NON-NLS-1$
expectedConst,
- ((ExpressionSymbol) ((AliasSymbol) elem.get(8)).getSymbol()).getExpression() // should be a AliasSymbol containing an expression
+ ((DerivedColumn) ((AliasSymbol) elem.get(8)).getSymbol()).getExpression() // should be a AliasSymbol containing an expression
);
}
@@ -359,7 +359,7 @@
Constant expectedConst = new Constant(new Double(10.0));
assertEquals("Did not get expected constant value for SqrtLeft in root node of plan: ", //$NON-NLS-1$
expectedConst,
- ((ExpressionSymbol) ((AliasSymbol) elem.get(8)).getSymbol()).getExpression() // should be a AliasSymbol containing an expression
+ ((DerivedColumn) ((AliasSymbol) elem.get(8)).getSymbol()).getExpression() // should be a AliasSymbol containing an expression
);
}
@@ -427,11 +427,11 @@
Constant expectedConst = new Constant(new Double(10.0));
assertEquals("Did not get expected constant value for SqrtLeft in root node of plan: ", //$NON-NLS-1$
expectedConst,
- ((ExpressionSymbol) ((AliasSymbol) elem.get(8)).getSymbol()).getExpression() // should be a AliasSymbol containing an expression
+ ((DerivedColumn) ((AliasSymbol) elem.get(8)).getSymbol()).getExpression() // should be a AliasSymbol containing an expression
);
assertEquals("Did not get expected constant value for SqrtTop in root node of plan: ", //$NON-NLS-1$
expectedConst,
- ((ExpressionSymbol) ((AliasSymbol) elem.get(9)).getSymbol()).getExpression() // should be a AliasSymbol containing an expression
+ ((DerivedColumn) ((AliasSymbol) elem.get(9)).getSymbol()).getExpression() // should be a AliasSymbol containing an expression
);
}
}
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestCapabilitiesUtil.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestCapabilitiesUtil.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/optimizer/relational/rules/TestCapabilitiesUtil.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -41,11 +41,11 @@
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.JoinType;
import com.metamatrix.query.sql.lang.SetQuery.Operation;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.ScalarSubquery;
import com.metamatrix.query.unittest.FakeMetadataFacade;
@@ -186,13 +186,13 @@
*/
public void testSupportsFunctionInGroupBy() throws Exception {
Function f = new Function("concat", new Expression[] { new Constant("a"), new Constant("b") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- ExpressionSymbol expr = new ExpressionSymbol("e", f); //$NON-NLS-1$
+ DerivedColumn expr = new DerivedColumn("e", f); //$NON-NLS-1$
List cols = new ArrayList();
cols.add(expr);
helpTestSupportsAggregates(false, false, cols);
}
- public void helpTestSupportsAggregateFunction(SourceCapabilities caps, AggregateSymbol aggregate, boolean expectedValue) throws QueryMetadataException, MetaMatrixComponentException {
+ public void helpTestSupportsAggregateFunction(SourceCapabilities caps, Aggregate aggregate, boolean expectedValue) throws QueryMetadataException, MetaMatrixComponentException {
// Set up metadata
FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
FakeMetadataObject modelID = metadata.getStore().findObject("pm1", FakeMetadataObject.MODEL); //$NON-NLS-1$
@@ -211,7 +211,7 @@
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.COUNT, false, null); //$NON-NLS-1$
+ Aggregate aggregate = new Aggregate(ReservedWords.COUNT, false, null); //$NON-NLS-1$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -223,7 +223,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, false);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.COUNT, false, null); //$NON-NLS-1$
+ Aggregate aggregate = new Aggregate(ReservedWords.COUNT, false, null); //$NON-NLS-1$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -235,7 +235,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, false);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.COUNT, false, null); //$NON-NLS-1$
+ Aggregate aggregate = new Aggregate(ReservedWords.COUNT, false, null); //$NON-NLS-1$
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
@@ -247,7 +247,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, false);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.COUNT, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate aggregate = new Aggregate(ReservedWords.COUNT, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -259,7 +259,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.COUNT, false, null); //$NON-NLS-1$
+ Aggregate aggregate = new Aggregate(ReservedWords.COUNT, false, null); //$NON-NLS-1$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -271,7 +271,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.COUNT, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate aggregate = new Aggregate(ReservedWords.COUNT, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
@@ -282,7 +282,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.SUM, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate aggregate = new Aggregate(ReservedWords.SUM, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -293,7 +293,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.SUM, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate aggregate = new Aggregate(ReservedWords.SUM, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
@@ -304,7 +304,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.AVG, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate aggregate = new Aggregate(ReservedWords.AVG, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -315,7 +315,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.AVG, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate aggregate = new Aggregate(ReservedWords.AVG, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
@@ -326,7 +326,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MIN, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.MIN, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate aggregate = new Aggregate(ReservedWords.MIN, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -337,7 +337,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MIN, true);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.MIN, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate aggregate = new Aggregate(ReservedWords.MIN, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
@@ -348,7 +348,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.MAX, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate aggregate = new Aggregate(ReservedWords.MAX, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -359,7 +359,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.MAX, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate aggregate = new Aggregate(ReservedWords.MAX, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
@@ -371,7 +371,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_DISTINCT, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.MAX, true, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate aggregate = new Aggregate(ReservedWords.MAX, true, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -383,7 +383,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_DISTINCT, true);
- AggregateSymbol aggregate = new AggregateSymbol("expr", ReservedWords.MAX, true, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate aggregate = new Aggregate(ReservedWords.MAX, true, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/parser/TestParser.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/parser/TestParser.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/parser/TestParser.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -57,6 +57,7 @@
import com.metamatrix.query.sql.lang.MatchCriteria;
import com.metamatrix.query.sql.lang.NotCriteria;
import com.metamatrix.query.sql.lang.OrderBy;
+import com.metamatrix.query.sql.lang.OrderByItem;
import com.metamatrix.query.sql.lang.PredicateCriteria;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.SPParameter;
@@ -70,6 +71,7 @@
import com.metamatrix.query.sql.lang.SubquerySetCriteria;
import com.metamatrix.query.sql.lang.UnaryFromClause;
import com.metamatrix.query.sql.lang.Update;
+import com.metamatrix.query.sql.lang.OrderByItem.OrderSpecification;
import com.metamatrix.query.sql.lang.SetQuery.Operation;
import com.metamatrix.query.sql.proc.AssignmentStatement;
import com.metamatrix.query.sql.proc.Block;
@@ -86,15 +88,14 @@
import com.metamatrix.query.sql.proc.Statement;
import com.metamatrix.query.sql.proc.TranslateCriteria;
import com.metamatrix.query.sql.proc.WhileStatement;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.AllInGroupSymbol;
import com.metamatrix.query.sql.symbol.AllSymbol;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
@@ -459,7 +460,7 @@
From from = new From();
from.addClause(jp);
- AliasSymbol as = new AliasSymbol("myA", new ElementSymbol("myG.a")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn as = new DerivedColumn("myA", new ElementSymbol("myG.a"), true); //$NON-NLS-1$ //$NON-NLS-2$
Select select = new Select();
select.addSymbol(as);
select.addSymbol(new ElementSymbol("myH.b")); //$NON-NLS-1$
@@ -486,7 +487,7 @@
From from = new From();
from.addClause(jp);
- AliasSymbol as = new AliasSymbol("myA", new ElementSymbol("myG.a")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn as = new DerivedColumn("myA", new ElementSymbol("myG.a"), true); //$NON-NLS-1$ //$NON-NLS-2$
Select select = new Select();
select.addSymbol(as);
select.addSymbol(new ElementSymbol("myH.b")); //$NON-NLS-1$
@@ -513,7 +514,7 @@
From from = new From();
from.addClause(jp);
- AliasSymbol as = new AliasSymbol("myA", new ElementSymbol("myG.a")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn as = new DerivedColumn("myA", new ElementSymbol("myG.a"), true); //$NON-NLS-1$ //$NON-NLS-2$
Select select = new Select();
select.addSymbol(as);
select.addSymbol(new ElementSymbol("myH.b")); //$NON-NLS-1$
@@ -540,7 +541,7 @@
From from = new From();
from.addClause(jp);
- AliasSymbol as = new AliasSymbol("myA", new ElementSymbol("myG.a")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn as = new DerivedColumn("myA", new ElementSymbol("myG.a"), true); //$NON-NLS-1$ //$NON-NLS-2$
Select select = new Select();
select.addSymbol(as);
select.addSymbol(new ElementSymbol("myH.b")); //$NON-NLS-1$
@@ -567,7 +568,7 @@
From from = new From();
from.addClause(jp);
- AliasSymbol as = new AliasSymbol("myA", new ElementSymbol("myG.a")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn as = new DerivedColumn("myA", new ElementSymbol("myG.a"), true); //$NON-NLS-1$ //$NON-NLS-2$
Select select = new Select();
select.addSymbol(as);
select.addSymbol(new ElementSymbol("myH.b")); //$NON-NLS-1$
@@ -615,7 +616,7 @@
from.addGroup(g);
Function f = new Function("CONVERT", new Expression[] {new ElementSymbol("a", false), new Constant("string")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -635,7 +636,7 @@
Function f = new Function("CONVERT", new Expression[] {new ElementSymbol("a", false), new Constant("timestamp")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Function f2 = new Function("CONVERT", new Expression[] {f, new Constant("string")}); //$NON-NLS-1$ //$NON-NLS-2$
- ExpressionSymbol es = new ExpressionSymbol("expr", f2); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f2); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -658,7 +659,7 @@
Function f = new Function("concat", new Expression[] {new ElementSymbol("a", false), new Constant("x")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Function f2 = new Function("length", new Expression[] {f}); //$NON-NLS-1$
Function f3 = new Function("+", new Expression[] {new Constant(new Integer(5)), f2}); //$NON-NLS-1$
- ExpressionSymbol es = new ExpressionSymbol("expr", f3); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f3); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -677,10 +678,9 @@
from.addGroup(g);
Function f = new Function("replace", new Expression[] {new ElementSymbol("a", false), new Constant("x"), new Constant("y")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- ExpressionSymbol es = new ExpressionSymbol("y", f); //$NON-NLS-1$
- AliasSymbol as = new AliasSymbol("y", es); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("y", f, true); //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(as);
+ select.addSymbol(es);
Query query = new Query();
query.setSelect(select);
@@ -697,7 +697,7 @@
from.addGroup(g);
Function f = new Function("cast", new Expression[] {new ElementSymbol("a", false), new Constant("string")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -717,7 +717,7 @@
Function f = new Function("cast", new Expression[] {new ElementSymbol("a", false), new Constant("timestamp")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Function f2 = new Function("cast", new Expression[] {f, new Constant("string")}); //$NON-NLS-1$ //$NON-NLS-2$
- ExpressionSymbol es = new ExpressionSymbol("expr", f2); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f2); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -736,10 +736,9 @@
from.addGroup(g);
Function f = new Function("left", new Expression[] {new ElementSymbol("fullname", false), new Constant(new Integer(3))}); //$NON-NLS-1$ //$NON-NLS-2$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
- AliasSymbol as = new AliasSymbol("x", es); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("x", f, true); //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(as);
+ select.addSymbol(es);
Query query = new Query();
query.setSelect(select);
@@ -756,10 +755,9 @@
from.addGroup(g);
Function f = new Function("right", new Expression[] {new ElementSymbol("fullname", false), new Constant(new Integer(3))}); //$NON-NLS-1$ //$NON-NLS-2$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
- AliasSymbol as = new AliasSymbol("x", es); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("x", f, true); //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(as);
+ select.addSymbol(es);
Query query = new Query();
query.setSelect(select);
@@ -776,10 +774,9 @@
from.addGroup(g);
Function f = new Function("char", new Expression[] { new Constant("x")}); //$NON-NLS-1$ //$NON-NLS-2$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
- AliasSymbol as = new AliasSymbol("x", es); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("x", f, true); //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(as);
+ select.addSymbol(es);
Query query = new Query();
query.setSelect(select);
@@ -796,10 +793,9 @@
from.addGroup(g);
Function f = new Function("insert", new Expression[] { new Constant("x"), new Constant(new Integer(1)), new Constant("a")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
- AliasSymbol as = new AliasSymbol("x", es); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("x", f, true); //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(as);
+ select.addSymbol(es);
Query query = new Query();
query.setSelect(select);
@@ -822,7 +818,7 @@
Select select = new Select();
// select.addSymbol( new ExpressionSymbol( new Constant( new Integer(1) ) ) );
- select.addSymbol( new ExpressionSymbol( "exp", new Constant( new Integer(1) ) ) ); //$NON-NLS-1$
+ select.addSymbol( new DerivedColumn( "exp", new Constant( new Integer(1) ) ) ); //$NON-NLS-1$
Query query = new Query();
query.setSelect(select);
@@ -841,7 +837,7 @@
from.addGroup(g);
Function f = new Function("translate", new Expression[] { new Constant("x"), new Constant("x"), new Constant("y")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -861,10 +857,9 @@
Function f = new Function("timestampadd", new Expression[] { //$NON-NLS-1$
new Constant("SQL_TSI_FRAC_SECOND"), new Constant(new Integer(10)), new Constant("2003-05-01 10:20:30")}); //$NON-NLS-1$ //$NON-NLS-2$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
- AliasSymbol as = new AliasSymbol("x", es); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("x", f, true); //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(as);
+ select.addSymbol(es);
Query query = new Query();
query.setSelect(select);
@@ -882,10 +877,9 @@
Function f = new Function("timestampadd", new Expression[] { //$NON-NLS-1$
new Constant("SQL_TSI_SECOND"), new Constant(new Integer(10)), new Constant("2003-05-01 10:20:30")}); //$NON-NLS-1$ //$NON-NLS-2$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
- AliasSymbol as = new AliasSymbol("x", es); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("x", f, true); //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(as);
+ select.addSymbol(es);
Query query = new Query();
query.setSelect(select);
@@ -903,10 +897,9 @@
Function f = new Function("timestampadd", new Expression[] { //$NON-NLS-1$
new Constant("SQL_TSI_MINUTE"), new Constant(new Integer(10)), new Constant("2003-05-01 10:20:30")}); //$NON-NLS-1$ //$NON-NLS-2$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
- AliasSymbol as = new AliasSymbol("x", es); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("x", f, true); //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(as);
+ select.addSymbol(es);
Query query = new Query();
query.setSelect(select);
@@ -924,10 +917,9 @@
Function f = new Function("timestampadd", new Expression[] { //$NON-NLS-1$
new Constant("SQL_TSI_HOUR"), new Constant(new Integer(10)), new Constant("2003-05-01 10:20:30")}); //$NON-NLS-1$ //$NON-NLS-2$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
- AliasSymbol as = new AliasSymbol("x", es); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("x", f, true); //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(as);
+ select.addSymbol(es);
Query query = new Query();
query.setSelect(select);
@@ -945,10 +937,9 @@
Function f = new Function("timestampadd", new Expression[] { //$NON-NLS-1$
new Constant("SQL_TSI_DAY"), new Constant(new Integer(10)), new Constant("2003-05-01 10:20:30")}); //$NON-NLS-1$ //$NON-NLS-2$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
- AliasSymbol as = new AliasSymbol("x", es); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("x", f, true); //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(as);
+ select.addSymbol(es);
Query query = new Query();
query.setSelect(select);
@@ -966,10 +957,9 @@
Function f = new Function("timestampadd", new Expression[] { //$NON-NLS-1$
new Constant("SQL_TSI_WEEK"), new Constant(new Integer(10)), new Constant("2003-05-01 10:20:30")}); //$NON-NLS-1$ //$NON-NLS-2$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
- AliasSymbol as = new AliasSymbol("x", es); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("x", f, true); //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(as);
+ select.addSymbol(es);
Query query = new Query();
query.setSelect(select);
@@ -987,10 +977,9 @@
Function f = new Function("timestampadd", new Expression[] { //$NON-NLS-1$
new Constant("SQL_TSI_QUARTER"), new Constant(new Integer(10)), new Constant("2003-05-01 10:20:30")}); //$NON-NLS-1$ //$NON-NLS-2$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
- AliasSymbol as = new AliasSymbol("x", es); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("x", f, true); //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(as);
+ select.addSymbol(es);
Query query = new Query();
query.setSelect(select);
@@ -1008,10 +997,9 @@
Function f = new Function("timestampadd", new Expression[] { //$NON-NLS-1$
new Constant("SQL_TSI_YEAR"), new Constant(new Integer(10)), new Constant("2003-05-01 10:20:30")}); //$NON-NLS-1$ //$NON-NLS-2$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
- AliasSymbol as = new AliasSymbol("x", es); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("x", f, true); //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(as);
+ select.addSymbol(es);
Query query = new Query();
query.setSelect(select);
@@ -1029,10 +1017,9 @@
Function f = new Function("timestampdiff", new Expression[] { //$NON-NLS-1$
new Constant("SQL_TSI_FRAC_SECOND"), new Constant("2003-05-01 10:20:10"), new Constant("2003-05-01 10:20:30")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
- AliasSymbol as = new AliasSymbol("x", es); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("x", f, true); //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(as);
+ select.addSymbol(es);
Query query = new Query();
query.setSelect(select);
@@ -1050,7 +1037,7 @@
Function f = new Function("+", new Expression[] {new Constant(new Integer(5)), new Constant(new Integer(2))}); //$NON-NLS-1$
Function f2 = new Function("+", new Expression[] {f, new Constant(new Integer(3))}); //$NON-NLS-1$
- ExpressionSymbol es = new ExpressionSymbol("expr", f2); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f2); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -1070,7 +1057,7 @@
Function f = new Function("+", new Expression[] {new Constant(new Integer(5)), new Constant(new Integer(2))}); //$NON-NLS-1$
Function f2 = new Function("-", new Expression[] {f, new Constant(new Integer(3))}); //$NON-NLS-1$
- ExpressionSymbol es = new ExpressionSymbol("expr", f2); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f2); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -1091,7 +1078,7 @@
Function f = new Function("*", new Expression[] {new Constant(new Integer(2)), new Constant(new Integer(3))}); //$NON-NLS-1$
Function f2 = new Function("+", new Expression[] {new Constant(new Integer(5)), f}); //$NON-NLS-1$
- ExpressionSymbol es = new ExpressionSymbol("expr", f2); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f2); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -1111,7 +1098,7 @@
Function f = new Function("*", new Expression[] {new Constant(new Integer(5)), new Constant(new Integer(2))}); //$NON-NLS-1$
Function f2 = new Function("+", new Expression[] {f, new Constant(new Integer(3))}); //$NON-NLS-1$
- ExpressionSymbol es = new ExpressionSymbol("expr", f2); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f2); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -1131,7 +1118,7 @@
Function f = new Function("*", new Expression[] {new Constant(new Integer(5)), new Constant(new Integer(2))}); //$NON-NLS-1$
Function f2 = new Function("*", new Expression[] {f, new Constant(new Integer(3))}); //$NON-NLS-1$
- ExpressionSymbol es = new ExpressionSymbol("expr", f2); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f2); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -1153,7 +1140,7 @@
Function f2 = new Function("*", new Expression[] {new Constant(new Integer(4)), new Constant(new Integer(5))}); //$NON-NLS-1$
Function f3 = new Function("+", new Expression[] {new Constant(new Integer(1)), f}); //$NON-NLS-1$
Function f4 = new Function("+", new Expression[] {f3, f2}); //$NON-NLS-1$
- ExpressionSymbol es = new ExpressionSymbol("expr", f4); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f4); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -1175,7 +1162,7 @@
Function f2 = new Function("*", new Expression[] {new Constant(new Integer(3)), new Constant(new Integer(4))}); //$NON-NLS-1$
Function f3 = new Function("+", new Expression[] {f, f2}); //$NON-NLS-1$
Function f4 = new Function("+", new Expression[] {f3, new Constant(new Integer(5))}); //$NON-NLS-1$
- ExpressionSymbol es = new ExpressionSymbol("expr", f4); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f4); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -1196,7 +1183,7 @@
Function f = new Function("-", new Expression[] {new Constant(new Integer(5)), new Constant(new Integer(4))}); //$NON-NLS-1$
Function f2 = new Function("-", new Expression[] {f, new Constant(new Integer(3))}); //$NON-NLS-1$
Function f3 = new Function("-", new Expression[] {f2, new Constant(new Integer(2))}); //$NON-NLS-1$
- ExpressionSymbol es = new ExpressionSymbol("expr", f3); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f3); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -1217,7 +1204,7 @@
Function f = new Function("/", new Expression[] {new Constant(new Integer(5)), new Constant(new Integer(4))}); //$NON-NLS-1$
Function f2 = new Function("/", new Expression[] {f, new Constant(new Integer(3))}); //$NON-NLS-1$
Function f3 = new Function("/", new Expression[] {f2, new Constant(new Integer(2))}); //$NON-NLS-1$
- ExpressionSymbol es = new ExpressionSymbol("expr", f3); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f3); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -1237,7 +1224,7 @@
Function f = new Function("||", new Expression[] {new Constant("a"), new Constant("b")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Function f2 = new Function("||", new Expression[] {f, new Constant("c")}); //$NON-NLS-1$ //$NON-NLS-2$
- ExpressionSymbol es = new ExpressionSymbol("expr", f2); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f2); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -1259,7 +1246,7 @@
Function f2 = new Function("+", new Expression[] {new Constant(new Integer(5)), f}); //$NON-NLS-1$
Function f3 = new Function("+", new Expression[] {new Constant(new Integer(2)), new Constant(new Integer(3))}); //$NON-NLS-1$
Function f4 = new Function("||", new Expression[] {f3, f2}); //$NON-NLS-1$
- ExpressionSymbol es = new ExpressionSymbol("expr", f4); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f4); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -1328,8 +1315,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new AliasSymbol("c", //$NON-NLS-1$
- new AggregateSymbol("c", "COUNT", false, new ElementSymbol("a", false)))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ select.addSymbol(new DerivedColumn("c", new Aggregate("COUNT", false, new ElementSymbol("a", false)), true)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Query query = new Query();
@@ -1347,8 +1333,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new AliasSymbol("c", //$NON-NLS-1$
- new AggregateSymbol("c", "COUNT", false, new ElementSymbol("a", false)))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ select.addSymbol(new DerivedColumn("c", new Aggregate("COUNT", false, new ElementSymbol("a", false)))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Query query = new Query();
@@ -1372,7 +1357,7 @@
groupBy.addSymbol(new ElementSymbol("a")); //$NON-NLS-1$
Criteria having = new CompareCriteria(
- new AggregateSymbol("count", "COUNT", false, new ElementSymbol("b", false)), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new Aggregate("COUNT", false, new ElementSymbol("b", false)), //$NON-NLS-1$ //$NON-NLS-2$
CompareCriteria.GT,
new Constant(new Integer(0)) );
@@ -1403,7 +1388,7 @@
CompoundCriteria having = new CompoundCriteria();
having.setOperator(CompoundCriteria.AND);
having.addCriteria(new CompareCriteria(
- new AggregateSymbol("count", "COUNT", false, new ElementSymbol("b", false)), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new Aggregate("COUNT", false, new ElementSymbol("b", false)), //$NON-NLS-1$ //$NON-NLS-2$
CompareCriteria.GT,
new Constant(new Integer(0)) ));
having.addCriteria(new CompareCriteria(
@@ -1459,12 +1444,11 @@
from.addGroup(g);
Select select = new Select();
- AggregateSymbol agg1 = new AggregateSymbol("count", "COUNT", false, new ElementSymbol("a", false)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- AggregateSymbol agg2 = new AggregateSymbol("sum", "SUM", false, new ElementSymbol("a", false)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Aggregate agg1 = new Aggregate("COUNT", false, new ElementSymbol("a", false)); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate agg2 = new Aggregate("SUM", false, new ElementSymbol("a", false)); //$NON-NLS-1$ //$NON-NLS-2$
Function f = new Function("*", new Expression[] { agg1, agg2 }); //$NON-NLS-1$
- ExpressionSymbol expr = new ExpressionSymbol("expr", f); //$NON-NLS-1$
- AliasSymbol alias = new AliasSymbol("c", expr); //$NON-NLS-1$
- select.addSymbol(alias);
+ DerivedColumn expr = new DerivedColumn("c", f, true); //$NON-NLS-1$
+ select.addSymbol(expr);
Query query = new Query();
query.setSelect(select);
@@ -1482,7 +1466,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol(
+ select.addSymbol(new DerivedColumn(
"expr", //$NON-NLS-1$
new Function("-", new Expression[] { new Constant(new Integer(5)), new Constant(null) }) ) ); //$NON-NLS-1$
select.addSymbol(new ElementSymbol("a.g1.c1")); //$NON-NLS-1$
@@ -1503,7 +1487,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant("abc"))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("expr", new Constant("abc"))); //$NON-NLS-1$ //$NON-NLS-2$
Query query = new Query();
query.setSelect(select);
@@ -1522,7 +1506,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant("O'Leary"))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("expr", new Constant("O'Leary"))); //$NON-NLS-1$ //$NON-NLS-2$
Query query = new Query();
query.setSelect(select);
@@ -1540,7 +1524,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant("'abc'"))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("expr", new Constant("'abc'"))); //$NON-NLS-1$ //$NON-NLS-2$
Query query = new Query();
query.setSelect(select);
@@ -1558,7 +1542,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant("a'b'c"))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("expr", new Constant("a'b'c"))); //$NON-NLS-1$ //$NON-NLS-2$
Query query = new Query();
query.setSelect(select);
@@ -1576,7 +1560,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant(" \" "))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("expr", new Constant(" \" "))); //$NON-NLS-1$ //$NON-NLS-2$
Query query = new Query();
query.setSelect(select);
@@ -1594,7 +1578,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant(new Long(123456789012L)))); //$NON-NLS-1$
+ select.addSymbol(new DerivedColumn("expr", new Constant(new Long(123456789012L)))); //$NON-NLS-1$
Query query = new Query();
query.setSelect(select);
@@ -1612,7 +1596,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant(new BigInteger("1000000000000000000000000")))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("expr", new Constant(new BigInteger("1000000000000000000000000")))); //$NON-NLS-1$ //$NON-NLS-2$
Query query = new Query();
query.setSelect(select);
@@ -1630,7 +1614,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant(new Double(1.3e8)))); //$NON-NLS-1$
+ select.addSymbol(new DerivedColumn("expr", new Constant(new Double(1.3e8)))); //$NON-NLS-1$
Query query = new Query();
query.setSelect(select);
@@ -1648,7 +1632,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant(new Double(-1.3e-6)))); //$NON-NLS-1$
+ select.addSymbol(new DerivedColumn("expr", new Constant(new Double(-1.3e-6)))); //$NON-NLS-1$
Query query = new Query();
query.setSelect(select);
@@ -1666,7 +1650,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant(new Double(-1.3e+8)))); //$NON-NLS-1$
+ select.addSymbol(new DerivedColumn("expr", new Constant(new Double(-1.3e+8)))); //$NON-NLS-1$
Query query = new Query();
query.setSelect(select);
@@ -1684,7 +1668,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant(java.sql.Date.valueOf("2002-10-02")))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("expr", new Constant(java.sql.Date.valueOf("2002-10-02")))); //$NON-NLS-1$ //$NON-NLS-2$
Query query = new Query();
query.setSelect(select);
@@ -1702,7 +1686,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant(java.sql.Date.valueOf("2002-09-01")))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("expr", new Constant(java.sql.Date.valueOf("2002-09-01")))); //$NON-NLS-1$ //$NON-NLS-2$
Query query = new Query();
query.setSelect(select);
@@ -1725,7 +1709,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant(java.sql.Time.valueOf("11:10:00")))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("expr", new Constant(java.sql.Time.valueOf("11:10:00")))); //$NON-NLS-1$ //$NON-NLS-2$
Query query = new Query();
query.setSelect(select);
@@ -1743,7 +1727,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant(java.sql.Time.valueOf("5:10:00")))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("expr", new Constant(java.sql.Time.valueOf("5:10:00")))); //$NON-NLS-1$ //$NON-NLS-2$
Query query = new Query();
query.setSelect(select);
@@ -1766,7 +1750,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant(java.sql.Timestamp.valueOf("2002-10-02 19:00:02.50")))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("expr", new Constant(java.sql.Timestamp.valueOf("2002-10-02 19:00:02.50")))); //$NON-NLS-1$ //$NON-NLS-2$
Query query = new Query();
query.setSelect(select);
@@ -1784,7 +1768,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant(Boolean.valueOf("true")))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("expr", new Constant(Boolean.valueOf("true")))); //$NON-NLS-1$ //$NON-NLS-2$
Query query = new Query();
query.setSelect(select);
@@ -1801,7 +1785,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant(Boolean.valueOf("true")))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("expr", new Constant(Boolean.valueOf("true")))); //$NON-NLS-1$ //$NON-NLS-2$
Query query = new Query();
query.setSelect(select);
@@ -1819,7 +1803,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant(Boolean.valueOf("false")))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("expr", new Constant(Boolean.valueOf("false")))); //$NON-NLS-1$ //$NON-NLS-2$
Query query = new Query();
query.setSelect(select);
@@ -1837,7 +1821,7 @@
from.addGroup(g);
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", new Constant(Boolean.valueOf("false")))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("expr", new Constant(Boolean.valueOf("false")))); //$NON-NLS-1$ //$NON-NLS-2$
Query query = new Query();
query.setSelect(select);
@@ -1897,7 +1881,7 @@
From from = new From();
from.addGroup(g);
- AliasSymbol as = new AliasSymbol("myA", new ElementSymbol("a")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn as = new DerivedColumn("myA", new ElementSymbol("a"), true); //$NON-NLS-1$ //$NON-NLS-2$
Select select = new Select();
select.addSymbol(as);
select.addSymbol(new ElementSymbol("b")); //$NON-NLS-1$
@@ -1918,7 +1902,7 @@
from.addGroup(g);
from.addGroup(h);
- AliasSymbol as = new AliasSymbol("myA", new ElementSymbol("a")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn as = new DerivedColumn("myA", new ElementSymbol("a"), true); //$NON-NLS-1$ //$NON-NLS-2$
Select select = new Select();
select.addSymbol(as);
select.addSymbol(new ElementSymbol("b")); //$NON-NLS-1$
@@ -2216,7 +2200,7 @@
from.addGroup(g);
Select select = new Select();
- ExpressionSymbol a = new ExpressionSymbol("expr", new Constant("g\".\"a")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn a = new DerivedColumn("expr", new Constant("g\".\"a")); //$NON-NLS-1$ //$NON-NLS-2$
select.addSymbol(a);
Query query = new Query();
@@ -2235,7 +2219,7 @@
from.addGroup(g);
Select select = new Select();
- AliasSymbol a = new AliasSymbol("select", new ElementSymbol("g.x")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn a = new DerivedColumn("select", new ElementSymbol("g.x"), true); //$NON-NLS-1$ //$NON-NLS-2$
select.addSymbol(a);
Query query = new Query();
@@ -2254,7 +2238,7 @@
from.addGroup(g);
Select select = new Select();
- AliasSymbol a = new AliasSymbol("year", new ElementSymbol("g.x")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn a = new DerivedColumn("year", new ElementSymbol("g.x"), true); //$NON-NLS-1$ //$NON-NLS-2$
select.addSymbol(a);
Query query = new Query();
@@ -2652,11 +2636,8 @@
Criteria crit = new CompareCriteria(new ElementSymbol("b"), CompareCriteria.EQ, new ElementSymbol("aString")); //$NON-NLS-1$ //$NON-NLS-2$
- ArrayList elements = new ArrayList();
- elements.add(new ElementSymbol("c")); //$NON-NLS-1$
- ArrayList orderTypes = new ArrayList();
- orderTypes.add(Boolean.FALSE);
- OrderBy orderBy = new OrderBy(elements, orderTypes);
+ OrderBy orderBy = new OrderBy();
+ orderBy.addItem(new OrderByItem(new ElementSymbol("c"), OrderSpecification.DESC)); //$NON-NLS-1$
Query query = new Query(select, from, crit, orderBy, null);
helpTest("SELECT a FROM db.g WHERE b = aString ORDER BY c desc", //$NON-NLS-1$
@@ -2699,13 +2680,9 @@
Criteria crit = new CompareCriteria(new ElementSymbol("b"), CompareCriteria.EQ, new ElementSymbol("aString")); //$NON-NLS-1$ //$NON-NLS-2$
- ArrayList elements = new ArrayList();
- elements.add(new ElementSymbol("c")); //$NON-NLS-1$
- elements.add(new ElementSymbol("d")); //$NON-NLS-1$
- ArrayList orderTypes = new ArrayList();
- orderTypes.add(Boolean.FALSE);
- orderTypes.add(Boolean.FALSE);
- OrderBy orderBy = new OrderBy(elements, orderTypes);
+ OrderBy orderBy = new OrderBy();
+ orderBy.addItem(new OrderByItem(new ElementSymbol("c"), OrderSpecification.DESC)); //$NON-NLS-1$
+ orderBy.addItem(new OrderByItem(new ElementSymbol("d"), OrderSpecification.DESC)); //$NON-NLS-1$
Query query = new Query(select, from, crit, orderBy, null);
helpTest("SELECT a FROM db.g WHERE b = aString ORDER BY c desc,d desc", //$NON-NLS-1$
@@ -2725,13 +2702,9 @@
Criteria crit = new CompareCriteria(new ElementSymbol("b"), CompareCriteria.EQ, new ElementSymbol("aString")); //$NON-NLS-1$ //$NON-NLS-2$
- ArrayList elements = new ArrayList();
- elements.add(new ElementSymbol("c")); //$NON-NLS-1$
- elements.add(new ElementSymbol("d")); //$NON-NLS-1$
- ArrayList orderTypes = new ArrayList();
- orderTypes.add(Boolean.FALSE);
- orderTypes.add(Boolean.TRUE);
- OrderBy orderBy = new OrderBy(elements, orderTypes);
+ OrderBy orderBy = new OrderBy();
+ orderBy.addItem(new OrderByItem(new ElementSymbol("c"), OrderSpecification.DESC)); //$NON-NLS-1$
+ orderBy.addItem(new OrderByItem(new ElementSymbol("d"), OrderSpecification.ASC)); //$NON-NLS-1$
Query query = new Query(select, from, crit, orderBy, null);
helpTest("SELECT a FROM db.g WHERE b = aString ORDER BY c desc,d", //$NON-NLS-1$
@@ -2939,7 +2912,7 @@
public void testNoFromClause(){
Select select = new Select();
ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
- ExpressionSymbol b = new ExpressionSymbol("expr", new Constant(new Integer(5), Integer.class)); //$NON-NLS-1$
+ DerivedColumn b = new DerivedColumn("expr", new Constant(new Integer(5), Integer.class)); //$NON-NLS-1$
select.addSymbol(a);
select.addSymbol(b);
Query query = new Query();
@@ -3048,7 +3021,7 @@
Select select = new Select();
Reference ref0 = new Reference(0);
- ExpressionSymbol expr = new ExpressionSymbol("expr", ref0); //$NON-NLS-1$
+ DerivedColumn expr = new DerivedColumn("expr", ref0); //$NON-NLS-1$
select.addSymbol(expr);
Reference ref1 = new Reference(1);
@@ -5333,7 +5306,7 @@
Query query = new Query();
Select select = new Select();
Constant c = new Constant("\u05e0"); //$NON-NLS-1$
- select.addSymbol(new ExpressionSymbol("expr", c)); //$NON-NLS-1$
+ select.addSymbol(new DerivedColumn("expr", c)); //$NON-NLS-1$
query.setSelect(select);
helpTest(sql, query.toString(), query);
@@ -5433,7 +5406,7 @@
Query query = new Query();
Select select = new Select();
Function func1 = new Function("yowza_yowza", new Expression[] { }); //$NON-NLS-1$
- ExpressionSymbol exprSymbol = new ExpressionSymbol("expr", func1); //$NON-NLS-1$
+ DerivedColumn exprSymbol = new DerivedColumn("expr", func1); //$NON-NLS-1$
select.addSymbol(exprSymbol);
query.setSelect(select);
@@ -5733,7 +5706,7 @@
Select s2 = new Select();
s2.addSymbol(new ElementSymbol("e1")); //$NON-NLS-1$
- s2.addSymbol(new ExpressionSymbol("expr", new ScalarSubquery(q1))); //$NON-NLS-1$
+ s2.addSymbol(new DerivedColumn("expr", new ScalarSubquery(q1))); //$NON-NLS-1$
From f2 = new From();
f2.addGroup(new GroupSymbol("m.g2")); //$NON-NLS-1$
Query q2 = new Query();
@@ -5756,7 +5729,7 @@
q1.setFrom(f1);
Select s2 = new Select();
- s2.addSymbol(new ExpressionSymbol("expr", new ScalarSubquery(q1))); //$NON-NLS-1$
+ s2.addSymbol(new DerivedColumn("expr", new ScalarSubquery(q1))); //$NON-NLS-1$
From f2 = new From();
f2.addGroup(new GroupSymbol("m.g2")); //$NON-NLS-1$
Query q2 = new Query();
@@ -5779,7 +5752,7 @@
q1.setFrom(f1);
Select s2 = new Select();
- s2.addSymbol(new ExpressionSymbol("expr", new ScalarSubquery(q1))); //$NON-NLS-1$
+ s2.addSymbol(new DerivedColumn("expr", new ScalarSubquery(q1))); //$NON-NLS-1$
s2.addSymbol(new ElementSymbol("e1")); //$NON-NLS-1$
From f2 = new From();
f2.addGroup(new GroupSymbol("m.g2")); //$NON-NLS-1$
@@ -5804,7 +5777,7 @@
Select s2 = new Select();
s2.addSymbol(new ElementSymbol("e1")); //$NON-NLS-1$
- s2.addSymbol(new AliasSymbol("X", new ExpressionSymbol("expr", new ScalarSubquery(q1)))); //$NON-NLS-1$ //$NON-NLS-2$
+ s2.addSymbol(new DerivedColumn("X", new ScalarSubquery(q1), true)); //$NON-NLS-1$
From f2 = new From();
f2.addGroup(new GroupSymbol("m.g2")); //$NON-NLS-1$
Query q2 = new Query();
@@ -5820,7 +5793,7 @@
Select s2 = new Select();
s2.addSymbol(new ElementSymbol("e1")); //$NON-NLS-1$
- s2.addSymbol(new AliasSymbol("X", new ExpressionSymbol("expr", QueryParser.getQueryParser().parseExpression("(SELECT e1 FROM m.g1) + 2")))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ s2.addSymbol(new DerivedColumn("X", QueryParser.getQueryParser().parseExpression("(SELECT e1 FROM m.g1) + 2"), true)); //$NON-NLS-1$ //$NON-NLS-2$
From f2 = new From();
f2.addGroup(new GroupSymbol("m.g2")); //$NON-NLS-1$
@@ -5837,7 +5810,7 @@
Select s2 = new Select();
s2.addSymbol(new ElementSymbol("e1")); //$NON-NLS-1$
- s2.addSymbol(new AliasSymbol("X", new ExpressionSymbol("expr", QueryParser.getQueryParser().parseExpression("3 + (SELECT e1 FROM m.g1)")))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ s2.addSymbol(new DerivedColumn("X", QueryParser.getQueryParser().parseExpression("3 + (SELECT e1 FROM m.g1)"), true)); //$NON-NLS-1$ //$NON-NLS-2$
From f2 = new From();
f2.addGroup(new GroupSymbol("m.g2")); //$NON-NLS-1$
@@ -5854,7 +5827,7 @@
Select s2 = new Select();
s2.addSymbol(new ElementSymbol("e1")); //$NON-NLS-1$
- s2.addSymbol(new AliasSymbol("X", new ExpressionSymbol("expr", QueryParser.getQueryParser().parseExpression("(SELECT e1 FROM m.g1) + (SELECT e3 FROM m.g3)")))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ s2.addSymbol(new DerivedColumn("X", QueryParser.getQueryParser().parseExpression("(SELECT e1 FROM m.g1) + (SELECT e3 FROM m.g3)"), true)); //$NON-NLS-1$ //$NON-NLS-2$
From f2 = new From();
f2.addGroup(new GroupSymbol("m.g2")); //$NON-NLS-1$
@@ -5871,7 +5844,7 @@
Select s2 = new Select();
s2.addSymbol(new ElementSymbol("e1")); //$NON-NLS-1$
- s2.addSymbol(new AliasSymbol("X", new ExpressionSymbol("expr", QueryParser.getQueryParser().getQueryParser().parseExpression("length((SELECT e1 FROM m.g1))")))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ s2.addSymbol(new DerivedColumn("X", QueryParser.getQueryParser().getQueryParser().parseExpression("length((SELECT e1 FROM m.g1))"), true)); //$NON-NLS-1$ //$NON-NLS-2$
From f2 = new From();
f2.addGroup(new GroupSymbol("m.g2")); //$NON-NLS-1$
@@ -6043,7 +6016,7 @@
select.addSymbol(new ElementSymbol("y")); //$NON-NLS-1$
select.addSymbol(new ElementSymbol("z")); //$NON-NLS-1$
// The parser hard-codes the name "expr"
- select.addSymbol(new ExpressionSymbol("expr", expr)); //$NON-NLS-1$
+ select.addSymbol(new DerivedColumn("expr", expr)); //$NON-NLS-1$
From from = new From();
from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
Query q = new Query();
@@ -6070,7 +6043,7 @@
select.addSymbol(new ElementSymbol("y")); //$NON-NLS-1$
select.addSymbol(new ElementSymbol("z")); //$NON-NLS-1$
// The parser hard-codes the name "expr"
- select.addSymbol(new ExpressionSymbol("expr", expr)); //$NON-NLS-1$
+ select.addSymbol(new DerivedColumn("expr", expr)); //$NON-NLS-1$
From from = new From();
from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
Query q = new Query();
@@ -6118,7 +6091,7 @@
select.addSymbol(new ElementSymbol("y")); //$NON-NLS-1$
select.addSymbol(new ElementSymbol("z")); //$NON-NLS-1$
// The parser hard-codes the name "expr"
- select.addSymbol(new ExpressionSymbol("expr", expr)); //$NON-NLS-1$
+ select.addSymbol(new DerivedColumn("expr", expr)); //$NON-NLS-1$
From from = new From();
from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
Query q = new Query();
@@ -6144,7 +6117,7 @@
select.addSymbol(new ElementSymbol("y")); //$NON-NLS-1$
select.addSymbol(new ElementSymbol("z")); //$NON-NLS-1$
// The parser hard-codes the name "expr"
- select.addSymbol(new ExpressionSymbol("expr", expr)); //$NON-NLS-1$
+ select.addSymbol(new DerivedColumn("expr", expr)); //$NON-NLS-1$
From from = new From();
from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
Query q = new Query();
@@ -6299,7 +6272,7 @@
public void testNationCharString() throws Exception {
Query query = (Query) QueryParser.getQueryParser().parseCommand("SELECT N'blah' FROM m.g"); //$NON-NLS-1$
Select select = query.getSelect();
- ExpressionSymbol s = (ExpressionSymbol) select.getSymbol(0);
+ DerivedColumn s = (DerivedColumn) select.getSymbol(0);
Constant c = (Constant) s.getExpression();
assertEquals(c, new Constant("blah")); //$NON-NLS-1$
}
@@ -6383,7 +6356,7 @@
From from = new From();
from.addGroup(g);
- AliasSymbol as = new AliasSymbol("fooAlias", new ElementSymbol("fooKey")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn as = new DerivedColumn("fooAlias", new ElementSymbol("fooKey"), true); //$NON-NLS-1$ //$NON-NLS-2$
Select select = new Select();
select.addSymbol(as);
@@ -6402,7 +6375,7 @@
From from = new From();
from.addGroup(g);
- AliasSymbol as = new AliasSymbol("fooAlias", new ElementSymbol("fooKey")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn as = new DerivedColumn("fooAlias", new ElementSymbol("fooKey"), true); //$NON-NLS-1$ //$NON-NLS-2$
Select select = new Select();
select.addSymbol(as);
@@ -6428,7 +6401,7 @@
Constant as = new Constant("fooString"); //$NON-NLS-1$
Select select = new Select();
- select.addSymbol(new ExpressionSymbol("expr", as)); //$NON-NLS-1$
+ select.addSymbol(new DerivedColumn("expr", as)); //$NON-NLS-1$
Query query = new Query();
query.setSelect(select);
@@ -6445,7 +6418,7 @@
From from = new From();
from.addGroup(g);
- AliasSymbol as = new AliasSymbol("fooAlias", new ElementSymbol("fooKey")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn as = new DerivedColumn("fooAlias", new ElementSymbol("fooKey"), true); //$NON-NLS-1$ //$NON-NLS-2$
Select select = new Select();
select.addSymbol(as);
@@ -6464,7 +6437,7 @@
From from = new From();
from.addGroup(g);
- AliasSymbol as = new AliasSymbol("fooAlias", new ElementSymbol("fooKey")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn as = new DerivedColumn("fooAlias", new ElementSymbol("fooKey"), true); //$NON-NLS-1$ //$NON-NLS-2$
Select select = new Select();
select.addSymbol(as);
@@ -6501,7 +6474,7 @@
Select select = new Select();
select.addSymbol(new ElementSymbol("x.y.z.fooKey")); //$NON-NLS-1$
- AliasSymbol alias = new AliasSymbol("key", new ElementSymbol("x.y.z.key2")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn alias = new DerivedColumn("key", new ElementSymbol("x.y.z.key2"), true); //$NON-NLS-1$ //$NON-NLS-2$
select.addSymbol(alias);
Criteria crit = new CompareCriteria(new ElementSymbol("x.y.z.fooKey"), SubqueryCompareCriteria.GT, new Constant(new Integer(10))); //$NON-NLS-1$
@@ -6604,7 +6577,7 @@
from.addGroup(g);
Function f = new Function("+", new Expression[] {new ElementSymbol("x"), new ElementSymbol("y")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -6625,7 +6598,7 @@
from.addGroup(g);
Function f = new Function("concat", new Expression[] {new ElementSymbol("x", false), new Constant("5")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- ExpressionSymbol es = new ExpressionSymbol("expr", f); //$NON-NLS-1$
+ DerivedColumn es = new DerivedColumn("expr", f); //$NON-NLS-1$
Select select = new Select();
select.addSymbol(es);
@@ -6734,7 +6707,7 @@
public void testLimit() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new Object[] {new AllSymbol()}));
+ Select select = new Select(Arrays.asList(new AllSymbol()));
From from = new From(Arrays.asList(new Object[] {new UnaryFromClause(new GroupSymbol("a"))})); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -6745,7 +6718,7 @@
public void testLimitWithOffset() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new Object[] {new AllSymbol()}));
+ Select select = new Select(Arrays.asList(new AllSymbol()));
From from = new From(Arrays.asList(new Object[] {new UnaryFromClause(new GroupSymbol("a"))})); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -6755,7 +6728,7 @@
public void testLimitWithReferences1() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new Object[] {new AllSymbol()}));
+ Select select = new Select(Arrays.asList(new AllSymbol()));
From from = new From(Arrays.asList(new Object[] {new UnaryFromClause(new GroupSymbol("a"))})); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -6765,7 +6738,7 @@
public void testLimitWithReferences2() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new Object[] {new AllSymbol()}));
+ Select select = new Select(Arrays.asList(new AllSymbol()));
From from = new From(Arrays.asList(new Object[] {new UnaryFromClause(new GroupSymbol("a"))})); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -6775,7 +6748,7 @@
public void testLimitWithReferences3() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new Object[] {new AllSymbol()}));
+ Select select = new Select(Arrays.asList(new AllSymbol()));
From from = new From(Arrays.asList(new Object[] {new UnaryFromClause(new GroupSymbol("a"))})); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -6899,7 +6872,7 @@
String expected = "CREATE PROCEDURE\nBEGIN\nIF(x > 1)\nBEGIN\nSELECT 1;\nEND\nIF(x > 1)\nBEGIN\nSELECT 1;\nEND\nELSE\nBEGIN\nSELECT 1;\nEND\nEND"; //$NON-NLS-1$
Query query = new Query();
- query.setSelect(new Select(Arrays.asList(new Object[] {new ExpressionSymbol("expr", new Constant(new Integer(1)))}))); //$NON-NLS-1$
+ query.setSelect(new Select(Arrays.asList(new DerivedColumn("expr", new Constant(new Integer(1)))))); //$NON-NLS-1$
CommandStatement commandStmt = new CommandStatement(query);
CompareCriteria criteria = new CompareCriteria(new ElementSymbol("x"), CompareCriteria.GT, new Constant(new Integer(1))); //$NON-NLS-1$
Block block = new Block();
@@ -6929,7 +6902,7 @@
Function convert = new Function("convert", new Expression[] {new Constant(null), new Constant("blob")}); //$NON-NLS-1$ //$NON-NLS-2$
Function convert1 = new Function("convert", new Expression[] {new Constant(null), new Constant("clob")}); //$NON-NLS-1$ //$NON-NLS-2$
Function convert2 = new Function("convert", new Expression[] {new Constant(null), new Constant("xml")}); //$NON-NLS-1$ //$NON-NLS-2$
- Select select = new Select(Arrays.asList(new Object[] {new ExpressionSymbol("expr", convert), new ExpressionSymbol("expr1", convert1), new ExpressionSymbol("expr2", convert2)})); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Select select = new Select(Arrays.asList(new DerivedColumn("expr", convert), new DerivedColumn("expr1", convert1), new DerivedColumn("expr2", convert2))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Query query = new Query();
query.setSelect(select);
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/eval/TestExpressionEvaluator.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -49,7 +49,7 @@
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.SPParameter;
import com.metamatrix.query.sql.lang.StoredProcedure;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
@@ -462,8 +462,8 @@
HashMap map = new HashMap();
map.put(x, y);
- AggregateSymbol countStar = new AggregateSymbol("agg1", ReservedWords.COUNT, false, null); //$NON-NLS-1$ //$NON-NLS-2$
- AggregateSymbol countStar1 = new AggregateSymbol("agg1", ReservedWords.COUNT, false, null); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate countStar = new Aggregate(ReservedWords.COUNT, false, null); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate countStar1 = new Aggregate(ReservedWords.COUNT, false, null); //$NON-NLS-1$ //$NON-NLS-2$
EvaluateExpressionVisitor.replaceExpressions(countStar, true, null, null);
assertEquals(countStar1, countStar);
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/relational/TestGroupingNode.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/relational/TestGroupingNode.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/relational/TestGroupingNode.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -44,7 +44,7 @@
import com.metamatrix.query.function.FunctionLibraryManager;
import com.metamatrix.query.processor.FakeDataManager;
import com.metamatrix.query.processor.FakeTupleSource;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
@@ -142,17 +142,17 @@
ElementSymbol col2 = new ElementSymbol("col2"); //$NON-NLS-1$
col2.setType(Integer.class);
outputElements.add(col1);
- outputElements.add(new AggregateSymbol("countAll", "COUNT", false, null)); //$NON-NLS-1$ //$NON-NLS-2$
- outputElements.add(new AggregateSymbol("count", "COUNT", false, col2)); //$NON-NLS-1$ //$NON-NLS-2$
- outputElements.add(new AggregateSymbol("countDist", "COUNT", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$
- outputElements.add(new AggregateSymbol("sum", "SUM", false, col2)); //$NON-NLS-1$ //$NON-NLS-2$
- outputElements.add(new AggregateSymbol("sumDist", "SUM", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$
- outputElements.add(new AggregateSymbol("avg", "AVG", false, col2)); //$NON-NLS-1$ //$NON-NLS-2$
- outputElements.add(new AggregateSymbol("avgDist", "AVG", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$
- outputElements.add(new AggregateSymbol("min", "MIN", false, col2)); //$NON-NLS-1$ //$NON-NLS-2$
- outputElements.add(new AggregateSymbol("minDist", "MIN", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$
- outputElements.add(new AggregateSymbol("max", "MAX", false, col2)); //$NON-NLS-1$ //$NON-NLS-2$
- outputElements.add(new AggregateSymbol("maxDist", "MAX", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("COUNT", false, null)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("COUNT", false, col2)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("COUNT", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("SUM", false, col2)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("SUM", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("AVG", false, col2)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("AVG", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("MIN", false, col2)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("MIN", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("MAX", false, col2)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("MAX", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$
node.setElements(outputElements);
List groupingElements = new ArrayList();
@@ -186,7 +186,7 @@
ElementSymbol col2 = new ElementSymbol("col2"); //$NON-NLS-1$
col2.setType(Integer.class);
outputElements.add(col1);
- outputElements.add(new AggregateSymbol("countDist", "COUNT", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("COUNT", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$
node.setElements(outputElements);
List groupingElements = new ArrayList();
@@ -222,7 +222,7 @@
ElementSymbol col2 = new ElementSymbol("col2"); //$NON-NLS-1$
col2.setType(Integer.class);
outputElements.add(col1);
- outputElements.add(new AggregateSymbol("countDist", "COUNT", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("COUNT", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$
node.setElements(outputElements);
List groupingElements = new ArrayList();
@@ -254,8 +254,8 @@
// Set up
GroupingNode node = new GroupingNode(1);
List outputElements = new ArrayList();
- outputElements.add(new AggregateSymbol("bigSum", "SUM", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$
- outputElements.add(new AggregateSymbol("bigAvg", "AVG", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("SUM", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("AVG", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$
node.setElements(outputElements);
// Set grouping elements to null
@@ -293,8 +293,8 @@
GroupingNode node = new GroupingNode(1);
List outputElements = new ArrayList();
outputElements.add(col1);
- outputElements.add(new AggregateSymbol("bigSum", "SUM", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$
- outputElements.add(new AggregateSymbol("bigAvg", "AVG", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("SUM", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("AVG", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$
node.setElements(outputElements);
// Set grouping elements to null
@@ -342,9 +342,9 @@
func.setType(DataTypeManager.DefaultDataClasses.INTEGER);
outputElements.add(col1);
- outputElements.add(new AggregateSymbol("count", "COUNT", false, func)); //$NON-NLS-1$ //$NON-NLS-2$
- outputElements.add(new AggregateSymbol("sum", "SUM", false, func)); //$NON-NLS-1$ //$NON-NLS-2$
- outputElements.add(new AggregateSymbol("sumDist", "SUM", true, func)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("COUNT", false, func)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("SUM", false, func)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("SUM", true, func)); //$NON-NLS-1$ //$NON-NLS-2$
node.setElements(outputElements);
List groupingElements = new ArrayList();
@@ -389,8 +389,8 @@
// Set up
GroupingNode node = new GroupingNode(1);
List outputElements = new ArrayList();
- outputElements.add(new AggregateSymbol("bigSum", "SUM", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$
- outputElements.add(new AggregateSymbol("bigAvg", "AVG", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("SUM", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$
+ outputElements.add(new Aggregate("AVG", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$
node.setElements(outputElements);
// Set grouping elements to null
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectNode.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectNode.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectNode.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -45,7 +45,7 @@
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.util.CommandContext;
@@ -214,7 +214,7 @@
FunctionDescriptor fd = FunctionLibraryManager.getFunctionLibrary().findFunction("concat", new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.STRING }); //$NON-NLS-1$
func.setFunctionDescriptor(fd);
func.setType(DataTypeManager.DefaultDataClasses.STRING);
- ExpressionSymbol expr = new ExpressionSymbol("expr", func); //$NON-NLS-1$
+ DerivedColumn expr = new DerivedColumn("expr", func); //$NON-NLS-1$
List projectElements = new ArrayList();
projectElements.add(expr);
@@ -238,7 +238,7 @@
FunctionDescriptor fd = FunctionLibraryManager.getFunctionLibrary().findFunction("convert", new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.STRING }); //$NON-NLS-1$
func.setFunctionDescriptor(fd);
func.setType(DataTypeManager.DefaultDataClasses.INTEGER);
- ExpressionSymbol expr = new ExpressionSymbol("expr", func); //$NON-NLS-1$
+ DerivedColumn expr = new DerivedColumn("expr", func); //$NON-NLS-1$
List projectElements = new ArrayList();
projectElements.add(expr);
@@ -262,7 +262,7 @@
func.setFunctionDescriptor(desc);
func.setType(DataTypeManager.DefaultDataClasses.STRING);
- ExpressionSymbol expr = new ExpressionSymbol("expr", func); //$NON-NLS-1$
+ DerivedColumn expr = new DerivedColumn("expr", func); //$NON-NLS-1$
List projectElements = new ArrayList();
projectElements.add(expr);
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -86,13 +86,13 @@
import com.metamatrix.query.sql.proc.CreateUpdateProcedureCommand;
import com.metamatrix.query.sql.proc.LoopStatement;
import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
import com.metamatrix.query.sql.symbol.SelectSymbol;
-import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
import com.metamatrix.query.sql.visitor.FunctionCollectorVisitor;
import com.metamatrix.query.sql.visitor.GroupCollectorVisitor;
@@ -2549,10 +2549,10 @@
new String[] { "PM1.G1.E2", "PM1.G1.E3" } ); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("Resolved string form was incorrect ", sql, resolvedQuery.toString()); //$NON-NLS-1$
- List projSymbols = resolvedQuery.getSelect().getProjectedSymbols();
+ List<DerivedColumn> projSymbols = resolvedQuery.getSelect().getProjectedSymbols();
assertEquals("Wrong number of projected symbols", 2, projSymbols.size()); //$NON-NLS-1$
- assertEquals("Wrong type for first symbol", String.class, ((SingleElementSymbol)projSymbols.get(0)).getType()); //$NON-NLS-1$
- assertEquals("Wrong type for second symbol", Double.class, ((SingleElementSymbol)projSymbols.get(1)).getType()); //$NON-NLS-1$
+ assertEquals("Wrong type for first symbol", String.class, (projSymbols.get(0)).getType()); //$NON-NLS-1$
+ assertEquals("Wrong type for second symbol", Double.class, (projSymbols.get(1)).getType()); //$NON-NLS-1$
}
public void testLookupFunctionFailBadElement() {
@@ -3183,7 +3183,7 @@
public void testNestedUnionQueryWithNull() throws Exception{
SetQuery command = (SetQuery)helpResolve("SELECT e2, e3 FROM pm1.g1 UNION (SELECT null, e3 FROM pm1.g2 UNION SELECT null, e3 from pm1.g1)"); //$NON-NLS-1$
- assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, ((SingleElementSymbol)command.getProjectedSymbols().get(0)).getType());
+ assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, (command.getProjectedSymbols().get(0)).getType());
}
public void testSelectIntoNoFrom() {
@@ -3502,7 +3502,7 @@
QueryResolver.resolveCommand(query, FakeMetadataFactory.exampleBQTCached(), AnalysisRecord.createNonRecordingRecord());
// Check type of resolved null constant
- SingleElementSymbol symbol = (SingleElementSymbol) query.getSelect().getSymbols().get(0);
+ DerivedColumn symbol = query.getProjectedSymbols().get(0);
assertNotNull(symbol.getType());
assertEquals(DataTypeManager.DefaultDataClasses.STRING, symbol.getType());
}
@@ -3765,9 +3765,9 @@
}
private void verifyProjectedTypes(Command c, Class[] types) {
- List projSymbols = c.getProjectedSymbols();
+ List<DerivedColumn> projSymbols = c.getProjectedSymbols();
for(int i=0; i<projSymbols.size(); i++) {
- assertEquals("Found type mismatch at column " + i, types[i], ((SingleElementSymbol) projSymbols.get(i)).getType()); //$NON-NLS-1$
+ assertEquals("Found type mismatch at column " + i, types[i], projSymbols.get(i).getType()); //$NON-NLS-1$
}
}
@@ -4614,21 +4614,21 @@
public void testReferenceInSelect() {
String sql = "select ?, e1 from pm1.g1"; //$NON-NLS-1$
Query command = (Query)helpResolve(sql, FakeMetadataFactory.example1Cached(), null);
- assertEquals(DataTypeManager.DefaultDataClasses.STRING, ((SingleElementSymbol)command.getProjectedSymbols().get(0)).getType());
+ assertEquals(DataTypeManager.DefaultDataClasses.STRING, (command.getProjectedSymbols().get(0)).getType());
}
public void testReferenceInSelect1() {
String sql = "select convert(?, integer), e1 from pm1.g1"; //$NON-NLS-1$
Query command = (Query)helpResolve(sql, FakeMetadataFactory.example1Cached(), null);
- assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, ((SingleElementSymbol)command.getProjectedSymbols().get(0)).getType());
+ assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, (command.getProjectedSymbols().get(0)).getType());
}
public void testUnionWithObjectTypeConversion() {
String sql = "select convert(null, xml) from pm1.g1 union all select 1"; //$NON-NLS-1$
SetQuery query = (SetQuery)helpResolve(sql, FakeMetadataFactory.example1Cached(), null);
- assertEquals(DataTypeManager.DefaultDataClasses.OBJECT, ((SingleElementSymbol)query.getProjectedSymbols().get(0)).getType());
+ assertEquals(DataTypeManager.DefaultDataClasses.OBJECT, (query.getProjectedSymbols().get(0)).getType());
}
public void testUnionWithSubQuery() {
@@ -4648,7 +4648,7 @@
private void helpTestOrderBy(OrderBy orderBy, int[] expectedPositions) {
assertEquals(expectedPositions.length, orderBy.getVariableCount());
for (int i = 0; i < expectedPositions.length; i++) {
- ElementSymbol symbol = (ElementSymbol)orderBy.getVariable(i);
+ ElementSymbol symbol = (ElementSymbol)orderBy.getSortOrder().get(0).getSortKey();
TempMetadataID tid = (TempMetadataID)symbol.getMetadataID();
assertEquals(expectedPositions[i], tid.getPosition());
}
@@ -4672,7 +4672,7 @@
}
public void testSPOutParamWithExec() {
- StoredProcedure proc = (StoredProcedure)helpResolve("exec pm2.spTest8(1)", FakeMetadataFactory.exampleBQTCached(), null);
+ StoredProcedure proc = (StoredProcedure)helpResolve("exec pm2.spTest8(1)", FakeMetadataFactory.exampleBQTCached(), null); //$NON-NLS-1$
assertEquals(2, proc.getProjectedSymbols().size());
}
@@ -4681,17 +4681,17 @@
* That hack is handled by the PreparedStatementRequest
*/
public void testSPOutParamWithCallableStatement() {
- StoredProcedure proc = (StoredProcedure)helpResolve("{call pm2.spTest8(1)}", FakeMetadataFactory.exampleBQTCached(), null);
+ StoredProcedure proc = (StoredProcedure)helpResolve("{call pm2.spTest8(1)}", FakeMetadataFactory.exampleBQTCached(), null); //$NON-NLS-1$
assertEquals(3, proc.getProjectedSymbols().size());
}
public void testProcRelationalWithOutParam() {
- Query proc = (Query)helpResolve("select * from pm2.spTest8 where inkey = 1", FakeMetadataFactory.exampleBQTCached(), null);
+ Query proc = (Query)helpResolve("select * from pm2.spTest8 where inkey = 1", FakeMetadataFactory.exampleBQTCached(), null); //$NON-NLS-1$
assertEquals(3, proc.getProjectedSymbols().size());
}
public void testSPReturnParamWithNoResultSet() {
- StoredProcedure proc = (StoredProcedure)helpResolve("exec pm4.spTest9(1)", FakeMetadataFactory.exampleBQTCached(), null);
+ StoredProcedure proc = (StoredProcedure)helpResolve("exec pm4.spTest9(1)", FakeMetadataFactory.exampleBQTCached(), null); //$NON-NLS-1$
assertEquals(1, proc.getProjectedSymbols().size());
}
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/rewriter/TestOrderByRewrite.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -39,7 +39,7 @@
import com.metamatrix.query.sql.lang.OrderBy;
import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
import com.metamatrix.query.sql.visitor.ExpressionSymbolCollector;
import com.metamatrix.query.unittest.FakeMetadataFactory;
@@ -89,7 +89,7 @@
assertEquals("Wrong number of Symbols: ", functionsNames.length, symbols.size()); //$NON-NLS-1$
for (int i = 0; i < symbols.size(); i++) {
- ExpressionSymbol symbol = (ExpressionSymbol)symbols.get(i);
+ DerivedColumn symbol = (DerivedColumn)symbols.get(i);
assertEquals("Expression Symbols does not match: ", functionsNames[i], symbol.toString()); //$NON-NLS-1$
}
}
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -20,8 +20,8 @@
* 02110-1301 USA.
*/
-package com.metamatrix.query.rewriter;
-
+package com.metamatrix.query.rewriter;
+
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
@@ -61,7 +61,7 @@
import com.metamatrix.query.sql.lang.Update;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.SingleElementSymbol;
@@ -71,388 +71,388 @@
import com.metamatrix.query.unittest.FakeMetadataObject;
import com.metamatrix.query.util.CommandContext;
import com.metamatrix.query.util.ContextProperties;
-
-public class TestQueryRewriter extends TestCase {
-
- private static final String TRUE_STR = "1 = 1"; //$NON-NLS-1$
- private static final String FALSE_STR = "1 = 0"; //$NON-NLS-1$
-
- // ################################## FRAMEWORK ################################
-
- public TestQueryRewriter(String name) {
- super(name);
- }
-
- // ################################## TEST HELPERS ################################
-
- private Criteria parseCriteria(String critStr, QueryMetadataInterface metadata) {
- try {
- Criteria crit = QueryParser.getQueryParser().parseCriteria(critStr);
-
- // resolve against metadata
- QueryResolver.resolveCriteria(crit, metadata);
-
- return crit;
- } catch(MetaMatrixException e) {
- throw new RuntimeException(e);
- }
- }
-
- private Criteria helpTestRewriteCriteria(String original, String expected) {
- try {
- return helpTestRewriteCriteria(original, expected, false);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- private Criteria helpTestRewriteCriteria(String original, String expected, boolean rewrite) throws QueryResolverException, QueryMetadataException, MetaMatrixComponentException, QueryValidatorException {
- FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
- Criteria expectedCrit = parseCriteria(expected, metadata);
- if (rewrite) {
- QueryResolver.resolveCriteria(expectedCrit, metadata);
- expectedCrit = QueryRewriter.rewriteCriteria(expectedCrit, null, null, metadata);
- }
- return helpTestRewriteCriteria(original, expectedCrit, metadata);
- }
-
- private Criteria helpTestRewriteCriteria(String original, Criteria expectedCrit, QueryMetadataInterface metadata) {
- Criteria origCrit = parseCriteria(original, metadata);
-
- Criteria actual = null;
- // rewrite
- try {
- actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
- assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
- } catch(QueryValidatorException e) {
- e.printStackTrace();
- fail("Exception during rewriting (" + e.getClass().getName() + "): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
- }
- return actual;
- }
-
- private String getReWrittenProcedure(String procedure, String userUpdateStr, String procedureType) {
- QueryMetadataInterface metadata = FakeMetadataFactory.exampleUpdateProc(procedureType, procedure);
-
- try {
- Command userCommand = QueryParser.getQueryParser().parseCommand(userUpdateStr);
- QueryResolver.resolveCommand(userCommand, metadata);
- QueryRewriter.rewrite(userCommand, null, metadata, null);
- return userCommand.getSubCommands().get(0).toString();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- private void helpFailUpdateProcedure(String procedure, String userUpdateStr, String procedureType) {
- QueryMetadataInterface metadata = FakeMetadataFactory.exampleUpdateProc(procedureType, procedure);
-
- Command userCommand = null;
- try {
- QueryParser parser = new QueryParser();
- userCommand = parser.parseCommand(userUpdateStr);
- QueryResolver.resolveCommand(userCommand, metadata);
- } catch(MetaMatrixException e) {
- e.printStackTrace();
- fail("Exception during parsing/resolution (" + e.getClass().getName() + "): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- QueryValidatorException exception = null;
- try {
- QueryRewriter.rewrite(userCommand, null, metadata, null);
- } catch(QueryValidatorException e) {
- exception = e;
- }
-
- assertNotNull("Expected a QueryValidatorException but got none.", exception); //$NON-NLS-1$
- }
-
- private Command helpTestRewriteCommand(String original, String expected) {
- try {
- return helpTestRewriteCommand(original, expected, FakeMetadataFactory.example1Cached());
- } catch(MetaMatrixException e) {
- throw new MetaMatrixRuntimeException(e);
- }
- }
-
- private Command helpTestRewriteCommand(String original, String expected, QueryMetadataInterface metadata) throws MetaMatrixException {
- Command command = QueryParser.getQueryParser().parseCommand(original);
- QueryResolver.resolveCommand(command, metadata);
- Command rewriteCommand = QueryRewriter.rewrite(command, null, metadata, null);
- assertEquals("Rewritten command was not expected", expected, rewriteCommand.toString()); //$NON-NLS-1$
- return rewriteCommand;
- }
-
- public void testRewriteUnknown() {
- helpTestRewriteCriteria("pm1.g1.e1 = '1' and '1' = convert(null, string)", "1 = 0"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteUnknown1() {
- helpTestRewriteCriteria("pm1.g1.e1 = '1' or '1' = convert(null, string)", "pm1.g1.e1 = '1'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteUnknown2() {
- helpTestRewriteCriteria("not('1' = convert(null, string))", "null <> null"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteUnknown3() {
- helpTestRewriteCriteria("pm1.g1.e1 like convert(null, string))", "null <> null"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteUnknown4() {
- helpTestRewriteCriteria("null in ('a', 'b', 'c')", "null <> null"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteUnknown5() {
- helpTestRewriteCriteria("(null <> null) and 1 = 0", "1 = 0"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteUnknown6() {
- helpTestRewriteCriteria("not(pm1.g1.e1 = '1' and '1' = convert(null, string))", "NOT ((pm1.g1.e1 = '1') and (NULL <> NULL))"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteUnknown7() {
- helpTestRewriteCriteria("not(pm1.g1.e1 = '1' or '1' = convert(null, string))", "NOT ((pm1.g1.e1 = '1') or (NULL <> NULL))"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteUnknown8() {
- helpTestRewriteCriteria("pm1.g1.e1 in (2, null)", "pm1.g1.e1 = '2'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteInCriteriaWithRepeats() {
- helpTestRewriteCriteria("pm1.g1.e1 in ('1', '1', '2')", "pm1.g1.e1 IN ('1', '2')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteInCriteriaWithSingleValue() {
- helpTestRewriteCriteria("pm1.g1.e1 in ('1')", "pm1.g1.e1 = '1'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteInCriteriaWithSingleValue1() {
- helpTestRewriteCriteria("pm1.g1.e1 not in ('1')", "pm1.g1.e1 != '1'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteInCriteriaWithNoValues() throws Exception {
- Criteria crit = new SetCriteria(new ElementSymbol("e1"), Collections.EMPTY_LIST); //$NON-NLS-1$
-
- Criteria actual = QueryRewriter.rewriteCriteria(crit, null, null, null);
-
- assertEquals(QueryRewriter.FALSE_CRITERIA, actual);
- }
-
- public void testRewriteBetweenCriteria1() {
- helpTestRewriteCriteria("pm1.g1.e1 BETWEEN 1000 AND 2000", "(pm1.g1.e1 >= '1000') AND (pm1.g1.e1 <= '2000')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteBetweenCriteria2() {
- helpTestRewriteCriteria("pm1.g1.e1 NOT BETWEEN 1000 AND 2000", "(pm1.g1.e1 < '1000') OR (pm1.g1.e1 > '2000')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCrit1() {
- helpTestRewriteCriteria("concat('a','b') = 'ab'", "1 = 1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCrit2() {
- helpTestRewriteCriteria("'x' = pm1.g1.e1", "(pm1.g1.e1 = 'x')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCrit3() {
- helpTestRewriteCriteria("pm1.g1.e1 = convert('a', string)", "pm1.g1.e1 = 'a'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCrit4() {
- helpTestRewriteCriteria("pm1.g1.e1 = CONVERT('a', string)", "pm1.g1.e1 = 'a'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCrit5() {
- helpTestRewriteCriteria("pm1.g1.e1 in ('a')", "pm1.g1.e1 = 'a'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCrit6() {
- helpTestRewriteCriteria("1 = convert(pm1.g1.e1,integer) + 10", "convert(pm1.g1.e1, integer) = -9"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCrit7() {
- helpTestRewriteCriteria("((pm1.g1.e1 = 1) and (pm1.g1.e1 = 1))", "pm1.g1.e1 = '1'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteMatchCritEscapeChar1() {
- helpTestRewriteCriteria("pm1.g1.e1 LIKE 'x_' ESCAPE '\\'", "pm1.g1.e1 LIKE 'x_'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteMatchCritEscapeChar2() {
- helpTestRewriteCriteria("pm1.g1.e1 LIKE '#%x' ESCAPE '#'", "pm1.g1.e1 LIKE '#%x' ESCAPE '#'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteMatchCritEscapeChar3() {
- helpTestRewriteCriteria("pm1.g1.e1 LIKE '#%x'", "pm1.g1.e1 LIKE '#%x'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteMatchCritEscapeChar4() {
- helpTestRewriteCriteria("pm1.g1.e1 LIKE pm1.g1.e1 ESCAPE '#'", "pm1.g1.e1 LIKE pm1.g1.e1 ESCAPE '#'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteMatchCritEscapeChar5() throws Exception {
- MatchCriteria mcrit = new MatchCriteria(new ElementSymbol("pm1.g1.e1"), new Constant(null, DataTypeManager.DefaultDataClasses.STRING), '#'); //$NON-NLS-1$
- Criteria expected = QueryRewriter.UNKNOWN_CRITERIA;
-
- Object actual = QueryRewriter.rewriteCriteria(mcrit, null, null, null);
- assertEquals("Did not get expected rewritten criteria", expected, actual); //$NON-NLS-1$
- }
-
- public void testRewriteMatchCrit1() {
- helpTestRewriteCriteria("pm1.g1.e1 LIKE 'x' ESCAPE '\\'", "pm1.g1.e1 = 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteMatchCrit2() {
- helpTestRewriteCriteria("pm1.g1.e1 NOT LIKE 'x'", "pm1.g1.e1 <> 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteMatchCrit3() {
- helpTestRewriteCriteria("pm1.g1.e1 NOT LIKE '%'", "1 = 0"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritTimestampCreate1() {
- helpTestRewriteCriteria("timestampCreate(pm3.g1.e2, pm3.g1.e3) = {ts'2004-11-23 09:25:00'}", "(pm3.g1.e2 = {d'2004-11-23'}) AND (pm3.g1.e3 = {t'09:25:00'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritTimestampCreate2() {
- helpTestRewriteCriteria("{ts'2004-11-23 09:25:00'} = timestampCreate(pm3.g1.e2, pm3.g1.e3)", "(pm3.g1.e2 = {d'2004-11-23'}) AND (pm3.g1.e3 = {t'09:25:00'})"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritSwap1() {
- helpTestRewriteCriteria("'x' = pm1.g1.e1", "pm1.g1.e1 = 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritSwap2() {
- helpTestRewriteCriteria("'x' <> pm1.g1.e1", "pm1.g1.e1 <> 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritSwap3() {
- helpTestRewriteCriteria("'x' < pm1.g1.e1", "pm1.g1.e1 > 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritSwap4() {
- helpTestRewriteCriteria("'x' <= pm1.g1.e1", "pm1.g1.e1 >= 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritSwap5() {
- helpTestRewriteCriteria("'x' > pm1.g1.e1", "pm1.g1.e1 < 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritSwap6() {
- helpTestRewriteCriteria("'x' >= pm1.g1.e1", "pm1.g1.e1 <= 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritExpr_op1() {
- helpTestRewriteCriteria("pm1.g1.e2 + 5 = 10", "pm1.g1.e2 = 5"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritExpr_op2() {
- helpTestRewriteCriteria("pm1.g1.e2 - 5 = 10", "pm1.g1.e2 = 15"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritExpr_op3() {
- helpTestRewriteCriteria("pm1.g1.e2 * 5 = 10", "pm1.g1.e2 = 2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritExpr_op4() {
- helpTestRewriteCriteria("pm1.g1.e2 / 5 = 10", "pm1.g1.e2 = 50"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritExpr_signFlip1() {
- helpTestRewriteCriteria("pm1.g1.e2 * -5 > 10", "pm1.g1.e2 < -2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritExpr_signFlip2() {
- helpTestRewriteCriteria("pm1.g1.e2 * -5 >= 10", "pm1.g1.e2 <= -2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritExpr_signFlip3() {
- helpTestRewriteCriteria("pm1.g1.e2 * -5 < 10", "pm1.g1.e2 > -2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritExpr_signFlip4() {
- helpTestRewriteCriteria("pm1.g1.e2 * -5 <= 10", "pm1.g1.e2 >= -2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritExpr_backwards1() {
- helpTestRewriteCriteria("5 + pm1.g1.e2 <= 10", "pm1.g1.e2 <= 5"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritExpr_backwards2() {
- helpTestRewriteCriteria("-5 * pm1.g1.e2 <= 10", "pm1.g1.e2 >= -2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritExpr_unhandled1() {
- helpTestRewriteCriteria("5 / pm1.g1.e2 <= 10", "5 / pm1.g1.e2 <= 10"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCritExpr_unhandled2() {
- helpTestRewriteCriteria("5 - pm1.g1.e2 <= 10", "5 - pm1.g1.e2 <= 10"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCrit_parseDate() {
- helpTestRewriteCriteria("PARSEDATE(pm3.g1.e1, 'yyyyMMdd') = {d'2003-05-01'}", //$NON-NLS-1$
- "pm3.g1.e1 = '20030501'" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_parseDate1() {
- helpTestRewriteCriteria("PARSEDATE(pm3.g1.e1, 'yyyyMM') = {d'2003-05-01'}", //$NON-NLS-1$
- "pm3.g1.e1 = '200305'" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_parseDate2() {
- helpTestRewriteCriteria("PARSEDATE(pm3.g1.e1, 'yyyyMM') = {d'2003-05-02'}", //$NON-NLS-1$
- "1 = 0" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_invalidParseDate() {
- QueryMetadataInterface metadata = FakeMetadataFactory.example1Cached();
- Criteria origCrit = parseCriteria("PARSEDATE(pm3.g1.e1, '''') = {d'2003-05-01'}", metadata); //$NON-NLS-1$
-
- try {
- QueryRewriter.rewriteCriteria(origCrit, null, null, null);
- fail("Expected failure"); //$NON-NLS-1$
- } catch(QueryValidatorException e) {
- assertEquals("Error simplifying criteria: PARSEDATE(pm3.g1.e1, '''') = {d'2003-05-01'}", e.getMessage()); //$NON-NLS-1$
- }
- }
-
- public void testRewriteCrit_parseTime() {
- helpTestRewriteCriteria("PARSETIME(pm3.g1.e1, 'HH mm ss') = {t'13:25:04'}", //$NON-NLS-1$
- "pm3.g1.e1 = '13 25 04'" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_parseTimestamp() {
- helpTestRewriteCriteria("PARSETimestamp(pm3.g1.e1, 'yyyy dd mm') = {ts'2003-05-01 13:25:04.5'}", //$NON-NLS-1$
- "1 = 0" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_parseTimestamp1() {
- helpTestRewriteCriteria("PARSETimestamp(pm3.g1.e1, 'yyyy dd mm') = {ts'2003-01-01 00:25:00.0'}", //$NON-NLS-1$
- "pm3.g1.e1 = '2003 01 25'" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_parseTimestamp2() {
- helpTestRewriteCriteria("PARSETimestamp(CONVERT(pm3.g1.e2, string), 'yyyy-MM-dd') = {ts'2003-05-01 13:25:04.5'}", //$NON-NLS-1$
- "1 = 0" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_parseTimestamp3() {
- helpTestRewriteCriteria("PARSETimestamp(pm3.g1.e1, 'yyyy dd mm') <> {ts'2003-05-01 13:25:04.5'}", //$NON-NLS-1$
- "1 = 1" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_parseTimestamp4() {
- helpTestRewriteCriteria("PARSETimestamp(CONVERT(pm3.g1.e2, string), 'yyyy-MM-dd') = {ts'2003-05-01 00:00:00.0'}", //$NON-NLS-1$
- "pm3.g1.e2 = {d'2003-05-01'}" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_parseTimestamp_notEquality() {
- helpTestRewriteCriteria("PARSETimestamp(pm3.g1.e1, 'yyyy dd mm') > {ts'2003-05-01 13:25:04.5'}", //$NON-NLS-1$
- "PARSETimestamp(pm3.g1.e1, 'yyyy dd mm') > {ts'2003-05-01 13:25:04.5'}" ); //$NON-NLS-1$
+
+public class TestQueryRewriter extends TestCase {
+
+ private static final String TRUE_STR = "1 = 1"; //$NON-NLS-1$
+ private static final String FALSE_STR = "1 = 0"; //$NON-NLS-1$
+
+ // ################################## FRAMEWORK ################################
+
+ public TestQueryRewriter(String name) {
+ super(name);
}
+
+ // ################################## TEST HELPERS ################################
+ private Criteria parseCriteria(String critStr, QueryMetadataInterface metadata) {
+ try {
+ Criteria crit = QueryParser.getQueryParser().parseCriteria(critStr);
+
+ // resolve against metadata
+ QueryResolver.resolveCriteria(crit, metadata);
+
+ return crit;
+ } catch(MetaMatrixException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private Criteria helpTestRewriteCriteria(String original, String expected) {
+ try {
+ return helpTestRewriteCriteria(original, expected, false);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private Criteria helpTestRewriteCriteria(String original, String expected, boolean rewrite) throws QueryResolverException, QueryMetadataException, MetaMatrixComponentException, QueryValidatorException {
+ FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+ Criteria expectedCrit = parseCriteria(expected, metadata);
+ if (rewrite) {
+ QueryResolver.resolveCriteria(expectedCrit, metadata);
+ expectedCrit = QueryRewriter.rewriteCriteria(expectedCrit, null, null, metadata);
+ }
+ return helpTestRewriteCriteria(original, expectedCrit, metadata);
+ }
+
+ private Criteria helpTestRewriteCriteria(String original, Criteria expectedCrit, QueryMetadataInterface metadata) {
+ Criteria origCrit = parseCriteria(original, metadata);
+
+ Criteria actual = null;
+ // rewrite
+ try {
+ actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
+ } catch(QueryValidatorException e) {
+ e.printStackTrace();
+ fail("Exception during rewriting (" + e.getClass().getName() + "): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return actual;
+ }
+
+ private String getReWrittenProcedure(String procedure, String userUpdateStr, String procedureType) {
+ QueryMetadataInterface metadata = FakeMetadataFactory.exampleUpdateProc(procedureType, procedure);
+
+ try {
+ Command userCommand = QueryParser.getQueryParser().parseCommand(userUpdateStr);
+ QueryResolver.resolveCommand(userCommand, metadata);
+ QueryRewriter.rewrite(userCommand, null, metadata, null);
+ return userCommand.getSubCommands().get(0).toString();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void helpFailUpdateProcedure(String procedure, String userUpdateStr, String procedureType) {
+ QueryMetadataInterface metadata = FakeMetadataFactory.exampleUpdateProc(procedureType, procedure);
+
+ Command userCommand = null;
+ try {
+ QueryParser parser = new QueryParser();
+ userCommand = parser.parseCommand(userUpdateStr);
+ QueryResolver.resolveCommand(userCommand, metadata);
+ } catch(MetaMatrixException e) {
+ e.printStackTrace();
+ fail("Exception during parsing/resolution (" + e.getClass().getName() + "): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ QueryValidatorException exception = null;
+ try {
+ QueryRewriter.rewrite(userCommand, null, metadata, null);
+ } catch(QueryValidatorException e) {
+ exception = e;
+ }
+
+ assertNotNull("Expected a QueryValidatorException but got none.", exception); //$NON-NLS-1$
+ }
+
+ private Command helpTestRewriteCommand(String original, String expected) {
+ try {
+ return helpTestRewriteCommand(original, expected, FakeMetadataFactory.example1Cached());
+ } catch(MetaMatrixException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
+ }
+
+ private Command helpTestRewriteCommand(String original, String expected, QueryMetadataInterface metadata) throws MetaMatrixException {
+ Command command = QueryParser.getQueryParser().parseCommand(original);
+ QueryResolver.resolveCommand(command, metadata);
+ Command rewriteCommand = QueryRewriter.rewrite(command, null, metadata, null);
+ assertEquals("Rewritten command was not expected", expected, rewriteCommand.toString()); //$NON-NLS-1$
+ return rewriteCommand;
+ }
+
+ public void testRewriteUnknown() {
+ helpTestRewriteCriteria("pm1.g1.e1 = '1' and '1' = convert(null, string)", "1 = 0"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteUnknown1() {
+ helpTestRewriteCriteria("pm1.g1.e1 = '1' or '1' = convert(null, string)", "pm1.g1.e1 = '1'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteUnknown2() {
+ helpTestRewriteCriteria("not('1' = convert(null, string))", "null <> null"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteUnknown3() {
+ helpTestRewriteCriteria("pm1.g1.e1 like convert(null, string))", "null <> null"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteUnknown4() {
+ helpTestRewriteCriteria("null in ('a', 'b', 'c')", "null <> null"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteUnknown5() {
+ helpTestRewriteCriteria("(null <> null) and 1 = 0", "1 = 0"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteUnknown6() {
+ helpTestRewriteCriteria("not(pm1.g1.e1 = '1' and '1' = convert(null, string))", "NOT ((pm1.g1.e1 = '1') and (NULL <> NULL))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteUnknown7() {
+ helpTestRewriteCriteria("not(pm1.g1.e1 = '1' or '1' = convert(null, string))", "NOT ((pm1.g1.e1 = '1') or (NULL <> NULL))"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteUnknown8() {
+ helpTestRewriteCriteria("pm1.g1.e1 in (2, null)", "pm1.g1.e1 = '2'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteInCriteriaWithRepeats() {
+ helpTestRewriteCriteria("pm1.g1.e1 in ('1', '1', '2')", "pm1.g1.e1 IN ('1', '2')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteInCriteriaWithSingleValue() {
+ helpTestRewriteCriteria("pm1.g1.e1 in ('1')", "pm1.g1.e1 = '1'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteInCriteriaWithSingleValue1() {
+ helpTestRewriteCriteria("pm1.g1.e1 not in ('1')", "pm1.g1.e1 != '1'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteInCriteriaWithNoValues() throws Exception {
+ Criteria crit = new SetCriteria(new ElementSymbol("e1"), Collections.EMPTY_LIST); //$NON-NLS-1$
+
+ Criteria actual = QueryRewriter.rewriteCriteria(crit, null, null, null);
+
+ assertEquals(QueryRewriter.FALSE_CRITERIA, actual);
+ }
+
+ public void testRewriteBetweenCriteria1() {
+ helpTestRewriteCriteria("pm1.g1.e1 BETWEEN 1000 AND 2000", "(pm1.g1.e1 >= '1000') AND (pm1.g1.e1 <= '2000')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteBetweenCriteria2() {
+ helpTestRewriteCriteria("pm1.g1.e1 NOT BETWEEN 1000 AND 2000", "(pm1.g1.e1 < '1000') OR (pm1.g1.e1 > '2000')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCrit1() {
+ helpTestRewriteCriteria("concat('a','b') = 'ab'", "1 = 1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCrit2() {
+ helpTestRewriteCriteria("'x' = pm1.g1.e1", "(pm1.g1.e1 = 'x')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCrit3() {
+ helpTestRewriteCriteria("pm1.g1.e1 = convert('a', string)", "pm1.g1.e1 = 'a'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCrit4() {
+ helpTestRewriteCriteria("pm1.g1.e1 = CONVERT('a', string)", "pm1.g1.e1 = 'a'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCrit5() {
+ helpTestRewriteCriteria("pm1.g1.e1 in ('a')", "pm1.g1.e1 = 'a'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCrit6() {
+ helpTestRewriteCriteria("1 = convert(pm1.g1.e1,integer) + 10", "convert(pm1.g1.e1, integer) = -9"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCrit7() {
+ helpTestRewriteCriteria("((pm1.g1.e1 = 1) and (pm1.g1.e1 = 1))", "pm1.g1.e1 = '1'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteMatchCritEscapeChar1() {
+ helpTestRewriteCriteria("pm1.g1.e1 LIKE 'x_' ESCAPE '\\'", "pm1.g1.e1 LIKE 'x_'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteMatchCritEscapeChar2() {
+ helpTestRewriteCriteria("pm1.g1.e1 LIKE '#%x' ESCAPE '#'", "pm1.g1.e1 LIKE '#%x' ESCAPE '#'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteMatchCritEscapeChar3() {
+ helpTestRewriteCriteria("pm1.g1.e1 LIKE '#%x'", "pm1.g1.e1 LIKE '#%x'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteMatchCritEscapeChar4() {
+ helpTestRewriteCriteria("pm1.g1.e1 LIKE pm1.g1.e1 ESCAPE '#'", "pm1.g1.e1 LIKE pm1.g1.e1 ESCAPE '#'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteMatchCritEscapeChar5() throws Exception {
+ MatchCriteria mcrit = new MatchCriteria(new ElementSymbol("pm1.g1.e1"), new Constant(null, DataTypeManager.DefaultDataClasses.STRING), '#'); //$NON-NLS-1$
+ Criteria expected = QueryRewriter.UNKNOWN_CRITERIA;
+
+ Object actual = QueryRewriter.rewriteCriteria(mcrit, null, null, null);
+ assertEquals("Did not get expected rewritten criteria", expected, actual); //$NON-NLS-1$
+ }
+
+ public void testRewriteMatchCrit1() {
+ helpTestRewriteCriteria("pm1.g1.e1 LIKE 'x' ESCAPE '\\'", "pm1.g1.e1 = 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteMatchCrit2() {
+ helpTestRewriteCriteria("pm1.g1.e1 NOT LIKE 'x'", "pm1.g1.e1 <> 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteMatchCrit3() {
+ helpTestRewriteCriteria("pm1.g1.e1 NOT LIKE '%'", "1 = 0"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritTimestampCreate1() {
+ helpTestRewriteCriteria("timestampCreate(pm3.g1.e2, pm3.g1.e3) = {ts'2004-11-23 09:25:00'}", "(pm3.g1.e2 = {d'2004-11-23'}) AND (pm3.g1.e3 = {t'09:25:00'})"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritTimestampCreate2() {
+ helpTestRewriteCriteria("{ts'2004-11-23 09:25:00'} = timestampCreate(pm3.g1.e2, pm3.g1.e3)", "(pm3.g1.e2 = {d'2004-11-23'}) AND (pm3.g1.e3 = {t'09:25:00'})"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritSwap1() {
+ helpTestRewriteCriteria("'x' = pm1.g1.e1", "pm1.g1.e1 = 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritSwap2() {
+ helpTestRewriteCriteria("'x' <> pm1.g1.e1", "pm1.g1.e1 <> 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritSwap3() {
+ helpTestRewriteCriteria("'x' < pm1.g1.e1", "pm1.g1.e1 > 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritSwap4() {
+ helpTestRewriteCriteria("'x' <= pm1.g1.e1", "pm1.g1.e1 >= 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritSwap5() {
+ helpTestRewriteCriteria("'x' > pm1.g1.e1", "pm1.g1.e1 < 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritSwap6() {
+ helpTestRewriteCriteria("'x' >= pm1.g1.e1", "pm1.g1.e1 <= 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritExpr_op1() {
+ helpTestRewriteCriteria("pm1.g1.e2 + 5 = 10", "pm1.g1.e2 = 5"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritExpr_op2() {
+ helpTestRewriteCriteria("pm1.g1.e2 - 5 = 10", "pm1.g1.e2 = 15"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritExpr_op3() {
+ helpTestRewriteCriteria("pm1.g1.e2 * 5 = 10", "pm1.g1.e2 = 2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritExpr_op4() {
+ helpTestRewriteCriteria("pm1.g1.e2 / 5 = 10", "pm1.g1.e2 = 50"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritExpr_signFlip1() {
+ helpTestRewriteCriteria("pm1.g1.e2 * -5 > 10", "pm1.g1.e2 < -2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritExpr_signFlip2() {
+ helpTestRewriteCriteria("pm1.g1.e2 * -5 >= 10", "pm1.g1.e2 <= -2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritExpr_signFlip3() {
+ helpTestRewriteCriteria("pm1.g1.e2 * -5 < 10", "pm1.g1.e2 > -2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritExpr_signFlip4() {
+ helpTestRewriteCriteria("pm1.g1.e2 * -5 <= 10", "pm1.g1.e2 >= -2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritExpr_backwards1() {
+ helpTestRewriteCriteria("5 + pm1.g1.e2 <= 10", "pm1.g1.e2 <= 5"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritExpr_backwards2() {
+ helpTestRewriteCriteria("-5 * pm1.g1.e2 <= 10", "pm1.g1.e2 >= -2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritExpr_unhandled1() {
+ helpTestRewriteCriteria("5 / pm1.g1.e2 <= 10", "5 / pm1.g1.e2 <= 10"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCritExpr_unhandled2() {
+ helpTestRewriteCriteria("5 - pm1.g1.e2 <= 10", "5 - pm1.g1.e2 <= 10"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCrit_parseDate() {
+ helpTestRewriteCriteria("PARSEDATE(pm3.g1.e1, 'yyyyMMdd') = {d'2003-05-01'}", //$NON-NLS-1$
+ "pm3.g1.e1 = '20030501'" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_parseDate1() {
+ helpTestRewriteCriteria("PARSEDATE(pm3.g1.e1, 'yyyyMM') = {d'2003-05-01'}", //$NON-NLS-1$
+ "pm3.g1.e1 = '200305'" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_parseDate2() {
+ helpTestRewriteCriteria("PARSEDATE(pm3.g1.e1, 'yyyyMM') = {d'2003-05-02'}", //$NON-NLS-1$
+ "1 = 0" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_invalidParseDate() {
+ QueryMetadataInterface metadata = FakeMetadataFactory.example1Cached();
+ Criteria origCrit = parseCriteria("PARSEDATE(pm3.g1.e1, '''') = {d'2003-05-01'}", metadata); //$NON-NLS-1$
+
+ try {
+ QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ fail("Expected failure"); //$NON-NLS-1$
+ } catch(QueryValidatorException e) {
+ assertEquals("Error simplifying criteria: PARSEDATE(pm3.g1.e1, '''') = {d'2003-05-01'}", e.getMessage()); //$NON-NLS-1$
+ }
+ }
+
+ public void testRewriteCrit_parseTime() {
+ helpTestRewriteCriteria("PARSETIME(pm3.g1.e1, 'HH mm ss') = {t'13:25:04'}", //$NON-NLS-1$
+ "pm3.g1.e1 = '13 25 04'" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_parseTimestamp() {
+ helpTestRewriteCriteria("PARSETimestamp(pm3.g1.e1, 'yyyy dd mm') = {ts'2003-05-01 13:25:04.5'}", //$NON-NLS-1$
+ "1 = 0" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_parseTimestamp1() {
+ helpTestRewriteCriteria("PARSETimestamp(pm3.g1.e1, 'yyyy dd mm') = {ts'2003-01-01 00:25:00.0'}", //$NON-NLS-1$
+ "pm3.g1.e1 = '2003 01 25'" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_parseTimestamp2() {
+ helpTestRewriteCriteria("PARSETimestamp(CONVERT(pm3.g1.e2, string), 'yyyy-MM-dd') = {ts'2003-05-01 13:25:04.5'}", //$NON-NLS-1$
+ "1 = 0" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_parseTimestamp3() {
+ helpTestRewriteCriteria("PARSETimestamp(pm3.g1.e1, 'yyyy dd mm') <> {ts'2003-05-01 13:25:04.5'}", //$NON-NLS-1$
+ "1 = 1" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_parseTimestamp4() {
+ helpTestRewriteCriteria("PARSETimestamp(CONVERT(pm3.g1.e2, string), 'yyyy-MM-dd') = {ts'2003-05-01 00:00:00.0'}", //$NON-NLS-1$
+ "pm3.g1.e2 = {d'2003-05-01'}" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_parseTimestamp_notEquality() {
+ helpTestRewriteCriteria("PARSETimestamp(pm3.g1.e1, 'yyyy dd mm') > {ts'2003-05-01 13:25:04.5'}", //$NON-NLS-1$
+ "PARSETimestamp(pm3.g1.e1, 'yyyy dd mm') > {ts'2003-05-01 13:25:04.5'}" ); //$NON-NLS-1$
+ }
+
public void testRewriteCrit_parseTimestamp_decompose() {
helpTestRewriteCriteria("PARSETIMESTAMP(CONCAT(FORMATDATE(pm3.g1.e2, 'yyyyMMdd'), FORMATTIME(pm3.g1.e3, 'HHmmss')), 'yyyyMMddHHmmss') = PARSETIMESTAMP('19690920183045', 'yyyyMMddHHmmss')", //$NON-NLS-1$
"(pm3.g1.e2 = {d'1969-09-20'}) AND (pm3.g1.e3 = {t'18:30:45'})" ); //$NON-NLS-1$
@@ -461,1639 +461,1639 @@
public void testRewriteCrit_timestampCreate_decompose() {
helpTestRewriteCriteria("timestampCreate(pm3.g1.e2, pm3.g1.e3) = PARSETIMESTAMP('19690920183045', 'yyyyMMddHHmmss')", //$NON-NLS-1$
"(pm3.g1.e2 = {d'1969-09-20'}) AND (pm3.g1.e3 = {t'18:30:45'})" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_parseInteger() {
- helpTestRewriteCriteria("parseInteger(pm1.g1.e1, '#,##0') = 1234", //$NON-NLS-1$
- "pm1.g1.e1 = '1,234'" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_parseLong() {
- helpTestRewriteCriteria("parseLong(pm1.g1.e1, '#,##0') = convert(1234, long)", //$NON-NLS-1$
- "pm1.g1.e1 = '1,234'" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_parseBigInteger() {
- helpTestRewriteCriteria("parseBigInteger(pm1.g1.e1, '#,##0') = convert(1234, biginteger)", //$NON-NLS-1$
- "pm1.g1.e1 = '1,234'" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_parseFloat() {
- helpTestRewriteCriteria("parseFloat(pm1.g1.e1, '#,##0.###') = convert(1234.1234, float)", //$NON-NLS-1$
- "pm1.g1.e1 = '1,234.123'" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_parseDouble() {
- helpTestRewriteCriteria("parseDouble(pm1.g1.e1, '$#,##0.00') = convert(1234.5, double)", //$NON-NLS-1$
- "pm1.g1.e1 = '$1,234.50'" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_parseBigDecimal() {
- helpTestRewriteCriteria("parseBigDecimal(pm1.g1.e1, '#,##0.###') = convert(1234.1234, bigdecimal)", //$NON-NLS-1$
- "pm1.g1.e1 = '1,234.123'" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_formatDate() {
- helpTestRewriteCriteria("formatDate(pm3.g1.e2, 'yyyyMMdd') = '20030501'", //$NON-NLS-1$
- "pm3.g1.e2 = {d'2003-05-01'}" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_formatTime() {
- helpTestRewriteCriteria("formatTime(pm3.g1.e3, 'HH mm ss') = '13 25 04'", //$NON-NLS-1$
- "pm3.g1.e3 = {t'13:25:04'}" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_formatTimestamp() {
- helpTestRewriteCriteria("formatTimestamp(pm3.g1.e4, 'MM dd, yyyy - HH:mm:ss') = '05 01, 1974 - 07:00:00'", //$NON-NLS-1$
- "formatTimestamp(pm3.g1.e4, 'MM dd, yyyy - HH:mm:ss') = '05 01, 1974 - 07:00:00'" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_formatTimestamp1() {
- helpTestRewriteCriteria("formatTimestamp(pm3.g1.e4, 'MM dd, yyyy - HH:mm:ss.S') = '05 01, 1974 - 07:00:00.0'", //$NON-NLS-1$
- "pm3.g1.e4 = {ts'1974-05-01 07:00:00.0'}" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_formatInteger() {
- helpTestRewriteCriteria("formatInteger(pm1.g1.e2, '#,##0') = '1,234'", //$NON-NLS-1$
- "pm1.g1.e2 = 1234" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_formatInteger1() {
- helpTestRewriteCriteria("formatInteger(pm1.g1.e2, '#5') = '105'", //$NON-NLS-1$
- "formatInteger(pm1.g1.e2, '#5') = '105'" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_formatLong() {
- helpTestRewriteCriteria("formatLong(convert(pm1.g1.e2, long), '#,##0') = '1,234,567,890,123'", //$NON-NLS-1$
- "convert(pm1.g1.e2, long) = 1234567890123" ); //$NON-NLS-1$
- }
-
- public void testRewriteCrit_formatTimestampInvert() {
- String original = "formatTimestamp(pm3.g1.e4, 'MM dd, yyyy - HH:mm:ss.S') = ?"; //$NON-NLS-1$
- String expected = "pm3.g1.e4 = parseTimestamp(?, 'MM dd, yyyy - HH:mm:ss.S')"; //$NON-NLS-1$
-
- helpTestRewriteCriteria(original, expected);
- }
-
- public void testRewriteCrit_plusInvert() {
- String original = "pm1.g1.e2 + 1.1 = ?"; //$NON-NLS-1$
- String expected = "pm1.g1.e2 = ? - 1.1"; //$NON-NLS-1$
-
- helpTestRewriteCriteria(original, expected);
- }
-
- public void testRewriteCrit_formatBigInteger() {
- String original = "formatBigInteger(convert(pm1.g1.e2, biginteger), '#,##0') = '1,234,567,890'"; //$NON-NLS-1$
- String expected = "convert(pm1.g1.e2, biginteger) = 1234567890"; //$NON-NLS-1$
-
- FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
- Criteria origCrit = parseCriteria(original, metadata);
- Criteria expectedCrit = parseCriteria(expected, metadata);
- ((CompareCriteria)expectedCrit).setRightExpression(new Constant(new BigInteger("1234567890"))); //$NON-NLS-1$
-
- // rewrite
- try {
- Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
- assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
- } catch(QueryValidatorException e) {
- e.printStackTrace();
- fail("Exception during rewriting (" + e.getClass().getName() + "): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- public void testRewriteCrit_formatFloat() throws Exception {
- String original = "formatFloat(convert(pm1.g1.e2, float), '#,##0.###') = '1,234.123'"; //$NON-NLS-1$
- String expected = "convert(pm1.g1.e2, float) = 1234.123"; //$NON-NLS-1$
-
- FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
- Criteria origCrit = parseCriteria(original, metadata);
-
- // rewrite
- Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
- assertEquals("Did not rewrite correctly: ", expected, actual.toString()); //$NON-NLS-1$
-
- Function left = (Function)((CompareCriteria)actual).getLeftExpression();
-
- assertFalse(left.isImplicit());
- }
-
- public void testRewriteCrit_formatDouble() {
- String original = "formatDouble(convert(pm1.g1.e2, double), '$#,##0.00') = '$1,234.50'"; //$NON-NLS-1$
- String expected = "convert(pm1.g1.e2, double) = 1234.5"; //$NON-NLS-1$
-
- FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
- Criteria origCrit = parseCriteria(original, metadata);
- Criteria expectedCrit = parseCriteria(expected, metadata);
- ((CompareCriteria)expectedCrit).setRightExpression(new Constant(new Double(1234.5)));
-
- // rewrite
- try {
- Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
- assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
- } catch(QueryValidatorException e) {
- e.printStackTrace();
- fail("Exception during rewriting (" + e.getClass().getName() + "): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- public void testRewriteCrit_formatBigDecimal() {
- String original = "formatBigDecimal(convert(pm1.g1.e2, bigdecimal), '#,##0.###') = convert(1234.5, bigdecimal)"; //$NON-NLS-1$
- String expected = "convert(pm1.g1.e2, bigdecimal) = 1234.5"; //$NON-NLS-1$
-
- FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
- Criteria origCrit = parseCriteria(original, metadata);
- Criteria expectedCrit = parseCriteria(expected, metadata);
- ((CompareCriteria)expectedCrit).setRightExpression(new Constant(new BigDecimal("1234.5"))); //$NON-NLS-1$
-
- // rewrite
- try {
- Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
- assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
- } catch(QueryValidatorException e) {
- e.printStackTrace();
- fail("Exception during rewriting (" + e.getClass().getName() + "): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- public void testRewriteCritTimestampDiffDate1() {
- helpTestRewriteCriteria("timestampdiff(SQL_TSI_DAY, {d'2003-05-15'}, {d'2003-05-17'} ) = 2", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteCritTimestampDiffDate2() {
- helpTestRewriteCriteria("timestampdiff(SQL_TSI_DAY, {d'2003-06-02'}, {d'2003-05-17'} ) = -16", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteCritTimestampDiffDate3() {
- helpTestRewriteCriteria("timestampdiff(SQL_TSI_QUARTER, {d'2002-01-25'}, {d'2003-06-01'} ) = 5", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteCritTimestampDiffTime1() {
- helpTestRewriteCriteria("timestampdiff(SQL_TSI_HOUR, {t'03:04:45'}, {t'05:05:36'} ) = 2", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteCritTimestampDiffTime1_ignorecase() {
- helpTestRewriteCriteria("timestampdiff(SQL_tsi_HOUR, {t'03:04:45'}, {t'05:05:36'} ) = 2", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteOr1() {
- helpTestRewriteCriteria("(5 = 5) OR (0 = 1)", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteOr2() {
- helpTestRewriteCriteria("(0 = 1) OR (5 = 5)", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteOr3() {
- helpTestRewriteCriteria("(1 = 1) OR (5 = 5)", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteOr4() {
- helpTestRewriteCriteria("(0 = 1) OR (4 = 5)", FALSE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteOr5() {
- helpTestRewriteCriteria("(0 = 1) OR (4 = 5) OR (pm1.g1.e1 = 'x')", "(pm1.g1.e1 = 'x')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteOr6() {
- helpTestRewriteCriteria("(0 = 1) OR (4 = 5) OR (pm1.g1.e1 = 'x') OR (pm1.g1.e1 = 'y')", "(pm1.g1.e1 = 'x') OR (pm1.g1.e1 = 'y')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteOr7() {
- helpTestRewriteCriteria("(pm1.g1.e1 = 'x') OR (pm1.g1.e1 = 'y')", "(pm1.g1.e1 = 'x') OR (pm1.g1.e1 = 'y')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteAnd1() {
- helpTestRewriteCriteria("(5 = 5) AND (0 = 1)", FALSE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteAnd2() {
- helpTestRewriteCriteria("(0 = 1) AND (5 = 5)", FALSE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteAnd3() {
- helpTestRewriteCriteria("(1 = 1) AND (5 = 5)", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteAnd4() {
- helpTestRewriteCriteria("(0 = 1) AND (4 = 5)", FALSE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteAnd5() {
- helpTestRewriteCriteria("(1 = 1) AND (5 = 5) AND (pm1.g1.e1 = 'x')", "(pm1.g1.e1 = 'x')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteAnd6() {
- helpTestRewriteCriteria("(1 = 1) AND (5 = 5) AND (pm1.g1.e1 = 'x') and (pm1.g1.e1 = 'y')", "(pm1.g1.e1 = 'x') AND (pm1.g1.e1 = 'y')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteAnd7() {
- helpTestRewriteCriteria("(pm1.g1.e1 = 'x') AND (pm1.g1.e1 = 'y')", "(pm1.g1.e1 = 'x') AND (pm1.g1.e1 = 'y')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteMixed1() {
- helpTestRewriteCriteria("((1=1) AND (1=1)) OR ((1=1) AND (1=1))", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteMixed2() {
- helpTestRewriteCriteria("((1=2) AND (1=1)) OR ((1=1) AND (1=1))", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteMixed3() {
- helpTestRewriteCriteria("((1=1) AND (1=2)) OR ((1=1) AND (1=1))", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteMixed4() {
- helpTestRewriteCriteria("((1=1) AND (1=1)) OR ((1=2) AND (1=1))", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteMixed5() {
- helpTestRewriteCriteria("((1=1) AND (1=1)) OR ((1=1) AND (1=2))", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteMixed6() {
- helpTestRewriteCriteria("((1=2) AND (1=1)) OR ((1=2) AND (1=1))", FALSE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteMixed7() {
- helpTestRewriteCriteria("((1=1) AND (1=2)) OR ((1=1) AND (1=2))", FALSE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteMixed8() {
- helpTestRewriteCriteria("((1=2) AND (1=2)) OR ((1=2) AND (1=2))", FALSE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteMixed9() {
- helpTestRewriteCriteria("((1=1) OR (1=1)) AND ((1=1) OR (1=1))", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteMixed10() {
- helpTestRewriteCriteria("((1=2) OR (1=1)) AND ((1=1) OR (1=1))", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteMixed11() {
- helpTestRewriteCriteria("((1=1) OR (1=2)) AND ((1=1) OR (1=1))", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteMixed12() {
- helpTestRewriteCriteria("((1=1) OR (1=1)) AND ((1=2) OR (1=1))", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteMixed13() {
- helpTestRewriteCriteria("((1=1) OR (1=1)) AND ((1=1) OR (1=2))", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteMixed14() {
- helpTestRewriteCriteria("((1=2) OR (1=1)) AND ((1=2) OR (1=1))", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteMixed15() {
- helpTestRewriteCriteria("((1=1) OR (1=2)) AND ((1=1) OR (1=2))", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteMixed16() {
- helpTestRewriteCriteria("((1=2) OR (1=2)) AND ((1=2) OR (1=2))", FALSE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteNot1() {
- helpTestRewriteCriteria("NOT (1=1)", FALSE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteNot2() {
- helpTestRewriteCriteria("NOT (1=2)", TRUE_STR); //$NON-NLS-1$
- }
-
- public void testRewriteNot3() {
- helpTestRewriteCriteria("NOT (pm1.g1.e1='x')", "NOT (pm1.g1.e1 = 'x')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteDefect1() {
- helpTestRewriteCriteria("(('DE' = 'LN') AND (null > '2002-01-01')) OR (('DE' = 'DE') AND (pm1.g1.e1 > '9000000'))", "(pm1.g1.e1 > '9000000')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteQueryCriteriaAlwaysTrue() {
- helpTestRewriteCommand("SELECT e1 FROM pm1.g1 WHERE 0 = 0", //$NON-NLS-1$
- "SELECT e1 FROM pm1.g1"); //$NON-NLS-1$
- }
-
- public void testSubquery1() {
- helpTestRewriteCommand("SELECT e1 FROM (SELECT e1 FROM pm1.g1 WHERE (1 - 1) = (0 + 0)) AS x", //$NON-NLS-1$
- "SELECT e1 FROM (SELECT e1 FROM pm1.g1) AS x"); //$NON-NLS-1$
- }
-
- public void testExistsSubquery() {
- helpTestRewriteCommand("SELECT e1 FROM pm1.g1 WHERE EXISTS (SELECT e1 FROM pm1.g2)", //$NON-NLS-1$
- "SELECT e1 FROM pm1.g1 WHERE EXISTS (SELECT e1 FROM pm1.g2)"); //$NON-NLS-1$
- }
-
- public void testCompareSubqueryANY() {
- helpTestRewriteCommand("SELECT e1 FROM pm1.g1 WHERE '3' = ANY (SELECT e1 FROM pm1.g2)", //$NON-NLS-1$
- "SELECT e1 FROM pm1.g1 WHERE '3' = SOME (SELECT e1 FROM pm1.g2)"); //$NON-NLS-1$
- }
-
- public void testCompareSubquery() {
- helpTestRewriteCommand("SELECT e1 FROM pm1.g1 WHERE '3' = SOME (SELECT e1 FROM pm1.g2)", //$NON-NLS-1$
- "SELECT e1 FROM pm1.g1 WHERE '3' = SOME (SELECT e1 FROM pm1.g2)"); //$NON-NLS-1$
- }
-
- public void testCompareSubqueryUnknown() {
- helpTestRewriteCommand("SELECT e1 FROM pm1.g1 WHERE null = SOME (SELECT e1 FROM pm1.g2)", //$NON-NLS-1$
- "SELECT e1 FROM pm1.g1 WHERE null <> null"); //$NON-NLS-1$
- }
-
- public void testINClauseSubquery() {
- helpTestRewriteCommand("SELECT e1 FROM pm1.g1 WHERE '3' IN (SELECT e1 FROM pm1.g2)", //$NON-NLS-1$
- "SELECT e1 FROM pm1.g1 WHERE '3' IN (SELECT e1 FROM pm1.g2)"); //$NON-NLS-1$
- }
-
- public void testRewriteXMLCriteria1() {
- helpTestRewriteCriteria("context(pm1.g1.e1, pm1.g1.e1) = convert(5, string)", "context(pm1.g1.e1, pm1.g1.e1) = '5'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteXMLCriteria2() {
- helpTestRewriteCriteria("context(pm1.g1.e1, convert(5, string)) = 2+3", "context(pm1.g1.e1, '5') = '5'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // HAS Criteria
- public void testRewriteProcedure1() {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (HAS = CRITERIA ON (vm1.g1.e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\", 1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.INSERT_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // HAS Criteria
- public void testRewriteProcedure2() {
-
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (HAS = CRITERIA ON (vm1.g1.e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ELSE \n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\", 1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT vm1.g1.e1 FROM vm1.g1 WHERE "+FALSE_STR+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.INSERT_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // HAS Criteria
- public void testRewriteProcedure3() {
-
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (HAS = CRITERIA ON (vm1.g1.e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "ELSE \n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\", 1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT vm1.g1.e1 FROM vm1.g1 WHERE "+FALSE_STR+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.INSERT_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- public void testRewriteProcedure4() {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (INPUT.e2 = 1)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\", 1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT vm1.g1.e1 FROM vm1.g1 WHERE "+FALSE_STR+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.INSERT_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // CHANGING
- public void testRewriteProcedure5() {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (CHANGING.e1 = \"false\")\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e2);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Update vm1.g1 SET e1 = \"String\", e2 =1 where e2 = 10"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // CHANGING
- public void testRewriteProcedure6() {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (CHANGING.e1 = \"true\")\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Update vm1.g1 SET e1 = \"String\", e2 =1 where e2 = 10"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // TRANSLATE CRITERIA
- public void testRewriteProcedure7() {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (CHANGING.e1 = \"true\")\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select e2 from pm1.g1 where TRANSLATE = CRITERIA ON (vm1.g1.e2);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Update vm1.g1 SET e1 = \"String\", e2 =1 where e2 = 10"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT e2 FROM pm1.g1 WHERE pm1.g1.e2 = 10;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // TRANSLATE CRITERIA
- public void testRewriteProcedure8() {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (CHANGING.e1 = \"true\")\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select e2 from pm1.g1 where TRANSLATE = CRITERIA ON (vm1.g1.e2) with (vm1.g1.e2 = convert(sqrt(pm1.g1.e2), integer));\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Update vm1.g1 SET e1 = \"String\", e2 =1 where e2 = 10"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT e2 FROM pm1.g1 WHERE convert(sqrt(pm1.g1.e2), integer) = 10;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // rewrite input/ changing variables
- public void testRewriteProcedure9() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Declare String var1;\n"; //$NON-NLS-1$
- procedure = procedure + "if(var1 = 'x' or var1 = 'y')\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2, Input.e2, CHANGING.e2, CHANGING.e1 from pm1.g1 order by CHANGING.e1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "INSERT into vm1.g1 (e1) values('x')"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE String var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "IF((var1 = 'x') OR (var1 = 'y'))\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2, null AS E2_0, FALSE AS E2_1, TRUE AS E1 FROM pm1.g1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.INSERT_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- public void testRewriteProcedure10() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1, pm1.g2 where TRANSLATE = CRITERIA ON (e2) WITH (e2 = pm1.g1.e2 + 20);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g1 SET e1='x' where e2 = e2 + 50"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1, pm1.g2 WHERE (pm1.g1.e2 + 20) = ((pm1.g1.e2 + 20) + 50);\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(HAS CRITERIA)
- public void testRewriteProcedure11() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE string var1;\n"; //$NON-NLS-1$
- procedure = procedure + "var1 = INPUT.e1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g1 SET e1=40"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE string var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "var1 = '40';\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- // with complex query transform
- public void testRewriteProcedure12() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA WITH (x = CONCAT(e1 , 'z'));\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where x =CONCAT(x , 'y')"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE CONCAT(e1, 'z') = CONCAT(CONCAT(e1, 'z'), 'y');\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- // with complex query transform
- public void testRewriteProcedure13() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA WITH (x = CONCAT(e1 , 'z'), y = convert(CONCAT(e1 , 'k'), integer));\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where x =CONCAT(x , 'y') and y= 1"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE (CONCAT(e1, 'z') = CONCAT(CONCAT(e1, 'z'), 'y')) AND (convert(CONCAT(e1, 'k'), integer) = 1);\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- public void testRewriteProcedure14() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA WITH (e4 = sqrt(e4));\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where e4= 1"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE sqrt(e4) = 1.0;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- public void testRewriteProcedure15() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA WITH (e4 = e4/50);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where y= 1"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE e2 = 0;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- public void testRewriteProcedure16() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE CRITERIA;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where e4= 1"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE e4 = 0.02;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- public void testRewriteProcedure17() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE LIKE CRITERIA WITH (e4 = e4/50);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g3 SET x='x' where e4= 1"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE "+FALSE_STR+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // Bug 8212 elements in INPUT and CHANGING special groups are cese sensitive
- public void testRewriteProcedure18() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select Input.E1, Input.e2, CHANGING.e2, CHANGING.E1 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "INSERT into vm1.g1 (e1, E2) values('x', 1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT 'x', 1, TRUE, TRUE FROM pm1.g1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.INSERT_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // elements being set in updates are dropped if INPUT var is not available, unless a default is available
- // Note that this test is a little odd in that it is an update inside of an insert
- public void testRewriteProcedure19() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "update pm1.g1 set e1=Input.E1, e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "INSERT into vm1.g1 (E2) values(1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "UPDATE pm1.g1 SET e1 = 'xyz', e2 = 1, e3 = TRUE;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.INSERT_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // elements being set in updates are dropped if INPUT var is not available, unless a default is supplied
-
- //this test fails because the default for E1 'xyz' cannot be converted into a integer
- public void testRewriteProcedure21() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "update pm1.g1 set e1=convert(Input.E1, integer)+INPUT.E2, e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "INSERT into vm1.g1 (E3) values({b'true'})"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "UPDATE pm1.g1 SET e3 = TRUE;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- this.helpFailUpdateProcedure(procedure, userQuery, FakeMetadataObject.Props.INSERT_PROCEDURE);
- }
-
- public void testRewriteProcedure21a() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "update pm1.g1 set e1=convert(Input.E1, integer)+INPUT.E2, e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "INSERT into vm1.g1 (E1) values(1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "UPDATE pm1.g1 SET e1 = null, e2 = null, e3 = TRUE;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.INSERT_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
-
- // none of input variables on update statement changing
- public void testRewriteProcedure22() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "update pm1.g1 set e1=convert(Input.E1, integer)+INPUT.E2, e2=Input.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "update vm1.g1 set E3 = {b'true'}"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // none of input variables on update statement changing
- public void testRewriteProcedure23() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "update pm1.g1 set e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "update vm1.g1 set E1 = 'x'"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- //with an insert, defaults are used
- public void testRewriteProcedure23a() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "update pm1.g1 set e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "INSERT into vm1.g1 (E1) values('x')"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "UPDATE pm1.g1 SET e2 = null, e3 = TRUE;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.INSERT_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // elements being set in updates are dropped if INPUT var is not available
- public void testRewriteProcedure24() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "UPDATE pm1.g1 SET e2=Input.e2 WHERE TRANSLATE LIKE CRITERIA ON (e1) WITH (e1=concat(pm1.g1.e1, \"%\"));\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g1 set E2=1 where e2 = 1 and e1 LIKE 'mnopxyz_'"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "UPDATE pm1.g1 SET e2 = 1 WHERE concat(pm1.g1.e1, '%') LIKE 'mnopxyz_';\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // INPUT vars in insert statements replaced by default variable when user's inser ignores values
- public void testRewriteProcedure25() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "INSERT into pm1.g1 (e1,e2,e3,e4) values (Input.e1, Input.e2, Input.e3, Input.e4);"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "INSERT into vm1.g1 (E2) values (1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "INSERT INTO pm1.g1 (e1, e2, e3, e4) VALUES ('xyz', 1, TRUE, 123.456);\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.INSERT_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- public void testRewriteProcedure26() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1, pm1.g2 where TRANSLATE = CRITERIA ON (e2);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g1 SET e1='x' where e2 = e2 + 50"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e2 = (pm1.g1.e2 + 50);\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- public void testRewriteProcedure27() {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1, pm1.g2 where TRANSLATE = CRITERIA ON (e2);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g1 SET e1='x' where e2 LIKE 'xyz'"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1, pm1.g2 WHERE "+FALSE_STR+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- /**
- * Per defect 9380 -
- * A criteria of the form
- * (? + 1) < (null)
- * caused a problem in the QueryRewriter.simplifyMathematicalCriteria method.
- * At the beginning of the method, the null constant is rewritten so that it
- * loses it's implicit type conversion to integer, then later on a function
- * descriptor couldn't be found for the "minus" operation for the two types
- * integer and MetaMatrix's null type.
- */
- public void testRewriteProcedure_9380() {
-
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var2;\n"; //$NON-NLS-1$
- procedure = procedure + "if((var1 + 1) < length(input.e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "var2 = INPUT.e2;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "UPDATE vm1.g1 SET e2=30"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var2;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- //base test. no change is expected
- public void testRewriteLookupFunction1() {
- String criteria = "lookup('pm1.g1','e1', 'e2', 'value') = 'ab'"; //$NON-NLS-1$
- CompareCriteria expected = (CompareCriteria)parseCriteria(criteria, FakeMetadataFactory.example1Cached());
- helpTestRewriteCriteria(criteria, expected, FakeMetadataFactory.example1Cached());
- }
-
- public void testRewriteLookupFunction1b() {
- helpTestRewriteCriteria("lookup('pm1.g1','e1', 'e2', pm1.g1.e1) = 'ab'", "lookup('pm1.g1','e1', 'e2', pm1.g1.e1) = 'ab'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /** defect 11630 1 should still get rewritten as '1'*/
- public void testRewriteLookupFunctionCompoundCriteria() {
- String criteria = "LOOKUP('pm1.g1','e1', 'e2', 'value') IS NULL AND pm1.g1.e1='1'"; //$NON-NLS-1$
- CompoundCriteria expected = (CompoundCriteria)parseCriteria(criteria, FakeMetadataFactory.example1Cached());
- helpTestRewriteCriteria("LOOKUP('pm1.g1','e1', 'e2', 'value') IS NULL AND pm1.g1.e1=1", expected, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
- }
-
- public void testSelectWithNoFrom() {
- helpTestRewriteCommand("SELECT 5", "SELECT 5"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- //defect 9822
- public void testStoredProcedure_9822() throws Exception {
-
- QueryParser parser = new QueryParser();
- Command command = parser.parseCommand("exec pm1.sp4(5)"); //$NON-NLS-1$
-
- // resolve
- QueryResolver.resolveCommand(command, FakeMetadataFactory.example1Cached());
-
- // rewrite
- Command rewriteCommand = QueryRewriter.rewrite(command, null, null, null);
-
- List parameters = ((StoredProcedure)rewriteCommand).getParameters();
-
- Iterator iter = parameters.iterator();
- while(iter.hasNext()){
- SPParameter param = (SPParameter)iter.next();
- if(param.getParameterType() == ParameterInfo.IN || param.getParameterType() == ParameterInfo.INOUT){
- assertTrue(param.getExpression() instanceof Constant);
- }
- }
- }
-
- public void testRewriteRecursive() {
- Command c = helpTestRewriteCommand("SELECT e2 FROM vm1.g33", "SELECT e2 FROM vm1.g33"); //$NON-NLS-1$ //$NON-NLS-2$
- Command innerCommand = (Command) c.getSubCommands().get(0);
-
- assertEquals("Inner command not rewritten", "SELECT e2 FROM pm1.g1 WHERE e2 = 2", innerCommand.toString()); //$NON-NLS-1$ //$NON-NLS-2$
-
- }
-
- public void testRewriteFunctionThrowsEvaluationError() {
- FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
- Criteria origCrit = parseCriteria("5 / 0 = 5", metadata); //$NON-NLS-1$
-
- // rewrite
- try {
- QueryRewriter.rewriteCriteria(origCrit, null, null, null);
- fail("Expected QueryValidatorException due to divide by 0"); //$NON-NLS-1$
- } catch(QueryValidatorException e) {
- assertEquals("Unable to evaluate (5 / 0): Error while evaluating function /", e.getMessage()); //$NON-NLS-1$
- }
- }
-
- public void testRewriteConvertThrowsEvaluationError() {
- FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
- Criteria origCrit = parseCriteria("convert('x', integer) = 0", metadata); //$NON-NLS-1$
-
- // rewrite
- try {
- QueryRewriter.rewriteCriteria(origCrit, null, null, null);
- fail("Expected QueryValidatorException due to invalid string"); //$NON-NLS-1$
- } catch(QueryValidatorException e) {
- assertEquals("Unable to convert 'x' of type [string] to the expected type [integer].", e.getMessage()); //$NON-NLS-1$
- }
- }
-
- public void testDefect13458() {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "IF (HAS = CRITERIA ON (vm1.g1.e1))\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "delete from vm1.g1 where e1='1'"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT vm1.g1.e1 FROM vm1.g1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.DELETE_PROCEDURE);
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- public void testRewriteCase1954() {
- helpTestRewriteCriteria("convert(pm1.g1.e2, string) = '3'", "pm1.g1.e2 = 3"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCase1954a() {
- helpTestRewriteCriteria("cast(pm1.g1.e2 as string) = '3'", "pm1.g1.e2 = 3"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCase1954b() throws Exception{
- FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
-
- // Have to hand-build the criteria, because 3.0 gets parsed as a Float by default
- // pm1.g1.e4 = 3.0
- CompareCriteria expected = new CompareCriteria();
- ElementSymbol leftElement = new ElementSymbol("pm1.g1.e4"); //$NON-NLS-1$
- Constant constant = new Constant(new Double(3.0), DataTypeManager.DefaultDataClasses.DOUBLE);
- expected.setLeftExpression(leftElement);
- expected.setRightExpression(constant);
- // resolve against metadata
- QueryResolver.resolveCriteria(expected, metadata);
-
- helpTestRewriteCriteria("convert(pm1.g1.e4, string) = '3'", expected, metadata); //$NON-NLS-1$
- }
-
- public void testRewriteCase1954c() {
- helpTestRewriteCriteria("convert(pm1.g1.e1, string) = 'x'", "pm1.g1.e1 = 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /** Test some other type besides 'string' has no effect */
- public void testRewriteCase1954d() {
- helpTestRewriteCriteria("convert(pm1.g1.e1, timestamp) = {ts '2005-01-03 00:00:00.0'}", "convert(pm1.g1.e1, timestamp) = {ts '2005-01-03 00:00:00.0'}"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /** Test some other type besides 'string' has no effect */
- public void testRewriteCase1954e() {
- helpTestRewriteCriteria("convert(pm1.g1.e4, integer) = 2", "convert(pm1.g1.e4, integer) = 2"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /** Check that this fails, x is not convertable to an int */
- public void testRewriteCase1954f() {
- helpTestRewriteCriteria("convert(pm1.g1.e2, string) = 'x'", "1 = 0"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /** Check that this returns true, x is not convertable to an int */
- public void testRewriteCase1954f1() {
- helpTestRewriteCriteria("convert(pm1.g1.e2, string) != 'x'", "1 = 1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCase1954Set() {
- helpTestRewriteCriteria("convert(pm1.g1.e2, string) in ('2', '3')", "pm1.g1.e2 IN (2,3)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCase1954SetA() {
- helpTestRewriteCriteria("convert(pm1.g1.e2, string) in ('2', 'x')", "convert(pm1.g1.e2, string) in ('2', 'x')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCase1954SetB() {
- helpTestRewriteCriteria("cast(pm1.g1.e2 as string) in ('2', '3')", "pm1.g1.e2 IN (2,3)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCase1954SetC() {
- helpTestRewriteCriteria("concat(pm1.g1.e2, 'string') in ('2', '3')", "concat(pm1.g1.e2, 'string') in ('2', '3')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCase1954SetD() {
- helpTestRewriteCriteria("convert(pm1.g1.e2, string) in ('2', pm1.g1.e1)", "convert(pm1.g1.e2, string) in ('2', pm1.g1.e1)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // First WHEN always true, so rewrite as THEN expression
- public void testRewriteCaseExpr1() {
- helpTestRewriteCriteria("case when 0=0 then 1 else 2 end = 1", "1 = 1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // First WHEN always false, so rewrite as ELSE expression
- public void testRewriteCaseExpr2() {
- helpTestRewriteCriteria("case when 0=1 then 1 else 2 end = 1", "1 = 0"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // First WHEN can't be rewritten, so no changes
- public void testRewriteCaseExpr3() {
- helpTestRewriteCriteria("case when 0 = pm1.g1.e2 then 1 else 2 end = 1", "CASE WHEN pm1.g1.e2 = 0 THEN 1 ELSE 2 END = 1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCaseExpr4() {
- helpTestRewriteCriteria("lookup('pm1.g1', 'e2', 'e1', case when 1=1 then pm1.g1.e1 end) = 0", "lookup('pm1.g1', 'e2', 'e1', pm1.g1.e1) = 0"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // First WHEN always false, so remove it
- public void testRewriteCaseExpr5() {
- helpTestRewriteCriteria("case when 0=1 then 1 when 0 = pm1.g1.e2 then 2 else 3 end = 1", "CASE WHEN pm1.g1.e2 = 0 THEN 2 ELSE 3 END = 1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCaseExprForCase5413aFrom502() {
- helpTestRewriteCriteria("pm1.g2.e1 = case when 0 = pm1.g1.e2 then 2 else 2 end", "pm1.g2.e1 = '2'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCaseExprForCase5413bFrom502() {
- helpTestRewriteCriteria("case when 0 = pm1.g1.e2 then null else null end IS NULL", TRUE_STR); //$NON-NLS-1$
- }
-
-
- public void testRewriteCaseExprForCase5413a() {
- helpTestRewriteCriteria("pm1.g2.e1 = case when 0 = pm1.g1.e2 then 2 else 2 end", "pm1.g2.e1 = '2'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCaseExprForCase5413b() {
- helpTestRewriteCriteria("case when 0 = pm1.g1.e2 then null else null end IS NULL", TRUE_STR); //$NON-NLS-1$
- }
-
- // First WHEN always true, so rewrite as THEN expression
- public void testRewriteSearchedCaseExpr1() {
- helpTestRewriteCriteria("case 0 when 0 then 1 else 2 end = 1", "1 = 1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- // First WHEN always false, so rewrite as ELSE expression
- public void testRewriteSearchedCaseExpr2() {
- helpTestRewriteCriteria("case 0 when 1 then 1 else 2 end = 1", "1 = 0"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteSearchedCaseExpr3() {
- helpTestRewriteCriteria("case 0 when pm1.g1.e2 then 1 else 2 end = 1", "CASE WHEN pm1.g1.e2 = 0 THEN 1 ELSE 2 END = 1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteSearchedCaseExpr4() {
- String criteria = "lookup('pm1.g1', 'e2', 'e1', null) = 0"; //$NON-NLS-1$
- CompareCriteria expected = (CompareCriteria)parseCriteria(criteria, FakeMetadataFactory.example1Cached());
- helpTestRewriteCriteria("lookup('pm1.g1', 'e2', 'e1', case 0 when 1 then pm1.g1.e1 end) = 0", expected, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
- }
-
- // First WHEN always false, so remove it
- public void testRewriteSearchedCaseExpr5() {
- helpTestRewriteCriteria("case 0 when 1 then 1 when pm1.g1.e2 then 2 else 3 end = 1", "CASE WHEN pm1.g1.e2 = 0 THEN 2 ELSE 3 END = 1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDefect16879_1(){
- helpTestRewriteCommand("SELECT decodestring(e1, 'a, b') FROM pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDefect16879_2(){
- helpTestRewriteCommand("SELECT decodestring(e1, 'a, b, c, d') FROM pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' WHEN e1 = 'c' THEN 'd' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDefect16879_3(){
- helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b') FROM pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDefect16879_4(){
- helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b, c, d') FROM pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' WHEN e1 = 'c' THEN 'd' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDefect16879_5(){
- helpTestRewriteCommand("SELECT decodeinteger(e1, 'null, b, c, d') FROM pm1.g1", "SELECT CASE WHEN e1 IS NULL THEN 'b' WHEN e1 = 'c' THEN 'd' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDefect16879_6(){
- helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b, null, d') FROM pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' WHEN e1 IS NULL THEN 'd' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDefect16879_7(){
- helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b, null, d, e') FROM pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' WHEN e1 IS NULL THEN 'd' ELSE 'e' END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ }
+
+ public void testRewriteCrit_parseInteger() {
+ helpTestRewriteCriteria("parseInteger(pm1.g1.e1, '#,##0') = 1234", //$NON-NLS-1$
+ "pm1.g1.e1 = '1,234'" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_parseLong() {
+ helpTestRewriteCriteria("parseLong(pm1.g1.e1, '#,##0') = convert(1234, long)", //$NON-NLS-1$
+ "pm1.g1.e1 = '1,234'" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_parseBigInteger() {
+ helpTestRewriteCriteria("parseBigInteger(pm1.g1.e1, '#,##0') = convert(1234, biginteger)", //$NON-NLS-1$
+ "pm1.g1.e1 = '1,234'" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_parseFloat() {
+ helpTestRewriteCriteria("parseFloat(pm1.g1.e1, '#,##0.###') = convert(1234.1234, float)", //$NON-NLS-1$
+ "pm1.g1.e1 = '1,234.123'" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_parseDouble() {
+ helpTestRewriteCriteria("parseDouble(pm1.g1.e1, '$#,##0.00') = convert(1234.5, double)", //$NON-NLS-1$
+ "pm1.g1.e1 = '$1,234.50'" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_parseBigDecimal() {
+ helpTestRewriteCriteria("parseBigDecimal(pm1.g1.e1, '#,##0.###') = convert(1234.1234, bigdecimal)", //$NON-NLS-1$
+ "pm1.g1.e1 = '1,234.123'" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_formatDate() {
+ helpTestRewriteCriteria("formatDate(pm3.g1.e2, 'yyyyMMdd') = '20030501'", //$NON-NLS-1$
+ "pm3.g1.e2 = {d'2003-05-01'}" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_formatTime() {
+ helpTestRewriteCriteria("formatTime(pm3.g1.e3, 'HH mm ss') = '13 25 04'", //$NON-NLS-1$
+ "pm3.g1.e3 = {t'13:25:04'}" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_formatTimestamp() {
+ helpTestRewriteCriteria("formatTimestamp(pm3.g1.e4, 'MM dd, yyyy - HH:mm:ss') = '05 01, 1974 - 07:00:00'", //$NON-NLS-1$
+ "formatTimestamp(pm3.g1.e4, 'MM dd, yyyy - HH:mm:ss') = '05 01, 1974 - 07:00:00'" ); //$NON-NLS-1$
+ }
+ public void testRewriteCrit_formatTimestamp1() {
+ helpTestRewriteCriteria("formatTimestamp(pm3.g1.e4, 'MM dd, yyyy - HH:mm:ss.S') = '05 01, 1974 - 07:00:00.0'", //$NON-NLS-1$
+ "pm3.g1.e4 = {ts'1974-05-01 07:00:00.0'}" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_formatInteger() {
+ helpTestRewriteCriteria("formatInteger(pm1.g1.e2, '#,##0') = '1,234'", //$NON-NLS-1$
+ "pm1.g1.e2 = 1234" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_formatInteger1() {
+ helpTestRewriteCriteria("formatInteger(pm1.g1.e2, '#5') = '105'", //$NON-NLS-1$
+ "formatInteger(pm1.g1.e2, '#5') = '105'" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_formatLong() {
+ helpTestRewriteCriteria("formatLong(convert(pm1.g1.e2, long), '#,##0') = '1,234,567,890,123'", //$NON-NLS-1$
+ "convert(pm1.g1.e2, long) = 1234567890123" ); //$NON-NLS-1$
+ }
+
+ public void testRewriteCrit_formatTimestampInvert() {
+ String original = "formatTimestamp(pm3.g1.e4, 'MM dd, yyyy - HH:mm:ss.S') = ?"; //$NON-NLS-1$
+ String expected = "pm3.g1.e4 = parseTimestamp(?, 'MM dd, yyyy - HH:mm:ss.S')"; //$NON-NLS-1$
+
+ helpTestRewriteCriteria(original, expected);
+ }
+
+ public void testRewriteCrit_plusInvert() {
+ String original = "pm1.g1.e2 + 1.1 = ?"; //$NON-NLS-1$
+ String expected = "pm1.g1.e2 = ? - 1.1"; //$NON-NLS-1$
+
+ helpTestRewriteCriteria(original, expected);
+ }
+
+ public void testRewriteCrit_formatBigInteger() {
+ String original = "formatBigInteger(convert(pm1.g1.e2, biginteger), '#,##0') = '1,234,567,890'"; //$NON-NLS-1$
+ String expected = "convert(pm1.g1.e2, biginteger) = 1234567890"; //$NON-NLS-1$
+
+ FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+ Criteria origCrit = parseCriteria(original, metadata);
+ Criteria expectedCrit = parseCriteria(expected, metadata);
+ ((CompareCriteria)expectedCrit).setRightExpression(new Constant(new BigInteger("1234567890"))); //$NON-NLS-1$
+
+ // rewrite
+ try {
+ Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
+ } catch(QueryValidatorException e) {
+ e.printStackTrace();
+ fail("Exception during rewriting (" + e.getClass().getName() + "): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ public void testRewriteCrit_formatFloat() throws Exception {
+ String original = "formatFloat(convert(pm1.g1.e2, float), '#,##0.###') = '1,234.123'"; //$NON-NLS-1$
+ String expected = "convert(pm1.g1.e2, float) = 1234.123"; //$NON-NLS-1$
+
+ FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+ Criteria origCrit = parseCriteria(original, metadata);
+
+ // rewrite
+ Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ assertEquals("Did not rewrite correctly: ", expected, actual.toString()); //$NON-NLS-1$
+
+ Function left = (Function)((CompareCriteria)actual).getLeftExpression();
+
+ assertFalse(left.isImplicit());
+ }
+
+ public void testRewriteCrit_formatDouble() {
+ String original = "formatDouble(convert(pm1.g1.e2, double), '$#,##0.00') = '$1,234.50'"; //$NON-NLS-1$
+ String expected = "convert(pm1.g1.e2, double) = 1234.5"; //$NON-NLS-1$
+
+ FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+ Criteria origCrit = parseCriteria(original, metadata);
+ Criteria expectedCrit = parseCriteria(expected, metadata);
+ ((CompareCriteria)expectedCrit).setRightExpression(new Constant(new Double(1234.5)));
+
+ // rewrite
+ try {
+ Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
+ } catch(QueryValidatorException e) {
+ e.printStackTrace();
+ fail("Exception during rewriting (" + e.getClass().getName() + "): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ public void testRewriteCrit_formatBigDecimal() {
+ String original = "formatBigDecimal(convert(pm1.g1.e2, bigdecimal), '#,##0.###') = convert(1234.5, bigdecimal)"; //$NON-NLS-1$
+ String expected = "convert(pm1.g1.e2, bigdecimal) = 1234.5"; //$NON-NLS-1$
+
+ FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+ Criteria origCrit = parseCriteria(original, metadata);
+ Criteria expectedCrit = parseCriteria(expected, metadata);
+ ((CompareCriteria)expectedCrit).setRightExpression(new Constant(new BigDecimal("1234.5"))); //$NON-NLS-1$
+
+ // rewrite
+ try {
+ Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ assertEquals("Did not rewrite correctly: ", expectedCrit, actual); //$NON-NLS-1$
+ } catch(QueryValidatorException e) {
+ e.printStackTrace();
+ fail("Exception during rewriting (" + e.getClass().getName() + "): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ public void testRewriteCritTimestampDiffDate1() {
+ helpTestRewriteCriteria("timestampdiff(SQL_TSI_DAY, {d'2003-05-15'}, {d'2003-05-17'} ) = 2", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteCritTimestampDiffDate2() {
+ helpTestRewriteCriteria("timestampdiff(SQL_TSI_DAY, {d'2003-06-02'}, {d'2003-05-17'} ) = -16", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteCritTimestampDiffDate3() {
+ helpTestRewriteCriteria("timestampdiff(SQL_TSI_QUARTER, {d'2002-01-25'}, {d'2003-06-01'} ) = 5", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteCritTimestampDiffTime1() {
+ helpTestRewriteCriteria("timestampdiff(SQL_TSI_HOUR, {t'03:04:45'}, {t'05:05:36'} ) = 2", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteCritTimestampDiffTime1_ignorecase() {
+ helpTestRewriteCriteria("timestampdiff(SQL_tsi_HOUR, {t'03:04:45'}, {t'05:05:36'} ) = 2", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteOr1() {
+ helpTestRewriteCriteria("(5 = 5) OR (0 = 1)", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteOr2() {
+ helpTestRewriteCriteria("(0 = 1) OR (5 = 5)", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteOr3() {
+ helpTestRewriteCriteria("(1 = 1) OR (5 = 5)", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteOr4() {
+ helpTestRewriteCriteria("(0 = 1) OR (4 = 5)", FALSE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteOr5() {
+ helpTestRewriteCriteria("(0 = 1) OR (4 = 5) OR (pm1.g1.e1 = 'x')", "(pm1.g1.e1 = 'x')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteOr6() {
+ helpTestRewriteCriteria("(0 = 1) OR (4 = 5) OR (pm1.g1.e1 = 'x') OR (pm1.g1.e1 = 'y')", "(pm1.g1.e1 = 'x') OR (pm1.g1.e1 = 'y')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteOr7() {
+ helpTestRewriteCriteria("(pm1.g1.e1 = 'x') OR (pm1.g1.e1 = 'y')", "(pm1.g1.e1 = 'x') OR (pm1.g1.e1 = 'y')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteAnd1() {
+ helpTestRewriteCriteria("(5 = 5) AND (0 = 1)", FALSE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteAnd2() {
+ helpTestRewriteCriteria("(0 = 1) AND (5 = 5)", FALSE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteAnd3() {
+ helpTestRewriteCriteria("(1 = 1) AND (5 = 5)", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteAnd4() {
+ helpTestRewriteCriteria("(0 = 1) AND (4 = 5)", FALSE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteAnd5() {
+ helpTestRewriteCriteria("(1 = 1) AND (5 = 5) AND (pm1.g1.e1 = 'x')", "(pm1.g1.e1 = 'x')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteAnd6() {
+ helpTestRewriteCriteria("(1 = 1) AND (5 = 5) AND (pm1.g1.e1 = 'x') and (pm1.g1.e1 = 'y')", "(pm1.g1.e1 = 'x') AND (pm1.g1.e1 = 'y')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteAnd7() {
+ helpTestRewriteCriteria("(pm1.g1.e1 = 'x') AND (pm1.g1.e1 = 'y')", "(pm1.g1.e1 = 'x') AND (pm1.g1.e1 = 'y')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteMixed1() {
+ helpTestRewriteCriteria("((1=1) AND (1=1)) OR ((1=1) AND (1=1))", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteMixed2() {
+ helpTestRewriteCriteria("((1=2) AND (1=1)) OR ((1=1) AND (1=1))", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteMixed3() {
+ helpTestRewriteCriteria("((1=1) AND (1=2)) OR ((1=1) AND (1=1))", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteMixed4() {
+ helpTestRewriteCriteria("((1=1) AND (1=1)) OR ((1=2) AND (1=1))", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteMixed5() {
+ helpTestRewriteCriteria("((1=1) AND (1=1)) OR ((1=1) AND (1=2))", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteMixed6() {
+ helpTestRewriteCriteria("((1=2) AND (1=1)) OR ((1=2) AND (1=1))", FALSE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteMixed7() {
+ helpTestRewriteCriteria("((1=1) AND (1=2)) OR ((1=1) AND (1=2))", FALSE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteMixed8() {
+ helpTestRewriteCriteria("((1=2) AND (1=2)) OR ((1=2) AND (1=2))", FALSE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteMixed9() {
+ helpTestRewriteCriteria("((1=1) OR (1=1)) AND ((1=1) OR (1=1))", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteMixed10() {
+ helpTestRewriteCriteria("((1=2) OR (1=1)) AND ((1=1) OR (1=1))", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteMixed11() {
+ helpTestRewriteCriteria("((1=1) OR (1=2)) AND ((1=1) OR (1=1))", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteMixed12() {
+ helpTestRewriteCriteria("((1=1) OR (1=1)) AND ((1=2) OR (1=1))", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteMixed13() {
+ helpTestRewriteCriteria("((1=1) OR (1=1)) AND ((1=1) OR (1=2))", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteMixed14() {
+ helpTestRewriteCriteria("((1=2) OR (1=1)) AND ((1=2) OR (1=1))", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteMixed15() {
+ helpTestRewriteCriteria("((1=1) OR (1=2)) AND ((1=1) OR (1=2))", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteMixed16() {
+ helpTestRewriteCriteria("((1=2) OR (1=2)) AND ((1=2) OR (1=2))", FALSE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteNot1() {
+ helpTestRewriteCriteria("NOT (1=1)", FALSE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteNot2() {
+ helpTestRewriteCriteria("NOT (1=2)", TRUE_STR); //$NON-NLS-1$
+ }
+
+ public void testRewriteNot3() {
+ helpTestRewriteCriteria("NOT (pm1.g1.e1='x')", "NOT (pm1.g1.e1 = 'x')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteDefect1() {
+ helpTestRewriteCriteria("(('DE' = 'LN') AND (null > '2002-01-01')) OR (('DE' = 'DE') AND (pm1.g1.e1 > '9000000'))", "(pm1.g1.e1 > '9000000')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteQueryCriteriaAlwaysTrue() {
+ helpTestRewriteCommand("SELECT e1 FROM pm1.g1 WHERE 0 = 0", //$NON-NLS-1$
+ "SELECT e1 FROM pm1.g1"); //$NON-NLS-1$
+ }
+
+ public void testSubquery1() {
+ helpTestRewriteCommand("SELECT e1 FROM (SELECT e1 FROM pm1.g1 WHERE (1 - 1) = (0 + 0)) AS x", //$NON-NLS-1$
+ "SELECT e1 FROM (SELECT e1 FROM pm1.g1) AS x"); //$NON-NLS-1$
+ }
+
+ public void testExistsSubquery() {
+ helpTestRewriteCommand("SELECT e1 FROM pm1.g1 WHERE EXISTS (SELECT e1 FROM pm1.g2)", //$NON-NLS-1$
+ "SELECT e1 FROM pm1.g1 WHERE EXISTS (SELECT e1 FROM pm1.g2)"); //$NON-NLS-1$
+ }
+
+ public void testCompareSubqueryANY() {
+ helpTestRewriteCommand("SELECT e1 FROM pm1.g1 WHERE '3' = ANY (SELECT e1 FROM pm1.g2)", //$NON-NLS-1$
+ "SELECT e1 FROM pm1.g1 WHERE '3' = SOME (SELECT e1 FROM pm1.g2)"); //$NON-NLS-1$
+ }
+
+ public void testCompareSubquery() {
+ helpTestRewriteCommand("SELECT e1 FROM pm1.g1 WHERE '3' = SOME (SELECT e1 FROM pm1.g2)", //$NON-NLS-1$
+ "SELECT e1 FROM pm1.g1 WHERE '3' = SOME (SELECT e1 FROM pm1.g2)"); //$NON-NLS-1$
+ }
+
+ public void testCompareSubqueryUnknown() {
+ helpTestRewriteCommand("SELECT e1 FROM pm1.g1 WHERE null = SOME (SELECT e1 FROM pm1.g2)", //$NON-NLS-1$
+ "SELECT e1 FROM pm1.g1 WHERE null <> null"); //$NON-NLS-1$
+ }
+
+ public void testINClauseSubquery() {
+ helpTestRewriteCommand("SELECT e1 FROM pm1.g1 WHERE '3' IN (SELECT e1 FROM pm1.g2)", //$NON-NLS-1$
+ "SELECT e1 FROM pm1.g1 WHERE '3' IN (SELECT e1 FROM pm1.g2)"); //$NON-NLS-1$
+ }
+
+ public void testRewriteXMLCriteria1() {
+ helpTestRewriteCriteria("context(pm1.g1.e1, pm1.g1.e1) = convert(5, string)", "context(pm1.g1.e1, pm1.g1.e1) = '5'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteXMLCriteria2() {
+ helpTestRewriteCriteria("context(pm1.g1.e1, convert(5, string)) = 2+3", "context(pm1.g1.e1, '5') = '5'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // HAS Criteria
+ public void testRewriteProcedure1() {
+
+ String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "IF (HAS = CRITERIA ON (vm1.g1.e1))\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\", 1)"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.INSERT_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // HAS Criteria
+ public void testRewriteProcedure2() {
+
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "IF (HAS = CRITERIA ON (vm1.g1.e1))\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "ELSE \n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\", 1)"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT vm1.g1.e1 FROM vm1.g1 WHERE "+FALSE_STR+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.INSERT_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // HAS Criteria
+ public void testRewriteProcedure3() {
+
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "IF (HAS = CRITERIA ON (vm1.g1.e1))\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "ELSE \n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\", 1)"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT vm1.g1.e1 FROM vm1.g1 WHERE "+FALSE_STR+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.INSERT_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ public void testRewriteProcedure4() {
+
+ String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "IF (INPUT.e2 = 1)\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\", 1)"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT vm1.g1.e1 FROM vm1.g1 WHERE "+FALSE_STR+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.INSERT_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // CHANGING
+ public void testRewriteProcedure5() {
+
+ String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "IF (CHANGING.e1 = \"false\")\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Select e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e2);\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "Update vm1.g1 SET e1 = \"String\", e2 =1 where e2 = 10"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // CHANGING
+ public void testRewriteProcedure6() {
+
+ String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "IF (CHANGING.e1 = \"true\")\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "Update vm1.g1 SET e1 = \"String\", e2 =1 where e2 = 10"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // TRANSLATE CRITERIA
+ public void testRewriteProcedure7() {
+
+ String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "IF (CHANGING.e1 = \"true\")\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Select e2 from pm1.g1 where TRANSLATE = CRITERIA ON (vm1.g1.e2);\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "Update vm1.g1 SET e1 = \"String\", e2 =1 where e2 = 10"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT e2 FROM pm1.g1 WHERE pm1.g1.e2 = 10;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // TRANSLATE CRITERIA
+ public void testRewriteProcedure8() {
+
+ String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "IF (CHANGING.e1 = \"true\")\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Select e2 from pm1.g1 where TRANSLATE = CRITERIA ON (vm1.g1.e2) with (vm1.g1.e2 = convert(sqrt(pm1.g1.e2), integer));\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "Update vm1.g1 SET e1 = \"String\", e2 =1 where e2 = 10"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT e2 FROM pm1.g1 WHERE convert(sqrt(pm1.g1.e2), integer) = 10;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // rewrite input/ changing variables
+ public void testRewriteProcedure9() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Declare String var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "if(var1 = 'x' or var1 = 'y')\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Select pm1.g1.e2, Input.e2, CHANGING.e2, CHANGING.e1 from pm1.g1 order by CHANGING.e1;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "INSERT into vm1.g1 (e1) values('x')"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "DECLARE String var1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "IF((var1 = 'x') OR (var1 = 'y'))\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT pm1.g1.e2, null AS E2_0, FALSE AS E2_1, TRUE AS E1 FROM pm1.g1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.INSERT_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
+ public void testRewriteProcedure10() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "Select pm1.g1.e2 from pm1.g1, pm1.g2 where TRANSLATE = CRITERIA ON (e2) WITH (e2 = pm1.g1.e2 + 20);\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "UPDATE vm1.g1 SET e1='x' where e2 = e2 + 50"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1, pm1.g2 WHERE (pm1.g1.e2 + 20) = ((pm1.g1.e2 + 20) + 50);\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // virtual group elements used in procedure in if statement(HAS CRITERIA)
+ public void testRewriteProcedure11() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE string var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "var1 = INPUT.e1;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "UPDATE vm1.g1 SET e1=40"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "DECLARE string var1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "var1 = '40';\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
+ // with complex query transform
+ public void testRewriteProcedure12() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA WITH (x = CONCAT(e1 , 'z'));\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "UPDATE vm1.g3 SET x='x' where x =CONCAT(x , 'y')"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE CONCAT(e1, 'z') = CONCAT(CONCAT(e1, 'z'), 'y');\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
+ // with complex query transform
+ public void testRewriteProcedure13() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA WITH (x = CONCAT(e1 , 'z'), y = convert(CONCAT(e1 , 'k'), integer));\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "UPDATE vm1.g3 SET x='x' where x =CONCAT(x , 'y') and y= 1"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE (CONCAT(e1, 'z') = CONCAT(CONCAT(e1, 'z'), 'y')) AND (convert(CONCAT(e1, 'k'), integer) = 1);\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
+ public void testRewriteProcedure14() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA WITH (e4 = sqrt(e4));\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "UPDATE vm1.g3 SET x='x' where e4= 1"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE sqrt(e4) = 1.0;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
+ public void testRewriteProcedure15() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE = CRITERIA WITH (e4 = e4/50);\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "UPDATE vm1.g3 SET x='x' where y= 1"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE e2 = 0;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
+ public void testRewriteProcedure16() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE CRITERIA;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "UPDATE vm1.g3 SET x='x' where e4= 1"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE e4 = 0.02;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
+ public void testRewriteProcedure17() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE LIKE CRITERIA WITH (e4 = e4/50);\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "UPDATE vm1.g3 SET x='x' where e4= 1"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE "+FALSE_STR+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // Bug 8212 elements in INPUT and CHANGING special groups are cese sensitive
+ public void testRewriteProcedure18() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Select Input.E1, Input.e2, CHANGING.e2, CHANGING.E1 from pm1.g1;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "INSERT into vm1.g1 (e1, E2) values('x', 1)"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT 'x', 1, TRUE, TRUE FROM pm1.g1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.INSERT_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // elements being set in updates are dropped if INPUT var is not available, unless a default is available
+ // Note that this test is a little odd in that it is an update inside of an insert
+ public void testRewriteProcedure19() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "update pm1.g1 set e1=Input.E1, e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "INSERT into vm1.g1 (E2) values(1)"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "UPDATE pm1.g1 SET e1 = 'xyz', e2 = 1, e3 = TRUE;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.INSERT_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // elements being set in updates are dropped if INPUT var is not available, unless a default is supplied
+
+ //this test fails because the default for E1 'xyz' cannot be converted into a integer
+ public void testRewriteProcedure21() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "update pm1.g1 set e1=convert(Input.E1, integer)+INPUT.E2, e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "INSERT into vm1.g1 (E3) values({b'true'})"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "UPDATE pm1.g1 SET e3 = TRUE;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ this.helpFailUpdateProcedure(procedure, userQuery, FakeMetadataObject.Props.INSERT_PROCEDURE);
+ }
+
+ public void testRewriteProcedure21a() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "update pm1.g1 set e1=convert(Input.E1, integer)+INPUT.E2, e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "INSERT into vm1.g1 (E1) values(1)"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "UPDATE pm1.g1 SET e1 = null, e2 = null, e3 = TRUE;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.INSERT_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+
+ // none of input variables on update statement changing
+ public void testRewriteProcedure22() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "update pm1.g1 set e1=convert(Input.E1, integer)+INPUT.E2, e2=Input.e2;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "update vm1.g1 set E3 = {b'true'}"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // none of input variables on update statement changing
+ public void testRewriteProcedure23() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "update pm1.g1 set e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "update vm1.g1 set E1 = 'x'"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ //with an insert, defaults are used
+ public void testRewriteProcedure23a() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "update pm1.g1 set e2=Input.e2, e3=Input.e3;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "INSERT into vm1.g1 (E1) values('x')"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "UPDATE pm1.g1 SET e2 = null, e3 = TRUE;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.INSERT_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // elements being set in updates are dropped if INPUT var is not available
+ public void testRewriteProcedure24() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "UPDATE pm1.g1 SET e2=Input.e2 WHERE TRANSLATE LIKE CRITERIA ON (e1) WITH (e1=concat(pm1.g1.e1, \"%\"));\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "UPDATE vm1.g1 set E2=1 where e2 = 1 and e1 LIKE 'mnopxyz_'"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "UPDATE pm1.g1 SET e2 = 1 WHERE concat(pm1.g1.e1, '%') LIKE 'mnopxyz_';\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // INPUT vars in insert statements replaced by default variable when user's inser ignores values
+ public void testRewriteProcedure25() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "INSERT into pm1.g1 (e1,e2,e3,e4) values (Input.e1, Input.e2, Input.e3, Input.e4);"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "INSERT into vm1.g1 (E2) values (1)"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "INSERT INTO pm1.g1 (e1, e2, e3, e4) VALUES ('xyz', 1, TRUE, 123.456);\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.INSERT_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
+ public void testRewriteProcedure26() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "Select pm1.g1.e2 from pm1.g1, pm1.g2 where TRANSLATE = CRITERIA ON (e2);\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "UPDATE vm1.g1 SET e1='x' where e2 = e2 + 50"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1, pm1.g2 WHERE pm1.g1.e2 = (pm1.g1.e2 + 50);\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
+ public void testRewriteProcedure27() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "Select pm1.g1.e2 from pm1.g1, pm1.g2 where TRANSLATE = CRITERIA ON (e2);\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "UPDATE vm1.g1 SET e1='x' where e2 LIKE 'xyz'"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1, pm1.g2 WHERE "+FALSE_STR+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ /**
+ * Per defect 9380 -
+ * A criteria of the form
+ * (? + 1) < (null)
+ * caused a problem in the QueryRewriter.simplifyMathematicalCriteria method.
+ * At the beginning of the method, the null constant is rewritten so that it
+ * loses it's implicit type conversion to integer, then later on a function
+ * descriptor couldn't be found for the "minus" operation for the two types
+ * integer and MetaMatrix's null type.
+ */
+ public void testRewriteProcedure_9380() {
+
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var2;\n"; //$NON-NLS-1$
+ procedure = procedure + "if((var1 + 1) < length(input.e1))\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "var2 = INPUT.e2;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "UPDATE vm1.g1 SET e2=30"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "DECLARE integer var2;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ //base test. no change is expected
+ public void testRewriteLookupFunction1() {
+ String criteria = "lookup('pm1.g1','e1', 'e2', 'value') = 'ab'"; //$NON-NLS-1$
+ CompareCriteria expected = (CompareCriteria)parseCriteria(criteria, FakeMetadataFactory.example1Cached());
+ helpTestRewriteCriteria(criteria, expected, FakeMetadataFactory.example1Cached());
+ }
+
+ public void testRewriteLookupFunction1b() {
+ helpTestRewriteCriteria("lookup('pm1.g1','e1', 'e2', pm1.g1.e1) = 'ab'", "lookup('pm1.g1','e1', 'e2', pm1.g1.e1) = 'ab'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /** defect 11630 1 should still get rewritten as '1'*/
+ public void testRewriteLookupFunctionCompoundCriteria() {
+ String criteria = "LOOKUP('pm1.g1','e1', 'e2', 'value') IS NULL AND pm1.g1.e1='1'"; //$NON-NLS-1$
+ CompoundCriteria expected = (CompoundCriteria)parseCriteria(criteria, FakeMetadataFactory.example1Cached());
+ helpTestRewriteCriteria("LOOKUP('pm1.g1','e1', 'e2', 'value') IS NULL AND pm1.g1.e1=1", expected, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
+ }
+
+ public void testSelectWithNoFrom() {
+ helpTestRewriteCommand("SELECT 5", "SELECT 5"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ //defect 9822
+ public void testStoredProcedure_9822() throws Exception {
+
+ QueryParser parser = new QueryParser();
+ Command command = parser.parseCommand("exec pm1.sp4(5)"); //$NON-NLS-1$
+
+ // resolve
+ QueryResolver.resolveCommand(command, FakeMetadataFactory.example1Cached());
+
+ // rewrite
+ Command rewriteCommand = QueryRewriter.rewrite(command, null, null, null);
+
+ List parameters = ((StoredProcedure)rewriteCommand).getParameters();
+
+ Iterator iter = parameters.iterator();
+ while(iter.hasNext()){
+ SPParameter param = (SPParameter)iter.next();
+ if(param.getParameterType() == ParameterInfo.IN || param.getParameterType() == ParameterInfo.INOUT){
+ assertTrue(param.getExpression() instanceof Constant);
+ }
+ }
+ }
+
+ public void testRewriteRecursive() {
+ Command c = helpTestRewriteCommand("SELECT e2 FROM vm1.g33", "SELECT e2 FROM vm1.g33"); //$NON-NLS-1$ //$NON-NLS-2$
+ Command innerCommand = (Command) c.getSubCommands().get(0);
+
+ assertEquals("Inner command not rewritten", "SELECT e2 FROM pm1.g1 WHERE e2 = 2", innerCommand.toString()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ }
+
+ public void testRewriteFunctionThrowsEvaluationError() {
+ FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+ Criteria origCrit = parseCriteria("5 / 0 = 5", metadata); //$NON-NLS-1$
+
+ // rewrite
+ try {
+ QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ fail("Expected QueryValidatorException due to divide by 0"); //$NON-NLS-1$
+ } catch(QueryValidatorException e) {
+ assertEquals("Unable to evaluate (5 / 0): Error while evaluating function /", e.getMessage()); //$NON-NLS-1$
+ }
+ }
+
+ public void testRewriteConvertThrowsEvaluationError() {
+ FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+ Criteria origCrit = parseCriteria("convert('x', integer) = 0", metadata); //$NON-NLS-1$
+
+ // rewrite
+ try {
+ QueryRewriter.rewriteCriteria(origCrit, null, null, null);
+ fail("Expected QueryValidatorException due to invalid string"); //$NON-NLS-1$
+ } catch(QueryValidatorException e) {
+ assertEquals("Unable to convert 'x' of type [string] to the expected type [integer].", e.getMessage()); //$NON-NLS-1$
+ }
+ }
+
+ public void testDefect13458() {
+
+ String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "IF (HAS = CRITERIA ON (vm1.g1.e1))\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Select vm1.g1.e1 from vm1.g1 where HAS = CRITERIA ON (vm1.g1.e1);\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "delete from vm1.g1 where e1='1'"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT vm1.g1.e1 FROM vm1.g1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.DELETE_PROCEDURE);
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ public void testRewriteCase1954() {
+ helpTestRewriteCriteria("convert(pm1.g1.e2, string) = '3'", "pm1.g1.e2 = 3"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCase1954a() {
+ helpTestRewriteCriteria("cast(pm1.g1.e2 as string) = '3'", "pm1.g1.e2 = 3"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCase1954b() throws Exception{
+ FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
+
+ // Have to hand-build the criteria, because 3.0 gets parsed as a Float by default
+ // pm1.g1.e4 = 3.0
+ CompareCriteria expected = new CompareCriteria();
+ ElementSymbol leftElement = new ElementSymbol("pm1.g1.e4"); //$NON-NLS-1$
+ Constant constant = new Constant(new Double(3.0), DataTypeManager.DefaultDataClasses.DOUBLE);
+ expected.setLeftExpression(leftElement);
+ expected.setRightExpression(constant);
+ // resolve against metadata
+ QueryResolver.resolveCriteria(expected, metadata);
+
+ helpTestRewriteCriteria("convert(pm1.g1.e4, string) = '3'", expected, metadata); //$NON-NLS-1$
+ }
+
+ public void testRewriteCase1954c() {
+ helpTestRewriteCriteria("convert(pm1.g1.e1, string) = 'x'", "pm1.g1.e1 = 'x'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /** Test some other type besides 'string' has no effect */
+ public void testRewriteCase1954d() {
+ helpTestRewriteCriteria("convert(pm1.g1.e1, timestamp) = {ts '2005-01-03 00:00:00.0'}", "convert(pm1.g1.e1, timestamp) = {ts '2005-01-03 00:00:00.0'}"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /** Test some other type besides 'string' has no effect */
+ public void testRewriteCase1954e() {
+ helpTestRewriteCriteria("convert(pm1.g1.e4, integer) = 2", "convert(pm1.g1.e4, integer) = 2"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /** Check that this fails, x is not convertable to an int */
+ public void testRewriteCase1954f() {
+ helpTestRewriteCriteria("convert(pm1.g1.e2, string) = 'x'", "1 = 0"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /** Check that this returns true, x is not convertable to an int */
+ public void testRewriteCase1954f1() {
+ helpTestRewriteCriteria("convert(pm1.g1.e2, string) != 'x'", "1 = 1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCase1954Set() {
+ helpTestRewriteCriteria("convert(pm1.g1.e2, string) in ('2', '3')", "pm1.g1.e2 IN (2,3)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCase1954SetA() {
+ helpTestRewriteCriteria("convert(pm1.g1.e2, string) in ('2', 'x')", "convert(pm1.g1.e2, string) in ('2', 'x')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCase1954SetB() {
+ helpTestRewriteCriteria("cast(pm1.g1.e2 as string) in ('2', '3')", "pm1.g1.e2 IN (2,3)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCase1954SetC() {
+ helpTestRewriteCriteria("concat(pm1.g1.e2, 'string') in ('2', '3')", "concat(pm1.g1.e2, 'string') in ('2', '3')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCase1954SetD() {
+ helpTestRewriteCriteria("convert(pm1.g1.e2, string) in ('2', pm1.g1.e1)", "convert(pm1.g1.e2, string) in ('2', pm1.g1.e1)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // First WHEN always true, so rewrite as THEN expression
+ public void testRewriteCaseExpr1() {
+ helpTestRewriteCriteria("case when 0=0 then 1 else 2 end = 1", "1 = 1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // First WHEN always false, so rewrite as ELSE expression
+ public void testRewriteCaseExpr2() {
+ helpTestRewriteCriteria("case when 0=1 then 1 else 2 end = 1", "1 = 0"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // First WHEN can't be rewritten, so no changes
+ public void testRewriteCaseExpr3() {
+ helpTestRewriteCriteria("case when 0 = pm1.g1.e2 then 1 else 2 end = 1", "CASE WHEN pm1.g1.e2 = 0 THEN 1 ELSE 2 END = 1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCaseExpr4() {
+ helpTestRewriteCriteria("lookup('pm1.g1', 'e2', 'e1', case when 1=1 then pm1.g1.e1 end) = 0", "lookup('pm1.g1', 'e2', 'e1', pm1.g1.e1) = 0"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // First WHEN always false, so remove it
+ public void testRewriteCaseExpr5() {
+ helpTestRewriteCriteria("case when 0=1 then 1 when 0 = pm1.g1.e2 then 2 else 3 end = 1", "CASE WHEN pm1.g1.e2 = 0 THEN 2 ELSE 3 END = 1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCaseExprForCase5413aFrom502() {
+ helpTestRewriteCriteria("pm1.g2.e1 = case when 0 = pm1.g1.e2 then 2 else 2 end", "pm1.g2.e1 = '2'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCaseExprForCase5413bFrom502() {
+ helpTestRewriteCriteria("case when 0 = pm1.g1.e2 then null else null end IS NULL", TRUE_STR); //$NON-NLS-1$
+ }
+
+
+ public void testRewriteCaseExprForCase5413a() {
+ helpTestRewriteCriteria("pm1.g2.e1 = case when 0 = pm1.g1.e2 then 2 else 2 end", "pm1.g2.e1 = '2'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCaseExprForCase5413b() {
+ helpTestRewriteCriteria("case when 0 = pm1.g1.e2 then null else null end IS NULL", TRUE_STR); //$NON-NLS-1$
+ }
+
+ // First WHEN always true, so rewrite as THEN expression
+ public void testRewriteSearchedCaseExpr1() {
+ helpTestRewriteCriteria("case 0 when 0 then 1 else 2 end = 1", "1 = 1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // First WHEN always false, so rewrite as ELSE expression
+ public void testRewriteSearchedCaseExpr2() {
+ helpTestRewriteCriteria("case 0 when 1 then 1 else 2 end = 1", "1 = 0"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteSearchedCaseExpr3() {
+ helpTestRewriteCriteria("case 0 when pm1.g1.e2 then 1 else 2 end = 1", "CASE WHEN pm1.g1.e2 = 0 THEN 1 ELSE 2 END = 1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteSearchedCaseExpr4() {
+ String criteria = "lookup('pm1.g1', 'e2', 'e1', null) = 0"; //$NON-NLS-1$
+ CompareCriteria expected = (CompareCriteria)parseCriteria(criteria, FakeMetadataFactory.example1Cached());
+ helpTestRewriteCriteria("lookup('pm1.g1', 'e2', 'e1', case 0 when 1 then pm1.g1.e1 end) = 0", expected, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
+ }
+
+ // First WHEN always false, so remove it
+ public void testRewriteSearchedCaseExpr5() {
+ helpTestRewriteCriteria("case 0 when 1 then 1 when pm1.g1.e2 then 2 else 3 end = 1", "CASE WHEN pm1.g1.e2 = 0 THEN 2 ELSE 3 END = 1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDefect16879_1(){
+ helpTestRewriteCommand("SELECT decodestring(e1, 'a, b') FROM pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDefect16879_2(){
+ helpTestRewriteCommand("SELECT decodestring(e1, 'a, b, c, d') FROM pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' WHEN e1 = 'c' THEN 'd' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDefect16879_3(){
+ helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b') FROM pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDefect16879_4(){
+ helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b, c, d') FROM pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' WHEN e1 = 'c' THEN 'd' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDefect16879_5(){
+ helpTestRewriteCommand("SELECT decodeinteger(e1, 'null, b, c, d') FROM pm1.g1", "SELECT CASE WHEN e1 IS NULL THEN 'b' WHEN e1 = 'c' THEN 'd' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDefect16879_6(){
+ helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b, null, d') FROM pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' WHEN e1 IS NULL THEN 'd' ELSE e1 END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testDefect16879_7(){
+ helpTestRewriteCommand("SELECT decodeinteger(e1, 'a, b, null, d, e') FROM pm1.g1", "SELECT CASE WHEN e1 = 'a' THEN 'b' WHEN e1 IS NULL THEN 'd' ELSE 'e' END FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
public void testCaseExpressionThatResolvesToNull() {
String sqlBefore = "SELECT CASE 'x' WHEN 'Old Inventory System' THEN NULL WHEN 'New Inventory System' THEN NULL END"; //$NON-NLS-1$
String sqlAfter = "SELECT null"; //$NON-NLS-1$
Command cmd = helpTestRewriteCommand( sqlBefore, sqlAfter );
- ExpressionSymbol es = (ExpressionSymbol)cmd.getProjectedSymbols().get(0);
+ DerivedColumn es = (DerivedColumn)cmd.getProjectedSymbols().get(0);
assertEquals( DataTypeManager.DefaultDataClasses.STRING, es.getType() );
}
-
- //note that the env is now treated as deterministic, however it is really only deterministic within a session
- public void testRewriteExecEnv() throws Exception {
- Command command = QueryParser.getQueryParser().parseCommand("exec pm1.sq2(env('sessionid'))"); //$NON-NLS-1$
-
- QueryResolver.resolveCommand(command, FakeMetadataFactory.example1Cached());
-
- CommandContext context = new CommandContext();
- Properties props = new Properties();
- props.setProperty(ContextProperties.SESSION_ID, "1"); //$NON-NLS-1$
- context.setEnvironmentProperties(props);
- Command rewriteCommand = QueryRewriter.rewrite(command, null, null, context);
-
- assertEquals("SELECT e1, e2 FROM pm1.g1 WHERE e1 = '1'", rewriteCommand.toString()); //$NON-NLS-1$
- }
-
- public void testRewriteExecCase6455() throws Exception {
- Command command = QueryParser.getQueryParser().parseCommand("exec pm1.sq2(env('sessionid')) OPTION PLANONLY DEBUG"); //$NON-NLS-1$
-
- QueryResolver.resolveCommand(command, FakeMetadataFactory.example1Cached());
-
- CommandContext context = new CommandContext();
- Properties props = new Properties();
- props.setProperty(ContextProperties.SESSION_ID, "1"); //$NON-NLS-1$
- context.setEnvironmentProperties(props);
- Command rewriteCommand = QueryRewriter.rewrite(command, null, null, context);
-
- assertEquals("SELECT e1, e2 FROM pm1.g1 WHERE e1 = '1' OPTION PLANONLY DEBUG", rewriteCommand.toString()); //$NON-NLS-1$
- }
-
-
- public void testRewriteNestedFunctions() {
- helpTestRewriteCommand("SELECT e1 FROM pm1.g1 where convert(parsedate(e1, 'yyyy-MM-dd'), string) = '2006-07-01'", "SELECT e1 FROM pm1.g1 WHERE e1 = '2006-07-01'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteWithReference() {
- helpTestRewriteCommand("SELECT e1 FROM pm1.g1 where parsetimestamp(e1, 'yyyy-MM-dd') != ?", "SELECT e1 FROM pm1.g1 WHERE e1 <> formattimestamp(?, 'yyyy-MM-dd')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewiteJoinCriteria() {
- helpTestRewriteCommand("SELECT pm1.g1.e1 FROM pm1.g1 inner join pm1.g2 on (pm1.g1.e1 = null)", "SELECT pm1.g1.e1 FROM pm1.g1 INNER JOIN pm1.g2 ON 1 = 0"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewiteCompoundCriteria() {
- helpTestRewriteCriteria("(pm1.g1.e1 = 1 and pm1.g1.e2 = 2) and (pm1.g1.e3 = 1 and pm1.g1.e4 = 2)", "(pm1.g1.e1 = '1') AND (pm1.g1.e2 = 2) AND (pm1.g1.e3 = TRUE) AND (pm1.g1.e4 = 2.0)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteWhile() throws Exception {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "while (1 = 1)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\", 1)"; //$NON-NLS-1$
-
- QueryMetadataInterface metadata = FakeMetadataFactory.exampleUpdateProc(FakeMetadataObject.Props.INSERT_PROCEDURE, procedure);
-
- QueryParser parser = new QueryParser();
- Command userCommand = parser.parseCommand(userQuery);
- QueryResolver.resolveCommand(userCommand, metadata);
-
- try {
- QueryRewriter.rewrite(userCommand, null, metadata, null);
- fail("exception expected"); //$NON-NLS-1$
- } catch (QueryValidatorException e) {
- assertEquals("Infinite loop detected, procedure will not be executed.", e.getMessage()); //$NON-NLS-1$
- }
-
- }
-
- public void testRewriteWhile1() {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "while (1 = 0)\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select vm1.g1.e1 from vm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\", 1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.INSERT_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- /**
- * Tests that VariableSubstitutionVisitor does not cause an NPE on count(*)
- */
- public void testRewriteProcedureWithCount() {
-
- String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "Select count(*) from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\", 1)"; //$NON-NLS-1$
-
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT COUNT(*) FROM pm1.g1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getReWrittenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.INSERT_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
- }
-
- /**
- * Test to ensure the update changing list retains e1 = ?
- */
- public void testVariableSubstitutionVisitor() throws Exception {
- String procedure1 = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure1 += "BEGIN\n"; //$NON-NLS-1$
- procedure1 += "DECLARE string var1 = INPUT.e1;\n"; //$NON-NLS-1$
- procedure1 += "ROWS_UPDATED = UPDATE vm1.g2 SET e1=var1;\n"; //$NON-NLS-1$
- procedure1 += "END"; //$NON-NLS-1$
-
- String procedure2 = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure2 += "BEGIN\n"; //$NON-NLS-1$
- procedure2 += "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure2 += "IF (INPUT.e1 = 1)\n"; //$NON-NLS-1$
- procedure2 += "ROWS_UPDATED = 5;\n"; //$NON-NLS-1$
- procedure2 += "ELSE\n"; //$NON-NLS-1$
- procedure2 += "ROWS_UPDATED = 5;\n"; //$NON-NLS-1$
- procedure2 += "END"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1 = 'x' WHERE e2 = 5"; //$NON-NLS-1$
-
- FakeMetadataFacade metadata = FakeMetadataFactory.exampleUpdateProc(FakeMetadataObject.Props.UPDATE_PROCEDURE, procedure1, procedure2);
-
- Update command = (Update)helpTestRewriteCommand(userUpdateStr, userUpdateStr, metadata);
-
- String expected = "CREATE PROCEDURE\nBEGIN\nDECLARE string var1 = 'x';\nROWS_UPDATED = UPDATE vm1.g2 SET e1 = var1;\nEND"; //$NON-NLS-1$
-
- assertEquals(expected, command.getSubCommand().toString());
- }
-
- public void testRemoveEmptyLoop() {
- String procedure1 = "CREATE virtual PROCEDURE "; //$NON-NLS-1$
- procedure1 += "BEGIN\n"; //$NON-NLS-1$
- procedure1 += "loop on (select e1 from pm1.g1) as myCursor\n"; //$NON-NLS-1$
- procedure1 += "begin\n"; //$NON-NLS-1$
- procedure1 += "end\n"; //$NON-NLS-1$
- procedure1 += "select e1 from pm1.g1;\n"; //$NON-NLS-1$
- procedure1 += "END"; //$NON-NLS-1$
-
- String expected = "CREATE VIRTUAL PROCEDURE\nBEGIN\nSELECT e1 FROM pm1.g1;\nEND"; //$NON-NLS-1$
-
- helpTestRewriteCommand(procedure1, expected);
- }
-
- public void testRewriteDeclare() {
- String procedure1 = "CREATE virtual PROCEDURE "; //$NON-NLS-1$
- procedure1 += "BEGIN\n"; //$NON-NLS-1$
- procedure1 += "declare integer x = 1 + 1;\n"; //$NON-NLS-1$
- procedure1 += "END"; //$NON-NLS-1$
-
- String expected = "CREATE VIRTUAL PROCEDURE\nBEGIN\nDECLARE integer x = 2;\nEND"; //$NON-NLS-1$
-
- helpTestRewriteCommand(procedure1, expected);
- }
-
- public void testRewriteUnionJoin() {
- String sql = "select pm1.g1.e1 from pm1.g1 union join pm1.g2 where g1.e1 = 1"; //$NON-NLS-1$
- String expected = "SELECT pm1.g1.e1 FROM pm1.g1 FULL OUTER JOIN pm1.g2 ON 1 = 0 WHERE g1.e1 = '1'"; //$NON-NLS-1$
-
- helpTestRewriteCommand(sql, expected);
- }
-
- public void testRewriteNonNullDependentFunction() {
- helpTestRewriteCriteria("pm1.g1.e1 = concat(null, pm1.g1.e2)", "null <> null"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteInWithNull() {
- helpTestRewriteCriteria("convert(null, string) in (pm1.g1.e1, pm1.g1.e2)", "null <> null"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteXMLCriteriaCases5630And5640() {
- helpTestRewriteCommand("select * from xmltest.doc1 where node1 = null", "SELECT * FROM xmltest.doc1 WHERE node1 = null"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteCorrelatedSubqueryInHaving() {
- String sql = "select pm1.g1.e1 from pm1.g1 group by pm1.g1.e1 having pm1.g1.e1 in (select pm1.g1.e1 from pm1.g2)"; //$NON-NLS-1$
- String expected = "SELECT pm1.g1.e1 FROM pm1.g1 GROUP BY pm1.g1.e1 HAVING pm1.g1.e1 IN (SELECT pm1.g1.e1 FROM pm1.g2)"; //$NON-NLS-1$
-
- Query query = (Query)helpTestRewriteCommand(sql, expected);
-
- List refs = new LinkedList();
-
- CorrelatedReferenceCollectorVisitor.collectReferences(query, Arrays.asList(new Object[] {new GroupSymbol("pm1.g1")}), refs);//$NON-NLS-1$
-
- assertEquals(1, refs.size());
- }
-
- public void testRewriteSelectInto() {
- String sql = "select distinct pm1.g1.e1 into #temp from pm1.g1"; //$NON-NLS-1$
- String expected = "SELECT DISTINCT pm1.g1.e1 INTO #temp FROM pm1.g1"; //$NON-NLS-1$
-
- helpTestRewriteCommand(sql, expected);
- }
-
- /**
- * Accounts for type change with duplicate names
- */
- public void testRewriteSelectInto1() {
- String sql = "select distinct e2, e2, e3, e4 into pm1.g1 from pm1.g2"; //$NON-NLS-1$
- String expected = "SELECT PM1_G1_1.E2 AS E2, PM1_G1_1.E2_0, PM1_G1_1.E3, PM1_G1_1.E4 INTO pm1.g1 FROM (SELECT DISTINCT e2, e2 AS E2_0, e3, e4 FROM pm1.g2) AS pm1_g1_1"; //$NON-NLS-1$
-
- helpTestRewriteCommand(sql, expected);
- }
-
- public void testUnionQueryNullInOneBranch() throws Exception {
- verifyProjectedTypesOnUnionBranches("SELECT e1, e2 FROM pm1.g1 UNION ALL SELECT e1, null FROM pm1.g2", //$NON-NLS-1$
- new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.INTEGER });
- }
-
- public void testUnionQueryNullInOneBranch2() throws Exception {
- verifyProjectedTypesOnUnionBranches("SELECT e1, e2 FROM pm1.g1 UNION ALL SELECT e1, e2 FROM pm1.g2 UNION ALL SELECT e1, null FROM pm1.g2", //$NON-NLS-1$
- new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.INTEGER });
- }
-
- public void testUnionQueryNullInOneBranch3() throws Exception {
- verifyProjectedTypesOnUnionBranches("SELECT e1, null FROM pm1.g1 UNION ALL SELECT e1, null FROM pm1.g2 UNION ALL SELECT e1, e2 FROM pm1.g2", //$NON-NLS-1$
- new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.INTEGER });
- }
-
- public void testUnionQueryNullInAllBranches() throws Exception {
- verifyProjectedTypesOnUnionBranches("SELECT e1, null FROM pm1.g1 UNION ALL SELECT e1, null FROM pm1.g2 UNION ALL SELECT e1, null FROM pm1.g2", //$NON-NLS-1$
- new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.STRING });
- }
-
- public void testUnionQueryWithTypeConversion() throws Exception {
- verifyProjectedTypesOnUnionBranches("SELECT e1 FROM pm1.g1 UNION ALL SELECT e2 FROM pm1.g2", //$NON-NLS-1$
- new Class[] { DataTypeManager.DefaultDataClasses.STRING});
- }
-
- private void verifyProjectedTypesOnUnionBranches(String unionQuery, Class[] types) throws QueryValidatorException, QueryParserException, QueryResolverException, MetaMatrixComponentException {
- SetQuery union = (SetQuery)QueryParser.getQueryParser().parseCommand(unionQuery);
- QueryResolver.resolveCommand(union, FakeMetadataFactory.example1Cached());
-
- union = (SetQuery)QueryRewriter.rewrite(union, null, FakeMetadataFactory.example1Cached(), null);
-
- for (QueryCommand query : union.getQueryCommands()) {
- List projSymbols = query.getProjectedSymbols();
- for(int i=0; i<projSymbols.size(); i++) {
- assertEquals("Found type mismatch at column " + i, types[i], ((SingleElementSymbol) projSymbols.get(i)).getType()); //$NON-NLS-1$
- }
- }
- }
-
- public void testRewiteOrderBy() {
- helpTestRewriteCommand("SELECT 1+1 as a FROM pm1.g1 order by a", "SELECT 2 AS a FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewiteOrderBy1() {
- helpTestRewriteCommand("SELECT 1+1 as a FROM pm1.g1 union select pm1.g2.e1 from pm1.g2 order by a", "SELECT '2' AS a FROM pm1.g1 UNION SELECT pm1.g2.e1 FROM pm1.g2 ORDER BY a"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * The rewrite creates inline view to do the type conversion.
- *
- * It also ensures that all project symbols are uniquely named in the inline view
- */
- public void testSelectIntoWithOrderByAndTypeConversion() throws Exception {
- String procedure = "CREATE VIRTUAL PROCEDURE\n"; //$NON-NLS-1$
- procedure += "BEGIN\n"; //$NON-NLS-1$
- procedure += "CREATE local temporary table temp (x string, y integer, z integer);\n"; //$NON-NLS-1$
- procedure += "Select pm1.g1.e2, 1 as x, 2 as x into temp from pm1.g1 order by pm1.g1.e2 limit 1;\n"; //$NON-NLS-1$
- procedure += "Select x from temp;\n"; //$NON-NLS-1$
- procedure += "END\n"; //$NON-NLS-1$
-
- helpTestRewriteCommand(procedure, "CREATE VIRTUAL PROCEDURE\nBEGIN\nCREATE LOCAL TEMPORARY TABLE temp (x string, y integer, z integer);\nSELECT TEMP_1.E2 AS E2, TEMP_1.X, TEMP_1.X_0 INTO temp FROM (SELECT pm1.g1.e2, 1 AS x, 2 AS X_0 FROM pm1.g1 ORDER BY pm1.g1.e2 LIMIT 1) AS temp_1;\nSELECT x FROM temp;\nEND"); //$NON-NLS-1$
- }
-
-
- public void testInsertWithQuery() throws Exception {
- String sql = "insert into pm1.g1 select e1, e2, e3, e4 from pm1.g2 union select e1, e2, e3, e4 from pm1.g2"; //$NON-NLS-1$
-
- helpTestRewriteCommand(sql, "SELECT PM1_G1_1.E1, PM1_G1_1.E2, PM1_G1_1.E3, PM1_G1_1.E4 INTO pm1.g1 FROM (SELECT e1, e2, e3, e4 FROM pm1.g2 UNION SELECT e1, e2, e3, e4 FROM pm1.g2) AS pm1_g1_1"); //$NON-NLS-1$
- }
-
- public void testRewriteNot() {
- helpTestRewriteCriteria("not(not(pm1.g1.e1 = 1 + 1))", "pm1.g1.e1 = '2'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteQueryWithNoFrom() {
- String sql = "select 1 as a order by a"; //$NON-NLS-1$
-
- helpTestRewriteCommand(sql, "SELECT 1 AS a"); //$NON-NLS-1$
- }
-
- public void testOrderByDuplicateRemoval() {
- String sql = "SELECT pm1.g1.e1, pm1.g1.e1 as c1234567890123456789012345678901234567890 FROM pm1.g1 ORDER BY c1234567890123456789012345678901234567890, e1 "; //$NON-NLS-1$
- helpTestRewriteCommand(sql, "SELECT pm1.g1.e1, pm1.g1.e1 AS c1234567890123456789012345678901234567890 FROM pm1.g1 ORDER BY c1234567890123456789012345678901234567890"); //$NON-NLS-1$
- }
-
- /**
- * Case 4814
- */
- public void testVirtualRightOuterJoinSwap() throws Exception {
- String sql = "SELECT sa.IntKey AS sa_IntKey, mb.IntKey AS mb_IntKey FROM (select * from BQT1.smalla) sa RIGHT OUTER JOIN (select BQT1.mediumb.intkey from BQT1.mediumb) mb ON sa.IntKey = mb.IntKey"; //$NON-NLS-1$
- helpTestRewriteCommand(sql, "SELECT sa.IntKey AS sa_IntKey, mb.IntKey AS mb_IntKey FROM (SELECT BQT1.mediumb.intkey FROM BQT1.mediumb) AS mb LEFT OUTER JOIN (SELECT * FROM BQT1.smalla) AS sa ON sa.IntKey = mb.IntKey", FakeMetadataFactory.exampleBQTCached()); //$NON-NLS-1$
- }
-
- /**
- * Case 4814
- */
- public void testVirtualRightOuterJoinSwap1() throws Exception {
- String sql = "SELECT sa.IntKey AS sa_IntKey, mb.IntKey AS mb_IntKey FROM ((select * from BQT1.smalla) sa inner join BQT1.smallb on sa.intkey = smallb.intkey) RIGHT OUTER JOIN (select BQT1.mediumb.intkey from BQT1.mediumb) mb ON sa.IntKey = mb.IntKey"; //$NON-NLS-1$
- helpTestRewriteCommand(sql, "SELECT sa.IntKey AS sa_IntKey, mb.IntKey AS mb_IntKey FROM (SELECT BQT1.mediumb.intkey FROM BQT1.mediumb) AS mb LEFT OUTER JOIN ((SELECT * FROM BQT1.smalla) AS sa INNER JOIN BQT1.smallb ON sa.intkey = smallb.intkey) ON sa.IntKey = mb.IntKey", FakeMetadataFactory.exampleBQTCached()); //$NON-NLS-1$
- }
-
- public void testRewriteConcat2() {
- helpTestRewriteCriteria("concat2('a','b') = 'ab'", "1 = 1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteConcat2_1() {
- helpTestRewriteCriteria("concat2(null, null) is null", "1 = 1"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteConcat2_2() throws Exception {
- helpTestRewriteCriteria("concat2(pm1.g1.e1, null) = 'xyz'", "CASE WHEN pm1.g1.e1 IS NULL THEN null ELSE concat(ifnull(pm1.g1.e1, ''), '') END = 'xyz'", true); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteConcat2_3() throws Exception {
- helpTestRewriteCriteria("concat2(pm1.g1.e1, convert(pm1.g1.e2, string)) = 'xyz'", "CASE WHEN (pm1.g1.e1 IS NULL) AND (convert(pm1.g1.e2, string) IS NULL) THEN null ELSE concat(ifnull(pm1.g1.e1, ''), ifnull(convert(pm1.g1.e2, string), '')) END = 'xyz'", true); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewriteConcat2_4() throws Exception {
- helpTestRewriteCriteria("concat2('a', pm1.g1.e1) = 'xyz'", "concat('a', ifnull(pm1.g1.e1, '')) = 'xyz'"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRewiteEvaluatableAggregate() {
- helpTestRewriteCommand("select pm1.g1.e1, max(1) from pm1.g1", "SELECT pm1.g1.e1, 1 FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ //note that the env is now treated as deterministic, however it is really only deterministic within a session
+ public void testRewriteExecEnv() throws Exception {
+ Command command = QueryParser.getQueryParser().parseCommand("exec pm1.sq2(env('sessionid'))"); //$NON-NLS-1$
+
+ QueryResolver.resolveCommand(command, FakeMetadataFactory.example1Cached());
+
+ CommandContext context = new CommandContext();
+ Properties props = new Properties();
+ props.setProperty(ContextProperties.SESSION_ID, "1"); //$NON-NLS-1$
+ context.setEnvironmentProperties(props);
+ Command rewriteCommand = QueryRewriter.rewrite(command, null, null, context);
+
+ assertEquals("SELECT e1, e2 FROM pm1.g1 WHERE e1 = '1'", rewriteCommand.toString()); //$NON-NLS-1$
}
+
+ public void testRewriteExecCase6455() throws Exception {
+ Command command = QueryParser.getQueryParser().parseCommand("exec pm1.sq2(env('sessionid')) OPTION PLANONLY DEBUG"); //$NON-NLS-1$
+
+ QueryResolver.resolveCommand(command, FakeMetadataFactory.example1Cached());
+
+ CommandContext context = new CommandContext();
+ Properties props = new Properties();
+ props.setProperty(ContextProperties.SESSION_ID, "1"); //$NON-NLS-1$
+ context.setEnvironmentProperties(props);
+ Command rewriteCommand = QueryRewriter.rewrite(command, null, null, context);
+
+ assertEquals("SELECT e1, e2 FROM pm1.g1 WHERE e1 = '1' OPTION PLANONLY DEBUG", rewriteCommand.toString()); //$NON-NLS-1$
+ }
+
+
+ public void testRewriteNestedFunctions() {
+ helpTestRewriteCommand("SELECT e1 FROM pm1.g1 where convert(parsedate(e1, 'yyyy-MM-dd'), string) = '2006-07-01'", "SELECT e1 FROM pm1.g1 WHERE e1 = '2006-07-01'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ public void testRewriteWithReference() {
+ helpTestRewriteCommand("SELECT e1 FROM pm1.g1 where parsetimestamp(e1, 'yyyy-MM-dd') != ?", "SELECT e1 FROM pm1.g1 WHERE e1 <> formattimestamp(?, 'yyyy-MM-dd')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewiteJoinCriteria() {
+ helpTestRewriteCommand("SELECT pm1.g1.e1 FROM pm1.g1 inner join pm1.g2 on (pm1.g1.e1 = null)", "SELECT pm1.g1.e1 FROM pm1.g1 INNER JOIN pm1.g2 ON 1 = 0"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewiteCompoundCriteria() {
+ helpTestRewriteCriteria("(pm1.g1.e1 = 1 and pm1.g1.e2 = 2) and (pm1.g1.e3 = 1 and pm1.g1.e4 = 2)", "(pm1.g1.e1 = '1') AND (pm1.g1.e2 = 2) AND (pm1.g1.e3 = TRUE) AND (pm1.g1.e4 = 2.0)"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteWhile() throws Exception {
+
+ String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "while (1 = 1)\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Select vm1.g1.e1 from vm1.g1;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\", 1)"; //$NON-NLS-1$
+
+ QueryMetadataInterface metadata = FakeMetadataFactory.exampleUpdateProc(FakeMetadataObject.Props.INSERT_PROCEDURE, procedure);
+
+ QueryParser parser = new QueryParser();
+ Command userCommand = parser.parseCommand(userQuery);
+ QueryResolver.resolveCommand(userCommand, metadata);
+
+ try {
+ QueryRewriter.rewrite(userCommand, null, metadata, null);
+ fail("exception expected"); //$NON-NLS-1$
+ } catch (QueryValidatorException e) {
+ assertEquals("Infinite loop detected, procedure will not be executed.", e.getMessage()); //$NON-NLS-1$
+ }
+
+ }
+
+ public void testRewriteWhile1() {
+
+ String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "while (1 = 0)\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Select vm1.g1.e1 from vm1.g1;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\", 1)"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.INSERT_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ /**
+ * Tests that VariableSubstitutionVisitor does not cause an NPE on count(*)
+ */
+ public void testRewriteProcedureWithCount() {
+
+ String procedure = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "Select count(*) from pm1.g1;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userQuery = "Insert into vm1.g1 (e1, e2) values (\"String\", 1)"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "SELECT COUNT(*) FROM pm1.g1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getReWrittenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.INSERT_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc, procReturned); //$NON-NLS-1$
+ }
+
+ /**
+ * Test to ensure the update changing list retains e1 = ?
+ */
+ public void testVariableSubstitutionVisitor() throws Exception {
+ String procedure1 = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure1 += "BEGIN\n"; //$NON-NLS-1$
+ procedure1 += "DECLARE string var1 = INPUT.e1;\n"; //$NON-NLS-1$
+ procedure1 += "ROWS_UPDATED = UPDATE vm1.g2 SET e1=var1;\n"; //$NON-NLS-1$
+ procedure1 += "END"; //$NON-NLS-1$
+
+ String procedure2 = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure2 += "BEGIN\n"; //$NON-NLS-1$
+ procedure2 += "DECLARE integer var1;\n"; //$NON-NLS-1$
+ procedure2 += "IF (INPUT.e1 = 1)\n"; //$NON-NLS-1$
+ procedure2 += "ROWS_UPDATED = 5;\n"; //$NON-NLS-1$
+ procedure2 += "ELSE\n"; //$NON-NLS-1$
+ procedure2 += "ROWS_UPDATED = 5;\n"; //$NON-NLS-1$
+ procedure2 += "END"; //$NON-NLS-1$
+
+ String userUpdateStr = "UPDATE vm1.g1 SET e1 = 'x' WHERE e2 = 5"; //$NON-NLS-1$
+
+ FakeMetadataFacade metadata = FakeMetadataFactory.exampleUpdateProc(FakeMetadataObject.Props.UPDATE_PROCEDURE, procedure1, procedure2);
+
+ Update command = (Update)helpTestRewriteCommand(userUpdateStr, userUpdateStr, metadata);
+
+ String expected = "CREATE PROCEDURE\nBEGIN\nDECLARE string var1 = 'x';\nROWS_UPDATED = UPDATE vm1.g2 SET e1 = var1;\nEND"; //$NON-NLS-1$
+
+ assertEquals(expected, command.getSubCommand().toString());
+ }
+
+ public void testRemoveEmptyLoop() {
+ String procedure1 = "CREATE virtual PROCEDURE "; //$NON-NLS-1$
+ procedure1 += "BEGIN\n"; //$NON-NLS-1$
+ procedure1 += "loop on (select e1 from pm1.g1) as myCursor\n"; //$NON-NLS-1$
+ procedure1 += "begin\n"; //$NON-NLS-1$
+ procedure1 += "end\n"; //$NON-NLS-1$
+ procedure1 += "select e1 from pm1.g1;\n"; //$NON-NLS-1$
+ procedure1 += "END"; //$NON-NLS-1$
+
+ String expected = "CREATE VIRTUAL PROCEDURE\nBEGIN\nSELECT e1 FROM pm1.g1;\nEND"; //$NON-NLS-1$
+
+ helpTestRewriteCommand(procedure1, expected);
+ }
+
+ public void testRewriteDeclare() {
+ String procedure1 = "CREATE virtual PROCEDURE "; //$NON-NLS-1$
+ procedure1 += "BEGIN\n"; //$NON-NLS-1$
+ procedure1 += "declare integer x = 1 + 1;\n"; //$NON-NLS-1$
+ procedure1 += "END"; //$NON-NLS-1$
+
+ String expected = "CREATE VIRTUAL PROCEDURE\nBEGIN\nDECLARE integer x = 2;\nEND"; //$NON-NLS-1$
+
+ helpTestRewriteCommand(procedure1, expected);
+ }
+
+ public void testRewriteUnionJoin() {
+ String sql = "select pm1.g1.e1 from pm1.g1 union join pm1.g2 where g1.e1 = 1"; //$NON-NLS-1$
+ String expected = "SELECT pm1.g1.e1 FROM pm1.g1 FULL OUTER JOIN pm1.g2 ON 1 = 0 WHERE g1.e1 = '1'"; //$NON-NLS-1$
+
+ helpTestRewriteCommand(sql, expected);
+ }
+
+ public void testRewriteNonNullDependentFunction() {
+ helpTestRewriteCriteria("pm1.g1.e1 = concat(null, pm1.g1.e2)", "null <> null"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteInWithNull() {
+ helpTestRewriteCriteria("convert(null, string) in (pm1.g1.e1, pm1.g1.e2)", "null <> null"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteXMLCriteriaCases5630And5640() {
+ helpTestRewriteCommand("select * from xmltest.doc1 where node1 = null", "SELECT * FROM xmltest.doc1 WHERE node1 = null"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteCorrelatedSubqueryInHaving() {
+ String sql = "select pm1.g1.e1 from pm1.g1 group by pm1.g1.e1 having pm1.g1.e1 in (select pm1.g1.e1 from pm1.g2)"; //$NON-NLS-1$
+ String expected = "SELECT pm1.g1.e1 FROM pm1.g1 GROUP BY pm1.g1.e1 HAVING pm1.g1.e1 IN (SELECT pm1.g1.e1 FROM pm1.g2)"; //$NON-NLS-1$
+
+ Query query = (Query)helpTestRewriteCommand(sql, expected);
+
+ List refs = new LinkedList();
+
+ CorrelatedReferenceCollectorVisitor.collectReferences(query, Arrays.asList(new Object[] {new GroupSymbol("pm1.g1")}), refs);//$NON-NLS-1$
+
+ assertEquals(1, refs.size());
+ }
+
+ public void testRewriteSelectInto() {
+ String sql = "select distinct pm1.g1.e1 into #temp from pm1.g1"; //$NON-NLS-1$
+ String expected = "SELECT DISTINCT pm1.g1.e1 INTO #temp FROM pm1.g1"; //$NON-NLS-1$
+
+ helpTestRewriteCommand(sql, expected);
+ }
+
+ /**
+ * Accounts for type change with duplicate names
+ */
+ public void testRewriteSelectInto1() {
+ String sql = "select distinct e2, e2, e3, e4 into pm1.g1 from pm1.g2"; //$NON-NLS-1$
+ String expected = "SELECT PM1_G1_1.E2 AS E2, PM1_G1_1.E2_0, PM1_G1_1.E3, PM1_G1_1.E4 INTO pm1.g1 FROM (SELECT DISTINCT e2, e2 AS E2_0, e3, e4 FROM pm1.g2) AS pm1_g1_1"; //$NON-NLS-1$
+
+ helpTestRewriteCommand(sql, expected);
+ }
+
+ public void testUnionQueryNullInOneBranch() throws Exception {
+ verifyProjectedTypesOnUnionBranches("SELECT e1, e2 FROM pm1.g1 UNION ALL SELECT e1, null FROM pm1.g2", //$NON-NLS-1$
+ new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.INTEGER });
+ }
+
+ public void testUnionQueryNullInOneBranch2() throws Exception {
+ verifyProjectedTypesOnUnionBranches("SELECT e1, e2 FROM pm1.g1 UNION ALL SELECT e1, e2 FROM pm1.g2 UNION ALL SELECT e1, null FROM pm1.g2", //$NON-NLS-1$
+ new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.INTEGER });
+ }
+
+ public void testUnionQueryNullInOneBranch3() throws Exception {
+ verifyProjectedTypesOnUnionBranches("SELECT e1, null FROM pm1.g1 UNION ALL SELECT e1, null FROM pm1.g2 UNION ALL SELECT e1, e2 FROM pm1.g2", //$NON-NLS-1$
+ new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.INTEGER });
+ }
+
+ public void testUnionQueryNullInAllBranches() throws Exception {
+ verifyProjectedTypesOnUnionBranches("SELECT e1, null FROM pm1.g1 UNION ALL SELECT e1, null FROM pm1.g2 UNION ALL SELECT e1, null FROM pm1.g2", //$NON-NLS-1$
+ new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.STRING });
+ }
+
+ public void testUnionQueryWithTypeConversion() throws Exception {
+ verifyProjectedTypesOnUnionBranches("SELECT e1 FROM pm1.g1 UNION ALL SELECT e2 FROM pm1.g2", //$NON-NLS-1$
+ new Class[] { DataTypeManager.DefaultDataClasses.STRING});
+ }
+
+ private void verifyProjectedTypesOnUnionBranches(String unionQuery, Class[] types) throws QueryValidatorException, QueryParserException, QueryResolverException, MetaMatrixComponentException {
+ SetQuery union = (SetQuery)QueryParser.getQueryParser().parseCommand(unionQuery);
+ QueryResolver.resolveCommand(union, FakeMetadataFactory.example1Cached());
+
+ union = (SetQuery)QueryRewriter.rewrite(union, null, FakeMetadataFactory.example1Cached(), null);
+
+ for (QueryCommand query : union.getQueryCommands()) {
+ List projSymbols = query.getProjectedSymbols();
+ for(int i=0; i<projSymbols.size(); i++) {
+ assertEquals("Found type mismatch at column " + i, types[i], ((SingleElementSymbol) projSymbols.get(i)).getType()); //$NON-NLS-1$
+ }
+ }
+ }
+
+ public void testRewiteOrderBy() {
+ helpTestRewriteCommand("SELECT 1+1 as a FROM pm1.g1 order by a", "SELECT 2 AS a FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewiteOrderBy1() {
+ helpTestRewriteCommand("SELECT 1+1 as a FROM pm1.g1 union select pm1.g2.e1 from pm1.g2 order by a", "SELECT '2' AS a FROM pm1.g1 UNION SELECT pm1.g2.e1 FROM pm1.g2 ORDER BY a"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * The rewrite creates inline view to do the type conversion.
+ *
+ * It also ensures that all project symbols are uniquely named in the inline view
+ */
+ public void testSelectIntoWithOrderByAndTypeConversion() throws Exception {
+ String procedure = "CREATE VIRTUAL PROCEDURE\n"; //$NON-NLS-1$
+ procedure += "BEGIN\n"; //$NON-NLS-1$
+ procedure += "CREATE local temporary table temp (x string, y integer, z integer);\n"; //$NON-NLS-1$
+ procedure += "Select pm1.g1.e2, 1 as x, 2 as x into temp from pm1.g1 order by pm1.g1.e2 limit 1;\n"; //$NON-NLS-1$
+ procedure += "Select x from temp;\n"; //$NON-NLS-1$
+ procedure += "END\n"; //$NON-NLS-1$
+
+ helpTestRewriteCommand(procedure, "CREATE VIRTUAL PROCEDURE\nBEGIN\nCREATE LOCAL TEMPORARY TABLE temp (x string, y integer, z integer);\nSELECT TEMP_1.E2 AS E2, TEMP_1.X, TEMP_1.X_0 INTO temp FROM (SELECT pm1.g1.e2, 1 AS x, 2 AS X_0 FROM pm1.g1 ORDER BY pm1.g1.e2 LIMIT 1) AS temp_1;\nSELECT x FROM temp;\nEND"); //$NON-NLS-1$
+ }
+
+
+ public void testInsertWithQuery() throws Exception {
+ String sql = "insert into pm1.g1 select e1, e2, e3, e4 from pm1.g2 union select e1, e2, e3, e4 from pm1.g2"; //$NON-NLS-1$
+
+ helpTestRewriteCommand(sql, "SELECT PM1_G1_1.E1, PM1_G1_1.E2, PM1_G1_1.E3, PM1_G1_1.E4 INTO pm1.g1 FROM (SELECT e1, e2, e3, e4 FROM pm1.g2 UNION SELECT e1, e2, e3, e4 FROM pm1.g2) AS pm1_g1_1"); //$NON-NLS-1$
+ }
+
+ public void testRewriteNot() {
+ helpTestRewriteCriteria("not(not(pm1.g1.e1 = 1 + 1))", "pm1.g1.e1 = '2'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteQueryWithNoFrom() {
+ String sql = "select 1 as a order by a"; //$NON-NLS-1$
+
+ helpTestRewriteCommand(sql, "SELECT 1 AS a"); //$NON-NLS-1$
+ }
+
+ public void testOrderByDuplicateRemoval() {
+ String sql = "SELECT pm1.g1.e1, pm1.g1.e1 as c1234567890123456789012345678901234567890 FROM pm1.g1 ORDER BY c1234567890123456789012345678901234567890, e1 "; //$NON-NLS-1$
+ helpTestRewriteCommand(sql, "SELECT pm1.g1.e1, pm1.g1.e1 AS c1234567890123456789012345678901234567890 FROM pm1.g1 ORDER BY c1234567890123456789012345678901234567890"); //$NON-NLS-1$
+ }
+
+ /**
+ * Case 4814
+ */
+ public void testVirtualRightOuterJoinSwap() throws Exception {
+ String sql = "SELECT sa.IntKey AS sa_IntKey, mb.IntKey AS mb_IntKey FROM (select * from BQT1.smalla) sa RIGHT OUTER JOIN (select BQT1.mediumb.intkey from BQT1.mediumb) mb ON sa.IntKey = mb.IntKey"; //$NON-NLS-1$
+ helpTestRewriteCommand(sql, "SELECT sa.IntKey AS sa_IntKey, mb.IntKey AS mb_IntKey FROM (SELECT BQT1.mediumb.intkey FROM BQT1.mediumb) AS mb LEFT OUTER JOIN (SELECT * FROM BQT1.smalla) AS sa ON sa.IntKey = mb.IntKey", FakeMetadataFactory.exampleBQTCached()); //$NON-NLS-1$
+ }
+
+ /**
+ * Case 4814
+ */
+ public void testVirtualRightOuterJoinSwap1() throws Exception {
+ String sql = "SELECT sa.IntKey AS sa_IntKey, mb.IntKey AS mb_IntKey FROM ((select * from BQT1.smalla) sa inner join BQT1.smallb on sa.intkey = smallb.intkey) RIGHT OUTER JOIN (select BQT1.mediumb.intkey from BQT1.mediumb) mb ON sa.IntKey = mb.IntKey"; //$NON-NLS-1$
+ helpTestRewriteCommand(sql, "SELECT sa.IntKey AS sa_IntKey, mb.IntKey AS mb_IntKey FROM (SELECT BQT1.mediumb.intkey FROM BQT1.mediumb) AS mb LEFT OUTER JOIN ((SELECT * FROM BQT1.smalla) AS sa INNER JOIN BQT1.smallb ON sa.intkey = smallb.intkey) ON sa.IntKey = mb.IntKey", FakeMetadataFactory.exampleBQTCached()); //$NON-NLS-1$
+ }
+
+ public void testRewriteConcat2() {
+ helpTestRewriteCriteria("concat2('a','b') = 'ab'", "1 = 1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteConcat2_1() {
+ helpTestRewriteCriteria("concat2(null, null) is null", "1 = 1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteConcat2_2() throws Exception {
+ helpTestRewriteCriteria("concat2(pm1.g1.e1, null) = 'xyz'", "CASE WHEN pm1.g1.e1 IS NULL THEN null ELSE concat(ifnull(pm1.g1.e1, ''), '') END = 'xyz'", true); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteConcat2_3() throws Exception {
+ helpTestRewriteCriteria("concat2(pm1.g1.e1, convert(pm1.g1.e2, string)) = 'xyz'", "CASE WHEN (pm1.g1.e1 IS NULL) AND (convert(pm1.g1.e2, string) IS NULL) THEN null ELSE concat(ifnull(pm1.g1.e1, ''), ifnull(convert(pm1.g1.e2, string), '')) END = 'xyz'", true); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewriteConcat2_4() throws Exception {
+ helpTestRewriteCriteria("concat2('a', pm1.g1.e1) = 'xyz'", "concat('a', ifnull(pm1.g1.e1, '')) = 'xyz'"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testRewiteEvaluatableAggregate() {
+ helpTestRewriteCommand("select pm1.g1.e1, max(1) from pm1.g1", "SELECT pm1.g1.e1, 1 FROM pm1.g1"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
public void testRewriteFromUnixTime() throws Exception {
TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("GMT-06:00")); //$NON-NLS-1$
try {
@@ -2122,5 +2122,5 @@
}
}
-
-}
+
+}
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestAliasSymbol.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestAliasSymbol.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestAliasSymbol.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -26,14 +26,14 @@
import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
public class TestAliasSymbol extends TestCase {
public void testAliasEquals() {
- AliasSymbol a1 = new AliasSymbol("X", new ExpressionSymbol("x", new Constant(1))); //$NON-NLS-1$ //$NON-NLS-2$
- AliasSymbol a2 = new AliasSymbol("X", new ExpressionSymbol("x", new Constant(2))); //$NON-NLS-1$ //$NON-NLS-2$
- AliasSymbol a3 = new AliasSymbol("x", new ExpressionSymbol("x", new Constant(1))); //$NON-NLS-1$ //$NON-NLS-2$
+ AliasSymbol a1 = new AliasSymbol("X", new DerivedColumn("x", new Constant(1))); //$NON-NLS-1$ //$NON-NLS-2$
+ AliasSymbol a2 = new AliasSymbol("X", new DerivedColumn("x", new Constant(2))); //$NON-NLS-1$ //$NON-NLS-2$
+ AliasSymbol a3 = new AliasSymbol("x", new DerivedColumn("x", new Constant(1))); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals(a1, a3); //just a different case for the alias
@@ -41,7 +41,7 @@
}
public void testClone() {
- AliasSymbol a1 = new AliasSymbol("X", new ExpressionSymbol("x", new Constant(1))); //$NON-NLS-1$ //$NON-NLS-2$
+ AliasSymbol a1 = new AliasSymbol("X", new DerivedColumn("x", new Constant(1))); //$NON-NLS-1$ //$NON-NLS-2$
a1.setOutputName("foo"); //$NON-NLS-1$
AliasSymbol clone = (AliasSymbol)a1.clone();
assertEquals(a1, clone);
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestExpressionSymbol.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestExpressionSymbol.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestExpressionSymbol.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -24,7 +24,7 @@
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import junit.framework.TestCase;
@@ -34,8 +34,8 @@
public void testExpressionHashCode() {
Expression expr1 = new Constant(new Integer(1));
Expression expr2 = new Constant(new Integer(2));
- ExpressionSymbol symbol1 = new ExpressionSymbol("foo", expr1); //$NON-NLS-1$
- ExpressionSymbol symbol2 = new ExpressionSymbol("bar", expr2); //$NON-NLS-1$
+ DerivedColumn symbol1 = new DerivedColumn("foo", expr1); //$NON-NLS-1$
+ DerivedColumn symbol2 = new DerivedColumn("bar", expr2); //$NON-NLS-1$
assertFalse(symbol1.hashCode() == symbol2.hashCode());
}
@@ -43,8 +43,8 @@
public void testExpressionHashCode1() {
Expression expr1 = new Constant(new Integer(1));
Expression expr2 = new Constant(new Integer(1));
- ExpressionSymbol symbol1 = new ExpressionSymbol("foo", expr1); //$NON-NLS-1$
- ExpressionSymbol symbol2 = new ExpressionSymbol("bar", expr2); //$NON-NLS-1$
+ DerivedColumn symbol1 = new DerivedColumn("foo", expr1); //$NON-NLS-1$
+ DerivedColumn symbol2 = new DerivedColumn("bar", expr2); //$NON-NLS-1$
assertTrue(symbol1.hashCode() == symbol2.hashCode());
}
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestSelect.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestSelect.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/lang/TestSelect.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -28,8 +28,8 @@
import junit.framework.TestCase;
import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.AllSymbol;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
public class TestSelect extends TestCase {
@@ -59,7 +59,7 @@
select.addSymbol(new ElementSymbol("a")); //$NON-NLS-1$
select.addSymbol(new ElementSymbol("b")); //$NON-NLS-1$
select.addSymbol(new ElementSymbol("c")); //$NON-NLS-1$
- select.addSymbol(new AliasSymbol("Z", new ElementSymbol("ZZ 9 Plural Z Alpha"))); //$NON-NLS-1$ //$NON-NLS-2$
+ select.addSymbol(new DerivedColumn("Z", new ElementSymbol("ZZ 9 Plural Z Alpha"), true)); //$NON-NLS-1$ //$NON-NLS-2$
return select;
}
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/symbol/TestAggregateSymbol.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/symbol/TestAggregateSymbol.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/symbol/TestAggregateSymbol.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -53,12 +53,12 @@
return new Function("+", new Expression[] { sampleElement(), sampleConstant() }); //$NON-NLS-1$
}
- private void helpParser(AggregateSymbol as, String expected) {
+ private void helpParser(Aggregate as, String expected) {
String toString = as.toString();
assertEquals("Parser string does not match", expected, toString); //$NON-NLS-1$
}
- private void helpEquals(AggregateSymbol as1, AggregateSymbol as2, boolean equal) {
+ private void helpEquals(Aggregate as1, Aggregate as2, boolean equal) {
if(equal) {
assertTrue("Aggregate symbols should be equal: " + as1 + ", " + as2, as1.equals(as2)); //$NON-NLS-1$ //$NON-NLS-2$
} else {
@@ -70,105 +70,105 @@
// ################################## ACTUAL TESTS ################################
public void testParser1() {
- AggregateSymbol as = new AggregateSymbol("count", ReservedWords.COUNT, false, sampleElement()); //$NON-NLS-1$
+ Aggregate as = new Aggregate(ReservedWords.COUNT, false, sampleElement()); //$NON-NLS-1$
helpParser(as, "COUNT(m.g.c)"); //$NON-NLS-1$
}
public void testParser2() {
- AggregateSymbol as = new AggregateSymbol("count", ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ Aggregate as = new Aggregate(ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
helpParser(as, "COUNT(DISTINCT m.g.c)"); //$NON-NLS-1$
}
public void testParser3() {
- AggregateSymbol as = new AggregateSymbol("x", ReservedWords.MIN, false, sampleConstant()); //$NON-NLS-1$
+ Aggregate as = new Aggregate(ReservedWords.MIN, false, sampleConstant()); //$NON-NLS-1$
helpParser(as, "MIN(5)"); //$NON-NLS-1$
}
public void testParser4() {
- AggregateSymbol as = new AggregateSymbol("x", ReservedWords.MAX, false, sampleFunction()); //$NON-NLS-1$
+ Aggregate as = new Aggregate(ReservedWords.MAX, false, sampleFunction()); //$NON-NLS-1$
helpParser(as, "MAX((m.g.c + 5))"); //$NON-NLS-1$
}
public void testParser5() {
- AggregateSymbol as = new AggregateSymbol("x", ReservedWords.COUNT, false, null); //$NON-NLS-1$
+ Aggregate as = new Aggregate(ReservedWords.COUNT, false, null); //$NON-NLS-1$
helpParser(as, "COUNT(*)"); //$NON-NLS-1$
}
public void testEquals1() {
- AggregateSymbol as = new AggregateSymbol("x", ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ Aggregate as = new Aggregate(ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
helpEquals(as, as, true);
}
public void testEquals2() {
- AggregateSymbol as1 = new AggregateSymbol("x", ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
- AggregateSymbol as2 = (AggregateSymbol) as1.clone();
+ Aggregate as1 = new Aggregate(ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ Aggregate as2 = (Aggregate) as1.clone();
helpEquals(as1, as2, true);
}
//just changing the name of an aggregatesymbol doesn't matter
public void testEquals3() {
- AggregateSymbol as1 = new AggregateSymbol("x", ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
- AggregateSymbol as2 = new AggregateSymbol("y", ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ Aggregate as1 = new Aggregate(ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ Aggregate as2 = new Aggregate(ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
helpEquals(as1, as2, true);
}
public void testEquals4() {
- AggregateSymbol as1 = new AggregateSymbol("count", ReservedWords.COUNT, false, null); //$NON-NLS-1$
- AggregateSymbol as2 = (AggregateSymbol) as1.clone();
+ Aggregate as1 = new Aggregate(ReservedWords.COUNT, false, null); //$NON-NLS-1$
+ Aggregate as2 = (Aggregate) as1.clone();
helpEquals(as1, as2, true);
}
public void testSelfEquivalence(){
- AggregateSymbol test = new AggregateSymbol("x", ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ Aggregate test = new Aggregate(ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
int equals = 0;
UnitTestUtil.helpTestEquivalence(equals, test, test);
}
public void testEquivalence(){
- AggregateSymbol test1 = new AggregateSymbol("x", ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
- AggregateSymbol test2 = new AggregateSymbol("x", ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ Aggregate test1 = new Aggregate(ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ Aggregate test2 = new Aggregate(ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
int equals = 0;
UnitTestUtil.helpTestEquivalence(equals, test1, test2);
}
public void testEquivalenceCountStar(){
- AggregateSymbol test1 = new AggregateSymbol("x", ReservedWords.COUNT, false, null); //$NON-NLS-1$
- AggregateSymbol test2 = new AggregateSymbol("x", ReservedWords.COUNT, false, null); //$NON-NLS-1$
+ Aggregate test1 = new Aggregate(ReservedWords.COUNT, false, null); //$NON-NLS-1$
+ Aggregate test2 = new Aggregate(ReservedWords.COUNT, false, null); //$NON-NLS-1$
int equals = 0;
UnitTestUtil.helpTestEquivalence(equals, test1, test2);
}
public void testEquivalenceCaseInsens(){
- AggregateSymbol test1 = new AggregateSymbol("x", ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
- AggregateSymbol test2 = new AggregateSymbol("X", ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ Aggregate test1 = new Aggregate(ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ Aggregate test2 = new Aggregate(ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
int equals = 0;
UnitTestUtil.helpTestEquivalence(equals, test1, test2);
}
public void testNonEquivalenceUsingDiffElements(){
- AggregateSymbol test1 = new AggregateSymbol("x", ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
- AggregateSymbol test2 = new AggregateSymbol("X", ReservedWords.COUNT, true, sampleElement2()); //$NON-NLS-1$
+ Aggregate test1 = new Aggregate(ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ Aggregate test2 = new Aggregate(ReservedWords.COUNT, true, sampleElement2()); //$NON-NLS-1$
int equals = -1;
UnitTestUtil.helpTestEquivalence(equals, test1, test2);
}
public void testNonEquivalence(){
- AggregateSymbol test1 = new AggregateSymbol("x", ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
- AggregateSymbol test2 = new AggregateSymbol("y", ReservedWords.COUNT, true, sampleElement2()); //$NON-NLS-1$
+ Aggregate test1 = new Aggregate(ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ Aggregate test2 = new Aggregate(ReservedWords.COUNT, true, sampleElement2()); //$NON-NLS-1$
int equals = -1;
UnitTestUtil.helpTestEquivalence(equals, test1, test2);
}
public void testNonEquivalence1(){
- AggregateSymbol test1 = new AggregateSymbol("x", ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
- AggregateSymbol test2 = new AggregateSymbol("x", ReservedWords.COUNT, true, sampleElement2()); //$NON-NLS-1$
+ Aggregate test1 = new Aggregate(ReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ Aggregate test2 = new Aggregate(ReservedWords.COUNT, true, sampleElement2()); //$NON-NLS-1$
int equals = -1;
UnitTestUtil.helpTestEquivalence(equals, test1, test2);
}
public void testNonEquivalence2(){
- AggregateSymbol test1 = new AggregateSymbol("x", ReservedWords.MAX, true, sampleElement()); //$NON-NLS-1$
- AggregateSymbol test2 = new AggregateSymbol("x", ReservedWords.COUNT, true, sampleElement2()); //$NON-NLS-1$
+ Aggregate test1 = new Aggregate(ReservedWords.MAX, true, sampleElement()); //$NON-NLS-1$
+ Aggregate test2 = new Aggregate(ReservedWords.COUNT, true, sampleElement2()); //$NON-NLS-1$
int equals = -1;
UnitTestUtil.helpTestEquivalence(equals, test1, test2);
}
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestSQLStringVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestSQLStringVisitor.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestSQLStringVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -76,15 +76,14 @@
import com.metamatrix.query.sql.proc.HasCriteria;
import com.metamatrix.query.sql.proc.IfStatement;
import com.metamatrix.query.sql.proc.RaiseErrorStatement;
-import com.metamatrix.query.sql.symbol.AggregateSymbol;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
+import com.metamatrix.query.sql.symbol.Aggregate;
import com.metamatrix.query.sql.symbol.AllInGroupSymbol;
import com.metamatrix.query.sql.symbol.AllSymbol;
import com.metamatrix.query.sql.symbol.CaseExpression;
import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Reference;
@@ -592,7 +591,7 @@
public void testOrderBy2() {
OrderBy ob = new OrderBy();
ob.addVariable(new ElementSymbol("e1")); //$NON-NLS-1$
- ob.addVariable(new AliasSymbol("x", new ElementSymbol("e2"))); //$NON-NLS-1$ //$NON-NLS-2$
+ ob.addVariable(new ElementSymbol("x")); //$NON-NLS-1$
helpTest(ob, "ORDER BY e1, x"); //$NON-NLS-1$
}
@@ -1051,48 +1050,48 @@
}
public void testAggregateSymbol1() {
- AggregateSymbol agg = new AggregateSymbol("abc", ReservedWords.COUNT, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate agg = new Aggregate(ReservedWords.COUNT, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
helpTest(agg, "COUNT('abc')"); //$NON-NLS-1$
}
public void testAggregateSymbol2() {
- AggregateSymbol agg = new AggregateSymbol("abc", ReservedWords.COUNT, true, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate agg = new Aggregate(ReservedWords.COUNT, true, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
helpTest(agg, "COUNT(DISTINCT 'abc')"); //$NON-NLS-1$
}
public void testAggregateSymbol3() {
- AggregateSymbol agg = new AggregateSymbol("abc", ReservedWords.COUNT, false, null); //$NON-NLS-1$
+ Aggregate agg = new Aggregate(ReservedWords.COUNT, false, null); //$NON-NLS-1$
helpTest(agg, "COUNT(*)"); //$NON-NLS-1$
}
public void testAggregateSymbol4() {
- AggregateSymbol agg = new AggregateSymbol("abc", ReservedWords.AVG, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate agg = new Aggregate(ReservedWords.AVG, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
helpTest(agg, "AVG('abc')"); //$NON-NLS-1$
}
public void testAggregateSymbol5() {
- AggregateSymbol agg = new AggregateSymbol("abc", ReservedWords.SUM, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate agg = new Aggregate(ReservedWords.SUM, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
helpTest(agg, "SUM('abc')"); //$NON-NLS-1$
}
public void testAggregateSymbol6() {
- AggregateSymbol agg = new AggregateSymbol("abc", ReservedWords.MIN, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate agg = new Aggregate(ReservedWords.MIN, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
helpTest(agg, "MIN('abc')"); //$NON-NLS-1$
}
public void testAggregateSymbol7() {
- AggregateSymbol agg = new AggregateSymbol("abc", ReservedWords.MAX, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
+ Aggregate agg = new Aggregate(ReservedWords.MAX, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
helpTest(agg, "MAX('abc')"); //$NON-NLS-1$
}
public void testAliasSymbol1() {
- AliasSymbol as = new AliasSymbol("x", new ElementSymbol("element")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn as = new DerivedColumn("x", new ElementSymbol("element"), true); //$NON-NLS-1$ //$NON-NLS-2$
helpTest(as, "element AS x"); //$NON-NLS-1$
}
// Test alias symbol with reserved word
public void testAliasSymbol2() {
- AliasSymbol as = new AliasSymbol("select", new ElementSymbol("element")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn as = new DerivedColumn("select", new ElementSymbol("element"), true); //$NON-NLS-1$ //$NON-NLS-2$
helpTest(as, "element AS \"select\""); //$NON-NLS-1$
}
@@ -1186,7 +1185,7 @@
}
public void testExpressionSymbol1() {
- ExpressionSymbol expr = new ExpressionSymbol("abc", new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
+ DerivedColumn expr = new DerivedColumn("abc", new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
helpTest(expr, "'abc'"); //$NON-NLS-1$
}
@@ -1824,7 +1823,7 @@
Select s2 = new Select();
s2.addSymbol(new ElementSymbol("e1")); //$NON-NLS-1$
- s2.addSymbol(new ExpressionSymbol("blargh", new ScalarSubquery(q1))); //$NON-NLS-1$
+ s2.addSymbol(new DerivedColumn("blargh", new ScalarSubquery(q1))); //$NON-NLS-1$
From f2 = new From();
f2.addGroup(new GroupSymbol("m.g2")); //$NON-NLS-1$
Criteria left = new SubqueryCompareCriteria(new ElementSymbol("e3"), q1, SubqueryCompareCriteria.GE, SubqueryCompareCriteria.ANY); //$NON-NLS-1$
@@ -1923,12 +1922,12 @@
String expected = "SELECT 'A' AS FOO UNION SELECT 'B' AS FOO"; //$NON-NLS-1$
Select s1 = new Select();
- s1.addSymbol(new AliasSymbol("FOO", new ExpressionSymbol("xxx", new Constant("A")))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ s1.addSymbol(new DerivedColumn("FOO", new Constant("A"), true)); //$NON-NLS-1$ //$NON-NLS-2$
Query q1 = new Query();
q1.setSelect(s1);
Select s2 = new Select();
- s2.addSymbol(new AliasSymbol("FOO", new ExpressionSymbol("xxx", new Constant("B")))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ s2.addSymbol(new DerivedColumn("FOO", new Constant("B"), true)); //$NON-NLS-1$ //$NON-NLS-2$
Query q2 = new Query();
q2.setSelect(s2);
@@ -1948,12 +1947,12 @@
String expected = "SELECT 'A' AS FOO UNION SELECT 'B' AS FOO"; //$NON-NLS-1$
Select s1 = new Select();
- s1.addSymbol(new AliasSymbol("FOO", new ExpressionSymbol("xxx", new Constant("A")))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ s1.addSymbol(new DerivedColumn("FOO", new Constant("A"), true)); //$NON-NLS-1$ //$NON-NLS-2$
Query q1 = new Query();
q1.setSelect(s1);
Select s2 = new Select();
- s2.addSymbol(new AliasSymbol("FOO", new ExpressionSymbol("yyy", new Constant("B")))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ s2.addSymbol(new DerivedColumn("FOO", new Constant("B"), true)); //$NON-NLS-1$ //$NON-NLS-2$
Query q2 = new Query();
q2.setSelect(s2);
@@ -1978,7 +1977,7 @@
public void testLimit() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new Object[] {new AllSymbol()}));
+ Select select = new Select(Arrays.asList(new AllSymbol()));
From from = new From(Arrays.asList(new Object[] {new UnaryFromClause(new GroupSymbol("a"))})); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
@@ -1988,7 +1987,7 @@
public void testLimitWithOffset() {
Query query = new Query();
- Select select = new Select(Arrays.asList(new Object[] {new AllSymbol()}));
+ Select select = new Select(Arrays.asList(new AllSymbol()));
From from = new From(Arrays.asList(new Object[] {new UnaryFromClause(new GroupSymbol("a"))})); //$NON-NLS-1$
query.setSelect(select);
query.setFrom(from);
Modified: branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestStaticSymbolMappingVisitor.java
===================================================================
--- branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestStaticSymbolMappingVisitor.java 2009-03-03 17:12:09 UTC (rev 531)
+++ branches/symbol_refactoring_61/engine/src/test/java/com/metamatrix/query/sql/visitor/TestStaticSymbolMappingVisitor.java 2009-03-03 17:26:43 UTC (rev 532)
@@ -48,13 +48,12 @@
import com.metamatrix.query.sql.navigator.DeepPreOrderNavigator;
import com.metamatrix.query.sql.proc.CriteriaSelector;
import com.metamatrix.query.sql.proc.TranslateCriteria;
-import com.metamatrix.query.sql.symbol.AliasSymbol;
import com.metamatrix.query.sql.symbol.AllInGroupSymbol;
import com.metamatrix.query.sql.symbol.AllSymbol;
import com.metamatrix.query.sql.symbol.Constant;
+import com.metamatrix.query.sql.symbol.DerivedColumn;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.symbol.Symbol;
@@ -193,7 +192,7 @@
OrderBy ob = new OrderBy();
ob.addVariable(exampleElement(true, 0));
ob.addVariable(exampleElement(true, 1));
- ob.addVariable(new AliasSymbol("abc", exampleElement(true, 2))); //$NON-NLS-1$
+ ob.addVariable(new DerivedColumn("abc", exampleElement(true, 2), true)); //$NON-NLS-1$
helpTest(ob, getSymbolMap());
}
@@ -219,7 +218,7 @@
public void testVisitSelect4() {
Select select = new Select();
- select.addSymbol( new ExpressionSymbol(
+ select.addSymbol( new DerivedColumn(
"x", new Function("length", new Expression[] {exampleElement(true, 0)})) ); //$NON-NLS-1$ //$NON-NLS-2$
select.addSymbol( new AllInGroupSymbol("abc.*") ); //$NON-NLS-1$
select.addSymbol( exampleElement(true, 1) );
@@ -256,7 +255,7 @@
}
public void testVisitAliasSymbol() {
- AliasSymbol as = new AliasSymbol("abc", exampleElement(true, 0)); //$NON-NLS-1$
+ DerivedColumn as = new DerivedColumn("abc", exampleElement(true, 0), true); //$NON-NLS-1$
helpTest(as, getSymbolMap());
}
16 years, 7 months
teiid SVN: r531 - trunk/server/src/main/java/com/metamatrix/common/net.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-03-03 12:12:09 -0500 (Tue, 03 Mar 2009)
New Revision: 531
Modified:
trunk/server/src/main/java/com/metamatrix/common/net/ServerSocketConfiguration.java
Log:
TEIID-388 - changed to use the default algorithm from the KeyManager instead of defaulting to SumX509, this is so environments (ie., Z900 IBM) can specify their own algorithm and we'll use it. (Reviewed Ramesh & Steve H)
Modified: trunk/server/src/main/java/com/metamatrix/common/net/ServerSocketConfiguration.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/common/net/ServerSocketConfiguration.java 2009-03-03 16:16:24 UTC (rev 530)
+++ trunk/server/src/main/java/com/metamatrix/common/net/ServerSocketConfiguration.java 2009-03-03 17:12:09 UTC (rev 531)
@@ -23,9 +23,11 @@
package com.metamatrix.common.net;
import java.io.IOException;
+import java.security.Security;
import java.util.Arrays;
import java.util.Properties;
+import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
@@ -60,7 +62,6 @@
public static final String ANONYMOUS = "anonymous"; //$NON-NLS-1$
public static final String DEFAULT_SSL_PROTOCOL = "SSLv3"; //$NON-NLS-1$
- public static final String DEFAULT_KEY_MANAGER_ALGORITHM = "SunX509"; //$NON-NLS-1$
public static final String DEFAULT_KEYSTORE_TYPE = "JKS"; //$NON-NLS-1$
public static final String UNENCRYPTED_CIPHER_SUITE = "SSL_RSA_WITH_NULL_SHA"; //$NON-NLS-1$
@@ -70,7 +71,7 @@
*/
private boolean ssl_enabled;
private String sslProtocol = DEFAULT_SSL_PROTOCOL;
- private String keyManagerFactoryAlgorithm = DEFAULT_KEY_MANAGER_ALGORITHM;
+ private String keyManagerFactoryAlgorithm;
private String keyStoreType = DEFAULT_KEYSTORE_TYPE;
private String keyStoreFileName;
private String keyStorePassword = ""; //$NON-NLS-1$
@@ -106,7 +107,8 @@
}
keyStoreType = props.getProperty(KEYSTORE_TYPE, DEFAULT_KEYSTORE_TYPE);
- keyManagerFactoryAlgorithm = props.getProperty(KEY_MANAGER_ALGORITHM, DEFAULT_KEY_MANAGER_ALGORITHM);
+
+ keyManagerFactoryAlgorithm = props.getProperty(KEY_MANAGER_ALGORITHM, KeyManagerFactory.getDefaultAlgorithm());
authenticationMode = props.getProperty(AUTHENTICATION_MODE);
16 years, 7 months
teiid SVN: r530 - in trunk/server/src/main/java/com/metamatrix: platform/vm/controller and 1 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2009-03-03 11:16:24 -0500 (Tue, 03 Mar 2009)
New Revision: 530
Modified:
trunk/server/src/main/java/com/metamatrix/platform/registry/ClusteredRegistryState.java
trunk/server/src/main/java/com/metamatrix/platform/registry/ServiceRegistryBinding.java
trunk/server/src/main/java/com/metamatrix/platform/registry/VMMonitor.java
trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ServerEvents.java
trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java
Log:
TEIID-309: JBoss core cache does not automatically update the objects that are put in the cache; to do that you would either use pojo cache, or manually update them. Since switch to Pojo cache is more intrusive, I opted use updating of the object in the cache. Typically only the objects in the cache are updated, when/if their state has changed.
Modified: trunk/server/src/main/java/com/metamatrix/platform/registry/ClusteredRegistryState.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/registry/ClusteredRegistryState.java 2009-03-03 15:31:10 UTC (rev 529)
+++ trunk/server/src/main/java/com/metamatrix/platform/registry/ClusteredRegistryState.java 2009-03-03 16:16:24 UTC (rev 530)
@@ -78,13 +78,13 @@
// only return the active vms
VMRegistryBinding binding = (VMRegistryBinding)vmNode.get(VM_CONTROLLER);
- if (!binding.isAlive()) {
- throw new CacheNodeNotFoundException("VM Node not found"); //$NON-NLS-1$
+ if (binding == null || !binding.isAlive()) {
+ throw new CacheNodeNotFoundException("VM Node's binding not found or not active"); //$NON-NLS-1$
}
return vmNode;
}
- protected void addHost(HostControllerRegistryBinding binding) {
+ protected synchronized void addHost(HostControllerRegistryBinding binding) {
String hostName = binding.getHostName().toUpperCase();
Cache n = this.cache.addChild(hostName);
n.put(NAME, hostName);
@@ -95,11 +95,19 @@
this.cache.removeChild(hostName.toUpperCase());
}
- protected void addVM(String hostName, String vmName, VMRegistryBinding vmBinding) throws CacheNodeNotFoundException {
+ protected synchronized void addVM(String hostName, String vmName, VMRegistryBinding vmBinding) throws CacheNodeNotFoundException {
Cache vmNode = addVMNode(hostName, vmName);
vmNode.put(VM_CONTROLLER, vmBinding);
}
+ protected void updateVM(String hostName, String vmName, VMRegistryBinding binding) throws ResourceNotBoundException, CacheNodeNotFoundException {
+ Cache vmNode = getVMNode(hostName, vmName);
+ if (vmNode.get(VM_CONTROLLER) == null) {
+ throw new ResourceNotBoundException(ServicePlugin.Util.getString(ServiceMessages.REGISTRY_0012, hostName+"/"+vmName )); //$NON-NLS-1$
+ }
+ vmNode.put(VM_CONTROLLER, binding);
+ }
+
protected void removeVM(String hostName, String vmName) {
try {
Cache hostNode = getHostNode(hostName);
@@ -178,7 +186,7 @@
}
- protected void addServiceBinding(String hostName, String vmName, ServiceRegistryBinding binding) throws ResourceAlreadyBoundException, CacheNodeNotFoundException {
+ protected synchronized void addServiceBinding(String hostName, String vmName, ServiceRegistryBinding binding) throws ResourceAlreadyBoundException, CacheNodeNotFoundException {
Cache services = getServices(hostName, vmName);
// check if this service already exists
@@ -190,6 +198,18 @@
services.put(binding.getServiceID(), binding);
}
+ protected void updateServiceBinding(String hostName, String vmName, ServiceRegistryBinding binding) throws ResourceNotBoundException, CacheNodeNotFoundException {
+ Cache services = getServices(hostName, vmName);
+
+ // check if this service already exists
+ ServiceRegistryBinding existing = (ServiceRegistryBinding)services.get(binding.getServiceID());
+ if (existing == null) {
+ throw new ResourceNotBoundException(ServicePlugin.Util.getString(ServiceMessages.REGISTRY_0011, binding.getServiceID() ));
+ }
+
+ services.put(binding.getServiceID(), binding);
+ }
+
public ServiceRegistryBinding getServiceBinding(String hostName, String vmName, ServiceID serviceId ) throws ResourceNotBoundException {
ServiceRegistryBinding binding;
try {
@@ -296,5 +316,5 @@
for(RegistryListener l:this.listeners) {
l.registryChanged();
}
- }
+ }
}
Modified: trunk/server/src/main/java/com/metamatrix/platform/registry/ServiceRegistryBinding.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/registry/ServiceRegistryBinding.java 2009-03-03 15:31:10 UTC (rev 529)
+++ trunk/server/src/main/java/com/metamatrix/platform/registry/ServiceRegistryBinding.java 2009-03-03 16:16:24 UTC (rev 530)
@@ -63,8 +63,8 @@
throw err.getTargetException();
}
+ ServiceRegistryBinding.this.setInitException(proxiedService.getInitException());
ServiceRegistryBinding.this.updateState(proxiedService.getCurrentState());
- ServiceRegistryBinding.this.setInitException(proxiedService.getInitException());
return returnObj;
}
}
@@ -119,6 +119,8 @@
private transient MessageBus messageBus;
+ private transient boolean dirty;
+
/**
* Create new ServiceRegistryInstance
*
@@ -246,8 +248,11 @@
}
public void updateState(int state) {
- this.currentState = state;
- this.stateChangeTime = new Date();
+ if (this.currentState != state) {
+ this.currentState = state;
+ this.stateChangeTime = new Date();
+ this.dirty = true;
+ }
}
private Collection buildQueueNames(ServiceInterface si) {
@@ -305,8 +310,16 @@
}
public void markServiceAsBad() {
- this.currentState = ServiceState.STATE_FAILED;
setService(null);
+ updateState(ServiceState.STATE_FAILED);
}
+
+ public void setDirty(boolean dirty) {
+ this.dirty = dirty;
+ }
+
+ public boolean isDirty() {
+ return dirty;
+ }
}
Modified: trunk/server/src/main/java/com/metamatrix/platform/registry/VMMonitor.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/registry/VMMonitor.java 2009-03-03 15:31:10 UTC (rev 529)
+++ trunk/server/src/main/java/com/metamatrix/platform/registry/VMMonitor.java 2009-03-03 16:16:24 UTC (rev 530)
@@ -91,15 +91,23 @@
@Override
public void run() {
List<VMRegistryBinding> vmBindings = VMMonitor.this.registry.getVMs(null);
+
for (VMRegistryBinding binding: vmBindings) {
- try {
- VMControllerInterface vm = binding.getVMController();
+ VMControllerInterface vm = binding.getVMController();
+ boolean alive = binding.isAlive();
+
+ try {
vm.ping();
binding.setAlive(true);
} catch (ServiceException e) {
// mark as not alive, then no services will be pinged from this vm
binding.setAlive(false);
}
+
+ // if the vmstate changed then, update the registry.
+ if (alive != binding.isAlive()) {
+ vmUpdated(binding);
+ }
}
}
}, POLLING_INTERVAL_DEFAULT, POLLING_INTERVAL_DEFAULT);
@@ -111,16 +119,23 @@
public void run() {
List<ServiceRegistryBinding> bindings = registry.getServiceBindings(hostName, vmId.toString());
for (ServiceRegistryBinding binding:bindings) {
- try {
+
+ ServiceInterface si = binding.getService();
+ try {
// when service in stopped state; this will be null
// if shut down there will not be a binding for it.
- ServiceInterface si = binding.getService();
if(si != null) {
binding.getService().checkState();
}
} catch (ServiceStateException e) {
// OK to throw up, service will capture the error to logs.
}
+
+ // the state of the service changed, then update the cache.
+ if (binding.isDirty()) {
+ serviceUpdated(binding);
+ binding.setDirty(false);
+ }
}
}
}, pollingIntervel, pollingIntervel);
@@ -158,4 +173,29 @@
this.registry.removeVM(hostName, vmId.toString());
LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "VM Removed:"+id); //$NON-NLS-1$
}
+
+ @Override
+ public void serviceUpdated(ServiceRegistryBinding binding) {
+ try {
+ this.registry.updateServiceBinding(binding.getHostName(), binding.getServiceID().getVMControllerID().toString(), binding);
+ LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "Service updated:"+binding.getServiceID()); //$NON-NLS-1$
+ } catch(CacheNodeNotFoundException e) {
+ LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, "Failed to add service:"+binding.getServiceID()); //$NON-NLS-1$
+ } catch (ResourceNotBoundException e) {
+ LogManager.logWarning(LogCommonConstants.CTX_CONTROLLER, "Service not exist:"+binding.getServiceID()); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ public void vmUpdated(VMRegistryBinding binding) {
+ try {
+ this.registry.updateVM(binding.getHostName(), binding.getVMControllerID().toString(), binding);
+ LogManager.logDetail(LogCommonConstants.CTX_CONTROLLER, "VM Added:"+binding.getVMControllerID()); //$NON-NLS-1$
+ } catch (CacheNodeNotFoundException e) {
+ LogManager.logError(LogCommonConstants.CTX_CONTROLLER, e, "Failed to add VM:"+binding.getVMControllerID()); //$NON-NLS-1$
+ throw new MetaMatrixRuntimeException("Failed to add VM:"+binding.getVMControllerID()); //$NON-NLS-1$
+ } catch(ResourceNotBoundException e) {
+ LogManager.logWarning(LogCommonConstants.CTX_CONTROLLER, "VM does not exist:"+binding.getVMControllerID()); //$NON-NLS-1$
+ }
+ }
}
Modified: trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ServerEvents.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ServerEvents.java 2009-03-03 15:31:10 UTC (rev 529)
+++ trunk/server/src/main/java/com/metamatrix/platform/vm/controller/ServerEvents.java 2009-03-03 16:16:24 UTC (rev 530)
@@ -32,8 +32,11 @@
void vmRemoved(VMControllerID id);
+ void vmUpdated(VMRegistryBinding binding);
+
void serviceAdded(ServiceRegistryBinding binding);
void serviceRemoved(ServiceID id);
+ void serviceUpdated(ServiceRegistryBinding binding);
}
Modified: trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java 2009-03-03 15:31:10 UTC (rev 529)
+++ trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java 2009-03-03 16:16:24 UTC (rev 530)
@@ -83,7 +83,7 @@
bindConstant().annotatedWith(Names.named(Configuration.VMID)).to(vmID);
bind(Host.class).annotatedWith(Names.named(Configuration.HOST)).toInstance(host);
bindConstant().annotatedWith(Names.named(Configuration.CLUSTERNAME)).to(systemName);
- bindConstant().annotatedWith(Names.named(Configuration.LOGFILE)).to(StringUtil.replaceAll(host.getFullName(), ".", "_")+this.vmName+".log"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ bindConstant().annotatedWith(Names.named(Configuration.LOGFILE)).to(StringUtil.replaceAll(host.getFullName(), ".", "_")+"_"+this.vmName+".log"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
bindConstant().annotatedWith(Names.named(Configuration.LOGDIR)).to(host.getLogDirectory());
Names.bindProperties(binder(), CurrentConfiguration.getInstance().getProperties());
16 years, 7 months
teiid SVN: r529 - branches.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-03-03 10:31:10 -0500 (Tue, 03 Mar 2009)
New Revision: 529
Added:
branches/symbol_refactoring_61/
Log:
creating symbol refactoring branch
Copied: branches/symbol_refactoring_61 (from rev 528, trunk)
16 years, 7 months
teiid SVN: r528 - in trunk/common-internal/src/main: resources/com/metamatrix/common and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2009-03-02 18:32:42 -0500 (Mon, 02 Mar 2009)
New Revision: 528
Modified:
trunk/common-internal/src/main/java/com/metamatrix/common/queue/WorkerPoolFactory.java
trunk/common-internal/src/main/resources/com/metamatrix/common/i18n.properties
Log:
TEIID-391
Modified: trunk/common-internal/src/main/java/com/metamatrix/common/queue/WorkerPoolFactory.java
===================================================================
--- trunk/common-internal/src/main/java/com/metamatrix/common/queue/WorkerPoolFactory.java 2009-03-02 23:27:55 UTC (rev 527)
+++ trunk/common-internal/src/main/java/com/metamatrix/common/queue/WorkerPoolFactory.java 2009-03-02 23:32:42 UTC (rev 528)
@@ -105,7 +105,7 @@
@Override
protected void afterExecute(Runnable r, Throwable t) {
if (t != null) {
- LogManager.logError(LogCommonConstants.CTX_POOLING, t, t.getMessage());
+ LogManager.logError(LogCommonConstants.CTX_POOLING, t, CommonPlugin.Util.getString("WorkerPool.uncaughtException")); //$NON-NLS-1$
}
activeCount.getAndDecrement();
completedCount.getAndIncrement();
Modified: trunk/common-internal/src/main/resources/com/metamatrix/common/i18n.properties
===================================================================
--- trunk/common-internal/src/main/resources/com/metamatrix/common/i18n.properties 2009-03-02 23:27:55 UTC (rev 527)
+++ trunk/common-internal/src/main/resources/com/metamatrix/common/i18n.properties 2009-03-02 23:32:42 UTC (rev 528)
@@ -3099,3 +3099,4 @@
VDBDefnXMLHelper.Unable_to_read_defn_file=Unable to read DEF file.
+WorkerPool.uncaughtException=Uncaught exception in worker pool
\ No newline at end of file
16 years, 7 months