Monday, 20 December 2010

Querying Coherence Cache from JRuby

To complete the Coherence/JRuby demos this final demo shows how we can query the cache using filters to show the data we are interested in. From this demo you can see our cache has the oracle data dictionary view ALL_DB_OBJECTS data which was loaded from an 11.2.0.2 RDBMS. The output will make that obvious.

JRuby script is as follows - coh-extend-client-query.rb

require 'java'
require 'C:/jdev/scripting/demos/jruby/extendclient-coherence/extenddemo.jar'
require 'C:/jdev/coherence/36/coherence/lib/coherence.jar'

include_class "pas.au.coherence.extend.server.AllDBObject"
import com.tangosol.net.CacheFactory
import com.tangosol.net.NamedCache
import java.util.Date
import java.lang.System
import java.math.BigDecimal
import java.util.Set

puts "***********************************************"
puts "Coherence 3.6 Extend Client Example from JRUBY"
puts "***********************************************"

print "Started at ", Date.new.toString, "\n"

begin

  # setup required properties to connect to proxy server as extend client
  System.setProperty("tangosol.pof.enabled", "true")
  System.setProperty("tangosol.pof.config", "extend-pof-config.xml")
  System.setProperty("tangosol.coherence.cacheconfig", "client-cache-config.xml")
  System.setProperty("proxy.host", "papicell-au2.au.oracle.com")

  # get named cache alldbobjs
  alldbobjs = CacheFactory.getCache("alldbobjs")

  #retrieve size of cache
  print "\nCache [alldbobjs] size  = " + alldbobjs.size().to_s + "\n\n"
  
  #retrieve all SCOTT schema entries
  filter = com.tangosol.util.filter.EqualsFilter.new("getOwner", "SCOTT")
  scottObjects = alldbobjs.entrySet(filter)
  
  #iterate through SCOTT's objects 
  print "\nTotal of " + scottObjects.size().to_s + " cache entries found \n"

  print "Is scottObjects empty : ", scottObjects.empty?, "\n"
  puts
  
  iterator = scottObjects.iterator()
  while iterator.hasNext()
    entry = iterator.next()
    print "Key : [" + entry.getKey().to_s + "] "
    print "Value : [Owner=" + entry.getValue().getOwner() + 
          ", objectName=" + entry.getValue().getObjectName() +
          ", objectType=" + entry.getValue().getObjectType() + "]"
    puts
  end
  
rescue 
  print "\n** Error occured **\n"
 print "Failed to access Coherence Cluster from proxy server -> \n", $!, "\n\n"
  
end

puts
print "Ended at ", Date.new.toString, "\n"

The output when run shows the SCOTT schema objects being queried from the cache


C:\jdev\scripting\demos\jruby\extendclient-coherence>vi coh-extend-client-query.rb


C:\jdev\scripting\demos\jruby\extendclient-coherence>jrb coh-extend-client-query.rb
***********************************************
Coherence 3.6 Extend Client Example from JRUBY
***********************************************
Started at Mon Dec 20 07:36:52 EST 2010
2010-12-20 07:36:52.752/0.869 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Loaded operational configuration from "jar:file:/C:
/jdev/coherence/36/coherence/lib/coherence.jar!/tangosol-coherence.xml"
2010-12-20 07:36:52.756/0.873 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Loaded operational overrides from "jar:file:/C:/jde
v/coherence/36/coherence/lib/coherence.jar!/tangosol-coherence-override-dev.xml"
2010-12-20 07:36:52.756/0.873 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Optional configuration override "/tangosol-coherence-
override.xml" is not specified
2010-12-20 07:36:52.759/0.876 Oracle Coherence 3.6.0.0 (thread=main, member=n/a): Optional configuration override "/custom-mbeans.xml"
is not specified


Oracle Coherence Version 3.6.0.0 Build 17229
 Grid Edition: Development mode
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.


2010-12-20 07:36:52.945/1.062 Oracle Coherence GE 3.6.0.0 (thread=main, member=n/a): Loaded cache configuration from "jar:file:/C:/jd
ev/scripting/demos/jruby/extendclient-coherence/extenddemo.jar!/client-cache-config.xml"
2010-12-20 07:36:53.107/1.224 Oracle Coherence GE 3.6.0.0 (thread=RemoteCache:TcpInitiator, member=n/a): Loaded POF configuration fro
m "jar:file:/C:/jdev/scripting/demos/jruby/extendclient-coherence/extenddemo.jar!/extend-pof-config.xml"
2010-12-20 07:36:53.111/1.228 Oracle Coherence GE 3.6.0.0 (thread=RemoteCache:TcpInitiator, member=n/a): Loaded included POF configur
ation from "jar:file:/C:/jdev/coherence/36/coherence/lib/coherence.jar!/coherence-pof-config.xml"
2010-12-20 07:36:53.214/1.331 Oracle Coherence GE 3.6.0.0 (thread=RemoteCache:TcpInitiator, member=n/a): Started: TcpInitiator{Name=Rem
oteCache:TcpInitiator, State=(SERVICE_STARTED), ThreadCount=0, Codec=Codec(Format=POF), PingInterval=0, PingTimeout=0, RequestTimeout=0, Con
nectTimeout=0, SocketProvider=SystemSocketProvider, RemoteAddresses=[papicell-au2.au.oracle.com/10.187.80.136:9099]}
2010-12-20 07:36:53.218/1.335 Oracle Coherence GE 3.6.0.0 (thread=main, member=n/a): Opening Socket connection to 10.187.80.136:9099
2010-12-20 07:36:53.220/1.337 Oracle Coherence GE 3.6.0.0 (thread=main, member=n/a): Connected to 10.187.80.136:9099


Cache [alldbobjs] size  = 99927




Total of 55 cache entries found
Is scottObjects empty : false


Key : [82967] Value : [Owner=SCOTT, objectName=TEST_STRING, objectType=TABLE]
Key : [126758] Value : [Owner=SCOTT, objectName=Host2, objectType=JAVA CLASS]
Key : [128400] Value : [Owner=SCOTT, objectName=DISPLAYPROPERTIES, objectType=FUNCTION]
Key : [173453] Value : [Owner=SCOTT, objectName=SYS_LOB0000173452C00002$$, objectType=LOB]
Key : [128399] Value : [Owner=SCOTT, objectName=CheckProperties, objectType=JAVA CLASS]
Key : [85457] Value : [Owner=SCOTT, objectName=JUNKPR, objectType=PROCEDURE]
Key : [150089] Value : [Owner=SCOTT, objectName=HELLOWORLDPKG, objectType=PACKAGE]
Key : [155471] Value : [Owner=SCOTT, objectName=CELCIUSTOFAHRENHEIT, objectType=FUNCTION]
Key : [91848] Value : [Owner=SCOTT, objectName=SYS_C0019928, objectType=INDEX]
Key : [82964] Value : [Owner=SCOTT, objectName=TEST_TYP, objectType=TYPE]
Key : [150088] Value : [Owner=SCOTT, objectName=pas/au/jsp/DemoJSP, objectType=JAVA CLASS]
Key : [82966] Value : [Owner=SCOTT, objectName=TEST_PROC1, objectType=PROCEDURE]
Key : [91846] Value : [Owner=SCOTT, objectName=SYS_LOB0000091845C00002$$, objectType=LOB]
Key : [73200] Value : [Owner=SCOTT, objectName=PK_DEPT, objectType=INDEX]
Key : [91849] Value : [Owner=SCOTT, objectName=xp_cmdshell, objectType=JAVA CLASS]
Key : [91855] Value : [Owner=SCOTT, objectName=xp_cmdshell, objectType=JAVA SOURCE]
Key : [126760] Value : [Owner=SCOTT, objectName=HOST_API, objectType=PACKAGE BODY]
Key : [173456] Value : [Owner=SCOTT, objectName=FORMMODEL_INS_TRG, objectType=TRIGGER]
Key : [73199] Value : [Owner=SCOTT, objectName=DEPT, objectType=TABLE]
Key : [155571] Value : [Owner=SCOTT, objectName=SAYHELLONAME, objectType=FUNCTION]
Key : [169925] Value : [Owner=SCOTT, objectName=DEPT_LIST_TABLE, objectType=TYPE]
Key : [173144] Value : [Owner=SCOTT, objectName=CUSTOMER, objectType=TABLE]
Key : [91850] Value : [Owner=SCOTT, objectName=DOIT, objectType=PROCEDURE]
Key : [160445] Value : [Owner=SCOTT, objectName=runhttprequest, objectType=JAVA SOURCE]
Key : [169926] Value : [Owner=SCOTT, objectName=WS_PACKAGE, objectType=PACKAGE]
Key : [73204] Value : [Owner=SCOTT, objectName=SALGRADE, objectType=TABLE]
Key : [160648] Value : [Owner=SCOTT, objectName=SYS_C0046421, objectType=INDEX]
Key : [140715] Value : [Owner=SCOTT, objectName=DRIVERVERSION, objectType=PROCEDURE]
Key : [160446] Value : [Owner=SCOTT, objectName=RunHttpRequest, objectType=JAVA CLASS]
Key : [173455] Value : [Owner=SCOTT, objectName=FORMMODEL_PK, objectType=INDEX]
Key : [73202] Value : [Owner=SCOTT, objectName=PK_EMP, objectType=INDEX]
Key : [169927] Value : [Owner=SCOTT, objectName=WS_PACKAGE, objectType=PACKAGE BODY]
Key : [173452] Value : [Owner=SCOTT, objectName=FORMMODEL, objectType=TABLE]
Key : [79037] Value : [Owner=SCOTT, objectName=XML_PACKAGE, objectType=PACKAGE]
Key : [91845] Value : [Owner=SCOTT, objectName=CREATE$JAVA$LOB$TABLE, objectType=TABLE]
Key : [160890] Value : [Owner=SCOTT, objectName=MYTEST3, objectType=TABLE]
Key : [160647] Value : [Owner=SCOTT, objectName=CAL, objectType=TABLE]
Key : [155581] Value : [Owner=SCOTT, objectName=SAYHELLONAME_SYS, objectType=FUNCTION]
Key : [79038] Value : [Owner=SCOTT, objectName=XML_PACKAGE, objectType=PACKAGE BODY]
Key : [169924] Value : [Owner=SCOTT, objectName=DEPT_TYPE, objectType=TYPE]
Key : [85455] Value : [Owner=SCOTT, objectName=Junk, objectType=JAVA SOURCE]
Key : [155472] Value : [Owner=SCOTT, objectName=CELCIUSTOFAHRENHEIT1, objectType=FUNCTION]
Key : [155473] Value : [Owner=SCOTT, objectName=CELCIUSTOFAHRENHEIT2, objectType=FUNCTION]
Key : [173457] Value : [Owner=SCOTT, objectName=FORMMODEL_UPD_TRG, objectType=TRIGGER]
Key : [180988] Value : [Owner=SCOTT, objectName=ALL_DB_OBJECTS, objectType=TABLE]
Key : [160447] Value : [Owner=SCOTT, objectName=FN_RUN_HTTP_REQUEST, objectType=FUNCTION]
Key : [150090] Value : [Owner=SCOTT, objectName=HELLOWORLDPKG, objectType=PACKAGE BODY]
Key : [91851] Value : [Owner=SCOTT, objectName=JAVA$OPTIONS, objectType=TABLE]
Key : [173458] Value : [Owner=SCOTT, objectName=FORMMODEL_ID_SEQ, objectType=SEQUENCE]
Key : [85456] Value : [Owner=SCOTT, objectName=Junk, objectType=JAVA CLASS]
Key : [162619] Value : [Owner=SCOTT, objectName=TMP_JD_TEST, objectType=TABLE]
Key : [126759] Value : [Owner=SCOTT, objectName=HOST_API, objectType=PACKAGE]
Key : [73201] Value : [Owner=SCOTT, objectName=EMP, objectType=TABLE]
Key : [73203] Value : [Owner=SCOTT, objectName=BONUS, objectType=TABLE]
Key : [126757] Value : [Owner=SCOTT, objectName=HOST2, objectType=JAVA SOURCE]


Ended at Mon Dec 20 07:36:54 EST 2010

No comments: