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:
parent
968b6bc3c1
commit
b36b22e7c5
|
@ -165,7 +165,11 @@ public class ModelClassGenerator
|
||||||
.append("/** Generated Model for ").append(tableName).append(Env.NL)
|
.append("/** Generated Model for ").append(tableName).append(Env.NL)
|
||||||
.append(" * @author Adempiere (generated) ").append(Env.NL)
|
.append(" * @author Adempiere (generated) ").append(Env.NL)
|
||||||
.append(" * @version ").append(Adempiere.MAIN_VERSION).append(" - $Id$ */").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)
|
.append("{").append(Env.NL)
|
||||||
|
|
||||||
// serialVersionUID
|
// serialVersionUID
|
||||||
|
@ -922,7 +926,6 @@ public class ModelClassGenerator
|
||||||
ResultSet rs = pstmt.executeQuery();
|
ResultSet rs = pstmt.executeQuery();
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
new ModelInterfaceGenerator(rs.getInt(1), directory, packageName);
|
|
||||||
new ModelClassGenerator(rs.getInt(1), directory, packageName);
|
new ModelClassGenerator(rs.getInt(1), directory, packageName);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
}
|
|
@ -1770,84 +1770,83 @@ public abstract class PO
|
||||||
return true;
|
return true;
|
||||||
} // is_new
|
} // is_new
|
||||||
|
|
||||||
public boolean save() {
|
/*
|
||||||
return PO.save(this);
|
* Classes which override save() method:
|
||||||
}
|
* org.compiere.process.DocActionTemplate
|
||||||
|
* org.compiere.model.MClient
|
||||||
public static boolean save(Object po) {
|
* org.compiere.model.MClientInfo
|
||||||
return save((PO) po);
|
* org.compiere.model.MSystem
|
||||||
|
*/
|
||||||
}
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Update Value or create new record.
|
* Update Value or create new record.
|
||||||
* To reload call load() - not updated
|
* To reload call load() - not updated
|
||||||
* @return true if saved
|
* @return true if saved
|
||||||
*/
|
*/
|
||||||
public static boolean save(PO po)
|
public boolean save()
|
||||||
{
|
{
|
||||||
CLogger.resetLast();
|
CLogger.resetLast();
|
||||||
boolean newRecord = po.is_new(); // save locally as load resets
|
boolean newRecord = is_new(); // save locally as load resets
|
||||||
if (!newRecord && !po.is_Changed())
|
if (!newRecord && !is_Changed())
|
||||||
{
|
{
|
||||||
po.log.fine("Nothing changed - " + po.p_info.getTableName());
|
log.fine("Nothing changed - " + p_info.getTableName());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Organization Check
|
// Organization Check
|
||||||
if (po.getAD_Org_ID() == 0
|
if (getAD_Org_ID() == 0
|
||||||
&& (po.get_AccessLevel() == ACCESSLEVEL_ORG
|
&& (get_AccessLevel() == ACCESSLEVEL_ORG
|
||||||
|| (po.get_AccessLevel() == ACCESSLEVEL_CLIENTORG
|
|| (get_AccessLevel() == ACCESSLEVEL_CLIENTORG
|
||||||
&& MClientShare.isOrgLevelOnly(po.getAD_Client_ID(), po.get_Table_ID()))))
|
&& 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;
|
return false;
|
||||||
}
|
}
|
||||||
// Should be Org 0
|
// Should be Org 0
|
||||||
if (po.getAD_Org_ID() != 0)
|
if (getAD_Org_ID() != 0)
|
||||||
{
|
{
|
||||||
boolean reset = po.get_AccessLevel() == ACCESSLEVEL_SYSTEM;
|
boolean reset = get_AccessLevel() == ACCESSLEVEL_SYSTEM;
|
||||||
if (!reset && MClientShare.isClientLevelOnly(po.getAD_Client_ID(), po.get_Table_ID()))
|
if (!reset && MClientShare.isClientLevelOnly(getAD_Client_ID(), get_Table_ID()))
|
||||||
{
|
{
|
||||||
reset = po.get_AccessLevel() == ACCESSLEVEL_CLIENT
|
reset = get_AccessLevel() == ACCESSLEVEL_CLIENT
|
||||||
|| po.get_AccessLevel() == ACCESSLEVEL_SYSTEMCLIENT
|
|| get_AccessLevel() == ACCESSLEVEL_SYSTEMCLIENT
|
||||||
|| po.get_AccessLevel() == ACCESSLEVEL_CLIENTORG;
|
|| get_AccessLevel() == ACCESSLEVEL_CLIENTORG;
|
||||||
}
|
}
|
||||||
if (reset)
|
if (reset)
|
||||||
{
|
{
|
||||||
po.log.warning("Set Org to 0");
|
log.warning("Set Org to 0");
|
||||||
po.setAD_Org_ID(0);
|
setAD_Org_ID(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Before Save
|
// Before Save
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!po.beforeSave(newRecord))
|
if (!beforeSave(newRecord))
|
||||||
{
|
{
|
||||||
po.log.warning("beforeSave failed - " + po.toString());
|
log.warning("beforeSave failed - " + toString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
po.log.log(Level.WARNING, "beforeSave - " + po.toString(), e);
|
log.log(Level.WARNING, "beforeSave - " + toString(), e);
|
||||||
po.log.saveError("Error", e.toString(), false);
|
log.saveError("Error", e.toString(), false);
|
||||||
// throw new DBException(e);
|
// throw new DBException(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Call ModelValidators TYPE_NEW/TYPE_CHANGE
|
// Call ModelValidators TYPE_NEW/TYPE_CHANGE
|
||||||
String errorMsg = ModelValidationEngine.get().fireModelChange
|
String errorMsg = ModelValidationEngine.get().fireModelChange
|
||||||
(po, newRecord ? ModelValidator.TYPE_NEW : ModelValidator.TYPE_CHANGE);
|
(this, newRecord ? ModelValidator.TYPE_NEW : ModelValidator.TYPE_CHANGE);
|
||||||
if (errorMsg != null)
|
if (errorMsg != null)
|
||||||
{
|
{
|
||||||
po.log.warning("Validation failed - " + errorMsg);
|
log.warning("Validation failed - " + errorMsg);
|
||||||
po.log.saveError("Error", errorMsg);
|
log.saveError("Error", errorMsg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Save
|
// Save
|
||||||
if (newRecord)
|
if (newRecord)
|
||||||
return po.saveNew();
|
return saveNew();
|
||||||
else
|
else
|
||||||
return po.saveUpdate();
|
return saveUpdate();
|
||||||
} // save
|
} // save
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue