001: package org.apache.torque.om;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.sql.Connection;
023:
024: /**
025: * This interface defines methods related to saving an object
026: *
027: * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
028: * @author <a href="mailto:fedor@apache.org">Fedor K.</a>
029: * @version $Id: Persistent.java 473821 2006-11-11 22:37:25Z tv $
030: */
031: public interface Persistent {
032: /**
033: * getter for the object primaryKey.
034: *
035: * @return the object primaryKey as an Object
036: */
037: ObjectKey getPrimaryKey();
038:
039: /**
040: * Sets the PrimaryKey for the object.
041: *
042: * @param primaryKey The new PrimaryKey for the object.
043: * @throws Exception This method might throw an exception
044: */
045: void setPrimaryKey(ObjectKey primaryKey) throws Exception;
046:
047: /**
048: * Sets the PrimaryKey for the object.
049: *
050: * @param primaryKey the String should be of the form produced by
051: * ObjectKey.toString().
052: * @throws Exception This method might throw an exception
053: */
054: void setPrimaryKey(String primaryKey) throws Exception;
055:
056: /**
057: * Returns whether the object has been modified, since it was
058: * last retrieved from storage.
059: *
060: * @return True if the object has been modified.
061: */
062: boolean isModified();
063:
064: /**
065: * Returns whether the object has ever been saved. This will
066: * be false, if the object was retrieved from storage or was created
067: * and then saved.
068: *
069: * @return true, if the object has never been persisted.
070: */
071: boolean isNew();
072:
073: /**
074: * Setter for the isNew attribute. This method will be called
075: * by Torque-generated children and Peers.
076: *
077: * @param b the state of the object.
078: */
079: void setNew(boolean b);
080:
081: /**
082: * Sets the modified state for the object.
083: *
084: * @param m The new modified state for the object.
085: */
086: void setModified(boolean m);
087:
088: /**
089: * Saves the object.
090: *
091: * @throws Exception This method might throw an exception
092: */
093: void save() throws Exception;
094:
095: /**
096: * Stores the object in the database. If the object is new,
097: * it inserts it; otherwise an update is performed.
098: *
099: * @param dbName the name of the database
100: * @throws Exception This method might throw an exception
101: */
102: void save(String dbName) throws Exception;
103:
104: /**
105: * Stores the object in the database. If the object is new,
106: * it inserts it; otherwise an update is performed. This method
107: * is meant to be used as part of a transaction, otherwise use
108: * the save() method and the connection details will be handled
109: * internally
110: *
111: * @param con the Connection used to store the object
112: * @throws Exception This method might throw an exception
113: */
114: void save(Connection con) throws Exception;
115: }
|