01: package org.apache.ojb.broker.ant;
02:
03: /* Copyright 1999-2005 The Apache Software Foundation.
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import org.apache.ddlutils.Platform;
19: import org.apache.ddlutils.model.Database;
20: import org.apache.ojb.broker.metadata.DescriptorRepository;
21: import org.apache.tools.ant.BuildException;
22: import org.apache.tools.ant.Task;
23:
24: /**
25: * Base class for commands that work with a database and repository model.
26: *
27: * @author Thomas Dudziak
28: * @version $Revision: 1.1.2.2 $
29: */
30: public abstract class Command {
31: /** The platform. */
32: private Platform _platform;
33: /** Whether to stop execution upon an error. */
34: private boolean _failOnError = true;
35:
36: /**
37: * Returns the database type.
38: *
39: * @return The database type
40: */
41: protected String getDatabaseType() {
42: return _platform.getName();
43: }
44:
45: /**
46: * Sets the platform.
47: *
48: * @param platform The platform
49: */
50: protected void setPlatform(Platform platform) {
51: _platform = platform;
52: }
53:
54: /**
55: * Determines whether the command execution will be stopped upon an error.
56: * Default value is <code>true</code>.
57: *
58: * @return <code>true</code> if the execution stops in case of an error
59: */
60: public boolean isFailOnError() {
61: return _failOnError;
62: }
63:
64: /**
65: * Specifies whether the command execution will be stopped upon an error.
66: *
67: * @param failOnError <code>true</code> if the execution stops in case of an error
68: */
69: public void setFailOnError(boolean failOnError) {
70: _failOnError = failOnError;
71: }
72:
73: /**
74: * Creates the platform for the configured database.
75: *
76: * @return The platform
77: */
78: protected Platform getPlatform() throws BuildException {
79: return _platform;
80: }
81:
82: /**
83: * Executes this command.
84: *
85: * @param task The executing task
86: * @param dbModel The database model
87: * @param objModel The object model
88: */
89: public abstract void execute(Task task, Database dbModel,
90: DescriptorRepository objModel) throws BuildException;
91: }
|