📄 xahelper.java
字号:
/* Derby - Class org.apache.derby.impl.tools.ij.xaHelper Copyright 1999, 2004 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derby.impl.tools.ij;import org.apache.derby.iapi.tools.i18n.LocalizedResource;import java.sql.Connection;import java.sql.SQLException;import java.util.Locale;import java.util.Vector;import javax.transaction.xa.Xid;import javax.transaction.xa.XAResource;import javax.transaction.xa.XAException;import javax.sql.PooledConnection;import javax.sql.XAConnection;import javax.sql.XADataSource;import javax.sql.DataSource;import javax.sql.ConnectionPoolDataSource;/* * The real xa helper class. Load this class only if we know the javax classes * are in the class path. */class xaHelper implements xaAbstractHelper{ private XADataSource currentXADataSource; private XAConnection currentXAConnection; private String databaseName; // non xa stuff private DataSource currentDataSource; private ConnectionPoolDataSource currentCPDataSource; private PooledConnection currentPooledConnection; private boolean isJCC; private boolean isNetClient; private String framework; xaHelper() { } public void setFramework(String fm) { framework = fm.toUpperCase(Locale.ENGLISH); if (framework.endsWith("NET") || framework.equals("DB2JCC")) isJCC = true; else if (framework.equals("DERBYNETCLIENT")) isNetClient = true; } private Xid makeXid(int xid) { return new ijXid(xid, databaseName.getBytes()); } public void XADataSourceStatement(ij parser, Token dbname, Token shutdown, String create) throws SQLException { try { currentXADataSource = (XADataSource) getXADataSource(); databaseName = parser.stringValue(dbname.image); if (isJCC || isNetClient) { xaHelper.setDataSourceProperty(currentXADataSource, "ServerName", "localhost"); xaHelper.setDataSourceProperty(currentXADataSource, "portNumber", 1527); String user; String password; user = "APP"; password = "APP"; xaHelper.setDataSourceProperty(currentXADataSource, "user", user); xaHelper.setDataSourceProperty(currentXADataSource, "password", password); //xaHelper.setDataSourceProperty(currentXADataSource, //"traceFile", "trace.out." + framework); } if (isJCC) { xaHelper.setDataSourceProperty(currentXADataSource, "driverType", 4); xaHelper.setDataSourceProperty(currentXADataSource, "retrieveMessagesFromServerOnGetMessage", true); } xaHelper.setDataSourceProperty(currentXADataSource, "databaseName", databaseName); if (shutdown != null && shutdown.toString().toLowerCase(Locale.ENGLISH).equals("shutdown")) { if (isJCC || isNetClient) xaHelper.setDataSourceProperty(currentXADataSource,"databaseName", databaseName + ";shutdown=true"); else xaHelper.setDataSourceProperty(currentXADataSource, "shutdownDatabase", "shutdown"); // do a getXAConnection to shut it down */ currentXADataSource.getXAConnection().getConnection(); currentXADataSource = null; currentXAConnection = null; } else if (create != null && create.toLowerCase(java.util.Locale.ENGLISH).equals("create")) { if (isJCC || isNetClient) xaHelper.setDataSourceProperty(currentXADataSource,"databaseName", databaseName + ";create=true"); else xaHelper.setDataSourceProperty(currentXADataSource, "createDatabase", "create"); /* do a getXAConnection to create it */ XAConnection conn = currentXADataSource.getXAConnection(); conn.close(); xaHelper.setDataSourceProperty(currentXADataSource, "createDatabase", null); } } catch (Throwable t) { handleException(t); } } public void XAConnectStatement(ij parser, Token user, Token pass, String id) throws SQLException { try { if (currentXAConnection != null) { try { currentXAConnection.close(); } catch (SQLException sqle) { } currentXAConnection = null; } String username = null; String password = ""; if (pass != null) password = parser.stringValue(pass.image); if (user != null) { username = parser.stringValue(user.image); currentXAConnection = currentXADataSource.getXAConnection(username, password); } else { currentXAConnection = currentXADataSource.getXAConnection(); } } catch (Throwable t) { handleException(t); } } public void XADisconnectStatement(ij parser, String n) throws SQLException { if (currentXAConnection == null) throw ijException.noSuchConnection("XAConnection"); currentXAConnection.close(); currentXAConnection = null; } public Connection XAGetConnectionStatement(ij parser, String n) throws SQLException { try { return currentXAConnection.getConnection(); } catch(Throwable t) { handleException(t); } return null; } public void CommitStatement(ij parser, Token onePhase, Token twoPhase, int xid) throws SQLException { try { currentXAConnection.getXAResource().commit(makeXid(xid), (onePhase != null)); } catch(Throwable t) { handleException(t); } } public void EndStatement(ij parser, int flag, int xid) throws SQLException { try { currentXAConnection.getXAResource().end(makeXid(xid), flag); } catch(Throwable t) { handleException(t); } } public void ForgetStatement(ij parser, int xid) throws SQLException { try { currentXAConnection.getXAResource().forget(makeXid(xid)); } catch(Throwable t) { handleException(t); } } public void PrepareStatement(ij parser, int xid) throws SQLException { try { currentXAConnection.getXAResource().prepare(makeXid(xid)); } catch(Throwable t) { handleException(t); } } public ijResult RecoverStatement(ij parser, int flag) throws SQLException { Object[] val = null; try { val = currentXAConnection.getXAResource().recover(flag); } catch(Throwable t) { handleException(t); } Vector v = new Vector(); v.addElement(""); v.addElement(LocalizedResource.getMessage("IJ_Reco0InDoubT", LocalizedResource.getNumber(val.length))); v.addElement(""); for (int i = 0; i < val.length; i++) v.addElement(LocalizedResource.getMessage("IJ_Tran01", LocalizedResource.getNumber(i+1), val[i].toString())); return new ijVectorResult(v,null); } public void RollbackStatement(ij parser, int xid) throws SQLException { try { currentXAConnection.getXAResource().rollback(makeXid(xid)); } catch(Throwable t) { handleException(t); } } public void StartStatement(ij parser, int flag, int xid) throws SQLException { try { currentXAConnection.getXAResource().start(makeXid(xid), flag); } catch(Throwable t)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -