Search in sources :

Example 1 with DatabaseTransaction

use of com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseTransaction in project cubrid-manager by CUBRID.

the class DatabaseDashboardEditor method loadTransactionInfo.

/**
	 * load lock and transaction information
	 */
public void loadTransactionInfo() {
    //if database is stop, do not get data
    if (database.getRunningType() != DbRunningType.CS) {
        return;
    }
    final CommonQueryTask<DatabaseLockInfo> getLockInfotask = new CommonQueryTask<DatabaseLockInfo>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DatabaseLockInfo());
    getLockInfotask.setDbName(database.getName());
    final CommonQueryTask<DbTransactionList> getTransactionTask = new CommonQueryTask<DbTransactionList>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbTransactionList());
    getTransactionTask.setDbName(database.getName());
    new Thread(new Runnable() {

        public void run() {
            getLockInfotask.execute();
            if (!getLockInfotask.isSuccess()) {
                getLockInfotask.finish();
                return;
            }
            getTransactionTask.execute();
            if (!getTransactionTask.isSuccess()) {
                getTransactionTask.finish();
                return;
            }
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    process();
                }
            });
        }

        private void process() {
            lockAndTransactionListData.clear();
            databaseLockInfo = getLockInfotask.getResultModel();
            LockInfo lockInfo = databaseLockInfo.getLockInfo();
            if (lockInfo == null) {
                return;
            }
            DbLotInfo dbLotInfo = lockInfo.getDbLotInfo();
            if (dbLotInfo == null) {
                return;
            }
            if (dbLotInfo.getDbLotEntryList() != null) {
                //get Lock
                for (DbLotEntry dbLot : dbLotInfo.getDbLotEntryList()) {
                    Map<String, String> map = new HashMap<String, String>();
                    if (dbLot.getLockHoldersList() != null) {
                        lockAndTransactionListData.add(map);
                        map.put("4", dbLot.getOb_type());
                        //get lock holder
                        for (int i = 0; i < dbLot.getLockHoldersList().size(); i++) {
                            LockHolders lockHolders = dbLot.getLockHoldersList().get(i);
                            //add mode to the last mode
                            String previousMode = map.get("5");
                            if (i != 0 && previousMode != null) {
                                previousMode += ",";
                            }
                            if (previousMode != null) {
                                previousMode += lockHolders.getGranted_mode();
                            } else {
                                previousMode = lockHolders.getGranted_mode();
                            }
                            map.put("5", previousMode);
                            //get DatabaseTransaction which id is equlas lock holder tranid
                            for (DatabaseTransaction tran : lockInfo.getTransaction()) {
                                if (tran.getIndex() == lockHolders.getTran_index()) {
                                    map.put("0", Integer.toString(tran.getIndex()));
                                    map.put("1", tran.getUid());
                                    map.put("2", tran.getHost());
                                    map.put("3", tran.getPid());
                                }
                            }
                        }
                    }
                }
            }
            setTransactionInfoData();
            getLockInfotask.finish();
            getTransactionTask.finish();
        }
    }).start();
}
Also used : LockHolders(com.cubrid.cubridmanager.core.cubrid.database.model.lock.LockHolders) DatabaseLockInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseLockInfo) HashMap(java.util.HashMap) DbLotInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DbLotInfo) DatabaseTransaction(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseTransaction) DbLotEntry(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DbLotEntry) DbTransactionList(com.cubrid.cubridmanager.core.cubrid.database.model.transaction.DbTransactionList) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) DatabaseLockInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseLockInfo) LockInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.LockInfo)

Example 2 with DatabaseTransaction

use of com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseTransaction in project cubrid-manager by CUBRID.

the class LockInfoDialog method initial.

/**
	 * 
	 * Initial data
	 * 
	 */
private void initial() {
    if (databaseLockInfo != null) {
        LockInfo lockInfo = databaseLockInfo.getLockInfo();
        DbLotInfo dbLotInfo = lockInfo.getDbLotInfo();
        lockEscLabel.setText(Messages.bind(Messages.lblLockEscalation, lockInfo.getEsc()));
        deadLockNumLabel.setText(Messages.bind(Messages.lblRunInterval, lockInfo.getDinterval()));
        connListData.clear();
        if (lockInfo.getTransaction() != null) {
            for (DatabaseTransaction tran : lockInfo.getTransaction()) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("0", String.valueOf(tran.getIndex()));
                map.put("1", String.valueOf(tran.getPname()));
                map.put("2", String.valueOf(tran.getUid()));
                map.put("3", String.valueOf(tran.getHost()));
                map.put("4", String.valueOf(tran.getPid()));
                map.put("5", String.valueOf(tran.getIsolevel()));
                map.put("6", String.valueOf(tran.getTimeout()));
                connListData.add(map);
            }
            connTableViewer.refresh();
            for (int i = 0; i < connectionList.getColumnCount(); i++) {
                connectionList.getColumn(i).pack();
            }
        }
        lockedNumLabel.setText(Messages.bind(Messages.lblCurrentLockedObjNum, dbLotInfo.getNumlocked()));
        maxLockLabel.setText(Messages.bind(Messages.lblMaxLockedObjNum, dbLotInfo.getMaxnumlock()));
        lockListData.clear();
        if (dbLotInfo.getDbLotEntryList() != null) {
            for (DbLotEntry entry : dbLotInfo.getDbLotEntryList()) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("0", entry.getOid());
                map.put("1", entry.getOb_type());
                map.put("2", String.valueOf(entry.getNum_holders()));
                map.put("3", String.valueOf(entry.getNum_b_holders()));
                map.put("4", String.valueOf(entry.getNum_waiters()));
                lockListData.add(map);
            }
            lockTableViewer.refresh();
            for (int i = 0; i < lockList.getColumnCount(); i++) {
                lockList.getColumn(i).pack();
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) DbLotInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DbLotInfo) DatabaseTransaction(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseTransaction) DatabaseLockInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseLockInfo) LockInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.LockInfo) DbLotEntry(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DbLotEntry) Point(org.eclipse.swt.graphics.Point)

Example 3 with DatabaseTransaction

use of com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseTransaction in project cubrid-manager by CUBRID.

the class LockDbTaskTest method testLockDbLocked.

public void testLockDbLocked() {
    if (StringUtil.isEqual(SystemParameter.getParameterValue("useMockTest"), "n"))
        return;
    System.out.println("<database.lockdb.002.req.txt>");
    CommonQueryTask<DatabaseLockInfo> task = new CommonQueryTask<DatabaseLockInfo>(ServerManager.getInstance().getServer(host, monport, userName), CommonSendMsg.getCommonDatabaseSendMsg(), new DatabaseLockInfo());
    task.setDbName("lockeddb");
    task.execute();
    assertTrue(task.isSuccess());
    assertNull(task.getErrorMsg());
    DatabaseLockInfo dli = task.getResultModel();
    assertNotNull(dli);
    assertEquals("lockdb", dli.getTaskName());
    LockInfo li = dli.getLockInfo();
    assertNotNull(li);
    assertEquals(1, li.getDinterval());
    assertEquals(100000, li.getEsc());
    List<DatabaseTransaction> dtList = li.getTransaction();
    assertNotNull(dtList);
    assertEquals(4, dtList.size());
    DatabaseTransaction dt = dtList.get(0);
    assertEquals(0, dt.getIndex());
    assertEquals("(unknown)", dt.getPname());
    assertEquals("(unknown)", dt.getUid());
    assertEquals("(unknown)", dt.getHost());
    assertEquals("-1", dt.getPid());
    assertEquals("REPEATABLE CLASSES AND READ UNCOMMITTED INSTANCES", dt.getIsolevel());
    assertEquals(-1, dt.getTimeout());
    dt = dtList.get(1);
    assertEquals(1, dt.getIndex());
    assertEquals("csql", dt.getPname());
    assertEquals("dba", dt.getUid());
    assertEquals("localhost.localdomain", dt.getHost());
    assertEquals("10731", dt.getPid());
    assertEquals("REPEATABLE CLASSES AND READ UNCOMMITTED INSTANCES", dt.getIsolevel());
    assertEquals(-1, dt.getTimeout());
    dt = dtList.get(2);
    assertEquals(2, dt.getIndex());
    assertEquals("csql", dt.getPname());
    assertEquals("dba", dt.getUid());
    assertEquals("localhost.localdomain", dt.getHost());
    assertEquals("10786", dt.getPid());
    assertEquals("REPEATABLE CLASSES AND READ UNCOMMITTED INSTANCES", dt.getIsolevel());
    assertEquals(-1, dt.getTimeout());
    dt = dtList.get(3);
    assertEquals(3, dt.getIndex());
    assertEquals("lockdb", dt.getPname());
    assertEquals("dba", dt.getUid());
    assertEquals("localhost.localdomain", dt.getHost());
    assertEquals("10987", dt.getPid());
    assertEquals("READ COMMITTED CLASSES AND READ UNCOMMITTED INSTANCES", dt.getIsolevel());
    assertEquals(-2, dt.getTimeout());
    DbLotInfo dbLotInfo = li.getDbLotInfo();
    assertNotNull(dbLotInfo);
    assertEquals(2, dbLotInfo.getNumlocked());
    assertEquals(10000, dbLotInfo.getMaxnumlock());
    assertNotNull(dbLotInfo.getDbLotEntryList());
    assertEquals(2, dbLotInfo.getDbLotEntryList().size());
    List<DbLotEntry> dbLotEntryList = dbLotInfo.getDbLotEntryList();
    assertNotNull(dbLotEntryList);
    assertEquals(2, dbLotEntryList.size());
    DbLotEntry dbLotEntry = dbLotEntryList.get(0);
    assertNotNull(dbLotEntry);
    assertEquals("0|354|2", dbLotEntry.getOid());
    assertEquals("Class = dual", dbLotEntry.getOb_type());
    assertEquals(1, dbLotEntry.getNum_holders());
    assertEquals(0, dbLotEntry.getNum_b_holders());
    assertEquals(0, dbLotEntry.getNum_waiters());
    List<LockHolders> lockHolderList = dbLotEntry.getLockHoldersList();
    assertNotNull(lockHolderList);
    assertEquals(1, lockHolderList.size());
    LockHolders lockHolders = lockHolderList.get(0);
    assertNotNull(lockHolders);
    assertEquals(2, lockHolders.getTran_index());
    assertEquals(2, lockHolders.getCount());
    assertEquals("IS_LOCK", lockHolders.getGranted_mode());
    assertEquals(0, lockHolders.getNsubgranules());
    assertNull(dbLotEntry.getBlockHoldersList());
    assertNull(dbLotEntry.getLockWaitersList());
    dbLotEntry = dbLotEntryList.get(1);
    assertNotNull(dbLotEntry);
    assertEquals("0|60|1", dbLotEntry.getOid());
    assertEquals("Root class", dbLotEntry.getOb_type());
    assertEquals(1, dbLotEntry.getNum_holders());
    assertEquals(0, dbLotEntry.getNum_b_holders());
    assertEquals(1, dbLotEntry.getNum_waiters());
    lockHolderList = dbLotEntry.getLockHoldersList();
    assertNotNull(lockHolderList);
    assertEquals(1, lockHolderList.size());
    lockHolders = lockHolderList.get(0);
    assertNotNull(lockHolders);
    assertEquals(2, lockHolders.getTran_index());
    assertEquals(1, lockHolders.getCount());
    assertEquals("IS_LOCK", lockHolders.getGranted_mode());
    assertEquals(1, lockHolders.getNsubgranules());
    assertNull(dbLotEntry.getBlockHoldersList());
    assertNotNull(dbLotEntry.getLockWaitersList());
    List<LockWaiters> lockWaitersList = dbLotEntry.getLockWaitersList();
    assertNotNull(lockWaitersList);
    assertEquals(1, lockWaitersList.size());
    LockWaiters lockWaiters = lockWaitersList.get(0);
    assertEquals("IX_LOCK", lockWaiters.getB_mode());
    assertEquals("Mon Jun 29 21:29:12 2009", lockWaiters.getStart_at());
    assertEquals("-1", lockWaiters.getWaitfornsec());
    assertEquals(1, lockWaiters.getTran_index());
//TODO: need a test for the b_holders attribute
}
Also used : LockHolders(com.cubrid.cubridmanager.core.cubrid.database.model.lock.LockHolders) DatabaseLockInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseLockInfo) DatabaseTransaction(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseTransaction) DbLotInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DbLotInfo) DbLotEntry(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DbLotEntry) LockWaiters(com.cubrid.cubridmanager.core.cubrid.database.model.lock.LockWaiters) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) LockInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.LockInfo) DatabaseLockInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseLockInfo)

Example 4 with DatabaseTransaction

use of com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseTransaction in project cubrid-manager by CUBRID.

the class LockDbTaskTest method testLockDbNoLock.

public void testLockDbNoLock() {
    if (StringUtil.isEqual(SystemParameter.getParameterValue("useMockTest"), "n"))
        return;
    System.out.println("<database.lockdb.001.req.txt>");
    CommonQueryTask<DatabaseLockInfo> task = new CommonQueryTask<DatabaseLockInfo>(ServerManager.getInstance().getServer(host, monport, userName), CommonSendMsg.getCommonDatabaseSendMsg(), new DatabaseLockInfo());
    task.setDbName("unlockeddb");
    task.execute();
    assertTrue(task.isSuccess());
    assertNull(task.getErrorMsg());
    DatabaseLockInfo dli = task.getResultModel();
    assertNotNull(dli);
    assertEquals("lockdb", dli.getTaskName());
    LockInfo li = dli.getLockInfo();
    assertNotNull(li);
    assertEquals(1, li.getDinterval());
    assertEquals(100000, li.getEsc());
    List<DatabaseTransaction> dtList = li.getTransaction();
    assertNotNull(dtList);
    assertEquals(2, dtList.size());
    DatabaseTransaction dt = dtList.get(0);
    assertEquals(0, dt.getIndex());
    assertEquals("(unknown)", dt.getPname());
    assertEquals("(unknown)", dt.getUid());
    assertEquals("(unknown)", dt.getHost());
    assertEquals("-1", dt.getPid());
    assertEquals("REPEATABLE CLASSES AND READ UNCOMMITTED INSTANCES", dt.getIsolevel());
    assertEquals(-1, dt.getTimeout());
    dt = dtList.get(1);
    assertEquals(1, dt.getIndex());
    assertEquals("lockdb", dt.getPname());
    assertEquals("dba", dt.getUid());
    assertEquals("localhost.localdomain", dt.getHost());
    assertEquals("5334", dt.getPid());
    assertEquals("READ COMMITTED CLASSES AND READ UNCOMMITTED INSTANCES", dt.getIsolevel());
    assertEquals(-2, dt.getTimeout());
    DbLotInfo dbLotInfo = li.getDbLotInfo();
    assertNotNull(dbLotInfo);
    assertEquals(0, dbLotInfo.getNumlocked());
    assertEquals(10000, dbLotInfo.getMaxnumlock());
    assertNotNull(dbLotInfo.getDbLotEntryList());
    assertEquals(0, dbLotInfo.getDbLotEntryList().size());
}
Also used : DatabaseLockInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseLockInfo) DatabaseTransaction(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseTransaction) DbLotInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DbLotInfo) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) LockInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.LockInfo) DatabaseLockInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseLockInfo)

Example 5 with DatabaseTransaction

use of com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseTransaction in project cubrid-manager by CUBRID.

the class TransactionModelTest method testModelDatabaseTransaction.

public void testModelDatabaseTransaction() {
    DatabaseTransaction bean = new DatabaseTransaction();
    bean.setIndex(5);
    assertEquals(bean.getIndex(), 5);
    bean.setPname("pname");
    assertEquals(bean.getPname(), "pname");
    bean.setUid("uid");
    assertEquals(bean.getUid(), "uid");
    bean.setHost("host");
    assertEquals(bean.getHost(), "host");
    bean.setPid("pid");
    assertEquals(bean.getPid(), "pid");
    bean.setIsolevel("isolevel");
    assertEquals(bean.getIsolevel(), "isolevel");
    bean.setTimeout(7);
    assertEquals(bean.getTimeout(), 7);
}
Also used : DatabaseTransaction(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseTransaction)

Aggregations

DatabaseTransaction (com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseTransaction)5 DatabaseLockInfo (com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseLockInfo)4 DbLotInfo (com.cubrid.cubridmanager.core.cubrid.database.model.lock.DbLotInfo)4 LockInfo (com.cubrid.cubridmanager.core.cubrid.database.model.lock.LockInfo)4 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)3 DbLotEntry (com.cubrid.cubridmanager.core.cubrid.database.model.lock.DbLotEntry)3 LockHolders (com.cubrid.cubridmanager.core.cubrid.database.model.lock.LockHolders)2 HashMap (java.util.HashMap)2 LockWaiters (com.cubrid.cubridmanager.core.cubrid.database.model.lock.LockWaiters)1 DbTransactionList (com.cubrid.cubridmanager.core.cubrid.database.model.transaction.DbTransactionList)1 Point (org.eclipse.swt.graphics.Point)1