當前位置: 首頁>>代碼示例>>Java>>正文


Java Dao類代碼示例

本文整理匯總了Java中com.j256.ormlite.dao.Dao的典型用法代碼示例。如果您正苦於以下問題:Java Dao類的具體用法?Java Dao怎麽用?Java Dao使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Dao類屬於com.j256.ormlite.dao包,在下文中一共展示了Dao類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDao

import com.j256.ormlite.dao.Dao; //導入依賴的package包/類
public synchronized Dao getDao(Class clazz) throws SQLException
{
    Dao dao = null;
    String className = clazz.getSimpleName();

    if (daos.containsKey(className))
    {
        dao = daos.get(className);
    }
    if (dao == null)
    {
        dao = super.getDao(clazz);
        daos.put(className, dao);
    }
    return dao;
}
 
開發者ID:li-xiaojun,項目名稱:OkhttpDownloader,代碼行數:17,代碼來源:DBHelper.java

示例2: save

import com.j256.ormlite.dao.Dao; //導入依賴的package包/類
/**
 * Saves the user data to the database.
 *
 * @param data The user data to save.
 */
private static void save(UserData data) {
    data.setAvatarUrl(data.getAvatarUrl());
    data.setUsername(data.getUsername());

    ZLevels.async.submit(() -> {
        try {
            ConnectionSource source = Database.openConnection();
            if (source == null) return;

            Dao<UserData, String> db = DaoManager.createDao(source, UserData.class);
            db.createOrUpdate(data);
            Database.closeConnection();
        } catch (Exception e) {
            ZLogger.warn("Could not save UserData for " + data.getUserId() + "!");
            e.printStackTrace();
        }
    });
}
 
開發者ID:ZP4RKER,項目名稱:zlevels,代碼行數:24,代碼來源:UserData.java

示例3: delete

import com.j256.ormlite.dao.Dao; //導入依賴的package包/類
/**
 * Deletes this user data from the database and cache.
 */
public void delete() {
    UserData current = this;

    if (cache.containsKey(current.getUserId())) cache.remove(current.getUserId());

    ZLevels.async.submit(() -> {
        try {
            ConnectionSource source = Database.openConnection();
            if (source == null) return;

            Dao<UserData, String> db = DaoManager.createDao(source, UserData.class);

            db.delete(current);

            Database.closeConnection();
        } catch (Exception e) {
            ZLogger.warn("Colud not delete UserData for " + getUserId() + "!");
            e.printStackTrace();
        }
    });
}
 
開發者ID:ZP4RKER,項目名稱:zlevels,代碼行數:25,代碼來源:UserData.java

示例4: fromId

import com.j256.ormlite.dao.Dao; //導入依賴的package包/類
/**
 * Gets the user data by userId from the cache and database.
 *
 * @param userId The user id.
 * @return The user data.
 */
public static UserData fromId(String userId) {
    if (cache.containsKey(userId)) {
        return cache.get(userId);
    }
    try {
        ConnectionSource source = Database.openConnection();
        if (source == null) return null;

        Dao<UserData, String> db = DaoManager.createDao(source, UserData.class);

        UserData data = db.queryForEq("userId", userId).get(0);

        Database.closeConnection();

        return data;
    } catch (Exception e) {
        if (e instanceof IndexOutOfBoundsException) {
            return null;
        }

        ZLogger.warn("Could not get UserData for " + userId + "!");
        e.printStackTrace();
        return null;
    }
}
 
開發者ID:ZP4RKER,項目名稱:zlevels,代碼行數:32,代碼來源:UserData.java

示例5: lastBg

import com.j256.ormlite.dao.Dao; //導入依賴的package包/類
@Nullable
public static BgReading lastBg() {
    List<BgReading> bgList = null;

    try {
        Dao<BgReading, Long> daoBgReadings = MainApp.getDbHelper().getDaoBgReadings();
        QueryBuilder<BgReading, Long> queryBuilder = daoBgReadings.queryBuilder();
        queryBuilder.orderBy("date", false);
        queryBuilder.limit(1L);
        queryBuilder.where().gt("value", 38);
        PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
        bgList = daoBgReadings.query(preparedQuery);

    } catch (SQLException e) {
        log.debug(e.getMessage(), e);
    }
    if (bgList != null && bgList.size() > 0)
        return bgList.get(0);
    else
        return null;
}
 
開發者ID:MilosKozak,項目名稱:AndroidAPS,代碼行數:22,代碼來源:DatabaseHelper.java

示例6: checkSuspectedApps

import com.j256.ormlite.dao.Dao; //導入依賴的package包/類
protected boolean checkSuspectedApps(String packageName) {
    boolean matched = true;
    if (!_settings.isAdvancedMode()) {
        try {
            Dao<SuspectedApp, Integer> suspectedAppDao = DatabaseHelper.getHelper(_context.getApplicationContext()).getSuspectedAppDao();
            List<SuspectedApp> res = suspectedAppDao.queryForEq("packageName", packageName);
            if (res.size() == 0) {
                Log.i(TAG, String.format("Skipping %s since not in suspected app list and is probably a FP", packageName));
                matched = false;
            } else {
                Log.d(TAG, String.format("Process %s found in suspected apps", packageName));
                matched = true;
            }
        } catch (SQLException e) {
            Log.e(TAG, String.format("SQL exception: %s", e.getMessage()));
            matched = false;
        }
    }
    return matched;
}
 
開發者ID:geeksonsecurity,項目名稱:android-overlay-protection,代碼行數:21,代碼來源:AbstractDetectionEngine.java

示例7: getDao

import com.j256.ormlite.dao.Dao; //導入依賴的package包/類
/**
 * This method obtains a DAO given its Class
 * <p/>
 * Source: https://goo.gl/6LIYy2
 *
 * @param clazz
 *         The DAO class
 * @param <D>
 *         DAO super class
 * @param <T>
 *         Requested DAO class
 *
 * @return The DAO instance
 *
 * @throws SQLException
 */
public <D extends Dao<T, ?>, T> D getDao(Class<T> clazz) throws SQLException {
  // lookup the dao, possibly invoking the cached database config
  Dao<T, ?> dao = DaoManager.lookupDao(connectionSource, clazz);
  if (dao == null) {
    // try to use our new reflection magic
    DatabaseTableConfig<T> tableConfig = DatabaseTableConfigUtil
            .fromClass(connectionSource, clazz);
    if (tableConfig == null) {
      /**
       * Note: We have to do this to get to see if they are using the deprecated
       * annotations like
       * {@link DatabaseFieldSimple}.
       */
      dao = (Dao<T, ?>) DaoManager.createDao(connectionSource, clazz);
    } else {
      dao = (Dao<T, ?>) DaoManager.createDao(connectionSource, tableConfig);
    }
  }

  @SuppressWarnings("unchecked")
  D castDao = (D) dao;
  return castDao;
}
 
開發者ID:aajn88,項目名稱:wakemeapp,代碼行數:40,代碼來源:DatabaseHelper.java

示例8: getTemptargetsDataFromTime

import com.j256.ormlite.dao.Dao; //導入依賴的package包/類
public List<TempTarget> getTemptargetsDataFromTime(long mills, boolean ascending) {
    try {
        Dao<TempTarget, Long> daoTempTargets = getDaoTempTargets();
        List<TempTarget> tempTargets;
        QueryBuilder<TempTarget, Long> queryBuilder = daoTempTargets.queryBuilder();
        queryBuilder.orderBy("date", ascending);
        Where where = queryBuilder.where();
        where.ge("date", mills);
        PreparedQuery<TempTarget> preparedQuery = queryBuilder.prepare();
        tempTargets = daoTempTargets.query(preparedQuery);
        return tempTargets;
    } catch (SQLException e) {
        log.error("Unhandled exception", e);
    }
    return new ArrayList<TempTarget>();
}
 
開發者ID:MilosKozak,項目名稱:AndroidAPS,代碼行數:17,代碼來源:DatabaseHelper.java

示例9: onCreate

import com.j256.ormlite.dao.Dao; //導入依賴的package包/類
@Override
    public void onCreate() {
        super.onCreate();
//        This is here because onStart is not called when BIND_AUTO_CREATE is used
        mContext = this;
        localBroadcastManager = LocalBroadcastManager.getInstance(this);
        final OrmHandler ormHandler = OpenHelperManager.getHelper(this, OrmHandler.class);
        Dao<Track, String> dbTrack;
        try {
            dbTrack = ormHandler.getDao(Track.class);
            mTrackList = dbTrack.queryForAll();
            mBucketList = dbTrack.queryForEq("bucket", true);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
 
開發者ID:Circle-Of-Music-Makers,項目名稱:com-android,代碼行數:17,代碼來源:MusicPlayerService.java

示例10: findTreatmentById

import com.j256.ormlite.dao.Dao; //導入依賴的package包/類
@Nullable
public Treatment findTreatmentById(String _id) {
    try {
        Dao<Treatment, Long> daoTreatments = getDaoTreatments();
        QueryBuilder<Treatment, Long> queryBuilder = daoTreatments.queryBuilder();
        Where where = queryBuilder.where();
        where.eq("_id", _id);
        queryBuilder.limit(10L);
        PreparedQuery<Treatment> preparedQuery = queryBuilder.prepare();
        List<Treatment> trList = daoTreatments.query(preparedQuery);
        if (trList.size() != 1) {
            //log.debug("Treatment findTreatmentById query size: " + trList.size());
            return null;
        } else {
            //log.debug("Treatment findTreatmentById found: " + trList.get(0).log());
            return trList.get(0);
        }
    } catch (SQLException e) {
        log.error("Unhandled exception", e);
    }
    return null;
}
 
開發者ID:MilosKozak,項目名稱:AndroidAPS,代碼行數:23,代碼來源:DatabaseHelper.java

示例11: getDao

import com.j256.ormlite.dao.Dao; //導入依賴的package包/類
/**
 * 獲取dao
 *
 * @param cls 表結構bean
 * @return
 */
public synchronized Dao getDao(Class cls) {
    Dao dao;
    String clsName = cls.getSimpleName();
    if (daoMap.containsKey(clsName)) {
        dao = daoMap.get(clsName);
    } else {
        try {
            dao = super.getDao(cls);
        } catch (SQLException e) {
            LogUtils.e("database operate fail", e);
            return null;
        }
        daoMap.put(clsName, dao);
    }
    return dao;
}
 
開發者ID:lujianzhao,項目名稱:AndroidBase,代碼行數:23,代碼來源:OrmLiteDatabaseHelper.java

示例12: doInBackground

import com.j256.ormlite.dao.Dao; //導入依賴的package包/類
@Override
protected Void doInBackground(Void... voids) {
    ArrayList<Track> mTrackList = Utils.musicLoader(mContext);
    OrmHandler ormHandler = OpenHelperManager.getHelper(mContext, OrmHandler.class);
    try {
        Dao<Track, String> dbTrack = ormHandler.getDao(Track.class);
        List<Track> _temp = dbTrack.queryForAll();
        _temp.removeAll(mTrackList);
        for (Track t :
                mTrackList) {
            dbTrack.createIfNotExists(t);
        }
        dbTrack.delete(_temp);
    } catch (SQLException e) {
        e.printStackTrace();
    }
    OpenHelperManager.releaseHelper();
    return null;
}
 
開發者ID:Circle-Of-Music-Makers,項目名稱:com-android,代碼行數:20,代碼來源:DatabaseSynchronization.java

示例13: bucketOps

import com.j256.ormlite.dao.Dao; //導入依賴的package包/類
public static void bucketOps(String path, Boolean bucket, Context mContext) {
    final OrmHandler ormHandler = OpenHelperManager.getHelper(mContext, OrmHandler.class);
    try {
        Dao<Track, String> dbTrack = ormHandler.getDao(Track.class);
        QueryBuilder<Track, String> queryBuilder = dbTrack.queryBuilder();
        SelectArg selectArg = new SelectArg();
        queryBuilder.where().eq("path", selectArg);
        PreparedQuery<Track> preparedQuery = queryBuilder.prepare();
        selectArg.setValue(path);
        List<Track> lister = dbTrack.query(preparedQuery);
        Track temp_track = lister.get(0);
        temp_track.setBucket(bucket);
        dbTrack.update(temp_track);
        BUCKET_OPS = true;
    } catch (SQLException | IndexOutOfBoundsException e) {
        e.printStackTrace();
    }
}
 
開發者ID:Circle-Of-Music-Makers,項目名稱:com-android,代碼行數:19,代碼來源:Utils.java

示例14: createAdapter

import com.j256.ormlite.dao.Dao; //導入依賴的package包/類
/**
 * Creates appropriate adapter for the specified action.
 * @param removeActionDao   content removal action DAO
 * @param action            removal action
 * @return  {@linkplain RemoveContentActionSyncAdapter} instance.
 */
public static RemoveContentActionSyncAdapter createAdapter(
	Dao<UserActionCache.ContentRemovedAction, Integer> removeActionDao,
	UserActionCache.ContentRemovedAction action) {

	INetworkOperation operation;

	switch (action.getContentType()) {
		case COMMENT:
			operation = (service) -> service.removeComment(new RemoveCommentRequest(action.getContentHandle()));
			break;

		case REPLY:
			operation = (service) -> service.removeReply(new RemoveReplyRequest(action.getContentHandle()));
			break;

		case TOPIC:
		default:
			operation = (service) -> service.removeTopic(new RemoveTopicRequest(action.getContentHandle()));
	}

	return new RemoveContentActionSyncAdapter(removeActionDao, action, operation);
}
 
開發者ID:Microsoft,項目名稱:EmbeddedSocial-Android-SDK,代碼行數:29,代碼來源:RemoveContentActionSyncAdapter.java

示例15: getCachedDao

import com.j256.ormlite.dao.Dao; //導入依賴的package包/類
public <D extends Dao<T, ?>, T> D getCachedDao(Class<T> clazz) {
    Dao dao = daoCacheMap.get(clazz);
    if (dao == null) {
        try {
            dao = this.getDao(clazz);
        } catch (Exception e) {
            e.printStackTrace();
        }
        daoCacheMap.put(clazz, dao);
    }
    return (D) dao;
}
 
開發者ID:aliyun,項目名稱:aliyun-cloudphotos-android-demo,代碼行數:13,代碼來源:DatabaseHelper.java


注:本文中的com.j256.ormlite.dao.Dao類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。