Skip to content

Commit

Permalink
Merge pull request #274 from vhalbert/teiid-2881-crud
Browse files Browse the repository at this point in the history
TEIID-2881  fixed an issue regarding deleting from the cache
  • Loading branch information
shawkins committed Jul 7, 2014
2 parents d60a894 + 9b53a16 commit 7cefb69
Show file tree
Hide file tree
Showing 11 changed files with 918 additions and 252 deletions.
Expand Up @@ -86,41 +86,29 @@ public BasicConnectionFactory<InfinispanConnectionImpl> createConnectionFactory(
throws ResourceException {

if (protobinFile == null) {
throw new InvalidPropertyException(
InfinispanPlugin.Util
.getString("InfinispanManagedConnectionFactory.invalidProtobinFile")); //$NON-NLS-1$
throw new InvalidPropertyException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25030));
}

if (messageMarshallers == null) {
throw new InvalidPropertyException(
InfinispanPlugin.Util
.getString("InfinispanManagedConnectionFactory.invalidMessagenMarshallers")); //$NON-NLS-1$
throw new InvalidPropertyException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25029));
}

if (messageDescriptor == null) {
throw new InvalidPropertyException(
InfinispanPlugin.Util
.getString("InfinispanManagedConnectionFactory.invalidMessageDescriptor")); //$NON-NLS-1$
throw new InvalidPropertyException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25020));
}

if (this.cacheTypes == null) {
throw new InvalidPropertyException(
InfinispanPlugin.Util
.getString("InfinispanManagedConnectionFactory.cacheTypeMapNotSet")); //$NON-NLS-1$
throw new InvalidPropertyException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25021));
}

if (remoteServerList == null
&& hotrodClientPropertiesFile == null && cacheJndiName == null) {
throw new InvalidPropertyException(
InfinispanPlugin.Util
.getString("InfinispanManagedConnectionFactory.invalidServerConfiguration")); //$NON-NLS-1$
throw new InvalidPropertyException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25023));
}

determineCacheType();
if (cacheType == null) {
throw new InvalidPropertyException(
InfinispanPlugin.Util
.getString("InfinispanManagedConnectionFactory.invalidServerConfiguration")); //$NON-NLS-1$
throw new InvalidPropertyException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25022));
}

/*
Expand Down Expand Up @@ -412,9 +400,7 @@ protected synchronized ClassLoader loadClasses() throws ResourceException {
for (String type : types) {
List<String> mapped = StringUtil.getTokens(type, ":"); //$NON-NLS-1$
if (mapped.size() != 2) {
throw new InvalidPropertyException(
InfinispanPlugin.Util
.getString("InfinispanManagedConnectionFactory.invalidCacheTypeMap")); //$NON-NLS-1$
throw new InvalidPropertyException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25022));
}
final String cacheName = mapped.get(0);
String className = mapped.get(1);
Expand All @@ -435,9 +421,7 @@ protected synchronized ClassLoader loadClasses() throws ResourceException {

List<String> mapped = StringUtil.getTokens(mm, ":"); //$NON-NLS-1$
if (mapped.size() != 2) {
throw new InvalidPropertyException(
InfinispanPlugin.Util
.getString("InfinispanManagedConnectionFactory.invalidMarshallerMapping")); //$NON-NLS-1$
throw new InvalidPropertyException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25031, new Object[] {mm}));
}
final String className = mapped.get(0);
final String m = mapped.get(1);
Expand Down Expand Up @@ -541,10 +525,7 @@ private RemoteCacheManager createRemoteCacheWrapperFromJNDI(
}

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


Expand All @@ -555,10 +536,7 @@ private RemoteCacheManager createRemoteCacheWrapperFromJNDI(
return cacheContainer;
}

throw new ResourceException(
InfinispanPlugin.Util
.getString(
"InfinispanManagedConnectionFactory.JNDInotInstanceOfRemoteCacheManager", cacheContainer.getClass().getName())); //$NON-NLS-1$
throw new ResourceException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25026, cacheContainer.getClass().getName()));

}

Expand Down Expand Up @@ -627,7 +605,6 @@ public boolean equals(Object obj) {
public void cleanUp() {

messageMarshallerMap = null;
// registeredClasses=null;
typeMap = null;
cacheContainer = null;
pkMap = null;
Expand Down
Expand Up @@ -90,8 +90,8 @@ public Class<?> getType(String cacheName) throws TranslatorException {
if (type != null) {
return type;
}
final String msg = InfinispanPlugin.Util.getString("InfinispanConnection.typeNotFoundForCache", (cacheName != null ? cacheName : "Default") ); //$NON-NLS-1$ //$NON-NLS-2$
throw new TranslatorException(msg);
throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25040, (cacheName != null ? cacheName : "Default")));

}

@Override
Expand Down Expand Up @@ -124,9 +124,7 @@ public Descriptor getDescriptor(String cacheName)
throws TranslatorException {
Descriptor d = ctx.getMessageDescriptor(config.getMessageDescriptor());
if (d == null) {
throw new TranslatorException(
InfinispanPlugin.Util
.getString("InfinispanManagedConnectionFactory.noDescriptorFoundForCache", config.getMessageDescriptor(), cacheName)); //$NON-NLS-1$
throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25028, config.getMessageDescriptor(), cacheName));
}

return d;
Expand All @@ -135,9 +133,8 @@ public Descriptor getDescriptor(String cacheName)
@SuppressWarnings({ "unused", "rawtypes" })
@Override
public QueryFactory getQueryFactory(String cacheName) throws TranslatorException {
RemoteCache rc = getCache(cacheName);

return Search.getQueryFactory(rc);
return Search.getQueryFactory(getCache(cacheName));
}

@Override
Expand Down
Expand Up @@ -48,13 +48,15 @@ public class ClassRegistry {
private TeiidScriptEngine readEngine = new TeiidScriptEngine();

private Map<String, Class<?>> registeredClasses = new HashMap<String, Class<?>>();
private Map<String, Class<?>> classTableMap = new HashMap<String, Class<?>>();

public synchronized void registerClass(Class<?> clz) throws TranslatorException {
try {
// preload methods
readEngine.getMethodMap(clz);

registeredClasses.put(clz.getName(), clz);
classTableMap.put(clz.getSimpleName(), clz);
} catch (ScriptException e) {
throw new TranslatorException(e);
}
Expand All @@ -80,5 +82,9 @@ public Class<?> getRegisteredClass(String className) {
public List<Class<?>> getRegisteredClasses() {
return new ArrayList<Class<?>>(registeredClasses.values());
}

public Class<?> getRegisteredClassToTable(String tableName) {
return classTableMap.get(tableName);
}

}
Expand Up @@ -69,7 +69,7 @@ public static Object performKeySearch(String cacheName, String columnNameInSourc
if (results.size() == 1) {
return results.get(0);
} else if (results.size() > 1) {
throw new TranslatorException("Multiple objects found for key: " + value.toString());
throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25053, value.toString()));
}

return null;
Expand Down Expand Up @@ -184,9 +184,7 @@ private static FilterConditionContext buildQueryFromWhereClause(Condition criter
break;

default:
final String msg = InfinispanPlugin.Util
.getString("LuceneSearch.invalidOperator", new Object[] { op, "And, Or" }); //$NON-NLS-1$ //$NON-NLS-2$
throw new TranslatorException(msg);
throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25050, new Object[] { op, "And, Or" }));
}

} else if (criteria instanceof Comparison) {
Expand All @@ -205,6 +203,9 @@ private static FilterConditionContext buildQueryFromWhereClause(Condition criter

} else if (criteria instanceof IsNull) {
fcc = visit( (IsNull) criteria, queryBuilder, fcbc);
} else {
throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25054, criteria.toString()));

}
// else if (criteria instanceof Not) {
// LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing NOT criteria."); //$NON-NLS-1$
Expand Down Expand Up @@ -248,9 +249,7 @@ public static FilterConditionContext visit(Comparison obj, QueryBuilder queryBui
}

if (value == null) {
final String msg = InfinispanPlugin.Util
.getString("LuceneSearch.unsupportedComparingByNull"); //$NON-NLS-1$
throw new TranslatorException(msg);
throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25051));
}


Expand Down Expand Up @@ -294,9 +293,7 @@ public static FilterConditionContext visit(Comparison obj, QueryBuilder queryBui
return fcbc.having(getNameInSource(mdIDElement)).lte(value);

default:
final String msg = InfinispanPlugin.Util
.getString("LuceneSearch.invalidOperator", new Object[] { op, "NE, EQ, GT, GE, LT, LE" }); //$NON-NLS-1$ //$NON-NLS-2$
throw new TranslatorException(msg);
throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25050, new Object[] { op, "NE, EQ, GT, GE, LT, LE" }));
}

}
Expand All @@ -321,10 +318,7 @@ public static FilterConditionContext visit(In obj, QueryBuilder queryBuilder, Fi
v.add(value);
createdQuery = true;
} else {
String msg = InfinispanPlugin.Util.getString(
"LuceneSearch.Unsupported_expression", //$NON-NLS-1$
new Object[] { expr, "IN" }); //$NON-NLS-1$
throw new TranslatorException(msg);
throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25052, new Object[] { expr, "IN" }));
}
}

Expand Down Expand Up @@ -367,10 +361,7 @@ public static FilterConditionContext visit(Like obj, QueryBuilder queryBuilder,
}
return fcbc.having(getNameInSource(c)).like(value);
}
final String msg = InfinispanPlugin.Util.getString(
"LuceneSearch.Unsupported_expression", //$NON-NLS-1$
new Object[] { literalExp.toString(), "LIKE" }); //$NON-NLS-1$
throw new TranslatorException(msg);
throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25052, new Object[] { literalExp.toString(), "LIKE" }));

}

Expand Down
Expand Up @@ -216,8 +216,7 @@ public InfinispanExecution(Select query, RuntimeMetadata metadata,
}

if (numForeignKeys > 1) {
final String msg = InfinispanPlugin.Util.getString("InfinispanExecution.mulitpleCollectionsInQueryNotAllowed", new Object[] {query}); //$NON-NLS-1$
throw new TranslatorException(msg);
throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25000, new Object[] {query}));
}

colObjects = new Object[colSize];
Expand All @@ -238,9 +237,7 @@ public InfinispanExecution(Select query, RuntimeMetadata metadata,
// nis with a period indicates an internal class to the root
} else if (nis.indexOf(".") > 0) {
if (fk == null) {
final String msg = InfinispanPlugin.Util.getString("InfinispanExecution.noForeignKeyDefinedOnTable", new Object[] {query.getFrom()}); //$NON-NLS-1$
throw new TranslatorException(msg);

throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25001, new Object[] {query.getFrom()}));
}
DepthNode dn = new DepthNode(fk.getNameInSource() + "." + name, col);
colObjects[col] = dn;
Expand All @@ -263,10 +260,6 @@ public InfinispanExecution(Select query, RuntimeMetadata metadata,

@Override
public void execute() throws TranslatorException {

LogManager.logTrace(LogConstants.CTX_CONNECTOR,
"InfinsipanExecution command:", query.toString(), "using connection:", connection.getClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$


String nameInSource = getNameInSource(((NamedTable)query.getFrom().get(0)).getMetadataObject());

Expand All @@ -290,7 +283,6 @@ public List<Object> next() throws TranslatorException,

// return the next row in the cache
return (List<Object>) cacheResultsIt.next();

}

cacheResultsIt = null;
Expand All @@ -299,8 +291,7 @@ public List<Object> next() throws TranslatorException,
if (objResultsItr.hasNext()) {
List<Object> r = new ArrayList<Object>(colSize);
final Object o = objResultsItr.next();
sc.setAttribute(ClassRegistry.OBJECT_NAME, o, ScriptContext.ENGINE_SCOPE);

sc.setAttribute(ClassRegistry.OBJECT_NAME, o, ScriptContext.ENGINE_SCOPE);

if (depth > 0) {
// this contains the object returned from a node that has depth
Expand Down
Expand Up @@ -34,4 +34,40 @@ public class InfinispanPlugin {
*/
public static final BundleUtil Util = new BundleUtil(PLUGIN_ID, PLUGIN_ID + ".i18n", ResourceBundle.getBundle(PLUGIN_ID + ".i18n")); //$NON-NLS-1$ //$NON-NLS-2$

public static enum Event implements BundleUtil.Event{
TEIID25000,
TEIID25001,
TEIID25002,
TEIID25003,
TEIID25004,
TEIID25005,
TEIID25006,
TEIID25007,
TEIID25008,
TEIID25009,
TEIID25010,

TEIID25020,
TEIID25021,
TEIID25022,
TEIID25023,
TEIID25024,
TEIID25025,
TEIID25026,
TEIID25027,
TEIID25028,
TEIID25029,
TEIID25030,
TEIID25031,

TEIID25040,

TEIID25050,
TEIID25051,
TEIID25052,
TEIID25053,
TEIID25054,

TEIID25060
}
}

0 comments on commit 7cefb69

Please sign in to comment.