Reverted PO.save() now is instance method.

Added I_Persistent interface. Generated model class implementes both I_Xxx and I_Persistent interfaces and extends PO class.
This commit is contained in:
trifonnt 2007-08-21 13:14:56 +00:00
parent 968b6bc3c1
commit b36b22e7c5
3 changed files with 78 additions and 36 deletions

View File

@ -165,7 +165,11 @@ public class ModelClassGenerator
.append("/** Generated Model for ").append(tableName).append(Env.NL)
.append(" * @author Adempiere (generated) ").append(Env.NL)
.append(" * @version ").append(Adempiere.MAIN_VERSION).append(" - $Id$ */").append(Env.NL)
.append("public class ").append(className).append(" extends PO implements I_").append(tableName).append(Env.NL)
.append("public class ").append(className)
.append(" extends PO")
.append(" implements I_").append(tableName)
.append(" implements I_Persistent ")
.append(Env.NL)
.append("{").append(Env.NL)
// serialVersionUID
@ -922,7 +926,6 @@ public class ModelClassGenerator
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
new ModelInterfaceGenerator(rs.getInt(1), directory, packageName);
new ModelClassGenerator(rs.getInt(1), directory, packageName);
count++;
}

View File

@ -0,0 +1,40 @@
/**********************************************************************
* This file is part of Adempiere ERP Bazaar *
* http://www.adempiere.org *
* *
* Copyright (C) Trifon Trifonov. *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - Trifon Trifonov (trifonnt@users.sourceforge.net) *
* *
* Sponsors: *
* - D3 Soft Ltd. (http://www.d3-soft.com) *
***********************************************************************/
package org.compiere.model;
/**
* @author Trifon Trifonov
* @version $Id$
*/
public interface I_Persistent {
public boolean save();
}

View File

@ -1770,84 +1770,83 @@ public abstract class PO
return true;
} // is_new
public boolean save() {
return PO.save(this);
}
public static boolean save(Object po) {
return save((PO) po);
}
/*
* Classes which override save() method:
* org.compiere.process.DocActionTemplate
* org.compiere.model.MClient
* org.compiere.model.MClientInfo
* org.compiere.model.MSystem
*/
/**************************************************************************
* Update Value or create new record.
* To reload call load() - not updated
* @return true if saved
*/
public static boolean save(PO po)
public boolean save()
{
CLogger.resetLast();
boolean newRecord = po.is_new(); // save locally as load resets
if (!newRecord && !po.is_Changed())
boolean newRecord = is_new(); // save locally as load resets
if (!newRecord && !is_Changed())
{
po.log.fine("Nothing changed - " + po.p_info.getTableName());
log.fine("Nothing changed - " + p_info.getTableName());
return true;
}
// Organization Check
if (po.getAD_Org_ID() == 0
&& (po.get_AccessLevel() == ACCESSLEVEL_ORG
|| (po.get_AccessLevel() == ACCESSLEVEL_CLIENTORG
&& MClientShare.isOrgLevelOnly(po.getAD_Client_ID(), po.get_Table_ID()))))
if (getAD_Org_ID() == 0
&& (get_AccessLevel() == ACCESSLEVEL_ORG
|| (get_AccessLevel() == ACCESSLEVEL_CLIENTORG
&& MClientShare.isOrgLevelOnly(getAD_Client_ID(), get_Table_ID()))))
{
po.log.saveError("FillMandatory", Msg.getElement(po.getCtx(), "AD_Org_ID"));
log.saveError("FillMandatory", Msg.getElement(getCtx(), "AD_Org_ID"));
return false;
}
// Should be Org 0
if (po.getAD_Org_ID() != 0)
if (getAD_Org_ID() != 0)
{
boolean reset = po.get_AccessLevel() == ACCESSLEVEL_SYSTEM;
if (!reset && MClientShare.isClientLevelOnly(po.getAD_Client_ID(), po.get_Table_ID()))
boolean reset = get_AccessLevel() == ACCESSLEVEL_SYSTEM;
if (!reset && MClientShare.isClientLevelOnly(getAD_Client_ID(), get_Table_ID()))
{
reset = po.get_AccessLevel() == ACCESSLEVEL_CLIENT
|| po.get_AccessLevel() == ACCESSLEVEL_SYSTEMCLIENT
|| po.get_AccessLevel() == ACCESSLEVEL_CLIENTORG;
reset = get_AccessLevel() == ACCESSLEVEL_CLIENT
|| get_AccessLevel() == ACCESSLEVEL_SYSTEMCLIENT
|| get_AccessLevel() == ACCESSLEVEL_CLIENTORG;
}
if (reset)
{
po.log.warning("Set Org to 0");
po.setAD_Org_ID(0);
log.warning("Set Org to 0");
setAD_Org_ID(0);
}
}
// Before Save
try
{
if (!po.beforeSave(newRecord))
if (!beforeSave(newRecord))
{
po.log.warning("beforeSave failed - " + po.toString());
log.warning("beforeSave failed - " + toString());
return false;
}
}
catch (Exception e)
{
po.log.log(Level.WARNING, "beforeSave - " + po.toString(), e);
po.log.saveError("Error", e.toString(), false);
log.log(Level.WARNING, "beforeSave - " + toString(), e);
log.saveError("Error", e.toString(), false);
// throw new DBException(e);
return false;
}
// Call ModelValidators TYPE_NEW/TYPE_CHANGE
String errorMsg = ModelValidationEngine.get().fireModelChange
(po, newRecord ? ModelValidator.TYPE_NEW : ModelValidator.TYPE_CHANGE);
(this, newRecord ? ModelValidator.TYPE_NEW : ModelValidator.TYPE_CHANGE);
if (errorMsg != null)
{
po.log.warning("Validation failed - " + errorMsg);
po.log.saveError("Error", errorMsg);
log.warning("Validation failed - " + errorMsg);
log.saveError("Error", errorMsg);
return false;
}
// Save
if (newRecord)
return po.saveNew();
return saveNew();
else
return po.saveUpdate();
return saveUpdate();
} // save
/**