📄 persistentobject.java
字号:
/*
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations under
* the License.
*
* The Original Code is jRelationalFramework.
*
* The Initial Developer of the Original Code is is.com.
* Portions created by is.com are Copyright (C) 2000 is.com.
* All Rights Reserved.
*
* Contributor(s): Jonathan Carlson (joncrlsn@users.sf.net)
* Contributor(s): ____________________________________
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License (the "GPL") or the GNU Lesser General
* Public license (the "LGPL"), in which case the provisions of the GPL or
* LGPL are applicable instead of those above. If you wish to allow use of
* your version of this file only under the terms of either the GPL or LGPL
* and not to allow others to use your version of this file under the MPL,
* indicate your decision by deleting the provisions above and replace them
* with the notice and other provisions required by either the GPL or LGPL
* License. If you do not delete the provisions above, a recipient may use
* your version of this file under either the MPL or GPL or LGPL License.
*
*/
package com.is.jrf;
import java.io.Serializable;
/**
* This is an abstract superclass for those objects wishing to participate
* in the domain-object SQL framework. When naming a variable for this, the
* shortcut of aPO is often used.
*/
public abstract class PersistentObject
implements Serializable
{
private PersistentState i_persistentState = PersistentState.NEW;
public PersistentState getPersistentState()
{
return i_persistentState;
}
public void setPersistentState(PersistentState state)
{
i_persistentState = state;
}
/**
* When true, this object is not in the database yet. This method name is
* somewhat cumbersome, however it is consistent, makes sense when you
* think about it, and it won't conflict with business methods like
* 'isNew()' or something similar would.
*
* @return a value of type 'boolean'
*/
public boolean hasNewPersistentState()
{
return i_persistentState.isNewPersistentState();
}
/**
* When true, this objects attributes do not match the database values.
* This method name is somewhat cumbersome, however it is consistent,
* makes sense when you think about it, and it won't conflict with
* business methods like 'isModified()' or something similar would.
*
* @return a value of type 'boolean'
*/
public boolean hasModifiedPersistentState()
{
return i_persistentState.isModifiedPersistentState();
}
/**
* When true, this object's attributes match the database values. This
* method name is somewhat cumbersome, however it is consistent, makes
* sense when you think about it, and it won't conflict with business
* methods like 'isCurrent()' or something similar would.
*
* @return a value of type 'boolean'
*/
public boolean hasCurrentPersistentState()
{
return i_persistentState.isCurrentPersistentState();
}
/**
* When true, this object has already been saved to the database once while
* ReturnSavedObject on the domain was set to true. In this case, the
* returned instance should replace the instance that was an argument to
* save() to avoid saving old information to the database (columns can
* change during the insert or update via triggers, optimistic locks,
* timestamps, etc...).
*
* @return a value of type 'boolean'
*/
public boolean hasDeadPersistentState()
{
return i_persistentState.isDeadPersistentState();
}
/* ========== These methods may cause a state change ========== */
public void markNewPersistentState()
{
i_persistentState.markNewPersistentState(this);
}
/** State change will only occur if state is "Current" */
public void markModifiedPersistentState()
{
i_persistentState.markModifiedPersistentState(this);
}
public void markCurrentPersistentState()
{
i_persistentState.markCurrentPersistentState(this);
}
public void markDeadPersistentState()
{
i_persistentState.markDeadPersistentState(this);
}
/* ========== These methods force a state change ========== */
public void forceNewPersistentState()
{
if ( !(i_persistentState instanceof NewPersistentState))
{
i_persistentState = PersistentState.NEW;
}
}
public void forceModifiedPersistentState()
{
if ( !(i_persistentState instanceof ModifiedPersistentState))
{
i_persistentState = PersistentState.MODIFIED;
}
}
public void forceCurrentPersistentState()
{
if ( !(i_persistentState instanceof CurrentPersistentState))
{
i_persistentState = PersistentState.CURRENT;
}
}
public void forceDeadPersistentState()
{
if ( !(i_persistentState instanceof DeadPersistentState))
{
i_persistentState = PersistentState.DEAD;
}
}
} // PersistentObject
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -