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

Formatting and documentation.

上级 77825d1b
......@@ -586,7 +586,7 @@ Another (more dangerous) solution is to set <code>useDatabaseLock</code> to fals
<h2 id="using_netbeans">Using H2 within NetBeans</h2>
<p>
The project <a href="">H2 Database Engine Support For NetBeans</a>
The project <a href="">H2 Database Engine Support For NetBeans</a>
allows you to start and stop the H2 server from within the IDE.
</p>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.command.ddl;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.schema.SchemaObject;
import java.util.ArrayList;
/**
* This class represents the statement
* ALTER SCHEMA RENAME
*/
public class AlterSchemaRename extends DefineCommand {
private Schema oldSchema;
private String newSchemaName;
public AlterSchemaRename(Session session) {
super(session);
}
public void setOldSchema(Schema Schema) {
oldSchema = Schema;
}
public void setNewName(String name) {
newSchemaName = name;
}
public int update() {
session.commit(true);
Database db = session.getDatabase();
if (db.findSchema(newSchemaName) != null || newSchemaName.equals(oldSchema.getName())) {
throw DbException.get(ErrorCode.SCHEMA_ALREADY_EXISTS_1, newSchemaName);
}
session.getUser().checkAdmin();
db.renameDatabaseObject(session, oldSchema, newSchemaName);
ArrayList<SchemaObject> all = db.getAllSchemaObjects();
for (SchemaObject schemaObject : all) {
db.update(session, schemaObject);
}
return 0;
}
}
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.command.ddl;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.schema.Schema;
import org.h2.schema.SchemaObject;
import java.util.ArrayList;
/**
* This class represents the statement
* ALTER SCHEMA RENAME
*/
public class AlterSchemaRename extends DefineCommand {
private Schema oldSchema;
private String newSchemaName;
public AlterSchemaRename(Session session) {
super(session);
}
public void setOldSchema(Schema Schema) {
oldSchema = Schema;
}
public void setNewName(String name) {
newSchemaName = name;
}
public int update() {
session.commit(true);
Database db = session.getDatabase();
if (db.findSchema(newSchemaName) != null || newSchemaName.equals(oldSchema.getName())) {
throw DbException.get(ErrorCode.SCHEMA_ALREADY_EXISTS_1, newSchemaName);
}
session.getUser().checkAdmin();
db.renameDatabaseObject(session, oldSchema, newSchemaName);
ArrayList<SchemaObject> all = db.getAllSchemaObjects();
for (SchemaObject schemaObject : all) {
db.update(session, schemaObject);
}
return 0;
}
}
......@@ -1227,18 +1227,18 @@ public class Database implements DataHandler {
}
/**
* Get all schema objects.
*
* @return all objects of all types
*/
public ArrayList<SchemaObject> getAllSchemaObjects() {
initMetaTables();
ArrayList<SchemaObject> list = New.arrayList();
for (Schema schema : schemas.values()) {
list.addAll(schema.getAll());
}
return list;
}
* Get all schema objects.
*
* @return all objects of all types
*/
public ArrayList<SchemaObject> getAllSchemaObjects() {
initMetaTables();
ArrayList<SchemaObject> list = New.arrayList();
for (Schema schema : schemas.values()) {
list.addAll(schema.getAll());
}
return list;
}
/**
* Get all schema objects of the given type.
......
......@@ -306,7 +306,7 @@ public class PgServer implements Service {
if (tableName.startsWith("\"") && tableName.endsWith("\"")) {
tableName = tableName.substring(1, tableName.length() - 1);
}
PreparedStatement prep = conn.prepareStatement("select oid from pg_class where relname = ?");
PreparedStatement prep = conn.prepareStatement("select oid from pg_class where relName = ?");
prep.setString(1, tableName);
ResultSet rs = prep.executeQuery();
if (!rs.next()) {
......
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.db;
import org.h2.constant.ErrorCode;
import org.h2.test.TestBase;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* Test ALTER SCHEMA RENAME statements.
*/
public class TestAlterSchemaRename extends TestBase {
private Connection conn;
private Statement stat;
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String... a) throws Exception {
TestBase.createCaller().init().test();
}
public void test() throws Exception {
deleteDb("alter");
conn = getConnection("alter");
stat = conn.createStatement();
testSimpleRename();
testRenameToExistingSchema();
testCrossSchemaViews();
testAlias();
conn.close();
deleteDb("alter");
}
private void testSimpleRename() throws SQLException {
stat.execute("create schema s1");
stat.execute("create table s1.tab(val int)");
stat.execute("insert into s1.tab(val) values (3)");
ResultSet rs = stat.executeQuery("select * from s1.tab");
assertTrue(rs.next());
assertEquals(3, rs.getInt(1));
stat.execute("alter schema s1 rename to s2");
rs = stat.executeQuery("select * from s2.tab");
assertTrue(rs.next());
assertEquals(3, rs.getInt(1));
stat.execute("drop schema s2");
}
private void testRenameToExistingSchema() throws SQLException {
stat.execute("create schema s1");
stat.execute("create schema s2");
try {
stat.execute("alter schema s1 rename to s2");
fail("Exception should be thrown");
} catch (SQLException e) {
assertEquals(ErrorCode.SCHEMA_ALREADY_EXISTS_1, e.getErrorCode());
}
stat.execute("drop schema s1");
stat.execute("drop schema s2");
}
private void testCrossSchemaViews() throws SQLException {
stat.execute("create schema s1");
stat.execute("create schema s2");
stat.execute("create table s1.tab(val int)");
stat.execute("insert into s1.tab(val) values (3)");
stat.execute("create view s1.v1 as select * from s1.tab");
stat.execute("create view s2.v1 as select val * 2 from s1.tab");
stat.execute("alter schema s2 rename to s2_new");
ResultSet rs = stat.executeQuery("select * from s1.v1");
assertTrue(rs.next());
assertEquals(3, rs.getInt(1));
rs = stat.executeQuery("select * from s2_new.v1");
assertTrue(rs.next());
assertEquals(6, rs.getInt(1));
if (!config.memory) {
conn.close();
conn = getConnection("alter");
stat = conn.createStatement();
stat.executeQuery("select * from s2_new.v1");
}
stat.execute("drop schema s1");
stat.execute("drop schema s2_new");
}
/**
* Check that aliases in the schema got moved
*/
private void testAlias() throws SQLException {
stat.execute("create schema s1");
stat.execute("CREATE ALIAS S1.REVERSE AS $$ " +
"String reverse(String s) {" +
" return new StringBuilder(s).reverse().toString();" +
"} $$;");
stat.execute("alter schema s1 rename to s2");
ResultSet rs = stat.executeQuery("CALL S2.REVERSE('1234')");
assertTrue(rs.next());
assertEquals("4321", rs.getString(1));
if (!config.memory) {
conn.close();
conn = getConnection("alter");
stat = conn.createStatement();
stat.executeQuery("CALL S2.REVERSE('1234')");
}
stat.execute("drop schema s2");
}
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.db;
import org.h2.constant.ErrorCode;
import org.h2.test.TestBase;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* Test ALTER SCHEMA RENAME statements.
*/
public class TestAlterSchemaRename extends TestBase {
private Connection conn;
private Statement stat;
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String... a) throws Exception {
TestBase.createCaller().init().test();
}
public void test() throws Exception {
deleteDb("alter");
conn = getConnection("alter");
stat = conn.createStatement();
testSimpleRename();
testRenameToExistingSchema();
testCrossSchemaViews();
testAlias();
conn.close();
deleteDb("alter");
}
private void testSimpleRename() throws SQLException {
stat.execute("create schema s1");
stat.execute("create table s1.tab(val int)");
stat.execute("insert into s1.tab(val) values (3)");
ResultSet rs = stat.executeQuery("select * from s1.tab");
assertTrue(rs.next());
assertEquals(3, rs.getInt(1));
stat.execute("alter schema s1 rename to s2");
rs = stat.executeQuery("select * from s2.tab");
assertTrue(rs.next());
assertEquals(3, rs.getInt(1));
stat.execute("drop schema s2");
}
private void testRenameToExistingSchema() throws SQLException {
stat.execute("create schema s1");
stat.execute("create schema s2");
try {
stat.execute("alter schema s1 rename to s2");
fail("Exception should be thrown");
} catch (SQLException e) {
assertEquals(ErrorCode.SCHEMA_ALREADY_EXISTS_1, e.getErrorCode());
}
stat.execute("drop schema s1");
stat.execute("drop schema s2");
}
private void testCrossSchemaViews() throws SQLException {
stat.execute("create schema s1");
stat.execute("create schema s2");
stat.execute("create table s1.tab(val int)");
stat.execute("insert into s1.tab(val) values (3)");
stat.execute("create view s1.v1 as select * from s1.tab");
stat.execute("create view s2.v1 as select val * 2 from s1.tab");
stat.execute("alter schema s2 rename to s2_new");
ResultSet rs = stat.executeQuery("select * from s1.v1");
assertTrue(rs.next());
assertEquals(3, rs.getInt(1));
rs = stat.executeQuery("select * from s2_new.v1");
assertTrue(rs.next());
assertEquals(6, rs.getInt(1));
if (!config.memory) {
conn.close();
conn = getConnection("alter");
stat = conn.createStatement();
stat.executeQuery("select * from s2_new.v1");
}
stat.execute("drop schema s1");
stat.execute("drop schema s2_new");
}
/**
* Check that aliases in the schema got moved
*/
private void testAlias() throws SQLException {
stat.execute("create schema s1");
stat.execute("CREATE ALIAS S1.REVERSE AS $$ " +
"String reverse(String s) {" +
" return new StringBuilder(s).reverse().toString();" +
"} $$;");
stat.execute("alter schema s1 rename to s2");
ResultSet rs = stat.executeQuery("CALL S2.REVERSE('1234')");
assertTrue(rs.next());
assertEquals("4321", rs.getString(1));
if (!config.memory) {
conn.close();
conn = getConnection("alter");
stat = conn.createStatement();
stat.executeQuery("CALL S2.REVERSE('1234')");
}
stat.execute("drop schema s2");
}
}
\ No newline at end of file
......@@ -649,4 +649,4 @@ importing cumulative fired convenient sums judged anybody vacuum encountered
corresponds cnf informatique ilm boundaries shao crossed retroweaver usr pico
pengxiang china timestampadd picked releasing autoboxing conversions
pagestore addon defaults introduced customized histogram transact locker activemq
iml
iml unified regclass netbeans geqo servername creator
......@@ -12,37 +12,43 @@ import org.h2.build.BuildBase;
/**
* Creates the v 1.1 upgrade sources
*/
public class UpgradeCreator {
public class UpgradeCreator {
/**
* This method is called when executing this application from the command
* line.
*
* @param args the command line parameters
*/
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.out.println("Usage: java -cp . org.h2.build.upgrade.UpgradeCreator <srcdir> <destdir>");
System.exit(1);
System.out.println("Usage: java -cp . org.h2.build.upgrade.UpgradeCreator <srcDir> <destDir>");
System.exit(1);
}
File srcDir = new File(args[0]);
if (!srcDir.exists()) {
System.out.println("Source dir does not exist");
System.exit(1);
System.exit(1);
}
File destDir = new File(args[1]);
if (destDir.exists()) {
System.out.println("Destination dir already exists");
System.exit(1);
System.exit(1);
}
destDir.mkdirs();
convert(srcDir, srcDir, destDir);
}
private static void convert(File file, File srcDir, File destDir) throws Exception {
String pathInDestDir = file.getCanonicalPath().substring(srcDir.getCanonicalPath().length());
pathInDestDir = pathInDestDir.replaceAll("org" + File.separator + "h2",
"org" + File.separator +
"h2" + File.separator +
"upgrade" + File.separator +
pathInDestDir = pathInDestDir.replaceAll("org" + File.separator + "h2",
"org" + File.separator +
"h2" + File.separator +
"upgrade" + File.separator +
"v1_1");
File fileInDestDir = new File(destDir, pathInDestDir);
// System.out.println(fileInDestDir.getAbsoluteFile());
// System.out.println(fileInDestDir.getAbsoluteFile());
if (file.isDirectory()) {
fileInDestDir.mkdirs();
File[] files = file.listFiles();
......@@ -60,10 +66,10 @@ public class UpgradeCreator {
contentString = contentString.replaceAll("org/h2/", "org/h2/upgrade/v1_1/");
}
content = contentString.getBytes();
BuildBase.writeFile(fileInDestDir, content);
BuildBase.writeFile(fileInDestDir, content);
}
}
private static String replaceInJavaFile(File file, String content) {
content = content.replaceAll("import org\\.h2", "import org.h2.upgrade.v1_1");
content = content.replaceAll("import static org\\.h2", "import static org.h2.upgrade.v1_1");
......@@ -84,9 +90,9 @@ public class UpgradeCreator {
if (file.getName().equals("SessionRemote.java")) {
content = content.replaceAll("org\\.h2\\.engine\\.SessionFactoryEmbedded", "org.h2.upgrade.v1_1.engine.SessionFactoryEmbedded");
}
return content;
}
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License, Version 1.0,
and under the Eclipse Public License, Version 1.0
(http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 9pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;"><p>
A tool to change the package name 'org.h2.' to a new name, to create a migration jar file.
</p></body></html>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论