简体   繁体   English

如何从数据库中存储对象?

[英]How to store Objects from Database?

I am developing a java application which will be graphically depicting and organizing hundreds of objects. 我正在开发一个java应用程序,它将以图形方式描绘和组织数百个对象。 Each of these objects is loaded in from a SQL database, for use in this program. 这些对象中的每一个都从SQL数据库加载,以便在此程序中使用。

I plan to keep a local copy of all the data, retrived through a JDBC connection, and then sort it locally (Likely with Merge Sort as that is my favorite) 我计划保留所有数据的本地副本,通过JDBC连接重新获得,然后在本地对其进行排序(可能与Merge Sort一样,因为这是我最喜欢的)

How would you recommend I store the data locally? 您如何建议我在本地存储数据? Ideally, it would be very easy to traverse, sort and compare to the source Database. 理想情况下,遍历,排序和比较源数据库非常容易。

Currently, I have objects called Ideas which are populated from the database. 目前,我有一些名为Ideas对象,这些对象是从数据库中填充的。 Then, to display them, I create the same number of IdeaGraphics objects and add them to the appropriate JPanels. 然后,为了显示它们,我创建了相同数量的IdeaGraphics对象并将它们添加到适当的JPanels中。 This can be quite slow at times. 这有时可能很慢。

您可以实现Comparator接口并使用Collections.sort()修改的归并,如图所示这里

Maybe you already did that but it's not so clear in your question: 也许你已经这样做但在你的问题中并不是那么清楚:

You can get almost as many instances of your data class (Ideas) but it's not the same at all with graphic classes. 您可以获得几乎与数据类(Ideas)一样多的实例,但它与图形类完全不同。 Limit the number of widgets and graphics to 1. 将小部件和图形的数量限制为1。

Build your own custom JPanel class, give it a list of Ideas and override the paintComponent method to draw all items in the list. 构建自己的自定义JPanel类,为其提供一个Ideas列表,并覆盖paintComponent方法以绘制列表中的所有项。

If your visible area is large, double buffer it. 如果您的可见区域很大,请对其进行双重缓冲。

I disagree with that and not good idea to holding lots of data in local Memory, with idea to simulate, excelent optimalized preprocesor from Sql Engine (most of todays engines), then basically faster as best EndUser PC 我不同意这一点并不是很好的想法,在本地内存中保存大量数据,想要模拟,优秀的Sql Engine优化预处理器(当今大多数引擎),然后基本上更快,因为最好的EndUser PC

and if you have some WHATEVER permisions to the Database, then there are still exist option(s) to loading data from DbEngine to the Embedded database (on Memory), maybe to H2 or maybe JavaDB 如果你对数据库有一些WHATEVER权限,那么仍然存在将数据从DbEngine加载到嵌入式数据库 (在内存中)的选项,可能是H2或者也许是JavaDB

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM