Package com.dbdeploy.scripts

Source Code of com.dbdeploy.scripts.ChangeScriptRepository

package com.dbdeploy.scripts;

import com.dbdeploy.exceptions.DuplicateChangeScriptException;
import com.dbdeploy.AvailableChangeScriptsProvider;

import java.util.Collections;
import java.util.List;


public class ChangeScriptRepository implements AvailableChangeScriptsProvider {

  private final List<ChangeScript> scripts;

  @SuppressWarnings("unchecked")
  public ChangeScriptRepository(List<ChangeScript> scripts) throws DuplicateChangeScriptException {
    this.scripts = scripts;

    Collections.sort(this.scripts);
   
    checkForDuplicateIds(scripts);
  }
 
  private void checkForDuplicateIds(List<ChangeScript> scripts) throws DuplicateChangeScriptException {
    long lastId = -1;
   
    for (ChangeScript script : scripts) {
      if (script.getId() == lastId) {
        throw new DuplicateChangeScriptException("There is more than one change script with number " + lastId);
      }
     
      lastId = script.getId();
    }
   
  }

  public List<ChangeScript> getOrderedListOfDoChangeScripts() {
    return Collections.unmodifiableList(scripts);
  }

  public List<ChangeScript> getAvailableChangeScripts() {
    return getOrderedListOfDoChangeScripts();
  }
}
TOP

Related Classes of com.dbdeploy.scripts.ChangeScriptRepository

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.