简体   繁体   English

SQLite,Derby与文件系统

[英]SQLite , Derby vs file system

I'm working on a Java desktop application that reads and writes from/to different files. 我正在使用一个Java桌面应用程序,该文件可以从不同的文件中读取和写入。 I think a better solution would be to replace the file system by a SQLite database. 我认为更好的解决方案是用SQLite数据库替换文件系统。 How hard is it to migrate to this system and embed a database in my application? 迁移到该系统并在应用程序中嵌入数据库有多难? are there real performance gains? 是否有真正的性能提升? Thanks a lot 非常感谢

I don't think you will get a performance just by changing the data store to SQLite. 我认为仅将数据存储更改为SQLite不会获得性能。 You should migrate a FS-based store to a relational (SQL) database store if. 您应该将基于FS的存储迁移到关系(SQL)数据库存储。

  • You need atomic operations. 您需要原子操作。 - your app can crash at any time and you don't have to worry about corrupt data) -您的应用随时可能崩溃,而您不必担心数据损坏)
  • You need asynchronous operations. 您需要异步操作。 - multiple instances of your application can simultaneously modify the data without corrupting it/getting an invalid state. -您的应用程序的多个实例可以同时修改数据而不会破坏数据/获得无效状态。
  • You need data normalization. 您需要数据标准化。 - Products -m2m-> Catalogs -产品-m2m->目录
  • Automatic Indexes - If you need fast searching capabilities (if your file system isn't already fast enough) 自动索引 -如果您需要快速搜索功能(如果您的文件系统不够快)
  • You need abstraction of complex data operations. 您需要抽象复杂的数据操作。 - ie SELECT SUM(Price) WHERE Price < 10 and the likes -即SELECT SUM(Price)WHERE价格<10之类的

Those are some of the gains you get by switching to SQLite. 这些是您通过切换到SQLite所获得的一些收益。

You can gets performance gains from SQLite if you also properly utilizes one or more of the above properties of a relational store that you don't have using a file-based system. 如果您还适当地利用了关系存储的上述一个或多个属性,而您没有使用基于文件的系统,则可以从SQLite获得性能提升。

I don't think you will get notable performance gains on any standard desktop - as long as your application isn't doing nothing else but torturing the file system with reads and writes :) At the end, performance mainly depends on your code. 我认为您不会在任何标准台式机上获得显着的性能提升-只要您的应用程序除了通过读写操作折腾文件系统之外,什么都没有做:)最后,性能主要取决于您的代码。

If you consider switching to SQLite, you may want to have a look at SQLJet, a pure Java implementation of SQLite . 如果考虑切换到SQLite,则可能需要看看SQLJet,这是SQLite的纯Java实现 I haven't used it myself, but I think deploying it should be similar to Derby: all you need is add some Jars to your application and you are settled. 我没有亲自使用过它,但是我认为部署它应该与Derby类似:您所需要的只是在应用程序中添加一些Jars,您就可以安定下来。 I would try to avoid using external SQLite (or any other dependency on an external application) as it will considerable complicate the setup of your application. 我会尽量避免使用外部SQLite(或对外部应用程序的任何其他依赖项),因为它将使您的应用程序的安装复杂化。

Embedding Derby in a Java desktop application is straightforward. 将Derby嵌入到Java桌面应用程序中非常简单。 You simply add the Derby jar to your application, decide where you want to store your data on disk, and write standard SQL and JDBC calls to invoke Derby operations. 您只需将Derby jar添加到您的应用程序中,确定要在磁盘上存储数据的位置,然后编写标准SQL和JDBC调用来调用Derby操作。 Well-written Derby applications can deliver extremely high performance but you must pay attention to your schema and transaction design. 编写良好的Derby应用程序可以提供极高的性能,但您必须注意架构和事务设计。 Derby has good tools for analyzing and addressing performance problems. Derby具有分析和解决性能问题的良好工具。

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

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