connect "DSN=dbxla"; Connection successful: DSN=dbxla;UID=oracle;DataStore=/u01/app/oracle/datastore/dbxla;DatabaseCharacterSet=WE8MSWIN1252;ConnectionCharacterSet=US7ASCII;DRIVER=/u01/app/oracle/product/11.2.1/TimesTen/tt1/lib/libtten.so;PermSize=32;TempSize=50;TypeMode=0;PLSQL=0;CacheGridEnable=0; (Default setting AutoCommit=1) Command> CREATE USER oratt IDENTIFIED BY oracle; User created. Command> grant create session, create table, XLA to oratt; Command> connect "DSN=dbxla;UID=oratt;PWD=oracle;"; Connection successful: DSN=dbxla;UID=oratt;DataStore=/u01/app/oracle/datastore/dbxla;DatabaseCharacterSet=WE8MSWIN1252;ConnectionCharacterSet=US7ASCII;DRIVER=/u01/app/oracle/product/11.2.1/TimesTen/tt1/lib/libtten.so;PermSize=32;TempSize=50;TypeMode=0;PLSQL=0;CacheGridEnable=0; (Default setting AutoCommit=1) con1: Command> create table xlatest ( id NUMBER NOT NULL PRIMARY KEY, > name VARCHAR2(100) ); con1: Command>
<xlaconfig> <topics> <!-- topic for Xla demo --> <topic name="xlademo" connectionString="DSN=dbxla" xlaPrefetch="100" /> </topics> </xlaconfig>
connection.start(); Topic topic = session.createTopic(topicName); TopicSubscriber subscriber = session.createDurableSubscriber(topic, bookmark); .. MapMessage message = (MapMessage)subscriber.receive(); ...
public class DemoXLA { private TopicConnectionFactory connectionFactory; private TopicConnection connection; private TopicSession session; private Topic topic; private TopicSubscriber subscriber; public DemoXLA( String cf, String topicName, String selector) throws JMSException, NamingException {String key; Context messaging = getInitialContext(); // getting the context connectionFactory = (TopicConnectionFactory)messaging.lookup(cf); connection = connectionFactory.createTopicConnection(); connection.start(); session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topic = session.createTopic(topicName); subscriber = session.createDurableSubscriber(topic, selector); int i=0; while (i<10) { MapMessage message = (MapMessage)subscriber.receive(); Enumeration e = message.getMapNames(); while (e.hasMoreElements()) { key = (String)e.nextElement(); System.out.println("[ " + key + " = " + message.getObject(key) + " ]"); } System.out.println("----------------------------------------"); } session.unsubscribe(selector); subscriber.close(); session.close(); connection.stop(); } private Context getInitialContext() throws NamingException { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.timesten.dataserver.jmsxla.SimpleInitialContextFactory"); InitialContext initialContext = new InitialContext(env); return initialContext; } public static void main(String[] args) throws JMSException, NamingException { DemoXLA demo = new DemoXLA("TopicConnectionFactory", "Level2Demo", "bookmark"); } }
public class MyListener implements MessageListener { public MyListener() {} public void onMessage(Message message) { MapMessage mp = (MapMessage)message; Enumeration e; try { e = mp.getMapNames(); } catch (JMSException s) { e = null; System.out.println("error 1"); } while (e.hasMoreElements()) { String key = (String)e.nextElement(); try { System.out.println("[ " + key + " = " + mp.getObject(key) + " ]"); } catch (JMSException f) { System.out.println("error 2"); } } System.out.println("----------------------------------------"); } }
public class DemoXLA2 { private javax.jms.TopicConnectionFactory connectionFactory; private javax.jms.TopicConnection connection; private TopicSession session; private Topic topic; private TopicSubscriber subscriber; public DemoXLA2( String cf, String topicName, String selector) throws JMSException, NamingException, InterruptedException { Context messaging = getInitialContext(); Object connectionFactoryObject = messaging.lookup(cf); connectionFactory = (TopicConnectionFactory)connectionFactoryObject; connection = connectionFactory.createTopicConnection(); MyListener myListener = new MyListener(); session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topic = session.createTopic(topicName); subscriber = session.createDurableSubscriber(topic, selector); subscriber.setMessageListener(myListener); connection.start(); Thread.sleep(60000); session.unsubscribe(selector); subscriber.close(); session.close(); connection.stop(); } private Context getInitialContext() throws NamingException { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.timesten.dataserver.jmsxla.SimpleInitialContextFactory"); InitialContext initialContext = new InitialContext(env); return initialContext; } public static void main(String[] args) throws JMSException, NamingException, InterruptedException { DemoXLA2 demo = new DemoXLA2("TopicConnectionFactory", "xlademo", "bookmark"); } }
Command> insert into xlatest values (2, 'w'); 1 row inserted. Command> update xlatest set name = 'test' where id=2; 1 row updated. Command> delete from xlatest; 1 row deleted. Command>
[ __TYPE = 10 ] [ __COMMIT = true ] [ __FIRST = true ] [ __NULLS = ] [ __TBLNAME = XLATEST ] [ __TBLOWNER = ORATT ] [ __mver = 5621355056449191939 ] [ __mtyp = null ] [ ID = 2 ] [ NAME = w ] ---------------------------------------- [ __TYPE = 11 ] [ __COMMIT = true ] [ __FIRST = true ] [ __UPDCOLS = NAME ] [ __NULLS = ] [ __TBLNAME = XLATEST ] [ __TBLOWNER = ORATT ] [ __mver = 5621355056449191942 ] [ __mtyp = null ] [ _ID = 2 ] [ ID = 2 ] [ _NAME = w ] [ NAME = test ] ---------------------------------------- [ __TYPE = 12 ] [ __COMMIT = true ] [ __FIRST = true ] [ __NULLS = ] [ __TBLNAME = XLATEST ] [ __TBLOWNER = ORATT ] [ __mver = 5621355056449191945 ] [ __mtyp = D ] [ ID = 2 ] [ NAME = test ] ----------------------------------------
Source: https://habr.com/ru/post/123442/
All Articles