Skip to content

Commit

Permalink
0001013: BshDatabaseWriterFilter should bind the error to use in a HA…
Browse files Browse the repository at this point in the history
…NDLE_ERROR script
  • Loading branch information
chenson42 committed Jan 29, 2013
1 parent ff8c6d2 commit 8a8a9e2
Showing 1 changed file with 30 additions and 8 deletions.
@@ -1,3 +1,23 @@
/*
* 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.load;

import java.util.HashSet;
Expand Down Expand Up @@ -31,6 +51,7 @@ public class BshDatabaseWriterFilter implements IDatabaseWriterFilter, IDatabase
private static final String CONTEXT = "context";
private static final String TABLE = "table";
private static final String DATA = "data";
private static final String ERROR = "error";
private static final String ENGINE = "engine";
private final String INTERPRETER_KEY = String.format("%d.BshInterpreter", hashCode());
private final String BATCH_COMPLETE_SCRIPTS_KEY = String.format("%d.BatchCompleteScripts",
Expand Down Expand Up @@ -59,15 +80,15 @@ public BshDatabaseWriterFilter(ISymmetricEngine symmetricEngine,
}

public boolean beforeWrite(DataContext context, Table table, CsvData data) {
return processLoadFilters(context, table, data, WriteMethod.BEFORE_WRITE);
return processLoadFilters(context, table, data, null, WriteMethod.BEFORE_WRITE);
}

public void afterWrite(DataContext context, Table table, CsvData data) {
processLoadFilters(context, table, data, WriteMethod.AFTER_WRITE);
processLoadFilters(context, table, data, null, WriteMethod.AFTER_WRITE);
}

public boolean handleError(DataContext context, Table table, CsvData data, Exception ex) {
return processLoadFilters(context, table, data, WriteMethod.HANDLE_ERROR);
public boolean handleError(DataContext context, Table table, CsvData data, Exception error) {
return processLoadFilters(context, table, data, error, WriteMethod.HANDLE_ERROR);
}

public boolean handlesMissingTable(DataContext context, Table table) {
Expand Down Expand Up @@ -98,13 +119,14 @@ protected Interpreter getInterpreter(Context context) {
return interpreter;
}

protected void bind(Interpreter interpreter, DataContext context, Table table, CsvData data)
protected void bind(Interpreter interpreter, DataContext context, Table table, CsvData data, Exception error)
throws EvalError {

interpreter.set(ENGINE, this.symmetricEngine);
interpreter.set(CONTEXT, context);
interpreter.set(TABLE, table);
interpreter.set(DATA, data);
interpreter.set(ERROR, error);

if (data != null) {
Map<String, String> sourceValues = data.toColumnNameValuePairs(table.getColumnNames(),
Expand Down Expand Up @@ -162,7 +184,7 @@ protected void executeScripts(DataContext context, String key) {
Interpreter interpreter = getInterpreter(context);
String currentScript = null;
try {
bind(interpreter, context, null, null);
bind(interpreter, context, null, null, null);
if (scripts != null) {
for (String script : scripts) {
currentScript = script;
Expand All @@ -180,7 +202,7 @@ protected void executeScripts(DataContext context, String key) {

}

protected boolean processLoadFilters(DataContext context, Table table, CsvData data,
protected boolean processLoadFilters(DataContext context, Table table, CsvData data, Exception error,
WriteMethod writeMethod) {

boolean writeRow = true;
Expand All @@ -191,7 +213,7 @@ protected boolean processLoadFilters(DataContext context, Table table, CsvData d
if (loadFiltersForTable != null && loadFiltersForTable.size() > 0) {
try {
Interpreter interpreter = getInterpreter(context);
bind(interpreter, context, table, data);
bind(interpreter, context, table, data, error);
for (LoadFilter filter : loadFiltersForTable) {
currentFilter = filter;
addBatchScriptsToContext(context, filter);
Expand Down

0 comments on commit 8a8a9e2

Please sign in to comment.