当前位置: 首页>>代码示例>>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;未经允许,请勿转载。