001 package org.apache.ojb.broker.ant;
002
003 /* Copyright 1999-2005 The Apache Software Foundation.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 import org.apache.ddlutils.Platform;
019 import org.apache.ddlutils.model.Database;
020 import org.apache.ojb.broker.metadata.DescriptorRepository;
021 import org.apache.tools.ant.BuildException;
022 import org.apache.tools.ant.Task;
023
024 /**
025 * Base class for commands that work with a database and repository model.
026 *
027 * @author Thomas Dudziak
028 * @version $Revision: 1.1 $
029 */
030 public abstract class Command
031 {
032 /** The platform. */
033 private Platform _platform;
034 /** Whether to stop execution upon an error. */
035 private boolean _failOnError = true;
036
037 /**
038 * Returns the database type.
039 *
040 * @return The database type
041 */
042 protected String getDatabaseType()
043 {
044 return _platform.getName();
045 }
046
047 /**
048 * Sets the platform.
049 *
050 * @param platform The platform
051 */
052 protected void setPlatform(Platform platform)
053 {
054 _platform = platform;
055 }
056
057 /**
058 * Determines whether the command execution will be stopped upon an error.
059 * Default value is <code>true</code>.
060 *
061 * @return <code>true</code> if the execution stops in case of an error
062 */
063 public boolean isFailOnError()
064 {
065 return _failOnError;
066 }
067
068 /**
069 * Specifies whether the command execution will be stopped upon an error.
070 *
071 * @param failOnError <code>true</code> if the execution stops in case of an error
072 */
073 public void setFailOnError(boolean failOnError)
074 {
075 _failOnError = failOnError;
076 }
077
078 /**
079 * Creates the platform for the configured database.
080 *
081 * @return The platform
082 */
083 protected Platform getPlatform() throws BuildException
084 {
085 return _platform;
086 }
087
088 /**
089 * Executes this command.
090 *
091 * @param task The executing task
092 * @param dbModel The database model
093 * @param objModel The object model
094 */
095 public abstract void execute(Task task, Database dbModel, DescriptorRepository objModel) throws BuildException;
096 }