List of usage examples for java.util Hashtable clear
public synchronized void clear()
From source file:com.flexive.shared.EJBLookup.java
/** * Lookup the EJB found under the given Class's name. Uses default flexive naming scheme. * * @param type EJB interface class instance * @param appName EJB application name * @param environment optional environment for creating the initial context * @param <T> EJB interface type * @return a reference to the given EJB//www. j ava 2s .c o m */ protected static <T> T getInterface(Class<T> type, String appName, Hashtable<String, String> environment) { // Try to obtain interface from the lookup cache Object ointerface = ejbCache.get(type.getName()); if (ointerface != null) { return type.cast(ointerface); } // Cache miss: obtain interface and store it in the cache Hashtable<String, String> env; synchronized (EJBLookup.class) { String name; InitialContext ctx = null; env = new Hashtable<String, String>(10); try { if (environment != null) env.putAll(environment); if (used_strategy == null) { appName = discoverStrategy(appName, env, type); if (used_strategy != null) { LOG.info("Working lookup strategy: " + used_strategy); } else { LOG.error("No working lookup strategy found! Possibly because of pending redeployment."); } } prepareEnvironment(used_strategy, env); ctx = new InitialContext(env); name = buildName(appName, type); ointerface = ctx.lookup(name); ejbCache.putIfAbsent(type.getName(), ointerface); return type.cast(ointerface); } catch (Exception exc) { //try one more time with a strategy rediscovery for that bean //this can happen if some beans use mapped names and some not used_strategy = null; try { env.clear(); if (environment != null) env.putAll(environment); appName = discoverStrategy(appName, env, type); if (used_strategy != null) { prepareEnvironment(used_strategy, env); ctx = new InitialContext(env); name = buildName(appName, type); ointerface = ctx.lookup(name); ejbCache.putIfAbsent(type.getName(), ointerface); return type.cast(ointerface); } } catch (Exception e) { LOG.warn("Attempt to rediscover lookup strategy for " + type + " failed!", e); } throw new FxLookupException(LOG, exc, "ex.ejb.lookup.failure", type, exc).asRuntimeException(); } finally { if (ctx != null) try { ctx.close(); } catch (NamingException e) { LOG.error("Failed to close context: " + e.getMessage(), e); } } } }
From source file:io.cloudslang.content.database.services.dbconnection.DBConnectionManager.java
/** * force shutdown everything//w w w .j a v a 2s . c o m */ public synchronized void shutdownDbmsPools() { //force shutdown //runnable datasourceCleaner.shutdown(); datasourceCleaner = null; //shell for the runnable cleanerThread.interrupt();//stop the thread cleanerThread = null; if (dbmsPoolTable == null) { return; } Enumeration<String> allDbmsKeys = dbmsPoolTable.keys(); while (allDbmsKeys.hasMoreElements()) { String dbmsKey = allDbmsKeys.nextElement(); PooledDataSourceProvider provider = this.getProvider(dbmsKey); Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(dbmsKey); for (DataSource ds : dsTable.values()) { try { provider.closePooledDataSource(ds); } catch (SQLException e) { // todo logger.error("Failed to close datasource in dbms poolKey = " // + dbmsKey); } } dsTable.clear(); } dbmsPoolTable.clear(); dbmsPoolTable = null; }
From source file:org.allcolor.yahp.converter.CClassLoader.java
/** * destroy the loader tree/* ww w. ja va2 s . c om*/ */ public static final void destroy() { if (CClassLoader.rootLoader == null) { return; } System.out.println("Destroying YAHP ClassLoader Tree"); CClassLoader.urlLoader = null; try { Field f = Class.forName("java.lang.Shutdown").getDeclaredField("hooks"); f.setAccessible(true); ArrayList l = (ArrayList) f.get(null); for (Iterator it = l.iterator(); it.hasNext();) { Object o = it.next(); if ((o != null) && (o.getClass().getClassLoader() != null) && (o.getClass().getClassLoader().getClass() == CClassLoader.class)) { it.remove(); } } } catch (Throwable ignore) { } try { Field f = Class.forName("java.lang.ApplicationShutdownHooks").getDeclaredField("hooks"); f.setAccessible(true); IdentityHashMap l = (IdentityHashMap) f.get(null); for (Iterator it = l.entrySet().iterator(); it.hasNext();) { Entry e = (Entry) it.next(); Thread o = (Thread) e.getKey(); if ((o != null) && (o.getClass().getClassLoader() != null) && (o.getClass().getClassLoader().getClass() == CClassLoader.class)) { it.remove(); continue; } o = (Thread) e.getValue(); if ((o != null) && (o.getClass().getClassLoader() != null) && (o.getClass().getClassLoader().getClass() == CClassLoader.class)) { it.remove(); } } } catch (Throwable ignore) { } try { if ((UIManager.getLookAndFeel() != null) && (UIManager.getLookAndFeel().getClass().getClassLoader() != null) && (UIManager.getLookAndFeel().getClass().getClassLoader().getClass() == CClassLoader.class)) { UIManager.setLookAndFeel((LookAndFeel) null); } Field f = UIManager.class.getDeclaredField("currentLAFState"); f.setAccessible(true); Object lafstate = f.get(null); if (lafstate != null) { Field fmultiUIDefaults = lafstate.getClass().getDeclaredField("multiUIDefaults"); fmultiUIDefaults.setAccessible(true); Object multiUIDefaults = fmultiUIDefaults.get(lafstate); Method clear = multiUIDefaults.getClass().getDeclaredMethod("clear", (Class[]) null); clear.setAccessible(true); clear.invoke(multiUIDefaults, (Object[]) null); Field tbl = lafstate.getClass().getDeclaredField("tables"); tbl.setAccessible(true); Hashtable[] tables = (Hashtable[]) tbl.get(lafstate); if (tables != null) { for (int i = 0; i < tables.length; i++) { Hashtable element = tables[i]; if (element != null) { element.clear(); } } } } } catch (Throwable ignore) { } try { Hashtable tb = UIManager.getDefaults(); Object cl = tb.get("ClassLoader"); if (cl.getClass() == CClassLoader.class) { tb.put("ClassLoader", CClassLoader.rootLoader.getParent()); } } catch (Throwable ignore) { } Method logFactoryRelease = null; try { logFactoryRelease = CClassLoader.rootLoader.loadClass("org.apache.commons.logging.LogFactory") .getMethod("release", new Class[] { ClassLoader.class }); } catch (final Throwable ignore) { } CClassLoader.rootLoader._destroy(logFactoryRelease); CClassLoader.mandatoryLoadersMap.clear(); CClassLoader.rootLoader = null; // deregister any sql driver loaded try { final List deregisterList = new ArrayList(); for (final Enumeration it = DriverManager.getDrivers(); it.hasMoreElements();) { final Driver d = (Driver) it.nextElement(); if ((d != null) && (d.getClass().getClassLoader() != null) && (d.getClass().getClassLoader().getClass() == CClassLoader.class)) { deregisterList.add(d); } } for (int i = 0; i < deregisterList.size(); i++) { final Driver driver = (Driver) deregisterList.get(i); DriverManager.deregisterDriver(driver); } } catch (final Throwable ignore) { } // stop dandling thread created with this classloader // tested only on sun jdk ThreadGroup tg = Thread.currentThread().getThreadGroup(); while ((tg != null) && (tg.getParent() != null)) { tg = tg.getParent(); } List ltg = new ArrayList(); ltg.add(tg); CClassLoader.getThreadGroups(tg, ltg); for (int ii = 0; ii < ltg.size(); ii++) { try { final ThreadGroup g = (ThreadGroup) ltg.get(ii); final Field fthreads = ThreadGroup.class.getDeclaredField("threads"); fthreads.setAccessible(true); final List toStop = new ArrayList(); Object threads[] = null; if (fthreads.getType() == Vector.class) { // in gnu classpath threads = ((Vector) fthreads.get(g)).toArray(); } else { // sun threads = (Object[]) fthreads.get(g); } for (int i = 0; i < threads.length; i++) { if (threads[i] == null) { continue; } if ((threads[i] != null) && (((Thread) threads[i]).getContextClassLoader() != null) && (((Thread) threads[i]).getContextClassLoader().getClass() == CClassLoader.class)) { ((Thread) threads[i]).setContextClassLoader(null); } if ((threads[i] != null) && (threads[i].getClass().getClassLoader() != null) && (threads[i].getClass().getClassLoader().getClass() == CClassLoader.class)) { toStop.add((Thread) threads[i]); } // remove any object in threadLocal referring an object // loaded // by this classloader tree try { final Field fthreadLocals = Thread.class.getDeclaredField("threadLocals"); fthreadLocals.setAccessible(true); final Object threadLocals = fthreadLocals.get(threads[i]); if (threadLocals != null) { final Field ftable = threadLocals.getClass().getDeclaredField("table"); ftable.setAccessible(true); final Object table[] = (Object[]) ftable.get(threadLocals); for (int kk = 0; kk < table.length; kk++) { final Object element = table[kk]; if (element != null) { final Field fvalue = element.getClass().getDeclaredField("value"); fvalue.setAccessible(true); final Object value = fvalue.get(element); if ((value != null) && (value.getClass().getClassLoader() != null) && (value .getClass().getClassLoader().getClass() == CClassLoader.class)) { fvalue.set(element, null); } if (value instanceof Map) { clearMap((Map) value); } else if (value instanceof List) { clearList((List) value); } else if (value instanceof Set) { clearSet((Set) value); } else if (value instanceof Object[]) { clearArray((Object[]) value); } fvalue.setAccessible(false); } } ftable.setAccessible(false); } fthreadLocals.setAccessible(false); } catch (final Throwable ignore) { ignore.printStackTrace(); } // remove any object in threadLocal referring an object // loaded // by this classloader tree try { final Field fthreadLocals = Thread.class.getDeclaredField("inheritableThreadLocals"); fthreadLocals.setAccessible(true); final Object threadLocals = fthreadLocals.get(threads[i]); if (threadLocals != null) { final Field ftable = threadLocals.getClass().getDeclaredField("table"); ftable.setAccessible(true); final Object table[] = (Object[]) ftable.get(threadLocals); for (int kk = 0; kk < table.length; kk++) { final Object element = table[kk]; if (element != null) { final Field fvalue = element.getClass().getDeclaredField("value"); fvalue.setAccessible(true); final Object value = fvalue.get(element); if ((value != null) && (value.getClass().getClassLoader() != null) && (value .getClass().getClassLoader().getClass() == CClassLoader.class)) { fvalue.set(element, null); } if (value instanceof Map) { clearMap((Map) value); } else if (value instanceof List) { clearList((List) value); } else if (value instanceof Set) { clearSet((Set) value); } else if (value instanceof Object[]) { clearArray((Object[]) value); } fvalue.setAccessible(false); } } ftable.setAccessible(false); } fthreadLocals.setAccessible(false); } catch (final Throwable ignore) { ignore.printStackTrace(); } // remove any protection domain referring this loader tree try { final Field finheritedAccessControlContext = Thread.class .getDeclaredField("inheritedAccessControlContext"); finheritedAccessControlContext.setAccessible(true); final Object inheritedAccessControlContext = finheritedAccessControlContext.get(threads[i]); if (inheritedAccessControlContext != null) { final Field fcontext = AccessControlContext.class.getDeclaredField("context"); fcontext.setAccessible(true); final Object context[] = (Object[]) fcontext.get(inheritedAccessControlContext); if (context != null) { for (int k = 0; k < context.length; k++) { if (context[k] == null) continue; final Field fclassloader = ProtectionDomain.class .getDeclaredField("classloader"); fclassloader.setAccessible(true); final Object classloader = fclassloader.get(context[k]); if ((classloader != null) && (classloader.getClass() == CClassLoader.class)) { context[k] = null; } fclassloader.setAccessible(false); } } fcontext.setAccessible(false); } finheritedAccessControlContext.setAccessible(false); } catch (final Throwable ignore) { ignore.printStackTrace(); } } fthreads.setAccessible(false); for (int i = 0; i < toStop.size(); i++) { try { final Thread t = (Thread) toStop.get(i); final Method stop = t.getClass().getMethod("stop", (Class[]) null); stop.invoke(t, (Object[]) null); } catch (final Throwable ignore) { } } } catch (final Throwable ignore) { } } try { CThreadContext.destroy(); } catch (Throwable ignore) { } System.runFinalization(); System.gc(); Introspector.flushCaches(); System.out.println("Destroying YAHP ClassLoader Tree : done"); }
From source file:com.stimulus.archiva.security.realm.ADRealm.java
public ArrayList<AttributeValue> getADAttributes(Config config, ADIdentity identity, String username, String password) throws ArchivaException { logger.debug("getADAttributes()"); validateLoginName(username);//from ww w. j a v a 2 s .c o m validatePassword(password); LoginContext serverLC = kereberosLogin(config, identity, identity.getServiceDN(), identity.getServicePassword()); Hashtable<String, String> env = new Hashtable<String, String>(11); String ldapAddress = identity.getLDAPAddress(); if (!ldapAddress.toLowerCase(Locale.ENGLISH).startsWith("ldap://")) ldapAddress = "ldap://" + ldapAddress; logger.debug("finding DN of user from LDAP using Kereberos token {ldapAddress='" + ldapAddress + "', username='" + username + "'}"); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, ldapAddress); env.put(Context.SECURITY_AUTHENTICATION, "GSSAPI"); int at = username.indexOf('@'); String uname = username; if (uname.indexOf("@") != -1) { uname = username.substring(0, at).toLowerCase(Locale.ENGLISH); } logger.debug("findUserDN {loginname='" + uname + "'}"); String bindDN = null; try { bindDN = (String) Subject.doAs(serverLC.getSubject(), new FindDNAction(identity, uname, env)); } catch (Exception e) { throw new ArchivaException("failed to bind to ldap server {uname='" + username + "''}", e, logger); } try { serverLC.logout(); } catch (Exception e) { throw new ArchivaException("failed to logout from kerberos server:" + e.getMessage() + " {uname='" + username + "',kdcAddress='" + identity.getKDCAddress() + "'}", e, logger); } ArrayList<AttributeValue> attributes = new ArrayList<AttributeValue>(); serverLC = kereberosLogin(config, identity, username, password); if (bindDN != null) { env.clear(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, ldapAddress); env.put(Context.SECURITY_AUTHENTICATION, "GSSAPI"); try { attributes = (ArrayList<AttributeValue>) Subject.doAs(serverLC.getSubject(), new GetAttributesAction(identity, username, env, bindDN)); } catch (Exception e) { throw new ArchivaException("failed to bind to ldap server:" + e.getMessage() + " {uname='" + username + "',ldapAddress='" + identity.getLDAPAddress() + "'}", e, logger); } } try { serverLC.logout(); } catch (Exception e) { throw new ArchivaException("failed to logout from kerberos server:" + e.getMessage() + " {uname='" + username + "',kdcAddress='" + identity.getKDCAddress() + "'}", e, logger); } logger.debug("getADAttributes() return"); return attributes; }
From source file:com.fiorano.openesb.application.aps.InPortInst.java
protected void populate(FioranoStaxParser parser) throws XMLStreamException, FioranoException { if (parser.markCursor(APSConstants.INPORT_INST)) { // Get Attributes if needs to accessed later. This MUST be done before accessing any data of element. Hashtable attributes = parser.getAttributes(); m_bIsSyncRequestType = XMLUtils/*from ww w . j a va2 s. c o m*/ .getStringAsBoolean((String) attributes.get(APSConstants.IS_SYNC_REQUEST_TYPE));//XMLDmiUtil.getAttributeAsBoolean(port, "isSyncRequestType"); m_bisDisabled = XMLUtils.getStringAsBoolean((String) attributes.get(APSConstants.IS_DISABLED));//XMLDmiUtil.getAttributeAsBoolean(port, "isSyncRequestType"); while (parser.nextElement()) { String nodeName = parser.getLocalName(); if (nodeName.equalsIgnoreCase("Name")) { m_strPortName = parser.getText();//XMLUtils.getNodeValueAsString(child).toUpperCase(); } if (nodeName.equalsIgnoreCase("Description")) { m_strDscription = parser.getText();//XMLUtils.getNodeValueAsString(child); } if (nodeName.equalsIgnoreCase(PortInstConstants.PORT_XSD)) { m_strXSD = parser.getCData();//XMLUtils.getNodeValueAsString(child); } if (nodeName.equalsIgnoreCase(PortInstConstants.PORT_XSDREF)) { m_strXSDRef = parser.getText();//XMLUtils.getNodeValueAsString(child); } if (nodeName.equalsIgnoreCase("JavaClass")) { m_strJavaClass = parser.getText();//XMLUtils.getNodeValueAsString(child); } if (nodeName.equalsIgnoreCase("Param")) { Param paramDmi = new Param(); paramDmi.setFieldValues(parser); addParam(paramDmi); } } if (attributes != null) { attributes.clear(); attributes = null; } } validate(); }
From source file:press.gfw.Server.java
/** * //from ww w. j ava 2s . c o m */ public void service() { if (System.currentTimeMillis() - lockFile.lastModified() < 30 * 000L) { log("???"); log("? " + lockFile.getAbsolutePath() + "??"); return; } try { lockFile.createNewFile(); } catch (IOException ioe) { } lockFile.deleteOnExit(); log("GFW.Press??......"); log("?" + proxyHost); log("??" + proxyPort); Hashtable<String, String> users = null; // Hashtable<String, Server> threads = new Hashtable<String, Server>(); // while (true) { lockFile.setLastModified(System.currentTimeMillis()); _sleep(20 * 1000L); // ?20 users = config.getUser(); // ? if (users == null || users.size() == 0) { continue; } Enumeration<String> threadPorts = threads.keys(); // ? while (threadPorts.hasMoreElements()) { // ??? String threadPort = threadPorts.nextElement(); String userPassword = users.remove(threadPort); if (userPassword == null) { // threads.remove(threadPort).kill(); log("?" + threadPort); } else { Server thread = threads.get(threadPort); if (!userPassword.equals(thread.getPassword())) { // ? log("??" + threadPort); threads.remove(threadPort); thread.kill(); thread = new Server(proxyHost, proxyPort, threadPort, userPassword); threads.put(threadPort, thread); thread.start(); } } } Enumeration<String> userPorts = users.keys(); while (userPorts.hasMoreElements()) { // String userPort = userPorts.nextElement(); Server thread = new Server(proxyHost, proxyPort, userPort, users.get(userPort)); threads.put(userPort, thread); thread.start(); } users.clear(); } }
From source file:org.unitime.timetable.solver.TimetableSolver.java
public Vector getTimetableGridTables(TimetableGridContext context) { Vector models = new Vector(); Query q = (context.getFilter() == null ? null : new Query(context.getFilter())); Lock lock = currentSolution().getLock().readLock(); lock.lock();//w ww . java 2s .c o m try { TimetableModel model = (TimetableModel) currentSolution().getModel(); switch (context.getResourceType()) { case TimetableGridModel.sResourceTypeRoom: for (RoomConstraint rc : model.getRoomConstraints()) { if (!match(q, rc)) continue; models.add(new SolverGridModel(this, rc, context)); } break; case TimetableGridModel.sResourceTypeInstructor: for (InstructorConstraint ic : model.getInstructorConstraints()) { if (!match(q, ic.getName())) continue; models.add(new SolverGridModel(this, ic, context)); } break; case TimetableGridModel.sResourceTypeDepartment: for (DepartmentSpreadConstraint dc : model.getDepartmentSpreadConstraints()) { if (!match(q, dc.getName())) continue; models.add(new SolverGridModel(this, dc, context)); } if (model.getDepartmentSpreadConstraints().isEmpty()) { org.cpsolver.ifs.assignment.Assignment<Lecture, Placement> assignment = currentSolution() .getAssignment(); Map<Department, Set<Long>> dept2class = new HashMap<Department, Set<Long>>(); for (Object[] pair : (List<Object[]>) DepartmentDAO.getInstance().getSession().createQuery( "select c.controllingDept, c.uniqueId from Class_ c where c.managingDept.solverGroup.uniqueId in :solverGroupIds") .setParameterList("solverGroupIds", getOwnerId(), new LongType()).list()) { Department dept = (Department) pair[0]; Long classId = (Long) pair[1]; Set<Long> classIds = dept2class.get(dept); if (classIds == null) { classIds = new HashSet<Long>(); dept2class.put(dept, classIds); } classIds.add(classId); } for (Department d : new TreeSet<Department>(dept2class.keySet())) { if (!match(q, d.getShortLabel())) continue; Set<Long> classIds = dept2class.get(d); int size = 0; List<Placement> placements = new ArrayList<Placement>(); for (Lecture lecture : currentSolution().getModel().variables()) { if (classIds.contains(lecture.getClassId())) { size++; Placement placement = assignment.getValue(lecture); if (placement != null) placements.add(placement); } } if (size > 0) models.add(new SolverGridModel(this, TimetableGridModel.sResourceTypeDepartment, d.getUniqueId(), d.getShortLabel(), size, placements, context)); } } break; case TimetableGridModel.sResourceTypeCurriculum: Hashtable<String, List<Student>> curricula = new Hashtable<String, List<Student>>(); boolean hasCurricula = false; HashSet<String> ignore = new HashSet<String>(), tested = new HashSet<String>(); for (Student student : model.getAllStudents()) { if (student.getCurriculum() != null && student.getAcademicClassification() != null) { if (!hasCurricula) { curricula.clear(); hasCurricula = true; } String c = student.getCurriculum() + " " + student.getAcademicClassification(); if (tested.add(c) && !match(q, c)) ignore.add(c); if (ignore.contains(c)) continue; List<Student> students = curricula.get(c); if (students == null) { students = new ArrayList<Student>(); curricula.put(c, students); } students.add(student); } else if (!hasCurricula && student.getAcademicArea() != null && student.getAcademicClassification() != null) { String c = student.getAcademicArea() + (student.getMajor() == null ? "" : " " + student.getMajor()) + " " + student.getAcademicClassification(); if (tested.add(c) && !match(q, c)) ignore.add(c); if (ignore.contains(c)) continue; List<Student> students = curricula.get(c); if (students == null) { students = new ArrayList<Student>(); curricula.put(c, students); } students.add(student); } } for (Map.Entry<String, List<Student>> curriculum : curricula.entrySet()) { models.add(new SolverGridModel(this, curriculum.getKey(), curriculum.getValue(), context)); } break; case TimetableGridModel.sResourceTypeSubjectArea: org.cpsolver.ifs.assignment.Assignment<Lecture, Placement> assignment = currentSolution() .getAssignment(); Map<SubjectArea, Set<Long>> sa2class = new HashMap<SubjectArea, Set<Long>>(); for (Object[] pair : (List<Object[]>) DepartmentDAO.getInstance().getSession().createQuery( "select co.subjectArea, c.uniqueId from Class_ c inner join c.schedulingSubpart.instrOfferingConfig.instructionalOffering.courseOfferings co where co.isControl = true and c.managingDept.solverGroup.uniqueId in :solverGroupIds") .setParameterList("solverGroupIds", getOwnerId(), new LongType()).list()) { SubjectArea sa = (SubjectArea) pair[0]; Long classId = (Long) pair[1]; Set<Long> classIds = sa2class.get(sa); if (classIds == null) { classIds = new HashSet<Long>(); sa2class.put(sa, classIds); } classIds.add(classId); } for (SubjectArea sa : new TreeSet<SubjectArea>(sa2class.keySet())) { if (!match(q, sa.getSubjectAreaAbbreviation())) continue; Set<Long> classIds = sa2class.get(sa); int size = 0; List<Placement> placements = new ArrayList<Placement>(); for (Lecture lecture : currentSolution().getModel().variables()) { if (classIds.contains(lecture.getClassId())) { size++; Placement placement = assignment.getValue(lecture); if (placement != null) placements.add(placement); } } if (size > 0) models.add(new SolverGridModel(this, TimetableGridModel.sResourceTypeSubjectArea, sa.getUniqueId(), sa.getSubjectAreaAbbreviation(), size, placements, context)); } break; } } finally { lock.unlock(); } return models; }
From source file:edu.ku.brc.specify.tasks.ExpressSearchTask.java
/** * Traverses through the results and adds to the panel to be displayed. * @param resultsMap the primary result tables * @param resultsForJoinsMap the related results table *//*from w ww . j a va 2 s.c o m*/ protected void displayResults(final ExpressSearchResultsPaneIFace esrPane, final QueryForIdResultsIFace queryResults, final Hashtable<String, QueryForIdResultsSQL> resultsForJoinsMap) { // For Debug Only if (false && resultsForJoinsMap != null) { for (Enumeration<QueryForIdResultsSQL> e = resultsForJoinsMap.elements(); e.hasMoreElements();) { QueryForIdResultsSQL qfirsql = e.nextElement(); if (qfirsql.getRecIds().size() > 0) { log.debug("\n\n------------------------------------"); log.debug("------------------------------------"); log.debug("Search Id " + qfirsql.getTableInfo().getId() + " Table Id " + qfirsql.getTableInfo().getTableId() + " Column Name " + qfirsql.getJoinColTableId()); log.debug("------------------------------------"); for (Integer l : qfirsql.getRecIds()) { log.debug(l + " "); } } } } if (queryResults.size() > 0) { esrPane.addSearchResults(queryResults); } if (resultsForJoinsMap != null) { for (QueryForIdResultsSQL rs : resultsForJoinsMap.values()) { if (rs.getRecIds().size() > 0) { esrPane.addSearchResults(rs); } } resultsForJoinsMap.clear(); } }
From source file:edu.ku.brc.af.ui.forms.persist.ViewLoader.java
/** * Creates the view./*from w w w.j a va2 s . c o m*/ * @param element the element to build the View from * @param altViewsViewDefName the hashtable to track the AltView's ViewDefName * @return the View * @throws Exception */ protected static ViewIFace createView(final Element element, final Hashtable<AltViewIFace, String> altViewsViewDefName) throws Exception { String name = element.attributeValue(NAME); String objTitle = getAttr(element, "objtitle", null); String className = element.attributeValue(CLASSNAME); String desc = getDesc(element); String businessRules = getAttr(element, "busrules", null); boolean isInternal = getAttr(element, "isinternal", true); DBTableInfo ti = DBTableIdMgr.getInstance().getByClassName(className); if (ti != null && StringUtils.isEmpty(objTitle)) { objTitle = ti.getTitle(); } View view = new View(instance.viewSetName, name, objTitle, className, businessRules != null ? businessRules.trim() : null, getAttr(element, "usedefbusrule", true), isInternal, desc); // Later we should get this from a properties file. if (ti != null) { view.setTitle(ti.getTitle()); } /*if (!isInternal) { System.err.println(StringUtils.replace(name, " ", "_")+"="+UIHelper.makeNamePretty(name)); }*/ Element altviews = (Element) element.selectSingleNode("altviews"); if (altviews != null) { AltViewIFace defaultAltView = null; AltView.CreationMode defaultMode = AltView.parseMode(getAttr(altviews, "mode", ""), AltViewIFace.CreationMode.VIEW); String selectorName = altviews.attributeValue("selector"); view.setDefaultMode(defaultMode); view.setSelectorName(selectorName); Hashtable<String, Boolean> nameCheckHash = new Hashtable<String, Boolean>(); // iterate through child elements for (Iterator<?> i = altviews.elementIterator("altview"); i.hasNext();) { Element altElement = (Element) i.next(); AltView.CreationMode mode = AltView.parseMode(getAttr(altElement, "mode", ""), AltViewIFace.CreationMode.VIEW); String altName = altElement.attributeValue(NAME); String viewDefName = altElement.attributeValue("viewdef"); String title = altElement.attributeValue(TITLE); boolean isValidated = getAttr(altElement, "validated", mode == AltViewIFace.CreationMode.EDIT); boolean isDefault = getAttr(altElement, "default", false); // Make sure we only have one default view if (defaultAltView != null && isDefault) { isDefault = false; } // Check to make sure all the AlViews have different names. Boolean nameExists = nameCheckHash.get(altName); if (nameExists == null) // no need to check the boolean { AltView altView = new AltView(view, altName, title, mode, isValidated, isDefault, null); // setting a null viewdef altViewsViewDefName.put(altView, viewDefName); if (StringUtils.isNotEmpty(selectorName)) { altView.setSelectorName(selectorName); String selectorValue = altElement.attributeValue("selector_value"); if (StringUtils.isNotEmpty(selectorValue)) { altView.setSelectorValue(selectorValue); } else { FormDevHelper.appendFormDevError("Selector Value is missing for viewDefName[" + viewDefName + "] altName[" + altName + "]"); } } if (defaultAltView == null && isDefault) { defaultAltView = altView; } view.addAltView(altView); nameCheckHash.put(altName, true); } else { log.error("The altView name[" + altName + "] already exists!"); } nameCheckHash.clear(); // why not? } // No default Alt View was indicated, so choose the first one (if there is one) if (defaultAltView == null && view.getAltViews() != null && view.getAltViews().size() > 0) { view.getAltViews().get(0).setDefault(true); } } return view; }
From source file:edu.ku.brc.specify.tasks.QueryTask.java
/** * Confgiure Queries that show in the sidebar. *///from w ww .ja va2 s.c o m protected void configureFavoriteQueries() { QueryConfigureDlg dlg = new QueryConfigureDlg(QueryTask.this); UIHelper.centerAndShow(dlg); if (!dlg.isCancelled()) { Vector<SpQuery> favs = dlg.getFavQueries(); Vector<SpQuery> extras = dlg.getOtherQueries(); Hashtable<Integer, Integer> hash = new Hashtable<Integer, Integer>(); for (SpQuery q : favs) { int id = q.getId(); hash.put(id, id); } for (NavBoxItemIFace nbi : new Vector<NavBoxItemIFace>(navBox.getItems())) { RecordSetIFace rs = (RecordSetIFace) nbi.getData(); if (rs != null) { RecordSetItemIFace rsi = rs.getOnlyItem(); Integer idInt = rsi.getRecordId(); if (idInt != null) { int id = idInt; if (hash.get(id) == null) { navBox.remove(nbi); } } } } hash.clear(); for (NavBoxItemIFace nbi : navBox.getItems()) { RecordSetIFace rs = (RecordSetIFace) nbi.getData(); if (rs != null) { RecordSetItemIFace rsi = rs.getOnlyItem(); int id = rsi.getRecordId(); hash.put(id, id); } } for (SpQuery query : favs) { int id = query.getId(); if (hash.get(id) == null) { RecordSet rs = new RecordSet(); rs.initialize(); rs.set(query.getName(), SpQuery.getClassTableId(), RecordSet.GLOBAL); rs.addItem(query.getSpQueryId()); addToNavBox(rs); } } // Persist out to database DataProviderSessionIFace session = null; try { session = DataProviderFactory.getInstance().createSession(); session.beginTransaction(); short order = 0; for (SpQuery query : favs) { query.setIsFavorite(true); query.setOrdinal(order++); session.saveOrUpdate(query); } for (SpQuery query : extras) { query.setIsFavorite(false); query.setOrdinal(null); session.saveOrUpdate(query); } session.commit(); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(QueryTask.class, ex); // XXX Error dialog session.rollback(); } finally { if (session != null) { session.close(); } } // Now Reorder list Hashtable<Integer, NavBoxItemIFace> nbiHash = new Hashtable<Integer, NavBoxItemIFace>(); for (NavBoxItemIFace nbi : navBox.getItems()) { RecordSetIFace rs = (RecordSetIFace) nbi.getData(); if (rs != null) { RecordSetItemIFace rsi = rs.getOnlyItem(); int id = rsi.getRecordId(); nbiHash.put(id, nbi); } } navBox.clear(); Collections.sort(favs, new Comparator<SpQuery>() { public int compare(SpQuery q1, SpQuery q2) { return q1.getOrdinal().compareTo(q2.getOrdinal()); } }); for (SpQuery query : favs) { int id = query.getId(); navBox.add(nbiHash.get(id)); } checkForOtherNavBtn(); navBox.validate(); navBox.doLayout(); NavBoxMgr.getInstance().validate(); NavBoxMgr.getInstance().doLayout(); NavBoxMgr.getInstance().repaint(); } }