Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Could you please help me to achieve the following functionality
- *
- *
- */
- package testapp;
- import com.j256.ormlite.dao.Dao;
- import com.j256.ormlite.dao.DaoManager;
- import com.j256.ormlite.jdbc.JdbcPooledConnectionSource;
- import com.j256.ormlite.table.TableUtils;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class TestApp {
- public static void main(String[] args) {
- try {
- //This example uses ORMLite
- //A solution with the help of any ORM will be fine
- JdbcPooledConnectionSource jdbcPooledConnectionSource = new JdbcPooledConnectionSource("jdbc:h2:mem:fzn");
- //ConversionPreset is my Entity POJO class
- Dao<ConversionPreset, Integer> conversionPresetDao = DaoManager.createDao(jdbcPooledConnectionSource, ConversionPreset.class);
- TableUtils.createTable(jdbcPooledConnectionSource, ConversionPreset.class);
- //Create an entity c1
- ConversionPreset c1 = new ConversionPreset(null, "TITLE", "ACODEC", "BITRATE", "ARATE", "VCODEC", "VBITRATE", "VRATE", "CONTAINER");
- //Persist or save in database
- conversionPresetDao.createOrUpdate(c1);
- //Retrieve the same from database
- ConversionPreset c2 = conversionPresetDao.queryForAll().get(0);
- //Change any field
- c2.setABitrate("ABR_CHANGED");
- conversionPresetDao.createOrUpdate(c2);
- //But the following test reveals that the same field of
- //c1 is not changed. But I need the change to be automatically reflected
- System.out.println(c1.getABitrate());
- //The reason I am needing this is for developing a small Download Manager
- //cum Converter. There are two threads in the app. UI thread and Downloader Thread
- //If the changes were reflected automatically, the downloader thread can be completely
- //de coupled from th UI. So that the downloader thread doesn't need to access the methods
- //of UI thread. Instead it will write to the entities and persist in database, then the UI
- //controls bound to the underlying javafx properties automatically reads them.
- //Feel free to suggest a better solution
- } catch (SQLException ex) {
- Logger.getLogger(TestApp.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement