提交 a033c81e authored 作者: Thomas Mueller's avatar Thomas Mueller

H2 Console: column of tables of non-default schemas are now also listed, except…

H2 Console: column of tables of non-default schemas are now also listed, except for schemas starting with 'INFO'.
上级 d2e85b27
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>ALTER TABLE: removing an auto-increment or identity column didn't remove the sequence. <ul><li>H2 Console: column of tables of non-default schemas are now also listed,
except for schemas starting with 'INFO'.
</li><li>ALTER TABLE: removing an auto-increment or identity column didn't remove the sequence.
</li><li>Creating indexes is now a bit faster. </li><li>Creating indexes is now a bit faster.
</li><li>PG Server: new system property h2.pgClientEncoding to explicitly set the encoding </li><li>PG Server: new system property h2.pgClientEncoding to explicitly set the encoding
for clients that don't send the encoding (the default encoding is UTF-8). for clients that don't send the encoding (the default encoding is UTF-8).
......
...@@ -46,25 +46,20 @@ public class Page { ...@@ -46,25 +46,20 @@ public class Page {
*/ */
public static final int TYPE_BTREE_NODE = 5; public static final int TYPE_BTREE_NODE = 5;
/**
* A btree overflow page.
*/
public static final int TYPE_BTREE_OVERFLOW = 6;
/** /**
* A page containing a list of free pages (the last page: + FLAG_LAST). * A page containing a list of free pages (the last page: + FLAG_LAST).
*/ */
public static final int TYPE_FREE_LIST = 7; public static final int TYPE_FREE_LIST = 6;
/** /**
* A stream trunk page. * A stream trunk page.
*/ */
public static final int TYPE_STREAM_TRUNK = 8; public static final int TYPE_STREAM_TRUNK = 7;
/** /**
* A stream data page. * A stream data page.
*/ */
public static final int TYPE_STREAM_DATA = 9; public static final int TYPE_STREAM_DATA = 8;
/** /**
* This is a root page. * This is a root page.
......
...@@ -187,10 +187,6 @@ abstract class PageBtree extends Record { ...@@ -187,10 +187,6 @@ abstract class PageBtree extends Record {
remapChildren(); remapChildren();
} }
int getPageId() {
return getPos();
}
/** /**
* Get the first child leaf page of a page. * Get the first child leaf page of a page.
* *
......
...@@ -92,8 +92,4 @@ public class PageBtreeCursor implements Cursor { ...@@ -92,8 +92,4 @@ public class PageBtreeCursor implements Cursor {
return true; return true;
} }
Session getSession() {
return session;
}
} }
...@@ -107,7 +107,7 @@ public class PageBtreeIndex extends BaseIndex { ...@@ -107,7 +107,7 @@ public class PageBtreeIndex extends BaseIndex {
SearchRow pivot = root.getRow(splitPoint - 1); SearchRow pivot = root.getRow(splitPoint - 1);
PageBtree page1 = root; PageBtree page1 = root;
PageBtree page2 = root.split(splitPoint); PageBtree page2 = root.split(splitPoint);
int rootPageId = root.getPageId(); int rootPageId = root.getPos();
int id = store.allocatePage(); int id = store.allocatePage();
page1.setPageId(id); page1.setPageId(id);
page1.setParentPageId(headPos); page1.setParentPageId(headPos);
...@@ -301,7 +301,7 @@ public class PageBtreeIndex extends BaseIndex { ...@@ -301,7 +301,7 @@ public class PageBtreeIndex extends BaseIndex {
* @param key the row key * @param key the row key
* @return the row * @return the row
*/ */
public Row getRow(Session session, int key) throws SQLException { Row getRow(Session session, int key) throws SQLException {
return tableData.getRow(session, key); return tableData.getRow(session, key);
} }
...@@ -309,16 +309,6 @@ public class PageBtreeIndex extends BaseIndex { ...@@ -309,16 +309,6 @@ public class PageBtreeIndex extends BaseIndex {
return store; return store;
} }
/**
* Read a row from the data page at the given position.
*
* @param data the data page
* @return the row
*/
Row readRow(Data data) throws SQLException {
return tableData.readRow(data);
}
public long getRowCountApproximation() { public long getRowCountApproximation() {
return rowCount; return rowCount;
} }
......
...@@ -13,7 +13,6 @@ import org.h2.message.Message; ...@@ -13,7 +13,6 @@ import org.h2.message.Message;
import org.h2.result.SearchRow; import org.h2.result.SearchRow;
import org.h2.store.Data; import org.h2.store.Data;
import org.h2.store.DataPage; import org.h2.store.DataPage;
import org.h2.store.PageStore;
/** /**
* A b-tree leaf page that contains index data. * A b-tree leaf page that contains index data.
...@@ -43,7 +42,7 @@ class PageBtreeLeaf extends PageBtree { ...@@ -43,7 +42,7 @@ class PageBtreeLeaf extends PageBtree {
int tableId = data.readInt(); int tableId = data.readInt();
if (tableId != index.getId()) { if (tableId != index.getId()) {
throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1, throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1,
"page:" + getPageId() + " expected table:" + index.getId() + "page:" + getPos() + " expected table:" + index.getId() +
"got:" + tableId); "got:" + tableId);
} }
entryCount = data.readShortInt(); entryCount = data.readShortInt();
...@@ -191,10 +190,6 @@ class PageBtreeLeaf extends PageBtree { ...@@ -191,10 +190,6 @@ class PageBtreeLeaf extends PageBtree {
index.getPageStore().writePage(getPos(), data); index.getPageStore().writePage(getPos(), data);
} }
PageStore getPageStore() {
return index.getPageStore();
}
private void write() throws SQLException { private void write() throws SQLException {
if (written) { if (written) {
return; return;
...@@ -214,11 +209,6 @@ class PageBtreeLeaf extends PageBtree { ...@@ -214,11 +209,6 @@ class PageBtreeLeaf extends PageBtree {
written = true; written = true;
} }
Data getData() throws SQLException {
write();
return data;
}
void find(PageBtreeCursor cursor, SearchRow first, boolean bigger) throws SQLException { void find(PageBtreeCursor cursor, SearchRow first, boolean bigger) throws SQLException {
int i = find(first, bigger, false); int i = find(first, bigger, false);
if (i > entryCount) { if (i > entryCount) {
......
...@@ -145,7 +145,7 @@ class PageBtreeNode extends PageBtree { ...@@ -145,7 +145,7 @@ class PageBtreeNode extends PageBtree {
return splitPoint2; return splitPoint2;
} }
PageBtree page2 = page.split(splitPoint); PageBtree page2 = page.split(splitPoint);
addChild(x, page2.getPageId(), pivot); addChild(x, page2.getPos(), pivot);
index.getPageStore().updateRecord(page, true, page.data); index.getPageStore().updateRecord(page, true, page.data);
index.getPageStore().updateRecord(page2, true, page2.data); index.getPageStore().updateRecord(page2, true, page2.data);
index.getPageStore().updateRecord(this, true, data); index.getPageStore().updateRecord(this, true, data);
...@@ -205,10 +205,10 @@ class PageBtreeNode extends PageBtree { ...@@ -205,10 +205,10 @@ class PageBtreeNode extends PageBtree {
*/ */
void init(PageBtree page1, SearchRow pivot, PageBtree page2) throws SQLException { void init(PageBtree page1, SearchRow pivot, PageBtree page2) throws SQLException {
entryCount = 0; entryCount = 0;
childPageIds = new int[] { page1.getPageId() }; childPageIds = new int[] { page1.getPos() };
rows = new SearchRow[0]; rows = new SearchRow[0];
offsets = MemoryUtils.EMPTY_INTS; offsets = MemoryUtils.EMPTY_INTS;
addChild(0, page2.getPageId(), pivot); addChild(0, page2.getPos(), pivot);
check(); check();
} }
...@@ -253,7 +253,7 @@ class PageBtreeNode extends PageBtree { ...@@ -253,7 +253,7 @@ class PageBtreeNode extends PageBtree {
return false; return false;
} }
// this child is now empty // this child is now empty
index.getPageStore().freePage(page.getPageId(), true, page.data); index.getPageStore().freePage(page.getPos(), true, page.data);
if (entryCount < 1) { if (entryCount < 1) {
// no more children - this page is empty as well // no more children - this page is empty as well
return true; return true;
......
...@@ -36,27 +36,27 @@ class PageDataLeaf extends PageData { ...@@ -36,27 +36,27 @@ class PageDataLeaf extends PageData {
/** /**
* The row offsets. * The row offsets.
*/ */
int[] offsets; private int[] offsets;
/** /**
* The rows. * The rows.
*/ */
Row[] rows; private Row[] rows;
/** /**
* For pages with overflow: the soft reference to the row * For pages with overflow: the soft reference to the row
*/ */
SoftReference<Row> rowRef; private SoftReference<Row> rowRef;
/** /**
* The page id of the first overflow page (0 if no overflow). * The page id of the first overflow page (0 if no overflow).
*/ */
int firstOverflowPageId; private int firstOverflowPageId;
/** /**
* The start of the data area. * The start of the data area.
*/ */
int start; private int start;
/** /**
* The size of the row in bytes for large rows. * The size of the row in bytes for large rows.
...@@ -340,10 +340,6 @@ class PageDataLeaf extends PageData { ...@@ -340,10 +340,6 @@ class PageDataLeaf extends PageData {
data.truncate(index.getPageStore().getPageSize()); data.truncate(index.getPageStore().getPageSize());
} }
PageStore getPageStore() {
return index.getPageStore();
}
private void readAllRows() throws SQLException { private void readAllRows() throws SQLException {
for (int i = 0; i < entryCount; i++) { for (int i = 0; i < entryCount; i++) {
getRowAt(i); getRowAt(i);
......
...@@ -153,10 +153,6 @@ public class PageDataLeafOverflow extends Record { ...@@ -153,10 +153,6 @@ public class PageDataLeafOverflow extends Record {
return index.getPageStore().getPageSize() >> 1; return index.getPageStore().getPageSize() >> 1;
} }
int getParent() {
return parentPage;
}
void setParent(int parent) { void setParent(int parent) {
this.parentPage = parent; this.parentPage = parent;
} }
......
...@@ -31,33 +31,47 @@ public class DbSchema { ...@@ -31,33 +31,47 @@ public class DbSchema {
/** /**
* The database content container. * The database content container.
*/ */
DbContents contents; final DbContents contents;
/** /**
* The schema name. * The schema name.
*/ */
String name; final String name;
/** /**
* The quoted schema name. * True if this is the default schema for this database.
*/ */
String quotedName; final boolean isDefault;
/** /**
* The table list. * True if this is a system schema (for example the INFORMATION_SCHEMA).
*/ */
DbTableOrView[] tables; final boolean isSystem;
/** /**
* True if this is the default schema for this database. * The quoted schema name.
*/ */
boolean isDefault; final String quotedName;
/**
* The table list.
*/
DbTableOrView[] tables;
DbSchema(DbContents contents, String name, boolean isDefault) { DbSchema(DbContents contents, String name, boolean isDefault) {
this.contents = contents; this.contents = contents;
this.name = name; this.name = name;
this.quotedName = contents.quoteIdentifier(name); this.quotedName = contents.quoteIdentifier(name);
this.isDefault = isDefault; this.isDefault = isDefault;
if (name.toUpperCase().startsWith("INFO")) {
isSystem = true;
} else if (contents.isPostgreSQL && name.toUpperCase().startsWith("PG_")) {
isSystem = true;
} else if (contents.isDerby && name.startsWith("SYS")) {
isSystem = true;
} else {
isSystem = false;
}
} }
/** /**
......
...@@ -678,7 +678,7 @@ class WebThread extends Thread implements DatabaseEventListener { ...@@ -678,7 +678,7 @@ class WebThread extends Thread implements DatabaseEventListener {
return "query.jsp"; return "query.jsp";
} }
private int addColumns(DbTableOrView table, StringBuilder buff, int treeIndex, boolean showColumnTypes, private int addColumns(boolean mainSchema, DbTableOrView table, StringBuilder buff, int treeIndex, boolean showColumnTypes,
StringBuilder columnsBuffer) { StringBuilder columnsBuffer) {
DbColumn[] columns = table.columns; DbColumn[] columns = table.columns;
for (int i = 0; columns != null && i < columns.length; i++) { for (int i = 0; columns != null && i < columns.length; i++) {
...@@ -688,10 +688,11 @@ class WebThread extends Thread implements DatabaseEventListener { ...@@ -688,10 +688,11 @@ class WebThread extends Thread implements DatabaseEventListener {
} }
columnsBuffer.append(column.name); columnsBuffer.append(column.name);
String col = StringUtils.urlEncode(PageParser.escapeJavaScript(column.name)); String col = StringUtils.urlEncode(PageParser.escapeJavaScript(column.name));
buff.append("setNode(" + treeIndex + ", 1, 1, 'column', '" + PageParser.escapeJavaScript(column.name) String level = mainSchema ? ", 1, 1" : ", 2, 2";
buff.append("setNode(" + treeIndex + level + ", 'column', '" + PageParser.escapeJavaScript(column.name)
+ "', 'javascript:ins(\\'" + col + "\\')');\n"); + "', 'javascript:ins(\\'" + col + "\\')');\n");
treeIndex++; treeIndex++;
if (showColumnTypes) { if (mainSchema && showColumnTypes) {
buff.append("setNode(" + treeIndex + ", 2, 2, 'type', '" + PageParser.escapeJavaScript(column.dataType) buff.append("setNode(" + treeIndex + ", 2, 2, 'type', '" + PageParser.escapeJavaScript(column.dataType)
+ "', null);\n"); + "', null);\n");
treeIndex++; treeIndex++;
...@@ -778,8 +779,9 @@ class WebThread extends Thread implements DatabaseEventListener { ...@@ -778,8 +779,9 @@ class WebThread extends Thread implements DatabaseEventListener {
Connection conn = session.getConnection(); Connection conn = session.getConnection();
DatabaseMetaData meta = session.getMetaData(); DatabaseMetaData meta = session.getMetaData();
int level = mainSchema ? 0 : 1; int level = mainSchema ? 0 : 1;
String indentation = ", " + level + ", " + (level + 1) + ", "; boolean showColumns = mainSchema || !schema.isSystem;
String indentNode = ", " + (level + 1) + ", " + (level + 1) + ", "; String indentation = ", " + level + ", " + (showColumns ? "1" : "2") + ", ";
String indentNode = ", " + (level + 1) + ", 2, ";
DbTableOrView[] tables = schema.tables; DbTableOrView[] tables = schema.tables;
if (tables == null) { if (tables == null) {
return treeIndex; return treeIndex;
...@@ -799,10 +801,10 @@ class WebThread extends Thread implements DatabaseEventListener { ...@@ -799,10 +801,10 @@ class WebThread extends Thread implements DatabaseEventListener {
buff.append("setNode(" + treeIndex + indentation + " 'table', '" + PageParser.escapeJavaScript(table.name) buff.append("setNode(" + treeIndex + indentation + " 'table', '" + PageParser.escapeJavaScript(table.name)
+ "', 'javascript:ins(\\'" + tab + "\\',true)');\n"); + "', 'javascript:ins(\\'" + tab + "\\',true)');\n");
treeIndex++; treeIndex++;
if (mainSchema) { if (mainSchema || showColumns) {
StringBuilder columnsBuffer = new StringBuilder(); StringBuilder columnsBuffer = new StringBuilder();
treeIndex = addColumns(table, buff, treeIndex, notManyTables, columnsBuffer); treeIndex = addColumns(mainSchema, table, buff, treeIndex, notManyTables, columnsBuffer);
if (!isOracle && notManyTables) { if (mainSchema && !isOracle && notManyTables) {
treeIndex = addIndexes(meta, table.name, schema.name, buff, treeIndex); treeIndex = addIndexes(meta, table.name, schema.name, buff, treeIndex);
} }
buff.append("addTable('" + PageParser.escapeJavaScript(table.name) + "', '" buff.append("addTable('" + PageParser.escapeJavaScript(table.name) + "', '"
...@@ -825,7 +827,7 @@ class WebThread extends Thread implements DatabaseEventListener { ...@@ -825,7 +827,7 @@ class WebThread extends Thread implements DatabaseEventListener {
treeIndex++; treeIndex++;
if (mainSchema) { if (mainSchema) {
StringBuilder columnsBuffer = new StringBuilder(); StringBuilder columnsBuffer = new StringBuilder();
treeIndex = addColumns(view, buff, treeIndex, notManyTables, columnsBuffer); treeIndex = addColumns(mainSchema, view, buff, treeIndex, notManyTables, columnsBuffer);
if (schema.contents.isH2) { if (schema.contents.isH2) {
PreparedStatement prep = null; PreparedStatement prep = null;
try { try {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论