Author: shawkins
Date: 2011-04-20 14:30:08 -0400 (Wed, 20 Apr 2011)
New Revision: 3106
Modified:
trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
trunk/runtime/src/main/java/org/teiid/transport/ODBCClientInstance.java
trunk/runtime/src/main/java/org/teiid/transport/PgFrontendProtocol.java
Log:
TEIID-1176 fix for odbc synch handling
Modified: trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2011-04-19
20:50:46 UTC (rev 3105)
+++ trunk/runtime/src/main/java/org/teiid/odbc/ODBCServerRemoteImpl.java 2011-04-20
18:30:08 UTC (rev 3106)
@@ -136,11 +136,12 @@
private static Pattern rollbackPattern =
Pattern.compile("ROLLBACK\\s*(to)*\\s*(\\w+\\d+_*)*"); //$NON-NLS-1$
private TeiidDriver driver;
- private ODBCClientInstance clientInstance;
private ODBCClientRemote client;
private Properties props;
private AuthenticationType authType;
private ConnectionImpl connection;
+ private boolean shouldSynch;
+ private boolean synchCalled;
private volatile ResultsFuture<Boolean> executionFuture;
@@ -151,7 +152,6 @@
public ODBCServerRemoteImpl(ODBCClientInstance client, AuthenticationType authType,
TeiidDriver driver) {
this.driver = driver;
this.client = client.getClient();
- this.clientInstance = client;
this.authType = authType;
}
@@ -179,7 +179,7 @@
this.connection = (ConnectionImpl)driver.connect(url, info);
int hash = this.connection.getConnectionId().hashCode();
this.client.authenticationSucess(hash, hash);
- sync();
+ ready(true);
} catch (SQLException e) {
this.client.errorOccurred(e);
terminate();
@@ -252,7 +252,7 @@
@Override
public void unsupportedOperation(String msg) {
this.client.errorOccurred(msg);
- sync();
+ ready(true);
}
@Override
@@ -267,7 +267,7 @@
final Portal query = this.portalMap.get(bindName);
if (query == null) {
this.client.errorOccurred(RuntimePlugin.Util.getString("not_bound",
bindName)); //$NON-NLS-1$
- sync();
+ ready(true);
}
else {
if (query.sql.trim().isEmpty()) {
@@ -297,9 +297,7 @@
} catch (Throwable e) {
client.errorOccurred(e);
}
- if (!clientInstance.hasPending()) {
- sync();
- }
+ ready(false);
}
});
} catch (SQLException e) {
@@ -418,7 +416,7 @@
if (query.trim().length() == 0) {
this.client.emptyQueryReceived();
- sync();
+ ready(false);
return;
}
QueryWorkItem r = new QueryWorkItem(query);
@@ -431,9 +429,12 @@
private boolean isAwaitingAsynch() {
if (this.executionFuture != null) {
this.client.errorOccurred("Awaiting asynch result"); //$NON-NLS-1$
- sync();
+ ready(true);
return true;
}
+ synchronized (this) {
+ this.shouldSynch = false;
+ }
return false;
}
@@ -445,7 +446,7 @@
Prepared query = this.preparedMap.get(prepareName);
if (query == null) {
this.client.errorOccurred(RuntimePlugin.Util.getString("no_stmt_found",
prepareName)); //$NON-NLS-1$
- sync();
+ ready(true);
}
else {
try {
@@ -476,9 +477,27 @@
@Override
public void sync() {
- if (this.executionFuture != null) {
- return;
+ boolean ready = false;
+ synchronized (this) {
+ synchCalled = true;
+ ready = this.shouldSynch;
}
+ if (ready) {
+ ready(true);
+ }
+ }
+
+ private void ready(boolean sendAlways) {
+ synchronized (this) {
+ if (!sendAlways) {
+ shouldSynch = true;
+ if (!synchCalled) {
+ return;
+ }
+ }
+ shouldSynch = true;
+ synchCalled = false;
+ }
boolean inTxn = false;
boolean failedTxn = false;
try {
@@ -581,7 +600,7 @@
@Override
public void functionCall(int oid) {
this.client.errorOccurred(RuntimePlugin.Util.getString("lo_not_supported"));
//$NON-NLS-1$
- sync();
+ ready(true);
}
@Override
@@ -640,7 +659,7 @@
modfiedSQL = fixSQL(sql);
} catch (Throwable e) {
client.errorOccurred(e);
- sync();
+ ready(true);
return;
} finally {
try {
@@ -661,7 +680,7 @@
} catch(IOException e) {
client.errorOccurred(e);
}
- sync();
+ ready(false);
}
}
Modified: trunk/runtime/src/main/java/org/teiid/transport/ODBCClientInstance.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/ODBCClientInstance.java 2011-04-19
20:50:46 UTC (rev 3105)
+++ trunk/runtime/src/main/java/org/teiid/transport/ODBCClientInstance.java 2011-04-20
18:30:08 UTC (rev 3106)
@@ -45,7 +45,6 @@
private ODBCClientRemote client;
private ODBCServerRemoteImpl server;
private ReflectionHelper serverProxy = new ReflectionHelper(ODBCServerRemote.class);
- private boolean hasPending;
public ODBCClientInstance(final ObjectChannel channel,
ODBCServerRemote.AuthenticationType authType, TeiidDriver driver) {
this.client =
(ODBCClientRemote)Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]
{ODBCClientRemote.class}, new InvocationHandler() {
@@ -76,10 +75,6 @@
server.terminate();
}
- public boolean hasPending() {
- return hasPending;
- }
-
@Override
public void onConnection() throws CommunicationException {
}
@@ -88,7 +83,6 @@
public void receivedMessage(Object msg) throws CommunicationException {
if (msg instanceof PGRequest) {
PGRequest request = (PGRequest)msg;
- hasPending = request.hasPending;
processMessage(request.struct);
}
}
Modified: trunk/runtime/src/main/java/org/teiid/transport/PgFrontendProtocol.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/PgFrontendProtocol.java 2011-04-19
20:50:46 UTC (rev 3105)
+++ trunk/runtime/src/main/java/org/teiid/transport/PgFrontendProtocol.java 2011-04-20
18:30:08 UTC (rev 3106)
@@ -131,7 +131,6 @@
byte[] data = createByteArray(this.dataLength - 4);
buffer.readBytes(data);
createRequestMessage(this.messageType, new NullTerminatedStringDataInputStream(new
DataInputStream(new ByteArrayInputStream(data, 0, this.dataLength-4)), this.encoding));
- message.hasPending = buffer.readableBytes() > 0;
this.dataLength = null;
this.messageType = null;
return message;
@@ -397,7 +396,6 @@
public static class PGRequest {
ServiceInvocationStruct struct;
- boolean hasPending;
}
static class NullTerminatedStringDataInputStream extends DataInputStream{