Behavior of sum Groovy
Hello
JDev 11.1.2.4
I have a VO with transient attributes BigDecimal.
The attribute A is a transitional BigDecimal with the value computed by the expression AmendmentsBlock4.sum ("Amount")
In DB, we have only a single folder and the amount is NUMBER (14.4) with the value - 22248.3949
Attribute B is a transitional BigDecimal with the value 22248.3949
Attribute C is a transitional BigDecimal with the calculated value A + B
If I run the application module I can see the following values
HAS:-22248.394899999999324791133403778076171875
B: 22248.3949
C: 6.75208866596221923828125E - 13
I understand why the value of A is displayed with so many decimals, it is because of the toString. What I don't understand is why the result of C is not 0. I checked with a pure Java class and it works as expected.
Thank you
import Java.Math.BigDecimal;
public class TestBigDecimal {}
Public Shared Sub main (String... args) {}
BigDecimal one = new BigDecimal(-22248.3949);
BigDecimal b = new BigDecimal (22248.3949);
System.out.println (a);
System.out.println (a.Add (b));
System.out.println (a.Add (b). CompareTo (BigDecimal.Zero));
}
}
Result:
C:\home > C:\Java\Java64\jdk1.7.0_21\bin\java TestBigDecimal
-22248.394899999999324791133403778076171875
0E-36
0
It is sometimes confusing to work with BigDecimal. Part of the problem is the way in which you create the variable a and b in your test.
a = new BigDecimal(-22248.3949);
the first problem is that the compiler has to guess the type of '-22248.3949'. '. If you are the type lucke correctly represents your number. in your case, it's not that you get "a =-22248.394899999999324791133403778076171875'."
Then, you use this misrepresentation to perform calculations. You see the problem? The problem becomes bigger and bigger, and in the end you get a result where a schoolkid can say "wow, that's wrong."
If you build a string figures you get better results
BigDecimal one = new BigDecimal(-22248.3949);
BigDecimal b = new BigDecimal (22248.3949);
BigDecimal one = new BigDecimal("-22248.3949");
BigDecimal b = new BigDecimal ("22248.3949");
System.out.println ("a =" + a);
System.out.println ("b =" + b);
System.out.println ("a + b =" + a.add (b));
System.out.println ("a is b =" + a.add (b) .compareTo (BigDecimal.ZERO));
will give you
a = 22248.3949
b = 22248.3949
a + b = 0.0000
So the problem is how the numbers are created.
You should do the same test in groovy. To get an output, you can use adfLogger in Groovy (https://blogs.oracle.com/jdevotnharvest/entry/using_adf_logger_with_groovy).
The I found this tutorial How to use Java BigDecimal: A Tutorial - Opentaps Wiki which gives some nice explanations on the use of BigDecimal.
Timo
Tags: Java
Similar Questions
-
Define 'Dimension to slow variation' behavior on a column of odi using Groovy
Hallo,
I want to tell him slowly change Dimensions behavior of a column in ODI via a groovy script.
In a loop, I says:
Col OdiColumn = new OdiColumn (ds, "ETL_ID");
col.setDataTypeCode ("NUMBER");
col.setMandatory (false);
col.setLength (20);
col.setScale (0);
Col. ScdType ("ADD_ROW_ON_CHANGE");
This work does'nt correct. I need to specify other parameters? (for the neck of the line. ScdType ("ADD_ROW_ON_CHANGE"); )
The manual States:
setScdType
public void setScdType (OdiColumn.ScdType pScdType)
Sets the OdiColumn.ScdType of this OdiColumn instance.
Parameters:
pScdType - type SCD
Can you help me?Oops, I forgot the name of Enum...
and you must use the setScdType methodTry this:
col.setScdType(ScdType.ADD_ROW_ON_CHANGE);
-
Dear all
I saw the video Of Grant Ronald about Groovy Exp, I tried to make small example to att in job VO to sum the salaries of employees for each job.
but, successful field calculating the problem now, when I'm with EmployeesVO1.sum ("Salary") the calculation for all employees regardless of the work!
I don't know why, but I have SSA & VL between EOs & your.
Please notify
Published by: Oracle itself July 15, 2011 07:41Then, you should make sure that your name of the accessor is correct. Double-click the JobEmpFkLink or any other name that is your link between the job and the employee. Go to the relatonship tab, in the users section and in the destination note your accessor for the employees name. Use this exact name in the expression.
-
Sum (1) vs Count (*) difference - bug?
Hello :-)
This morning I was very shocked after that I discovered that my COUNT (*) wasn't behaving as I supposed it should do.
I managed to create a simple SELECT statement shows the unexpected behavior.
Can someone explain to me what is happening here? Is this a bug? It happens to you too?
My real workaround is to use SUM (1).
WITH T1 AS)
NAME OF SELECT 'ROBERT', 'USA' COUNTRY OF DOUBLE UNION ALL
NAME OF SELECT 'TOM', 'USA' COUNTRY OF DOUBLE UNION ALL
'JOHN' SELECT NAME, 'CANADA' COUNTRY OF DOUBLE),
() AS T2
SELECT SUM (1) SUM1;
COUNT (*) COUNT_STAR,
COUNT (DISTINCT NAME) COUNT_DISTINCT
FROM T1
GROUP OF COUNTRIES
ORDER BY COUNTRY
)
SELECT * FROM T2;
SUM1 COUNT_STAR COUNT_DISTINCT
---------- ---------- --------------
1 1 1
2 1 2
I thought that SUM1 and COUNT_STAR should give the same result, but for the second row COUNT_STAR is 1 instead of 2.
That's not counting the lines.
Please note that if you write this query a little differently then SUM (1) and COUNT (*) give the same result.
For example, WITH the kidnapping:
WITH T1 AS)
NAME OF SELECT 'ROBERT', 'USA' COUNTRY OF DOUBLE UNION ALL
NAME OF SELECT 'TOM', 'USA' COUNTRY OF DOUBLE UNION ALL
'JOHN' SELECT NAME, 'CANADA' COUNTRY OF DOUBLE)
SELECT SUM (1) SUM1;
COUNT (*) COUNT_STAR,
COUNT (DISTINCT NAME) COUNT_DISTINCT
FROM T1
GROUP OF COUNTRIES
ORDER BY COUNTRY
Example Order By deleted
WITH T1 AS)
NAME OF SELECT 'ROBERT', 'USA' COUNTRY OF DOUBLE UNION ALL
NAME OF SELECT 'TOM', 'USA' COUNTRY OF DOUBLE UNION ALL
'JOHN' SELECT NAME, 'CANADA' COUNTRY OF DOUBLE),
() AS T2
SELECT SUM (1) SUM1;
COUNT (*) COUNT_STAR,
COUNT (DISTINCT NAME) COUNT_DISTINCT
FROM T1
GROUP OF COUNTRIES
)
SELECT * FROM T2;
Deleted COUNT DISTINCT example
WITH T1 AS)
NAME OF SELECT 'ROBERT', 'USA' COUNTRY OF DOUBLE UNION ALL
NAME OF SELECT 'TOM', 'USA' COUNTRY OF DOUBLE UNION ALL
'JOHN' SELECT NAME, 'CANADA' COUNTRY OF DOUBLE),
() AS T2
SELECT SUM (1) SUM1;
COUNT (*) COUNT_STAR
FROM T1
GROUP OF COUNTRIES
ORDER BY COUNTRY
)
SELECT * FROM T2;
DB is
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production on 64-bit Linux.
Good bye
Andrea
I think you hit bug
Bug 9857247 Erroneous for count (*) results with investment group
It affects 11.2.0.1 and 11.2.0.2 version and is set to 11.2.0.3 and 12.1.0.1.
A workaround mentioned in the note of support is to
Set "_optimizer_group_by_placement" = false
-
Groovy aggregate function based on condition
Hi all
I use jdev 12.1.3.0.0
I've set up an aggregate function in my master EO as explained in the blog
https://blogs.Oracle.com/ADF/entry/using_groovy_aggregate_functions_in
I need to add a condition to the number of records based on an attribute of the object of details view. Algorithm for the use case is
detailsAccessor.count ("SmsId")
where detailsAccessor.MessageType is equal to "file."
Could you help me write an expression to achieve this functionality.
Thank you
Mozakkir
All aggregate in groovy functions accept a groovy as a parameter expression.
So instead of detailsAccessor.count("SmsId") you can try something like: detailsAccessor.count ("MessageType is 'Applicant'")
Or convert sum() like this: detailsAccessor.sum ("MessageType is"Applying"? 1: 0 ")"
Dario
-
CERTAIN behaviors, NULL values
I am a little confused about the following situation:
I have a PL/SQL code with a block similar to this:
BEGIN
SELECT MAX (col1)
IN myVar
FROM MyTable
WHERE col1 < (SELECT MAX (col1) FROM MaTable;
EXCEPTION
WHEN NO_DATA_FOUND THEN
myVar: < something > =;
WHEN OTHERS RAISE.
END;The behavior I expect from this is to assign a value to myVar, which is the next most great. value to the record value of col1. If there is no record in myTable the NO_DATA_FOUND exception is thrown and myVar is filled with predetermined values. Everything works fine execpt...
When there is only one record stored in myTable, there is no exception raised and myVar is assigned to NULL. I think that since there is only one line in the table there is no trace of return that meets the SELECTION criteria and therefore the NO_DATA_FOUND exception which is not the case here would be raised but myVar is assigned NULL and the program continues to flow from there.
What is the problem with my way of thinking that the exception must be raised when there is a single record in myTable?
Thank you.
Documentation:
A SELECT INTO statement returns no rows, or your program refers to an element deleted in a nested table or a component not initialized in an index - by table. Aggregate SQL such as AVG and SUM always functions return a value or a null value. As a result, a SELECT INTO statement that calls an aggregate function ever triggers NO_DATA_FOUND.
That would be your MAX.
-
Display the sum of all salaries of employees @ footer section
Hi team,
I use Jdev 11.1.2.3.0 version.
I have a requirement where I need to see the sum of all the wages of employees in the employee table footer section in the user interface.
Is there a declarative approach to this question without using any method Java and master-details relationship.
Let me know if you need additional information on my problem.
Thanks in advance,
Check out ADF - Groovy amounting to Total of a column in a Table. Techartifact that should make your use case.
Timo
-
Groovy Support for aggregation in VO even function
Hello
I've looked through a lot of post that talks with aggregate function Groovy on the attributes of the use of relationship VO discovered accessor.
But is there a way that we can use the aggregate on the same VO function. Suppose I have EmoloyeesView and I have a transitional filed TotalSalary I want must have a value as the sum of all the wages of all employees.
How can I do this using Groovy.
Thank youCreate new in EmployeesView ViewAccessor points to EmployeesView, it will be called EmployeesView1 by default
Then in your object of EmployeesView add a new attribute and put the phrase such as EmployeesView1.sum ("Salary")However, this amount only will salaries in the cache - if not of all wages are interviewed you might not get a full picture in which case perhaps the expression of your attribute must call a SQL function to summarize the wages in the database.
concerning
Grant Ronald -
Calculation of sum in the attribute of the entity
Dear all,
I have following the entity attr.
The problem is that it does not display the design for attribute value, betai I created the accessor to view in the attribute of the entity.<Attribute Name="TotalAppraisedIncome" ColumnName="TOTAL_APPRAISED_INCOME" SQLType="NUMERIC" Type="oracle.jbo.domain.Number" ColumnType="NUMBER" TableName="z_z" IsQueriable="false" RetrievedOnUpdate="true" RetrievedOnInsert="true"> <DesignTime> <Attr Name="_DisplaySize" Value="22"/> </DesignTime> <TransientExpression><![CDATA[adf.object.IncomeDetailSummary_VO1.sum("(AppraisedIncome/100)*IncomeCombination")]]></TransientExpression> </Attribute>
But when I use it in viewobject as transitional attribute, it works very well...
I need to do at the level of the entities because the value is caluclated runtime and it should be updated in the field of database corrosponding.<ViewAttribute Name="TotalAppraisedIncomeView" IsSelected="false" IsPersistent="false" PrecisionRule="true" Type="oracle.jbo.domain.Number" ColumnType="NUMBER" AliasName="VIEW_ATTR" SQLType="NUMERIC"> <RecalcCondition><![CDATA[true]]></RecalcCondition> <TransientExpression><![CDATA[IncomeDetailSummary_VO1.getRowSet().sum("(AppraisedIncome/100)*IncomeCombination")]]></TransientExpression> </ViewAttribute>
Any ideas?
Thank you and best regards,
Sicard.
JDeveloper 11.1.1.5.0Hello
based on a usage example Dept/Emp in human resources
1 create EO departments and employees EO with Department/employee Association (master / detail)
2. search the name of the Association (in my case employees) end in detail
3. create a transient in EO departments attribute - say 'SalariesPaid '.
4. create a class Impl (EmployeesImpl and make associations that are exposed as methods)--> getEmployees1 in my case
5. use the following expression Groovy on the transient attributeadf.source.getEmployees1 (.sum ('Salary'));
... or whatever the mathematics you need to perform
Frank
-
Sum of the field of af: table
I have an af:table that when the click on add new button line is set
Here I have a column called quantity
I am entering data in each row of the total field
Now, I have a field outside af: table which is the Total amount... I need to enter the amount in the amount field in the Total amount field outside the af: table
How can we achieve thisHello
If your table is based on a view object, then you can use a transitional attribute and its value, use an expression groovy.
the new attribute must have:
value type: "expression".
"value: object.getRowSet (.sum ('AmountAttribute')).Drag the new attribute from sources of data to your page and add partialTriggers of the components that affect it
(Insert/remove buttons and the table field that it summarizes).Gabriel.
-
Display object attribute transitional (calculate amount) using groovy problem
Hello
I have a read-only view object named 'ConnectionVVO '. And there the database field name ' points of "(type is number)."»
Now, I need to take the sum of the points.
For this, I did the following.
View free object added to the same view as a view accessor named 'ConnectionVVO1 '.
Created a transitional attribute named "TotalPoints".
Added after groovy as an expression of the value of the transient above attribute.
After that, when I run the module the application and run the view object that is extremely slow. In fact nothing had appeared. After I changed the sql statement and added a clouse where clause to select a few lines.adf.object.ConnectionVVO1.getRowSet().sum("points")
Then he was appeared without delay.
The table has about 11 million documents.
Could you please provide a tip or any other way to do this (get the sum of the points).
Help, please.
Published by: benoit on March 9, 2011 14:56The problem is that you browse through all the data to summarize all the point values. Do this to 11 million lines takes time (lots of db back and forth). This is the reason why you must use a new VO with a query like
select sum(points) from yourtable
When you run this VO the sum is constructed in the comic book, using caches generate with one trip to the db and the DB. This should give you much better performance.
The solution you found in the blog is only good for small data sets.
Timo
-
Bizare behavior date field in an Oracle database.
I have this weird data problem seeking a date field oracle.
Look at these two result sets.
Two records are missing. :
COUNTY_CD CONAME FILE_DATE TRANSMISSIONS RECORDS NO_ERROR_RECORDS ERROR_RECORDS TOTAL_ERRORS 03 AMADOR NOVEMBER 7, 11 10 405 396 9 9 10 FRESNO NOVEMBER 7, 11 1 204 200 4 4 16 KINGS NOVEMBER 7, 11 3 1296 1110 186 194 20 MADERA NOVEMBER 7, 11 1 552 535 17 17 51 SUTTER NOVEMBER 7, 11 1 43 5 38 38 WHERE r.file_date BETWEEN TO_DATE('2011-11-07 00:00:00','YYYY-MM-DD HH24:MI:SS') AND TO_DATE('2011-11-07 15:00:00','YYYY-MM-DD HH24:MI:SS')
All records expected
COUNTY_CD CONAME FILE_DATE TRANSMISSIONS RECORDS NO_ERROR_RECORDS ERROR_RECORDS TOTAL_RECORDS 03 AMADOR NOVEMBER 7, 11 10 20 s 396 9 9 10 FRESNO NOVEMBER 7, 11 1 204 200 4 4 16 KINGS NOVEMBER 7, 11 3 1296 1110 186 194 20 MADERA NOVEMBER 7, 11 1 552 535 17 17 50 STANISLAS NOVEMBER 7, 11 2 17002 7165 9837 10028 51 SUTTER NOVEMBER 7, 11 1 43 5 38 38 WHERE r.file_date BETWEEN TO_DATE('2011-11-07 00:00:00','YYYY-MM-DD HH24:MI:SS') AND TO_DATE('2011-11-07 15:59:59','YYYY-MM-DD HH24:MI:SS')
Can someone tell me why recrods by the FILE_DATE field that has no portion of time looking, it's a field of data type 'DATE', would produce different results according to the time different parameters passed in the WHERE clause? This got me really confused and I just can't understand why this behavior change which makes me leary to trust a work around solution of data random apending time just at the place where clause.
Underneath the entire SQL query of the origanal source.
SELECT r.county_cd, c.coname, COUNT(unique r.file_name) AS transmissions, count(r.use_no) AS records, count(r.use_no) - count(e.use_no) AS no_error_records, count(e.use_no) AS error_records, sum(e.errors) AS total_errors FROM raw_pur r INNER JOIN pur_lookup l ON (r.use_no = l.use_no AND r.year = l.seq_year) LEFT OUTER JOIN ( SELECT year, use_no, count(use_no) AS errors FROM errors WHERE NOT (error_code = 17 OR error_code = 20 OR error_code = 72 OR error_code = 52 OR (error_code = 12 AND error_type = 'POSSIBLE') OR (error_code = 69 AND error_type = 'POSSIBLE') OR (error_code = 37 AND error_type = 'POSSIBLE') OR (error_code = 39 AND error_type = 'POSSIBLE')) GROUP BY year, use_no ) e ON (r.year = e.year AND r.use_no = e.use_no) INNER JOIN county c ON (r.county_cd = c.county_cd) WHERE r.file_date BETWEEN <cfqueryparam value="#form.fromDate#" cfsqltype="cf_sql_date"> AND <cfqueryparam value="#form.toDate#" cfsqltype="cf_sql_date"> GROUP BY r.county_cd, c.coname ORDER BY r.county_cd
Two things to consider: firstly, Yes, Oracle * always * retains part of the time in a date column, midnight if you do not specify. Secondly, cf_sql_date can give you weird results because of that, I tend to use the timestamp.
How the date has been entered in the first place? Much of the time it is put to use SYSDATE, which not only stores the date of the day, but the time, if you see that your form is another thing. Therefore, you might end up not getting results because you're doing something like this:
WHERE itemdate = February 8, 2011"
Backstage, itemdate is actually store some of the time, in order to not * not * equal this date is greater than it.
Use TRUNC (itemdate) If you want to just Oracle review date part in queries.
-
JTable: update behavior by using the arrow button
Dear Experts,
I create the following JTable to act as a calculator.import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.text.NumberFormat; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableColumn; public class CalculatorTable extends JFrame { //Fields private final String[] COLUMN_NAMES = {"1", "2", "3"}; private final int[] intArrayFirst = {1, 10, 100, 1000}; private NumberFormat nf = NumberFormat.getNumberInstance(); private TableBalanceCalculator tbc; // extends JPanel private JPanel pnlX, pnlY; private JButton btnClear; private JLabel lblTotal; private JTextField txtTotal; private int intTotal; //Constructors public CalculatorTable() { // Set up frame setTitle("Calculator"); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setSize(380, 280); // Initialize form and set to be visible initComponents(); setVisible(true); }// end of constructors private void initComponents() { getContentPane().setLayout(new BorderLayout()); pnlY = new JPanel(); pnlY.setLayout(new BoxLayout(pnlY, BoxLayout.Y_AXIS)); pnlX = new JPanel(); pnlX.setLayout(new BoxLayout(pnlX, BoxLayout.X_AXIS)); pnlX.add(Box.createHorizontalStrut(10)); pnlX.setAlignmentX(JFrame.RIGHT_ALIGNMENT); pnlY.add(Box.createVerticalStrut(15)); pnlY.add(pnlX); tbc = new TableBalanceCalculator(); pnlX = new JPanel(); pnlX.setLayout(new BoxLayout(pnlX, BoxLayout.X_AXIS)); pnlX.add(Box.createHorizontalStrut(10)); pnlX.add(tbc); pnlY.add(Box.createVerticalStrut(10)); pnlY.add(pnlX); lblTotal = new JLabel("Total:"); txtTotal = new JTextField(); txtTotal.setFocusable(false); txtTotal.setHorizontalAlignment(JTextField.RIGHT); pnlX = new JPanel(); pnlX.setLayout(new BoxLayout(pnlX, BoxLayout.X_AXIS)); pnlX.add(Box.createHorizontalStrut(140)); pnlX.add(lblTotal); pnlX.add(Box.createHorizontalStrut(20)); pnlX.add(txtTotal); pnlX.add(Box.createHorizontalStrut(25)); pnlY.add(Box.createVerticalStrut(10)); pnlY.add(pnlX); btnClear = new JButton("Clear"); btnClear.setMnemonic(KeyEvent.VK_C); btnClear.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { tbc.clearTable(); } }); pnlX = new JPanel(); pnlX.setLayout(new BoxLayout(pnlX, BoxLayout.X_AXIS)); pnlX.add(Box.createHorizontalStrut(60)); pnlX.add(btnClear); pnlX.add(Box.createHorizontalStrut(15)); pnlY.add(Box.createVerticalStrut(20)); pnlY.add(pnlX); pnlY.add(Box.createVerticalStrut(20)); getContentPane().add(pnlY); } //Class to create tables with one model private class TableBalanceCalculator extends JPanel { // Fields static final long serialVersionUID = 200907131455L; // YYYY MM DD hh mm private JScrollPane tblScrPn; private CalculatorJTable tblCalc; private CalculatorTableModel mdlTableCalc; // Constructor private TableBalanceCalculator(){ mdlTableCalc = new CalculatorTableModel(COLUMN_NAMES, intArrayFirst); mdlTableCalc.addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent tme) { intTotal = 0; for (int i = 0; i < intArrayFirst.length; i++) { intTotal = intTotal + (Integer)(tblCalc.getValueAt(i, 2)); } txtTotal.setText(nf.format(intTotal)); } }); tblCalc = new CalculatorJTable(mdlTableCalc); tblCalc.setPreferredScrollableViewportSize(new Dimension(320, 100)); tblCalc.setRowHeight(25); tblCalc.setRowSelectionAllowed(false); tblCalc.setColumnSelectionAllowed(false); // Only allow cell selection // Set column width TableColumn col; for (int i = 0; i < COLUMN_NAMES.length; i++){ col = tblCalc.getColumnModel().getColumn(i); if (i == 0) col.setPreferredWidth(60); else if (i==1) { col.setPreferredWidth(40); col.setCellRenderer(new DefaultTableCellRenderer() { static final long serialVersionUID = 201101151629L; // Override the renderer to format String public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel jlabRender = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); jlabRender.setHorizontalAlignment(SwingConstants.CENTER); return jlabRender; } }); } else col.setPreferredWidth(120); } // Create the scroll pane and add the table to it. tblScrPn = new JScrollPane(tblCalc); // Add the scroll pane to this panel. add(tblScrPn); tblCalc.changeSelection(0, 1, false, false); // set initial selection } // end of constructor // Methods CalculatorJTable getTable() { return tblCalc; } void clearTable() { for (int i = 0; i < intArrayFirst.length; i++) { tblCalc.setValueAt(null, i, 1); tblCalc.changeSelection(0, 1, false, false); // return to the first cell in the column tblCalc.requestFocusInWindow(); // otherwise the focus is still in btnClear } } } // end of class Table Cash Inventory //Special JTable class to override changeSelection private class CalculatorJTable extends JTable { // Fields static final long serialVersionUID = 201111121009L; // Constructor private CalculatorJTable(CalculatorTableModel dm) { super(dm); } // Overriding to prevent selection on some columns public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) { super.changeSelection(rowIndex, 1, toggle, extend); // only column 2 is editable. } } public class CalculatorTableModel extends AbstractTableModel { // Fields static final long serialVersionUID = 201101111111L; // YYYY MM DD hh mm private final int MAX_ROWS; private String[] columnNames; private Object[][] objData; // Constructor CalculatorTableModel(String[] astrC, int[] aintBNoteType) { MAX_ROWS = aintBNoteType.length; columnNames = astrC; objData = new Object[MAX_ROWS][columnNames.length]; for (int i = 0; i < MAX_ROWS; i++) { objData[0] = aintBNoteType[i];
}
}
// Three methods that must be implemented
public int getRowCount(){
return MAX_ROWS; // Set table to have maximum allowable items in a transaction
}
public int getColumnCount(){
return columnNames.length;
}
public Object getValueAt(int row, int col){
if (col == 2) { // the column is summarized to obtain a sum in a JTextField
if ((objData[row][col] == null) || (objData[row][col].toString().length() == 0)) return 0;
else return objData[row][col];
} else return objData[row][col];
}
// Method to set column name
public String getColumnName(int col){
return columnNames[col];
}
// Override setValueAt to update objData, because column 1 is editable
public void setValueAt(Object value, int row, int col) {
if (col == 1) {
objData[row][col] = value;
objData[row][2] = (value != null ? (Short)value * (Integer)objData[row][0] : null);
}
fireTableCellUpdated(row, col);
}
// Wihtout the following method no cell is editable
public boolean isCellEditable(int row, int col) {
if (col == 1) return true;
else return false;
}
public Class<?> getColumnClass(int c) {
if (c==1) return Short.class;
else return Integer.class;
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new CalculatorTable();
}
});
}
}
I don't have any problem when I use <Enter> key to confirm my input in Column 2. However, if I use <ARROW DOWN> key, it will not work perfectly in the last row. When I reach the bottom row, press a number and then <ARROW DOWN> key, only the total sum is updated, but the value in Column 3 remains unchanged. My questions are: 1. What is the best explanation of this behavior? 2. What is the best approach to solve the problem? I have thought of disabling the arrow key, but the problem also occurs on the first row with <ARROW UP> key. Thank you for your help. Patrick
your model should trigger rowsUpdated (instead of cellUpdated) as the other cell values are changed so
Basically, it's an accident (due to the internal implementation of paint on updates) it seems to work in other rows
See you soon
Jeanette -
Hello
Today I have a situation that did not expceted by me. A simple request like:
SELECT STOCK_CODE, TO_CHAR (SUM(PRICE*LOTS), '999,999,999,999.00') AS VOLUME
OF ISE_OPS
WHERE BUY_SIDE = "XYZ" OR SELL_SIDE = "XYZ".
Returns a value that is less than the sum of:
SELECT STOCK_CODE, TO_CHAR (SUM(PRICE*LOTS), '999,999,999,999.00') AS VOLUME
OF ISE_OPS
WHERE BUY_SIDE = 'XYZ '.
SELECT STOCK_CODE, TO_CHAR (SUM(PRICE*LOTS), '999,999,999,999.00') AS VOLUME
OF ISE_OPS
WHERE SELL_SIDE = 'XYZ '.
There are records of the table that have the BUY_SIDE and the "XYZ" SELL_SIDE and difference is little. 'OR' in the where clause behaves as an XOR Gate.
This is the normal behavior or am I missing something?
Kind regards.user508101 wrote:
This is the normal behaviorYes.
But maybe you want something like:
SELECT STOCK_CODE, TO_CHAR(SUM(PRICE*LOTS),'999,999,999,999.00') AS VOLUME FROM ( SELECT STOCK_CODE, PRICE, LOT FROM ISE_OPS WHERE BUY_SIDE='XYZ' UNION ALL SELECT STOCK_CODE, PRICE, LOT FROM ISE_OPS WHERE SELL_SIDE='XYZ' ) GROUP BY STOCK_CODE;
-
export, import of behavior
Hello
DB - 10.2.0.1 (company)
A user has exported its data using 'owner of queue = elec.dmp system@elecdb exp = elec'
The bucket size is 250 MB. I created the user elec in my assignment PB connect role only. Imported from this discharge as ' imp system@proddb file = elec.dmp fromuser = touser = elec elec
When I select tablespace_name, dba_segments sum(bytes/1024/1024) where owner = 'ELEC' group by tablespace_name; It shows 4GB!
After ' exec dbms_stats.gather_schema_stats (ownname = > 'elec') and asking questions show the same size as 4 GB.
An organization can help me understand this behavior?
(I guess that's maybe because of statistics)
Thank you
AshishThis is because the default value for the parameter 'COMPRESS' is "O" and you have a table that grew very big but suffered cuts (or himself, had been created similarly to an import of an another similar export!).
The "COMPRESSION" = "Y" causes a statement CREATE TABLE (and CREATE INDEX) to write with a very large INITIAL extent. Even if the target tablespace with AUTOALLOCATE or UNIFORM was created, Oracle creates the table in the goal of database with very large or very many allocated extensions.Hemant K Collette
http://hemantoracledba.blogspot.com
Maybe you are looking for
-
Satellite L300 14 c: driver download link does not work for XP
Hello! From the 19/05/2008, Windows XP compatible drivers & utilities launched by TOSHIBA, I try to download the same. But I am facing a common error for each download "Page is not found... "as if the source files are not all present or URL is wrong!
-
Wake-up keyboard or mouse mode standby? Where is it?
I somehow activate or disable something so now I can me wake up the computer by moving the mouse, but the problem is that the computer does not go on standby at all then that before the cessation of any activity, including the fans, but now, just the
-
I bought a Canon EOS Rebel T4i camera. What is the best memory card to use? I am a novice.
-
As I unlock my external hard drive with Bit Locker Drive Encryption, I get an error.
Hi, I'm unlock my external hard drive with Bit Locker Drive Encryption I get an error like "BitLocker Drive Encryption doesn't have to recover from a suddenly completed conversion. This can result from the newspaper of conversion being corrupt or the
-
I been using PS CS5 for a long time and you want to finally updated to at CC, there will be a sharp learning curve? My styles, templates, palettes, etc. will always be compatible? Thank you!