Esempio n. 1
0
  /**
   * ** Gets a virtual DBRecord from the specified remote service ** @param servReq The remote web
   * service ** @return The virtual DBRecord (cannot be saved or reloaded)
   */
  @SuppressWarnings("unchecked")
  public gDBR getVirtualDBRecord(final ServiceRequest servReq) throws DBException {
    String CMD_dbget = DBFactory.CMD_dbget;
    String TAG_Response = servReq.getTagResponse();
    String TAG_Record = DBFactory.TAG_Record;
    String ATTR_command = servReq.getAttrCommand();
    String ATTR_result = servReq.getAttrResult();

    /* send request / get response */
    Document xmlDoc = null;
    try {
      xmlDoc =
          servReq.sendRequest(
              CMD_dbget,
              new ServiceRequest.RequestBody() {
                public StringBuffer appendRequestBody(StringBuffer sb, int indent) {
                  return DBRecordKey.this.toRequestXML(sb, indent);
                }
              });
    } catch (IOException ioe) {
      Print.logException("Error", ioe);
      throw new DBException("Request read error", ioe);
    }

    /* parse 'GTSResponse' */
    Element gtsResponse = xmlDoc.getDocumentElement();
    if (!gtsResponse.getTagName().equalsIgnoreCase(TAG_Response)) {
      Print.logError("Request XML does not start with '%s'", TAG_Response);
      throw new DBException("Response XML does not begin eith '" + TAG_Response + "'");
    }

    /* request command/argument */
    String cmd = StringTools.trim(gtsResponse.getAttribute(ATTR_command));
    String result = StringTools.trim(gtsResponse.getAttribute(ATTR_result));
    if (StringTools.isBlank(result)) {
      result = StringTools.trim(gtsResponse.getAttribute("type"));
    }
    if (!result.equalsIgnoreCase("success")) {
      Print.logError("Response indicates failure");
      throw new DBException("Response does not indicate 'success'");
    }

    /* Record */
    NodeList rcdList = XMLTools.getChildElements(gtsResponse, TAG_Record);
    if (rcdList.getLength() <= 0) {
      Print.logError("No 'Record' tags");
      throw new DBException("GTSResponse does not contain any 'Record' tags");
    }
    Element rcdElem = (Element) rcdList.item(0);

    /* return DBRecord */
    gDBR dbr = (gDBR) DBFactory.parseXML_DBRecord(rcdElem);
    dbr.setVirtual(true);
    return dbr;
  }
Esempio n. 2
0
 JdbcIndexDefinition(
     DataSource ds,
     Element element,
     Set allIndexedFields,
     boolean storeText,
     boolean mergeText,
     Analyzer a,
     boolean isSub) {
   this.dataSource = ds;
   indexSql = element.getAttribute("sql");
   key = element.getAttribute("key");
   String elementId = element.getAttribute("identifier");
   identifier = "".equals(elementId) ? key : elementId;
   findSql = element.getAttribute("find");
   NodeList childNodes = element.getChildNodes();
   for (int k = 0; k < childNodes.getLength(); k++) {
     if (childNodes.item(k) instanceof Element) {
       Element childElement = (Element) childNodes.item(k);
       if ("field".equals(childElement.getLocalName())) {
         if (childElement.getAttribute("keyword").equals("true")) {
           keyWords.add(childElement.getAttribute("name"));
         }
         String m = childElement.getAttribute("multiple");
         if ("".equals(m)) m = "add";
         if (!m.equals("add")) {
           nonDefaultMultiples.put(
               childElement.getAttribute("name"), Indexer.Multiple.valueOf(m.toUpperCase()));
         }
         String b = childElement.getAttribute("boost");
         if (!b.equals("")) {
           boosts.put(childElement.getAttribute("name"), Float.valueOf(b));
         }
       } else if ("related".equals(childElement.getLocalName())) {
         subQueries.add(
             new JdbcIndexDefinition(
                 ds, childElement, allIndexedFields, storeText, mergeText, a, true));
       }
     }
   }
   this.analyzer = a;
   this.isSub = isSub;
   assert !isSub || "".equals(findSql);
 }