public void run() { int numOfCdrs = 0; // System.out.println("Getting data from queue table"); Logger.info("CDRServer:", "Getting data from queue table"); while (CDRServer.running) { try { this.readCDRinQueueEx(); if ("VMS".equals(Preference.mobileOperator.toUpperCase())) { // CdrFileCopier4vms cdrcopy = new CdrFileCopier4vms(); // System.out.println("Starting FTP"); Logger.info("FTP:", " starting FTP cdr file"); Ftp2CdrServer ftp = new Ftp2CdrServer(); // .start(); ftp.runftp(); } else { // System.out.println("Invalid mobile operator: " + // Preference.mobileOperator); Logger.info("Invalid mobile operator:", Preference.mobileOperator); exit(); } sleep10Minutes(); } catch (InterruptedException ex) { } catch (DBException ex) { // when lost connection to db // System.out.println("DBScanner::" + ex.getMessage()); Logger.info("DBScanner:", ex.getMessage()); try { dbTools.log_alert( "Billing system", "-> ERROR: Ket noi Database bi loi: " + ex.getMessage(), 1, 0, "serious", Preference.alert_person); } catch (Exception e) { } GatewayCDR.rebuildDBConnections(1); // 1 connection } catch (Exception ex) { // System.out.println("DBScanner::" + ex.getMessage()); Logger.info("DBScanner:", ex.getMessage()); try { // dbTools.log_alert(Preference.sourceAddressList.toString(), // "CDR->DBSCanner", // "<-" + Preference.mobileOperator + "-> ERROR: " + // ex.getMessage(), // 1, Preference.alert_person, // Preference.alert_mobile); dbTools.log_alert( "Billing system", "-> ERROR: Loi dinh dang MOBILE OPERATOR: " + ex.getMessage(), 1, 0, "serious", Preference.alert_person); } catch (Exception e) { } } } }
public void run() { try { _db.init(); } catch (DBException e) { // TODO make error logging level configurable e.printStackTrace(); return; } try { _workloadstate = _workload.initThread(_props); } catch (WorkloadException e) { e.printStackTrace(); return; } // spread the thread operations out so they don't all hit the DB at the same time try { // GH issue 4 - throws exception if _target>1 because random.nextInt argument must be >0 // and the sleep() doesn't make sense for granularities < 1 ms anyway if ((_target > 0) && (_target <= 1.0)) { sleep(Utils.random().nextInt((int) (1.0 / _target))); } } catch (InterruptedException e) { // do nothing. } try { if (_dotransactions) { run( new OperationHandler() { @Override public boolean doOperation(DB db, Object workloadstate) { return _workload.doTransaction(db, workloadstate); } }); } else { run( new OperationHandler() { @Override public boolean doOperation(DB db, Object workloadstate) { return _workload.doInsert(db, workloadstate); } }); } } catch (Exception e) { e.printStackTrace(); } try { _db.cleanup(); } catch (DBException e) { e.printStackTrace(); } }
public void run() { // /////////////////////////// Gateway.addLiveThread(this); // /////////////////////////// while (Gateway.running) { try { pdud = (PDUData) fromSMSC.dequeue(); // blocks until having // an item // pdu = (PDU) fromSMSC.dequeue(); //blocks until having an item pdu = (PDU) pdud.getPDU(); if (pdu.isRequest()) { this.RequestID = pdud.getRequestID(); processRequest(pdu); } } catch (DBException ex) { // when lost connection to db Logger.error(this.getClass().getName(), "DBException: " + ex.getMessage()); DBTools.ALERT( "RequestProcessor", "RequestProcessor", Constants.ALERT_WARN, Preference.Channel + "DBException: " + ex.getMessage(), Preference.ALERT_CONTACT); Logger.error(this.getClass().getName(), "Alert2YM DBException: " + ex.getMessage()); } catch (Exception e) { Logger.error(this.getClass().getName(), "Exception: " + e.getMessage()); DBTools.ALERT( "RequestProcessor", "RequestProcessor", Constants.ALERT_WARN, Preference.Channel + "Exception: " + e.getMessage(), Preference.ALERT_CONTACT); } try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } } // ///////////////////////////// Logger.info(this.getClass().getName(), "{" + this.getClass().getName() + " stopped}"); this.destroy(); // ///////////////////////////// }
public ColumnPairElement getColumnPair(DBIdentifier name) { ColumnPairElement cpe = (ColumnPairElement) columnPairs.find(name); if (cpe == null) try { String fullName = name.getFullName(); if (fullName == null) { return null; } int pos = fullName.indexOf(";"); String firstHalf = fullName.substring(0, pos); String secondHalf = fullName.substring(pos + 1); ColumnElement lce = getColumn(DBIdentifier.create(firstHalf)); pos = secondHalf.lastIndexOf("."); TableElement te = ((TableElement) element) .getDeclaringSchema() .getTable(DBIdentifier.create(secondHalf.substring(0, pos))); if (te == null) return null; ColumnElement fce = te.getColumn(DBIdentifier.create(secondHalf)); if (lce == null || fce == null) return null; ColumnPairElementImpl cpei = new ColumnPairElementImpl( lce.getName().getFullName() + ";" + fce.getName().getFullName()); // NOI18N cpe = new ColumnPairElement(cpei, lce, fce, (TableElement) element); changeColumnPairs(new ColumnPairElement[] {cpe}, DBElement.Impl.ADD); } catch (DBException exc) { exc.printStackTrace(); return null; } return cpe; }
public static void main(String[] args) { try { GatewayCDR gateway = new GatewayCDR(); try { Preference.loadProperties("gateway.cfg"); // if ("GPC".equals(Preference.mobileOperator) || // "VIETTEL".equals(Preference.mobileOperator)) FtpData.loadProperties("ftp2cdrserver.cfg"); } catch (Exception e) { System.out.println("CDRServer: khong tim thay file cau hinh "); } gateway.addMoreConnection2Pool(1); if (args != null && args.length > 1) { System.out.println(">>>" + args[0] + " >>> " + args[1]); DBScanner.pushCDRinQueueEx8x99(args[0].trim(), args[1].trim()); } else { System.out.println(">>>Thang 04 !!!"); DBScanner.pushCDRinQueueEx8x99("060401000000", "060425093500"); } } catch (DBException ex) { System.out.println(">>>>Loi: " + ex.toString()); } }
public void doAddWord(String text) { T9DB db = T9DB.getInstance(this); try { db.addWord(text, LangHelper.LANGUAGE.get(lang)); } catch (DBException e) { AlertDialog.Builder builder = new AlertDialog.Builder(this); String msg = e.getMessage(); // Log.e("AddWord.doAddWord", msg); builder .setMessage(msg) .setTitle(R.string.add_word) .setPositiveButton( android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); AlertDialog dialog = builder.create(); dialog.show(); } db.storeSettingString(SETTING.LAST_WORD, text); }
public static void testDBuilder(Context context) { DBBuilder builder = new DBBuilder(context); builder.setDatabaseName("testing.db"); String testingTable = "testingTable"; builder.setMainTableName(testingTable); List<String> columns = new ArrayList<String>(); columns.add("col1"); columns.add("col2"); columns.add("col3"); columns.add("col4"); builder.addTable(testingTable, columns); try { BaseDatabaseHelper buildHelper = builder.build(); buildHelper.dropDatabase(); List<String> data = new ArrayList<String>(); data.add("data1-1"); data.add("data1-2"); data.add("data1-3"); data.add("data1-4"); long row1Id = buildHelper.insertEntry(builder.getTableEntry(testingTable), data); Logger.debug(context, "Id is " + row1Id); data.clear(); data.add("data2-1"); data.add("data2-2"); data.add("data2-3"); data.add("data2-4"); long row2Id = buildHelper.insertEntry(builder.getTableEntry(testingTable), data); Cursor allEntries = buildHelper.getAllEntries(builder.getTableEntry(testingTable)); Logger.debug(context, "After inserting row " + row2Id); if (allEntries != null) { if (allEntries.moveToFirst()) { printCursor(context, allEntries); } allEntries.close(); } Cursor cursor = buildHelper.getEntry(builder.getTableEntry(testingTable), row1Id); Logger.debug(context, "Searching for row " + row1Id); if (cursor != null) { try { if (cursor.moveToFirst()) { printCursor(context, cursor); } } finally { cursor.close(); } } cursor = buildHelper.getEntry(builder.getTableEntry(testingTable), "col2", "data1-2"); Logger.debug(context, "Searching for data1-2"); if (cursor != null) { try { if (cursor.moveToFirst()) { printCursor(context, cursor); } } finally { cursor.close(); } } buildHelper.deleteEntry(builder.getTableEntry(testingTable), row1Id); Logger.debug(context, "After deleting row " + row1Id); allEntries = buildHelper.getAllEntries(builder.getTableEntry(testingTable)); if (allEntries != null) { if (allEntries.moveToFirst()) { printCursor(context, allEntries); } allEntries.close(); } data.clear(); data.add(String.valueOf(row2Id)); data.add("data2-2-1"); data.add("data2-2-2"); data.add("data2-2-3"); data.add("data2-2-4"); buildHelper.updateEntry(builder.getTableEntry(testingTable), data, String.valueOf(row2Id)); cursor = buildHelper.getEntry(builder.getTableEntry(testingTable), row2Id); Logger.debug(context, "After updating row " + row2Id); if (cursor != null) { try { if (cursor.moveToFirst()) { printCursor(context, cursor); } } finally { cursor.close(); } } } catch (DBException e) { e.printStackTrace(); } }
public static void main(String argv[]) { DBConfig.cmdLineInit(argv, true); // main String accountID = RTConfig.getString(ARG_ACCOUNT, ""); String deviceID = RTConfig.getString(ARG_DEVICE, ""); int statusCode = RTConfig.getInt(ARG_CODE, 0); boolean anyCode = true; // RTConfig.hasProperty(ARG_ECODE); /* account-id specified? */ if (StringTools.isBlank(accountID)) { Print.logError("Account-ID not specified."); usage(); } /* get account */ Account account = null; try { account = Account.getAccount(accountID); // may throw DBException if (account == null) { Print.logError("Account-ID does not exist: " + accountID); usage(); } } catch (DBException dbe) { Print.logException("Error loading Account: " + accountID, dbe); // dbe.printException(); System.exit(99); } /* device-id specified? */ if (StringTools.isBlank(deviceID) || deviceID.startsWith("/")) { deviceID = ALL_DEVICES; } /* check device existance */ if (!deviceID.equals(ALL_DEVICES)) { try { Device device = Device.getDevice(account, deviceID); // may throw DBException if (device == null) { Print.logError("Device-ID does not exist: " + accountID + " / " + deviceID); usage(); } } catch (DBException dbe) { Print.logException("Error loading Device: " + accountID + " / " + deviceID, dbe); System.exit(99); } } /* status-code specified? */ if ((statusCode > 0) && !anyCode && !StatusCodes.IsValid(statusCode, account.getPrivateLabel())) { Print.logError("Invalid Status Code specified."); usage(); } /* statusCode specified? */ if (statusCode <= 0) { Print.logError("StatusCode not specified."); usage(); } /* statusCode exists? */ boolean statusCodeExists = false; try { statusCodeExists = StatusCode.exists(accountID, deviceID, statusCode); } catch (DBException dbe) { Print.logError( "Error determining if StatusCode exists: " + accountID + "/" + deviceID + "/" + statusCode); System.exit(99); } /* option count */ int opts = 0; /* delete */ if (RTConfig.getBoolean(ARG_DELETE, false)) { opts++; if (!statusCodeExists) { Print.logWarn( "StatusCode does not exist: " + accountID + "/" + deviceID + "/" + statusCode); Print.logWarn("Continuing with delete process ..."); } try { StatusCode.Key scKey = new StatusCode.Key(accountID, deviceID, statusCode); scKey.delete(true); // also delete dependencies (if any) Print.logInfo("StatusCode deleted: " + accountID + "/" + deviceID + "/" + statusCode); statusCodeExists = false; } catch (DBException dbe) { Print.logError( "Error deleting StatusCode: " + accountID + "/" + deviceID + "/" + statusCode); dbe.printException(); System.exit(99); } System.exit(0); } /* create */ if (RTConfig.getBoolean(ARG_CREATE, false)) { opts++; if (statusCodeExists) { Print.logWarn( "StatusCode already exists: " + accountID + "/" + deviceID + "/" + statusCode); } else { try { StatusCode.createNewStatusCode(account, deviceID, statusCode); Print.logInfo("Created StatusCode: " + accountID + "/" + deviceID + "/" + statusCode); statusCodeExists = true; } catch (DBException dbe) { Print.logError( "Error creating StatusCode: " + accountID + "/" + deviceID + "/" + statusCode); dbe.printException(); System.exit(99); } } } /* edit */ if (RTConfig.getBoolean(ARG_EDIT, false)) { opts++; if (!statusCodeExists) { Print.logError( "StatusCode does not exist: " + accountID + "/" + deviceID + "/" + statusCode); } else { try { StatusCode sc = StatusCode.getStatusCode(account, deviceID, statusCode); // may throw DBException DBEdit editor = new DBEdit(sc); editor.edit(); // may throw IOException } catch (IOException ioe) { if (ioe instanceof EOFException) { Print.logError("End of input"); } else { Print.logError("IO Error"); } } catch (DBException dbe) { Print.logError( "Error editing StatusCode: " + accountID + "/" + deviceID + "/" + statusCode); dbe.printException(); } } System.exit(0); } /* list */ if (RTConfig.hasProperty(ARG_LIST)) { opts++; String listType = RTConfig.getString(ARG_LIST, null); // TODO: complete ... } /* no options specified */ if (opts == 0) { Print.logWarn("Missing options ..."); usage(); } }
public static void main(String args[]) { DBConfig.cmdLineInit(args, true); // main String acctID = RTConfig.getString(ARG_ACCOUNT, ""); String strID = RTConfig.getString(ARG_STRING, ""); /* account-id specified? */ if (StringTools.isBlank(acctID)) { Print.logError("Account-ID not specified."); usage(); } /* get account */ Account acct = null; try { acct = Account.getAccount(acctID); // may throw DBException if (acct == null) { Print.logError("Account-ID does not exist: " + acctID); usage(); } } catch (DBException dbe) { Print.logException("Error loading Account: " + acctID, dbe); // dbe.printException(); System.exit(99); } /* string-id specified? */ if ((strID == null) || strID.equals("")) { Print.logError("String-ID not specified."); usage(); } /* string exists? */ boolean stringExists = false; try { stringExists = AccountString.exists(acctID, strID); } catch (DBException dbe) { Print.logError("Error determining if AccountString exists: " + _fmtStrID(acctID, strID)); System.exit(99); } /* option count */ int opts = 0; /* delete */ if (RTConfig.getBoolean(ARG_DELETE, false) && !acctID.equals("") && !strID.equals("")) { opts++; if (!stringExists) { Print.logWarn("AccountString does not exist: " + _fmtStrID(acctID, strID)); Print.logWarn("Continuing with delete process ..."); } try { AccountString.Key strKey = new AccountString.Key(acctID, strID); strKey.delete(true); // also delete dependencies Print.logInfo("AccountString deleted: " + _fmtStrID(acctID, strID)); stringExists = false; } catch (DBException dbe) { Print.logError("Error deleting AccountString: " + _fmtStrID(acctID, strID)); dbe.printException(); System.exit(99); } System.exit(0); } /* create */ if (RTConfig.getBoolean(ARG_CREATE, false)) { opts++; if (stringExists) { Print.logWarn("AccountString already exists: " + _fmtStrID(acctID, strID)); } else { try { AccountString.createNewAccountString(acct, strID); Print.logInfo("Created AccountString: " + _fmtStrID(acctID, strID)); stringExists = true; } catch (DBException dbe) { Print.logError("Error creating AccountString: " + _fmtStrID(acctID, strID)); dbe.printException(); System.exit(99); } } } /* edit */ if (RTConfig.getBoolean(ARG_EDIT, false)) { opts++; if (!stringExists) { Print.logError("AccountString does not exist: " + _fmtStrID(acctID, strID)); } else { try { AccountString str = AccountString.getAccountString(acct, strID, false); // may throw DBException DBEdit editor = new DBEdit(str); editor.edit(true); // may throw IOException } catch (IOException ioe) { if (ioe instanceof EOFException) { Print.logError("End of input"); } else { Print.logError("IO Error"); } } catch (DBException dbe) { Print.logError("Error editing AccountString: " + _fmtStrID(acctID, strID)); dbe.printException(); } } System.exit(0); } /* no options specified */ if (opts == 0) { Print.logWarn("Missing options ..."); usage(); } }
public void run() { try { _db.init(); } catch (DBException e) { e.printStackTrace(); e.printStackTrace(System.out); return; } try { _workloadstate = _workload.initThread(_props, _threadid, _threadcount); } catch (WorkloadException e) { e.printStackTrace(); e.printStackTrace(System.out); return; } // spread the thread operations out so they don't all hit the DB at the same time try { // GH issue 4 - throws exception if _target>1 because random.nextInt argument must be >0 // and the sleep() doesn't make sense for granularities < 1 ms anyway if ((_target > 0) && (_target <= 1.0)) { sleep(Utils.random().nextInt((int) (1.0 / _target))); } } catch (InterruptedException e) { // do nothing. } try { if (_dotransactions) { long st = System.currentTimeMillis(); while (((_opcount == 0) || (_opsdone < _opcount)) && !_workload.isStopRequested()) { if (!_workload.doTransaction(_db, _workloadstate)) { break; } _opsdone++; // throttle the operations if (_target > 0) { // this is more accurate than other throttling approaches we have tried, // like sleeping for (1/target throughput)-operation latency, // because it smooths timing inaccuracies (from sleep() taking an int, // current time in millis) over many operations while (System.currentTimeMillis() - st < ((double) _opsdone) / _target) { try { sleep(1); } catch (InterruptedException e) { // do nothing. } } } } } else { long st = System.currentTimeMillis(); while (((_opcount == 0) || (_opsdone < _opcount)) && !_workload.isStopRequested()) { if (!_workload.doInsert(_db, _workloadstate)) { break; } _opsdone++; // throttle the operations if (_target > 0) { // this is more accurate than other throttling approaches we have tried, // like sleeping for (1/target throughput)-operation latency, // because it smooths timing inaccuracies (from sleep() taking an int, // current time in millis) over many operations while (System.currentTimeMillis() - st < ((double) _opsdone) / _target) { try { sleep(1); } catch (InterruptedException e) { // do nothing. } } } } } } catch (Exception e) { e.printStackTrace(); e.printStackTrace(System.out); System.exit(0); } try { _db.cleanup(); } catch (DBException e) { e.printStackTrace(); e.printStackTrace(System.out); return; } }
public static void main(String args[]) { DBConfig.cmdLineInit(args, true); // main String acctID = RTConfig.getString(ARG_ACCOUNT, ""); String roleID = RTConfig.getString(ARG_ROLE, ""); String aclID = RTConfig.getString(ARG_ACL, ""); /* account-id specified? */ if ((acctID == null) || acctID.equals("")) { Print.logError("Account-ID not specified."); usage(); } /* get account */ Account acct = null; try { acct = Account.getAccount(acctID); // may return DBException if (acct == null) { Print.logError("Account-ID does not exist: " + acctID); usage(); } } catch (DBException dbe) { Print.logException("Error loading Account: " + acctID, dbe); // dbe.printException(); System.exit(99); } /* role-id specified? */ if ((roleID == null) || roleID.equals("")) { Print.logError("Role-ID not specified."); usage(); } /* get role */ Role role = null; try { role = Role.getRole(acct, roleID); // may return DBException if (role == null) { Print.logError("Role-ID does not exist: " + acctID + "/" + roleID); usage(); } } catch (DBException dbe) { Print.logException("Error loading Role: " + acctID + "/" + roleID, dbe); // dbe.printException(); System.exit(99); } /* RoleAcl exists? */ boolean aclExists = false; if ((aclID != null) && !aclID.equals("")) { try { aclExists = RoleAcl.exists(acctID, roleID, aclID); } catch (DBException dbe) { Print.logError( "Error determining if RoleAcl exists: " + acctID + "/" + roleID + "/" + aclID); System.exit(99); } } /* option count */ int opts = 0; /* list */ if (RTConfig.getBoolean(ARG_LIST, false)) { opts++; try { String aclList[] = role.getAclsForRole(); for (int i = 0; i < aclList.length; i++) { AccessLevel level = RoleAcl.getAccessLevel(role, aclList[i], AccessLevel.NONE); Print.sysPrintln(" " + aclList[i] + " ==> " + level); } } catch (DBException dbe) { Print.logError("Error getting Acl list: " + dbe); System.exit(99); } System.exit(0); } /* delete */ if (RTConfig.getBoolean(ARG_DELETE, false) && !acctID.equals("") && !roleID.equals("")) { opts++; if (!aclExists) { Print.logWarn("RoleAcl does not exist: " + acctID + "/" + roleID + "/" + aclID); Print.logWarn("Continuing with delete process ..."); } try { RoleAcl.Key aclKey = new RoleAcl.Key(acctID, roleID, aclID); aclKey.delete(true); // also delete dependencies Print.logInfo("RoleAcl deleted: " + acctID + "/" + roleID + "/" + aclID); } catch (DBException dbe) { Print.logError("Error deleting RoleAcl: " + acctID + "/" + roleID + "/" + aclID); dbe.printException(); System.exit(99); } System.exit(0); } /* create */ if (RTConfig.getBoolean(ARG_CREATE, false)) { opts++; if (aclExists) { Print.logWarn("RoleAcl already exists: " + acctID + "/" + roleID + "/" + aclID); } else { try { RoleAcl.createNewRoleAcl(role, aclID); Print.logInfo("Created RoleAcl: " + acctID + "/" + roleID + "/" + aclID); aclExists = true; } catch (DBException dbe) { Print.logError("Error creating RoleAcl: " + acctID + "/" + roleID + "/" + aclID); dbe.printException(); System.exit(99); } } } /* set */ if (RTConfig.hasProperty(ARG_SET)) { opts++; AccessLevel aclLevel = EnumTools.getValueOf(AccessLevel.class, RTConfig.getInt(ARG_SET, -1)); try { RoleAcl.setAccessLevel(role, aclID, aclLevel); Print.logInfo( "Set RoleAcl '" + acctID + "/" + roleID + "/" + aclID + "' to level " + aclLevel); } catch (DBException dbe) { Print.logError("Error setting RoleAcl: " + acctID + "/" + roleID + "/" + aclID); dbe.printException(); System.exit(99); } System.exit(0); } /* edit */ if (RTConfig.getBoolean(ARG_EDIT, false)) { opts++; if (!aclExists) { Print.logError("RoleAcl does not exist: " + acctID + "/" + roleID + "/" + aclID); } else { try { RoleAcl roleAcl = RoleAcl.getRoleAcl(role, aclID, false); // may throw DBException DBEdit editor = new DBEdit(roleAcl); editor.edit(); // may throw IOException } catch (IOException ioe) { if (ioe instanceof EOFException) { Print.logError("End of input"); } else { Print.logError("IO Error"); } } catch (DBException dbe) { Print.logError("Error editing RoleAcl: " + acctID + "/" + roleID + "/" + aclID); dbe.printException(); } } System.exit(0); } /* no options specified */ if (opts == 0) { Print.logWarn("Missing options ..."); usage(); } }