Exemplo n.º 1
0
  /**
   * Adds a link.
   *
   * @param owner the owning Entity
   * @param pathIn the path (url, filepath, or entity key)
   * @param linkType the link type
   * @throws Exception the exception
   */
  public void addLink(KeyedEntity<?> owner, String pathIn, LinkType linkType) throws Exception {
    String path = pathIn;
    if (owner == null) {
      Errmsg.getErrorHandler().notice(Resource.getResourceString("att_owner_null"));
      return;
    }

    if (linkType == LinkType.ATTACHMENT) {

      String atfolder = attachmentFolder();
      if (atfolder == null) throw new Exception("attachments not supported");

      // need to copy file and create new path
      File orig = new File(path);
      String fname = orig.getName();
      String newpath = atfolder + "/" + fname;

      int i = 1;
      while (true) {
        File newfile = new File(newpath);
        if (!newfile.exists()) break;

        fname = Integer.toString(i) + orig.getName();
        newpath = atfolder + "/" + fname;
        i++;
      }

      copyFile(path, newpath);
      path = fname;
    }

    Link at = newLink();
    at.setKey(-1);
    at.setOwnerKey(new Integer(owner.getKey()));
    LinkType type = typemap.get(owner.getClass());
    if (type == null) throw new Exception("illegal link owner type");
    at.setOwnerType(type.toString());
    at.setPath(path);
    at.setLinkType(linkType.toString());
    saveLink(at);

    // * modification for backtrace/2way link

    if (linkType == LinkType.ADDRESS
        || linkType == LinkType.APPOINTMENT
        || linkType == LinkType.PROJECT
        || linkType == LinkType.TASK) {
      Link at2way = newLink();
      at2way.setKey(-1);
      at2way.setOwnerKey(new Integer(at.getPath()));
      at2way.setOwnerType(at.getLinkType());
      at2way.setPath(at.getOwnerKey().toString());
      at2way.setLinkType(at.getOwnerType());
      saveLink(at2way);
    }
    // end of modification

  }
Exemplo n.º 2
0
  /* (non-Javadoc)
   * @see net.sf.borg.model.db.EntityDB#addObj(net.sf.borg.model.entity.KeyedEntity)
   */
  @Override
  public void addObj(Link att) throws Exception {
    PreparedStatement stmt =
        JdbcDB.getConnection()
            .prepareStatement(
                "INSERT INTO links ( id, linktype, ownerkey, ownertype, path) "
                    + " VALUES "
                    + "( ?, ?, ?, ?, ?)");

    stmt.setInt(1, att.getKey());
    stmt.setString(2, att.getLinkType());
    stmt.setInt(3, JdbcDB.toInt(att.getOwnerKey()));
    stmt.setString(4, att.getOwnerType());
    stmt.setString(5, att.getPath());

    stmt.executeUpdate();
    stmt.close();

    writeCache(att);
  }
Exemplo n.º 3
0
  /* (non-Javadoc)
   * @see net.sf.borg.model.db.EntityDB#updateObj(net.sf.borg.model.entity.KeyedEntity)
   */
  @Override
  public void updateObj(Link att) throws Exception {

    PreparedStatement stmt =
        JdbcDB.getConnection()
            .prepareStatement(
                "UPDATE links SET linktype = ?, ownerkey = ?, ownertype = ?, path = ?"
                    + " WHERE id = ?");

    stmt.setString(1, att.getLinkType());
    stmt.setInt(2, att.getOwnerKey().intValue());
    stmt.setString(3, att.getOwnerType());
    stmt.setString(4, att.getPath());
    stmt.setInt(5, att.getKey());

    stmt.executeUpdate();
    stmt.close();

    delCache(att.getKey());
    writeCache(att);
  }