class EnClient::DBUtils

Public Class Methods

exist_tag_in_cache?(dm, guid) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1443
def self.exist_tag_in_cache?(dm, guid)
  dm.transaction do
    dm.open_tag do |db|
      if db.has_key? guid
        return true
      end
    end
  end
  return false
end
get_all_notebooks(dm) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1392
def self.get_all_notebooks(dm)
  notebooks = []
  dm.transaction do
    dm.open_notebook do |db|
      db.each_value do |value|
        nb = Evernote::EDAM::Type::Notebook.new
        nb.deserialize value
        notebooks << nb
      end
    end
  end
  notebooks
end
get_all_searches(dm) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1462
def self.get_all_searches(dm)
  searches = []
  dm.transaction do
    dm.open_search do |db|
      db.each_value do |value|
        s = Evernote::EDAM::Type::SavedSearch.new
        s.deserialize value
        searches << s
      end
    end
  end
  searches
end
get_all_tags(dm) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1429
def self.get_all_tags(dm)
  tags = []
  dm.transaction do
    dm.open_tag do |db|
      db.each_value do |value|
        t = Evernote::EDAM::Type::Tag.new
        t.deserialize value
        tags << t
      end
    end
  end
  tags
end
get_last_sync_and_usn(dm) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1361
def self.get_last_sync_and_usn(dm)
  last_sync, usn = nil, nil
  dm.transaction do
    dm.open_sync do |db|
      last_sync, usn = db[DBManager::DB_SYNC_LAST_SYNC_FIELD], db[DBManager::DB_SYNC_USN_FIELD]
    end
  end

  if last_sync
    last_sync = last_sync.to_i
  else
    last_sync = 0
  end
  if usn
    usn = usn.to_i
  else
    usn = 0
  end

  [last_sync, usn]
end
get_note(dm, guid) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1406
def self.get_note(dm, guid)
  note = Evernote::EDAM::Type::Note.new
  dm.transaction do
    dm.open_note do |db|
      if db.has_key? guid
        note.deserialize db[guid]
      else
        raise NotFoundException.new("Note guid #{guid} is not found")
      end
    end
  end
  note
end
set_last_sync_and_usn(dm, last_sync, usn) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1383
def self.set_last_sync_and_usn(dm, last_sync, usn)
  dm.transaction do
    dm.open_sync do |db|
      db[DBManager::DB_SYNC_LAST_SYNC_FIELD] = last_sync.to_s
      db[DBManager::DB_SYNC_USN_FIELD] = usn.to_s
    end
  end
end
set_note_and_content(dm, note, content) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1420
def self.set_note_and_content(dm, note, content)
  dm.transaction do
    dm.open_note do |db|
      note.contentFile = dm.set_note_content note.guid, content if content
      db[note.guid] = note.serialize
    end
  end
end
set_notebook(dm, notebook) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1484
def self.set_notebook(dm, notebook)
  dm.transaction do
    dm.open_notebook do |db|
      if notebook.defaultNotebook
        # unset defaultNotebook of all notebooks
        db.each_value do |value|
          n = Evernote::EDAM::Type::Notebook.new
          n.deserialize value
          if n.guid != notebook.guid
            n.defaultNotebook = false
            db[n.guid] = n.serialize
          end
        end
      end
      db[notebook.guid] = notebook.serialize
    end
  end
end
set_tag(dm, tag) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1454
def self.set_tag(dm, tag)
  dm.transaction do
    dm.open_tag do |db|
      db[tag.guid] = tag.serialize
    end
  end
end
sync_expunged_notebooks(dm, guids) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1578
def self.sync_expunged_notebooks(dm, guids)
  dm.transaction do
    dm.open_notebook do |db|
      guids.each do |guid|
        db.delete guid
      end
    end
  end
end
sync_expunged_notes(dm, guids, tm = nil) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1588
def self.sync_expunged_notes(dm, guids, tm = nil)
  dm.transaction do
    dm.open_note do |db|
      guids.each do |guid|
        dm.remove_note_content guid # remove content cache if updated
        db.delete guid
      end
    end
  end
end
sync_expunged_searches(dm, guids) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1609
def self.sync_expunged_searches(dm, guids)
  dm.transaction do
    dm.open_search do |db|
      guids.each do |guid|
        db.delete guid
      end
    end
  end
end
sync_expunged_tags(dm, guids) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1599
def self.sync_expunged_tags(dm, guids)
  dm.transaction do
    dm.open_tag do |db|
      guids.each do |guid|
        db.delete guid
      end
    end
  end
end
sync_updated_notebooks(dm, notebooks) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1503
def self.sync_updated_notebooks(dm, notebooks)
  dm.transaction do
    dm.open_notebook do |db|
      notebooks.each do |new_notebook|
        if db.has_key? new_notebook.guid
          current_notebook = Evernote::EDAM::Type::Notebook.new
          current_notebook.deserialize db[new_notebook.guid]
          if current_notebook.updateSequenceNum < new_notebook.updateSequenceNum
            db[new_notebook.guid] = new_notebook.serialize
          end
        else
          db[new_notebook.guid] = new_notebook.serialize
        end
      end
    end
  end
end
sync_updated_notes(dm, sm, tm, notes) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1521
def self.sync_updated_notes(dm, sm, tm, notes)
  dm.transaction do
    dm.open_note do |db|
      notes.each do |new_note|
        # this method set editMode.
        new_note.editMode = Formatter.get_edit_mode new_note.attributes.sourceApplication
        if db.has_key? new_note.guid
          current_note = Evernote::EDAM::Type::Note.new
          current_note.deserialize db[new_note.guid]
          if current_note.updateSequenceNum < new_note.updateSequenceNum
            dm.remove_note_content new_note.guid # remove content cache if updated
            db[new_note.guid] = new_note.serialize # update note info
          end
        else
          db[new_note.guid] = new_note.serialize
        end
      end
    end
  end
end
sync_updated_searches(dm, searches) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1560
def self.sync_updated_searches(dm, searches)
  dm.transaction do
    dm.open_search do |db|
      searches.each do |new_search|
        if db.has_key? new_search.guid
          current_search = Evernote::EDAM::Type::SavedSearch.new
          current_search.deserialize db[new_search.guid]
          if current_search.updateSequenceNum < new_search.updateSequenceNum
            db[new_search.guid] = new_search.serialize
          end
        else
          db[new_search.guid] = new_search.serialize
        end
      end
    end
  end
end
sync_updated_tags(dm, tags) click to toggle source
# File usr/lib/evernote-mode/enclient.rb, line 1542
def self.sync_updated_tags(dm, tags)
  dm.transaction do
    dm.open_tag do |db|
      tags.each do |new_tag|
        if db.has_key? new_tag.guid
          current_tag = Evernote::EDAM::Type::Tag.new
          current_tag.deserialize db[new_tag.guid]
          if current_tag.updateSequenceNum < new_tag.updateSequenceNum
            db[new_tag.guid] = new_tag.serialize
          end
        else
          db[new_tag.guid] = new_tag.serialize
        end
      end
    end
  end
end