Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.j256.ormlite.field.FieldType;
- import com.j256.ormlite.field.SqlType;
- import com.j256.ormlite.field.types.StringType;
- import javafx.beans.property.SimpleStringProperty;
- import javafx.beans.property.StringProperty;
- public class StringPropertyPersister extends StringType {
- private static final StringPropertyPersister INSTANCE = new StringPropertyPersister();
- private StringPropertyPersister() {
- super(SqlType.STRING, new Class<?>[]{StringProperty.class});
- }
- public static StringPropertyPersister getSingleton() {
- return INSTANCE;
- }
- @Override
- public Object javaToSqlArg(FieldType fieldType, Object javaObject) {
- if (javaObject == null) {
- return "";
- } else {
- StringProperty property = (StringProperty) javaObject;
- return property.getValue();
- }
- }
- @Override
- public Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos) {
- if (sqlArg == null) {
- return new SimpleStringProperty("");
- } else {
- String value = (String) sqlArg;
- if (value == null) {
- value = "";
- }
- return new SimpleStringProperty(value);
- }
- }
- }
Add Comment
Please, Sign In to add comment