Refresh connection cache from JSP(this howto is deprecated)Tag(s): DEPRECATED


Thanks to A. Maddox
<%--  JSP Page Directives  --%>
<%@ page import="java.util.*" %>
<%@ page import="com.sybase.jaguar.system.Jaguar1" %>
<%
  String result = new String();
  //Do CORBA lookup
  Properties props = new Properties();
  props.put("org.omg.CORBA.ORBClass", "com.sybase.CORBA.ORB");
  org.omg.CORBA.ORB orb = com.sybase.CORBA.ORB.init
     ((java.lang.String[]) null, props);
  Management iJagComponent =
    ManagementHelper.narrow
       (orb.string_to_object("Jaguar/Management"));
  try{
    iJagComponent.refresh
      ("ConnCache", "theNameOfYourConnectionCache");
    out.write("theNameOfYourConnectionCache");
    }
  catch(Exception e) {}
%>
This snippet will delete a connection cache and create a new one with possibly different parameters.
<%@ page import="org.omg.CORBA.*" %>
<%@ page import="com.sybase.jaguar.system.*,SessionManager.*" %>
<html>
<body>
<%
    java.util.Properties props = new java.util.Properties();
    props.put("org.omg.CORBA.ORBClass", "com.sybase.CORBA.ORB");
    ORB orb = ORB.init((String [])null, props);
    String serverUrl = "iiop://localhost:9000";
    org.omg.CORBA.Object objRef = orb.string_to_object( serverUrl );
    Manager manager = ManagerHelper.narrow(objRef);
    Session jagSession = manager.createSession("jagadmin", "");
    Factory compFactory = FactoryHelper.narrow
       ( jagSession.lookup("Jaguar/Repository") );
    com.sybase.jaguar.system.Repository repository =
       com.sybase.jaguar.system.RepositoryHelper.narrow
          (compFactory.create());
    com.sybase.jaguar.system.Property[] connCacheProps =
       repository.lookup("ConnCache", "MyCache_jConnect");
    /* List properties */
    for(int i = 0; i<connCacheProps.length; i++){
        out.println("Name: " + connCacheProps[i].name + "<br>");
        out.println("Value: " + connCacheProps[i].value + "<p>");
    }
    /* Remove CC */
    repository.remove("ConnCache", "MyCache_jConnect");

    Property[] new_connCacheProps = new Property[10];
    int inx=0;

    /* Set up properties */
    new_connCacheProps[inx++]= new Property
      ( "com.sybase.jaguar.conncache.conlibdll",
        "com.sybase.jdbc.SybDriver");
    new_connCacheProps[inx++]= new Property
      ( "com.sybase.jaguar.conncache.description", "Test CC");
    new_connCacheProps[inx++]= new Property
      ( "com.sybase.jaguar.conncache.remotesvrname",
        "jdbc:sybase:Tds:localhost:4100/test");
    new_connCacheProps[inx++]= new Property
      ( "com.sybase.jaguar.conncache.checkallowed", "true");
    new_connCacheProps[inx++]= new Property
      ( "com.sybase.jaguar.conncache.cachesize", "10");
    new_connCacheProps[inx++]= new Property
      ( "com.sybase.jaguar.conncache.name", "MyCache_jConnect");
    new_connCacheProps[inx++]= new Property
      ( "com.sybase.jaguar.conncache.conlibname", "JDBC");
    new_connCacheProps[inx++]= new Property
      ( "com.sybase.jaguar.conncache.cachebyname", "true");
    new_connCacheProps[inx++]= new Property
      ( "com.sybase.jaguar.conncache.username", "test");
    new_connCacheProps[inx++]= new Property
      ( "com.sybase.jaguar.conncache.password", "test");

    /* Add to repository */
    repository.define("ConnCache", "MyCache_jConnect", new_connCacheProps);
%>
</body>
</html>

blog comments powered by Disqus