Author: shawkins
Date: 2011-10-05 23:13:25 -0400 (Wed, 05 Oct 2011)
New Revision: 3535
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
branches/7.4.x/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java
branches/7.4.x/runtime/src/main/java/org/teiid/transport/SocketClientInstance.java
Log:
TEIID-1771 adding a fix to ensure backwards compatibility
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java 2011-10-06
02:25:05 UTC (rev 3534)
+++
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPWorkContext.java 2011-10-06
03:13:25 UTC (rev 3535)
@@ -29,7 +29,9 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
@@ -48,6 +50,39 @@
private static final long serialVersionUID = -6389893410233192977L;
+ public enum Version {
+ SEVEN_1("7.1"), //$NON-NLS-1$
+ SEVEN_2("7.2"), //$NON-NLS-1$
+ SEVEN_3("7.3"), //$NON-NLS-1$
+ SEVEN_4("7.4"); //$NON-NLS-1$
+
+ private String string;
+
+ private Version(String string) {
+ this.string = string;
+ }
+
+ @Override
+ public String toString() {
+ return string;
+ }
+
+ private static TreeMap<String, Version> versionMap = new TreeMap<String,
Version>();
+ static {
+ for (Version v : Version.values()) {
+ versionMap.put(v.toString(), v);
+ }
+ }
+
+ public static Version getVersion(String version) {
+ Map.Entry<String, Version> v = versionMap.floorEntry(version);
+ if (v == null) {
+ return SEVEN_1;
+ }
+ return v.getValue();
+ }
+ }
+
private static ThreadLocal<DQPWorkContext> CONTEXTS = new
ThreadLocal<DQPWorkContext>() {
protected DQPWorkContext initialValue() {
return new DQPWorkContext();
@@ -72,6 +107,7 @@
private SecurityHelper securityHelper;
private HashMap<String, DataPolicy> policies;
private boolean useCallingThread;
+ private Version clientVersion = Version.SEVEN_4;
public DQPWorkContext() {
}
@@ -257,5 +293,13 @@
}
}
return roles;
- }
+ }
+
+ public Version getClientVersion() {
+ return clientVersion;
+ }
+
+ public void setClientVersion(Version clientVersion) {
+ this.clientVersion = clientVersion;
+ }
}
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2011-10-06
02:25:05 UTC (rev 3534)
+++
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2011-10-06
03:13:25 UTC (rev 3535)
@@ -39,6 +39,7 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.XMLType;
import org.teiid.dqp.internal.process.DQPCore.ClientState;
+import org.teiid.dqp.internal.process.DQPWorkContext.Version;
import org.teiid.dqp.internal.process.SessionAwareCache.CacheID;
import org.teiid.dqp.internal.process.multisource.MultiSourceMetadataWrapper;
import org.teiid.dqp.message.RequestID;
@@ -77,6 +78,8 @@
private int vdbVersion;
private RequestID requestID;
+ private boolean labelAsName;
+
public MetaDataProcessor(DQPCore requestManager,
SessionAwareCache<PreparedPlan> planCache, String vdbName, int vdbVersion) {
this.requestManager = requestManager;
this.planCache = planCache;
@@ -97,6 +100,7 @@
this.requestID = requestId;
this.metadata =
workContext.getVDB().getAttachment(QueryMetadataInterface.class);
+ this.labelAsName = workContext.getClientVersion().compareTo(Version.SEVEN_3)
<= 0;
// If multi-source, use the multi-source wrapper as well
Set<String> multiModels = workContext.getVDB().getMultiSourceModelNames();
@@ -243,7 +247,7 @@
Class<?> type = symbol.getType();
column.put(ResultsMetadataConstants.DATA_TYPE,
DataTypeManager.getDataTypeName(type));
column.put(ResultsMetadataConstants.ELEMENT_LABEL, label);
- column.put(ResultsMetadataConstants.ELEMENT_NAME, metadata.getName(elementID));
+ column.put(ResultsMetadataConstants.ELEMENT_NAME,
labelAsName?label:metadata.getName(elementID));
GroupSymbol group = symbol.getGroupSymbol();
if(group == null || group.getMetadataID() == null) {
@@ -396,7 +400,7 @@
column.put(ResultsMetadataConstants.VIRTUAL_DATABASE_NAME, vdbName);
column.put(ResultsMetadataConstants.VIRTUAL_DATABASE_VERSION, vdbVersion);
column.put(ResultsMetadataConstants.GROUP_NAME, tableName);
- column.put(ResultsMetadataConstants.ELEMENT_NAME, columnName);
+ column.put(ResultsMetadataConstants.ELEMENT_NAME,
labelAsName?columnLabel:columnName);
column.put(ResultsMetadataConstants.ELEMENT_LABEL, columnLabel);
column.put(ResultsMetadataConstants.AUTO_INCREMENTING, Boolean.FALSE);
column.put(ResultsMetadataConstants.CASE_SENSITIVE, Boolean.FALSE);
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java 2011-10-06
02:25:05 UTC (rev 3534)
+++
branches/7.4.x/engine/src/test/java/org/teiid/dqp/internal/process/TestMetaDataProcessor.java 2011-10-06
03:13:25 UTC (rev 3535)
@@ -28,6 +28,7 @@
import java.util.Map;
import java.util.Set;
+import org.junit.Before;
import org.junit.Test;
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;
@@ -36,6 +37,7 @@
import org.teiid.client.metadata.ResultsMetadataConstants;
import org.teiid.core.types.DataTypeManager;
import org.teiid.dqp.internal.datamgr.FakeTransactionService;
+import org.teiid.dqp.internal.process.DQPWorkContext.Version;
import org.teiid.dqp.message.RequestID;
import org.teiid.metadata.Column;
import org.teiid.metadata.MetadataStore;
@@ -54,6 +56,12 @@
*/
@SuppressWarnings({"nls", "unchecked"})
public class TestMetaDataProcessor {
+
+ private boolean asLegacyClient;
+
+ @Before public void setup() {
+ asLegacyClient = false;
+ }
public Map[] helpGetMetadata(String sql, QueryMetadataInterface metadata, VDBMetaData
vdb) throws Exception {
// Prepare sql
@@ -66,6 +74,9 @@
requestMgr.setTransactionService(new FakeTransactionService());
DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(metadata,
vdb);
+ if (asLegacyClient) {
+ workContext.setClientVersion(Version.SEVEN_3);
+ }
// Initialize components
RequestID requestID = workContext.getRequestID(1);
@@ -81,7 +92,18 @@
Map[] metadata = helpGetMetadata("SELECT e1 FROM pm1.g1",
RealMetadataFactory.example1Cached(), RealMetadataFactory.example1VDB()); //$NON-NLS-1$
assertNotNull(metadata);
assertEquals(1, metadata.length);
+ assertEquals("e1",
metadata[0].get(ResultsMetadataConstants.ELEMENT_NAME)); //$NON-NLS-1$
+ assertEquals("e1",
metadata[0].get(ResultsMetadataConstants.ELEMENT_LABEL)); //$NON-NLS-1$
}
+
+ @Test public void testLegacyClient() throws Exception {
+ asLegacyClient = true;
+ Map[] metadata = helpGetMetadata("SELECT e1 as e2 FROM pm1.g1",
RealMetadataFactory.example1Cached(), RealMetadataFactory.example1VDB()); //$NON-NLS-1$
+ assertNotNull(metadata);
+ assertEquals(1, metadata.length);
+ assertEquals("e2",
metadata[0].get(ResultsMetadataConstants.ELEMENT_NAME)); //$NON-NLS-1$
+ assertEquals("e2",
metadata[0].get(ResultsMetadataConstants.ELEMENT_LABEL)); //$NON-NLS-1$
+ }
@Test public void testSimpleUpdate() throws Exception {
Map[] metadata = helpGetMetadata("INSERT INTO pm1.g1 (e1) VALUES
('x')", RealMetadataFactory.example1Cached(),
RealMetadataFactory.example1VDB()); //$NON-NLS-1$
@@ -246,7 +268,7 @@
Table pm1g2 = RealMetadataFactory.createPhysicalGroup("g2", pm1);
//$NON-NLS-1$
// Create physical elements
- List<Column> pm1g1e = RealMetadataFactory.createElements(pm1g1,
+ RealMetadataFactory.createElements(pm1g1,
new String[] { "e1"}, //$NON-NLS-1$
new String[] { DataTypeManager.DefaultDataTypes.SHORT});
Modified:
branches/7.4.x/runtime/src/main/java/org/teiid/transport/SocketClientInstance.java
===================================================================
---
branches/7.4.x/runtime/src/main/java/org/teiid/transport/SocketClientInstance.java 2011-10-06
02:25:05 UTC (rev 3534)
+++
branches/7.4.x/runtime/src/main/java/org/teiid/transport/SocketClientInstance.java 2011-10-06
03:13:25 UTC (rev 3535)
@@ -33,6 +33,7 @@
import org.teiid.core.crypto.DhKeyGenerator;
import org.teiid.core.crypto.NullCryptor;
import org.teiid.dqp.internal.process.DQPWorkContext;
+import org.teiid.dqp.internal.process.DQPWorkContext.Version;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.logging.MessageLevel;
@@ -125,6 +126,8 @@
}
private void receivedHahdshake(Handshake handshake) throws CommunicationException {
+ String clientVersion = handshake.getVersion();
+ this.workContext.setClientVersion(Version.getVersion(clientVersion));
if (usingEncryption) {
byte[] returnedPublicKey = handshake.getPublicKey();