Android Open Source - nl.fhict.intellicloud.answers.android Question Data Source






From Project

Back to project page nl.fhict.intellicloud.answers.android.

License

The source code is released under:

Apache License

If you think the Android project nl.fhict.intellicloud.answers.android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package nl.fhict.intellicloud.answers.backendcommunication;
//w  w w .  j av  a2  s. c  o  m
import java.util.ArrayList;
import java.util.Date;

import nl.fhict.intellicloud.answers.Question;
import nl.fhict.intellicloud.answers.QuestionState;
import nl.fhict.intellicloud.answers.User;
import nl.fhict.intellicloud.answers.UserType;
import nl.fhict.intellicloud.answers.backendcommunication.IntellicloudDbContract.*;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class QuestionDataSource implements IQuestionService {
  private SQLiteDatabase database;
  private LocalStorageSQLiteHelper dbHelper;
  private Context context;
  IAnswerService answerService;
  private final String[] allColumns = { QuestionsEntry.COLUMN_ID, 
                  QuestionsEntry.COLUMN_BACKEND_ID,
                  QuestionsEntry.COLUMN_ANSWERER_ID,
                  QuestionsEntry.COLUMN_ASKER_ID, 
                  QuestionsEntry.COLUMN_DATE, 
                  QuestionsEntry.COLUMN_QUESTION, 
                  QuestionsEntry.COLUMN_QUESTIONSTATE,
                  QuestionsEntry.COLUMN_IS_PRIVATE,
                  QuestionsEntry.COLUMN_TITLE,
                  QuestionsEntry.COLUMN_ANSWER_ID};
  
  
  public QuestionDataSource(Context context) {
    dbHelper = new LocalStorageSQLiteHelper(context);
    this.context = context;
    
  }
  
  private void open() throws SQLException {
    database = dbHelper.getWritableDatabase();
  }
  
  private void close() {
    dbHelper.close();
  }

  @Override
  public Question GetQuestion(int id) {
    answerService = new AnswerDataSource(context);
    open();
    Question question = null;
    Cursor cursor = database.query(QuestionsEntry.TABLE_NAME, allColumns, QuestionsEntry.COLUMN_BACKEND_ID + " == " + id, null, null, null, null);
    if (cursor.moveToFirst())
    {
      
      question = getNextQuestionFromCursor(cursor);
      
    }
    cursor.close();
    close();
    return question;
  }

  @Override
  public ArrayList<Question> GetQuestions() {
    return GetQuestions(-1);
  }

  @Override
  public ArrayList<Question> GetQuestions(int employeeId) {
    answerService = new AnswerDataSource(context);
    String employeeFilter = null;
    if (employeeId >= 0)
    {
      employeeFilter = QuestionsEntry.COLUMN_ANSWERER_ID + " = " + employeeId;
    }
    ArrayList<Question> filteredQuestions = new ArrayList<Question>();
    open();
    Cursor cursor = database.query(QuestionsEntry.TABLE_NAME, allColumns, employeeFilter, null, null, null, null);
    cursor.moveToFirst();
    
    while (!cursor.isAfterLast()) {
      filteredQuestions.add(getNextQuestionFromCursor(cursor));
      cursor.moveToNext();
    }
    cursor.close();
    close();
    return filteredQuestions;
  }

  
  private Question getNextQuestionFromCursor(Cursor cursor)
  {
    
    Long unixMilliSeconds = cursor.getLong(4);
    Question question = new Question(cursor.getInt(1), 
                cursor.getString(5), 
                UserDataSource.GetUser(cursor.getInt(3), database), 
                UserDataSource.GetUser(cursor.getInt(2), database),
                QuestionState.valueOf(cursor.getString(6)), 
                new Date(unixMilliSeconds));
    question.setIsPrivate(cursor.getInt(7) > 0);
    question.setTitle(cursor.getString(8));
    int answerId = cursor.getInt(9);
    question.setAnswer(answerService.GetAnswer(answerId));
    return question;
  }

  @Override
  public void UpdateQuestion(Question question) {
    ContentValues values = new ContentValues();
    values.put(QuestionsEntry.COLUMN_QUESTIONSTATE, question.getQuestionState().toString());
    if (question.getAnswer() != null)
    {
      values.put(QuestionsEntry.COLUMN_ANSWER_ID, question.getAnswer().getId());
    }

  
    open();
    database.update(QuestionsEntry.TABLE_NAME, values, QuestionsEntry.COLUMN_BACKEND_ID + " = " + question.getId(), null);
    close();
    
  }

  @Override
  public Question GetQuestionUsingAnswer(int answerId) {
    open();
    Question question = null;
    Cursor cursor = database.query(QuestionsEntry.TABLE_NAME, allColumns, QuestionsEntry.COLUMN_ANSWER_ID + " = " + answerId, null, null, null, null);
    if (cursor.moveToFirst())
    {
      
      question = getNextQuestionFromCursor(cursor);
      
    }
    cursor.close();
    close();
    return question;
  }
  
}




Java Source Code List

nl.fhict.intellicloud.answers.AddReviewActivity.java
nl.fhict.intellicloud.answers.AnswerState.java
nl.fhict.intellicloud.answers.Answer.java
nl.fhict.intellicloud.answers.AuthorizationActivity.java
nl.fhict.intellicloud.answers.FeedbackState.java
nl.fhict.intellicloud.answers.FeedbackType.java
nl.fhict.intellicloud.answers.Feedback.java
nl.fhict.intellicloud.answers.FilterList.java
nl.fhict.intellicloud.answers.GetUserIdTask.java
nl.fhict.intellicloud.answers.IUserFoundObserver.java
nl.fhict.intellicloud.answers.IncomingQuestionsListAdapter.java
nl.fhict.intellicloud.answers.ListFragment.java
nl.fhict.intellicloud.answers.MainActivity.java
nl.fhict.intellicloud.answers.OriginalAnswerActivity.java
nl.fhict.intellicloud.answers.QuestionListOnClickListener.java
nl.fhict.intellicloud.answers.QuestionState.java
nl.fhict.intellicloud.answers.Question.java
nl.fhict.intellicloud.answers.RejectedAnswerActivity.java
nl.fhict.intellicloud.answers.ReviewListAdapter.java
nl.fhict.intellicloud.answers.ReviewOverviewActivity.java
nl.fhict.intellicloud.answers.ReviewState.java
nl.fhict.intellicloud.answers.Review.java
nl.fhict.intellicloud.answers.SendAnswerActivity.java
nl.fhict.intellicloud.answers.SlidingMenuListAdapter.java
nl.fhict.intellicloud.answers.UserType.java
nl.fhict.intellicloud.answers.User.java
nl.fhict.intellicloud.answers.backendcommunication.AnswerDataSource.java
nl.fhict.intellicloud.answers.backendcommunication.AnswerSync.java
nl.fhict.intellicloud.answers.backendcommunication.AuthenticatorService.java
nl.fhict.intellicloud.answers.backendcommunication.Authenticator.java
nl.fhict.intellicloud.answers.backendcommunication.BackendContentProvider.java
nl.fhict.intellicloud.answers.backendcommunication.BackendSyncAdapter.java
nl.fhict.intellicloud.answers.backendcommunication.BackendSyncService.java
nl.fhict.intellicloud.answers.backendcommunication.DummyBackend.java
nl.fhict.intellicloud.answers.backendcommunication.IAnswerService.java
nl.fhict.intellicloud.answers.backendcommunication.IClaimService.java
nl.fhict.intellicloud.answers.backendcommunication.IQuestionService.java
nl.fhict.intellicloud.answers.backendcommunication.IReviewService.java
nl.fhict.intellicloud.answers.backendcommunication.IUserService.java
nl.fhict.intellicloud.answers.backendcommunication.IntellicloudDbContract.java
nl.fhict.intellicloud.answers.backendcommunication.LocalStorageSQLiteHelper.java
nl.fhict.intellicloud.answers.backendcommunication.QuestionDataSource.java
nl.fhict.intellicloud.answers.backendcommunication.QuestionsSync.java
nl.fhict.intellicloud.answers.backendcommunication.ReviewDataSource.java
nl.fhict.intellicloud.answers.backendcommunication.ReviewSync.java
nl.fhict.intellicloud.answers.backendcommunication.ServerAccessor.java
nl.fhict.intellicloud.answers.backendcommunication.SyncHelper.java
nl.fhict.intellicloud.answers.backendcommunication.UserDataSource.java
nl.fhict.intellicloud.answers.backendcommunication.UserSync.java
nl.fhict.intellicloud.answers.backendcommunication.oauth.AuthenticationManager.java