Java Code Examples for org.h2.util.StringUtils

The following examples show how to use org.h2.util.StringUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: DiscordSoundboard   Source File: LeaveSoundBoardListener.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"rawtypes"})
public void onGuildVoiceLeave(GuildVoiceLeaveEvent event) {
    String userDisconnected = event.getMember().getEffectiveName();
    String userDisconnectedId = event.getMember().getId();
    User user = userRepository.findOneByIdOrUsernameIgnoreCase(userDisconnectedId, userDisconnected);
    if (user != null && !StringUtils.isNullOrEmpty(user.getLeaveSound())) {
        bot.playFileInChannel(user.getLeaveSound(), event.getChannelJoined());
    } else {
        //If DB doesn't have a leave sound check for a file
        String fileToPlay = bot.getFileForUser(userDisconnected, false);
        if (!fileToPlay.equals("")) {
            try {
                bot.playFileInChannel(fileToPlay, event.getChannelLeft());
            } catch (Exception e) {
                LOG.fatal("Could not play file for disconnection of " + userDisconnected);
            }
        } else {
            LOG.debug("Could not find disconnection sound for " + userDisconnected + ", so ignoring disconnection event.");
        }
    }
}
 
Example 2
@SuppressWarnings({"rawtypes"})
public void onGuildVoiceJoin(GuildVoiceJoinEvent event) {
    if (!event.getMember().getUser().isBot()) {
        String userJoined = event.getMember().getEffectiveName();
        String userId = event.getMember().getId();

        User user = userRepository.findOneByIdOrUsernameIgnoreCase(userId, userJoined);
        if (user != null && !StringUtils.isNullOrEmpty(user.getEntranceSound())) {
            bot.playFileInChannel(user.getEntranceSound(), event.getChannelJoined());
        } else {
            //If DB doesn't have an entrance sound check for a file.
            String entranceFile = bot.getFileForUser(userJoined, true);
            if (!entranceFile.equals("")) {
                try {
                    bot.playFileInChannel(entranceFile, event.getChannelJoined());
                } catch (Exception e) {
                    LOG.fatal("Could not play file for entrance of " + userJoined);
                }

            } else {

                LOG.debug("Could not find any sound that starts with " + userJoined + ", so ignoring entrance.");
            }
        }
    }
}
 
Example 3
Source Project: ignite   Source File: GridSqlUpdate.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public String getSQL() {
    StatementBuilder buff = new StatementBuilder(explain() ? "EXPLAIN " : "");
    buff.append("UPDATE ")
        .append(target.getSQL())
        .append("\nSET\n");

    for (GridSqlColumn c : cols) {
        GridSqlElement e = set.get(c.columnName());
        buff.appendExceptFirst(",\n    ");
        buff.append(c.columnName()).append(" = ").append(e != null ? e.getSQL() : "DEFAULT");
    }

    if (where != null)
        buff.append("\nWHERE ").append(StringUtils.unEnclose(where.getSQL()));

    if (limit != null)
        buff.append("\nLIMIT ").append(StringUtils.unEnclose(limit.getSQL()));

    return buff.toString();
}
 
Example 4
Source Project: Spring   Source File: RoomServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Room findByRoomNumber(String roomNumber) {
	if (!StringUtils.isNullOrEmpty(roomNumber) && StringUtils.isNumber(roomNumber)) {
		Room room = repo.findByRoomNumber(roomNumber);
		if (room == null) {
			throw new RoomServiceClientException("Room number: " + roomNumber + ", does not exist.");
		}
		return room;
	}
	else {
		throw new RoomServiceClientException("Room number: " + roomNumber + ", is an invalid room number format.");
	}
}
 
Example 5
Source Project: Spring   Source File: RoomServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Room findByRoomNumber(String roomNumber) {
	if (!StringUtils.isNullOrEmpty(roomNumber) && StringUtils.isNumber(roomNumber)) {
		Room room = repo.findByRoomNumber(roomNumber);
		if (room == null) {
			throw new RoomServiceClientException("Room number: " + roomNumber + ", does not exist.");
		}
		return room;
	}
	else {
		throw new RoomServiceClientException("Room number: " + roomNumber + ", is an invalid room number format.");
	}
}
 
Example 6
Source Project: Spring   Source File: RoomServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Room findByRoomNumber(String roomNumber) {
	if (!StringUtils.isNullOrEmpty(roomNumber) && StringUtils.isNumber(roomNumber)) {
		Room room = repo.findByRoomNumber(roomNumber);
		if (room == null) {
			throw new RoomServiceClientException("Room number: " + roomNumber + ", does not exist.");
		}
		return room;
	}
	else {
		throw new RoomServiceClientException("Room number: " + roomNumber + ", is an invalid room number format.");
	}
}
 
Example 7
Source Project: Spring   Source File: RoomServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Room findByRoomNumber(String roomNumber) {
	if (!StringUtils.isNullOrEmpty(roomNumber) && StringUtils.isNumber(roomNumber)) {
		Room room = repo.findByRoomNumber(roomNumber);
		if (room == null) {
			throw new RoomServiceClientException("Room number: " + roomNumber + ", does not exist.");
		}
		return room;
	}
	else {
		throw new RoomServiceClientException("Room number: " + roomNumber + ", is an invalid room number format.");
	}
}
 
Example 8
Source Project: x-pipe   Source File: FunctionsMySQL.java    License: Apache License 2.0 5 votes vote down vote up
private static String convertToSimpleDateFormat(String format) {
    String[] replace = FORMAT_REPLACE;
    for (int i = 0; i < replace.length; i += 2) {
        format = StringUtils.replaceAll(format, replace[i], replace[i + 1]);
    }
    return format;
}
 
Example 9
Source Project: ignite   Source File: GridSqlDelete.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public String getSQL() {
    StatementBuilder buff = new StatementBuilder(explain() ? "EXPLAIN " : "");
    buff.append("DELETE")
        .append("\nFROM ")
        .append(from.getSQL());

    if (where != null)
        buff.append("\nWHERE ").append(StringUtils.unEnclose(where.getSQL()));

    if (limit != null)
        buff.append("\nLIMIT (").append(StringUtils.unEnclose(limit.getSQL())).append(')');

    return buff.toString();
}
 
Example 10
/**
 * Tests the {@code !connect} command passing in the password in as a hash,
 * and using h2's {@code PASSWORD_HASH} property outside of the URL:
 *
 * <blockquote>
 * !connect -p PASSWORD_HASH TRUE jdbc:h2:mem sa 6e6f6e456d707479506173737764
 * </blockquote>
 */
@Test
public void testConnectWithDbPropertyAsParameter() {
  try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
    SqlLine.Status status =
        begin(sqlLine, os, false, "-e", "!set maxwidth 80");
    assertThat(status, equalTo(SqlLine.Status.OK));
    DispatchCallback dc = new DispatchCallback();
    sqlLine.runCommands(dc,
        "!set maxwidth 80",
        "!set incremental true");
    String fakeNonEmptyPassword = "nonEmptyPasswd";
    final byte[] bytes =
        fakeNonEmptyPassword.getBytes(StandardCharsets.UTF_8);
    sqlLine.runCommands(dc, "!connect "
        + " -p PASSWORD_HASH TRUE "
        + ConnectionSpec.H2.url + " "
        + ConnectionSpec.H2.username + " "
        + StringUtils.convertBytesToHex(bytes));
    sqlLine.runCommands(dc, "!tables");
    String output = os.toString("UTF8");
    final String expected = "| TABLE_CAT | TABLE_SCHEM | "
        + "TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_CAT | TYP |";
    assertThat(output, containsString(expected));
    sqlLine.runCommands(new DispatchCallback(), "!quit");
    assertTrue(sqlLine.isExit());
  } catch (Throwable t) {
    // fail
    throw new RuntimeException(t);
  }
}
 
Example 11
/**
 * Tests the {@code !connect} command passing in the password in as a hash,
 * and using h2's {@code PASSWORD_HASH} and {@code ALLOW_LITERALS} properties
 * outside of the URL:
 *
 * <blockquote>
 * !connect -p PASSWORD_HASH TRUE -p ALLOW_LITERALS NONE
 * jdbc:h2:mem sa 6e6f6e456d707479506173737764
 * </blockquote>
 */
@Test
public void testConnectWithDbPropertyAsParameter2() {
  try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
    SqlLine.Status status =
        begin(sqlLine, os, false, "-e", "!set maxwidth 80");
    assertThat(status, equalTo(SqlLine.Status.OK));
    DispatchCallback dc = new DispatchCallback();
    sqlLine.runCommands(dc, "!set maxwidth 80");
    String fakeNonEmptyPassword = "nonEmptyPasswd";
    final byte[] bytes =
        fakeNonEmptyPassword.getBytes(StandardCharsets.UTF_8);
    sqlLine.runCommands(dc, "!connect "
          + " -p PASSWORD_HASH TRUE -p ALLOW_LITERALS NONE "
          + ConnectionSpec.H2.url + " "
          + ConnectionSpec.H2.username + " "
          + StringUtils.convertBytesToHex(bytes));
    sqlLine.runCommands(dc, "select 1;");
    String output = os.toString("UTF8");
    final String expected = "Error:";
    assertThat(output, containsString(expected));
    sqlLine.runCommands(new DispatchCallback(), "!quit");
    assertTrue(sqlLine.isExit());
  } catch (Throwable t) {
    // fail
    throw new RuntimeException(t);
  }
}
 
Example 12
Source Project: ignite   Source File: GridSqlSelect.java    License: Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override public String getSQL() {
    StatementBuilder buff = new StatementBuilder(explain() ? "EXPLAIN SELECT" : "SELECT");

    if (distinct)
        buff.append(" DISTINCT");

    for (GridSqlAst expression : columns(true)) {
        buff.appendExceptFirst(",");
        buff.append('\n');
        buff.append(expression.getSQL());
    }

    if (from != null)
        buff.append("\nFROM ").append(from.getSQL());

    if (where != null)
        buff.append("\nWHERE ").append(StringUtils.unEnclose(where.getSQL()));

    if (grpCols != null) {
        buff.append("\nGROUP BY ");

        buff.resetCount();

        for (int grpCol : grpCols) {
            buff.appendExceptFirst(", ");

            addAlias(buff, cols.get(grpCol));
        }
    }

    if (havingCol >= 0) {
        buff.append("\nHAVING ");

        addAlias(buff, cols.get(havingCol));
    }

    getSortLimitSQL(buff);

    if (isForUpdate)
        buff.append("\nFOR UPDATE");

    return buff.toString();
}
 
Example 13
Source Project: ignite   Source File: GridSqlSelect.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @param buff Statement builder.
 * @param exp Alias expression.
 */
private static void addAlias(StatementBuilder buff, GridSqlAst exp) {
    exp = GridSqlAlias.unwrap(exp);

    buff.append(StringUtils.unEnclose(exp.getSQL()));
}
 
Example 14
/**
 * Tests the {@code !connect} command passing the password in as a hash:
 *
 * <blockquote>
 * !connect "jdbc:h2:mem; PASSWORD_HASH=TRUE" sa 6e6f6e456d707479506173737764
 * </blockquote>
 */
@Test
public void testConnectWithDbProperty() {
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  SqlLine.Status status =
      begin(sqlLine, os, false, "-e", "!set maxwidth 80");
  assertThat(status, equalTo(SqlLine.Status.OK));
  DispatchCallback dc = new DispatchCallback();

  try {
    sqlLine.runCommands(dc, "!set maxwidth 80");

    // fail attempt
    String fakeNonEmptyPassword = "nonEmptyPasswd";
    sqlLine.runCommands(dc, "!connect \""
          + ConnectionSpec.H2.url
          + " ;PASSWORD_HASH=TRUE\" "
          + ConnectionSpec.H2.username
          + " \"" + fakeNonEmptyPassword + "\"");
    String output = os.toString("UTF8");
    final String expected0 = "Error:";
    assertThat(output, containsString(expected0));
    os.reset();

    // success attempt
    final byte[] bytes =
        fakeNonEmptyPassword.getBytes(StandardCharsets.UTF_8);
    sqlLine.runCommands(dc, "!connect \""
          + ConnectionSpec.H2.url
          + " ;PASSWORD_HASH=TRUE;ALLOW_LITERALS=NONE\" "
          + ConnectionSpec.H2.username + " \""
          + StringUtils.convertBytesToHex(bytes)
          + "\"");
    sqlLine.runCommands(dc, "!set incremental true");
    sqlLine.runCommands(dc, "!tables");
    output = os.toString("UTF8");
    final String expected1 = "| TABLE_CAT | TABLE_SCHEM | "
        + "TABLE_NAME | TABLE_TYPE | REMARKS | TYPE_CAT | TYP |";
    assertThat(output, containsString(expected1));

    sqlLine.runCommands(dc, "select 5;");
    output = os.toString("UTF8");
    final String expected2 = "Error:";
    assertThat(output, containsString(expected2));
    os.reset();

    sqlLine.runCommands(new DispatchCallback(), "!quit");
    output = os.toString("UTF8");
    assertThat(output,
        allOf(not(containsString("Error:")), containsString("!quit")));
    assertTrue(sqlLine.isExit());
  } catch (Exception e) {
    // fail
    throw new RuntimeException(e);
  }
}
 
Example 15
Source Project: ignite   Source File: GridSqlJoin.java    License: Apache License 2.0 3 votes vote down vote up
/** {@inheritDoc} */
@Override public String getSQL() {
    StatementBuilder buff = new StatementBuilder();

    buff.append(leftTable().getSQL());

    buff.append(leftOuter ? " \n LEFT OUTER JOIN " : " \n INNER JOIN ");

    buff.append(rightTable().getSQL());

    buff.append(" \n ON ").append(StringUtils.unEnclose(on().getSQL()));

    return buff.toString();
}