Package ru.tehkode.permissions.backends

Examples of ru.tehkode.permissions.backends.SchemaUpdate


    if (!baseDirectory.exists()) {
      baseDirectory.mkdirs();
    }

    this.permissionsFile = new File(baseDir, permissionFilename);
    addSchemaUpdate(new SchemaUpdate(1) {
      @Override
      public void performUpdate() {
        ConfigurationSection userSection = permissions.getConfigurationSection("users");
        if (userSection != null) {
          for (Map.Entry<String, Object> e : userSection.getValues(false).entrySet()) {
View Full Code Here


      throw new PermissionBackendException("Unable to connect to SQL database", e);
    }

    getManager().getLogger().info("Successfully connected to SQL database");

    addSchemaUpdate(new SchemaUpdate(2) {
      @Override
      public void performUpdate() throws PermissionBackendException {
        // Change encoding for all columns to utf8mb4
        // Change collation for all columns to utf8mb4_general_ci
        try (SQLConnection conn = getSQL()) {
          conn.prep("ALTER TABLE `{permissions}` DROP KEY `unique`, MODIFY COLUMN `permission` TEXT NOT NULL").execute();
          conn.prep("ALTER TABLE `{permissions}` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci").execute();
          conn.prep("ALTER TABLE `{permissions_entity}` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci").execute();
          conn.prep("ALTER TABLE `{permissions_inheritance}` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci").execute();
        } catch (SQLException | IOException e) {
          throw new PermissionBackendException(e);
        }
      }
    });
    addSchemaUpdate(new SchemaUpdate(1) {
      @Override
      public void performUpdate() throws PermissionBackendException {
        try (SQLConnection conn = getSQL()) {
          PreparedStatement updateStmt = conn.prep("entity.options.add");
          ResultSet res = conn.prepAndBind("SELECT `name`, `type` FROM `{permissions_entity}` WHERE `default`='1'").executeQuery();
          while (res.next()) {
              conn.bind(updateStmt, res.getString("name"), res.getInt("type"), "default", "", "true");
              updateStmt.addBatch();
          }
          updateStmt.executeBatch();

          // Update tables
          conn.prep("ALTER TABLE `{permissions_entity}` DROP COLUMN `default`").execute();
        } catch (SQLException | IOException e) {
          throw new PermissionBackendException(e);
        }
      }
    });
    addSchemaUpdate(new SchemaUpdate(0) {
      @Override
      public void performUpdate() throws PermissionBackendException {
        try (SQLConnection conn = getSQL()) {
          // TODO: Table modifications not supported in SQLite
          // Prefix/sufix -> options
View Full Code Here

TOP

Related Classes of ru.tehkode.permissions.backends.SchemaUpdate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.