/**
 * @license
 * Copyright 2018 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.dao;

import foam.core.ClassInfo;
import foam.lib.json.Outputter;
import foam.lib.json.OutputterMode;
import java.io.*;

public class JDAO
  extends AbstractJDAO
{
  protected Outputter outputter_ = new Outputter(OutputterMode.STORAGE);

  public JDAO(foam.core.X x, ClassInfo classInfo, String filename) {
    this(x, new MapDAO(classInfo), filename);
  }

  public JDAO(foam.core.X x, DAO delegate, String filename) {
    super(x, delegate, filename + ".1");
    try {
      int index = 0;
      File file = null;
      while ( true ) {
        file = getX().get(foam.nanos.fs.Storage.class).get(filename + "." + index);
        if ( ! file.exists() ) break;
        loadJournal(file);
        index++;
      } 
    } catch ( IOException e ) {
      logger_.error(e);
      throw new RuntimeException(e);
    }
  }

  @Override
  protected Outputter getOutputter() {
    return outputter_;
  }
}

@@ -247,17 +247,27 @@
 java.io.
-*
+IOException
 ;%0A%0Apubli
@@ -595,15 +595,8 @@
 name
- + %22.1%22
 );%0A 
@@ -614,244 +614,75 @@
     
-int index = 0;%0A      File file = null;%0A      while ( true ) %7B%0A        file = getX().get(foam.nanos.fs.Storage.class).get(filename + %22.%22 + index);%0A        if ( ! file.exists() ) break;%0A        loadJournal(file);%0A        index++;%0A      %7D 
+loadJournal(getX().get(foam.nanos.fs.Storage.class).get(filename));
 %0A   

revert JDAO; keep JDAO same as before