提交 481146ad authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 bccf4e46
......@@ -133,8 +133,8 @@
<java classname="org.h2.tools.doc.LinkChecker" classpath="bin">
<arg line="-dir docs"/>
</java>
<java classname="org.h2.tools.doc.XMLChecker" classpath="bin">
</java>
<java classname="org.h2.tools.doc.XMLChecker" classpath="bin"/>
<java classname="org.h2.tools.doc.SpellChecker" classpath="bin"/>
</target>
<target name="gcj" depends="compileResources">
......
......@@ -44,7 +44,7 @@ public class TestManyJdbcObjects extends TestBase {
// SERVER_CACHED_OBJECTS = 500: connections = 40
// SERVER_CACHED_OBJECTS = 50: connections = 120
deleteDb("manyObjects");
Constants.RUN_FINALIZERS = false;
Constants.RUN_FINALIZE = false;
int connCount = getSize(4, 40);
Connection[] conn = new Connection[connCount];
for(int i=0; i<connCount; i++) {
......@@ -62,12 +62,12 @@ public class TestManyJdbcObjects extends TestBase {
for(int i=0; i<connCount; i++) {
conn[i].close();
}
Constants.RUN_FINALIZERS = true;
Constants.RUN_FINALIZE = true;
}
private void testOneConnectionPrepare() throws Exception {
deleteDb("manyObjects");
Constants.RUN_FINALIZERS = false;
Constants.RUN_FINALIZE = false;
Connection conn = getConnection("manyObjects");
PreparedStatement prep;
Statement stat;
......@@ -98,7 +98,7 @@ public class TestManyJdbcObjects extends TestBase {
for(int i=0; i<size; i++) {
prep.executeQuery();
}
Constants.RUN_FINALIZERS = true;
Constants.RUN_FINALIZE = true;
conn.close();
}
......
......@@ -27,6 +27,7 @@ public class TestPreparedStatement extends TestBase {
deleteDb("preparedStatement");
Connection conn = getConnection("preparedStatement");
testUUIDGeneratedKeys(conn);
testSetObject(conn);
testPreparedSubquery(conn);
testLikeIndex(conn);
......@@ -43,6 +44,17 @@ public class TestPreparedStatement extends TestBase {
conn.close();
}
private void testUUIDGeneratedKeys(Connection conn) throws Exception {
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TESTUUID(id UUID DEFAULT random_UUID() PRIMARY KEY)");
stat.execute("INSERT INTO TESTUUID() VALUES()");
ResultSet rs = stat.getGeneratedKeys();
rs.next();
byte[] data = rs.getBytes(1);
check(data.length, 16);
stat.execute("DROP TABLE TESTUUID");
}
private void testSetObject(Connection conn) throws Exception {
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT, DATA BINARY, JAVA OTHER)");
......
......@@ -15,7 +15,7 @@ public class CheckTextFiles {
new CheckTextFiles().run();
}
String[] suffixCheck = new String[]{"html", "jsp", "js", "css", "bat", "nsi", "java", "txt", "properties", "cpp", "def", "h", "rc", "dev", "sql", "xml", "csv", "Driver"};
String[] suffixCheck = new String[]{"html", "jsp", "js", "css", "bat", "nsi", "java", "txt", "properties", "cpp", "def", "h", "rc", "dev", "sql", "xml", "csv", "Driver", "php"};
String[] suffixIgnore = new String[]{"gif", "png", "odg", "ico", "sxd", "layout", "res", "win", "dll", "jar", "task"};
boolean failOnError;
boolean allowTab, allowCR = true, allowTrailingSpaces = true;
......@@ -92,6 +92,15 @@ public class CheckTextFiles {
if(text.indexOf(copyrightLicense) < 0) {
fail(file, "license is missing", 0);
}
if(text.indexOf(" " + "//#") > 0) {
fail(file, "unexpected space,//#", 0);
}
if(text.indexOf(" " + "#ifdef") > 0) {
fail(file, "unexpected space,#if", 0);
}
if(text.indexOf(" " + "#endif") > 0) {
fail(file, "unexpected space,#endif", 0);
}
}
}
int line = 1;
......@@ -167,7 +176,20 @@ public class CheckTextFiles {
}
private void fail(File file, String error, int line) {
System.out.println("FAIL: File " + file.getAbsolutePath() + " " + error + " at line " + line);
if(line <= 0) {
line = 1;
}
String name = file.getAbsolutePath();
int idx = name.lastIndexOf(File.separatorChar);
if(idx >= 0) {
name = name.replace(File.separatorChar, '.');
name = name + "(" + name.substring(idx + 1) + ":" + line + ")";
idx = name.indexOf("org.");
if(idx > 0) {
name = name.substring(idx);
}
}
System.out.println("FAIL at " + name + " " + error + " " + file.getAbsolutePath());
hasError = true;
if(failOnError) {
throw new Error("FAIL");
......
......@@ -194,7 +194,7 @@ public class CodeSwitch {
if (lineTrim.startsWith("//#")) {
if (lineTrim.startsWith("//#ifdef ")) {
if (state != 0) {
printError("//#ifdef not allowed inside //#ifdef");
printError("//#ifdef not allowed inside " + "//#ifdef");
return false;
}
state = 1;
......@@ -244,7 +244,7 @@ public class CodeSwitch {
}
} else if (lineTrim.startsWith("//#else")) {
if (state != 1) {
printError("//#else without //#ifdef");
printError("//#else without " + "//#ifdef");
return false;
}
state = 2;
......@@ -259,7 +259,7 @@ public class CodeSwitch {
}
} else if (lineTrim.startsWith("//#endif")) {
if (state == 0) {
printError("//#endif without //#ifdef");
printError("//#endif without " + "//#ifdef");
return false;
}
state = 0;
......
package org.h2.tools.doc;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.StringTokenizer;
import org.h2.util.IOUtils;
public class SpellChecker {
private HashSet dictionary = new HashSet();
private HashSet used = new HashSet();
private HashMap unknown = new HashMap();
private boolean debug;
private boolean addToDictionary;
private static final String[] SUFFIX = new String[]{"java", "sql", "cpp", "txt", "html", "xml", "jsp", "css", "bat", "nsi", "csv", "xml", "js", "def", "dev", "h", "Driver", "properties", "win", "task", "php", "" };
private static final String[] IGNORE = new String[]{"gif", "png", "odg", "ico", "sxd", "zip", "bz2", "rc", "layout", "res", "dll", "jar"};
public static void main(String[] args) throws IOException {
String dir = "src";
new SpellChecker().run("tools/org/h2/tools/doc/dictionary.txt", dir);
}
private void run(String dictionary, String dir) throws IOException {
process(new File(dir + "/" + dictionary));
process(new File(dir));
System.out.println("used words");
for(Iterator it = used.iterator(); it.hasNext();) {
String s = (String) it.next();
System.out.print(s + " ");
}
System.out.println();
System.out.println("ALL UNKNOWN ----------------------------");
for(Iterator it = unknown.keySet().iterator(); it.hasNext();) {
String s = (String) it.next();
int count = ((Integer) unknown.get(s)).intValue();
if(count > 5) {
System.out.print(s + " ");
}
}
System.out.println();
if(unknown.size() > 0) {
throw new IOException("spell check failed");
}
}
private void process(File file) throws IOException {
String name = file.getCanonicalPath();
if(name.endsWith(".svn")) {
return;
}
int removeThisLater;
if(name.indexOf("\\test\\") >= 0) {
return;
}
if(file.isDirectory()) {
File[] list = file.listFiles();
for(int i=0; i<list.length; i++) {
process(list[i]);
}
} else {
String fileName = file.getAbsolutePath();
int idx = fileName.lastIndexOf('.');
String suffix;
if(idx < 0) {
suffix = "";
} else {
suffix = fileName.substring(idx + 1);
}
boolean ignore = false;
for(int i=0; i<IGNORE.length; i++) {
if(IGNORE[i].equals(suffix)) {
ignore = true;
break;
}
}
if(ignore) {
return;
}
boolean ok = false;
for(int i=0; i<SUFFIX.length; i++) {
if(SUFFIX[i].equals(suffix)) {
ok = true;
break;
}
}
if(!ok) {
throw new IOException("Unsupported suffix: " + suffix + " for file: " + fileName);
}
if("java".equals(suffix) || "xml".equals(suffix) || "txt".equals(suffix)) {
FileReader reader = null;
String text = null;
try {
reader = new FileReader(file);
text = readStringAndClose(reader, -1);
} finally {
IOUtils.closeSilently(reader);
}
if(fileName.endsWith("dictionary.txt")) {
addToDictionary = true;
} else {
addToDictionary = false;
}
scan(fileName, text);
}
}
}
private void scan(String fileName, String text) {
HashSet notfound = new HashSet();
StringTokenizer tokenizer = new StringTokenizer(text, "\r\n \t+\"*%&/()='[]{},.-;:_<>\\!?$@#|~^`");
while(tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
char first = token.charAt(0);
if(Character.isDigit(first)) {
continue;
}
if(!addToDictionary && debug) {
System.out.print(token + " ");
}
scanCombinedToken(notfound, token);
if(!addToDictionary && debug) {
System.out.println();
}
}
if(notfound.isEmpty()) {
return;
}
if(notfound.size() > 0) {
System.out.println("file: " + fileName);
for(Iterator it = notfound.iterator(); it.hasNext();) {
String s = (String) it.next();
System.out.print(s + " ");
}
System.out.println();
}
}
private void scanCombinedToken(HashSet notfound, String token) {
for(int i=1; i<token.length(); i++) {
char cleft = token.charAt(i-1);
char cright = token.charAt(i);
if(Character.isLowerCase(cleft) && Character.isUpperCase(cright)) {
scanToken(notfound, token.substring(0, i));
token = token.substring(i);
i = 1;
} else if(Character.isUpperCase(cleft) && Character.isLowerCase(cright)) {
scanToken(notfound, token.substring(0, i - 1));
token = token.substring(i - 1);
i = 1;
}
}
scanToken(notfound, token);
}
private void scanToken(HashSet notfound, String token) {
if(token.length() < 3) {
return;
}
while(true) {
char last = token.charAt(token.length() - 1);
if(!Character.isDigit(last)) {
break;
}
token = token.substring(0, token.length() - 1);
}
if(token.length() < 3) {
return;
}
for(int i=0; i<token.length(); i++) {
if(Character.isDigit(token.charAt(i))) {
return;
}
}
token = token.toLowerCase();
if(!addToDictionary && debug) {
System.out.print(token + " ");
}
if(addToDictionary) {
dictionary.add(token);
} else {
if(!dictionary.contains(token)) {
notfound.add(token);
increment(unknown, token);
} else {
used.add(token);
}
}
}
private void increment(HashMap map, String key) {
Integer value = (Integer) map.get(key);
value = new Integer(value == null ? 0 : value.intValue() + 1);
map.put(key, value);
}
public static String readStringAndClose(Reader in, int length) throws IOException {
if(length <= 0) {
length = Integer.MAX_VALUE;
}
int block = Math.min(4096, length);
StringWriter out=new StringWriter(length == Integer.MAX_VALUE ? block : length);
char[] buff=new char[block];
while(length > 0) {
int len = Math.min(block, length);
len = in.read(buff, 0, len);
if(len < 0) {
break;
}
out.write(buff, 0, len);
length -= len;
}
in.close();
return out.toString();
}
}
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论