public static function transaction($connection, callable $function, $context = null)
	{
		static::_connection($connection);
		static::_associate($function, $context);

		return function() use ($connection, $function) {
			if (!$connection->beginTransaction())
				throw new \RuntimeException("unable to begin transaction");

			try {
				if (call_user_func_array($function, func_get_args()) === false)
					goto rollback;
			} catch (\PDOException $e) {
				throw $e;
			} catch (\Exception $e) {
				goto rollback;
			}

			if (!$connection->commit())
				throw new \RuntimeException("unable to commit transaction");

			return true;

			rollback:
			if (!$connection->rollback())
				throw new \RuntimeException("unable to rollback transaction");

			return false;
		};
	}