我有一个 JSF 表格, 该表格使用 Hashmap 存储选中的复选框。 我的问题是: 是否可以使用 2D Java 阵列存储密钥而不是 Hashmap?
EDIT
I use this code to store the selected keys. How this code can be rewritten for Map
?
private HashMap<String, Boolean> selected = new HashMap<>();
// send the list
public Map<String, Boolean> getselected() {
return selected;
}
我的想法是创建 2D 数组( 将使用 MAP), 以存储页面页数和列表。 例如 100 页 x 10 个密钥 。
<强 > EDIT 2 强 >
I created JSF table with lazy loading which takes data from Oracle. The JSF works very well and fast. The problem that I face is when I tried to create select all
checkbox which takes all kays and stores the keys into hashmap
. Later those keys will be used for SQL query to delete the rows which the user selects.
I created database table with 10 000 rows and displayed them into JSF table. When I clicked them all I created hashmap
with 10 000. the performance is relatively good for that size. I tested to delete them - I created Java method which takes the generated hashmap
and deletes the database rows using the keys stored into the hashmap
. It s show but there can be done a few code optimizations.
The big problem is the scalability. I tested the hashmap
with 1 000 000 keys - it works but it s terribly slow. I need to design the JSF table to handle very big data.
I think that the solution is to use 2D array (lets call it for this example). I will explain my idea this way:
I will have for example JSF table with 100 pages. Every page will have 10 rows. Into the standard hashmap
I will have 1000 keys when I select all rows.
In 2D array solution I can create array with 100 elements and when I switch between the pages I will have only 10 rows which will be generated from the pagination code. When I select all database rows I can insert only the visible rows key into the 2D array. The other positions into the the array I replace with for example 1
in order to know that there is something. When I press the delete button the Java code will know that all elements are "virtually" selected. Is there a better and more simple solution?