实现预订数据库 EJB 3.0 的好方法是什么

发布于 2024-12-08 12:20:20 字数 1143 浏览 2 评论 0原文

在我正在开发的系统中,我们允许客户预订很多东西。目前,我有这 2 个实体:

@Entity
public class Reservation implements Serializable {
    ...
    private long startTime;
    private long endTime;
    private int  status;
    @ManyToOne
    private Customer theCustomer;   // record who made this reservation
    @ManyToOne
    private ReservableUnit theUnit; // record what this reservation is for
    ...
}

@Entity
public class ReservableUnit implements Serializable {

    private int numOfAvailableUnits;
    ...
    private int[][][] firstMonth = new int[31][24][2];
    ...
    private int[][][] fourthMonth = new int[31][24][2];
}

//status
public static final int AVAILABLE = 0;
public static final int BLOCKED   = 1;
public static final int RESERVED  = 2;

在 ReservableUnit 表中,我有 4 个 int[31][24][2] 数组来存储最多 3 个月之前的所有 30 分钟时段的状态。我使用数组是因为我认为当我将它们放入内存时,可以快速检查请求的时隙是否可用。

我的一个朋友告诉我,这不是一个好方法,因为我必须在数据库中存储大对象。他建议我应该删除这些字段,当我需要检查插槽是否可用时,我应该通过计算预订表中的行数来计算为这些插槽进行的预订数量。显然,我朋友的方式可以为我们节省一些数据库空间。然而,从长远来看,我们的 Reservation 表中将会有很多行,这意味着处理槽位状态的时间会越来越长。

我是一名学生,在设计数据库方面没有扎实的工作经验。因此,如果有人能就此事给我建议,我将不胜感激。

最好的问候,

詹姆斯·特兰

In the system I am working on, we allow customers to make reservations for a lot of things. Currently, I have these 2 entities:

@Entity
public class Reservation implements Serializable {
    ...
    private long startTime;
    private long endTime;
    private int  status;
    @ManyToOne
    private Customer theCustomer;   // record who made this reservation
    @ManyToOne
    private ReservableUnit theUnit; // record what this reservation is for
    ...
}

@Entity
public class ReservableUnit implements Serializable {

    private int numOfAvailableUnits;
    ...
    private int[][][] firstMonth = new int[31][24][2];
    ...
    private int[][][] fourthMonth = new int[31][24][2];
}

//status
public static final int AVAILABLE = 0;
public static final int BLOCKED   = 1;
public static final int RESERVED  = 2;

In the ReservableUnit table, I have 4 int[31][24][2] arrays to store the status of all 30-minute time slots up to 3 months ahead. I used arrays because I think that when I bring them into memory, it would be fast to check if the requested time slots are available or not.

A friend of mine told me that this is not a good approach because I have to store big objects in the database. He suggested that I should remove those fields and when I need to check if the slots are available, I should count the number of reservations that have been made for those slots by counting rows in the Reservation table. Obviously, my friend's way can save us some space in the database. However, in the long run, we will have a lot of rows in the Reservation table which means it will take longer and longer to process the status of slots.

I am a student with no solid working experience on designing database. Hence, I'd be very grateful if someone could give me an advice on this matter.

Best regards,

James Tran

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文