Skip to content

Commit

Permalink
Added the beginnings of an idea for a bsh data router
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Aug 10, 2009
1 parent 669a2d6 commit dd7b88e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions symmetric/pom.xml
Expand Up @@ -558,6 +558,11 @@
<artifactId>commons-math</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.beanshell</groupId>
<artifactId>bsh</artifactId>
<version>2.0b4</version>
</dependency>
<!-- Should the jetty stuff be split to another project: symmetric-jetty? -->
<dependency>
<groupId>org.mortbay.jetty</groupId>
Expand Down
Expand Up @@ -24,13 +24,17 @@
import java.util.Map;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ddlutils.model.Column;
import org.jumpmind.symmetric.db.IDbDialect;
import org.jumpmind.symmetric.model.DataMetaData;
import org.jumpmind.symmetric.model.Node;

public abstract class AbstractDataRouter implements IDataRouter {

protected final Log logger = LogFactory.getLog(getClass());

private boolean autoRegister = true;

public boolean isAutoRegister() {
Expand Down
@@ -0,0 +1,48 @@
package org.jumpmind.symmetric.route;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.jumpmind.symmetric.model.DataMetaData;
import org.jumpmind.symmetric.model.Node;

import bsh.EvalError;
import bsh.Interpreter;

/**
* In Progress ...
* TODO javadoc and unit test
*/
public class BshDataRouter extends AbstractDataRouter {

public void completeBatch(IRouterContext context) {
}

public Collection<String> routeToNodes(IRouterContext context, DataMetaData dataMetaData, Set<Node> nodes,
boolean initialLoad) {
try {
Interpreter interpreter = new Interpreter();
interpreter.set("nodes", nodes);
// set old and new and cur column values
Object value = interpreter.eval(dataMetaData.getTrigger().getRouterExpression());
if (value instanceof Boolean && value.equals(Boolean.TRUE)) {
return toNodeIds(nodes);
} else if (value instanceof Collection<?>) {
Collection<?> values = (Collection<?>) value;
Set<String> nodeIds = new HashSet<String>(values.size());
for (Object v : values) {
if (v != null) {
nodeIds.add(v.toString());
}
}
return nodeIds;
}
} catch (EvalError e) {
logger.error(e, e);
}
return Collections.emptySet();
}

}

0 comments on commit dd7b88e

Please sign in to comment.