Ejemplo n.º 1
0
  @Override
  public void visit(Field aField) {
    try {
      NamedNodeMap attrs = currentTag.getAttributes();
      Node a = attrs.getNamedItem(NAME_ATTR_NAME);
      if (a != null) {
        aField.setName(a.getNodeValue());
      }
      a = attrs.getNamedItem(DESCRIPTION_ATTR_NAME);
      if (a != null) {
        aField.setDescription(a.getNodeValue());
      }
      a = attrs.getNamedItem(TYPE_ATTR_NAME);
      if (a != null) {
        aField.setType(a.getNodeValue());
      }
      aField.setNullable(readBooleanAttribute(NULLABLE_ATTR_NAME, true));
      aField.setPk(readBooleanAttribute(IS_PK_ATTR_NAME, false));

      if (aField instanceof Parameter) {
        ((Parameter) aField).setMode(readIntegerAttribute(MODE_ATTR_NAME, 0 /*
																					 * ParameterMetaData.
																					 * parameterModeUnknown
																					 */));
        if (currentTag.getAttributes().getNamedItem(SELECTION_FORM_TAG_NAME) != null
            && !"null"
                .equals(
                    currentTag
                        .getAttributes()
                        .getNamedItem(SELECTION_FORM_TAG_NAME)
                        .getNodeValue()))
          ((Parameter) aField).setSelectionForm(readDoubleAttribute(SELECTION_FORM_TAG_NAME, null));
      }
      Element lcurrentTag = currentTag;
      try {
        currentTag = Utils.getElementByTagName(currentTag, PRIMARY_KEY_TAG_NAME);
        if (currentTag != null) {
          PrimaryKeySpec pk = new PrimaryKeySpec();
          visit(pk);
          ForeignKeySpec fk =
              new ForeignKeySpec(
                  "",
                  "",
                  "",
                  "",
                  ForeignKeySpec.ForeignKeyRule.CASCADE,
                  ForeignKeySpec.ForeignKeyRule.CASCADE,
                  false,
                  pk.getSchema(),
                  pk.getTable(),
                  pk.getField(),
                  pk.getCName());
          aField.setFk(fk);
        }
      } finally {
        currentTag = lcurrentTag;
      }
    } catch (NumberFormatException ex) {
      Logger.getLogger(XmlDom2Model.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Ejemplo n.º 2
0
  @Override
  public JSObject execute(
      Scripts.Space aSpace, Consumer<JSObject> onSuccess, Consumer<Exception> onFailure)
      throws Exception {
    assert Scripts.getSpace() == aSpace : "Scripts.Space TLS assumption failed";
    if (onSuccess != null) {
      ScriptedResource._require(
          new String[] {entityName},
          null,
          aSpace,
          new HashSet<>(),
          (Void v) -> {
            JSObject source = aSpace.createModule(entityName);
            if (source.hasMember("fetch")) {
              Object oFetch = source.getMember("fetch");
              if (oFetch instanceof JSObject) {
                JSObject jsFetch = (JSObject) oFetch;
                if (jsFetch.isFunction()) {
                  JSObject jsParams = aSpace.makeObj();
                  for (int i = 0; i < params.getParametersCount(); i++) {
                    Parameter p = params.get(i + 1);
                    jsParams.setMember(p.getName(), aSpace.toJs(p.getValue()));
                  }
                  final ExecutionChecker exChecker = new ExecutionChecker();
                  Object oRowset =
                      jsFetch.call(
                          source,
                          aSpace.toJs(
                              new Object[] {
                                jsParams,
                                new AbstractJSObject() {

                                  @Override
                                  public Object call(final Object thiz, final Object... args) {
                                    if (exChecker.isExecutionNeeded()) {
                                      try {
                                        JSObject jsRowset =
                                            args.length > 0
                                                ? (JSObject) aSpace.toJava(args[0])
                                                : null;
                                        try {
                                          onSuccess.accept(jsRowset);
                                        } catch (Exception ex) {
                                          Logger.getLogger(ScriptedQuery.class.getName())
                                              .log(Level.SEVERE, null, ex);
                                        }
                                      } catch (Exception ex) {
                                        if (onFailure != null) {
                                          onFailure.accept(ex);
                                        }
                                      }
                                    }
                                    return null;
                                  }
                                },
                                new AbstractJSObject() {

                                  @Override
                                  public Object call(final Object thiz, final Object... args) {
                                    if (exChecker.isExecutionNeeded()) {
                                      if (onFailure != null) {
                                        if (args.length > 0) {
                                          if (args[0] instanceof Exception) {
                                            onFailure.accept((Exception) args[0]);
                                          } else {
                                            onFailure.accept(
                                                new Exception(
                                                    String.valueOf(aSpace.toJava(args[0]))));
                                          }
                                        } else {
                                          onFailure.accept(
                                              new Exception(
                                                  "No error information from fetch method"));
                                        }
                                      }
                                    }
                                    return null;
                                  }
                                }
                              }));
                  if (!JSType.nullOrUndefined(oRowset)) {
                    onSuccess.accept((JSObject) aSpace.toJava(oRowset));
                    exChecker.setExecutionNeeded(false);
                  }
                }
              }
            }
          },
          onFailure);
      return null;
    } else {
      JSObject source = aSpace.createModule(entityName);
      if (source.hasMember("fetch")) {
        Object oFetch = source.getMember("fetch");
        if (oFetch instanceof JSObject) {
          JSObject jsFetch = (JSObject) oFetch;
          if (jsFetch.isFunction()) {
            JSObject jsParams = aSpace.makeObj();
            Object oRowset = jsFetch.call(source, aSpace.toJs(new Object[] {jsParams}));
            if (!JSType.nullOrUndefined(oRowset)) {
              return (JSObject) aSpace.toJava(oRowset);
            }
          }
        }
      }
      return null;
    }
  }