Android Open Source - geocamTalkForAndroid Message Store






From Project

Back to project page geocamTalkForAndroid.

License

The source code is released under:

NASA OPEN SOURCE AGREEMENT VERSION 1.3 THIS OPEN SOURCE AGREEMENT ("AGREEMENT") DEFINES THE RIGHTS OF USE, REPRODUCTION, DISTRIBUTION, MODIFICATION AND REDISTRIBUTION OF CERTAIN COMPUTER SOFTWARE ORI...

If you think the Android project geocamTalkForAndroid 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 gov.nasa.arc.geocam.talk.service;
/*w  w  w.j  a  v a2  s  .  c  om*/
import gov.nasa.arc.geocam.talk.bean.GeoCamTalkMessage;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

import android.content.res.Resources.NotFoundException;
import android.util.Log;

import com.google.inject.Inject;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.SelectArg;

/**
 * The Class MessageStore.
 */
public class MessageStore implements IMessageStore {

  /** The dao. */
  private Dao<GeoCamTalkMessage, Integer> dao;
  
  /** The intent helper. */
  private IIntentHelper intentHelper;
  
  /**
   * Instantiates a new message store.
   *
   * @param dbHelper the db helper
   * @param intentHelper the intent helper
   */
  @Inject
  public MessageStore(IDatabaseHelper dbHelper, IIntentHelper intentHelper)
  {
    this.intentHelper = intentHelper;
    
    try {
      this.dao = dbHelper.getGeoCamTalkMessageDao();
    } catch (SQLException e) {
      Log.e("GeoCam Talk", e.toString());
    }
  }
  
  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IMessageStore#synchronize()
   */
  @Override
  public void synchronize() {
    this.intentHelper.Synchronize();
  }
  
  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IMessageStore#getAllLocalMessages()
   */
  @Override
  public List<GeoCamTalkMessage> getAllLocalMessages() throws SQLException {
    QueryBuilder<GeoCamTalkMessage, Integer> qb = dao.queryBuilder();
    qb.where().eq(GeoCamTalkMessage.IS_SYNCHRONIZED_FIELD_NAME, false);
    
    SortedSet<GeoCamTalkMessage> hash = 
      new TreeSet<GeoCamTalkMessage>(Collections.reverseOrder());
    hash.addAll(dao.query(qb.prepare()));
    
    return new ArrayList<GeoCamTalkMessage>(hash);
  }

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IMessageStore#getAllMessages()
   */
  @Override
  public List<GeoCamTalkMessage> getAllMessages() throws SQLException {
    SortedSet<GeoCamTalkMessage> hash = 
      new TreeSet<GeoCamTalkMessage>(Collections.reverseOrder());
    hash.addAll(dao.queryForAll());
    return new ArrayList<GeoCamTalkMessage>(hash);
  }

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IMessageStore#getMessagesSince(java.util.Date)
   */
  @Override
  public List<GeoCamTalkMessage> getMessagesSince(Date sinceDate) throws SQLException{
    QueryBuilder<GeoCamTalkMessage, Integer> qb = dao.queryBuilder();
    SelectArg dateArg = new SelectArg();
    dateArg.setValue(sinceDate);
    qb.where().gt(GeoCamTalkMessage.DATE_FIELD_NAME, dateArg);
    List<GeoCamTalkMessage> list =
      dao.query(qb.prepare());
    return list;
  }

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IMessageStore#addMessage(java.util.List)
   */
  @Override
  public void addMessage(List<GeoCamTalkMessage> messages) throws SQLException{
    List<GeoCamTalkMessage> existingMessages = getAllMessages();
    
    for(GeoCamTalkMessage m:messages)
    {
      if(!existingMessages.contains(m))
      dao.create(m);
    }
  }

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IMessageStore#addMessage(gov.nasa.arc.geocam.talk.bean.GeoCamTalkMessage)
   */
  @Override
  public void addMessage(GeoCamTalkMessage message) throws SQLException {
    List<GeoCamTalkMessage> singleItemList = new ArrayList<GeoCamTalkMessage>();
    singleItemList.add(message);
    addMessage(singleItemList);
  }
  
  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IMessageStore#removeMessage(gov.nasa.arc.geocam.talk.bean.GeoCamTalkMessage)
   */
  @Override
  public void removeMessage(GeoCamTalkMessage message) throws SQLException {
    dao.delete(message);
  }
  
  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IMessageStore#updateMessage(gov.nasa.arc.geocam.talk.bean.GeoCamTalkMessage)
   */
  @Override
  public void updateMessage(GeoCamTalkMessage message) throws SQLException {
    dao.update(message);
  }

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.IMessageStore#getNewestMessageId()
   */
  @Override
  public int getNewestMessageId() throws SQLException, NotFoundException {
    QueryBuilder<GeoCamTalkMessage, Integer> qb = dao.queryBuilder();
    
    qb.where().eq(GeoCamTalkMessage.IS_SYNCHRONIZED_FIELD_NAME, true);
    qb.selectColumns(GeoCamTalkMessage.MESSAGE_ID_FIELD_NAME);
    qb.limit(1);
    qb.orderBy(GeoCamTalkMessage.MESSAGE_ID_FIELD_NAME, false);
    
    return dao.query(qb.prepare()).get(0).getMessageId();
  }
}




Java Source Code List

gov.nasa.arc.geocam.talk.GeoCamTalkModule.java
gov.nasa.arc.geocam.talk.GeoCamTalkRoboApplication.java
gov.nasa.arc.geocam.talk.UIUtils.java
gov.nasa.arc.geocam.talk.activity.AuthenticatedBaseActivity.java
gov.nasa.arc.geocam.talk.activity.GeoCamTalkActivity.java
gov.nasa.arc.geocam.talk.activity.GeoCamTalkCreateActivity.java
gov.nasa.arc.geocam.talk.activity.GeoCamTalkLogon.java
gov.nasa.arc.geocam.talk.activity.GeoCamTalkMapActivity.java
gov.nasa.arc.geocam.talk.activity.GeoCamTalkMessageAdapter.java
gov.nasa.arc.geocam.talk.activity.SettingsActivity.java
gov.nasa.arc.geocam.talk.bean.GeoCamTalkMessage.java
gov.nasa.arc.geocam.talk.bean.ServerResponse.java
gov.nasa.arc.geocam.talk.bean.TalkServerIntent.java
gov.nasa.arc.geocam.talk.exception.AuthenticationFailedException.java
gov.nasa.arc.geocam.talk.service.AudioPlayer.java
gov.nasa.arc.geocam.talk.service.AudioRecorder.java
gov.nasa.arc.geocam.talk.service.C2DMReciever.java
gov.nasa.arc.geocam.talk.service.DatabaseHelper.java
gov.nasa.arc.geocam.talk.service.GeoCamSynchronizationTimerTask.java
gov.nasa.arc.geocam.talk.service.GeoLocationListener.java
gov.nasa.arc.geocam.talk.service.IAudioPlayer.java
gov.nasa.arc.geocam.talk.service.IAudioRecorder.java
gov.nasa.arc.geocam.talk.service.IDatabaseHelper.java
gov.nasa.arc.geocam.talk.service.IGeoCamSynchronizationTimerTask.java
gov.nasa.arc.geocam.talk.service.IIntentHelper.java
gov.nasa.arc.geocam.talk.service.IMessageStore.java
gov.nasa.arc.geocam.talk.service.ISiteAuth.java
gov.nasa.arc.geocam.talk.service.ITalkJsonConverter.java
gov.nasa.arc.geocam.talk.service.ITalkServer.java
gov.nasa.arc.geocam.talk.service.IntentHelper.java
gov.nasa.arc.geocam.talk.service.MessageStore.java
gov.nasa.arc.geocam.talk.service.SiteAuthCookie.java
gov.nasa.arc.geocam.talk.service.TalkJsonConverter.java
gov.nasa.arc.geocam.talk.service.TalkMapOverlay.java
gov.nasa.arc.geocam.talk.service.TalkServer.java