org.javalite.common.Util.join()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(202)

本文整理了Java中org.javalite.common.Util.join()方法的一些代码示例,展示了Util.join()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.join()方法的具体详情如下:
包路径:org.javalite.common.Util
类名称:Util
方法名:join

Util.join介绍

[英]Joins the items in collection with a delimiter, and appends the result to StringBuilder.
[中]使用分隔符连接集合中的项,并将结果附加到StringBuilder。

代码示例

代码示例来源:origin: javalite/activejdbc

  1. private String getAllColumns(String[] columns){
  2. return columns == null ? " *" : " " + join(columns, ", ");
  3. }

代码示例来源:origin: javalite/activejdbc

  1. private String getSQColumns(String[] columns){
  2. if(columns == null){
  3. return "sq.*";
  4. }
  5. List<String> names = new ArrayList<>();
  6. for (String column : columns) {
  7. names.add("sq." + column);
  8. }
  9. return join(names, ", ");
  10. }

代码示例来源:origin: javalite/activejdbc

  1. protected void appendOrderBy(StringBuilder query, List<String> orderBys) {
  2. if (!orderBys.isEmpty()) {
  3. query.append(" ORDER BY ");
  4. join(query, orderBys, ", ");
  5. }
  6. }

代码示例来源:origin: javalite/activejdbc

  1. /**
  2. * Joins the items in collection with a delimiter.
  3. *
  4. * @param collection collection of items to join.
  5. * @param delimiter delimiter to insert between elements of collection.
  6. * @return string with collection elements separated by delimiter. There is no trailing delimiter in the string.
  7. */
  8. public static String join(Collection<?> collection, String delimiter) {
  9. if (collection.isEmpty()) { return ""; }
  10. StringBuilder sb = new StringBuilder();
  11. join(sb, collection, delimiter);
  12. return sb.toString();
  13. }

代码示例来源:origin: javalite/activejdbc

  1. private static String getMessage(String query, Object[] params, Throwable cause){
  2. StringBuilder sb = new StringBuilder(cause.toString()).append(", query: ").append(query);
  3. if (params != null && params.length > 0) {
  4. sb.append(", params: ");
  5. join(sb, params, ", ");
  6. }
  7. return sb.toString();
  8. }
  9. }

代码示例来源:origin: javalite/activejdbc

  1. /**
  2. * Joins the items in array with a delimiter.
  3. *
  4. * @param array array of items to join.
  5. * @param delimiter delimiter to insert between elements of array.
  6. * @return string with array elements separated by delimiter. There is no trailing delimiter in the string.
  7. */
  8. public static String join(String[] array, String delimiter) {
  9. if (empty(array)) { return ""; }
  10. StringBuilder sb = new StringBuilder();
  11. join(sb, array, delimiter);
  12. return sb.toString();
  13. }

代码示例来源:origin: javalite/activejdbc

  1. /**
  2. * Produces a parametrized AND query.
  3. * Example:
  4. * <pre>
  5. * String sql = dialect.selectStarParametrized("people", "name", "ssn", "dob");
  6. * //generates:
  7. * //SELECT * FROM people WHERE name = ? AND ssn = ? AND dob = ?
  8. * </pre>
  9. *
  10. *
  11. * @param table name of table
  12. * @param parameters list of parameter names
  13. * @return something like: "select * from table_name where name = ? and last_name = ? ..."
  14. */
  15. @Override
  16. public String selectStarParametrized(String table, String ... parameters) {
  17. StringBuilder sql = new StringBuilder().append("SELECT * FROM ").append(table).append(" WHERE ");
  18. join(sql, parameters, " = ? AND ");
  19. sql.append(" = ?");
  20. return sql.toString();
  21. }

代码示例来源:origin: javalite/activejdbc

  1. protected void appendSelect(StringBuilder queryBuilder, String tableName, String[] columns, String tableAlias, String subQuery, List<String> orderBys) {
  2. if (tableName == null) {
  3. queryBuilder.append(subQuery);
  4. } else {
  5. if (tableAlias == null) {
  6. String cols = columns == null? "*" : join(columns, ",");
  7. queryBuilder.append("SELECT ").append(cols).append(" FROM ").append(tableName);
  8. } else {
  9. queryBuilder.append("SELECT ").append(tableAlias).append(".* FROM ").append(tableName).append(' ')
  10. .append(tableAlias);
  11. }
  12. appendSubQuery(queryBuilder, subQuery);
  13. }
  14. appendOrderBy(queryBuilder, orderBys);
  15. }

代码示例来源:origin: javalite/activejdbc

  1. @Override
  2. public String insertParametrized(MetaModel metaModel, List<String> columns, boolean containsId) {
  3. StringBuilder query = new StringBuilder().append("INSERT INTO ").append(metaModel.getTableName()).append(' ');
  4. if (columns.isEmpty()) {
  5. appendEmptyRow(metaModel, query);
  6. } else {
  7. boolean addIdGeneratorCode = (!containsId && metaModel.getIdGeneratorCode() != null);
  8. query.append('(');
  9. if (addIdGeneratorCode) {
  10. query.append(metaModel.getIdName()).append(", ");
  11. }
  12. join(query, columns, ", ");
  13. query.append(") VALUES (");
  14. if (addIdGeneratorCode) {
  15. query.append(metaModel.getIdGeneratorCode()).append(", ");
  16. }
  17. appendQuestions(query, columns.size());
  18. query.append(')');
  19. }
  20. return query.toString();
  21. }

代码示例来源:origin: javalite/activejdbc

  1. @Override
  2. public String insert(MetaModel metaModel, Map<String, Object> attributes, String ... replacements) {
  3. StringBuilder query = new StringBuilder().append("INSERT INTO ").append(metaModel.getTableName()).append(' ');
  4. if (attributes.isEmpty()) {
  5. appendEmptyRow(metaModel, query);
  6. } else {
  7. boolean addIdGeneratorCode = (metaModel.getIdGeneratorCode() != null
  8. && attributes.get(metaModel.getIdName()) == null); // do not use containsKey
  9. query.append('(');
  10. if (addIdGeneratorCode) {
  11. query.append(metaModel.getIdName()).append(", ");
  12. }
  13. join(query, attributes.keySet(), ", ");
  14. query.append(") VALUES (");
  15. if (addIdGeneratorCode) {
  16. query.append(metaModel.getIdGeneratorCode()).append(", ");
  17. }
  18. Iterator<Object> it = attributes.values().iterator();
  19. appendValue(query, it.next());
  20. while (it.hasNext()) {
  21. query.append(", ");
  22. appendValue(query, it.next(), replacements);
  23. }
  24. query.append(')');
  25. }
  26. return query.toString();
  27. }

代码示例来源:origin: javalite/activejdbc

  1. if (needOffset) {
  2. fullQuery.append("SELECT " + getSQColumns(columns) + " FROM (SELECT ROW_NUMBER() OVER (ORDER BY ");
  3. join(fullQuery, orderBys, ", ");
  4. fullQuery.append(") AS rownumber,");
  5. } else if (needLimit) {

代码示例来源:origin: javalite/activejdbc

  1. /**
  2. * Use to see what SQL will be sent to the database.
  3. *
  4. * @param showParameters true to see parameter values, false not to.
  5. * @return SQL in a dialect for current connection which will be used if you start querying this
  6. * list.
  7. */
  8. public String toSql(boolean showParameters) {
  9. String sql;
  10. if(forPaginator){
  11. sql = metaModel.getDialect().formSelect(null, null, fullQuery, orderBys, limit, offset);
  12. }else{
  13. sql = fullQuery != null ? fullQuery
  14. : metaModel.getDialect().formSelect(metaModel.getTableName(), null, subQuery, orderBys, limit, offset);
  15. }
  16. if (showParameters) {
  17. StringBuilder sb = new StringBuilder(sql).append(", with parameters: ");
  18. join(sb, params, ", ");
  19. sql = sb.toString();
  20. }
  21. return sql;
  22. }

代码示例来源:origin: javalite/activejdbc

  1. /**
  2. * Sets a parent on this instance. Basically this sets a correct value of a foreign key in a
  3. * parent/child relationship. This only works for one to many and polymorphic associations.
  4. * The act of setting a parent does not result in saving to a database.
  5. *
  6. * @param parent potential parent of this instance. Its ID value must not be null.
  7. */
  8. public void setParent(Model parent) {
  9. if (parent == null || parent.getId() == null) {
  10. throw new IllegalArgumentException("parent cannot ne null and parent ID cannot be null");
  11. }
  12. List<Association> associations = metaModelLocal.getAssociations();
  13. for (Association association : associations) {
  14. if (association instanceof BelongsToAssociation && association.getTargetClass().equals(parent.metaModelLocal.getModelClass())) {
  15. set(((BelongsToAssociation)association).getFkName(), parent.getId());
  16. return;
  17. }
  18. if(association instanceof BelongsToPolymorphicAssociation && association.getTargetClass().equals(parent.metaModelLocal.getModelClass())){
  19. set("parent_id", parent.getId());
  20. set("parent_type", ((BelongsToPolymorphicAssociation)association).getTypeLabel());
  21. return;
  22. }
  23. }
  24. StringBuilder sb = new StringBuilder();
  25. sb.append("Class: ").append(parent.getClass()).append(" is not associated with ").append(this.getClass())
  26. .append(", list of existing associations:\n");
  27. join(sb, metaModelLocal.getAssociations(), "\n");
  28. throw new IllegalArgumentException(sb.toString());
  29. }

代码示例来源:origin: javalite/activejdbc

  1. attributeNames.retainAll(dirtyAttributeNames);
  2. if(attributeNames.size() > 0) {
  3. join(query, attributeNames, " = ?, ");
  4. query.append(" = ?");

代码示例来源:origin: org.javalite/activejdbc

  1. private String getSQColumns(String[] columns){
  2. if(columns == null){
  3. return "sq.*";
  4. }
  5. List<String> names = new ArrayList<>();
  6. for (String column : columns) {
  7. names.add("sq." + column);
  8. }
  9. return join(names, ", ");
  10. }

代码示例来源:origin: org.javalite/activejdbc

  1. protected void appendOrderBy(StringBuilder query, List<String> orderBys) {
  2. if (!orderBys.isEmpty()) {
  3. query.append(" ORDER BY ");
  4. join(query, orderBys, ", ");
  5. }
  6. }

代码示例来源:origin: com.github.tchoulihan/activejdbc

  1. protected void appendOrderBy(StringBuilder query, List<String> orderBys) {
  2. if (!orderBys.isEmpty()) {
  3. query.append(" ORDER BY ");
  4. join(query, orderBys, ", ");
  5. }
  6. }

代码示例来源:origin: com.github.tchoulihan/javalite-common

  1. /**
  2. * Joins the items in collection with a delimiter.
  3. *
  4. * @param collection collection of items to join.
  5. * @param delimiter delimiter to insert between elements of collection.
  6. * @return string with collection elements separated by delimiter. There is no trailing delimiter in the string.
  7. */
  8. public static String join(Collection<?> collection, String delimiter) {
  9. if (collection.isEmpty()) { return ""; }
  10. StringBuilder sb = new StringBuilder();
  11. join(sb, collection, delimiter);
  12. return sb.toString();
  13. }

代码示例来源:origin: org.javalite/javalite-common

  1. /**
  2. * Joins the items in array with a delimiter.
  3. *
  4. * @param array array of items to join.
  5. * @param delimiter delimiter to insert between elements of array.
  6. * @return string with array elements separated by delimiter. There is no trailing delimiter in the string.
  7. */
  8. public static String join(String[] array, String delimiter) {
  9. if (empty(array)) { return ""; }
  10. StringBuilder sb = new StringBuilder();
  11. join(sb, array, delimiter);
  12. return sb.toString();
  13. }

代码示例来源:origin: com.github.tchoulihan/activejdbc

  1. static void logAccess(String query, Object[] params, String access) {
  2. if (logger.isInfoEnabled()) {
  3. StringBuilder log = new StringBuilder().append(access).append(", ").append('"').append(query).append('"');
  4. if (!empty(params)) {
  5. log.append(", with parameters: ").append('<');
  6. join(log, params, ">, <");
  7. log.append('>');
  8. }
  9. LogFilter.log(logger, log.toString());
  10. }
  11. }

相关文章