Beispiel #1
0
  /**
   * Initaialization: Create the table mappings (@see PersistentObject), check the version and
   * create or update the table if necessary
   */
  static {
    addMapping(
        TABLENAME,
        FLD_PARENT,
        FLD_TITLE,
        FLD_CONTENTS,
        "Datum=S:D:Date",
        FLD_REFS,
        FLD_KEYWORDS,
        FLD_MIMETYPE);
    Note start = load("1"); // $NON-NLS-1$
    if (!start.exists()) {
      createOrModifyTable(create);
    } else {
      VersionInfo vi = new VersionInfo(start.get(FLD_TITLE));
      if (vi.isOlder(DBVERSION)) {
        if (vi.isOlder("0.2.0")) { // $NON-NLS-1$
          getConnection()
              .exec(
                  "ALTER TABLE "
                      + TABLENAME
                      + " ADD deleted CHAR(1) default '0';"); //$NON-NLS-1$ //$NON-NLS-2$
        }
        if (vi.isOlder("0.3.1")) { // $NON-NLS-1$
          createOrModifyTable(upd031);
        }
        if (vi.isOlder("0.3.2")) { // $NON-NLS-1$
          createOrModifyTable(upd032);
        }

        start.set(FLD_TITLE, DBVERSION);
      }
    }
  }
Beispiel #2
0
 @Override
 public boolean delete() {
   Query<Note> qbe = new Query<Note>(Note.class);
   qbe.add(FLD_PARENT, Query.EQUALS, getId());
   List<Note> list = qbe.execute();
   for (Note note : list) {
     note.delete();
   }
   return super.delete();
 }
    @Override
    public boolean select(Viewer viewer, Object parentElement, Object element) {

      if (filterExpr.length() == 0) {
        return true;
      }
      boolean bMatch = isMatch((Note) element, filterExpr);
      if (bMatch) {
        Note parent = (Note) element;
        while ((parent = parent.getParent()) != null) {
          matches.put(parent, filterExpr);
        }
      }
      return bMatch;
    }
Beispiel #4
0
 /**
  * find the parent note of this note
  *
  * @return the parent note or null if this is a top level note.
  */
 public Note getParent() {
   String pid = get(FLD_PARENT);
   if (pid == null) {
     return null;
   }
   Note p = Note.load(pid);
   return p;
 }
Beispiel #5
0
 /**
  * Create a new Note with binary content
  *
  * @param parent the parent note or null if this is a top level note
  * @param title a Title for this note
  * @param contents the contents of this note in
  * @param mimettype the mimetype of the contents
  */
 public Note(Note parent, String title, byte[] contents, String mimetype) {
   create(null);
   set(
       new String[] {FLD_TITLE, FLD_DATE, FLD_MIMETYPE},
       title,
       new TimeTool().toString(TimeTool.DATE_GER),
       mimetype);
   setContent(contents);
   if (parent != null) {
     set(FLD_PARENT, parent.getId());
   }
 }
    private boolean isMatch(Note n, String t) {
      if (matches.get(n) != null) {
        return true;
      }

      String lbl = n.getLabel().toLowerCase();
      if (lbl.startsWith(t) || n.getKeywords().contains(t)) {
        matches.put(n, t);

        return true;
      }

      List<Note> l = n.getChildren();
      for (Note note : l) {
        if (isMatch(note, t)) {
          matches.put(n, t);
          return true;
        }
      }
      return false;
    }
Beispiel #7
0
 /**
  * Create a new Note with text content
  *
  * @param parent the parent note or null if this is a top level note
  * @param title a Title for this note
  * @param text the text content of this note
  */
 public Note(Note parent, String title, String text) {
   create(null);
   set(
       new String[] {FLD_TITLE, FLD_DATE, FLD_MIMETYPE},
       title,
       new TimeTool().toString(TimeTool.DATE_GER),
       "text/plain"); //$NON-NLS-1$
   try {
     setContent(text.getBytes("utf-8")); // $NON-NLS-1$
   } catch (UnsupportedEncodingException e) {
     ExHandler.handle(e);
     // should never happen
   }
   if (parent != null) {
     set(FLD_PARENT, parent.getId());
   }
 }