IDEMPIERE-6061 Performance - MPrintFormatItem loading MPrintFormat on constructor (#2258)
This commit is contained in:
parent
7ff0f2f2b9
commit
69121c5794
|
@ -75,7 +75,6 @@ public class MPrintFormat extends X_AD_PrintFormat implements ImmutablePOSupport
|
||||||
m_language = Env.getLanguage(ctx);
|
m_language = Env.getLanguage(ctx);
|
||||||
if (Util.isEmpty(AD_PrintFormat_UU))
|
if (Util.isEmpty(AD_PrintFormat_UU))
|
||||||
setInitialDefaults();
|
setInitialDefaults();
|
||||||
m_items = getItems();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,7 +91,6 @@ public class MPrintFormat extends X_AD_PrintFormat implements ImmutablePOSupport
|
||||||
m_language = Env.getLanguage(ctx);
|
m_language = Env.getLanguage(ctx);
|
||||||
if (AD_PrintFormat_ID == 0)
|
if (AD_PrintFormat_ID == 0)
|
||||||
setInitialDefaults();
|
setInitialDefaults();
|
||||||
m_items = getItems();
|
|
||||||
} // MPrintFormat
|
} // MPrintFormat
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,9 +104,10 @@ public class MPrintFormat extends X_AD_PrintFormat implements ImmutablePOSupport
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadItems() {
|
public void reloadItems() {
|
||||||
m_items = getItems();
|
m_items = null;
|
||||||
if (is_Immutable() && m_items != null && m_items.length > 0)
|
getItems();
|
||||||
Arrays.stream(m_items).forEach(e -> e.markImmutable());
|
if (is_Immutable() && getItems() != null && getItems().length > 0)
|
||||||
|
Arrays.stream(getItems()).forEach(e -> e.markImmutable());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,7 +120,6 @@ public class MPrintFormat extends X_AD_PrintFormat implements ImmutablePOSupport
|
||||||
{
|
{
|
||||||
super(ctx, rs, trxName);
|
super(ctx, rs, trxName);
|
||||||
m_language = Env.getLanguage(ctx);
|
m_language = Env.getLanguage(ctx);
|
||||||
m_items = getItems();
|
|
||||||
} // MPrintFormat
|
} // MPrintFormat
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -159,7 +157,7 @@ public class MPrintFormat extends X_AD_PrintFormat implements ImmutablePOSupport
|
||||||
this.m_tFormat = copy.m_tFormat != null ? new MPrintTableFormat(ctx, copy.m_tFormat, trxName) : null;
|
this.m_tFormat = copy.m_tFormat != null ? new MPrintTableFormat(ctx, copy.m_tFormat, trxName) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Items */
|
/** Items - do not access directly - always use getItems() */
|
||||||
private MPrintFormatItem[] m_items = null;
|
private MPrintFormatItem[] m_items = null;
|
||||||
/** Translation View Language */
|
/** Translation View Language */
|
||||||
private String m_translationViewLanguage = null;
|
private String m_translationViewLanguage = null;
|
||||||
|
@ -200,11 +198,11 @@ public class MPrintFormat extends X_AD_PrintFormat implements ImmutablePOSupport
|
||||||
public int[] getOrderAD_Column_IDs()
|
public int[] getOrderAD_Column_IDs()
|
||||||
{
|
{
|
||||||
HashMap<Integer,Integer> map = new HashMap<Integer,Integer>(); // SortNo - AD_Column_ID
|
HashMap<Integer,Integer> map = new HashMap<Integer,Integer>(); // SortNo - AD_Column_ID
|
||||||
for (int i = 0; i < m_items.length; i++)
|
for (int i = 0; i < getItems().length; i++)
|
||||||
{
|
{
|
||||||
// Sort Order and Column must be > 0
|
// Sort Order and Column must be > 0
|
||||||
if (m_items[i].getSortNo() != 0 && m_items[i].getAD_Column_ID() != 0)
|
if (getItems()[i].getSortNo() != 0 && getItems()[i].getAD_Column_ID() != 0)
|
||||||
map.put(Integer.valueOf(m_items[i].getSortNo()), Integer.valueOf(m_items[i].getAD_Column_ID()));
|
map.put(Integer.valueOf(getItems()[i].getSortNo()), Integer.valueOf(getItems()[i].getAD_Column_ID()));
|
||||||
}
|
}
|
||||||
// Get SortNo and Sort them
|
// Get SortNo and Sort them
|
||||||
Integer[] keys = new Integer[map.keySet().size()];
|
Integer[] keys = new Integer[map.keySet().size()];
|
||||||
|
@ -228,10 +226,10 @@ public class MPrintFormat extends X_AD_PrintFormat implements ImmutablePOSupport
|
||||||
public int[] getAD_Column_IDs()
|
public int[] getAD_Column_IDs()
|
||||||
{
|
{
|
||||||
ArrayList<Integer> list = new ArrayList<Integer>();
|
ArrayList<Integer> list = new ArrayList<Integer>();
|
||||||
for (int i = 0; i < m_items.length; i++)
|
for (int i = 0; i < getItems().length; i++)
|
||||||
{
|
{
|
||||||
if (m_items[i].getAD_Column_ID() != 0 && m_items[i].isPrinted())
|
if (getItems()[i].getAD_Column_ID() != 0 && getItems()[i].isPrinted())
|
||||||
list.add(Integer.valueOf(m_items[i].getAD_Column_ID()));
|
list.add(Integer.valueOf(getItems()[i].getAD_Column_ID()));
|
||||||
}
|
}
|
||||||
// Convert
|
// Convert
|
||||||
int[] retValue = new int[list.size()];
|
int[] retValue = new int[list.size()];
|
||||||
|
@ -256,6 +254,8 @@ public class MPrintFormat extends X_AD_PrintFormat implements ImmutablePOSupport
|
||||||
*/
|
*/
|
||||||
private MPrintFormatItem[] getItems()
|
private MPrintFormatItem[] getItems()
|
||||||
{
|
{
|
||||||
|
if (m_items != null)
|
||||||
|
return m_items;
|
||||||
ArrayList<MPrintFormatItem> list = new ArrayList<MPrintFormatItem>();
|
ArrayList<MPrintFormatItem> list = new ArrayList<MPrintFormatItem>();
|
||||||
String sql = "SELECT * FROM AD_PrintFormatItem pfi "
|
String sql = "SELECT * FROM AD_PrintFormatItem pfi "
|
||||||
+ "WHERE pfi.AD_PrintFormat_ID=? AND pfi.IsActive='Y'"
|
+ "WHERE pfi.AD_PrintFormat_ID=? AND pfi.IsActive='Y'"
|
||||||
|
@ -290,6 +290,7 @@ public class MPrintFormat extends X_AD_PrintFormat implements ImmutablePOSupport
|
||||||
//
|
//
|
||||||
MPrintFormatItem[] retValue = new MPrintFormatItem[list.size()];
|
MPrintFormatItem[] retValue = new MPrintFormatItem[list.size()];
|
||||||
list.toArray(retValue);
|
list.toArray(retValue);
|
||||||
|
m_items = retValue;
|
||||||
return retValue;
|
return retValue;
|
||||||
} // getItems
|
} // getItems
|
||||||
|
|
||||||
|
@ -378,9 +379,9 @@ public class MPrintFormat extends X_AD_PrintFormat implements ImmutablePOSupport
|
||||||
*/
|
*/
|
||||||
public int getItemCount()
|
public int getItemCount()
|
||||||
{
|
{
|
||||||
if (m_items == null)
|
if (getItems() == null)
|
||||||
return -1;
|
return -1;
|
||||||
return m_items.length;
|
return getItems().length;
|
||||||
} // getItemCount
|
} // getItemCount
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -390,9 +391,9 @@ public class MPrintFormat extends X_AD_PrintFormat implements ImmutablePOSupport
|
||||||
*/
|
*/
|
||||||
public MPrintFormatItem getItem (int index)
|
public MPrintFormatItem getItem (int index)
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= m_items.length)
|
if (index < 0 || index >= getItems().length)
|
||||||
throw new ArrayIndexOutOfBoundsException("Index=" + index + " - Length=" + m_items.length);
|
throw new ArrayIndexOutOfBoundsException("Index=" + index + " - Length=" + getItems().length);
|
||||||
return m_items[index];
|
return getItems()[index];
|
||||||
} // getItem
|
} // getItem
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1385,9 +1386,9 @@ public class MPrintFormat extends X_AD_PrintFormat implements ImmutablePOSupport
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public MPrintFormat clone() throws CloneNotSupportedException {
|
public MPrintFormat clone() throws CloneNotSupportedException {
|
||||||
MPrintFormat clone = (MPrintFormat) super.clone();
|
MPrintFormat clone = (MPrintFormat) super.clone();
|
||||||
clone.m_items = m_items == null ? null : new MPrintFormatItem[m_items.length];
|
clone.m_items = getItems() == null ? null : new MPrintFormatItem[getItems().length];
|
||||||
for(int i = 0; i < m_items.length; i++) {
|
for(int i = 0; i < getItems().length; i++) {
|
||||||
clone.m_items[i] = m_items[i];
|
clone.m_items[i] = getItems()[i];
|
||||||
}
|
}
|
||||||
clone.m_tFormat = m_tFormat;
|
clone.m_tFormat = m_tFormat;
|
||||||
clone.m_language = Env.getLanguage(Env.getCtx());
|
clone.m_language = Env.getLanguage(Env.getCtx());
|
||||||
|
@ -1407,8 +1408,8 @@ public class MPrintFormat extends X_AD_PrintFormat implements ImmutablePOSupport
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
makeImmutable();
|
makeImmutable();
|
||||||
if (m_items != null && m_items.length > 0)
|
if (getItems() != null && getItems().length > 0)
|
||||||
Arrays.stream(m_items).forEach(e -> e.markImmutable());
|
Arrays.stream(getItems()).forEach(e -> e.markImmutable());
|
||||||
if (m_tFormat != null)
|
if (m_tFormat != null)
|
||||||
m_tFormat.markImmutable();
|
m_tFormat.markImmutable();
|
||||||
return this;
|
return this;
|
||||||
|
|
Loading…
Reference in New Issue