use of org.compiere.model.MTable in project adempiere by adempiere.
the class CreateAdempiere method copy.
// dropDatabase
/**
* Create Tables and copy data
* @param whereClause optional where clause
* @param dropFirst drop first
* @return true if executed
*/
public boolean copy(String whereClause, boolean dropFirst) {
log.info(whereClause);
if (getConnection(false, true) == null)
return false;
//
boolean success = true;
int count = 0;
ArrayList<String> list = new ArrayList<String>();
String sql = "SELECT * FROM AD_Table";
if (whereClause != null && whereClause.length() > 0)
sql += " WHERE " + whereClause;
sql += " ORDER BY TableName";
//
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
//jz: pstmt.getConnection() could be null
Connection conn = pstmt.getConnection();
DatabaseMetaData md = null;
if (conn != null)
md = conn.getMetaData();
else {
//jz: globalization issue??
throw new DBException("No Connection");
}
rs = pstmt.executeQuery();
while (rs.next() && success) {
MTable table = new MTable(m_ctx, rs, null);
if (table.isView())
continue;
if (dropFirst) {
executeCommands(new String[] { "DROP TABLE " + table.getTableName() }, m_conn, false, false);
}
//
if (createTable(table, md)) {
list.add(table.getTableName());
count++;
} else
success = false;
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
success = false;
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
if (!success)
return false;
/** Enable Contraints */
enableConstraints(list);
databaseBuild();
log.info("#" + count);
try {
if (m_conn != null)
m_conn.close();
} catch (SQLException e2) {
log.log(Level.SEVERE, "close connection", e2);
}
m_conn = null;
return success;
}
use of org.compiere.model.MTable in project adempiere by adempiere.
the class WFieldRecordInfo method dynInit.
// init
/**
* Dynamic Init
* @param title title
* @return true if table initialized
*/
private boolean dynInit(String title) {
// Title
if (AD_Table_ID != 0) {
MTable table1 = MTable.get(Env.getCtx(), AD_Table_ID);
setTitle(title + " - " + table1.getName());
}
// Only Client Preference can view Change Log
if (!MRole.PREFERENCETYPE_Client.equals(MRole.getDefault().getPreferenceType()))
return false;
if (Record_ID == 0)
return false;
// Data
String sql = "SELECT AD_Column_ID, Updated, UpdatedBy, OldValue, NewValue " + "FROM AD_ChangeLog " + "WHERE AD_Table_ID=? AND Record_ID=? AND AD_Column_ID=?" + "ORDER BY Updated DESC";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Table_ID);
pstmt.setInt(2, Record_ID);
pstmt.setInt(3, AD_Column_ID);
rs = pstmt.executeQuery();
while (rs.next()) {
addLine(rs.getInt(1), rs.getTimestamp(2), rs.getInt(3), rs.getString(4), rs.getString(5));
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
}
//
Vector<String> columnNames = new Vector<String>();
columnNames.add(Msg.translate(Env.getCtx(), "NewValue"));
columnNames.add(Msg.translate(Env.getCtx(), "OldValue"));
columnNames.add(Msg.translate(Env.getCtx(), "UpdatedBy"));
columnNames.add(Msg.translate(Env.getCtx(), "Updated"));
Listhead listhead = new Listhead();
listhead.setSizable(true);
for (int i = 0; i < columnNames.size(); i++) {
Listheader listheader = new Listheader(columnNames.get(i).replaceAll("[&]", ""));
listhead.appendChild(listheader);
}
table.appendChild(listhead);
List<Object> list = new ArrayList<Object>();
for (Vector<String> data : m_data) {
list.add(data.toString());
}
SimpleListModel model = new SimpleListModel(list);
table.setItemRenderer(model);
table.setModel(model);
return true;
}
use of org.compiere.model.MTable in project adempiere by adempiere.
the class WDocActionPanel method dynInit.
/**
* Dynamic Init - determine valid DocActions based on DocStatus for the different documents.
*/
private void dynInit() {
//
Object Processing = gridTab.getValue("Processing");
String OrderType = Env.getContext(Env.getCtx(), gridTab.getWindowNo(), "OrderType");
String IsSOTrx = Env.getContext(Env.getCtx(), gridTab.getWindowNo(), "IsSOTrx");
if (DocStatus == null) {
//message.setText("*** ERROR ***");
return;
}
logger.fine("DocStatus=" + DocStatus + ", DocAction=" + DocAction + ", OrderType=" + OrderType + ", IsSOTrx=" + IsSOTrx + ", Processing=" + Processing + ", AD_Table_ID=" + gridTab.getAD_Table_ID() + ", Record_ID=" + gridTab.getRecord_ID());
int index = 0;
if (lstDocAction.getSelectedItem() != null) {
String selected = (lstDocAction.getSelectedItem().getValue()).toString();
for (int i = 0; i < s_value.length && index == 0; i++) {
if (s_value[i].equals(selected)) {
index = i;
}
}
}
String[] options = new String[s_value.length];
/**
* Check Existence of Workflow Acrivities
*/
String wfStatus = MWFActivity.getActiveInfo(Env.getCtx(), m_AD_Table_ID, gridTab.getRecord_ID());
if (wfStatus != null) {
FDialog.error(gridTab.getWindowNo(), this, "WFActiveForRecord", wfStatus);
return;
}
// Status Change
if (!checkStatus(gridTab.getTableName(), gridTab.getRecord_ID(), DocStatus)) {
FDialog.error(gridTab.getWindowNo(), this, "DocumentStatusChanged");
return;
}
/*******************
* General Actions
*/
String[] docActionHolder = new String[] { DocAction };
index = DocumentEngine.getValidActions(DocStatus, Processing, OrderType, IsSOTrx, m_AD_Table_ID, docActionHolder, options);
MTable table = MTable.get(Env.getCtx(), m_AD_Table_ID);
PO po = table.getPO(gridTab.getRecord_ID(), null);
if (po instanceof DocOptions)
index = ((DocOptions) po).customizeValidActions(DocStatus, Processing, OrderType, IsSOTrx, m_AD_Table_ID, docActionHolder, options, index);
Integer doctypeId = (Integer) gridTab.getValue("C_DocType_ID");
if (doctypeId == null || doctypeId.intValue() == 0) {
doctypeId = (Integer) gridTab.getValue("C_DocTypeTarget_ID");
}
logger.fine("get doctype: " + doctypeId);
if (doctypeId != null) {
index = DocumentEngine.checkActionAccess(Env.getAD_Client_ID(Env.getCtx()), Env.getAD_Role_ID(Env.getCtx()), doctypeId, options, index);
}
DocAction = docActionHolder[0];
/**
* Fill actionCombo
*/
boolean firstadded = true;
for (int i = 0; i < index; i++) {
// Serach for option and add it
boolean added = false;
for (int j = 0; j < s_value.length && !added; j++) {
if (options[i].equals(s_value[j])) {
Listitem newitem = lstDocAction.appendItem(s_name[j], s_value[j]);
if (firstadded) {
// select by default the first added item - can be changed below
lstDocAction.setSelectedItem(newitem);
firstadded = false;
}
added = true;
}
}
}
// look if the current DocAction is within the list and assign it as selected if it exists
List<Listitem> lst = (List<Listitem>) lstDocAction.getItems();
for (Listitem item : lst) {
String value = item.getValue().toString();
if (DocAction.equals(value)) {
lstDocAction.setSelectedItem(item);
label.setValue(s_description[getSelectedIndex()]);
}
}
// setDefault
if (// If None, suggest closing
DocAction.equals("--"))
DocAction = DocumentEngine.ACTION_Close;
}
use of org.compiere.model.MTable in project adempiere by adempiere.
the class ReferenceTableElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
String elementValue = element.getElementValue();
log.info(elementValue);
Attributes atts = element.attributes;
String entitytype = atts.getValue("EntityType");
String name = atts.getValue("ADRefenceNameID");
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.skip) {
element.skip = true;
return;
}
int AD_Reference_ID = 0;
if (element.parent != null && element.parent.getElementValue().equals("reference") && element.parent.recordId > 0) {
AD_Reference_ID = element.parent.recordId;
} else {
StringBuffer sqlB = new StringBuffer("SELECT AD_Reference_ID FROM AD_Reference WHERE Name= ?");
AD_Reference_ID = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), name);
}
if (AD_Reference_ID <= 0 && atts.getValue("AD_Reference_ID") != null && Integer.parseInt(atts.getValue("AD_Reference_ID")) <= PackOut.MAX_OFFICIAL_ID)
AD_Reference_ID = Integer.parseInt(atts.getValue("AD_Reference_ID"));
int tableId = get_IDWithColumn(ctx, "AD_Table", "TableName", atts.getValue("ADTableNameID"));
if (tableId == 0) {
MTable m_Table = new MTable(ctx, 0, getTrxName(ctx));
m_Table.setAccessLevel("3");
m_Table.setName(atts.getValue("ADTableNameID"));
m_Table.setTableName(atts.getValue("ADTableNameID"));
if (m_Table.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Table.getName(), "Table", m_Table.get_ID(), 0, "New", "AD_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Table"));
} else {
record_log(ctx, 0, m_Table.getName(), "Table", m_Table.get_ID(), 0, "New", "AD_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Table"));
}
tableId = get_IDWithColumn(ctx, "AD_Table", "TableName", atts.getValue("ADTableNameID"));
}
name = atts.getValue("Key");
int keyId = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", name, "AD_Table", tableId);
if (keyId == 0)
throw new AdempiereException("@AD_Column_ID@:" + name + "@NotFound@");
int displayId = 0;
name = atts.getValue("ADDisplay");
displayId = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", name, "AD_Table", tableId);
String isDisplayIdentifier = atts.getValue("IsDisplayIdentifier");
String isAlert = atts.getValue("IsAlert");
String entityType = atts.getValue("EntityType");
String isValueDisplayed = atts.getValue("IsValueDisplayed");
String OrderByClause = "";
String WhereClause = "";
String displaySQL = "";
if (DB.isOracle()) {
OrderByClause = atts.getValue("OrderByClause");
WhereClause = atts.getValue("WhereClause");
displaySQL = atts.getValue("DisplaySQL");
} else if (DB.isPostgreSQL()) {
OrderByClause = atts.getValue("OrderByClause").replaceAll("''", "'");
WhereClause = atts.getValue("WhereClause").replaceAll("''", "'");
displaySQL = atts.getValue("DisplaySQL").replaceAll("''", "'");
;
}
MRefTable refTable = new Query(ctx, I_AD_Ref_Table.Table_Name, COLUMNNAME_AD_Reference_ID + "=?", getTrxName(ctx)).setParameters(AD_Reference_ID).firstOnly();
if (refTable != null) {
refTable.setAD_Table_ID(tableId);
refTable.setAD_Display(displayId);
refTable.setAD_Key(keyId);
refTable.setIsValueDisplayed(isValueDisplayed.equals("Y"));
refTable.setIsDisplayIdentifier(isDisplayIdentifier.equals("Y"));
refTable.setIsAlert(isAlert.equals("Y"));
refTable.setDisplaySQL(displaySQL);
refTable.setOrderByClause(OrderByClause);
refTable.setEntityType(entityType);
refTable.setWhereClause(WhereClause);
refTable.saveEx();
if (refTable != null) {
record_log(ctx, 1, atts.getValue("ADRefenceNameID"), "Reference Table", AD_Reference_ID, 0, "Update", "AD_Ref_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Ref_Table"));
} else {
record_log(ctx, 0, atts.getValue("ADRefenceNameID"), "Reference Table", AD_Reference_ID, 0, "Update", "AD_Ref_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Ref_Table"));
throw new POSaveFailedException("ReferenceTable");
}
} else {
refTable = new MRefTable(ctx, 0, getTrxName(ctx));
refTable.setAD_Reference_ID(AD_Reference_ID);
refTable.setAD_Table_ID(tableId);
refTable.setAD_Display(displayId);
refTable.setAD_Key(keyId);
refTable.setIsValueDisplayed(isValueDisplayed.equals("Y"));
refTable.setIsDisplayIdentifier(isDisplayIdentifier.equals("Y"));
refTable.setIsAlert(isAlert.equals("Y"));
refTable.setDisplaySQL(displaySQL);
refTable.setOrderByClause(OrderByClause);
refTable.setEntityType(entityType);
refTable.setWhereClause(WhereClause);
if (refTable.save())
record_log(ctx, 1, atts.getValue("ADRefenceNameID"), "Reference Table", AD_Reference_ID, 0, "New", "AD_Ref_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Ref_Table"));
else {
record_log(ctx, 0, atts.getValue("ADRefenceNameID"), "Reference Table", AD_Reference_ID, 0, "New", "AD_Ref_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Ref_Table"));
throw new POSaveFailedException("ReferenceTable");
}
}
} else {
element.skip = true;
}
}
use of org.compiere.model.MTable in project adempiere by adempiere.
the class TableElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
final PackIn packIn = (PackIn) ctx.get("PackInProcess");
final String elementValue = element.getElementValue();
final Attributes atts = element.attributes;
log.info(elementValue + " " + atts.getValue("ADTableNameID"));
final String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
final String tableName = atts.getValue("ADTableNameID");
int id = packIn.getTableId(tableName);
if (id <= 0) {
id = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
if (id > 0)
packIn.addTable(tableName, id);
}
if (id > 0 && isTableProcess(ctx, id) && element.pass == 1) {
return;
}
MTable m_Table = new MTable(ctx, id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_Table_ID") != null && Integer.parseInt(atts.getValue("AD_Table_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Table.setAD_Table_ID(Integer.parseInt(atts.getValue("AD_Table_ID")));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Table", m_Table);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_Table.setTableName(tableName);
//
// Window
final String windowName = atts.getValue("ADWindowNameID");
if (!Util.isEmpty(windowName, true)) {
id = get_IDWithColumn(ctx, "AD_Window", "Name", windowName);
if (id > 0) {
m_Table.setAD_Window_ID(id);
} else if (!element.defer) {
element.defer = true;
element.unresolved = "Window:" + windowName;
} else {
log.warning("@NotFound@ @AD_Window_ID@:" + windowName);
}
}
//
// PO Window
final String poWindowName = getStringValue(atts, "POWindowNameID");
if (!Util.isEmpty(poWindowName, true)) {
id = get_IDWithColumn(ctx, "AD_Window", "Name", poWindowName);
if (id > 0) {
m_Table.setPO_Window_ID(id);
} else if (!element.defer) {
element.defer = true;
element.unresolved = "POWindow:" + poWindowName;
} else {
log.warning("@NotFound@ @PO_Window_ID@:" + poWindowName);
}
}
//
// Validation Rule
final String valRuleName = getStringValue(atts, "ADValRuleNameID");
if (!Util.isEmpty(valRuleName, true)) {
id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", valRuleName);
if (id > 0) {
m_Table.setAD_Val_Rule_ID(id);
} else {
element.defer = true;
element.unresolved = "ValRule:" + valRuleName;
}
}
//
m_Table.setAccessLevel(atts.getValue("AccessLevel"));
m_Table.setDescription(getStringValue(atts, "Description"));
m_Table.setEntityType(atts.getValue("EntityType"));
m_Table.setHelp(getStringValue(atts, "Help"));
m_Table.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
m_Table.setImportTable(getStringValue(atts, "ImportTable"));
m_Table.setIsChangeLog(Boolean.valueOf(atts.getValue("isChangeLog")).booleanValue());
m_Table.setIsDeleteable(Boolean.valueOf(atts.getValue("isDeleteable")).booleanValue());
m_Table.setIsHighVolume(Boolean.valueOf(atts.getValue("isHighVolume")).booleanValue());
m_Table.setIsSecurityEnabled(Boolean.valueOf(atts.getValue("isSecurityEnabled")).booleanValue());
m_Table.setIsView(Boolean.valueOf(atts.getValue("isView")).booleanValue());
//m_Table.setLoadSeq(Integer.parseInt(atts.getValue("LoadSeq")));
m_Table.setName(atts.getValue("Name"));
m_Table.setReplicationType(getStringValue(atts, "ReplicationType"));
m_Table.setTableName(atts.getValue("TableName"));
if (m_Table.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Table.getName(), "Table", m_Table.get_ID(), AD_Backup_ID, Object_Status, "AD_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Table"));
tables.add(m_Table.getAD_Table_ID());
packIn.addTable(tableName, m_Table.getAD_Table_ID());
element.recordId = m_Table.getAD_Table_ID();
} else {
record_log(ctx, 0, m_Table.getName(), "Table", m_Table.get_ID(), AD_Backup_ID, Object_Status, "AD_Table", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Table"));
throw new POSaveFailedException("Table");
}
} else {
element.skip = true;
}
}
Aggregations