与 Java 中的数据表作斗争

发布于 2024-09-25 16:50:21 字数 347 浏览 8 评论 0原文

我是一名 .NET 开发人员,正在尝试使用 Java。我当前的项目有 UI 层、业务逻辑层和数据访问层。我目前正在 DAL 工作。

我还没有连接到外部数据库;我曾希望让我的 DAL 类利用内存中的数据表,直到数据库就位。

在 .NET 中,创建内存数据表、从中选择、添加到其中以及从中删除非常容易。但是,在 Java 中,我一直无法找到做同样事情的东西。

我正在考虑用强类型对象的集合替换“dataTables”;但这需要在 DAL 内部添加对业务层的引用(我认为这是一个禁忌)。

有人可以帮助困惑的开发人员吗?如果整个方法有缺陷,你会怎么做?如果我错过了 Java 中 dataTable 的等价物 - 它是什么?

I'm a .NET Developer trying my hand at Java. My current project has a UI layer, Business logic layer, and a Data Access layer. I'm currently working on the DAL.

I'm not connecting to an external database yet; I had hoped to have my DAL classes utilize in-memory dataTables until the DB is in place.

In .NET it's very easy to make in-memory dataTables, select from them, add to them, and remove from them. But, in Java, I've been unable to find something that does the same thing.

I was considering replacing the 'dataTables' with a collection of strongly typed objects; but that would require adding references to Business layer inside of the DAL (and I thought that was a no-no).

Can someone help a confused developer out? If this whole approach is flawed, what would you do? If I missed the equivalent of a dataTable in Java - what is it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一身骄傲 2024-10-02 16:50:21

这是一篇文章 关于运行内存中 Derby 数据库。

如果我知道您正在使用什么数据库和持久性库,我也许能够给出更准确的答案。

Here's an article on running an in-memory Derby database.

If I knew what database and what persistence library you're using, I might be able to give a more precise answer.

隱形的亼 2024-10-02 16:50:21

您可以使用 这个答案

这个 SO 问题中显示了不同内存数据库的比较。

You could use a memory database like described in this answer.

A comparison of different memory databases is shown in this SO question.

抚你发端 2024-10-02 16:50:21

我正在考虑更换
'dataTables' 的集合
强类型对象;但这会
需要添加对业务的引用
DAL 内部的层(我认为
这是一个禁忌)。

这些规则是谁制定的?

如果您的数据访问层负责模型对象的 CRUD 操作,那么在我看来,它必须引用它们。没有办法解决这个问题。

持久层不需要了解服务层或视图层。

唯一完全解耦的类是不与任何人交谈且不提供任何内容的类。没用的。

不要太执着于“规则”。您正在尝试对您的应用程序进行分层。您将有关持久性的所有内容放入类层中。

我不认为内存数据库对设计持久层的方式有任何影响。您应该能够交换关系数据库或平面文件或任何其他机制,但界面不应更改。这是一个实现细节。

I was considering replacing the
'dataTables' with a collection of
strongly typed objects; but that would
require adding references to Business
layer inside of the DAL (and I thought
that was a no-no).

Who makes up these rules?

If your data access layer is responsible for CRUD operations for model objects, it seems to me that it has to have references to them. There's no way around that.

The persistence tier need not know about the service or view layers.

The only completely uncoupled class is one that talks to no one and offers nothing. It's useless.

Don't be so hung up on "rules". You're trying to layer your application. You're putting all things about persistence into a layer of classes.

I don't think in-memory database has any effect on the way you design the persistence tier. You should be able to swap in a relational database or flat file or any other mechanism, but the interface shouldn't change. That's an implementation detail.

困倦 2024-10-02 16:50:21

OR/M 在 Java 中的出现比在 .NET 中要早得多。数据集有缺陷,因为它们迫使您按程序进行编程。尝试与对象交互并稍后将它们映射到数据库。

OR/Ms were available much earlier in Java than in .NET. DataSets are flawed in that they force you to program procedurally. Try to interact with objects and map those to the DB later.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文