package me.simple.util;

import java.util.UUID;
import java.util.regex.Pattern;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import org.springframework.web.util.HtmlUtils;

public final class SqlUtil {
    private static final Logger logger = LoggerFactory.getLogger(SqlUtil.class);

    public static String countSql(String querySql) {
	return Pattern.compile("^(select).*?(from)", Pattern.CASE_INSENSITIVE).matcher(querySql.toString())
		.replaceFirst("select count(1) from");
    }

    public static String like(String value) {
	return "%" + StringUtils.trimWhitespace(value) + "%";
    }

    public static String getOrder(String value) {
	return value;
    }
    public static String getSort(String value) {
	return value;
    }
    
    public static String uuid() {
	String uuid = UUID.randomUUID().toString();
	StringBuffer buffer = new StringBuffer();
	buffer.append(uuid.substring(0, 8));
	buffer.append(uuid.substring(9, 13));
	buffer.append(uuid.substring(14, 18));
	buffer.append(uuid.substring(19,23));
	buffer.append(uuid.substring(24));
	
	return buffer.toString();
    }

    public static void main(String[] args) {
	logger.debug(countSql("select * from sys_user"));
	logger.debug(HtmlUtils.htmlEscape("select ' from ' delete from "));
    }
}

@@ -637,32 +637,934 @@
 ) + %22%25%22;%0A    %7D%0A%0A
+    public static String toBeanFieldname(String columname) %7B%0A%09if (!StringUtils.hasText(columname)) %7B%0A%09    return null;%0A%09%7D%0A%09if (columname.indexOf('_') != -1) %7B%0A%09    char%5B%5D ca = columname.toCharArray();%0A%09    boolean bool = false;%0A%09    StringBuffer buffer = new StringBuffer();%0A%09    for (char c : ca) %7B%0A%09%09if (Character.isWhitespace(c)) %7B%0A%09%09    continue;%0A%09%09%7D%0A%09%09if (c == '_') %7B%0A%09%09    bool = true;%0A%09%09    continue;%0A%09%09%7D%0A%09%09if (bool) %7B%0A%09%09    buffer.append(Character.toUpperCase(c));%0A%09%09%7D else %7B%0A%09%09    buffer.append(Character.toLowerCase(c));%0A%09%09%7D%0A%09%09bool = false;%0A%09    %7D%0A%09    if (buffer.length() %3E 1)%0A%09%09return buffer.substring(0, 1).toLowerCase() + buffer.substring(1);%0A%09    else%0A%09%09return buffer.substring(0, 1).toLowerCase();%0A%09%7D else %7B%0A%09    if (columname.length() %3E 1)%0A%09%09return columname.substring(0, 1).toLowerCase() + columname.substring(1);%0A%09    else%0A%09%09return columname.substring(0, 1).toLowerCase();%0A%09%7D%0A    %7D%0A%0A
     public stati
@@ -1589,32 +1589,32 @@
 String value) %7B%0A
-
 %09return value;%0A 
@@ -1614,24 +1614,25 @@
 alue;%0A    %7D%0A
+%0A
     public s
@@ -1693,13 +1693,9 @@
   %7D%0A
-    
 %0A
+
     
@@ -1962,16 +1962,17 @@
 ring(19,
+ 
 23));%0A%09b
@@ -2005,17 +2005,16 @@
 g(24));%0A
-%09
 %0A%09return

add columname to BeanFieldname