Skip to content

Commit

Permalink
TEIID-4333 changed so supportsCompareCriteriaOrdered is set based on …
Browse files Browse the repository at this point in the history
…JDG version that is determined at runtime based on the version of the cache accessed. Also, cleaned up libmode to remove old code related to remote cache that is now fully supported under hotrod.
  • Loading branch information
vhalbert committed Aug 3, 2016
1 parent 1a7f471 commit cac67f5
Show file tree
Hide file tree
Showing 20 changed files with 366 additions and 635 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ public RemoteCache getCache(String cacheName) {
Assertion.isNotNull(cacheName, "Program Error: Cache Name is null");
}

return cacheContainer.getCache(cacheName);
return cacheContainer.getCache(cacheName);

}

/**
Expand Down Expand Up @@ -666,6 +667,12 @@ private RemoteCacheManager getRemoteCacheFromJNDI(
protected void registerWithCacheManager(SerializationContext ctx, RemoteCacheManager cc, ClassLoader cl, boolean useAnnotations) throws ResourceException {

}

public String getVersion() throws TranslatorException {
RemoteCache rc = this.getCache(this.getCacheNameProxy().getPrimaryCacheKey());
if (rc != null) return rc.getProtocolVersion();
return "";
}

@Override
public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public InfinispanConnectionImpl(AbstractInfinispanManagedConnectionFactory confi
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Infinispan Connection has been newly created "); //$NON-NLS-1$
}

@Override
public String getVersion() throws TranslatorException {
return this.config.getVersion();
}

/**
* Close the connection, if a connection requires closing.
* (non-Javadoc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public void testConnection() throws Exception {

assertNotNull(conn.getCache());


assertEquals("Version doesn't start with 7.2", conn.getVersion().startsWith("7.2"));


conn.cleanUp();

} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.jboss.teiid.jdg_remote.pojo.AllTypes;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,20 @@
*/
package org.teiid.resource.adapter.infinispan;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.resource.ResourceException;

import org.infinispan.Cache;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.query.Search;
import org.infinispan.query.dsl.QueryFactory;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
Expand All @@ -39,154 +51,202 @@
*/
public class InfinispanCacheRAConnection extends BasicConnection
implements InfinispanCacheConnection {

private InfinispanManagedConnectionFactory config;

private InfinispanCacheWrapper<?, ?> cacheWrapper;

public InfinispanCacheRAConnection(InfinispanManagedConnectionFactory config) {
this.cacheWrapper = config.getCacheWrapper();
this.config = config;
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Infinispan-Library Mode Cache Connection has been created."); //$NON-NLS-1$
}

@Override
public Object getCache() throws TranslatorException {
return cacheWrapper.getCache();
}

@Override
public Collection<Object> getAll() throws TranslatorException {
return cacheWrapper.getAll();
public InfinispanManagedConnectionFactory getConfig() {
return config;
}

@Override
public QueryFactory getQueryFactory() throws TranslatorException {
return cacheWrapper.getQueryFactory();
public String getVersion() throws TranslatorException {
return this.getConfig().getVersion();
}

@Override
public String getPkField() {
return cacheWrapper.getPkField();
}

@SuppressWarnings("unused")
@Override
public Class<?> getCacheKeyClassType() throws TranslatorException {
return cacheWrapper.getCacheKeyClassType();
}

/**
* {@inheritDoc}
*
* @see org.teiid.translator.object.ObjectConnection#getCacheName()
* @see org.teiid.translator.object.ObjectConnection#getPkField()
*/
@Override
public String getCacheName() {
return cacheWrapper.getCacheName();
public String getPkField() {
return getConfig().getPKey();
}

/**
* {@inheritDoc}
*
* @see org.teiid.translator.object.ObjectConnection#getCacheClassType()
* @see org.teiid.translator.object.ObjectConnection#getCacheKeyClassType()
*/
@Override
public Class<?> getCacheClassType() throws TranslatorException {
return cacheWrapper.getCacheClassType();
public Class<?> getCacheKeyClassType() {
return getConfig().getCacheKeyClassType();
}

/**
* {@inheritDoc}
*
* @see org.teiid.translator.object.ObjectConnection#add(java.lang.Object, java.lang.Object)
* @see org.teiid.translator.object.ObjectConnection#getCacheName()
*/
@Override
public void add(Object key, Object value) throws TranslatorException {
this.cacheWrapper.add(key, value);
public String getCacheName() {
return getTargetCacheName();
}

/**
* {@inheritDoc}
*
* @see org.teiid.translator.object.ObjectConnection#remove(java.lang.Object)
* @see org.teiid.translator.object.ObjectConnection#getCacheClassType()
*/
@Override
public Object remove(Object key) throws TranslatorException {
return this.cacheWrapper.remove(key);
public Class<?> getCacheClassType() {
return getConfig().getCacheClassType();
}

/**
* {@inheritDoc}
*
* @see org.teiid.translator.object.ObjectConnection#update(java.lang.Object, java.lang.Object)
* @see org.teiid.translator.object.ObjectConnection#getClassRegistry()
*/
@Override
public void update(Object key, Object value) throws TranslatorException {
this.cacheWrapper.update(key, value);
public ClassRegistry getClassRegistry() {
return getConfig().getClassRegistry();
}

@Override
public DDLHandler getDDLHandler() {
return getConfig().getCacheNameProxy().getDDLHandler();
}

@Override
public boolean isAlive() {
boolean alive = (config == null ? false : this.config.isAlive());
LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Infinispan Library Mode Connection is alive:", alive); //$NON-NLS-1$
return (alive);

}

private String getTargetCacheName() {
if (getDDLHandler().isStagingTarget()) {
return config.getCacheNameProxy().getStageCacheAliasName();
}
return config.getCacheNameProxy().getPrimaryCacheAliasName();// public String getCacheName() {
// // return the cacheName that is mapped as the alias
// return cacheNameProxy.getPrimaryCacheAliasName();
// }
//
// public String getCacheStagingName() {
// return cacheNameProxy.getStageCacheAliasName();
// }

}

public Cache<Object, Object> getCache() {
return getCache(getTargetCacheName());
}

/**
* {@inheritDoc}
*
* @see org.teiid.translator.object.ObjectConnection#getClassRegistry()
* @see org.teiid.translator.object.ObjectConnection#getCache(java.lang.String)
*/
@Override
public ClassRegistry getClassRegistry() {
return cacheWrapper.getClassRegistry();
public Cache<Object, Object> getCache(String cacheName) {
return config.getCache(cacheName);
}

@Override
public Collection<Object> getAll() {
Collection<Object> objs = new ArrayList<Object>();
Cache c = getCache(getTargetCacheName());
for (Object k : c.keySet()) {
objs.add(c.get(k));
}
return objs;
}

/**
* {@inheritDoc}
*
* @see org.teiid.translator.object.ObjectConnection#get(java.lang.Object)
*/
/* split out for testing purposes */
protected Object performJNDICacheLookup(String jndiName) throws Exception {
Context context = null;

context = new InitialContext();
final Object cache = context.lookup(jndiName);

if (cache == null) {
throw new ResourceException(
InfinispanManagedConnectionFactory.UTIL
.getString(
"InfinispanManagedConnectionFactory.unableToFindCacheUsingJNDI", jndiName)); //$NON-NLS-1$
}

return cache;
}

@Override
public Object get(Object key) throws TranslatorException {
return this.cacheWrapper.get(key);
public void cleanUp() {
config = null;

}

/**
* {@inheritDoc}
*
* @see javax.resource.cci.Connection#close()
*/
@SuppressWarnings("rawtypes")
@Override
public void close() {
this.cacheWrapper = null;
public QueryFactory getQueryFactory() {

return Search.getQueryFactory(getCache(getTargetCacheName()));

}

/**
* {@inheritDoc}
*
* @see org.teiid.translator.object.ObjectConnection#getCache(java.lang.String)
*/
@Override
public Object getCache(String cacheName) throws TranslatorException {
return cacheWrapper.getCache(cacheName);
public Object get(Object key) {
return getCache(getTargetCacheName()).get(key);
}

/**
* {@inheritDoc}
*
* @see org.teiid.translator.object.ObjectConnection#clearCache(java.lang.String)
*/
@Override
public void clearCache(String cacheName) throws TranslatorException {
cacheWrapper.clearCache(cacheName);
public void add(Object key, Object value) {
getCache(getTargetCacheName()).put(key, value);
}

@Override
public DDLHandler getDDLHandler() {
return cacheWrapper.getDDLHandler();
public Object remove(Object key) {
return getCache(getTargetCacheName()).removeAsync(key);
}

@Override
public void update(Object key, Object value) {
getCache(getTargetCacheName()).replace(key, value);
}

@Override
public void clearCache(String cacheName) throws TranslatorException {
getCache(cacheName).clear();
}

protected void shutDownCacheManager() {
getCache().stop();
}

/**
* Returns the <code>SearchType</code> that will be used to perform
* dynamic searching of the cache.
* @return SearchType
*/
@Override
public SearchType getSearchType() {
return cacheWrapper.getSearchType();
return new DSLSearch(this);
}

/**
* {@inheritDoc}
*
* @see javax.resource.cci.Connection#close()
*/
@Override
public void close() throws ResourceException {
}


}

0 comments on commit cac67f5

Please sign in to comment.