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


Java SelectArg.setValue方法代码示例

本文整理汇总了Java中com.j256.ormlite.stmt.SelectArg.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java SelectArg.setValue方法的具体用法?Java SelectArg.setValue怎么用?Java SelectArg.setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.j256.ormlite.stmt.SelectArg的用法示例。


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

示例1: getTag

import com.j256.ormlite.stmt.SelectArg; //导入方法依赖的package包/类
public Tag getTag(final String aTag) {
    try {
        QueryBuilder<Tag, Long> queryBuilder = dbHelper.getTagDao().queryBuilder();
        Where<Tag, Long> where = queryBuilder.where();
        SelectArg selectArg = new SelectArg();

        // define our query as 'name = ?'
        where.eq(Tag.COLUMN_NAME_TITLE, selectArg);

        // prepare it so it is ready for later query or iterator calls
        PreparedQuery<Tag> preparedQuery = queryBuilder.prepare();

        // later we can set the select argument and issue the query
        selectArg.setValue(aTag);
        List<Tag> tgs = dbHelper.getTagDao().query(preparedQuery);
        if (!tgs.isEmpty()) {
            return tgs.get(0);
        }
    } catch (java.sql.SQLException pE) {
        pE.printStackTrace();
    }
    return null;
}
 
开发者ID:mrspaceman,项目名称:ebookmgr,代码行数:24,代码来源:LibraryManager.java

示例2: getBook

import com.j256.ormlite.stmt.SelectArg; //导入方法依赖的package包/类
public EBook getBook(final String fullFilename) {
    EBook ebk = null;
    try {
        QueryBuilder<EBook, Long> queryBuilder = dbHelper.getEBookDao().queryBuilder();
        Where<EBook, Long> where = queryBuilder.where();
        SelectArg selectArg = new SelectArg();

        // define our query as 'name = ?'
        where.eq(EBook.COLUMN_FULL_FILE_NAME, selectArg);

        // prepare it so it is ready for later query or iterator calls
        PreparedQuery<EBook> preparedQuery = queryBuilder.prepare();

        // later we can set the select argument and issue the query
        selectArg.setValue(fullFilename);
        List<EBook> result = dbHelper.getEBookDao().query(preparedQuery);

        if (result.size() > 0) {
            ebk = result.get(0);
        }
    } catch (java.sql.SQLException pE) {
        BookLibApplication.getInstance().e("Exception reading ebooks", pE);
    }
    return ebk;
}
 
开发者ID:mrspaceman,项目名称:ebookmgr,代码行数:26,代码来源:LibraryManager.java

示例3: getFileType

import com.j256.ormlite.stmt.SelectArg; //导入方法依赖的package包/类
public FileType getFileType(final String aFileType) {
    try {
        QueryBuilder<FileType, Long> queryBuilder = dbHelper.getFileTypeDao().queryBuilder();
        Where<FileType, Long> where = queryBuilder.where();
        SelectArg selectArg = new SelectArg();

        // define our query as 'name = ?'
        where.eq(FileType.COLUMN_NAME_TITLE, selectArg);

        // prepare it so it is ready for later query or iterator calls
        PreparedQuery<FileType> preparedQuery = queryBuilder.prepare();

        // later we can set the select argument and issue the query
        selectArg.setValue(aFileType);
        List<FileType> tgs = dbHelper.getFileTypeDao().query(preparedQuery);
        if (!tgs.isEmpty()) {
            return tgs.get(0);
        }
    } catch (java.sql.SQLException pE) {
        pE.printStackTrace();
    }
    return null;
}
 
开发者ID:mrspaceman,项目名称:ebookmgr,代码行数:24,代码来源:LibraryManager.java

示例4: getAuthor

import com.j256.ormlite.stmt.SelectArg; //导入方法依赖的package包/类
public Author getAuthor(final String pFirstname, final String pLastname) {
    try {
        QueryBuilder<Author, Long> queryBuilder = dbHelper.getAuthorDao().queryBuilder();
        Where<Author, Long> where = queryBuilder.where();
        SelectArg selectArg = new SelectArg();

        // define our query as 'name = ?'
        where.eq(Author.COLUMN_NAME_FIRSTNAME, selectArg);

        // prepare it so it is ready for later query or iterator calls
        PreparedQuery<Author> preparedQuery = queryBuilder.prepare();

        // later we can set the select argument and issue the query
        selectArg.setValue(pFirstname);
        List<Author> tgs = dbHelper.getAuthorDao().query(preparedQuery);
        if (!tgs.isEmpty()) {
            return tgs.get(0);
        }
    } catch (java.sql.SQLException pE) {
        pE.printStackTrace();
    }
    return null;
}
 
开发者ID:mrspaceman,项目名称:ebookmgr,代码行数:24,代码来源:LibraryManager.java

示例5: searchBooksMatching

import com.j256.ormlite.stmt.SelectArg; //导入方法依赖的package包/类
public List<EBook> searchBooksMatching(final String searchStr) {
    List<EBook> result = new ArrayList<>();
    try {
        QueryBuilder<EBook, Long> queryBuilder = dbHelper.getEBookDao().queryBuilder();
        Where<EBook, Long> where = queryBuilder.where();
        SelectArg selectArg2 = new SelectArg();
        selectArg2.setValue("%" + searchStr + "%");
        SelectArg selectArg1 = new SelectArg();
        selectArg1.setValue("%" + searchStr + "%");

        // define our query as 'name = ?'
        where.like(EBook.COLUMN_FULL_FILE_NAME, selectArg1).or()
                .like(EBook.COLUMN_BOOK_TITLE, selectArg2);

        // prepare it so it is ready for later query or iterator calls
        PreparedQuery<EBook> preparedQuery = queryBuilder.prepare();

        // later we can set the select argument and issue the query
        result = dbHelper.getEBookDao().query(preparedQuery);
    } catch (SQLException pE) {
        pE.printStackTrace();
    }

    return result;
}
 
开发者ID:mrspaceman,项目名称:ebookmgr,代码行数:26,代码来源:LibraryManager.java

示例6: bucketOps

import com.j256.ormlite.stmt.SelectArg; //导入方法依赖的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

示例7: getPreparedQuery

import com.j256.ormlite.stmt.SelectArg; //导入方法依赖的package包/类
protected PreparedQuery<T> getPreparedQuery()
{
  if (this.dao == null)
    return null;
  if (this.preparedQuery == null)
  {
    SelectArg localSelectArg = new SelectArg();
    localSelectArg.setValue(this.parentId);
    QueryBuilder localQueryBuilder = this.dao.queryBuilder();
    if (this.orderColumn != null)
      localQueryBuilder.orderBy(this.orderColumn, this.orderAscending);
    this.preparedQuery = localQueryBuilder.where().eq(this.foreignFieldType.getColumnName(), localSelectArg).prepare();
    if ((this.preparedQuery instanceof MappedPreparedStmt))
      ((MappedPreparedStmt)this.preparedQuery).setParentInformation(this.parent, this.parentId);
  }
  return this.preparedQuery;
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:18,代码来源:BaseForeignCollection.java

示例8: checkQueryResult

import com.j256.ormlite.stmt.SelectArg; //导入方法依赖的package包/类
/**
 * Returns the object if the query failed or null otherwise.
 */
private boolean checkQueryResult(Dao<AllTypes, Integer> allDao, QueryBuilder<AllTypes, Integer> qb,
		AllTypes allTypes, String fieldName, Object value, boolean required) throws SQLException {
	qb.where().eq(fieldName, value);
	List<AllTypes> results = allDao.query(qb.prepare());
	if (required) {
		assertEquals(1, results.size());
		assertTrue(allDao.objectsEqual(allTypes, results.get(0)));
	} else if (results.size() == 1) {
		assertTrue(allDao.objectsEqual(allTypes, results.get(0)));
	} else {
		return false;
	}

	SelectArg selectArg = new SelectArg();
	qb.where().eq(fieldName, selectArg);
	selectArg.setValue(value);
	results = allDao.query(qb.prepare());
	assertEquals(1, results.size());
	assertTrue(allDao.objectsEqual(allTypes, results.get(0)));
	return true;
}
 
开发者ID:j256,项目名称:ormlite-jdbc,代码行数:25,代码来源:JdbcBaseDaoImplTest.java

示例9: getMemberIdFromMemberName

import com.j256.ormlite.stmt.SelectArg; //导入方法依赖的package包/类
protected long getMemberIdFromMemberName(String memberName, long groupId) {
    try {
        SelectArg selectArg = new SelectArg();
        selectArg.setValue(memberName);

        Member member = mDbHelper.getDaoEx(Member.class).queryBuilder()
                                   .where().eq(Member.Columns.NAME_COLUMN, selectArg).and()
                                           .eq(Member.Columns.GROUP_ID_COLUMN, groupId)
                                   .queryForFirst();
        if (member != null) {
            return member.getId();
        } else {
            return createMemberEntry(memberName, groupId);
        }
    } catch (SQLException e) {
        throw new android.database.SQLException(e.getMessage());
    }
}
 
开发者ID:peter-tackage,项目名称:open-secret-santa,代码行数:19,代码来源:DatabaseUpgrader.java

示例10: testSelectArgs

import com.j256.ormlite.stmt.SelectArg; //导入方法依赖的package包/类
public void testSelectArgs() throws Exception {
	Dao<Foo, String> fooDao = createTestData();
	QueryBuilder<Foo, String> qb = fooDao.queryBuilder();

	SelectArg idSelectArg = new SelectArg();
	qb.where().eq(Foo.ID_COLUMN_NAME, idSelectArg);
	PreparedQuery<Foo> preparedQuery = qb.prepare();

	idSelectArg.setValue(foo1.id);
	List<Foo> results = fooDao.query(preparedQuery);
	assertEquals(1, results.size());
	assertEquals(foo1, results.get(0));

	idSelectArg.setValue(foo2.id);
	results = fooDao.query(qb.prepare());
	assertEquals(1, results.size());
	assertEquals(foo2, results.get(0));
}
 
开发者ID:j256,项目名称:ormlite-android-tests,代码行数:19,代码来源:AndroidJdbcQueryBuilderTest.java

示例11: testBetweenSelectArg

import com.j256.ormlite.stmt.SelectArg; //导入方法依赖的package包/类
public void testBetweenSelectArg() throws Exception {
	Dao<Foo, String> fooDao = createTestData();
	QueryBuilder<Foo, String> qb = fooDao.queryBuilder();

	SelectArg lowSelectArg = new SelectArg();
	qb.where().between(Foo.VAL_COLUMN_NAME, lowSelectArg, HIGH_VAL);
	lowSelectArg.setValue(LOW_VAL);
	List<Foo> results = fooDao.query(qb.prepare());
	assertEquals(2, results.size());
	assertEquals(foo1, results.get(0));
	assertEquals(foo2, results.get(1));

	SelectArg highSelectArg = new SelectArg();
	lowSelectArg.setValue(LOW_VAL + 1);
	highSelectArg.setValue(HIGH_VAL);
	qb.where().between(Foo.VAL_COLUMN_NAME, lowSelectArg, highSelectArg);
	results = fooDao.query(qb.prepare());
	assertEquals(1, results.size());
	assertEquals(foo2, results.get(0));
}
 
开发者ID:j256,项目名称:ormlite-android-tests,代码行数:21,代码来源:AndroidJdbcQueryBuilderTest.java

示例12: getPreparedQuery

import com.j256.ormlite.stmt.SelectArg; //导入方法依赖的package包/类
protected PreparedQuery<T> getPreparedQuery() throws SQLException {
	if (dao == null) {
		return null;
	}
	if (preparedQuery == null) {
		SelectArg fieldArg = new SelectArg();
		fieldArg.setValue(parentId);
		QueryBuilder<T, ID> qb = dao.queryBuilder();
		if (orderColumn != null) {
			qb.orderBy(orderColumn, orderAscending);
		}
		preparedQuery = qb.where().eq(foreignFieldType.getColumnName(), fieldArg).prepare();
		if (preparedQuery instanceof MappedPreparedStmt) {
			@SuppressWarnings("unchecked")
			MappedPreparedStmt<T, Object> mappedStmt = ((MappedPreparedStmt<T, Object>) preparedQuery);
			mappedStmt.setParentInformation(parent, parentId);
		}
	}
	return preparedQuery;
}
 
开发者ID:j256,项目名称:ormlite-core,代码行数:21,代码来源:BaseForeignCollection.java

示例13: getEBookTag

import com.j256.ormlite.stmt.SelectArg; //导入方法依赖的package包/类
public EBookTags getEBookTag(final EBook ebk, final Tag tg) {
    try {
        QueryBuilder<EBookTags, Long> queryBuilder = dbHelper.getEBookTagsDao().queryBuilder();
        Where<EBookTags, Long> where = queryBuilder.where();
        SelectArg selectArgEbk = new SelectArg();
        SelectArg selectArgTg = new SelectArg();

        // define our query as 'name = ?'
        where.eq(EBookTags.COLUMN_NAME_BOOK_ID, selectArgEbk)
                .and()
                .eq(EBookTags.COLUMN_NAME_TAG_ID, selectArgTg);

        // prepare it so it is ready for later query or iterator calls
        PreparedQuery<EBookTags> preparedQuery = queryBuilder.prepare();

        // later we can set the select argument and issue the query
        selectArgEbk.setValue(ebk.getId());
        selectArgTg.setValue(tg.getId());
        List<EBookTags> tgs = dbHelper.getEBookTagsDao().query(preparedQuery);
        if (!tgs.isEmpty()) {
            return tgs.get(0);
        }
        return new EBookTags(ebk, tg);
    } catch (java.sql.SQLException pE) {
        pE.printStackTrace();
    }
    return null;
}
 
开发者ID:mrspaceman,项目名称:ebookmgr,代码行数:29,代码来源:LibraryManager.java

示例14: getCountry

import com.j256.ormlite.stmt.SelectArg; //导入方法依赖的package包/类
@Override
public Country getCountry(String countryName) {
    try {
        // Use SelectArg to ensure values are properly escaped
        // Refer - http://ormlite.com/javadoc/ormlite-core/doc-files/ormlite_3.html#index-select-arguments
        SelectArg selectArg = new SelectArg();
        selectArg.setValue(countryName);
        return dbHelper.getDaoEx(Country.class).queryBuilder().where()
                .like(Country.Columns.NAME_COLUMN, selectArg)
                .queryForFirst();
    } catch (java.sql.SQLException e) {
        throw new android.database.SQLException(e.getMessage());
    }
}
 
开发者ID:peter-tackage,项目名称:refuge,代码行数:15,代码来源:PersistentRefugeeDataStore.java

示例15: useSelectArgFeature

import com.j256.ormlite.stmt.SelectArg; //导入方法依赖的package包/类
/**
 * Example of created a query with a ? argument using the {@link SelectArg} object. You then can set the value of
 * this object at a later time.
 */
private void useSelectArgFeature() throws Exception {

	String name1 = "foo";
	String name2 = "bar";
	String name3 = "baz";
	assertEquals(1, accountDao.create(new Account(name1)));
	assertEquals(1, accountDao.create(new Account(name2)));
	assertEquals(1, accountDao.create(new Account(name3)));

	QueryBuilder<Account, Integer> statementBuilder = accountDao.queryBuilder();
	SelectArg selectArg = new SelectArg();
	// build a query with the WHERE clause set to 'name = ?'
	statementBuilder.where().like(Account.NAME_FIELD_NAME, selectArg);
	PreparedQuery<Account> preparedQuery = statementBuilder.prepare();

	// now we can set the select arg (?) and run the query
	selectArg.setValue(name1);
	List<Account> results = accountDao.query(preparedQuery);
	assertEquals("Should have found 1 account matching our query", 1, results.size());
	assertEquals(name1, results.get(0).getName());

	selectArg.setValue(name2);
	results = accountDao.query(preparedQuery);
	assertEquals("Should have found 1 account matching our query", 1, results.size());
	assertEquals(name2, results.get(0).getName());

	selectArg.setValue(name3);
	results = accountDao.query(preparedQuery);
	assertEquals("Should have found 1 account matching our query", 1, results.size());
	assertEquals(name3, results.get(0).getName());
}
 
开发者ID:j256,项目名称:ormlite-jdbc,代码行数:36,代码来源:SimpleMain.java


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