use of org.adempiere.pipo.PackIn in project adempiere by adempiere.
the class FieldElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
final String include_tabname = element.attributes.getValue("ADIncludeTabNameID");
// Set Included Tab ID if this task was previously postponed
if (element.defer && element.recordId > 0 && include_tabname != null) {
MField field = new MField(ctx, element.recordId, getTrxName(ctx));
setIncluded_Tab_ID(ctx, field, include_tabname);
field.saveEx();
return;
}
PackIn packIn = (PackIn) ctx.get("PackInProcess");
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
log.info(elementValue + " " + atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.getElementValue().equals("tab") && element.parent.defer) {
element.defer = true;
return;
}
String name = atts.getValue("Name");
String tabname = atts.getValue("ADTabNameID");
String colname = atts.getValue("ADColumnNameID");
String tableName = atts.getValue("ADTableNameID");
int tableid = packIn.getTableId(tableName);
if (tableid <= 0) {
tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
if (tableid > 0)
packIn.addTable(tableName, tableid);
}
if (tableid <= 0) {
element.defer = true;
return;
}
int windowid = get_ID(ctx, "AD_Window", atts.getValue("ADWindowNameID"));
if (windowid <= 0) {
element.defer = true;
return;
}
int columnid = packIn.getColumnId(tableName, colname);
if (columnid <= 0) {
columnid = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", colname, "AD_Table", tableid);
if (columnid > 0)
packIn.addColumn(tableName, colname, columnid);
}
if (columnid <= 0) {
element.defer = true;
return;
}
int tabid = 0;
if (element.parent != null && element.parent.getElementValue().equals("tab") && element.parent.recordId > 0) {
tabid = element.parent.recordId;
} else {
StringBuffer sqlB = new StringBuffer("select AD_Tab_ID from AD_Tab where AD_Window_ID = " + windowid).append(" and Name = '" + tabname + "'").append(" and AD_Table_ID = ?");
tabid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), tableid);
if (element.parent != null && element.parent.getElementValue().equals("tab") && tabid > 0) {
element.parent.recordId = tabid;
}
}
if (tabid > 0) {
StringBuffer sqlB = new StringBuffer("select AD_Field_ID from AD_Field where AD_Column_ID = ").append(columnid).append(" and AD_Tab_ID = ?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), tabid);
final MField m_Field = new MField(ctx, id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_Field_ID") != null && Integer.parseInt(atts.getValue("AD_Field_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Field.setAD_Field_ID(Integer.parseInt(atts.getValue("AD_Field_ID")));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Field", m_Field);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_Field.setName(atts.getValue("Name"));
m_Field.setAD_Column_ID(columnid);
name = atts.getValue("ADFieldGroupNameID");
id = get_IDWithColumn(ctx, "AD_FieldGroup", "Name", name);
m_Field.setAD_FieldGroup_ID(id);
m_Field.setAD_Tab_ID(tabid);
m_Field.setEntityType(atts.getValue("EntityType"));
m_Field.setIsSameLine(Boolean.valueOf(atts.getValue("SameLine")).booleanValue());
m_Field.setIsCentrallyMaintained(Boolean.valueOf(atts.getValue("isCentrallyMaintained")).booleanValue());
m_Field.setIsDisplayed(Boolean.valueOf(atts.getValue("Displayed")).booleanValue());
// m_Field.setIsEncrypted(Boolean.valueOf(atts.getValue("isEncrypted")).booleanValue());
m_Field.setIsFieldOnly(Boolean.valueOf(atts.getValue("isFieldOnly")).booleanValue());
m_Field.setIsHeading(Boolean.valueOf(atts.getValue("isHeading")).booleanValue());
m_Field.setIsReadOnly(Boolean.valueOf(atts.getValue("isReadOnly")).booleanValue());
m_Field.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
m_Field.setDisplayLength(Integer.parseInt(atts.getValue("DisplayLength")));
m_Field.setDescription(getStringValue(atts, "Description"));
m_Field.setHelp(getStringValue(atts, "Help"));
m_Field.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
String sortNo = getStringValue(atts, "SortNo");
if (sortNo != null)
m_Field.setSortNo(new BigDecimal(sortNo));
m_Field.setDisplayLogic(getStringValue(atts, "DisplayLogic"));
String Name = atts.getValue("ADReferenceNameID");
id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
m_Field.setAD_Reference_ID(id);
Name = atts.getValue("ADValRuleNameID");
id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name);
m_Field.setAD_Val_Rule_ID(id);
Name = atts.getValue("ADReferenceNameValueID");
id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
m_Field.setAD_Reference_Value_ID(id);
m_Field.setInfoFactoryClass(getStringValue(atts, "InfoFactoryClass"));
if ("Y".equals(atts.getValue("isMandatory")))
m_Field.setIsMandatory(atts.getValue("isMandatory"));
else if ("N".equals(atts.getValue("isMandatory")))
m_Field.setIsMandatory(atts.getValue("isMandatory"));
m_Field.setDefaultValue(atts.getValue("DefaultValue"));
if (atts.getValue("IsDisplayedGrid") != null)
m_Field.setIsDisplayedGrid(Boolean.valueOf(atts.getValue("IsDisplayedGrid")).booleanValue());
if (atts.getValue("PreferredWidth") != null)
m_Field.setPreferredWidth(Integer.parseInt(atts.getValue("PreferredWidth")));
setIncluded_Tab_ID(ctx, m_Field, include_tabname);
if (m_Field.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Field.getName(), "Field", m_Field.get_ID(), AD_Backup_ID, Object_Status, "AD_Field", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Field"));
element.recordId = m_Field.getAD_Field_ID();
} else {
record_log(ctx, 0, m_Field.getName(), "Field", m_Field.get_ID(), AD_Backup_ID, Object_Status, "AD_Field", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Field"));
throw new POSaveFailedException("Failed to save field definition.");
}
// If Included Tab not found, then postpone this task for later processing
if (m_Field.getAD_Field_ID() > 0 && include_tabname != null && m_Field.getIncluded_Tab_ID() <= 0) {
element.defer = true;
}
} else {
element.defer = true;
return;
}
} else {
element.skip = true;
}
}
use of org.adempiere.pipo.PackIn in project adempiere by adempiere.
the class ViewColumnElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
PackIn packIn = (PackIn) ctx.get("PackInProcess");
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
log.info(elementValue + " " + atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.getElementValue().equals("viewdefinition") && element.parent.defer) {
element.defer = true;
return;
}
String name = atts.getValue("Name");
String viewdenitionname = atts.getValue("ADViewDefinitionNameID");
String colname = atts.getValue("ADColumnNameID");
String viewColumnName = atts.getValue("ADViewColumnNameID");
String tableName = atts.getValue("ADTableNameID");
int tableid = packIn.getTableId(tableName);
if (tableid <= 0) {
tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
if (tableid > 0)
packIn.addTable(tableName, tableid);
}
if (tableid <= 0 && tableName.length() > 0) {
element.defer = true;
return;
}
int viewid = get_ID(ctx, "AD_View", atts.getValue("ADViewNameID"));
if (viewid <= 0) {
element.defer = true;
return;
}
int columnid = packIn.getColumnId(tableName, colname);
if (columnid <= 0) {
columnid = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", colname, "AD_Table", tableid);
if (columnid > 0)
packIn.addColumn(tableName, colname, columnid);
}
if (columnid <= 0 && colname.length() > 0) {
element.defer = true;
return;
}
int viewdefinitionid = 0;
if (element.parent != null && element.parent.getElementValue().equals("viewdefinition") && element.parent.recordId > 0) {
viewdefinitionid = element.parent.recordId;
} else {
StringBuffer sqlB = new StringBuffer("select AD_View_Definition_ID from AD_View_Definition where AD_View_ID = " + viewid).append(" and TableAlias = '" + viewdenitionname + "'").append(" and AD_Table_ID = ?");
viewdefinitionid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), tableid);
if (element.parent != null && element.parent.getElementValue().equals("viewdefinition") && viewdefinitionid > 0) {
element.parent.recordId = viewdefinitionid;
}
}
if (viewdefinitionid > 0) {
StringBuilder sqlB = new StringBuilder("SELECT AD_View_Column_ID from AD_View_Column WHERE ColumnName=?").append(" AND AD_View_Definition_ID=?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), viewColumnName, viewdefinitionid);
final MViewColumn m_ColumnView = new MViewColumn(ctx, id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_View_Column_ID") != null && Integer.parseInt(atts.getValue("AD_View_Column_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_ColumnView.setAD_View_Column_ID(Integer.parseInt(atts.getValue("AD_View_Column_ID")));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_View_Column_ID", m_ColumnView);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_ColumnView.setName(atts.getValue("Name"));
m_ColumnView.setAD_View_ID(viewid);
if (columnid > 0)
m_ColumnView.setAD_Column_ID(columnid);
m_ColumnView.setAD_View_Definition_ID(viewdefinitionid);
m_ColumnView.setEntityType(atts.getValue("EntityType"));
m_ColumnView.setColumnSQL(atts.getValue("ColumnSQL"));
m_ColumnView.setColumnName(viewColumnName);
// m_ColumnView.setIsReadOnly(Boolean.valueOf(
// atts.getValue("isReadOnly")).booleanValue());
m_ColumnView.setDescription(getStringValue(atts, "Description"));
m_ColumnView.setHelp(getStringValue(atts, "Help"));
m_ColumnView.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
if (m_ColumnView.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_ColumnView.getName(), "ViewColumn", m_ColumnView.get_ID(), AD_Backup_ID, Object_Status, "ViewColumn", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_View_Column"));
element.recordId = m_ColumnView.getAD_View_Column_ID();
} else {
record_log(ctx, 0, m_ColumnView.getName(), "ViewColumn", m_ColumnView.get_ID(), AD_Backup_ID, Object_Status, "AD_View_Column", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_View_Column"));
throw new POSaveFailedException("Failed to save view column definition.");
}
}
} else {
element.skip = true;
}
}
use of org.adempiere.pipo.PackIn 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;
}
}
use of org.adempiere.pipo.PackIn in project adempiere by adempiere.
the class ColumnElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
PackIn packIn = (PackIn) ctx.get("PackInProcess");
String elementValue = element.getElementValue();
Attributes atts = element.attributes;
log.info(elementValue + " " + atts.getValue("ColumnName"));
int success = 0;
String entitytype = atts.getValue("EntityType");
if (isProcessElement(ctx, entitytype)) {
if (element.parent != null && element.parent.getElementValue().equals("table") && element.parent.defer) {
element.defer = true;
return;
}
String columnName = atts.getValue("ColumnName");
String tableName = atts.getValue("ADTableNameID");
int tableid = 0;
if (element.parent != null && element.parent.getElementValue().equals("table") && element.parent.recordId > 0) {
tableid = element.parent.recordId;
} else {
tableid = packIn.getTableId(tableName);
}
if (tableid <= 0) {
tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
if (tableid > 0)
packIn.addTable(tableName, tableid);
}
int id = packIn.getColumnId(tableName, columnName);
if (id <= 0) {
id = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableid);
if (id > 0) {
packIn.addColumn(tableName, columnName, id);
}
}
MColumn m_Column = new MColumn(ctx, id, getTrxName(ctx));
if (id <= 0 && atts.getValue("AD_Column_ID") != null && Integer.parseInt(atts.getValue("AD_Column_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Column.setAD_Column_ID(Integer.parseInt(atts.getValue("AD_Column_ID")));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Column", m_Column);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
m_Column.setColumnName(columnName);
// Process
String processName = atts.getValue("ADProcessNameID");
int AD_Process_ID = get_IDWithColumn(ctx, "AD_Process", "Value", processName);
if (AD_Process_ID <= 0) /** TODO PackOut version check 005 */
{
AD_Process_ID = get_IDWithColumn(ctx, "AD_Process", "Name", processName);
}
m_Column.setAD_Process_ID(AD_Process_ID);
//
String Name = atts.getValue("ADReferenceNameID");
int referenceId = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
m_Column.setAD_Reference_ID(referenceId);
// log.info("Column ID ->"+id);
Name = atts.getValue("ADTableNameID");
id = get_IDWithColumn(ctx, "AD_Table", "TableName", Name);
m_Column.setAD_Table_ID(id);
Name = atts.getValue("ADValRuleNameID");
id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name);
m_Column.setAD_Val_Rule_ID(id);
//Validate that reference id is for Table or List
if (DisplayType.Table == referenceId || DisplayType.List == referenceId || DisplayType.Search == referenceId) {
Name = atts.getValue("ADReferenceNameValueID");
id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
m_Column.setAD_Reference_Value_ID(id);
}
m_Column.setCallout(getStringValue(atts, "Callout"));
m_Column.setColumnSQL(getStringValue(atts, "ColumnSQL"));
m_Column.setColumnName(atts.getValue("ColumnName"));
m_Column.setDefaultValue(getStringValue(atts, "DefaultValue"));
m_Column.setDescription(getStringValue(atts, "Description"));
m_Column.setEntityType(atts.getValue("EntityType"));
if (Integer.parseInt(atts.getValue("FieldLength")) > 0)
m_Column.setFieldLength(Integer.parseInt(atts.getValue("FieldLength")));
m_Column.setHelp(getStringValue(atts, "Help"));
m_Column.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
m_Column.setIsAlwaysUpdateable((Boolean.valueOf(atts.getValue("isAlwaysUpdateable")).booleanValue()));
// m_Column.setIsEncrypted(atts.getValue("isEncrypted"));
m_Column.setIsIdentifier((Boolean.valueOf(atts.getValue("isIdentifier")).booleanValue()));
m_Column.setIsKey((Boolean.valueOf(atts.getValue("isKey")).booleanValue()));
m_Column.setIsMandatory((Boolean.valueOf(atts.getValue("isMandatory")).booleanValue()));
m_Column.setIsParent((Boolean.valueOf(atts.getValue("isParent")).booleanValue()));
m_Column.setIsSelectionColumn((Boolean.valueOf(atts.getValue("isSelectionColumn")).booleanValue()));
m_Column.setIsSyncDatabase(atts.getValue("getIsSyncDatabase"));
m_Column.setIsTranslated((Boolean.valueOf(atts.getValue("isTranslated")).booleanValue()));
m_Column.setIsUpdateable((Boolean.valueOf(atts.getValue("isUpdateable")).booleanValue()));
m_Column.setName(atts.getValue("Name"));
m_Column.setReadOnlyLogic(getStringValue(atts, "ReadOnlyLogic"));
if (Integer.parseInt(atts.getValue("SeqNo")) > 0)
m_Column.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
m_Column.setVFormat(getStringValue(atts, "VFormat"));
if (getStringValue(atts, "ValueMax") != null)
m_Column.setValueMax(atts.getValue("ValueMax"));
if (getStringValue(atts, "ValueMin") != null)
m_Column.setValueMin(atts.getValue("ValueMin"));
if (getStringValue(atts, "Version") != null)
m_Column.setVersion(new BigDecimal(atts.getValue("Version")));
m_Column.setInfoFactoryClass(getStringValue(atts, "InfoFactoryClass"));
// Setup Element.
id = get_IDWithColumn(ctx, "AD_Element", "ColumnName", m_Column.getColumnName());
X_AD_Element adElement = new X_AD_Element(ctx, id, getTrxName(ctx));
String Object_Status_col = Object_Status;
if (adElement.getAD_Element_ID() == 0) {
// Object_Status = "New";
adElement.setColumnName(m_Column.getColumnName());
adElement.setEntityType(m_Column.getEntityType());
adElement.setPrintName(m_Column.getColumnName());
adElement.setName(m_Column.getColumnName());
if (adElement.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Column.getName(), "Element", adElement.getAD_Element_ID(), AD_Backup_ID, "New", "AD_Element", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Element"));
} else {
record_log(ctx, 0, m_Column.getName(), "Element", adElement.getAD_Element_ID(), AD_Backup_ID, "New", "AD_Element", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Element"));
}
}
Object_Status = Object_Status_col;
m_Column.setAD_Element_ID(adElement.getAD_Element_ID());
boolean recreateColumn = (m_Column.is_new() || m_Column.is_ValueChanged("AD_Reference_ID") || m_Column.is_ValueChanged("FieldLength") || m_Column.is_ValueChanged("ColumnName") || m_Column.is_ValueChanged("IsMandatory"));
//ignore fieldlength change for clob and lob
if (!m_Column.is_ValueChanged("AD_Reference_ID") && m_Column.is_ValueChanged("FieldLength")) {
if (DisplayType.isLOB(m_Column.getAD_Reference_ID())) {
recreateColumn = false;
}
}
// nulls
if (!recreateColumn) {
String oldDefault = (String) m_Column.get_ValueOld("DefaultValue");
String newDefault = m_Column.getDefaultValue();
if (oldDefault != null && oldDefault.length() == 0)
oldDefault = null;
if (newDefault != null && newDefault.length() == 0)
newDefault = null;
if ((oldDefault == null && newDefault != null) || (oldDefault != null && newDefault == null)) {
recreateColumn = true;
} else if (oldDefault != null && newDefault != null) {
if (!oldDefault.equals(newDefault))
recreateColumn = true;
}
}
// Don't create database column for virtual columns
boolean syncDatabase = "Y".equalsIgnoreCase(atts.getValue("getIsSyncDatabase"));
if (recreateColumn) {
if (m_Column.isVirtualColumn() || !syncDatabase)
recreateColumn = false;
}
if (m_Column.save(getTrxName(ctx)) == true) {
record_log(ctx, 1, m_Column.getName(), "Column", m_Column.get_ID(), AD_Backup_ID, Object_Status, "AD_Column", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Column"));
element.recordId = m_Column.getAD_Column_ID();
} else {
record_log(ctx, 0, m_Column.getName(), "Column", m_Column.get_ID(), AD_Backup_ID, Object_Status, "AD_Column", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Column"));
throw new POSaveFailedException("Failed to import column.");
}
if (recreateColumn || syncDatabase) {
MTable table = new MTable(ctx, m_Column.getAD_Table_ID(), getTrxName(ctx));
if (!table.isView() && !m_Column.isVirtualColumn()) {
success = createColumn(ctx, table, m_Column, recreateColumn);
if (success == 1) {
record_log(ctx, 1, m_Column.getColumnName(), "dbColumn", m_Column.get_ID(), 0, Object_Status, atts.getValue("ADTableNameID").toUpperCase(), get_IDWithColumn(ctx, "AD_Table", "TableName", atts.getValue("ADTableNameID").toUpperCase()));
} else {
record_log(ctx, 0, m_Column.getColumnName(), "dbColumn", m_Column.get_ID(), 0, Object_Status, atts.getValue("ADTableNameID").toUpperCase(), get_IDWithColumn(ctx, "AD_Table", "TableName", atts.getValue("ADTableNameID").toUpperCase()));
throw new DatabaseAccessException("Failed to create column or related constraint for " + m_Column.getColumnName());
}
}
}
} else {
element.skip = true;
}
}
Aggregations