📄 client.java
字号:
// $Id: Client.java,v 1.1 2001/12/17 17:45:08 per_nyfelt Exp $import org.ozoneDB.*;import javax.transaction.xa.*;import javax.transaction.*;import tyrex.tm.*;//import tyrex.server.*;import java.sql.*;import javax.sql.*;import org.postgresql.PostgresqlDataSource;class Client { public static TransactionManager tm; public static RemoteDatabase db; public static XADataSource postgres; public static XAConnection xacon; public static void main( String[] args ) throws Exception { tm = Tyrex.getTransactionManager(); db = (RemoteDatabase)ExternalDatabase.openDatabase( "ozonedb:remote://localhost:3333" ); System.out.println( "Got ozone connection..." ); tm.begin(); Transaction tx = tm.getTransaction(); tx.enlistResource( db.getXAResource() ); tx.registerSynchronization( new Callback() ); Auto auto = (Auto)db.objectForName( "MG" ); if (auto == null) { auto = (Auto)db.createObject( AutoImpl.class.getName(), OzoneInterface.Public, "MG" ); } Client.print( auto.toString() ); tx.delistResource( db.getXAResource(), XAResource.TMSUCCESS ); System.out.println( "after delist..." ); tm.rollback();// postgres = initPostgres();// xacon = postgres.getXAConnection();// xacon.getConnection().getWarnings();// System.out.println( "Got postgres connection..." );//// //// Configure config = new Configure();//// config.setLogWriter( new PrintWriter( System.out, true ) );//// config.startServer();// // // beginTX();// // print( postgres.getXAConnection().getConnection().toString() );// // Connection conn = xacon.getConnection();// printTestRow( conn );// Statement s = conn.createStatement();// s.execute( "update personen set name = '2' where id = 100;" );// printTestRow( conn );// // Auto auto = (Auto)db.objectForName( "MG" );// if (auto == null) {// auto = (Auto)db.createObject( AutoImpl.class.getName(), OzoneInterface.Public, "MG" );// } // Client.print( auto.toString() );// // new AccessThread().start();// Thread.sleep( 3000 );// //// Transaction tx = tm.suspend();//// //// //*************//////// beginTX();//// try {//// Auto auto2 = (Auto)db.objectForName( "MG" );//// Client.print( "auto2:" + auto2 );//// //// auto2 = (Auto)db.createObject( AutoImpl.class.getName() );//// // auto2.crash();//// }//// catch (Exception e) {//// }//// tm.commit();//// //// //*************//////// tm.resume( tx );// // tm.rollback();// db.close(); Client.print( "deconnected..." ); System.exit( 0 ); } protected static XADataSource initPostgres() { PostgresqlDataSource pgdata = new PostgresqlDataSource(); pgdata.setDatabaseName( "intra" ); pgdata.setUser( "psql" ); pgdata.setPassword( "daniela" ); pgdata.setServerName( "david" ); pgdata.setPortNumber( 5432 ); return pgdata;// Driver driver = (Driver)(Class.forName("org.postgresql.Driver").newInstance());// DriverManager.registerDriver(driver);// // // ein paar Vorbereitungen zum Verbindungsaufbau...// Properties props = new Properties();// props.put ("user", "daniela");// props.put ("password", "daniela");// String jdbcURL = "jdbc:postgresql://david:5432/intra"; // //Verbindung herstellen // Connection conn = DriverManager.getConnection( jdbcURL, props); } public static void beginTX() throws Exception { tm.begin(); Transaction tx = tm.getTransaction(); print( tx.toString() ); tx.registerSynchronization( new Callback() ); tx.enlistResource( db.getXAResource() ); tx.enlistResource( xacon.getXAResource() ); tx.enlistResource( db.getXAResource() ); Connection conn = xacon.getConnection(); print( conn.toString() + " autoCommit: " + conn.getAutoCommit() + " catalog: " + conn.getCatalog() ); } public static void printTestRow( Connection conn ) throws Exception { Statement s = conn.createStatement(); s.execute( "select name from personen where id = 100;" ); ResultSet rs = s.getResultSet(); rs.next(); print( "SQL: name = " + rs.getString( 1 ) ); } public static void print( String msg ) { System.out.println( "CLIENT: " + Thread.currentThread() + ": " + msg ); } }class AccessThread extends Thread { public AccessThread() { } public void run() { try { Client.print( "------------" ); Client.print( "AccessThread.run()..." ); Client.beginTX(); Connection conn = Client.postgres.getXAConnection().getConnection(); Client.printTestRow( conn ); Auto auto = (Auto)Client.db.objectForName( "MG" ); Client.print( "" + auto ); Thread.sleep( 1000 ); Client.tm.commit(); } catch (Exception e) { e.printStackTrace(); } } }class Callback implements Synchronization { public Callback() { } public void beforeCompletion() { Client.print( "Callback: beforeCompletion()" ); } public void afterCompletion( int status ) { Client.print( "Callback: afterCompletion(): status:" + status ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -