Azure mobile service for android query table - android

I'm using azure sdk for android and follow the tutorial https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-android-get-started-data/.
When I'm trying to connect and insert data to mobile service table all is ok, but when I query the table in activity my app gets stuck, though there are only several entries in the table and execute method successfully returns Future.
public static MobileServiceClient mClient;
public static void connect(Context context) {
try {
mClient = new MobileServiceClient(storageLink, key, context);
} catch (MalformedURLException e) {
Log.e("AzureService.connect", "Storage access failed" + storageLink);
}
}
public static InstallationData get(final String deviceId) {
MobileServiceTable<InstallationData> table= mClient.getTable(InstallationData.class);
final MobileServiceList<InstallationData> result;
try {
result = table.where().field("deviceid").eq(deviceId).execute().get();
for (InstallationData item : result) {
return item;
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
return null;
}
public static void store(final InstallationData item) {
mClient.getTable(InstallationData.class).insert(item, new TableOperationCallback<InstallationData>() {
public void onCompleted(InstallationData entity, Exception exception, ServiceFilterResponse response) {
if (exception == null) {
Log.d("AzureService.store()", "Data about " + item.getDeviceid() + "" + "is successfully updated");
} else {
exception.printStackTrace();
Log.e("AzureService.store()", "Data about " + item.getDeviceid() + "" + "is failed to update");
}
}
});
}
Thank you in advance!

Related

Android: How to maintain user online/offline status using quickblox?

I had integrated quickblox chat in my application and want to maintain user online and offline status and tried following options.
1) as described in doc i had followed this link https://quickblox.com/developers/SimpleSample-users-android#Online.5COffline_status but one issue is there that it not give clarity about user online status
2) used Ping Manager: https://quickblox.com/developers/Android_XMPP_Chat_Sample#Ping_a_user
but it always give QBResponseException
3) QBRoaster: this option is not suitable as requirement.
[note : I am using quickblox version 3.3.1]
I have implemented QBPingManager as following
public void checkUserOnlineStatus(String mOpponentName) {
QBChatService.getInstance().getPingManager().setPingInterval(1);
Performer<QBUser> qbUser = QBUsers.getUserByLogin(mOpponentName);
qbUser.performAsync(new QBEntityCallback<QBUser>() {
#Override
public void onSuccess(QBUser qbUser, Bundle bundle) {
final int mOpponentUserId = qbUser.getId();
final QBPingManager pingManager = QBChatService.getInstance().getPingManager();
pingManager.pingServer(new QBEntityCallback<Void>() {
#Override
public void onSuccess(Void aVoid, Bundle bundle) {
pingManager.pingUser(mOpponentUserId, new QBEntityCallback<Void>() {
#Override
public void onSuccess(Void aVoid, Bundle bundle) {
Timber.tag(TAG).w("Opponent User is online ");
}
#Override
public void onError(QBResponseException e) {
Timber.tag(TAG).e("message(ping user): " + e.getMessage() + "\n localized message: " + e.getLocalizedMessage());
e.printStackTrace();
}
});
}
#Override
public void onError(QBResponseException e) {
Timber.tag(TAG).e("message (ping server): " + e.getMessage() + "\n localized message: " + e.getLocalizedMessage());
}
});
}
#Override
public void onError(QBResponseException e) {
Timber.tag(TAG).e("Error : " + e.getMessage() + "\n Message : " + e.getLocalizedMessage());
}
});
}
any help is appreciated thank you.
Here we will find online/offline status with last seen time/date :-
To get online/offline status of user you need to send and has to confirm subscription request
// to confirm subscription request
QBSubscriptionListener subscriptionListener = new QBSubscriptionListener() {
#Override
public void subscriptionRequested(int userId) {
try {
if (chatRoster != null)
chatRoster.confirmSubscription(userId);
} catch (SmackException.NotConnectedException e) {
} catch (SmackException.NotLoggedInException e) {
} catch (XMPPException e) {
} catch (SmackException.NoResponseException e) {
}
}
};
chatRoster = QBChatService.getInstance().getRoster(QBRoster.SubscriptionMode.mutual, subscriptionListener);
// to send subscription request
try {
chatRoster.subscribe(qbChatDialog.getRecipientId()); //getRecipientId is Opponent UserID
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
Send presence whenever user comes online/offline
QBPresence presence = new QBPresence(QBPresence.Type.online, "I am now available", 1, QBPresence.Mode.available);
try {
chatRoster.sendPresence(presence);
} catch (SmackException.NotConnectedException e) {
} catch (Exception e) {
e.printStackTrace();
}
Get Presence of opponent user
QBPresence presence = chatRoster.getPresence(qbChatDialog.getRecipientId());
if (presence.getType() == QBPresence.Type.online) {
//online
}else{
//offline
}
Identify when user's online status has been changed
QBRosterListener rosterListener = new QBRosterListener() {
#Override
public void entriesDeleted(Collection<Integer> userIds) {
}
#Override
public void entriesAdded(Collection<Integer> userIds) {
}
#Override
public void entriesUpdated(Collection<Integer> userIds) {
}
#Override
public void presenceChanged(QBPresence presence1) {
try {
int userid = presence1.getUserId();
int recid = qbChatDialog.getRecipientId();//opponent user id
if (userid == recid) {
if (presence1.getType() == QBPresence.Type.online)
status.setText(getResources().getString(R.string.online));
else {
status.setText("");
String lastseen = getlastseen();
if (lastseen.length() > 0) {
status.setText(lastseen);
}
}
} else {
}
} catch (Exception e) {
}
}
};
To get Last Seen of offline user
private String getlastseen() {
String lastseen = "";
String appendstring = "";
try {
long lastUserActivity = QBChatService.getInstance().getLastUserActivity(qbChatDialog.getRecipientId()); //returns last activity in seconds or error
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, -(int) lastUserActivity);
String format = "dd MMM yyyy hh:mm a";
if (DateUtils.isToday(calendar.getTimeInMillis())) {
format = "hh:mm a";
appendstring = ChatActivity.this.getResources().getString(R.string.today) + ",";
} else if (isyesterday(calendar.getTimeInMillis())) {
format = "hh:mm a";
appendstring = ChatActivity.this.getResources().getString(R.string.yesterday) + ",";
} else if (Calendar.YEAR == Calendar.getInstance().YEAR)
format = "dd MMM hh:mm aa";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
lastseen = simpleDateFormat.format(calendar.getTime());
} catch (XMPPException.XMPPErrorException | SmackException.NotConnectedException e) {
} catch (Exception e) {
e.printStackTrace();
}
return appendstring + lastseen;
}
You can use new feature of QuickBlox Android SDK since version 3.3.3 which called 'last activity'. You can call QBChatService.getInstance().getLastUserActivity(userId); As result you will get:
- 0 if opponent online or
- seconds ago opponent was online or
- error if user newer logged to chat.

found index 0, size is 0 in android

"There i found index out of bound exception how can i solve???"
public static void addToCart() {
ArrayList<ItemData> iArr;
if (holdSelection != null) {
String categoryID = holdSelection.getCategoryID();
int position = categoriesAddedd.indexOf(holdSelection.getCategoryID());
int itemPosition =categoriesitemAddedd.indexOf(holdSelection.getItemData().get(0).getItemID());
if (!categoriesAddedd.contains(categoryID)) {
CategoryData data = new CategoryData();
data.setCategoryID(categoryID);
data.setCategoryName(holdSelection.getCategoryName());
data.setItemData(holdSelection.getItemData());
mAddedToCart.add(data);
categoriesAddedd.add(categoryID); categoriesitemAddedd.add(holdSelection.getItemData().get(0).getItemID());
Toast.makeText(mContext,R.string.Add_to_cart,Toast.LENGTH_SHORT).show();
} else {
if (position>=0) {
if(itemPosition>=0){
if(holdSelection.getItemData().get(0).getScaled()){
Toast.makeText(mContext,R.string.Already_in_cart,Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(mContext,R.string.Already_in_cart,Toast.LENGTH_SHORT).show();
}
}else{
try{
CategoryData data = mAddedToCart.get(position);
iArr = data.getItemData();
iArr.add(holdSelection.getItemData().get(0));
categoriesAddedd.add(categoryID);
categoriesitemAddedd.add(holdSelection.getItemData().get(0).getItemID());
Toast.makeText(mContext, R.string.Add_to_cart,Toast.LENGTH_SHORT).show();
}catch (Exception e) {
// TODO: handle exception
Toast.makeText(mContext, "There is " +e,Toast.LENGTH_SHORT).show();
System.out.println("Exception : "+ e.getMessage());
e.printStackTrace();
}
}
}
}
}
}
It's impossible to help without a minimum of (structured) information (and also without a Hello, please, tank you, polite words if you prefer).
First of all, you have to use the brackets to display code when you post, so your clean code should appear as follow :
public static void addToCart() {
ArrayList iArr;
if (holdSelection != null) {
String categoryID = holdSelection.getCategoryID();
int position = categoriesAddedd.indexOf(holdSelection.getCategoryID());
int itemPosition =categoriesitemAddedd.indexOf(holdSelection.getItemData().get(0).getItemID());
if (!categoriesAddedd.contains(categoryID)) {
CategoryData data = new CategoryData();
data.setCategoryID(categoryID);
data.setCategoryName(holdSelection.getCategoryName());
data.setItemData(holdSelection.getItemData());
mAddedToCart.add(data);
categoriesAddedd.add(categoryID);
categoriesitemAddedd.add(holdSelection.getItemData().get(0).getItemID());
Toast.makeText(mContext,R.string.Add_to_cart,Toast.LENGTH_SHORT).show();
} else {
if (position>=0) {
if(itemPosition>=0){
if(holdSelection.getItemData().get(0).getScaled()){
Toast.makeText(mContext,R.string.Already_in_cart,Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(mContext,R.string.Already_in_cart,Toast.LENGTH_SHORT).show();
}
}else{
try{
CategoryData data = mAddedToCart.get(position);
iArr = data.getItemData(); iArr.add(holdSelection.getItemData().get(0));
categoriesAddedd.add(categoryID);
categoriesitemAddedd.add(holdSelection.getItemData().get(0).getItemID());
Toast.makeText(mContext, R.string.Add_to_cart,Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{ // TODO: handle exception Toast.makeText(mContext, "There is " +e,Toast.LENGTH_SHORT).show();
System.out.println("Exception : "+ e.getMessage()); e.printStackTrace();
}
}
}
}
}
}
then my first question will be : what is holdSelection related to?
Please add more parts of your code as your log (asked by Remees).
Alex.

Throw exception and getting e null

I throw a exception with some message like:
public static ILSResponseEmailLookUPBO getILSUserAccounts(Resources res,
String email) throws TripLoggerCustomException,
TripLoggerUnexpectedErrorException {
String resp = null;
String lookupURL;
try {
lookupURL = TripLoggerConstants.ServerConstants.ILS_LOOKUP_URL
+ URLEncoder.encode(email, "UTF-8");
} catch (UnsupportedEncodingException e1) {
throw new TripLoggerCustomException(
res.getString(R.string.error_try_again));
}
try {
resp = ConnectionManager.getInstance().httpRequest(lookupURL,
TripLoggerConstants.RequestMethods.GET);
} catch (IOException e) {
if (e.getMessage().equals(
res.getString(R.string.network_unreachable))
|| e.getMessage().equals(
res.getString(R.string.host_unresolved))) {
throw new TripLoggerCustomException(
res.getString(R.string.network_not_reachable));
} else {
throw new TripLoggerCustomException(
res.getString(R.string.email_notfound_ils));
}
}
here my else part execute.
And my exception class is:
public class TripLoggerCustomException extends Exception {
private String customMessage;
private static final long serialVersionUID = 1L;
public TripLoggerCustomException() {
super();
}
public TripLoggerCustomException(String message) {
super(message);
this.customMessage = (message == null ? "" : message);
}
public String getCustomMessage() {
return this.customMessage;
}
public void setCustomMessage(String customMessage) {
this.customMessage = customMessage;
}
}
And here i catch this exception:
private void manageLookUpActions(final String emailID) {
new Thread() {
public void run() {
try {
listILSAccounts = ILSLookupEmailBL.getILSUserAccounts(
getResources(), emailID);
} catch (TripLoggerCustomException e) {
dismissProgressBar();
handleException(e.getMessage());
return;
} catch (TripLoggerUnexpectedErrorException e) {
dismissProgressBar();
handleException(e.getMessage());
return;
}
}
}.start();
}
but here in catch of TripLoggerCustomException e is null.why?Can anyone help me?
After looking into multiple reports on StackOverflow, it seems like this is not an actual issue. Multiple people have been saying that it is a problem in the combination of the Eclipse debugger and the Android Emulator. That is why you don't get a NullPointerException, which you would definitely get if e was null.
So this is probably not an issue you have to worry about.

AsyncTask slow with OnClick

Goodmorning,
I have a button on my android app that launches a search on the web (through google endpoints) through an AsyncTask. My problem is that the button does not "unclick" until the AsyncTask is completed, which may take several seconds. When the internet connection is slow, this even makes the application crash, in any case the application is completely stuck until the AsyncTask is completed. Now the reason for using AsyncTask was exactly to eliminate this problem, so I don't really get what happens!
Here is the OnClickListener:
SearchListener = new OnClickListener() {
#Override
public void onClick(View v) {
String cname=TextCourse.getText().toString();
if (!cname.isEmpty()){
try {
CollectionResponseWine listavini= new QueryWinesTask(messageEndpoint,cname,5).execute().get();
} catch (InterruptedException e) {
showDialog("Errore ricerca");
e.printStackTrace();
} catch (ExecutionException e) {
showDialog("Errore ricerca");
e.printStackTrace();
}
} else{
showDialog("Inserisci un piatto");
}
}
};
and here is the AsyncTask that is being called:
private class QueryWinesTask
extends AsyncTask<Void, Void, CollectionResponseWine> {
Exception exceptionThrown = null;
MessageEndpoint messageEndpoint;
String cname;
Integer limit;
public QueryWinesTask(MessageEndpoint messageEndpoint, String cname, Integer limit) {
this.messageEndpoint = messageEndpoint;
this.cname=cname;
this.limit=limit;
}
#Override
protected CollectionResponseWine doInBackground(Void... params) {
try {
CollectionResponseWine wines = messageEndpoint.listwines().setCoursename(cname).setLimit(limit).execute();
return wines;
} catch (IOException e) {
exceptionThrown = e;
return null;
//Handle exception in PostExecute
}
}
protected void onPostExecute(CollectionResponseWine wines) {
// Check if exception was thrown
if (exceptionThrown != null) {
Log.e(RegisterActivity.class.getName(),
"Exception when listing Messages", exceptionThrown);
showDialog("Non ci sono vini associati al tuo piatto. Aggiungine uno!");
}
else {
messageView.setText("Vini piu' votati per " +
cname + ":\n\n");
for(Wine wine : wines.getItems()) {
messageView.append(wine.getName() + " (" + wine.getScore() + ")\n");
}
}
}
}
...execute().get() is blocking. It makes UI thread wait for Task to complete.
Don't do get(). Use onPostExecute() to get the result (wines) of task and update the UI.

How to test my dbmanager class in android?

In my android app I am using ormlite. Now I want to create some testcases for the db helper methods. I do not know how this should work properly. The database need to be created in my testcase before the concrete test can start. For example I want to test if a user will be created as expected. For this I have a addUser Method which should be tested, but how can this be done?
Currently I created a TestProject with a TestCase for my DBManager-Class.
Here is my DBHelper class
public class DBHelper extends OrmLiteSqliteOpenHelper{
private static final String DATABASE_NAME = "pdixattach.db";
private static final int DATABASE_VERSION = 4;
private static final String TAG = DBHelper.class.getSimpleName();
private static DBHelper _helperInstance;
private Dao<Attachment, Integer> attachmentDao = null;
private Dao<User, Integer> userDao = null;
private Dao<Comment, Integer> commentDao = null;
private Dao<Job, Integer> jobDao = null;
private Dao<Target, Integer> targetDao = null;
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db, ConnectionSource source) {
Log.i(TAG, "onCreate");
try{
dropTables(source);
TableUtils.createTable(source, Attachment.class);
TableUtils.createTable(source, User.class);
TableUtils.createTable(source, Comment.class);
TableUtils.createTable(source, Target.class);
TableUtils.createTable(source, Job.class);
TableUtils.createTable(source, ConfigurationParameter.class);
} catch (Exception e){
Log.e(TAG, "error while creating tables " + e.getMessage());
throw new RuntimeException(e);
}
}
#Override
public void onUpgrade(final SQLiteDatabase db, final ConnectionSource connectionSource, final int oldVersion, final int newVersion) {
Log.i(TAG, "onUpgrade");
try {
dropTables(connectionSource);
onCreate(db, connectionSource);
} catch (SQLException e) {
Log.e(TAG, "error while upgrading tables " + e.getMessage());
throw new RuntimeException(e);
}
// after we drop the old databases, we create the new ones
onCreate(db, connectionSource);
}
private void dropTables(final ConnectionSource connectionSource)
throws SQLException {
TableUtils.dropTable(connectionSource, Attachment.class, true);
TableUtils.dropTable(connectionSource, User.class, true);
TableUtils.dropTable(connectionSource, Target.class, true);
TableUtils.dropTable(connectionSource, Job.class, true);
TableUtils.dropTable(connectionSource, Comment.class, true);
TableUtils.dropTable(connectionSource, ConfigurationParameter.class, true);
}
public Dao<Attachment, Integer> getAttachmentDao() throws SQLException {
if (this.attachmentDao == null) {
this.attachmentDao = getDao(Attachment.class);
}
return this.attachmentDao;
}
public Dao<User, Integer> getUserDao() throws SQLException {
if (this.userDao == null) {
this.userDao = getDao(User.class);
}
return this.userDao;
}
public Dao<Comment, Integer> getCommentDao() throws SQLException {
if (this.commentDao == null) {
this.commentDao = getDao(Comment.class);
}
return this.commentDao;
}
public Dao<Target, Integer> getTargetDao() throws SQLException {
if (this.targetDao == null) {
this.targetDao = getDao(Target.class);
}
return this.targetDao;
}
public Dao<Job, Integer> getJobDao() throws SQLException {
if (this.jobDao == null) {
this.jobDao = getDao(Job.class);
}
return this.jobDao;
}
/**
* Close the database connections and clear any cached DAOs.
*/
#Override
public void close() {
super.close();
_helperInstance = null;
this.attachmentDao = null;
this.commentDao = null;
this.jobDao = null;
this.targetDao = null;
this.userDao = null;
}
}
and my DBManager which I want to test, for example the storeUser Method
public class DBManager {
private DBHelper helper;
private static DBManager uniqueInstance;
private static final String TAG = DBManager.class.getSimpleName();
public DBManager(Context context) {
helper = new DBHelper(context);
}
public static void init(Context context) {
if (uniqueInstance == null) {
uniqueInstance = new DBManager(context);
}
}
public static DBManager getInstance() {
return uniqueInstance;
}
public boolean addUser(User u) {
boolean retVal = false;
if (u == null) {
throw new IllegalArgumentException("user must not be null");
}
try {
helper.getUserDao().create(u);
retVal = true;
} catch (SQLException e) {
Log.e(TAG, "error while adding user to db " + e.getMessage());
}
return retVal;
}
public boolean addServiceEndpoint(String endpoint) {
Log.d(TAG, "adding Service Endpoint " + endpoint);
boolean retVal = false;
if (endpoint == null) {
throw new IllegalArgumentException("endpoint must not be null");
}
try {
Target t = new Target(endpoint);
int result = helper.getTargetDao().create(t);
Log.d(TAG, "creating target entry resulted with value " + result);
retVal = (result == 1);
} catch (SQLException e) {
Log.e(TAG,"error while adding target to db, with service endpoint " + endpoint + "error" + e.getMessage());
}
return retVal;
}
public List<Target> getAllTargets() {
List<Target> retVal = new ArrayList<Target>();
try {
retVal = helper.getTargetDao().queryForAll();
} catch (SQLException e) {
Log.e(TAG,
"error while retrieving service endpoints, error" + e.getMessage());
}
return retVal;
}
public User storeUser(String username, String hashedPw, Target target,
boolean storeLogin) {
User loggedInUser = null;
int loginState = (storeLogin) ? 1 : 0;
if (username == null || hashedPw == null || target == null) {
throw new IllegalArgumentException(
"cannot store login with empty/null values");
}
try {
QueryBuilder<User, Integer> queryBuilder = helper.getUserDao().queryBuilder();
Where<User, Integer> where = queryBuilder.where();
where.eq(User.USERNAME, username)
.and().eq(User.TARGET_ID, target.getServiceEndpoint());
PreparedQuery<User> prepareStmt = queryBuilder.prepare();
List<User> userList = helper.getUserDao().query(prepareStmt);
if (userList.isEmpty()) {
Log.d(TAG, "no user found with this name in the db, need to store it");
User newUser = new User(username, hashedPw, target);
newUser.setStored(loginState);
addUser(newUser);
userList = helper.getUserDao().query(prepareStmt);
loggedInUser = userList.get(0);
} else {
Log.d(TAG, "found at least one user with username " + username + " target " + target);
for (User u : userList) {
if (u.getPassword().equals(hashedPw)) {
Log.d(TAG, "password is equal to the one in db");
}
else {
u.setPassword(hashedPw);
}
// setze diesen User als aktiv!
u.setStatus(1);
u.setStored(loginState);
helper.getUserDao().update(u);
loggedInUser = u;
}
}
} catch (SQLException e) {
Log.d(TAG, "error while storing login" + e.getMessage());
}
return loggedInUser;
}
public Comment addComment(Comment cmt) {
Comment retVal = null;
if (cmt == null) {
throw new IllegalArgumentException("cannot create a comment entry in database without comment");
}
try {
retVal = helper.getCommentDao().createIfNotExists(cmt);
} catch (SQLException e) {
e.printStackTrace();
}
return retVal;
}
public Attachment addAttachment(Attachment att) {
if (att == null) {
throw new IllegalArgumentException(
"cannot create attachment entry in database without attachment");
}
Attachment dbAttach = null;
try {
dbAttach = helper.getAttachmentDao().createIfNotExists(att);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dbAttach;
}
public Job addJob(Job job) {
Job dbJob = null;
if (job == null) {
throw new IllegalArgumentException(
"no job given, cannot create an entry");
}
try {
QueryBuilder<Job, Integer> queryBuilder = helper.getJobDao()
.queryBuilder();
Where<Job, Integer> where = queryBuilder.where();
if (job.getInstanceId() == null)
where.isNull(Job.INSTANCE_ID);
else
where.eq(Job.INSTANCE_ID, job.getInstanceId());
where.and().eq(Job.COMMENT_ID, job.getComment().getComment()).and()
.eq(Job.ATTACH_ID, job.getAtach().getAttUri()).and()
.eq(Job.STATUS, "0").and()
.eq(Job.TARGET_ID, job.getTarget().getServiceEndpoint());
PreparedQuery<Job> prepareStmt = queryBuilder.prepare();
Log.d(TAG, "querystring is " + prepareStmt.getStatement());
List<Job> jobList = helper.getJobDao().query(prepareStmt);
if (jobList.isEmpty()) {
Log.d(TAG, "no job with these parameters given, need to create one");
Log.d(TAG, "job id is " + job.getId());
dbJob = helper.getJobDao().createIfNotExists(job);
Log.d(TAG, "dbJob id is " + dbJob.getId());
} else {
Log.d(TAG,
"job does already exists for this parameters, wont create new");
dbJob = jobList.get(0);
// hier comment und status usw updaten
}
} catch (SQLException e) {
Log.d(TAG, "Exception during adding a job to db: " + e.getMessage());
}
return dbJob;
}
public void attachInstanceIdToJob(String instanceId, long jobId) {
Log.d(TAG, "attaching instance id " + instanceId + " to job with id " + jobId);
try {
Job job = helper.getJobDao().queryForId((int) jobId);
if (job != null){
job.setInstanceId(instanceId);
helper.getJobDao().update(job);
}
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
Log.d(TAG, "error while attaching instance id " + instanceId + " to job with id " + jobId);
}
}
public List<Job> getAllOpenJobs() {
List<Job> jobList = null;
QueryBuilder<Job, Integer> queryBuilder;
try {
queryBuilder = helper.getJobDao()
.queryBuilder();
Where<Job, Integer> where = queryBuilder.where();
where.eq(Job.STATUS, JobStatusEnum.OPEN.getState())
.or().eq(Job.STATUS, JobStatusEnum.RETRY.getState());
;
PreparedQuery<Job> prepareStmt = queryBuilder.prepare();
Log.d(TAG, "querystring is " + prepareStmt.getStatement());
jobList = helper.getJobDao().query(prepareStmt);
} catch (SQLException e) {
Log.d(TAG, "error while retrieving open jobs from db" + e.getMessage());
}
return jobList;
}
public void getDataForJob(Job j, User u, Attachment att, Target target, Comment comment) {
try {
if (j != null){
helper.getUserDao().refresh(j.getUser());
helper.getAttachmentDao().refresh(j.getAtach());
helper.getTargetDao().refresh(j.getTarget());
helper.getCommentDao().refresh(j.getComment());
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public User getCurrentStoredUser(){
try {
List<User> users = helper.getUserDao().queryForAll();
for (User u: users){
if (u.getStored() == 1){
return u;
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public void updateJob(Job j) {
if (j != null){
try {
helper.getJobDao().update(j);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/**
* The status of the given user will be configured to stored. All others will be set to unstored
* #param loggedInUser
*/
public void setUserStatusToStored(User loggedInUser) {
List<User> listOfUsers;
try {
listOfUsers = helper.getUserDao().queryForAll();
for (User u: listOfUsers){
if (u.equals(loggedInUser)){
u.setStatus(UserStatusEnum.STORED.getState());
}
else{
u.setStatus(UserStatusEnum.UNSTORED.getState());
}
helper.getUserDao().update(u);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
and my TestClass
public class DBManagerTest
extends TestCase
{
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void testDBManager() {
fail( "Not yet implemented" );
}
}
Can someone help me with shat, I guess once the first test is running the others should be clear.
Thanks

Categories

Resources