Пример #1
0
 private MovieList createMovieList() throws InvalidRatingScoreException {
   Movie movie1 = new Movie("First Movie", "Director A", new Rating(10));
   Movie movie2 = new Movie("Second Movie", "Director A", null);
   Movie movie3 = new Movie("Third Movie", "Director B", new Rating(4));
   MovieList movieList = new MovieList();
   movieList.add(movie1);
   movieList.add(movie2);
   movieList.add(movie3);
   return movieList;
 }
  @Override
  public void startUp() throws Exception {
    // do a DB backup, and keep last 15 copies
    File db = new File(Settings.getInstance().getSettingsFolder(), MOVIE_DB);
    Utils.createBackupFile(db);
    Utils.deleteOldBackupFile(db, 15);

    // configure database
    mvStore =
        new MVStore.Builder()
            .fileName(Settings.getInstance().getSettingsFolder() + File.separatorChar + MOVIE_DB)
            .compressHigh()
            .open();
    mvStore.setAutoCommitDelay(2000); // 2 sec
    mvStore.setRetentionTime(0);
    mvStore.setReuseSpace(true);

    // configure JSON
    objectMapper = new ObjectMapper();
    objectMapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
    objectMapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
    objectMapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
    objectMapper.configure(MapperFeature.AUTO_DETECT_FIELDS, false);
    objectMapper.setTimeZone(TimeZone.getDefault());
    objectMapper.setSerializationInclusion(Include.NON_DEFAULT);

    movieObjectWriter = objectMapper.writerFor(Movie.class);
    movieSetObjectWriter = objectMapper.writerFor(MovieSet.class);

    movieMap = mvStore.openMap("movies");
    movieSetMap = mvStore.openMap("movieSets");

    MovieList.getInstance().loadMoviesFromDatabase(movieMap, objectMapper);
    MovieList.getInstance().loadMovieSetsFromDatabase(movieSetMap, objectMapper);
    MovieList.getInstance().initDataAfterLoading();
    enabled = true;
  }