Java Code Examples for com.j256.ormlite.dao.RuntimeExceptionDao#create()

The following examples show how to use com.j256.ormlite.dao.RuntimeExceptionDao#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserDatabaseHelper.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
/**
 * 数据初始化
 */
private void initDatabase()
{
	RuntimeExceptionDao<FocusItemInfo, Long> koItemInfoDao = getFocusItemInfoDao();
	int length = BusinessData.LOCAL_ALBUM_FOCUS.length;
	int itemCount = BusinessData.LOCAL_ALBUM_FOCUS[0].length;
	
	FocusItemInfo itemInfo = null;
	for (int i = 0; i < length; i++)
	{
		itemInfo = new FocusItemInfo();
		itemInfo.setData(BusinessData.LOCAL_ALBUM_FOCUS[i][0]);
		itemInfo.setBucket_display_name(BusinessData.LOCAL_ALBUM_FOCUS[i][1]);
		itemInfo.setBeautiful_name(BusinessData.LOCAL_ALBUM_FOCUS[i][2]);
		itemInfo.setIcon(BusinessData.LOCAL_ALBUM_FOCUS[i][3]);
		
		itemInfo.setSystem(true);
		// 系统自带索引1000开始, 用户添加的应当排在最前面.
		itemInfo.setOrder_by(1000 + i);
		
		koItemInfoDao.create(itemInfo);
	}
}
 
Example 2
Source File: DatabaseHelper.java    From ormlite-android-gradle-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * This is called when the database is first created. Usually you should call createTable statements here to create
 * the tables that will store your data.
 */
@Override
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);
    }

    // here we try inserting data in the on-create as a test
    RuntimeExceptionDao<SimpleData, Integer> dao = getSimpleDataDao();
    long millis = System.currentTimeMillis();
    // create some entries in the onCreate
    SimpleData simple = new SimpleData(millis);
    dao.create(simple);
    simple = new SimpleData(millis + 1);
    dao.create(simple);
    Log.i(DatabaseHelper.class.getName(), "created new entries in onCreate: " + millis);
}
 
Example 3
Source File: UserDatabaseHelper.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
/**
 * 数据初始化
 */
private void initDatabase_BAK()
{
	RuntimeExceptionDao<FocusItemInfo, Long> koItemInfoDao = getFocusItemInfoDao();
	int length = BusinessData.LOCAL_FOCUS_PARENT_DIRECTORY.length;
	int itemCount = BusinessData.LOCAL_FOCUS_PARENT_DIRECTORY[0].length;

	String sdcard_root = null;

	if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
	{
		File sdcard_dir = Environment.getExternalStorageDirectory();
		sdcard_root = sdcard_dir.getPath();
	}
	
	FocusItemInfo itemInfo = null;
	for (int i = 0; i < length; i++)
	{
		itemInfo = new FocusItemInfo();
		itemInfo.setData(sdcard_root + BusinessData.LOCAL_ALBUM_FOCUS[i][0]);
		itemInfo.setBucket_display_name(BusinessData.LOCAL_ALBUM_FOCUS[i][1]);
		itemInfo.setBeautiful_name(BusinessData.LOCAL_ALBUM_FOCUS[i][1]);
		itemInfo.setIcon(BusinessData.LOCAL_ALBUM_FOCUS[i][2]);

		itemInfo.setSystem(true);
		// 系统自带索引1000开始, 用户添加的应当排在最前面.
		itemInfo.setOrder_by(1000 + i);

		koItemInfoDao.create(itemInfo);
	}
}