private Column[] createColumns(Table t, JsStringArray colNames) {
   Column[] result = new Column[colNames.size()];
   for (int i = 0; i < result.length; i++) {
     result[i] = t.getColumn(colNames.get(i));
   }
   return result;
 }
Esempio n. 2
0
  // XXX better place for this?
  // only internal "optimisation"?
  public void addReverseConstraints() {
    List<ConstraintReferential> crs = new ArrayList<ConstraintReferential>();
    for (Table t : getTables()) {
      for (Constraint c : t.getConstraints()) {
        if (c instanceof ConstraintReferential) {
          crs.add((ConstraintReferential) c);
        }
      }
    }

    for (ConstraintReferential cr : crs) {
      String title = cr.getRevName();
      if (title == null) {
        title = "Rev " + cr.getName();
      }
      ConstraintReferential cr2 = new ConstraintReferential(title, cr.getRefTable());
      cr2.setRefColumns(cr.getColumns());
      cr2.setColumns(cr.getRefColumns());
      cr2.setRefTable(cr.getTable());
      cr.getRefTable().add(cr2);
      cr2.setHidden(cr.isRevHidden());
    }
  }
Esempio n. 3
0
 public void add(Table p) {
   tables.put(p.getName().toUpperCase(), p);
 }
  private void addSchema(Database database, JsDatabase meta) {
    if (meta == null) {
      throw new IllegalArgumentException("Meta is null.");
    }
    Type[] types = new Type[meta.getTypes().length()];
    for (int i = 0; i < types.length; i++) {
      JsType jsType = meta.getTypes().get(i);
      Type type = new Type(jsType.getName());
      type.setEditor(Editor.valueOf(jsType.getEditor()));
      Operator[] ops = new Operator[jsType.getOperators().length()];
      for (int j = 0; j < ops.length; j++) {
        JsOperator jsOp = jsType.getOperators().get(j);
        Operator op = new Operator(jsOp.getName());
        op.setLabel(jsOp.getLabel());
        String cardName = jsOp.getCardinality();
        if (cardName != null) {
          op.setCardinality(Cardinality.valueOf(cardName));
        }
        ops[j] = op;
      }
      type.setOperators(ops);
      types[i] = type;
      type.setStyleName(jsType.getStyleName());
    }

    database.setTypes(types);

    for (int i = 0; i < meta.getTables().length(); i++) {
      JsTable jst = meta.getTables().get(i);
      Table t = new Table(jst.getName());
      t.setLabel(jst.getLabel());
      for (int j = 0; j < jst.getColumns().length(); j++) {
        JsColumn jsColumn = jst.getColumns().get(j);
        Column c = new Column(jsColumn.getName(), database.getTypeByName(jsColumn.getType()));
        c.setLabel(jsColumn.getLabel());
        if (jsColumn.getEditor() != null) {
          c.setEditor(Editor.valueOf(jsColumn.getEditor()));
        }
        c.setStyleName(jsColumn.getStyleName());
        t.add(c);
      }
      database.getMainSchema().add(t);
    }

    for (int i = 0; i < meta.getTables().length(); i++) {
      JsTable jst = meta.getTables().get(i);

      Table pkTable = database.getMainSchema().findTableOrView(jst.getName());
      JsArray<JsFk> fks = jst.getFks();
      for (int j = 0; j < fks.length(); j++) {
        JsFk jsfk = fks.get(j);
        Table fkTable = database.getMainSchema().findTableOrView(jsfk.getFkTableName());

        ConstraintReferential fk = new ConstraintReferential(jsfk.getName(), pkTable);
        fk.setLabel(jsfk.getLabel());

        fk.setRefTable(fkTable);
        fk.setColumns(createColumns(pkTable, jsfk.getPkColumnNames()));
        fk.setRefColumns(createColumns(fkTable, jsfk.getFkColumnNames()));
        pkTable.add(fk);

        ConstraintReferential fkr = new ConstraintReferential(jsfk.getName() + ".reverse", fkTable);
        fkr.setLabel(jsfk.getReverseLabel());

        fkr.setRefTable(pkTable);
        fkr.setColumns(createColumns(fkTable, jsfk.getFkColumnNames())); // XXX
        // already
        // done
        // this
        fkr.setRefColumns(createColumns(pkTable, jsfk.getPkColumnNames())); // XXX
        // already
        // done
        // this
        fkTable.add(fkr);
      }
    }
  }