View Javadoc
1   /*
2    *    Copyright 2006-2023 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.generator.api;
17  
18  /**
19   * This interface can be implemented to return progress information from the file generation process.
20   *
21   * <p>During the execution of code generation, there are three main operations:
22   * database introspection, code generation based on the results of
23   * introspection, and then merging/saving generated files. Methods
24   * in this interface accordingly and in this order:
25   * <ol>
26   * <li>introspectionStarted(int)</li>
27   * <li>(Repeatedly) startTask(String)</li>
28   * <li>generationStarted(int)</li>
29   * <li>(Repeatedly) startTask(String)</li>
30   * <li>saveStarted(int)</li>
31   * <li>(Repeatedly) startTask(String)</li>
32   * <li>done()</li>
33   * </ol>
34   *
35   * <p>Periodically, the <code>checkCancel()</code> method will be called to see if the
36   * method should be canceled.
37   *
38   * <p>For planning purposes, the most common use case will have a ratio of 20%
39   * introspection tasks, 40% generation tasks, and 40% save tasks.
40   *
41   * @author Jeff Butler
42   */
43  public interface ProgressCallback {
44      /**
45       * Called to note the start of the introspection phase, and to note the
46       * maximum number of startTask messages that will be sent for the
47       * introspection phase.
48       *
49       * @param totalTasks
50       *            the maximum number of times startTask will be called for the
51       *            introspection phase.
52       */
53      default void introspectionStarted(int totalTasks) {}
54  
55      /**
56       * Called to note the start of the generation phase, and to note the maximum
57       * number of startTask messages that will be sent for the generation phase.
58       *
59       * @param totalTasks
60       *            the maximum number of times startTask will be called for the
61       *            generation phase.
62       */
63      default void generationStarted(int totalTasks) {}
64  
65      /**
66       * Called to note the start of the file saving phase, and to note the
67       * maximum number of startTask messages that will be sent for the file
68       * saving phase.
69       *
70       * @param totalTasks
71       *            the maximum number of times startTask will be called for the
72       *            file saving phase.
73       */
74      default void saveStarted(int totalTasks) {}
75  
76      /**
77       * Called to denote the beginning of a save task.
78       *
79       * @param taskName
80       *            a descriptive name of the current work step
81       */
82      default void startTask(String taskName) {}
83  
84      /**
85       * This method is called when all generated files have been saved.
86       */
87      default void done() {}
88  
89      /**
90       * The method is called periodically during a long-running method.
91       * If the implementation throws <code>InterruptedException</code> then
92       * the method will be canceled. Any files that have already been saved will
93       * remain on the file system.
94       *
95       * @throws InterruptedException
96       *             if the operation should be halted
97       */
98      default void checkCancel() throws InterruptedException {}
99  }