本文整理了Java中org.javalite.common.Util.join()
方法的一些代码示例,展示了Util.join()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.join()
方法的具体详情如下:
包路径:org.javalite.common.Util
类名称:Util
方法名:join
[英]Joins the items in collection with a delimiter, and appends the result to StringBuilder.
[中]使用分隔符连接集合中的项,并将结果附加到StringBuilder。
代码示例来源:origin: javalite/activejdbc
private String getAllColumns(String[] columns){
return columns == null ? " *" : " " + join(columns, ", ");
}
代码示例来源:origin: javalite/activejdbc
private String getSQColumns(String[] columns){
if(columns == null){
return "sq.*";
}
List<String> names = new ArrayList<>();
for (String column : columns) {
names.add("sq." + column);
}
return join(names, ", ");
}
代码示例来源:origin: javalite/activejdbc
protected void appendOrderBy(StringBuilder query, List<String> orderBys) {
if (!orderBys.isEmpty()) {
query.append(" ORDER BY ");
join(query, orderBys, ", ");
}
}
代码示例来源:origin: javalite/activejdbc
/**
* Joins the items in collection with a delimiter.
*
* @param collection collection of items to join.
* @param delimiter delimiter to insert between elements of collection.
* @return string with collection elements separated by delimiter. There is no trailing delimiter in the string.
*/
public static String join(Collection<?> collection, String delimiter) {
if (collection.isEmpty()) { return ""; }
StringBuilder sb = new StringBuilder();
join(sb, collection, delimiter);
return sb.toString();
}
代码示例来源:origin: javalite/activejdbc
private static String getMessage(String query, Object[] params, Throwable cause){
StringBuilder sb = new StringBuilder(cause.toString()).append(", query: ").append(query);
if (params != null && params.length > 0) {
sb.append(", params: ");
join(sb, params, ", ");
}
return sb.toString();
}
}
代码示例来源:origin: javalite/activejdbc
/**
* Joins the items in array with a delimiter.
*
* @param array array of items to join.
* @param delimiter delimiter to insert between elements of array.
* @return string with array elements separated by delimiter. There is no trailing delimiter in the string.
*/
public static String join(String[] array, String delimiter) {
if (empty(array)) { return ""; }
StringBuilder sb = new StringBuilder();
join(sb, array, delimiter);
return sb.toString();
}
代码示例来源:origin: javalite/activejdbc
/**
* Produces a parametrized AND query.
* Example:
* <pre>
* String sql = dialect.selectStarParametrized("people", "name", "ssn", "dob");
* //generates:
* //SELECT * FROM people WHERE name = ? AND ssn = ? AND dob = ?
* </pre>
*
*
* @param table name of table
* @param parameters list of parameter names
* @return something like: "select * from table_name where name = ? and last_name = ? ..."
*/
@Override
public String selectStarParametrized(String table, String ... parameters) {
StringBuilder sql = new StringBuilder().append("SELECT * FROM ").append(table).append(" WHERE ");
join(sql, parameters, " = ? AND ");
sql.append(" = ?");
return sql.toString();
}
代码示例来源:origin: javalite/activejdbc
protected void appendSelect(StringBuilder queryBuilder, String tableName, String[] columns, String tableAlias, String subQuery, List<String> orderBys) {
if (tableName == null) {
queryBuilder.append(subQuery);
} else {
if (tableAlias == null) {
String cols = columns == null? "*" : join(columns, ",");
queryBuilder.append("SELECT ").append(cols).append(" FROM ").append(tableName);
} else {
queryBuilder.append("SELECT ").append(tableAlias).append(".* FROM ").append(tableName).append(' ')
.append(tableAlias);
}
appendSubQuery(queryBuilder, subQuery);
}
appendOrderBy(queryBuilder, orderBys);
}
代码示例来源:origin: javalite/activejdbc
@Override
public String insertParametrized(MetaModel metaModel, List<String> columns, boolean containsId) {
StringBuilder query = new StringBuilder().append("INSERT INTO ").append(metaModel.getTableName()).append(' ');
if (columns.isEmpty()) {
appendEmptyRow(metaModel, query);
} else {
boolean addIdGeneratorCode = (!containsId && metaModel.getIdGeneratorCode() != null);
query.append('(');
if (addIdGeneratorCode) {
query.append(metaModel.getIdName()).append(", ");
}
join(query, columns, ", ");
query.append(") VALUES (");
if (addIdGeneratorCode) {
query.append(metaModel.getIdGeneratorCode()).append(", ");
}
appendQuestions(query, columns.size());
query.append(')');
}
return query.toString();
}
代码示例来源:origin: javalite/activejdbc
@Override
public String insert(MetaModel metaModel, Map<String, Object> attributes, String ... replacements) {
StringBuilder query = new StringBuilder().append("INSERT INTO ").append(metaModel.getTableName()).append(' ');
if (attributes.isEmpty()) {
appendEmptyRow(metaModel, query);
} else {
boolean addIdGeneratorCode = (metaModel.getIdGeneratorCode() != null
&& attributes.get(metaModel.getIdName()) == null); // do not use containsKey
query.append('(');
if (addIdGeneratorCode) {
query.append(metaModel.getIdName()).append(", ");
}
join(query, attributes.keySet(), ", ");
query.append(") VALUES (");
if (addIdGeneratorCode) {
query.append(metaModel.getIdGeneratorCode()).append(", ");
}
Iterator<Object> it = attributes.values().iterator();
appendValue(query, it.next());
while (it.hasNext()) {
query.append(", ");
appendValue(query, it.next(), replacements);
}
query.append(')');
}
return query.toString();
}
代码示例来源:origin: javalite/activejdbc
if (needOffset) {
fullQuery.append("SELECT " + getSQColumns(columns) + " FROM (SELECT ROW_NUMBER() OVER (ORDER BY ");
join(fullQuery, orderBys, ", ");
fullQuery.append(") AS rownumber,");
} else if (needLimit) {
代码示例来源:origin: javalite/activejdbc
/**
* Use to see what SQL will be sent to the database.
*
* @param showParameters true to see parameter values, false not to.
* @return SQL in a dialect for current connection which will be used if you start querying this
* list.
*/
public String toSql(boolean showParameters) {
String sql;
if(forPaginator){
sql = metaModel.getDialect().formSelect(null, null, fullQuery, orderBys, limit, offset);
}else{
sql = fullQuery != null ? fullQuery
: metaModel.getDialect().formSelect(metaModel.getTableName(), null, subQuery, orderBys, limit, offset);
}
if (showParameters) {
StringBuilder sb = new StringBuilder(sql).append(", with parameters: ");
join(sb, params, ", ");
sql = sb.toString();
}
return sql;
}
代码示例来源:origin: javalite/activejdbc
/**
* Sets a parent on this instance. Basically this sets a correct value of a foreign key in a
* parent/child relationship. This only works for one to many and polymorphic associations.
* The act of setting a parent does not result in saving to a database.
*
* @param parent potential parent of this instance. Its ID value must not be null.
*/
public void setParent(Model parent) {
if (parent == null || parent.getId() == null) {
throw new IllegalArgumentException("parent cannot ne null and parent ID cannot be null");
}
List<Association> associations = metaModelLocal.getAssociations();
for (Association association : associations) {
if (association instanceof BelongsToAssociation && association.getTargetClass().equals(parent.metaModelLocal.getModelClass())) {
set(((BelongsToAssociation)association).getFkName(), parent.getId());
return;
}
if(association instanceof BelongsToPolymorphicAssociation && association.getTargetClass().equals(parent.metaModelLocal.getModelClass())){
set("parent_id", parent.getId());
set("parent_type", ((BelongsToPolymorphicAssociation)association).getTypeLabel());
return;
}
}
StringBuilder sb = new StringBuilder();
sb.append("Class: ").append(parent.getClass()).append(" is not associated with ").append(this.getClass())
.append(", list of existing associations:\n");
join(sb, metaModelLocal.getAssociations(), "\n");
throw new IllegalArgumentException(sb.toString());
}
代码示例来源:origin: javalite/activejdbc
attributeNames.retainAll(dirtyAttributeNames);
if(attributeNames.size() > 0) {
join(query, attributeNames, " = ?, ");
query.append(" = ?");
代码示例来源:origin: org.javalite/activejdbc
private String getSQColumns(String[] columns){
if(columns == null){
return "sq.*";
}
List<String> names = new ArrayList<>();
for (String column : columns) {
names.add("sq." + column);
}
return join(names, ", ");
}
代码示例来源:origin: org.javalite/activejdbc
protected void appendOrderBy(StringBuilder query, List<String> orderBys) {
if (!orderBys.isEmpty()) {
query.append(" ORDER BY ");
join(query, orderBys, ", ");
}
}
代码示例来源:origin: com.github.tchoulihan/activejdbc
protected void appendOrderBy(StringBuilder query, List<String> orderBys) {
if (!orderBys.isEmpty()) {
query.append(" ORDER BY ");
join(query, orderBys, ", ");
}
}
代码示例来源:origin: com.github.tchoulihan/javalite-common
/**
* Joins the items in collection with a delimiter.
*
* @param collection collection of items to join.
* @param delimiter delimiter to insert between elements of collection.
* @return string with collection elements separated by delimiter. There is no trailing delimiter in the string.
*/
public static String join(Collection<?> collection, String delimiter) {
if (collection.isEmpty()) { return ""; }
StringBuilder sb = new StringBuilder();
join(sb, collection, delimiter);
return sb.toString();
}
代码示例来源:origin: org.javalite/javalite-common
/**
* Joins the items in array with a delimiter.
*
* @param array array of items to join.
* @param delimiter delimiter to insert between elements of array.
* @return string with array elements separated by delimiter. There is no trailing delimiter in the string.
*/
public static String join(String[] array, String delimiter) {
if (empty(array)) { return ""; }
StringBuilder sb = new StringBuilder();
join(sb, array, delimiter);
return sb.toString();
}
代码示例来源:origin: com.github.tchoulihan/activejdbc
static void logAccess(String query, Object[] params, String access) {
if (logger.isInfoEnabled()) {
StringBuilder log = new StringBuilder().append(access).append(", ").append('"').append(query).append('"');
if (!empty(params)) {
log.append(", with parameters: ").append('<');
join(log, params, ">, <");
log.append('>');
}
LogFilter.log(logger, log.toString());
}
}
内容来源于网络,如有侵权,请联系作者删除!