且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在ORMLite一个类中创建多个表

更新时间:2023-11-30 20:09:34

最大的问题在这里是你所说的动态的意思。如果你的意思是,你需要创建这些模块订单 S上的苍蝇,你不知道他们的名字事先那么我相信一​​个模块名称字段是一个有效的方法做这个事情。为每种类型的顺序来创建一个表看起来像premature优化我 - 复杂性没有充分理由

The big question here is what do you mean by "dynamic". If you mean that you need to create these module Orders on the fly and you don't know their names beforehand then I believe a module-name field is the an efficient way to do this. To create a table for each type of order seems like premature optimization to me -- complexity without good reason.

也就是说,你可以通过实例化一个DatabaseTableConfig$c$c>每个表和定义的类编程的。

That said, you can accomplish dynamic classes by instantiating a DatabaseTableConfig for each table and defining the class programmatically.

如果你真的不意味着动态的,那么要完成把每个模块订单在其自己的表将与子类最简单的方法。

If you don't really mean dynamic, then the easiest way to accomplish putting each module Order in its own table would be with subclasses.

您可以有:

@DatabaseTable
public class FooOrder extends Order {
    // fields will be gotten from Order
}

@DatabaseTable
public class BarOrder extends Order {
    // fields will be gotten from Order
}

订单的字段将在每个 fooorder barorder 表。