List of usage examples for java.lang Throwable Throwable
public Throwable()
From source file:org.dspace.storage.rdbms.MockDatabaseManager.java
/** * Release resources associated with this connection. * * @param c/*from w w w . jav a 2s.com*/ * The connection to release */ @Mock public static void freeConnection(Connection c) { //we check who frees the connection Throwable t = new Throwable(); StackTraceElement[] elements = t.getStackTrace(); String callers = ""; for (int i = 0; i < Math.min(elements.length, 4); i++) { callers += " > " + elements[i].getClassName() + ":" + elements[i].getMethodName(); } //uncomment to see the infromation on callers //log.info(callers+" ("+connectionPool.getNumActive()+" "+connectionPool.getNumIdle()+")"); try { if (c != null) { c.close(); } } catch (SQLException e) { log.warn(e.getMessage()); } }
From source file:ca.sqlpower.sqlobject.BaseSQLObjectTestCase.java
/** * @throws IllegalArgumentException/*from w ww . j a v a2 s . c o m*/ * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException * @throws SQLObjectException */ public void testAllSettersAreUndoable() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, SQLObjectException { SQLObject so = getSQLObjectUnderTest(); propertiesToIgnoreForUndo.add("referenceCount"); propertiesToIgnoreForUndo.add("populated"); propertiesToIgnoreForUndo.add("exportedKeysPopulated"); propertiesToIgnoreForUndo.add("importedKeysPopulated"); propertiesToIgnoreForUndo.add("columnsPopulated"); propertiesToIgnoreForUndo.add("indicesPopulated"); propertiesToIgnoreForUndo.add("SQLObjectListeners"); propertiesToIgnoreForUndo.add("children"); propertiesToIgnoreForUndo.add("parent"); propertiesToIgnoreForUndo.add("parentDatabase"); propertiesToIgnoreForUndo.add("class"); propertiesToIgnoreForUndo.add("childCount"); propertiesToIgnoreForUndo.add("undoEventListeners"); propertiesToIgnoreForUndo.add("connection"); propertiesToIgnoreForUndo.add("typeMap"); propertiesToIgnoreForUndo.add("secondaryChangeMode"); propertiesToIgnoreForUndo.add("zoomInAction"); propertiesToIgnoreForUndo.add("zoomOutAction"); propertiesToIgnoreForUndo.add("magicEnabled"); propertiesToIgnoreForUndo.add("deleteRule"); propertiesToIgnoreForUndo.add("updateRule"); propertiesToIgnoreForUndo.add("tableContainer"); propertiesToIgnoreForUndo.add("session"); propertiesToIgnoreForUndo.add("workspaceContainer"); propertiesToIgnoreForUndo.add("runnableDispatcher"); propertiesToIgnoreForUndo.add("foregroundThread"); if (so instanceof SQLDatabase) { // should be handled in the Datasource propertiesToIgnoreForUndo.add("name"); } SPObjectUndoManager undoManager = new SPObjectUndoManager(so); List<PropertyDescriptor> settableProperties; settableProperties = Arrays.asList(PropertyUtils.getPropertyDescriptors(so.getClass())); if (so instanceof SQLDatabase) { // should be handled in the Datasource settableProperties.remove("name"); } for (PropertyDescriptor property : settableProperties) { Object oldVal; if (propertiesToIgnoreForUndo.contains(property.getName())) continue; try { oldVal = PropertyUtils.getSimpleProperty(so, property.getName()); if (property.getWriteMethod() == null) { continue; } } catch (NoSuchMethodException e) { System.out.println( "Skipping non-settable property " + property.getName() + " on " + so.getClass().getName()); continue; } Object newVal; // don't init here so compiler can warn if the following code doesn't always give it a value if (property.getPropertyType() == Integer.TYPE || property.getPropertyType() == Integer.class) { if (oldVal != null) { newVal = ((Integer) oldVal) + 1; } else { newVal = 1; } } else if (property.getPropertyType() == String.class) { // make sure it's unique newVal = "new " + oldVal; } else if (property.getPropertyType() == Boolean.TYPE || property.getPropertyType() == Boolean.class) { if (oldVal == null) { newVal = Boolean.TRUE; } else { newVal = new Boolean(!((Boolean) oldVal).booleanValue()); } } else if (property.getPropertyType() == SQLCatalog.class) { newVal = new SQLCatalog(new SQLDatabase(), "This is a new catalog"); } else if (property.getPropertyType() == SPDataSource.class) { newVal = new JDBCDataSource(getPLIni()); ((SPDataSource) newVal).setName("test"); ((SPDataSource) newVal).setDisplayName("test"); ((JDBCDataSource) newVal).setUser("a"); ((JDBCDataSource) newVal).setPass("b"); ((JDBCDataSource) newVal).getParentType().setJdbcDriver(MockJDBCDriver.class.getName()); ((JDBCDataSource) newVal).setUrl("jdbc:mock:tables=tab1,tab2"); } else if (property.getPropertyType() == JDBCDataSource.class) { newVal = new JDBCDataSource(getPLIni()); ((SPDataSource) newVal).setName("test"); ((SPDataSource) newVal).setDisplayName("test"); ((JDBCDataSource) newVal).setUser("a"); ((JDBCDataSource) newVal).setPass("b"); ((JDBCDataSource) newVal).getParentType().setJdbcDriver(MockJDBCDriver.class.getName()); ((JDBCDataSource) newVal).setUrl("jdbc:mock:tables=tab1,tab2"); } else if (property.getPropertyType() == SQLTable.class) { newVal = new SQLTable(); } else if (property.getPropertyType() == SQLColumn.class) { newVal = new SQLColumn(); } else if (property.getPropertyType() == SQLIndex.class) { newVal = new SQLIndex(); } else if (property.getPropertyType() == SQLRelationship.SQLImportedKey.class) { SQLRelationship rel = new SQLRelationship(); newVal = rel.getForeignKey(); } else if (property.getPropertyType() == SQLRelationship.Deferrability.class) { if (oldVal == SQLRelationship.Deferrability.INITIALLY_DEFERRED) { newVal = SQLRelationship.Deferrability.NOT_DEFERRABLE; } else { newVal = SQLRelationship.Deferrability.INITIALLY_DEFERRED; } } else if (property.getPropertyType() == SQLIndex.AscendDescend.class) { if (oldVal == SQLIndex.AscendDescend.ASCENDING) { newVal = SQLIndex.AscendDescend.DESCENDING; } else { newVal = SQLIndex.AscendDescend.ASCENDING; } } else if (property.getPropertyType() == Throwable.class) { newVal = new Throwable(); } else if (property.getPropertyType() == BasicSQLType.class) { if (oldVal != BasicSQLType.OTHER) { newVal = BasicSQLType.OTHER; } else { newVal = BasicSQLType.TEXT; } } else if (property.getPropertyType() == UserDefinedSQLType.class) { newVal = new UserDefinedSQLType(); } else if (property.getPropertyType() == SQLTypeConstraint.class) { if (oldVal != SQLTypeConstraint.NONE) { newVal = SQLTypeConstraint.NONE; } else { newVal = SQLTypeConstraint.CHECK; } } else if (property.getPropertyType() == SQLCheckConstraint.class) { newVal = new SQLCheckConstraint("check constraint name", "check constraint condition"); } else if (property.getPropertyType() == SQLEnumeration.class) { newVal = new SQLEnumeration("some enumeration"); } else if (property.getPropertyType() == String[].class) { newVal = new String[3]; } else if (property.getPropertyType() == PropertyType.class) { if (oldVal != PropertyType.NOT_APPLICABLE) { newVal = PropertyType.NOT_APPLICABLE; } else { newVal = PropertyType.VARIABLE; } } else { throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type " + property.getPropertyType().getName() + ") from " + so.getClass()); } int oldChangeCount = undoManager.getUndoableEditCount(); try { BeanUtils.copyProperty(so, property.getName(), newVal); // some setters fire multiple events (they change more than one property) but only register one as an undo assertEquals( "Event for set " + property.getName() + " on " + so.getClass().getName() + " added multiple (" + undoManager.printUndoVector() + ") undos!", oldChangeCount + 1, undoManager.getUndoableEditCount()); } catch (InvocationTargetException e) { System.out.println("(non-fatal) Failed to write property '" + property.getName() + " to type " + so.getClass().getName()); } } }
From source file:org.apache.sqoop.manager.oracle.OraOopUtilities.java
public static boolean stackContainsClass(String className) { StackTraceElement[] stackTraceElements = (new Throwable()).getStackTrace(); for (StackTraceElement stackTraceElement : stackTraceElements) { if (stackTraceElement.getClassName().equalsIgnoreCase(className)) { return true; }/*from w ww . j a va2 s. c om*/ } return false; }
From source file:com.flexive.tests.browser.AbstractBackendBrowserTest.java
/** * write the given String to a file//from w w w. j ava2 s .co m * @param prefix the prefix of the file * @param LOG the Log to log errors * @param html the String to write * @return the name of the file created */ protected String writeHTMLtoHD(String prefix, Log LOG, String html) { // http://localhost:8080/flexive/adm/structure/propertyEditor.jsf?action=createProperty&id=10&nodeType=Type File f = new File(prefix + "@" + System.currentTimeMillis() + ".html"); try { FileOutputStream fos = new FileOutputStream(f); fos.write(html.getBytes()); fos.flush(); fos.close(); LOG.info(f.getAbsolutePath() + "\t" + new Throwable().getStackTrace()[2].toString().replaceAll("com.flexive.tests.browser.", "")); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return f.getAbsolutePath(); }
From source file:org.o3project.ocnrm.odenos.driver.AbstractDriver.java
@Override protected boolean onFlowAddedPre(final String networkId, final Flow flow) { logger.debug(">> " + new Throwable().getStackTrace()[0].getMethodName()); logger.debug("network component ID : " + networkId); statusLog(flow);//from w w w . j a v a 2s .co m NetworkInterface networkIf = networkInterfaces().get(networkId); BasicFlow targetFlow = getFlow(networkIf, flow.getFlowId()); logger.debug(seqNo + "\t" + "flow Status:" + flow.getStatus()); logger.debug(seqNo + "\t" + "targetFlow Status:" + targetFlow.getStatus()); if (!flow.getStatus().equals(FlowStatus.ESTABLISHED.toString())) { statusLog(flow); return true; } statusLog(flow); return false; }
From source file:net.minecraftforge.fml.common.FMLCommonHandler.java
/** * Used to exit from java, with system exit preventions in place. Will be tidy about it and just log a message, * unless debugging is enabled//from w w w . j av a 2 s . co m * * @param exitCode The exit code * @param hardExit Perform a halt instead of an exit (only use when the world is unsavable) - read the warnings at {@link Runtime#halt(int)} */ public void exitJava(int exitCode, boolean hardExit) { FMLLog.log(Level.INFO, "Java has been asked to exit (code %d) by %s.", exitCode, Thread.currentThread().getStackTrace()[1]); if (hardExit) { FMLLog.log(Level.INFO, "This is an abortive exit and could cause world corruption or other things"); } if (Boolean.parseBoolean(System.getProperty("fml.debugExit", "false"))) { FMLLog.log(Level.INFO, new Throwable(), "Exit trace"); } else { FMLLog.log(Level.INFO, "If this was an unexpected exit, use -Dfml.debugExit=true as a JVM argument to find out where it was called"); } if (hardExit) { Runtime.getRuntime().halt(exitCode); } else { Runtime.getRuntime().exit(exitCode); } }
From source file:org.o3project.ocnrm.odenos.driver.AbstractDriver.java
@Override protected boolean onFlowUpdatePre(final String networkId, final Flow prev, final Flow curr, final ArrayList<String> attributesList) { logger.debug(">> " + new Throwable().getStackTrace()[0].getMethodName()); logger.debug("network component ID : " + networkId); statusLog(curr);/*from ww w . j a v a2 s . com*/ NetworkInterface networkIf = networkInterfaces().get(networkId); BasicFlow targetFlow = getFlow(networkIf, curr.getFlowId()); logger.debug(seqNo + "\t" + " flow Status:" + curr.getStatus()); logger.debug(seqNo + "\t" + "targetFlow Status:" + targetFlow.getStatus()); if (!curr.getStatus().equals(FlowStatus.ESTABLISHED.toString())) { statusLog(curr); return true; } statusLog(curr); return false; }
From source file:com.alipay.vbizplatform.web.controller.MyCarManageController.java
/** * ??/*from w w w . j a va 2 s . c o m*/ * @param request * @param response * @return */ @RequestMapping("/queryCarCC") public String queryCarCC(HttpServletRequest request, HttpServletResponse response) { logger.info("uid={},class={},method=queryCarCC,desc=?", super.getUserInfo(request).getUid(), this.getClass().getName()); Map<String, String> pageParam = super.getParametersFromPage(request); long startTime = System.currentTimeMillis(); String uId = null; //? Map<String, Object> vo = null; // Map<String, Map> vehicleTypeListMap = null; try { //1?session?? // Object obj = request.getSession().getAttribute("newVehicleModel"); uId = super.getUserInfo(request).getUid(); String vehicleModelKey = uId + VEHICLE_MODEL_KEY_PREFIX; Object obj = spyMemcachedClient.get(vehicleModelKey); if (obj != null) { vo = (HashMap<String, Object>) obj; /*****???vo******/ if (StringUtils.isNotEmpty(pageParam.get("viNumber"))) { vo.put("viNumber", URLDecoder.decode(pageParam.get("viNumber"), "UTF-8").toUpperCase()); } if (StringUtils.isNotEmpty(pageParam.get("viStartTime"))) {// vo.put("viStartTime", DateUtil.parserDateFromString(pageParam.get("viStartTime"), DateUtil.DATEFORMAT5)); } if (StringUtils.isNotEmpty(pageParam.get("vlCityId"))) {// vo.put("vlCityId", pageParam.get("vlCityId")); } if (StringUtils.isNotEmpty(pageParam.get("vlCityName"))) {// ?? vo.put("vlCityName", URLDecoder.decode(pageParam.get("vlCityName"), "UTF-8")); } // vo.put("viMileage", pageParam.get("viMileage")); // ? vo.put("viVin", pageParam.get("viVin").toUpperCase()); // ?? vo.put("engineNo", pageParam.get("engineNo").toUpperCase()); this.spyMemcachedClient.set(vehicleModelKey, Constant.MEMCACHED_SAVETIME_24, vo); // ?? request.setAttribute("brandName", vo.get("viBrandName")); request.setAttribute("carSeriesName", vo.get("viSeriesName")); if (StringUtils.isNotEmpty(ObjectUtil.toString(vo.get("viLogoUrl")))) { request.setAttribute("modPicUrl", vo.get("viLogoUrl")); } else { request.setAttribute("modPicUrl", vo.get("viBrandLogo")); } request.setAttribute("viId", vo.get("viId")); request.setAttribute("upst", pageParam.get("upst")); request.setAttribute("url_res", ObjectUtil.toString(pageParam.get("url_res"))); } else { // ? if (logger.isErrorEnabled()) { logger.error("session??,toPage->/page/cars/carsList.jsp"); } logUtil.log(new Throwable(), "CARCC", uId, MethodCallResultEnum.EXCEPTION, null, "??session??", startTime); return "redirect:/car/myCarList"; } // // 1???? vehicleTypeListMap = myCarManageService.getVehiclesNow(String.valueOf(vo.get("manufacturer")), String.valueOf(vo.get("viSeriesName"))); //mapset List<String> carCCList = null; if (vehicleTypeListMap != null && !vehicleTypeListMap.isEmpty()) { carCCList = new ArrayList<String>(); for (Map.Entry<String, Map> entry : vehicleTypeListMap.entrySet()) { carCCList.add(entry.getKey()); } request.setAttribute("carCCList", carCCList); request.setAttribute("collapseFlag", pageParam.get("collapseFlag")); } } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("???", e); } logUtil.log(new Throwable(), "CARCC", uId, MethodCallResultEnum.EXCEPTION, null, "???", startTime); super.redirectErrorPage("BUSY-ERR", "??", null, null, response); return null; } logUtil.log(new Throwable(), "CARCC", uId, MethodCallResultEnum.SUCCESS, null, "????", startTime); return "page/cars/selectCarCc"; }
From source file:com.flexive.core.Database.java
/** * Helper function to close connections and statements. * A FxDbException is thrown if the close of the connection failed. * No Exception is thrown if the Statement failed to close, but a error is logged. * * @param caller a string representing the calling function/module, or null * @param con the connection to close, or null * @param stmt the statement to close, or null *//* w ww . j a va 2 s. c om*/ public static void closeObjects(String caller, Connection con, Statement stmt) { try { if (stmt != null) stmt.close(); } catch (Exception exc) { //noinspection ThrowableInstanceNeverThrown StackTraceElement[] se = new Throwable().getStackTrace(); LOG.error(((caller != null) ? caller + " f" : "F") + "ailed to close the statement(s): " + exc.getMessage() + " Calling line: " + se[2].toString()); } if (con != null) { try { if (!con.isClosed()) { con.close(); } } catch (SQLException exc) { //noinspection ThrowableInstanceNeverThrown FxDbException dbExc = new FxDbException( ((caller != null) ? caller + " is u" : "U") + "nable to close the db connection"); LOG.error(dbExc); System.err.println(dbExc.getMessage()); } } }
From source file:com.flexive.core.Database.java
/** * Helper function to close connections and statements. * No Exception is thrown if the Statement failed to close, but a error is logged. * * @param caller a string representing the calling function/module, or null * @param stmts the statements to close, or null *///from w w w . ja v a 2 s. c o m public static void closeObjects(String caller, Statement... stmts) { for (Statement stmt : stmts) { try { if (stmt != null) stmt.close(); } catch (Exception exc) { //noinspection ThrowableInstanceNeverThrown StackTraceElement[] se = new Throwable().getStackTrace(); LOG.error(((caller != null) ? caller + " f" : "F") + "ailed to close the statement(s): " + exc.getMessage() + " Calling line: " + se[2].toString()); } } }