在Java桌面应用程序中持久保存数据的最佳方法是什么? [英] What's the best way to persist data in a Java Desktop Application?

查看:83
本文介绍了在Java桌面应用程序中持久保存数据的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的桌面应用程序中有一棵大的Java对象,正在尝试确定将它们作为文件持久保存到文件系统的最佳方法.

I have a large tree of Java Objects in my Desktop Application and am trying to decide on the best way of persisting them as a file to the file system.

我的一些想法是:

  • 使用DataOutputStream滚动我自己的序列化器:这将使我对文件中的内容拥有最大的控制权,但要以微管理方式为代价.

  • Roll my own serializer using DataOutputStream: This would give me the greatest control of what was in the file, but at the cost of micromanaging it.

使用ObjectOutputStream及其各种相关类的直接旧序列化:虽然我发现数据很脆弱,但是我没有将其出售.更改任何对象的结构都会破坏它的序列化实例.因此,我陷入了可怕的版本控制噩梦.

Straight old Serialization using ObjectOutputStream and its various related classes: I'm not sold on it though since I find the data brittle. Changing any object's structure breaks the serialized instances of it. So I'm locked in to what seems to be a horrible versioning nightmare.

XML序列化:虽然不那么脆弱,但是直接进行序列化的速度要慢得多.可以在我的程序之外进行转换.

XML Serialization: It's not as brittle, but it's significantly slower that straight out serialization. It can be transformed outside of my program.

JavaDB :考虑到编写JDBC应用程序的舒适性,我考虑了这一点.此处的区别在于,数据库实例仅在打开或保存文件时才会保留.它不是很漂亮,但是...的确可以在以后出现需求时迁移到中央服务器体系结构,并且它提供了以更简单的方式查询数据模型的可能性.

JavaDB: I'd considered this since I'm comfortable writing JDBC applications. The difference here is that the database instance would only persist while the file was being opened or saved. It's not pretty but... it does lend itself to migrating to a central server architecture if the need arises later and it introduces the possibility of quering the datamodel in a simpler way.

我很好奇看到别人的想法.我希望我错过了一种比上述方法更简单明了的方法.

I'm curious to see what other people think. And I'm hoping that I've missed some obvious, and simpler approach than the ones above.

以下是从答案中得出的更多选择:

Here are some more options culled from the answers below:

  • 对象数据库-与ORM方法相比,其基础结构要少得多,并且其执行速度要比XML方法快.谢谢aku
  • An Object Database - Has significantly less infrastructure than ORM approaches and performs faster than an XML approach. thanks aku

推荐答案

db4objects 可能是最佳选择

这篇关于在Java桌面应用程序中持久保存数据的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆