1 /**
2 * Copyright 2006-2016 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 * http://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
20 * file generation process.
21 *
22 * During the execution of code generation, there are three main operations:
23 * database introspection, code generation based on the results of
24 * introspection, and then merging/saving generated files. Methods
25 * in this interface accordingly and in this order:
26 * <ol>
27 * <li>introspectionStarted(int)</li>
28 * <li>(Repeatedly) startTask(String)</li>
29 * <li>generationStarted(int)</li>
30 * <li>(Repeatedly) startTask(String)</li>
31 * <li>saveStarted(int)</li>
32 * <li>(Repeatedly) startTask(String)</li>
33 * <li>done()</li>
34 * </ol>
35 * <p>
36 * Periodically, the <code>checkCancel()</code> method will be called to see if the
37 * method should be canceled.
38 * <p>
39 * For planning purposes, the most common use case will have a ratio of 20%
40 * introspection tasks, 40% generation tasks, and 40% save tasks.
41 *
42 * @author Jeff Butler
43 */
44 public interface ProgressCallback {
45 /**
46 * Called to note the start of the introspection phase, and to note the
47 * maximum number of startTask messages that will be sent for the
48 * introspection phase.
49 *
50 * @param totalTasks
51 * the maximum number of times startTask will be called for the
52 * introspection phase.
53 */
54 void introspectionStarted(int totalTasks);
55
56 /**
57 * Called to note the start of the generation phase, and to note the maximum
58 * number of startTask messages that will be sent for the generation phase.
59 *
60 * @param totalTasks
61 * the maximum number of times startTask will be called for the
62 * generation phase.
63 */
64 void generationStarted(int totalTasks);
65
66 /**
67 * Called to note the start of the file saving phase, and to note the
68 * maximum number of startTask messages that will be sent for the file
69 * saving phase phase.
70 *
71 * @param totalTasks
72 * the maximum number of times startTask will be called for the
73 * file saving phase.
74 */
75 void saveStarted(int totalTasks);
76
77 /**
78 * Called to denote the beginning of a save task
79 *
80 * @param taskName
81 * a descriptive name of the current work step
82 */
83 void startTask(String taskName);
84
85 /**
86 * This method is called when all generated files have been saved
87 */
88 void done();
89
90 /**
91 * The method is called periodically during a long running method.
92 * If the the implementation throws <code>InterruptedException</code> then
93 * the method will be canceled. Any files that have already been saved will
94 * remain on the file system.
95 *
96 * @throws InterruptedException
97 * if the operation should be halted
98 */
99 void checkCancel() throws InterruptedException;
100 }