1 package org.apache.torque.om; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.sql.Connection; 23 24 import org.apache.torque.TorqueException; 25 26 /** 27 * This interface defines methods related to saving an object 28 * 29 * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a> 30 * @author <a href="mailto:fedor@apache.org">Fedor K.</a> 31 * @version $Id: Persistent.java 1152582 2011-07-31 13:59:17Z tfischer $ 32 */ 33 public interface Persistent 34 { 35 /** 36 * getter for the object primaryKey. 37 * 38 * @return the object primaryKey as an Object 39 */ 40 ObjectKey getPrimaryKey(); 41 42 /** 43 * Sets the PrimaryKey for the object. 44 * 45 * @param primaryKey The new PrimaryKey for the object. 46 * @throws TorqueException This method might throw an exception 47 */ 48 void setPrimaryKey(ObjectKey primaryKey) throws TorqueException; 49 50 /** 51 * Sets the PrimaryKey for the object. 52 * 53 * @param primaryKey the String should be of the form produced by 54 * ObjectKey.toString(). 55 * @throws TorqueException This method might throw an exception 56 */ 57 void setPrimaryKey(String primaryKey) throws TorqueException; 58 59 /** 60 * Returns whether the object has been modified, since it was 61 * last retrieved from storage. 62 * 63 * @return True if the object has been modified. 64 */ 65 boolean isModified(); 66 67 /** 68 * Returns whether the object has ever been saved. This will 69 * be false, if the object was retrieved from storage or was created 70 * and then saved. 71 * 72 * @return true, if the object has never been persisted. 73 */ 74 boolean isNew(); 75 76 /** 77 * Setter for the isNew attribute. This method will be called 78 * by Torque-generated children and Peers. 79 * 80 * @param b the state of the object. 81 */ 82 void setNew(boolean b); 83 84 /** 85 * Sets the modified state for the object. 86 * 87 * @param m The new modified state for the object. 88 */ 89 void setModified(boolean m); 90 91 /** 92 * Saves the object. 93 * 94 * @throws Exception This method might throw an exception 95 */ 96 void save() throws Exception; 97 98 /** 99 * Stores the object in the database. If the object is new, 100 * it inserts it; otherwise an update is performed. 101 * 102 * @param dbName the name of the database 103 * @throws Exception This method might throw an exception 104 */ 105 void save(String dbName) throws Exception; 106 107 /** 108 * Stores the object in the database. If the object is new, 109 * it inserts it; otherwise an update is performed. This method 110 * is meant to be used as part of a transaction, otherwise use 111 * the save() method and the connection details will be handled 112 * internally 113 * 114 * @param con the Connection used to store the object 115 * @throws Exception This method might throw an exception 116 */ 117 void save(Connection con) throws Exception; 118 }