com.j256.ormlite.dao.GenericRawResults Java Examples

The following examples show how to use com.j256.ormlite.dao.GenericRawResults. 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: StatementExecutor.java    From ormlite-core with ISC License 6 votes vote down vote up
/**
 * Return a results object associated with an internal iterator is mapped by the user's rowMapper.
 */
public <UO> GenericRawResults<UO> queryRaw(ConnectionSource connectionSource, String query,
		RawRowMapper<UO> rowMapper, String[] arguments, ObjectCache objectCache) throws SQLException {
	logger.debug("executing raw query for: {}", query);
	if (arguments.length > 0) {
		// need to do the (Object) cast to force args to be a single object
		logger.trace("query arguments: {}", (Object) arguments);
	}
	DatabaseConnection connection = connectionSource.getReadOnlyConnection(tableInfo.getTableName());
	CompiledStatement compiledStatement = null;
	try {
		compiledStatement = connection.compileStatement(query, StatementType.SELECT, noFieldTypes,
				DatabaseConnection.DEFAULT_RESULT_FLAGS, false);
		assignStatementArguments(compiledStatement, arguments);
		RawResultsImpl<UO> rawResults = new RawResultsImpl<UO>(connectionSource, connection, query, String[].class,
				compiledStatement, new UserRawRowMapper<UO>(rowMapper, this), objectCache);
		compiledStatement = null;
		connection = null;
		return rawResults;
	} finally {
		IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
		if (connection != null) {
			connectionSource.releaseConnection(connection);
		}
	}
}
 
Example #2
Source File: EnumToStringTypeTest.java    From ormlite-core with ISC License 6 votes vote down vote up
@Test
public void testEnumToStringValue() throws Exception {
	Class<LocalEnumToString> clazz = LocalEnumToString.class;
	Dao<LocalEnumToString, Object> dao = createDao(clazz, true);
	LocalEnumToString foo = new LocalEnumToString();
	foo.ourEnum = OurEnum.SECOND;
	assertEquals(1, dao.create(foo));
	GenericRawResults<String[]> results = dao.queryRaw("select * from " + TABLE_NAME);
	CloseableIterator<String[]> iterator = results.closeableIterator();
	try {
		assertTrue(iterator.hasNext());
		String[] result = iterator.next();
		assertNotNull(result);
		assertEquals(1, result.length);
		assertFalse(OurEnum.SECOND.name().equals(result[0]));
		assertTrue(OurEnum.SECOND.toString().equals(result[0]));
	} finally {
		IOUtils.closeQuietly(iterator);
	}
}
 
Example #3
Source File: RawResultsImplTest.java    From ormlite-core with ISC License 6 votes vote down vote up
@Test
public void testCustomColumnNames() throws Exception {
	Dao<Foo, Integer> dao = createDao(Foo.class, true);
	Foo foo = new Foo();
	foo.val = 1213213;
	assertEquals(1, dao.create(foo));
	final String idName = "SOME_ID";
	final String valName = "SOME_VAL";
	final AtomicBoolean gotResult = new AtomicBoolean(false);
	GenericRawResults<Object> results =
			dao.queryRaw("select id as " + idName + ", val as " + valName + " from foo",
					new RawRowMapper<Object>() {
						@Override
						public Object mapRow(String[] columnNames, String[] resultColumns) {
							assertEquals(idName, columnNames[0]);
							assertEquals(valName, columnNames[1]);
							gotResult.set(true);
							return new Object();
						}
					});
	assertEquals(1, results.getResults().size());
	results.close();
	assertTrue(gotResult.get());
}
 
Example #4
Source File: RawResultsImplTest.java    From ormlite-core with ISC License 6 votes vote down vote up
@Test
public void testGetFirstResult() throws Exception {
	Dao<Foo, Integer> dao = createDao(Foo.class, true);
	Foo foo1 = new Foo();
	foo1.val = 342;
	assertEquals(1, dao.create(foo1));
	Foo foo2 = new Foo();
	foo2.val = 9045342;
	assertEquals(1, dao.create(foo2));

	QueryBuilder<Foo, Integer> qb = dao.queryBuilder();
	qb.selectRaw("MAX(" + Foo.VAL_COLUMN_NAME + ")");
	GenericRawResults<String[]> results = dao.queryRaw(qb.prepareStatementString());
	String[] result = results.getFirstResult();
	int max = Integer.parseInt(result[0]);
	if (foo1.val > foo2.val) {
		assertEquals(foo1.val, max);
	} else {
		assertEquals(foo2.val, max);
	}
}
 
Example #5
Source File: RawResultsImplTest.java    From ormlite-core with ISC License 6 votes vote down vote up
@Test
public void testQueryRaw() throws Exception {
	Dao<Foo, Integer> dao = createDao(Foo.class, true);
	Foo foo = new Foo();
	foo.val = 1;
	foo.equal = 10;
	assertEquals(1, dao.create(foo));
	QueryBuilder<Foo, Integer> qb = dao.queryBuilder();
	qb.where().eq(Foo.VAL_COLUMN_NAME, new SelectArg());
	GenericRawResults<String[]> rawResults = dao.queryRaw(qb.prepareStatementString(), Integer.toString(foo.val));
	List<String[]> results = rawResults.getResults();
	assertEquals(1, results.size());
	boolean found = false;
	String[] columnNames = rawResults.getColumnNames();
	for (int i = 0; i < rawResults.getNumberColumns(); i++) {
		if (columnNames[i].equalsIgnoreCase(Foo.ID_COLUMN_NAME)) {
			assertEquals(Integer.toString(foo.id), results.get(0)[0]);
			found = true;
		}
	}
	assertTrue(found);
}
 
Example #6
Source File: SelectIteratorTest.java    From ormlite-core with ISC License 6 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testIteratorRawResults() throws Exception {
	Dao<Foo, Integer> dao = createDao(Foo.class, true);
	Foo foo1 = new Foo();
	assertEquals(1, dao.create(foo1));

	GenericRawResults<String[]> rawResults = dao.queryRaw("SELECT " + Foo.ID_COLUMN_NAME + " FROM FOO");
	CloseableIterator<String[]> iterator = rawResults.closeableIterator();
	try {
		assertTrue(iterator.hasNext());
		iterator.next();
		iterator.remove();
	} finally {
		iterator.close();
	}
}
 
Example #7
Source File: StatementExecutor.java    From ormlite-core with ISC License 6 votes vote down vote up
/**
 * Return a results object associated with an internal iterator is mapped by the user's rowMapper.
 */
public <UO> GenericRawResults<UO> queryRaw(ConnectionSource connectionSource, String query,
		DatabaseResultsMapper<UO> mapper, String[] arguments, ObjectCache objectCache) throws SQLException {
	logger.debug("executing raw query for: {}", query);
	if (arguments.length > 0) {
		// need to do the (Object) cast to force args to be a single object
		logger.trace("query arguments: {}", (Object) arguments);
	}
	DatabaseConnection connection = connectionSource.getReadOnlyConnection(tableInfo.getTableName());
	CompiledStatement compiledStatement = null;
	try {
		compiledStatement = connection.compileStatement(query, StatementType.SELECT, noFieldTypes,
				DatabaseConnection.DEFAULT_RESULT_FLAGS, false);
		assignStatementArguments(compiledStatement, arguments);
		RawResultsImpl<UO> rawResults = new RawResultsImpl<UO>(connectionSource, connection, query, Object[].class,
				compiledStatement, new UserDatabaseResultsMapper<UO>(mapper), objectCache);
		compiledStatement = null;
		connection = null;
		return rawResults;
	} finally {
		IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
		if (connection != null) {
			connectionSource.releaseConnection(connection);
		}
	}
}
 
Example #8
Source File: StatementExecutor.java    From ormlite-core with ISC License 6 votes vote down vote up
/**
 * Return a results object associated with an internal iterator that returns Object[] results.
 */
public GenericRawResults<Object[]> queryRaw(ConnectionSource connectionSource, String query, DataType[] columnTypes,
		String[] arguments, ObjectCache objectCache) throws SQLException {
	logger.debug("executing raw query for: {}", query);
	if (arguments.length > 0) {
		// need to do the (Object) cast to force args to be a single object
		logger.trace("query arguments: {}", (Object) arguments);
	}
	DatabaseConnection connection = connectionSource.getReadOnlyConnection(tableInfo.getTableName());
	CompiledStatement compiledStatement = null;
	try {
		compiledStatement = connection.compileStatement(query, StatementType.SELECT, noFieldTypes,
				DatabaseConnection.DEFAULT_RESULT_FLAGS, false);
		assignStatementArguments(compiledStatement, arguments);
		RawResultsImpl<Object[]> rawResults = new RawResultsImpl<Object[]>(connectionSource, connection, query,
				Object[].class, compiledStatement, new ObjectArrayRowMapper(columnTypes), objectCache);
		compiledStatement = null;
		connection = null;
		return rawResults;
	} finally {
		IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
		if (connection != null) {
			connectionSource.releaseConnection(connection);
		}
	}
}
 
Example #9
Source File: StatementExecutor.java    From ormlite-core with ISC License 6 votes vote down vote up
/**
 * Return a results object associated with an internal iterator is mapped by the user's rowMapper.
 */
public <UO> GenericRawResults<UO> queryRaw(ConnectionSource connectionSource, String query, DataType[] columnTypes,
		RawRowObjectMapper<UO> rowMapper, String[] arguments, ObjectCache objectCache) throws SQLException {
	logger.debug("executing raw query for: {}", query);
	if (arguments.length > 0) {
		// need to do the (Object) cast to force args to be a single object
		logger.trace("query arguments: {}", (Object) arguments);
	}
	DatabaseConnection connection = connectionSource.getReadOnlyConnection(tableInfo.getTableName());
	CompiledStatement compiledStatement = null;
	try {
		compiledStatement = connection.compileStatement(query, StatementType.SELECT, noFieldTypes,
				DatabaseConnection.DEFAULT_RESULT_FLAGS, false);
		assignStatementArguments(compiledStatement, arguments);
		RawResultsImpl<UO> rawResults = new RawResultsImpl<UO>(connectionSource, connection, query, String[].class,
				compiledStatement, new UserRawRowObjectMapper<UO>(rowMapper, columnTypes), objectCache);
		compiledStatement = null;
		connection = null;
		return rawResults;
	} finally {
		IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
		if (connection != null) {
			connectionSource.releaseConnection(connection);
		}
	}
}
 
Example #10
Source File: StatementExecutor.java    From ormlite-core with ISC License 6 votes vote down vote up
/**
 * Return a results object associated with an internal iterator that returns String[] results.
 */
public GenericRawResults<String[]> queryRaw(ConnectionSource connectionSource, String query, String[] arguments,
		ObjectCache objectCache) throws SQLException {
	logger.debug("executing raw query for: {}", query);
	if (arguments.length > 0) {
		// need to do the (Object) cast to force args to be a single object
		logger.trace("query arguments: {}", (Object) arguments);
	}
	DatabaseConnection connection = connectionSource.getReadOnlyConnection(tableInfo.getTableName());
	CompiledStatement compiledStatement = null;
	try {
		compiledStatement = connection.compileStatement(query, StatementType.SELECT, noFieldTypes,
				DatabaseConnection.DEFAULT_RESULT_FLAGS, false);
		assignStatementArguments(compiledStatement, arguments);
		GenericRawResults<String[]> rawResults = new RawResultsImpl<String[]>(connectionSource, connection, query,
				String[].class, compiledStatement, this, objectCache);
		compiledStatement = null;
		connection = null;
		return rawResults;
	} finally {
		IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
		if (connection != null) {
			connectionSource.releaseConnection(connection);
		}
	}
}
 
Example #11
Source File: JdbcRawResultsImplTest.java    From ormlite-jdbc with ISC License 6 votes vote down vote up
@Test
public void testCustomColumnNames() throws Exception {
	Dao<Foo, Integer> dao = createDao(Foo.class, true);
	Foo foo = new Foo();
	foo.val = 1213213;
	assertEquals(1, dao.create(foo));

	final String idName = "SOME_ID";
	final String valName = "SOME_VAL";
	final AtomicBoolean gotResult = new AtomicBoolean(false);
	GenericRawResults<Object> results = dao.queryRaw("select id as " + idName + ", val as " + valName + " from foo",
			new RawRowMapper<Object>() {
				@Override
				public Object mapRow(String[] columnNames, String[] resultColumns) {
					assertEquals(idName, columnNames[0]);
					assertEquals(valName, columnNames[1]);
					gotResult.set(true);
					return new Object();
				}
			});
	List<Object> list = results.getResults();
	assertNotNull(list);
	assertEquals(1, list.size());
	assertTrue(gotResult.get());
}
 
Example #12
Source File: NotificationItemDaoImpl.java    From Notification-Analyser with MIT License 6 votes vote down vote up
private List<NotificationDateView> getSummaryLastPeriod(String rawQuery) throws SQLException {
    LinkedList<NotificationDateView> list = new LinkedList<NotificationDateView>();
    GenericRawResults<String[]> rawResults = this.queryRaw(rawQuery);
    List<String[]> results = rawResults.getResults();

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS");
    for (String[] result : results) {
        try {
            Date date = formatter.parse(result[0]);
            Integer notifications = Integer.parseInt(result[1]);
            list.add(new NotificationDateView(date, notifications));
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }
    Collections.reverse(list);
    return list;
}
 
Example #13
Source File: SqliteDatabaseTypeTest.java    From ormlite-jdbc with ISC License 5 votes vote down vote up
@Test
public void testDateFormat() throws Exception {
	Dao<AllTypes, Object> dao = createDao(AllTypes.class, true);
	AllTypes all = new AllTypes();
	all.dateField = new Date();
	assertEquals(1, dao.create(all));
	GenericRawResults<String[]> results = dao.queryRaw("select * from alltypes");
	List<String[]> stringslist = results.getResults();
	String[] names = results.getColumnNames();
	for (String[] strings : stringslist) {
		for (int i = 0; i < strings.length; i++) {
			System.out.println(names[i] + "=" + strings[i]);
		}
	}
}
 
Example #14
Source File: RxBaseDaoImpl.java    From AndroidStarter with Apache License 2.0 5 votes vote down vote up
@Override
public <UO> Observable<GenericRawResults<UO>> rxQueryRaw(final String query, final RawRowMapper<UO> mapper, final String... arguments) {
    final Func0<Observable<GenericRawResults<UO>>> loFunc = () -> {
        try {
            return Observable.just(queryRaw(query, mapper, arguments));
        } catch (SQLException e) {
            return Observable.error(e);
        }
    };
    return Observable.defer(loFunc);
}
 
Example #15
Source File: RxBaseDaoImpl.java    From AndroidStarter with Apache License 2.0 5 votes vote down vote up
@Override
public <UO> Observable<GenericRawResults<UO>> rxQueryRaw(final String query, final com.j256.ormlite.field.DataType[] columnTypes, final RawRowObjectMapper<UO> mapper, final String... arguments) {
    final Func0<Observable<GenericRawResults<UO>>> loFunc = () -> {
        try {
            return Observable.just(queryRaw(query, columnTypes, mapper, arguments));
        } catch (SQLException e) {
            return Observable.error(e);
        }
    };
    return Observable.defer(loFunc);
}
 
Example #16
Source File: RxBaseDaoImpl.java    From AndroidStarter with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<GenericRawResults<Object[]>> rxQueryRaw(final String query, final com.j256.ormlite.field.DataType[] columnTypes, final String... arguments) {
    final Func0<Observable<GenericRawResults<Object[]>>> loFunc = () -> {
        try {
            return Observable.just(queryRaw(query, columnTypes, arguments));
        } catch (SQLException e) {
            return Observable.error(e);
        }
    };
    return Observable.defer(loFunc);
}
 
Example #17
Source File: RawResultsImplTest.java    From ormlite-core with ISC License 5 votes vote down vote up
@Test
public void testHaving() throws Exception {
	Dao<Foo, Integer> dao = createDao(Foo.class, true);

	Foo foo = new Foo();
	int val1 = 243342;
	foo.val = val1;
	assertEquals(1, dao.create(foo));
	foo = new Foo();
	foo.val = val1;
	assertEquals(1, dao.create(foo));
	foo = new Foo();
	// only one of these
	int val2 = 6543;
	foo.val = val2;
	assertEquals(1, dao.create(foo));

	QueryBuilder<Foo, Integer> qb = dao.queryBuilder();
	qb.selectColumns(Foo.VAL_COLUMN_NAME);
	qb.groupBy(Foo.VAL_COLUMN_NAME);
	qb.having("COUNT(VAL) > 1");
	GenericRawResults<String[]> results = dao.queryRaw(qb.prepareStatementString());
	List<String[]> list = results.getResults();
	// only val2 has 2 of them
	assertEquals(1, list.size());
	assertEquals(String.valueOf(val1), list.get(0)[0]);

	qb.having("COUNT(VAL) > 2");
	results = dao.queryRaw(qb.prepareStatementString());
	list = results.getResults();
	assertEquals(0, list.size());
}
 
Example #18
Source File: RawResultsImplTest.java    From ormlite-core with ISC License 5 votes vote down vote up
@Test
public void testQueryRawColumns() throws Exception {
	Dao<Foo, Integer> dao = createDao(Foo.class, true);
	Foo foo1 = new Foo();
	foo1.val = 1;
	foo1.equal = 10;
	assertEquals(1, dao.create(foo1));
	Foo foo2 = new Foo();
	foo2.val = 10;
	foo2.equal = 5;
	assertEquals(1, dao.create(foo2));
	QueryBuilder<Foo, Integer> qb = dao.queryBuilder();
	qb.selectRaw("COUNT(*)");
	GenericRawResults<String[]> rawResults = dao.queryRaw(qb.prepareStatementString());
	List<String[]> results = rawResults.getResults();
	assertEquals(1, results.size());
	// 2 rows inserted
	assertEquals("2", results.get(0)[0]);

	qb = dao.queryBuilder();
	qb.selectRaw("MIN(val)", "MAX(val)");
	rawResults = dao.queryRaw(qb.prepareStatementString());
	results = rawResults.getResults();
	assertEquals(1, results.size());
	String[] result = results.get(0);
	assertEquals(2, result.length);
	// foo1 has the maximum value
	assertEquals(Integer.toString(foo1.val), result[0]);
	// foo2 has the maximum value
	assertEquals(Integer.toString(foo2.val), result[1]);
}
 
Example #19
Source File: QueryBuilderTest.java    From ormlite-core with ISC License 5 votes vote down vote up
@Test
public void testQueryRawMax() throws Exception {
	Dao<Foo, Object> dao = createDao(Foo.class, true);

	Foo foo1 = new Foo();
	foo1.stringField = "1";
	foo1.val = 10;
	assertEquals(1, dao.create(foo1));
	Foo foo2 = new Foo();
	foo2.stringField = "1";
	foo2.val = 20;
	assertEquals(1, dao.create(foo2));
	Foo foo3 = new Foo();
	foo3.stringField = "2";
	foo3.val = 30;
	assertEquals(1, dao.create(foo3));
	Foo foo4 = new Foo();
	foo4.stringField = "2";
	foo4.val = 40;
	assertEquals(1, dao.create(foo4));

	QueryBuilder<Foo, Object> qb = dao.queryBuilder();
	qb.selectRaw("string, max(val) as val");
	qb.groupBy(Foo.STRING_COLUMN_NAME);
	GenericRawResults<Foo> results = dao.queryRaw(qb.prepareStatementString(), dao.getRawRowMapper());
	assertNotNull(results);
	CloseableIterator<Foo> iterator = results.closeableIterator();
	try {
		assertTrue(iterator.hasNext());
		assertEquals(foo2.val, iterator.next().val);
		assertTrue(iterator.hasNext());
		assertEquals(foo4.val, iterator.next().val);
		assertFalse(iterator.hasNext());
	} finally {
		iterator.close();
	}
}
 
Example #20
Source File: RxBaseDaoImpl.java    From AndroidStarter with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<GenericRawResults<String[]>> rxQueryRaw(final String query, final String... arguments) {
    final Func0<Observable<GenericRawResults<String[]>>> loFunc = () -> {
        try {
            return Observable.just(queryRaw(query, arguments));
        } catch (SQLException e) {
            return Observable.error(e);
        }
    };
    return Observable.defer(loFunc);
}
 
Example #21
Source File: QueryBuilder.java    From ormlite-core with ISC License 4 votes vote down vote up
/**
 * A short cut to {@link Dao#queryRaw(String, String...)}.
 */
public GenericRawResults<String[]> queryRaw() throws SQLException {
	return dao.queryRaw(prepareStatementString());
}
 
Example #22
Source File: QueryBuilderTest.java    From ormlite-core with ISC License 4 votes vote down vote up
@Test
public void testQueryColumnsPlusQueryRawMax() throws Exception {
	Dao<Foo, Object> dao = createDao(Foo.class, true);

	Foo foo1 = new Foo();
	foo1.stringField = "1";
	foo1.val = 10;
	assertEquals(1, dao.create(foo1));
	Foo foo2 = new Foo();
	foo2.stringField = "1";
	foo2.val = 20;
	assertEquals(1, dao.create(foo2));
	Foo foo3 = new Foo();
	foo3.stringField = "2";
	foo3.val = 40;
	assertEquals(1, dao.create(foo3));
	Foo foo4 = new Foo();
	foo4.stringField = "2";
	foo4.val = 30;
	assertEquals(1, dao.create(foo4));

	QueryBuilder<Foo, Object> qb = dao.queryBuilder();
	qb.selectColumns(Foo.STRING_COLUMN_NAME);
	qb.selectRaw("MAX(val) AS val");
	qb.groupBy(Foo.STRING_COLUMN_NAME);
	GenericRawResults<Foo> results = dao.queryRaw(qb.prepareStatementString(), dao.getRawRowMapper());
	assertNotNull(results);
	CloseableIterator<Foo> iterator = results.closeableIterator();
	try {
		assertTrue(iterator.hasNext());
		Foo result = iterator.next();
		assertEquals(foo2.val, result.val);
		assertEquals(foo2.stringField, result.stringField);
		assertTrue(iterator.hasNext());
		result = iterator.next();
		assertEquals(foo3.val, result.val);
		assertEquals(foo3.stringField, result.stringField);
		assertFalse(iterator.hasNext());
	} finally {
		iterator.close();
	}
}
 
Example #23
Source File: GetMyPrivateKey.java    From passopolis-server with GNU General Public License v3.0 4 votes vote down vote up
private void sendEmailAndThrow(GetMyPrivateKeyRequest in, MitroRequestContext context, DBIdentity identity) throws MitroServletException {
  try {
    String token = makeLoginTokenString(identity, in.extensionId, in.deviceId);
    String tokenSignature = TwoFactorSigningService.signToken(token);

    GenericRawResults<String[]> queuedEmails = context.manager.emailDao.queryRaw(
            "SELECT type_string, arg_string FROM ("
            + "(SELECT type_string, arg_string FROM email_queue)"
            + " UNION "
            + "(SELECT type_string, arg_string FROM email_queue_sent) "
            + ") AS email_queues_merged WHERE type_string=? AND arg_string LIKE ?",
            DBEmailQueue.Type.LOGIN_ON_NEW_DEVICE.getValue(),
            "%" + identity.getName() + "%"
    );
    boolean recentEmail = false;

    // this should be UTC as per the JDK documentation
    final long now = System.currentTimeMillis();
    for(String[] emailArguments : queuedEmails) {
        String[] args = DBEmailQueue.decodeArguments(emailArguments[1]);
        String emailRecipient = args[0];
        DBEmailQueue.DeviceVerificationArguments arguments = DBEmailQueue.decodeDeviceVerificationArguments(args[1]);

        // Gautier: People trying to sign in a few times in a row is a common
        // pattern I've seen in the logs so I'd like to make sure we don't
        // flood their inboxes and trigger spam filters.  A new token valid
        // for 12 hours is generated every time the users try to sign in on a
        // new device. With this PR, users are able to resend 15 minutes
        // after the previous try.
        //
        // timestampMs is used at the token creating in the
        // makeLoginTokenString function using System.currentTimeMillis
        if (emailRecipient.equals(identity.getName())
                && arguments.deviceId != null && in.deviceId != null && arguments.deviceId.equals(in.deviceId)
                && (now - arguments.timestampMs) < 1000 * 60 * 15) {
            recentEmail = true;
            break;
        }
    }

    if (!recentEmail) {
        if (!context.manager.isReadOnly()) {
          DBEmailQueue email = DBEmailQueue.makeNewDeviceVerification(identity.getName(), token, tokenSignature, context.platform, context.requestServerUrl, context.sourceIp);
          context.manager.emailDao.create(email);
          context.manager.commitTransaction();
        }
        // TODO: throw ReadOnlyServerException if isReadOnly, after we don't retry on the secondary!
        logger.info("Forcing user {} to verify device {}", identity.getName(), in.deviceId);
    } else {
        logger.info("Forcing user {} to verify device {} (email already sent)", identity.getName(), in.deviceId);
    }
    throw new DoEmailVerificationException();
  } catch (SQLException|KeyczarException e) {
    throw new MitroServletException(e);
  }
}
 
Example #24
Source File: Where.java    From ormlite-core with ISC License 4 votes vote down vote up
/**
 * A short-cut for calling {@link QueryBuilder#queryRaw()}.
 */
public GenericRawResults<String[]> queryRaw() throws SQLException {
	return checkQueryBuilderMethod("queryRaw()").queryRaw();
}
 
Example #25
Source File: IRxDao.java    From AndroidStarter with Apache License 2.0 2 votes vote down vote up
/**
 * Similar to the {@link #queryRaw(String, String...)} but this iterator returns rows that you can map yourself. For
 * every result that is returned by the database, the {@link RawRowMapper#mapRow(String[], String[])} method is
 * called so you can convert the result columns into an object to be returned by the iterator. The arguments are
 * optional but can be set with strings to expand ? type of SQL. For a simple implementation of a raw row mapper,
 * see {@link #getRawRowMapper()}.
 */
<UO> Observable<GenericRawResults<UO>> rxQueryRaw(final String query, final RawRowMapper<UO> mapper, final String... arguments)
;
 
Example #26
Source File: IRxDao.java    From AndroidStarter with Apache License 2.0 2 votes vote down vote up
/**
 * <p>
 * Similar to the {@link #iterator(PreparedQuery)} except it returns a GenericRawResults object associated with the
 * SQL select rxQuery argument. Although you should use the {@link #iterator()} for most queries, this method allows
 * you to do special queries that aren't supported otherwise. Like the above iterator methods, you must call close
 * on the returned RawResults object once you are done with it. The arguments are optional but can be set with
 * strings to expand ? type of SQL.
 * </p>
 * <p>
 * <p>
 * You can use the {@link QueryBuilder#prepareStatementString()} method here if you want to build the rxQuery using
 * the structure of the  QueryBuilder.
 * </p>
 * <p>
 * <pre>
 *  QueryBuilder&lt;Account, Integer&gt; qb = accountDao.queryBuilder();
 * qb.where().ge(&quot;orderCount&quot;, 10);
 * results = accountDao.queryRaw(qb.prepareStatementString());
 * </pre>
 * <p>
 * <p>
 * If you want to use the  QueryBuilder with arguments to the raw rxQuery then you should do something like:
 * </p>
 * <p>
 * <pre>
 *  QueryBuilder&lt;Account, Integer&gt; qb = accountDao.queryBuilder();
 * // we specify a SelectArg here to generate a ? in the statement string below
 * qb.where().ge(&quot;orderCount&quot;, new SelectArg());
 * // the 10 at the end is an optional argument to fulfill the SelectArg above
 * results = accountDao.queryRaw(qb.prepareStatementString(), rawRowMapper, 10);
 * </pre>
 * <p>
 * <p>
 * <b>NOTE:</b> If you are using the {@link QueryBuilder#prepareStatementString()} to build your rxQuery, it may have
 * added the id column to the selected column list if the Dao object has an id you did not include it in the columns
 * you selected. So the results might have one more column than you are expecting.
 * </p>
 */
Observable<GenericRawResults<String[]>> rxQueryRaw(final String query, final String... arguments);
 
Example #27
Source File: IRxDao.java    From AndroidStarter with Apache License 2.0 2 votes vote down vote up
/**
 * Similar to the {@link #queryRaw(String, RawRowMapper, String...)} but uses the column-types array to present an
 * array of object results to the mapper instead of strings. The arguments are optional but can be set with strings
 * to expand ? type of SQL.
 */
<UO> Observable<GenericRawResults<UO>> rxQueryRaw(final String query, final DataType[] columnTypes, final RawRowObjectMapper<UO> mapper,
                                                  final String... arguments);
 
Example #28
Source File: IRxDao.java    From AndroidStarter with Apache License 2.0 2 votes vote down vote up
/**
 * Similar to the {@link #queryRaw(String, String...)} but instead of an array of String results being returned by
 * the iterator, this uses the column-types parameter to return an array of Objects instead. The arguments are
 * optional but can be set with strings to expand ? type of SQL.
 */
Observable<GenericRawResults<Object[]>> rxQueryRaw(final String query, final DataType[] columnTypes, final String... arguments)
;