Author: clebert.suconic(a)jboss.com
Date: 2010-05-10 19:11:36 -0400 (Mon, 10 May 2010)
New Revision: 9222
Modified:
trunk/src/main/org/hornetq/jms/client/HornetQDestination.java
trunk/src/main/org/hornetq/jms/client/HornetQSession.java
Log:
https://jira.jboss.org/jira/browse/HORNETQ-384 - Fixing CreateQueueTest
Modified: trunk/src/main/org/hornetq/jms/client/HornetQDestination.java
===================================================================
--- trunk/src/main/org/hornetq/jms/client/HornetQDestination.java 2010-05-10 21:31:57 UTC
(rev 9221)
+++ trunk/src/main/org/hornetq/jms/client/HornetQDestination.java 2010-05-10 23:11:36 UTC
(rev 9222)
@@ -170,21 +170,40 @@
return new HornetQTopic(name);
}
+ public static HornetQTemporaryQueue createTemporaryQueue(final String name, final
HornetQSession session)
+ {
+ return new HornetQTemporaryQueue(JMS_TEMP_QUEUE_ADDRESS_PREFIX.concat(name), name,
session);
+ }
+
+ public static HornetQTemporaryQueue createTemporaryQueue(final String name)
+ {
+ return createTemporaryQueue(name, null);
+ }
+
public static HornetQTemporaryQueue createTemporaryQueue(final HornetQSession
session)
{
String name = UUID.randomUUID().toString();
- return new HornetQTemporaryQueue(JMS_TEMP_QUEUE_ADDRESS_PREFIX.concat(name), name,
session);
+ return createTemporaryQueue(name, session);
}
public static HornetQTemporaryTopic createTemporaryTopic(final HornetQSession
session)
{
String name = UUID.randomUUID().toString();
+ return createTemporaryTopic(name, session);
+ }
+
+ public static HornetQTemporaryTopic createTemporaryTopic(String name, final
HornetQSession session)
+ {
return new HornetQTemporaryTopic(JMS_TEMP_TOPIC_ADDRESS_PREFIX.concat(name), name,
session);
}
-
+ public static HornetQTemporaryTopic createTemporaryTopic(String name)
+ {
+ return createTemporaryTopic(name, null);
+ }
+
// Attributes ----------------------------------------------------
/**
Modified: trunk/src/main/org/hornetq/jms/client/HornetQSession.java
===================================================================
--- trunk/src/main/org/hornetq/jms/client/HornetQSession.java 2010-05-10 21:31:57 UTC (rev
9221)
+++ trunk/src/main/org/hornetq/jms/client/HornetQSession.java 2010-05-10 23:11:36 UTC (rev
9222)
@@ -385,13 +385,16 @@
throw new IllegalStateException("Cannot create a queue using a
TopicSession");
}
- HornetQQueue queue = HornetQDestination.createQueue(queueName);
-
try
{
- QueueQuery response = session.queueQuery(queue.getSimpleAddress());
+ HornetQQueue queue = lookupQueue(queueName, false);
+
+ if (queue == null)
+ {
+ queue = lookupQueue(queueName, true);
+ }
- if (!response.isExists())
+ if (queue == null)
{
throw new JMSException("There is no queue with name " +
queueName);
}
@@ -405,6 +408,7 @@
throw JMSExceptionHelper.convertFromHornetQException(e);
}
}
+
public Topic createTopic(final String topicName) throws JMSException
{
@@ -414,14 +418,18 @@
throw new IllegalStateException("Cannot create a topic on a
QueueSession");
}
- HornetQTopic topic = HornetQDestination.createTopic(topicName);
try
{
- BindingQuery query = session.bindingQuery(topic.getSimpleAddress());
+ HornetQTopic topic = lookupTopic(topicName, false);
- if (!query.isExists())
+ if (topic == null)
{
+ topic = lookupTopic(topicName, true);
+ }
+
+ if (topic == null)
+ {
throw new JMSException("There is no topic with name " +
topicName);
}
else
@@ -994,7 +1002,59 @@
throw new IllegalStateException("Session is closed");
}
}
+
+ private HornetQQueue lookupQueue(final String queueName, boolean isTemporary) throws
HornetQException
+ {
+ HornetQQueue queue;
+
+ if (isTemporary)
+ {
+ queue = HornetQDestination.createTemporaryQueue(queueName);
+ }
+ else
+ {
+ queue = HornetQDestination.createQueue(queueName);
+ }
+
+ QueueQuery response = session.queueQuery(queue.getSimpleAddress());
+ if (response.isExists())
+ {
+ return queue;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ private HornetQTopic lookupTopic(final String topicName, final boolean isTemporary)
throws HornetQException
+ {
+
+ HornetQTopic topic;
+
+ if (isTemporary)
+ {
+ topic = HornetQDestination.createTemporaryTopic(topicName);
+ }
+ else
+ {
+ topic = HornetQDestination.createTopic(topicName);
+ }
+
+ BindingQuery query = session.bindingQuery(topic.getSimpleAddress());
+
+ if (!query.isExists())
+ {
+ return null;
+ }
+ else
+ {
+ return topic;
+ }
+ }
+
+
// Inner classes -------------------------------------------------
}