public void init() {
   SqlService sql =
       Sponge.getServiceManager()
           .provide(SqlService.class)
           .orElseThrow(() -> new IllegalStateException("NoSQL?"));
   String jdbcUrl = Planetesimals.getInstance().getJDBCUrl();
   String[] dbParts = jdbcUrl.split(":");
   if (dbParts.length < 2 || !dbParts[1].equals("h2")) {
     throw new IllegalStateException("Not H2. Dunno what to do.");
   }
   try {
     this.data = sql.getDataSource(jdbcUrl);
   } catch (SQLException e) {
     throw new IllegalStateException("Couldn't load DB", e);
   }
   this.db = using(this.data, SQLDialect.H2);
   if (getDB()
       .meta()
       .getTables()
       .stream()
       .noneMatch(t -> t.getName().equalsIgnoreCase(PLANETS_TABLE.getName()))) {
     getDB()
         .createTable(PLANETS_TABLE)
         .column(CHUNK_X_FIELD, getDataType(Integer.class))
         .column(CHUNK_Y_FIELD, getDataType(Integer.class))
         .column(CHUNK_Z_FIELD, getDataType(Integer.class))
         .column(PLANET_X_FIELD, getDataType(Integer.class))
         .column(PLANET_Y_FIELD, getDataType(Integer.class))
         .column(PLANET_Z_FIELD, getDataType(Integer.class))
         .column(PLANET_RADIUS_FIELD, getDataType(Integer.class))
         .execute();
   }
 }
Beispiel #2
0
 private String[] getTableNames() {
   if (databaseDescriptor == null) {
     return new String[0];
   }
   List<Table<?>> tableList = databaseDescriptor.getSchema().getTables();
   List<String> tableNameList = new ArrayList<String>();
   for (Table<? extends Record> table : tableList) {
     String tableName = table.getName();
     tableNameList.add(tableName);
   }
   Collections.sort(tableNameList, String.CASE_INSENSITIVE_ORDER);
   return tableNameList.toArray(new String[0]);
 }
Beispiel #3
0
    @Override
    public final String getTableName(int column) throws SQLException {
      checkNotClosed();

      Field<?> field = result.getField(column - 1);
      if (field instanceof TableField) {
        Table<?> table = ((TableField<?, ?>) field).getTable();

        if (table != null) {
          return table.getName();
        }
      }

      // By default, no table is available
      return "";
    }