Skip to content

Commit

Permalink
give bsh transformer scripts access to jdbctemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Aug 16, 2011
1 parent 58bd30b commit 609d45b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
@@ -1,9 +1,31 @@
/*
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU Lesser General Public License (the
* "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.jumpmind.symmetric.transform;

import java.util.Map;

import org.jumpmind.symmetric.ext.IBuiltInExtensionPoint;
import org.jumpmind.symmetric.ext.ICacheContext;
import org.springframework.jdbc.core.JdbcTemplate;

import bsh.Interpreter;

Expand All @@ -13,6 +35,8 @@ public class BshColumnTransform implements ISingleValueColumnTransform, IBuiltIn

public static final String NAME = "bsh";

protected JdbcTemplate jdbcTemplate;

public boolean isAutoRegister() {
return true;
}
Expand All @@ -26,6 +50,7 @@ public String transform(ICacheContext context, TransformColumn column,
throws IgnoreColumnException, IgnoreRowException {
try {
Interpreter interpreter = getInterpreter(context);
interpreter.set("jdbcTemplate", jdbcTemplate);
interpreter.set("currentValue", value);
interpreter.set("oldValue", oldValue);
for (String columnName : sourceValues.keySet()) {
Expand All @@ -50,4 +75,8 @@ protected Interpreter getInterpreter(ICacheContext context) {
}
return interpreter;
}

public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
}
Expand Up @@ -36,7 +36,9 @@

<bean id="substrColumnTransform" class="org.jumpmind.symmetric.transform.SubstrColumnTransform" />

<bean id="bshColumnTransform" class="org.jumpmind.symmetric.transform.BshColumnTransform" />
<bean id="bshColumnTransform" class="org.jumpmind.symmetric.transform.BshColumnTransform">
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>

<bean id="lookupColumnTransform" class="org.jumpmind.symmetric.transform.LookupColumnTransform">
<property name="jdbcTemplate" ref="jdbcTemplate" />
Expand Down

0 comments on commit 609d45b

Please sign in to comment.