use of org.apache.derby.iapi.store.access.TransactionInfo in project derby by apache.
the class TransactionTable method next.
/**
* @see java.sql.ResultSet#next
* @exception SQLException if no transaction context can be found
*/
public boolean next() throws SQLException {
if (!initialized) {
LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
transactionTable = lcc.getTransactionExecute().getAccessManager().getTransactionInfo();
initialized = true;
currentRow = -1;
}
if (transactionTable == null)
return false;
for (currentRow++; currentRow < transactionTable.length; currentRow++) {
TransactionInfo info = transactionTable[currentRow];
if (info == null)
// transaction object in flux while the
continue;
// snap shot was taken, get another row
return true;
}
// currentRow >= transactionTable.length
transactionTable = null;
return false;
}
use of org.apache.derby.iapi.store.access.TransactionInfo in project derby by apache.
the class TransactionTable method getString.
/**
* All columns in TransactionTable VTI is of String type.
* @see java.sql.ResultSet#getString
*/
public String getString(int columnNumber) {
TransactionInfo info = transactionTable[currentRow];
String str = null;
switch(columnNumber) {
case 1:
str = info.getTransactionIdString();
break;
case 2:
str = info.getGlobalTransactionIdString();
break;
case 3:
str = info.getUsernameString();
break;
case 4:
str = info.getTransactionTypeString();
break;
case 5:
str = info.getTransactionStatusString();
break;
case 6:
str = info.getFirstLogInstantString();
break;
case 7:
str = info.getStatementTextString();
str = StringUtil.truncate(str, Limits.DB2_VARCHAR_MAXWIDTH);
break;
default:
str = null;
}
wasNull = (str == null);
return str;
}
use of org.apache.derby.iapi.store.access.TransactionInfo in project derby by apache.
the class Deadlock method buildException.
/**
* Build an exception that describes a deadlock.
*
* @param factory the lock factory requesting the exception
* @param data an array with information about who's involved in
* a deadlock (as returned by {@link #handle})
* @return a deadlock exception
*/
static StandardException buildException(AbstractPool factory, Object[] data) {
Stack chain = (Stack) data[0];
Dictionary waiters = (Dictionary) data[1];
LanguageConnectionContext lcc = (LanguageConnectionContext) getContext(LanguageConnectionContext.CONTEXT_ID);
TableNameInfo tabInfo = null;
TransactionInfo[] tt = null;
TransactionController tc = null;
if (lcc != null) {
try {
tc = lcc.getTransactionExecute();
tabInfo = new TableNameInfo(lcc, false);
tt = tc.getAccessManager().getTransactionInfo();
} catch (StandardException se) {
// just don't get any table info.
}
}
StringBuffer sb = new StringBuffer(200);
Hashtable<String, Object> attributes = new Hashtable<String, Object>(17);
String victimXID = null;
for (int i = 0; i < chain.size(); i++) {
Object space = chain.elementAt(i);
if (space instanceof List) {
List grants = (List) space;
if (grants.size() != 0) {
sb.append(" Granted XID : ");
for (int j = 0; j < grants.size(); j++) {
if (j != 0)
sb.append(", ");
Lock gl = (Lock) grants.get(j);
sb.append("{");
sb.append(gl.getCompatabilitySpace().getOwner());
sb.append(", ");
sb.append(gl.getQualifier());
sb.append("} ");
}
sb.append('\n');
}
continue;
}
// Information about the lock we are waiting on
// TYPE |TABLENAME |LOCKNAME
Lock lock = ((Lock) waiters.get(space));
// see if this lockable object wants to participate
lock.getLockable().lockAttributes(VirtualLockTable.ALL, attributes);
addInfo(sb, "Lock : ", attributes.get(VirtualLockTable.LOCKTYPE));
if (tabInfo != null) {
Long conglomId = (Long) attributes.get(VirtualLockTable.CONGLOMID);
if (conglomId == null) {
Long containerId = (Long) attributes.get(VirtualLockTable.CONTAINERID);
try {
conglomId = tc.findConglomid(containerId.longValue());
} catch (StandardException se) {
}
}
addInfo(sb, ", ", tabInfo.getTableName(conglomId));
}
addInfo(sb, ", ", attributes.get(VirtualLockTable.LOCKNAME));
sb.append('\n');
String xid = String.valueOf(lock.getCompatabilitySpace().getOwner());
if (i == 0)
victimXID = xid;
addInfo(sb, " Waiting XID : {", xid);
addInfo(sb, ", ", lock.getQualifier());
sb.append("} ");
if (tt != null) {
for (int tti = tt.length - 1; tti >= 0; tti--) {
TransactionInfo ti = tt[tti];
// ti.getTransactionIdString() or ti can return null.
if (ti != null) {
String idString = ti.getTransactionIdString();
if (idString != null && idString.equals(xid)) {
addInfo(sb, ", ", ti.getUsernameString());
addInfo(sb, ", ", ti.getStatementTextString());
break;
}
}
}
}
sb.append('\n');
attributes.clear();
}
StandardException se = StandardException.newException(SQLState.DEADLOCK, sb.toString(), victimXID);
se.setReport(factory.deadlockMonitor);
return se;
}
Aggregations