How to persist JavaFX properties in SQLite using ORMLite?

210 Views Asked by At

I am using JavaFX to create an app and I need (it would be very cool) to persist JavaFX properties such as SimpleStringProperty or SimpleObjectProperty.

I've seen this issue (now closed) that make use of the SimpleStringPropertyPersister class.

But, I don't actually have this class.

I've tried using the SerializablePersister class as my persister class, and ORMLite didn't send me a huge error. But I'm not sure that all JavaFX properties (at least the ones that I want to use) are Serializable, as in the javadoc it is not.

I'm using the last version available at the maven central :

<dependency>
  <groupId>com.j256.ormlite</groupId>
  <artifactId>ormlite-jdbc</artifactId>
  <version>5.1</version>
</dependency>

How can I achieve this ?

1

There are 1 best solutions below

1
Gray On

I am using JavaFX to create an app and I need (it would be very cool) to persist JavaFX properties such as SimpleStringProperty or SimpleObjectProperty.

The first link in a search on google for "ormlite custom persister" brought me to the documentation for customer persisters. Shocking. I spent a lot of time on the ORMLite docs so they should be helpful. There also is source code example of a custom date persister.

To quote from the docs:

When defining a data persister class from scratch, you could extend one of the other data type persisters or the BaseDataType class. You will need to define the following methods.

  • parseDefaultString – Converts a default string into a SQL argument suitable to be loaded into the database.
  • resultToSqlArg – Uses the DatabaseResults object to get the right SQL argument type out of the results.
  • sqlArgToJava – Converts the SQL argument to the associated Java class.