Beispiel #1
0
  @Override
  public final String formatCSV(char delimiter, String nullString) {
    StringBuilder sb = new StringBuilder();

    String sep1 = "";
    for (Field<?> field : fields) {
      sb.append(sep1);
      sb.append(formatCSV0(field.getName(), ""));

      sep1 = Character.toString(delimiter);
    }

    sb.append("\n");

    for (Record record : this) {
      String sep2 = "";

      for (int index = 0; index < fields.fields.length; index++) {
        sb.append(sep2);
        sb.append(formatCSV0(record.getValue(index), nullString));

        sep2 = Character.toString(delimiter);
      }

      sb.append("\n");
    }

    return sb.toString();
  }
Beispiel #2
0
  @Override
  public final String formatJSON() {
    List<Map<String, String>> f = new ArrayList<Map<String, String>>();
    List<List<Object>> r = new ArrayList<List<Object>>();

    Map<String, String> fieldMap;
    for (Field<?> field : fields) {
      fieldMap = new LinkedHashMap<String, String>();
      fieldMap.put("name", field.getName());
      fieldMap.put("type", field.getDataType().getTypeName().toUpperCase());

      f.add(fieldMap);
    }

    for (Record record : this) {
      List<Object> list = new ArrayList<Object>();

      for (int index = 0; index < fields.fields.length; index++) {
        list.add(record.getValue(index));
      }

      r.add(list);
    }

    Map<String, List<?>> map = new LinkedHashMap<String, List<?>>();

    map.put("fields", f);
    map.put("records", r);

    return JSONObject.toJSONString(map);
  }
Beispiel #3
0
    @Test
    public void testConditionsAsFields() throws Exception {
        Record record = create().select(field(one().eq(zero())), field(one().eq(1))).fetchOne();

        assertEquals(false, record.getValue(0));
        assertEquals(true, record.getValue(1));
    }
Beispiel #4
0
  @Override
  public final String formatHTML() {
    StringBuilder sb = new StringBuilder();

    sb.append("<table>");
    sb.append("<thead>");
    sb.append("<tr>");

    for (Field<?> field : fields) {
      sb.append("<th>");
      sb.append(field.getName());
      sb.append("</th>");
    }

    sb.append("</tr>");
    sb.append("</thead>");
    sb.append("<tbody>");

    for (Record record : this) {
      sb.append("<tr>");

      for (int index = 0; index < fields.fields.length; index++) {
        sb.append("<td>");
        sb.append(format0(record.getValue(index), false));
        sb.append("</td>");
      }

      sb.append("</tr>");
    }

    sb.append("</tbody>");
    sb.append("</table>");

    return sb.toString();
  }
Beispiel #5
0
  @Test
  public void testT65822() {
    Connection conn = null;
    String userName = "******";
    String password = "******";
    String url = "jdbc:derby://localhost:1527/test;create=true";

    try {
      Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
      conn = DriverManager.getConnection(url, userName, password);
      TestFactory create = new TestFactory(conn);

      // MP-MANAGED-UPDATABLE-BEGINNING-DISABLE @jooq-unittest-testT65822-test@
      // write your own tests, just set DISABLE to ENABLE in the comment above
      // future generation will not erase your code ;)
      Result<Record> result = create.select().from(__T_658_22).limit(1).fetch();
      for (Record r : result) {
        java.lang.Integer id = r.getValue(__T_658_22.ID);
        System.out.println("id : " + id + "");
        // MP-MANAGED-UPDATABLE-ENDING
      }

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (conn != null) {
        try {
          conn.close();
        } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
  }
Beispiel #6
0
  @Override
  protected void loadPrimaryKeys(DefaultRelations relations) throws SQLException {
    for (Record record :
        create()
            .select(
                concat(SYSTABLE.TABLE_NAME, val("__"), SYSIDX.INDEX_NAME).as("indexName"),
                SYSTABLE.TABLE_NAME,
                SYSTABCOL.COLUMN_NAME)
            .from(SYSIDX)
            .join(SYSIDXCOL)
            .on(SYSIDX.TABLE_ID.equal(SYSIDXCOL.TABLE_ID))
            .and(SYSIDX.INDEX_ID.equal(SYSIDXCOL.INDEX_ID))
            .join(SYSTABLE)
            .on(SYSIDXCOL.TABLE_ID.equal(SYSTABLE.TABLE_ID))
            .join(SYSTABCOL)
            .on(SYSIDXCOL.TABLE_ID.equal(SYSTABCOL.TABLE_ID))
            .and(SYSIDXCOL.COLUMN_ID.equal(SYSTABCOL.COLUMN_ID))
            .where(SYSIDX.INDEX_CATEGORY.equal((byte) 1))
            .orderBy(SYSIDXCOL.SEQUENCE)
            .fetch()) {

      String key = record.getValue("indexName", String.class);
      String tableName = record.getValue(SYSTABLE.TABLE_NAME);
      String columnName = record.getValue(SYSTABCOL.COLUMN_NAME);

      TableDefinition table = getTable(getSchema(), tableName);
      if (table != null) {
        relations.addPrimaryKey(key, table.getColumn(columnName));
      }
    }
  }
 /**
  * 班级数据
  *
  * @param gradeVo
  * @return
  */
 @RequestMapping("/maintainer/grade/gradeData")
 @ResponseBody
 public AjaxData<GradeVo> gradeData(GradeVo gradeVo) {
   AjaxData<GradeVo> ajaxData = new AjaxData<>();
   // 通过用户类型获取系表ID
   Record record = usersService.findAll(usersService.getUserName());
   int tieId = 0;
   if (!ObjectUtils.isEmpty(record)) {
     tieId = record.getValue(Tables.TIE.ID);
   }
   List<GradeVo> gradeVos = new ArrayList<>();
   if (tieId > 0) {
     Result<Record7<Integer, String, Integer, String, String, String, String>> record7s =
         gradeService.findAllByPage(gradeVo, tieId);
     if (record7s.isNotEmpty()) {
       gradeVos = record7s.into(GradeVo.class);
       PaginationData paginationData = new PaginationData();
       paginationData.setPageNum(gradeVo.getPageNum());
       paginationData.setPageSize(gradeVo.getPageSize());
       paginationData.setTotalDatas(gradeService.findAllByPageCount(gradeVo, tieId));
       ajaxData.success().listData(gradeVos).paginationData(paginationData);
     } else {
       ajaxData.fail().listData(gradeVos);
     }
   } else {
     ajaxData.fail().listData(gradeVos);
   }
   return ajaxData;
 }
Beispiel #8
0
  @Override
  protected List<RoutineDefinition> getRoutines0() {
    List<RoutineDefinition> result = new ArrayList<RoutineDefinition>();

    for (Record record :
        create()
            .selectDistinct(
                ALL_ARGUMENTS.OBJECT_NAME, ALL_ARGUMENTS.OBJECT_ID, ALL_ARGUMENTS.OVERLOAD)
            .from(ALL_ARGUMENTS)
            .where(ALL_ARGUMENTS.OWNER.equal(getSchema().getName()))
            .and(ALL_ARGUMENTS.PACKAGE_NAME.equal(getName()))
            .orderBy(ALL_ARGUMENTS.OBJECT_NAME, ALL_ARGUMENTS.OVERLOAD)
            .fetch()) {

      result.add(
          new OracleRoutineDefinition(
              getSchema(),
              this,
              record.getValue(ALL_ARGUMENTS.OBJECT_NAME),
              "",
              record.getValue(ALL_ARGUMENTS.OBJECT_ID),
              record.getValue(ALL_ARGUMENTS.OVERLOAD)));
    }

    return result;
  }
 /**
  * 班级主任自动完成数据
  *
  * @param search
  * @return
  */
 @RequestMapping("/maintainer/grade/gradeHead")
 @ResponseBody
 public List<AutoCompleteData> gradeHead(String search) {
   List<AutoCompleteData> autoCompleteDatas = new ArrayList<>();
   // 通过用户类型获取系表ID
   Record record = usersService.findAll(usersService.getUserName());
   int tieId = 0;
   if (!ObjectUtils.isEmpty(record)) {
     tieId = record.getValue(Tables.TIE.ID);
   }
   Result<Record4<Integer, Integer, String, String>> teachers =
       teacherService.findByTieIdAndTeacherName(search, tieId);
   if (teachers.isNotEmpty()) {
     teachers.forEach(
         teacherRecord -> {
           AutoCompleteData data = new AutoCompleteData();
           data.setValue(teacherRecord.getValue(Tables.TEACHER.TEACHER_JOB_NUMBER));
           data.setTitle(teacherRecord.getValue(Tables.USERS.REAL_NAME));
           data.setUrl("#");
           data.setText("账号:" + teacherRecord.getValue(Tables.TEACHER.TEACHER_JOB_NUMBER));
           autoCompleteDatas.add(data);
         });
   }
   return autoCompleteDatas;
 }
Beispiel #10
0
 public static Event fromRecord(Record record) {
   return new Event(
       record.getValue(EVENT.ID),
       record.getValue(EVENT.PLAYER_ID),
       record.getValue(EVENT.PLANET_ID),
       EventType.fromId(record.getValue(EVENT.TYPE)),
       record.getValue(EVENT.ROUND),
       Optional.ofNullable(record.getValue(EVENT.FIGHT_ID)));
 }
Beispiel #11
0
 @Override
 public void fromRecord(Record r, Logo l) {
   // TODO remove it, get id from db
   Integer id = r.getValue(OFC_LOGO.POS);
   LogoPosition p = LogoDao.getPositionFromId(id);
   l.setId(id);
   l.setPosition(p);
   l.setImage(r.getValue(OFC_LOGO.IMAGE));
   // TODO set contentType
   // l.setContentType(contentType);
 }
Beispiel #12
0
    @Test
    public void testManyVarcharBindValues() throws Exception {

        // [#1726] Check if large amounts of VARCHAR bind values can be handled
        Record record = create().select(Collections.nCopies(1000, val("abc"))).fetchOne();
        assertEquals(1000, record.size());
        assertEquals(Collections.nCopies(1000, "abc"), asList(record.intoArray()));

        assertEquals(1, create().selectOne()
            .where(val("abc").in(Collections.nCopies(1000, val("abc")).toArray(new Field[0])))
            .fetchOne(0));
    }
Beispiel #13
0
 /**
  * 班级管理界面
  *
  * @param modelMap
  * @return
  */
 @RequestMapping("/maintainer/grade/gradeManager")
 public String gradeManager(ModelMap modelMap, GradeVo gradeVo) {
   // 通过用户类型获取系表ID
   Record record = usersService.findAll(usersService.getUserName());
   int tieId = 0;
   if (!ObjectUtils.isEmpty(record)) {
     tieId = record.getValue(Tables.TIE.ID);
   }
   List<Major> majors = majorService.findByTieId(tieId);
   modelMap.addAttribute("majorNames", majors);
   modelMap.addAttribute("gradeVo", gradeVo);
   return "/maintainer/grade/gradelist";
 }
  @Override
  public Optional<ContestTeamMemberRole> get(Long id_) throws NotFoundException {

    final Record record =
        this.dslContext
            .selectFrom(CONTEST_TEAM_MEMBER_ROLE)
            .where(CONTEST_TEAM_MEMBER_ROLE.ID_.eq(id_))
            .fetchOne();

    if (record == null) {
      return Optional.empty();
    }
    return Optional.of(record.into(ContestTeamMemberRole.class));
  }
Beispiel #15
0
  @Override
  public final Document intoXML() {
    final int size = getFields().size();

    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document document = builder.newDocument();

      Element eResult = document.createElement("result");
      eResult.setAttribute("xmlns", "http://www.jooq.org/xsd/jooq-export-2.6.0.xsd");
      document.appendChild(eResult);

      Element eFields = document.createElement("fields");
      eResult.appendChild(eFields);

      for (Field<?> field : getFields()) {
        Element eField = document.createElement("field");
        eField.setAttribute("name", field.getName());
        eField.setAttribute("type", field.getDataType().getTypeName().toUpperCase());
        eFields.appendChild(eField);
      }

      Element eRecords = document.createElement("records");
      eResult.appendChild(eRecords);

      for (Record record : this) {
        Element eRecord = document.createElement("record");
        eRecords.appendChild(eRecord);

        for (int index = 0; index < size; index++) {
          Field<?> field = getField(index);
          Object value = record.getValue(index);

          Element eValue = document.createElement("value");
          eValue.setAttribute("field", field.getName());
          eRecord.appendChild(eValue);

          if (value != null) {
            eValue.setTextContent(format0(value));
          }
        }
      }

      return document;
    } catch (ParserConfigurationException ignore) {
      throw new RuntimeException(ignore);
    }
  }
Beispiel #16
0
  @Override
  public final String formatXML() {
    final int size = getFields().size();

    StringBuilder sb = new StringBuilder();

    sb.append("<result xmlns=\"http://www.jooq.org/xsd/jooq-export-2.6.0.xsd\">");
    sb.append("<fields>");

    for (Field<?> field : getFields()) {
      sb.append("<field name=\"");
      sb.append(escapeXML(field.getName()));
      sb.append("\" ");
      sb.append("type=\"");
      sb.append(field.getDataType().getTypeName().toUpperCase());
      sb.append("\"/>");
    }

    sb.append("</fields>");
    sb.append("<records>");

    for (Record record : this) {
      sb.append("<record>");

      for (int index = 0; index < size; index++) {
        Field<?> field = getField(index);
        Object value = record.getValue(index);

        sb.append("<value field=\"");
        sb.append(escapeXML(field.getName()));
        sb.append("\"");

        if (value == null) {
          sb.append("/>");
        } else {
          sb.append(">");
          sb.append(escapeXML(format0(value)));
          sb.append("</value>");
        }
      }

      sb.append("</record>");
    }

    sb.append("</records>");
    sb.append("</result>");

    return sb.toString();
  }
Beispiel #17
0
  @Override
  protected void loadForeignKeys(DefaultRelations relations) throws SQLException {
    Sysidx fkIndex = SYSIDX.as("fkIndex");
    Sysidx ukIndex = SYSIDX.as("ukIndex");

    Systable fkTable = SYSTABLE.as("fkTable");
    Systable ukTable = SYSTABLE.as("ukTable");

    for (Record record :
        create()
            .select(
                concat(fkTable.TABLE_NAME, val("__"), fkIndex.INDEX_NAME).as("fkIndexName"),
                fkTable.TABLE_NAME,
                SYSTABCOL.COLUMN_NAME,
                concat(ukTable.TABLE_NAME, val("__"), ukIndex.INDEX_NAME).as("ukIndexName"))
            .from(SYSFKEY)
            .join(fkIndex)
            .on(SYSFKEY.FOREIGN_INDEX_ID.equal(fkIndex.INDEX_ID))
            .and(SYSFKEY.FOREIGN_TABLE_ID.equal(fkIndex.TABLE_ID))
            .join(SYSIDXCOL)
            .on(fkIndex.INDEX_ID.equal(SYSIDXCOL.INDEX_ID))
            .and(fkIndex.TABLE_ID.equal(SYSIDXCOL.TABLE_ID))
            .join(fkTable)
            .on(SYSFKEY.FOREIGN_TABLE_ID.equal(fkTable.TABLE_ID))
            .join(SYSTABCOL)
            .on(SYSIDXCOL.TABLE_ID.equal(SYSTABCOL.TABLE_ID))
            .and(SYSIDXCOL.COLUMN_ID.equal(SYSTABCOL.COLUMN_ID))
            .join(ukIndex)
            .on(SYSFKEY.PRIMARY_INDEX_ID.equal(ukIndex.INDEX_ID))
            .and(SYSFKEY.PRIMARY_TABLE_ID.equal(ukIndex.TABLE_ID))
            .join(ukTable)
            .on(SYSFKEY.PRIMARY_TABLE_ID.equal(ukTable.TABLE_ID))
            .orderBy(fkTable.TABLE_NAME.asc(), fkIndex.INDEX_NAME.asc(), SYSIDXCOL.SEQUENCE.asc())
            .fetch()) {

      String foreignKey = record.getValue("fkIndexName", String.class);
      String foreignKeyTableName = record.getValue(SYSTABLE.TABLE_NAME);
      String foreignKeyColumn = record.getValue(SYSTABCOL.COLUMN_NAME);
      String referencedKey = record.getValue("ukIndexName", String.class);

      TableDefinition foreignKeyTable = getTable(getSchema(), foreignKeyTableName);

      if (foreignKeyTable != null) {
        ColumnDefinition referencingColumn = foreignKeyTable.getColumn(foreignKeyColumn);
        relations.addForeignKey(foreignKey, referencedKey, referencingColumn, getSchema());
      }
    }
  }
Beispiel #18
0
  @Override
  protected void loadUniqueKeys(DefaultRelations relations) throws SQLException {
    for (Record record : fetchKeys("UNIQUE")) {
      SchemaDefinition schema = getSchema(record.getValue(KeyColumnUsage.TABLE_SCHEMA));
      String constraintName = record.getValue(KeyColumnUsage.CONSTRAINT_NAME);
      String tableName = record.getValue(KeyColumnUsage.TABLE_NAME);
      String columnName = record.getValue(KeyColumnUsage.COLUMN_NAME);

      String key = getKeyName(tableName, constraintName);
      TableDefinition table = getTable(schema, tableName);

      if (table != null) {
        relations.addUniqueKey(key, table.getColumn(columnName));
      }
    }
  }
Beispiel #19
0
  @Override
  protected void loadUniqueKeys(DefaultRelations relations) throws SQLException {
    for (Record record : fetchKeys(false)) {
      SchemaDefinition schema = getSchema(record.get(Statistics.TABLE_SCHEMA));
      String constraintName = record.get(Statistics.INDEX_NAME);
      String tableName = record.get(Statistics.TABLE_NAME);
      String columnName = record.get(Statistics.COLUMN_NAME);

      String key = getKeyName(tableName, constraintName);
      TableDefinition table = getTable(schema, tableName);

      if (table != null) {
        relations.addUniqueKey(key, table.getColumn(columnName));
      }
    }
  }
Beispiel #20
0
  @Override
  protected List<TableDefinition> getTables0() throws SQLException {
    List<TableDefinition> result = new ArrayList<TableDefinition>();

    for (Record record :
        create().select(SYSTABLE.TABLE_NAME, SYSTABLE.REMARKS).from(SYSTABLE).fetch()) {

      String name = record.getValue(SYSTABLE.TABLE_NAME);
      String comment = record.getValue(SYSTABLE.REMARKS);

      SybaseTableDefinition table = new SybaseTableDefinition(getSchema(), name, comment);
      result.add(table);
    }

    return result;
  }
  @Override
  public List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();

    for (Record record :
        create()
            .select(
                COLUMNS.COLUMN_NAME,
                COLUMNS.ORDINAL_POSITION,
                COLUMNS.DATA_TYPE,
                COLUMNS.CHARACTER_MAXIMUM_LENGTH,
                COLUMNS.NUMERIC_PRECISION,
                COLUMNS.NUMERIC_SCALE,
                COLUMNS.IS_NULLABLE,
                COLUMNS.IDENTITY_GENERATION,
                COLUMNS.COLUMN_DEFAULT,
                COLUMNS.UDT_NAME)
            .from(COLUMNS)
            .where(COLUMNS.TABLE_SCHEMA.equal(getSchema().getName()))
            .and(COLUMNS.TABLE_NAME.equal(getName()))
            .orderBy(COLUMNS.ORDINAL_POSITION)
            .fetch()) {

      DataTypeDefinition type =
          new DefaultDataTypeDefinition(
              getDatabase(),
              getSchema(),
              record.getValue(COLUMNS.DATA_TYPE),
              record.getValue(COLUMNS.CHARACTER_MAXIMUM_LENGTH),
              record.getValue(COLUMNS.NUMERIC_PRECISION),
              record.getValue(COLUMNS.NUMERIC_SCALE),
              record.getValue(COLUMNS.UDT_NAME));

      ColumnDefinition column =
          new DefaultColumnDefinition(
              getDatabase().getTable(getSchema(), getName()),
              record.getValue(COLUMNS.COLUMN_NAME),
              record.getValue(COLUMNS.ORDINAL_POSITION, int.class),
              type,
              record.getValue(COLUMNS.IS_NULLABLE, boolean.class),
              record.getValue(COLUMNS.COLUMN_DEFAULT, "").startsWith("nextval"),
              null);
      result.add(column);
    }

    return result;
  }
Beispiel #22
0
  @Override
  protected List<RoutineDefinition> getRoutines0() throws SQLException {
    List<RoutineDefinition> result = new ArrayList<RoutineDefinition>();

    for (Record record :
        create()
            .select(SYSPROCEDURE.PROC_NAME)
            .from(SYSPROCEDURE)
            .orderBy(SYSPROCEDURE.PROC_NAME)
            .fetch()) {

      String name = record.getValue(SYSPROCEDURE.PROC_NAME);
      result.add(new SybaseRoutineDefinition(getSchema(), null, name));
    }

    return result;
  }
Beispiel #23
0
  /**
   * This method was implemented with [#799]. It may be useful to make it public for broader use...?
   */
  protected final void from(Record source) {
    for (Field<?> field : fields.fields.fields) {
      Field<?> sourceField = source.field(field);

      if (sourceField != null) {
        Utils.setValue(this, field, source, sourceField);
      }
    }
  }
Beispiel #24
0
  @Override
  protected void init0() throws SQLException {
    for (Record record :
        create()
            .select(
                FunctionColumns.COLUMN_NAME,
                FunctionColumns.TYPE_NAME,
                FunctionColumns.PRECISION,
                FunctionColumns.SCALE,
                FunctionColumns.POS,
                FunctionColumns.NULLABLE,
                FunctionColumns.COLUMN_DEFAULT)
            .from(FUNCTION_COLUMNS)
            .where(FunctionColumns.ALIAS_SCHEMA.equal(getSchema().getName()))
            .and(FunctionColumns.ALIAS_NAME.equal(getName()))

            // [#4193] recent versions of H2 produce a row for the function
            // return value at position 0
            .and(FunctionColumns.POS.gt(0))
            .orderBy(FunctionColumns.POS.asc())
            .fetch()) {

      String paramName = record.get(FunctionColumns.COLUMN_NAME);
      String typeName = record.get(FunctionColumns.TYPE_NAME);
      Integer precision = record.get(FunctionColumns.PRECISION);
      Short scale = record.get(FunctionColumns.SCALE);
      int position = record.get(FunctionColumns.POS);
      boolean nullable = record.get(FunctionColumns.NULLABLE, boolean.class);
      String defaultValue = record.get(FunctionColumns.COLUMN_DEFAULT);

      // VERY special case for H2 alias/function parameters. The first parameter
      // may be a java.sql.Connection object and in such cases it should NEVER be used.
      // It is only used internally by H2 to provide a connection to the current database.
      if (position == 0 && H2DataType.OTHER.getTypeName().equalsIgnoreCase(typeName)) {
        continue;
      }

      DataTypeDefinition type =
          new DefaultDataTypeDefinition(
              getDatabase(),
              getSchema(),
              typeName,
              precision,
              precision,
              scale,
              nullable,
              defaultValue);

      ParameterDefinition parameter =
          new DefaultParameterDefinition(this, paramName, position, type);
      addParameter(InOutDefinition.IN, parameter);
    }
  }
Beispiel #25
0
    @Test
    public void testH2V2603WithExcludedColumns() throws Exception {

        // The generated table only has two columns
        V_2603Record record =
        create().selectFrom(V_2603)
                .fetchOne();

        assertEquals(2, record.size());
        assertEquals(1, (int) record.getCol1());
        assertEquals(4, (int) record.getCol4());

        // The actual table has four columns
        Record r =
        create().selectFrom(table(V_2603.getName()))
                .fetchOne();

        assertEquals(4, r.size());
        assertEquals(asList(1, 2, 3, 4), asList(r.intoArray()));
    }
Beispiel #26
0
  @Override
  protected List<TableDefinition> getTables0() throws SQLException {
    List<TableDefinition> result = new ArrayList<TableDefinition>();

    for (Record record :
        create()
            .select(Tables.TABLE_SCHEMA, Tables.TABLE_NAME, Tables.TABLE_COMMENT)
            .from(TABLES)
            .where(Tables.TABLE_SCHEMA.in(getInputSchemata()))
            .orderBy(Tables.TABLE_SCHEMA, Tables.TABLE_NAME)
            .fetch()) {

      SchemaDefinition schema = getSchema(record.getValue(Tables.TABLE_SCHEMA));
      String name = record.getValue(Tables.TABLE_NAME);
      String comment = record.getValue(Tables.TABLE_COMMENT);

      MySQLTableDefinition table = new MySQLTableDefinition(schema, name, comment);
      result.add(table);
    }

    return result;
  }
Beispiel #27
0
  @Override
  protected List<RoutineDefinition> getRoutines0() throws SQLException {
    List<RoutineDefinition> result = new ArrayList<RoutineDefinition>();

    try {
      create(true).fetchCount(PROC);
    } catch (DataAccessException e) {
      log.warn(
          "Table unavailable",
          "The `mysql`.`proc` table is unavailable. Stored procedures cannot be loaded. Check if you have sufficient grants");
      return result;
    }

    Result<Record6<String, String, String, byte[], byte[], ProcType>> records =
        create()
            .select(Proc.DB, Proc.NAME, Proc.COMMENT, Proc.PARAM_LIST, Proc.RETURNS, Proc.TYPE)
            .from(PROC)
            .where(DB.in(getInputSchemata()))
            .orderBy(DB, Proc.NAME)
            .fetch();

    Map<Record, Result<Record6<String, String, String, byte[], byte[], ProcType>>> groups =
        records.intoGroups(new Field[] {Proc.DB, Proc.NAME});

    // [#1908] This indirection is necessary as MySQL allows for overloading
    // procedures and functions with the same signature.
    for (Entry<Record, Result<Record6<String, String, String, byte[], byte[], ProcType>>> entry :
        groups.entrySet()) {
      Result<?> overloads = entry.getValue();

      for (int i = 0; i < overloads.size(); i++) {
        Record record = overloads.get(i);

        SchemaDefinition schema = getSchema(record.get(DB));
        String name = record.get(Proc.NAME);
        String comment = record.get(Proc.COMMENT);
        String params = new String(record.get(Proc.PARAM_LIST));
        String returns = new String(record.get(Proc.RETURNS));
        ProcType type = record.get(Proc.TYPE);

        if (overloads.size() > 1) {
          result.add(
              new MySQLRoutineDefinition(
                  schema, name, comment, params, returns, type, "_" + type.name()));
        } else {
          result.add(
              new MySQLRoutineDefinition(schema, name, comment, params, returns, type, null));
        }
      }
    }

    return result;
  }
Beispiel #28
0
  @Test
  public void testXUnused() {
    Connection conn = null;
    String userName = "******";
    String password = "";
    String url = "jdbc:mysql://localhost/test";

    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      conn = DriverManager.getConnection(url, userName, password);
      TestFactory create = new TestFactory(conn);

      // MP-MANAGED-UPDATABLE-BEGINNING-DISABLE @jooq-unittest-testXUnused-test@
      // write your own tests, just set DISABLE to ENABLE in the comment above
      // future generation will not erase your code ;)
      Result<Record> result = create.select().from(__X_UNUSED).limit(1).fetch();
      for (Record r : result) {
        java.lang.Integer id = r.getValue(__X_UNUSED.ID);
        java.lang.String name = r.getValue(__X_UNUSED.NAME);
        java.lang.Integer idRef = r.getValue(__X_UNUSED.ID_REF);
        System.out.println("id : " + id + "name : " + name + "idRef : " + idRef + "");
        // MP-MANAGED-UPDATABLE-ENDING
      }

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (conn != null) {
        try {
          conn.close();
        } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
  }
Beispiel #29
0
  @Override
  public final String formatHTML() {
    final int size = getFields().size();

    StringBuilder sb = new StringBuilder();

    sb.append("<table>");
    sb.append("<thead>");
    sb.append("<tr>");

    for (Field<?> field : getFields()) {
      sb.append("<th>");
      sb.append(field.getName());
      sb.append("</th>");
    }

    sb.append("</tr>");
    sb.append("</thead>");
    sb.append("<tbody>");

    for (Record record : this) {
      sb.append("<tr>");

      for (int index = 0; index < size; index++) {
        sb.append("<td>");
        sb.append(format0(record.getValue(index)));
        sb.append("</td>");
      }

      sb.append("</tr>");
    }

    sb.append("</tbody>");
    sb.append("</table>");

    return sb.toString();
  }
  @Test
  public void testInsertAndReturn() {
    // Add another author, with a generated ID
    Record record =
        create
            .insertInto(AUTHOR, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
            .values("Charlotte", "Roche")
            .returning(AUTHOR.ID)
            .fetchOne();
    System.out.println(record.getValue(AUTHOR.ID));

    // For some RDBMS, this also works when inserting several values
    // The following should return a 2x2 table
    Result<?> result =
        create
            .insertInto(AUTHOR, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
            .values("Johann Wolfgang", "von Goethe")
            .values("Friedrich", "Schiller")
            // You can request any field. Also trigger-generated values
            .returning(AUTHOR.ID, AUTHOR.LAST_NAME)
            .fetch();
    System.out.println(result.getValue(0, AUTHOR.ID));
    System.out.println(result.getValue(1, AUTHOR.ID));
  }