开发者

Yml files in Play framework: can they refer to one another

开发者 https://www.devze.com 2023-04-06 05:47 出处:网络
In my application, I want to initialize it with large data. when I wrote all these data in one YML file it was about 4 MB but then the application didn\'t start making a java heap space error. when I

In my application, I want to initialize it with large data. when I wrote all these data in one YML file it was about 4 MB but then the application didn't start making a java heap space error. when I remove some parts of it till 109 KB, everything works but of course with some missing data.

My expectation to solve this problem is one of the following:

  1. make more than one file, But how to refer to an object in another YML file, is this possi开发者_StackOverflowble?
  2. Load a schema into the database via code at start up, is this easy to make?
  3. a solution proposed by any of this question readers ...

Note: most of the data in my application refers to each other so I couldn't separate them in more than one file totally.


You could look at DBUnit to dump and reload your whole DB, assuming it's SQL.


I did something like that on a startup Job:

@Override
public void doJob() {
    if (Image.count() == 0 && Play.mode.equals(Play.Mode.DEV)) {
        Fixtures.deleteAllModels();
        List<Image> images = Fixtures.loadYaml("Images.yml", List.class); //<-- this just loads the image objects (not in db yet)
        Fixtures.loadModels("Albums.yml"); // <----- this puts albums into db
        int i = 0;
        for (Image img : images) {
            img.album = Album.find("byName", img.album.name).first();
            img.save(); // <--- here image entities go into db
            i++;
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号