001package io.ebeaninternal.server.autotune.service; 002 003import io.ebeaninternal.server.autotune.model.Autotune; 004 005import java.util.Collection; 006 007/** 008 * Event where all tuned query information is collected. 009 * <p> 010 * This is for writing the "all" file on shutdown when using runtime tuning. 011 * </p> 012 */ 013public class AutoTuneAllCollection { 014 015 final Autotune document = new Autotune(); 016 017 final BaseQueryTuner queryTuner; 018 019 /** 020 * Construct to collect/report all tuned queries. 021 */ 022 public AutoTuneAllCollection(BaseQueryTuner queryTuner) { 023 this.queryTuner = queryTuner; 024 loadAllTuned(); 025 } 026 027 /** 028 * Return the number of origin elements in the document. 029 */ 030 public int size() { 031 return document.getOrigin().size(); 032 } 033 034 /** 035 * Return the Autotune document object. 036 */ 037 public Autotune getDocument() { 038 return document; 039 } 040 041 /** 042 * Write the document as an xml file. 043 */ 044 public void writeFile(String filePrefix, boolean withNow) { 045 046 AutoTuneXmlWriter writer = new AutoTuneXmlWriter(); 047 writer.write(document, filePrefix, withNow); 048 } 049 050 /** 051 * Loads all the existing query tuning into the document. 052 */ 053 private void loadAllTuned() { 054 055 Collection<TunedQueryInfo> all = queryTuner.getAll(); 056 for (TunedQueryInfo tuned : all) { 057 document.getOrigin().add(tuned.getOrigin()); 058 } 059 } 060 061}