当前位置: 首页>>代码示例>>Java>>正文


Java Database类代码示例

本文整理汇总了Java中org.greenrobot.greendao.database.Database的典型用法代码示例。如果您正苦于以下问题:Java Database类的具体用法?Java Database怎么用?Java Database使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Database类属于org.greenrobot.greendao.database包,在下文中一共展示了Database类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTable

import org.greenrobot.greendao.database.Database; //导入依赖的package包/类
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
    String constraint = ifNotExists? "IF NOT EXISTS ": "";
    db.execSQL("CREATE TABLE " + constraint + "\"VIDEO_BEAN\" (" + //
            "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
            "\"DATA_TYPE\" TEXT," + // 1: dataType
            "\"TITLE\" TEXT," + // 2: title
            "\"TEXT\" TEXT," + // 3: text
            "\"DESCRIPTION\" TEXT," + // 4: description
            "\"IMAGE\" TEXT," + // 5: image
            "\"ACTION_URL\" TEXT," + // 6: actionUrl
            "\"SHADE\" INTEGER NOT NULL ," + // 7: shade
            "\"PLAY_URL\" TEXT," + // 8: playUrl
            "\"CATEGORY\" TEXT," + // 9: category
            "\"DURATION\" INTEGER NOT NULL ," + // 10: duration
            "\"ICON\" TEXT);"); // 11: icon
}
 
开发者ID:popo1379,项目名称:popomusic,代码行数:18,代码来源:VideoBeanDao.java

示例2: createTable

import org.greenrobot.greendao.database.Database; //导入依赖的package包/类
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
    String constraint = ifNotExists? "IF NOT EXISTS ": "";
    db.execSQL("CREATE TABLE " + constraint + "\"TRACE_REPO\" (" + //
            "\"ID\" INTEGER PRIMARY KEY NOT NULL ," + // 0: id
            "\"NAME\" TEXT NOT NULL ," + // 1: name
            "\"DESCRIPTION\" TEXT," + // 2: description
            "\"LANGUAGE\" TEXT," + // 3: language
            "\"STARGAZERS_COUNT\" INTEGER," + // 4: stargazersCount
            "\"WATCHERS_COUNT\" INTEGER," + // 5: watchersCount
            "\"FORKS_COUNT\" INTEGER," + // 6: forksCount
            "\"FORK\" INTEGER," + // 7: fork
            "\"OWNER_LOGIN\" TEXT," + // 8: ownerLogin
            "\"OWNER_AVATAR_URL\" TEXT," + // 9: ownerAvatarUrl
            "\"START_TIME\" INTEGER," + // 10: startTime
            "\"LATEST_TIME\" INTEGER," + // 11: latestTime
            "\"TRACE_NUM\" INTEGER);"); // 12: traceNum
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:19,代码来源:TraceRepoDao.java

示例3: createTable

import org.greenrobot.greendao.database.Database; //导入依赖的package包/类
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
    String constraint = ifNotExists? "IF NOT EXISTS ": "";
    db.execSQL("CREATE TABLE " + constraint + "\"MUSIC_BEAN\" (" + //
            "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
            "\"SONGNAME\" TEXT," + // 1: songname
            "\"SECONDS\" INTEGER NOT NULL ," + // 2: seconds
            "\"ALBUMMID\" TEXT," + // 3: albummid
            "\"SONGID\" INTEGER NOT NULL ," + // 4: songid
            "\"SINGERID\" INTEGER NOT NULL ," + // 5: singerid
            "\"ALBUMPIC_BIG\" TEXT," + // 6: albumpic_big
            "\"ALBUMPIC_SMALL\" TEXT," + // 7: albumpic_small
            "\"DOWN_URL\" TEXT," + // 8: downUrl
            "\"URL\" TEXT," + // 9: url
            "\"SINGERNAME\" TEXT," + // 10: singername
            "\"ALBUMID\" INTEGER NOT NULL ," + // 11: albumid
            "\"TYPE\" INTEGER NOT NULL ," + // 12: type
            "\"IS_COLLECTED\" INTEGER NOT NULL );"); // 13: isCollected
}
 
开发者ID:popo1379,项目名称:popomusic,代码行数:20,代码来源:MusicBeanDao.java

示例4: getColumns

import org.greenrobot.greendao.database.Database; //导入依赖的package包/类
/**
 * 获取表列名集合
 **/
private static List<String> getColumns(Database db, String tableName) {
    List<String> columns = new ArrayList<>();
    Cursor cursor = null;
    try {
        cursor = db.rawQuery("SELECT * FROM " + tableName + " limit 1", null);
        if (cursor != null) {
            columns = new ArrayList<>(Arrays.asList(cursor.getColumnNames()));
        }
    } catch (Exception e) {
        Log.v(tableName, e.getMessage());
        e.printStackTrace();
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return columns;
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:21,代码来源:MigrationHelper.java

示例5: transferBookmarksAndTraceData

import org.greenrobot.greendao.database.Database; //导入依赖的package包/类
private void transferBookmarksAndTraceData(Database db){
    DaoSession daoSession = new DaoMaster(db).newSession();
    List<TraceRepo> traceRepoList = daoSession.getTraceRepoDao().loadAll();
    List<TraceUser> traceUserList = daoSession.getTraceUserDao().loadAll();
    List<BookMarkRepo> bookmarkRepoList = daoSession.getBookMarkRepoDao().loadAll();
    List<BookMarkUser> bookMarkUserList = daoSession.getBookMarkUserDao().loadAll();

    List<LocalRepo> localRepoList = getLocalRepoList(traceRepoList, bookmarkRepoList);
    List<LocalUser> localUserList = getLocalUserList(traceUserList, bookMarkUserList);
    List<Trace> traceList = getTraceList(traceRepoList, traceUserList);
    List<Bookmark> bookmarkList = getBookmarkList(bookmarkRepoList, bookMarkUserList);

    daoSession.getLocalRepoDao().insertInTx(localRepoList);
    daoSession.getLocalUserDao().insertInTx(localUserList);
    daoSession.getTraceDao().insertInTx(traceList);
    daoSession.getBookmarkDao().insertInTx(bookmarkList);

    daoSession.clear();
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:20,代码来源:DBOpenHelper.java

示例6: createTable

import org.greenrobot.greendao.database.Database; //导入依赖的package包/类
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
    String constraint = ifNotExists? "IF NOT EXISTS ": "";
    db.execSQL("CREATE TABLE " + constraint + "\"BOOK_MARK_REPO\" (" + //
            "\"ID\" INTEGER PRIMARY KEY NOT NULL ," + // 0: id
            "\"NAME\" TEXT NOT NULL ," + // 1: name
            "\"DESCRIPTION\" TEXT," + // 2: description
            "\"LANGUAGE\" TEXT," + // 3: language
            "\"STARGAZERS_COUNT\" INTEGER," + // 4: stargazersCount
            "\"WATCHERS_COUNT\" INTEGER," + // 5: watchersCount
            "\"FORKS_COUNT\" INTEGER," + // 6: forksCount
            "\"FORK\" INTEGER," + // 7: fork
            "\"OWNER_LOGIN\" TEXT," + // 8: ownerLogin
            "\"OWNER_AVATAR_URL\" TEXT," + // 9: ownerAvatarUrl
            "\"MARK_TIME\" INTEGER);"); // 10: markTime
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:17,代码来源:BookMarkRepoDao.java

示例7: DaoSession

import org.greenrobot.greendao.database.Database; //导入依赖的package包/类
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
        daoConfigMap) {
    super(db);

    bpmDaoConfig = daoConfigMap.get(BpmDao.class).clone();
    bpmDaoConfig.initIdentityScope(type);

    sMSDaoConfig = daoConfigMap.get(SMSDao.class).clone();
    sMSDaoConfig.initIdentityScope(type);

    bpmDao = new BpmDao(bpmDaoConfig, this);
    sMSDao = new SMSDao(sMSDaoConfig, this);

    registerDao(Bpm.class, bpmDao);
    registerDao(SMS.class, sMSDao);
}
 
开发者ID:InnoFang,项目名称:FamilyBond,代码行数:17,代码来源:DaoSession.java

示例8: generateTempTables

import org.greenrobot.greendao.database.Database; //导入依赖的package包/类
/**
 * 生成临时表,存储旧的表数据
 * @param db
 * @param daoClasses
 */
private static void generateTempTables(Database db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    //方法2
    for (int i=0;i<daoClasses.length;i++){
        DaoConfig daoConfig = new DaoConfig(db,daoClasses[i]);
        String tableName = daoConfig.tablename;
        if (!checkTable(db,tableName))
            continue;
        String tempTableName = daoConfig.tablename.concat("_TEMP");
        StringBuilder insertTableStringBuilder = new StringBuilder();
        insertTableStringBuilder.append("alter table ")
                .append(tableName)
                .append(" rename to ")
                .append(tempTableName)
                .append(";");
        db.execSQL(insertTableStringBuilder.toString());
    }
}
 
开发者ID:yzzslow0,项目名称:Ec2m,代码行数:23,代码来源:MigrationHelper.java

示例9: createTable

import org.greenrobot.greendao.database.Database; //导入依赖的package包/类
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
    String constraint = ifNotExists? "IF NOT EXISTS ": "";
    db.execSQL("CREATE TABLE " + constraint + "\"tangshi\" (" + //
            "\"_id\" INTEGER PRIMARY KEY ," + // 0: id
            "\"AUTHOR\" TEXT," + // 1: author
            "\"TITLE\" TEXT," + // 2: title
            "\"STRAINS\" TEXT," + // 3: strains
            "\"PARAGRAPHS\" TEXT," + // 4: paragraphs
            "\"PYQUANY\" TEXT," + // 5: pyquany
            "\"PYJIAN\" TEXT," + // 6: pyjian
            "\"AUTHORJT\" TEXT," + // 7: authorjt
            "\"PYQUAN\" TEXT);"); // 8: pyquan
    // Add Indexes
    db.execSQL("CREATE UNIQUE INDEX " + constraint + "IDX_tangshi_AUTHOR_TITLE_STRAINS ON tangshi" +
            " (\"AUTHOR\" ASC,\"TITLE\" ASC,\"STRAINS\" ASC);");
}
 
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:18,代码来源:TangshiDao.java

示例10: getColumns

import org.greenrobot.greendao.database.Database; //导入依赖的package包/类
private List<String> getColumns(Database db, String tableName) {
    List<String> columns = new ArrayList<>();
    Cursor cursor = null;
    try {
        cursor = db.rawQuery("SELECT * FROM " + tableName + " limit 1", null);
        if (cursor != null) {
            columns = new ArrayList<>(Arrays.asList(cursor.getColumnNames()));
        }
    } catch (Exception e) {
        Log.v(tableName, e.getMessage(), e);
        e.printStackTrace();
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return columns;
}
 
开发者ID:newbiechen1024,项目名称:NovelReader,代码行数:18,代码来源:MigrationHelper.java

示例11: initDatabase

import org.greenrobot.greendao.database.Database; //导入依赖的package包/类
/**
 * 初始化greenDao,这个操作建议在Application初始化的时候添加;
 */
public static void initDatabase(Context context) {
    if (mDaoSession != null) {
        return;
    }
    if (context == null) {
        throw new IllegalArgumentException("You cannot start a load on a null Context");
    }
    DatabaseOpenHelper mHelper;
    mHelper = new DaoMaster.DevOpenHelper(context.getApplicationContext(), DB_NAME);
   /* if (BuildConfig.DEBUG) {
        mHelper = new DaoMaster.DevOpenHelper(context.getApplicationContext(), DB_NAME);
    } else {
        mHelper = new MySQLiteOpenHelper(context.getApplicationContext(), DB_NAME);
    }*/
    Database db = mHelper.getWritableDb();
    DaoMaster mDaoMaster = new DaoMaster(db);
    mDaoSession = mDaoMaster.newSession();
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:22,代码来源:DBRepository.java

示例12: migrate

import org.greenrobot.greendao.database.Database; //导入依赖的package包/类
/**
 * 数据迁移
 *
 * @param db
 * @param daoClasses
 */
public void migrate(SQLiteDatabase db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    Database database = new StandardDatabase(db);

    logger.log("The Old Database Version " + db.getVersion());
    logger.log("Generate temp table start.");
    generateTempTables(database, daoClasses);
    logger.log("Generate temp table complete.");

    dropAllTables(database, true, daoClasses);
    createAllTables(database, false, daoClasses);

    logger.log("Restore data start.");
    restoreData(database, daoClasses);
    logger.log("Restore data complete.");
}
 
开发者ID:RockyQu,项目名称:MVVMFrames,代码行数:22,代码来源:MigrationHelper.java

示例13: onUpgrade

import org.greenrobot.greendao.database.Database; //导入依赖的package包/类
@Override
public void onUpgrade(Database db, int oldVersion, int newVersion) {
    super.onUpgrade(db, oldVersion, newVersion);
    AppLogger.d("DEBUG", "DB_OLD_VERSION : " + oldVersion + ", DB_NEW_VERSION : " + newVersion);
    switch (oldVersion) {
        case 1:
        case 2:
            //db.execSQL("ALTER TABLE " + UserDao.TABLENAME + " ADD COLUMN "
            // + UserDao.Properties.Name.columnName + " TEXT DEFAULT 'DEFAULT_VAL'");
    }
}
 
开发者ID:MindorksOpenSource,项目名称:android-mvp-architecture,代码行数:12,代码来源:DbOpenHelper.java

示例14: onUpgrade

import org.greenrobot.greendao.database.Database; //导入依赖的package包/类
@Override
public void onUpgrade(Database db, int oldVersion, int newVersion) {
    if(oldVersion == 2 && newVersion == 3){
        //create new table, keep ori
        TraceUserDao.createTable(db, false);
        TraceRepoDao.createTable(db, false);
        BookMarkUserDao.createTable(db, false);
        BookMarkRepoDao.createTable(db, false);
    } else if(oldVersion == 3 && newVersion == 4){
        //create new table
        LocalUserDao.createTable(db, false);
        LocalRepoDao.createTable(db, false);
        TraceDao.createTable(db, false);
        BookmarkDao.createTable(db, false);

        //transfer data from ori
        transferBookmarksAndTraceData(db);

        //drop old tables
        TraceUserDao.dropTable(db, true);
        TraceRepoDao.dropTable(db, true);
        BookMarkUserDao.dropTable(db, true);
        BookMarkRepoDao.dropTable(db, true);
    } else if(oldVersion == 4 && newVersion == 5){
        MyTrendingLanguageDao.createTable(db, true);
    } else {
        super.onUpgrade(db, oldVersion, newVersion);
    }
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:30,代码来源:DBOpenHelper.java

示例15: setUpClass

import org.greenrobot.greendao.database.Database; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() {
    DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(InstrumentationRegistry.getTargetContext(), "wulkanowyTest-db");
    Database database = devOpenHelper.getWritableDb();
    daoSession = new DaoMaster(database).newSession();

    DaoMaster.dropAllTables(database, true);
    DaoMaster.createAllTables(database, true);
}
 
开发者ID:wulkanowy,项目名称:wulkanowy,代码行数:10,代码来源:FirstAccountLoginTest.java


注:本文中的org.greenrobot.greendao.database.Database类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。