Created
October 29, 2021 17:53
-
-
Save sumanentc/1f42cbcfd1508732b01754780017b22f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<Player> sqlQuerySearch(String text) { | |
log.info("SqlQuery search to find players whose team contain the given text"); | |
IgniteCache<Long, Player> playerCache = Ignition.ignite().getOrCreateCache(PLAYER); | |
Collection<QueryEntity> queryEntities = playerCache.getConfiguration(CacheConfiguration.class).getQueryEntities(); | |
String tableName = queryEntities.stream().findFirst().orElseThrow(() -> new IllegalArgumentException(PLAYER + "doesn't exists")).getTableName(); | |
SqlFieldsQuery sqlQuery = new SqlFieldsQuery("select * from " + tableName + " where team='" + text + "'"); | |
log.info("Query :: " + sqlQuery.getSql()); | |
List<List<?>> records = playerCache.query(sqlQuery).getAll(); | |
return records.stream().map(objects -> convert((List<Object>) objects)).collect(Collectors.toList()); | |
} | |
private Player convert(List<Object> values) { | |
return Player.builder().id((Long) values.get(0)).name(String.valueOf(values.get(1))) | |
.team(String.valueOf(values.get(2))) | |
.salary(Double.parseDouble(values.get(3).toString())).build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment