2012-04-17 138 views
2

我了解ORMLite Android examples。但是,我有不止一个类要与ORMlite映射。ORMlite创建多个表ANDROID

在这个例子中创建匹配,我们使用这个“SimpleData”类表:

public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) { 
    try { 
     Log.i(DatabaseHelper.class.getName(), "onCreate"); 
     TableUtils.createTable(connectionSource, SimpleData.class); 
    } 

    catch (SQLException e) { 
     Log.e(DatabaseHelper.class.getName(), "Can't create database", e); 
     throw new RuntimeException(e); 
    } 

我如何创建我的所有表(这我的课比赛)?

回答

2

创建的第一个相同的方式,即用TableUtils.createTable方法的多次调用,向谁你会经过代表数据库中的表类

3

所以也许我不理解你想什么去做。在上面的SimpleData示例中,您引用DatabaseHelper中的代码。在onCreate方法,你可以创建任意数量的想要类:

public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) { 
    try { 
     Log.i(DatabaseHelper.class.getName(), "onCreate"); 
     TableUtils.createTable(connectionSource, SimpleData.class); 
     TableUtils.createTable(connectionSource, AnotherData.class); 
     TableUtils.createTable(connectionSource, AndAnotherData.class); 
     ... 
    } catch (SQLException e) { 
     ... 

对于工作程序。如果您看一下ClickCounter example,则会在其onCreate方法中创建两个实体:

public void onCreate(SQLiteDatabase sqliteDatabase, ConnectionSource connectionSource) { 
    try { 
     TableUtils.createTable(connectionSource, ClickGroup.class); 
     TableUtils.createTable(connectionSource, ClickCount.class); 
    } catch (SQLException e) { 
     Log.e(DatabaseHelper.class.getName(), "Unable to create datbases", e); 
    } 
}