diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2014-03-20 04:17:37 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2014-03-20 04:17:37 +0000 |
commit | f73e6c33c75c8a0ba444ff200fdc234b59e59027 (patch) | |
tree | 9fb6c4cc452ec52b4945cf584800f7b068f26daf /src/main/java/com/healthmarketscience/jackcess/util | |
parent | a8a31e67bc8ec31c6377c5f38299314721a5c0fb (diff) | |
download | jackcess-f73e6c33c75c8a0ba444ff200fdc234b59e59027.tar.gz jackcess-f73e6c33c75c8a0ba444ff200fdc234b59e59027.zip |
add initial ColumnValidator support
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@849 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/main/java/com/healthmarketscience/jackcess/util')
4 files changed, 158 insertions, 0 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/util/ColumnValidator.java b/src/main/java/com/healthmarketscience/jackcess/util/ColumnValidator.java new file mode 100644 index 0000000..50c8916 --- /dev/null +++ b/src/main/java/com/healthmarketscience/jackcess/util/ColumnValidator.java @@ -0,0 +1,41 @@ +/* +Copyright (c) 2014 James Ahlborn + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +*/ + +package com.healthmarketscience.jackcess.util; + +import java.io.IOException; + +import com.healthmarketscience.jackcess.Column; + +/** + * Interface which allows for data manipulation/validation as values are being + * inserted into a database. + * + * @author James Ahlborn + */ +public interface ColumnValidator +{ + /** + * Validates and/or manipulates the given potential new value for the given + * column. This method may return an entirely different value or throw an + * exception if the input value is not valid. + */ + public Object validate(Column col, Object val) throws IOException; +} diff --git a/src/main/java/com/healthmarketscience/jackcess/util/ColumnValidatorFactory.java b/src/main/java/com/healthmarketscience/jackcess/util/ColumnValidatorFactory.java new file mode 100644 index 0000000..3a8a323 --- /dev/null +++ b/src/main/java/com/healthmarketscience/jackcess/util/ColumnValidatorFactory.java @@ -0,0 +1,38 @@ +/* +Copyright (c) 2014 James Ahlborn + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +*/ + +package com.healthmarketscience.jackcess.util; + +import com.healthmarketscience.jackcess.Column; + +/** + * Factory which generates appropriate ColumnValidators when Column instances + * are created. + * + * @author James Ahlborn + */ +public interface ColumnValidatorFactory +{ + /** + * Returns a ColumnValidator instance for the given column, must be + * non-{@code null}. + */ + public ColumnValidator createValidator(Column col); +} diff --git a/src/main/java/com/healthmarketscience/jackcess/util/SimpleColumnValidator.java b/src/main/java/com/healthmarketscience/jackcess/util/SimpleColumnValidator.java new file mode 100644 index 0000000..7dd8817 --- /dev/null +++ b/src/main/java/com/healthmarketscience/jackcess/util/SimpleColumnValidator.java @@ -0,0 +1,40 @@ +/* +Copyright (c) 2014 James Ahlborn + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +*/ + +package com.healthmarketscience.jackcess.util; + +import java.io.IOException; + +import com.healthmarketscience.jackcess.Column; + +/** + * Simple concrete implementation of ColumnValidator which simply returns the + * given value. + * + * @author James Ahlborn + */ +public class SimpleColumnValidator implements ColumnValidator +{ + public static final SimpleColumnValidator INSTANCE = new SimpleColumnValidator(); + + public Object validate(Column col, Object val) throws IOException { + return val; + } +} diff --git a/src/main/java/com/healthmarketscience/jackcess/util/SimpleColumnValidatorFactory.java b/src/main/java/com/healthmarketscience/jackcess/util/SimpleColumnValidatorFactory.java new file mode 100644 index 0000000..367f8c7 --- /dev/null +++ b/src/main/java/com/healthmarketscience/jackcess/util/SimpleColumnValidatorFactory.java @@ -0,0 +1,39 @@ +/* +Copyright (c) 2014 James Ahlborn + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +*/ + +package com.healthmarketscience.jackcess.util; + +import com.healthmarketscience.jackcess.Column; + +/** + * Simple concrete implementation of ColumnValidatorFactory which returns + * {@link SimpleColumnValidator.INSTANCE} for all columns. + * + * @author James Ahlborn + */ +public class SimpleColumnValidatorFactory implements ColumnValidatorFactory +{ + public static final SimpleColumnValidatorFactory INSTANCE = + new SimpleColumnValidatorFactory(); + + public ColumnValidator createValidator(Column col) { + return SimpleColumnValidator.INSTANCE; + } +} |