activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r365954 - in /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc: ./ adapter/
Date Wed, 04 Jan 2006 17:40:45 GMT
Author: chirino
Date: Wed Jan  4 09:40:32 2006
New Revision: 365954

URL: http://svn.apache.org/viewcvs?rev=365954&view=rev
Log:
Use the jdbc catalog to avoid displaying warning messages on startup when the activemq tables
allready exist.

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/StatementProvider.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/AxionJDBCAdapter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/CachingStatementProvider.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultJDBCAdapter.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultStatementProvider.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/StatementProvider.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/StatementProvider.java?rev=365954&r1=365953&r2=365954&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/StatementProvider.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/StatementProvider.java
Wed Jan  4 09:40:32 2006
@@ -46,4 +46,6 @@
     public void setUseExternalMessageReferences(boolean useExternalMessageReferences);
     public boolean isUseExternalMessageReferences();
 
+    public String getFullMessageTableName();
+
 }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/AxionJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/AxionJDBCAdapter.java?rev=365954&r1=365953&r2=365954&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/AxionJDBCAdapter.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/AxionJDBCAdapter.java
Wed Jan  4 09:40:32 2006
@@ -33,7 +33,7 @@
         DefaultStatementProvider answer = new DefaultStatementProvider() {
             public String [] getCreateSchemaStatments() {
                 return new String[]{
-                    "CREATE TABLE "+tablePrefix+messageTableName+"("
+                    "CREATE TABLE "+getTablePrefix()+messageTableName+"("
                            +"ID "+sequenceDataType+" NOT NULL"
                            +", CONTAINER "+containerNameDataType
                            +", MSGID_PROD "+msgIdDataType
@@ -41,9 +41,9 @@
                            +", EXPIRATION "+longDataType
                            +", MSG "+(useExternalMessageReferences ? stringIdDataType : binaryDataType)
                            +", PRIMARY KEY ( ID ) )",                          
-                     "CREATE INDEX "+tablePrefix+messageTableName+"_MIDX ON "+tablePrefix+messageTableName+"
(MSGID_PROD,MSGID_SEQ)",
-                     "CREATE INDEX "+tablePrefix+messageTableName+"_CIDX ON "+tablePrefix+messageTableName+"
(CONTAINER)",                                       
-                     "CREATE TABLE "+tablePrefix+durableSubAcksTableName+"("
+                     "CREATE INDEX "+getTablePrefix()+messageTableName+"_MIDX ON "+getTablePrefix()+messageTableName+"
(MSGID_PROD,MSGID_SEQ)",
+                     "CREATE INDEX "+getTablePrefix()+messageTableName+"_CIDX ON "+getTablePrefix()+messageTableName+"
(CONTAINER)",                                       
+                     "CREATE TABLE "+getTablePrefix()+durableSubAcksTableName+"("
                            +"CONTAINER "+containerNameDataType+" NOT NULL"
                            +", CLIENT_ID "+stringIdDataType+" NOT NULL"
                            +", SUB_NAME "+stringIdDataType+" NOT NULL"
@@ -55,7 +55,7 @@
             }
             
             public String getDeleteOldMessagesStatment() {
-                return "DELETE FROM "+tablePrefix+messageTableName+
+                return "DELETE FROM "+getTablePrefix()+messageTableName+
                     " WHERE ( EXPIRATION<>0 AND EXPIRATION<?)";
             }
 

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/CachingStatementProvider.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/CachingStatementProvider.java?rev=365954&r1=365953&r2=365954&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/CachingStatementProvider.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/CachingStatementProvider.java
Wed Jan  4 09:40:32 2006
@@ -218,4 +218,8 @@
     public boolean isUseExternalMessageReferences() {
         return statementProvider.isUseExternalMessageReferences();
     }
+
+    public String getFullMessageTableName() {
+        return statementProvider.getFullMessageTableName();
+    }
 }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultJDBCAdapter.java?rev=365954&r1=365953&r2=365954&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultJDBCAdapter.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultJDBCAdapter.java
Wed Jan  4 09:40:32 2006
@@ -81,7 +81,19 @@
     public void doCreateTables(TransactionContext c) throws SQLException, IOException {
         Statement s = null;
         try {
-            log.info("creating tables");
+            
+            // Check to see if the table already exists.  If it does, then don't log warnings
during startup.
+            // Need to run the scripts anyways since they may contain ALTER statements that
upgrade a previous version of the table
+            boolean alreadyExists = false;
+            ResultSet rs=null;
+            try {
+                rs= c.getConnection().getMetaData().getTables(null,null, statementProvider.getFullMessageTableName(),
new String[] {"TABLE"});
+                alreadyExists = rs.next();                
+            } catch (Throwable ignore) {
+            } finally {
+                close(rs);
+            }
+            
             s = c.getConnection().createStatement();
             String[] createStatments = statementProvider.getCreateSchemaStatments();
             for (int i = 0; i < createStatments.length; i++) {
@@ -91,13 +103,19 @@
                     boolean rc = s.execute(createStatments[i]);
                 }
                 catch (SQLException e) {
-                    log.warn("Could not create JDBC tables; they could already exist." +
-                        " Failure was: " + createStatments[i] + " Message: " + e.getMessage()
+
-                        " SQLState: " + e.getSQLState() + " Vendor code: " + e.getErrorCode()
);
+                    if( alreadyExists )  {
+                        log.debug("Could not create JDBC tables; The message table already
existed." +
+                                " Failure was: " + createStatments[i] + " Message: " + e.getMessage()
+
+                                " SQLState: " + e.getSQLState() + " Vendor code: " + e.getErrorCode()
);
+                    } else {
+                        log.warn("Could not create JDBC tables; they could already exist."
+
+                            " Failure was: " + createStatments[i] + " Message: " + e.getMessage()
+
+                            " SQLState: " + e.getSQLState() + " Vendor code: " + e.getErrorCode()
);
+                    }
                 }
             }
             c.getConnection().commit();
-            log.info("done creating tables");
+            
         }
         finally {
             try {

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultStatementProvider.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultStatementProvider.java?rev=365954&r1=365953&r2=365954&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultStatementProvider.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/adapter/DefaultStatementProvider.java
Wed Jan  4 09:40:32 2006
@@ -24,7 +24,7 @@
  */
 public class DefaultStatementProvider implements StatementProvider {
 
-    protected String tablePrefix = "";
+    private   String tablePrefix = "";
     protected String messageTableName = "ACTIVEMQ_MSGS";
     protected String durableSubAcksTableName = "ACTIVEMQ_ACKS";
 
@@ -41,7 +41,7 @@
     
     public String [] getCreateSchemaStatments() {
         return new String[]{
-            "CREATE TABLE "+tablePrefix+messageTableName+"("
+            "CREATE TABLE "+getFullMessageTableName()+"("
             			   +"ID "+sequenceDataType+" NOT NULL"
             			   +", CONTAINER "+containerNameDataType
             			   +", MSGID_PROD "+msgIdDataType
@@ -49,9 +49,9 @@
                         +", EXPIRATION "+longDataType
             			   +", MSG "+(useExternalMessageReferences ? stringIdDataType : binaryDataType)
             			   +", PRIMARY KEY ( ID ) )",						   
-            "CREATE INDEX "+tablePrefix+messageTableName+"_MIDX ON "+tablePrefix+messageTableName+"
(MSGID_PROD,MSGID_SEQ)",
-            "CREATE INDEX "+tablePrefix+messageTableName+"_CIDX ON "+tablePrefix+messageTableName+"
(CONTAINER)",			
-            "CREATE TABLE "+tablePrefix+durableSubAcksTableName+"("
+            "CREATE INDEX "+getFullMessageTableName()+"_MIDX ON "+getFullMessageTableName()+"
(MSGID_PROD,MSGID_SEQ)",
+            "CREATE INDEX "+getFullMessageTableName()+"_CIDX ON "+getFullMessageTableName()+"
(CONTAINER)",			
+            "CREATE TABLE "+getTablePrefix()+durableSubAcksTableName+"("
                         +"CONTAINER "+containerNameDataType+" NOT NULL"
                         +", CLIENT_ID "+stringIdDataType+" NOT NULL"
                         +", SUB_NAME "+stringIdDataType+" NOT NULL"
@@ -61,88 +61,92 @@
         };
     }
 
+    public String getFullMessageTableName() {
+        return getTablePrefix()+messageTableName;
+    }
+    
     public String [] getDropSchemaStatments() {
         return new String[]{
-            "DROP TABLE "+tablePrefix+durableSubAcksTableName+"",
-            "DROP TABLE "+tablePrefix+messageTableName+"",
+            "DROP TABLE "+getTablePrefix()+durableSubAcksTableName+"",
+            "DROP TABLE "+getFullMessageTableName()+"",
         };
     }
 
     public String getAddMessageStatment() {
-        return "INSERT INTO "+tablePrefix+messageTableName+"(ID, MSGID_PROD, MSGID_SEQ, CONTAINER,
EXPIRATION, MSG) VALUES (?, ?, ?, ?, ?, ?)";
+        return "INSERT INTO "+getFullMessageTableName()+"(ID, MSGID_PROD, MSGID_SEQ, CONTAINER,
EXPIRATION, MSG) VALUES (?, ?, ?, ?, ?, ?)";
     }
     public String getUpdateMessageStatment() {
-        return "UPDATE "+tablePrefix+messageTableName+" SET MSG=? WHERE ID=?";
+        return "UPDATE "+getFullMessageTableName()+" SET MSG=? WHERE ID=?";
     }
     public String getRemoveMessageStatment() {
-        return "DELETE FROM "+tablePrefix+messageTableName+" WHERE ID=?";
+        return "DELETE FROM "+getFullMessageTableName()+" WHERE ID=?";
     }
     public String getFindMessageSequenceIdStatment() {
-        return "SELECT ID FROM "+tablePrefix+messageTableName+" WHERE MSGID_PROD=? AND MSGID_SEQ=?";
+        return "SELECT ID FROM "+getFullMessageTableName()+" WHERE MSGID_PROD=? AND MSGID_SEQ=?";
     }
     public String getFindMessageStatment() {
-        return "SELECT MSG FROM "+tablePrefix+messageTableName+" WHERE ID=?";
+        return "SELECT MSG FROM "+getFullMessageTableName()+" WHERE ID=?";
     }
     public String getFindAllMessagesStatment() {
-        return "SELECT ID, MSG FROM "+tablePrefix+messageTableName+" WHERE CONTAINER=? ORDER
BY ID";
+        return "SELECT ID, MSG FROM "+getFullMessageTableName()+" WHERE CONTAINER=? ORDER
BY ID";
     }
     public String getFindLastSequenceIdInMsgs() {
-        return "SELECT MAX(ID) FROM "+tablePrefix+messageTableName;
+        return "SELECT MAX(ID) FROM "+getFullMessageTableName();
     }
     public String getFindLastSequenceIdInAcks() {
-        return "SELECT MAX(LAST_ACKED_ID) FROM "+tablePrefix+durableSubAcksTableName;
+        return "SELECT MAX(LAST_ACKED_ID) FROM "+getTablePrefix()+durableSubAcksTableName;
     }
 
     public String getCreateDurableSubStatment() {
-        return "INSERT INTO "+tablePrefix+durableSubAcksTableName
+        return "INSERT INTO "+getTablePrefix()+durableSubAcksTableName
         	   +"(CONTAINER, CLIENT_ID, SUB_NAME, SELECTOR, LAST_ACKED_ID) "
          	   +"VALUES (?, ?, ?, ?, ?)";
     }
 
     public String getFindDurableSubStatment() {
         return "SELECT SELECTOR, SUB_NAME " +
-                "FROM "+tablePrefix+durableSubAcksTableName+
+                "FROM "+getTablePrefix()+durableSubAcksTableName+
                 " WHERE CONTAINER=? AND CLIENT_ID=? AND SUB_NAME=?";
     }
 
     public String getUpdateLastAckOfDurableSub() {
-        return "UPDATE "+tablePrefix+durableSubAcksTableName+
+        return "UPDATE "+getTablePrefix()+durableSubAcksTableName+
                 " SET LAST_ACKED_ID=?" +
                 " WHERE CONTAINER=? AND CLIENT_ID=? AND SUB_NAME=?";
     }
 
     public String getDeleteSubscriptionStatment() {
-        return "DELETE FROM "+tablePrefix+durableSubAcksTableName+
+        return "DELETE FROM "+getTablePrefix()+durableSubAcksTableName+
                 " WHERE CONTAINER=? AND CLIENT_ID=? AND SUB_NAME=?";
     }
 
     public String getFindAllDurableSubMessagesStatment() {
         return "SELECT M.ID, M.MSG FROM "
-		        +tablePrefix+messageTableName+" M, "
-			    +tablePrefix+durableSubAcksTableName +" D "
+		        +getFullMessageTableName()+" M, "
+			    +getTablePrefix()+durableSubAcksTableName +" D "
 		        +" WHERE D.CONTAINER=? AND D.CLIENT_ID=? AND D.SUB_NAME=?" 
 				+" AND M.CONTAINER=D.CONTAINER AND M.ID > D.LAST_ACKED_ID"
 				+" ORDER BY M.ID";
     }
 
     public String getFindAllDestinationsStatment() {
-        return "SELECT DISTINCT CONTAINER FROM "+tablePrefix+messageTableName;
+        return "SELECT DISTINCT CONTAINER FROM "+getFullMessageTableName();
     }
     
     public String getRemoveAllMessagesStatment() {
-        return "DELETE FROM "+tablePrefix+messageTableName+" WHERE CONTAINER=?";
+        return "DELETE FROM "+getFullMessageTableName()+" WHERE CONTAINER=?";
     }
 
     public String getRemoveAllSubscriptionsStatment() {
-        return "DELETE FROM "+tablePrefix+durableSubAcksTableName+" WHERE CONTAINER=?";
+        return "DELETE FROM "+getTablePrefix()+durableSubAcksTableName+" WHERE CONTAINER=?";
     }
 
     public String getDeleteOldMessagesStatment() {
-        return "DELETE FROM "+tablePrefix+messageTableName+
+        return "DELETE FROM "+getFullMessageTableName()+
             " WHERE ( EXPIRATION<>0 AND EXPIRATION<?) OR ID <= " +
-            "( SELECT min("+tablePrefix+durableSubAcksTableName+".LAST_ACKED_ID) " +
-                "FROM "+tablePrefix+durableSubAcksTableName+" WHERE " +
-                tablePrefix+durableSubAcksTableName+".CONTAINER="+tablePrefix+messageTableName+
+            "( SELECT min("+getTablePrefix()+durableSubAcksTableName+".LAST_ACKED_ID) " +
+                "FROM "+getTablePrefix()+durableSubAcksTableName+" WHERE " +
+                getTablePrefix()+durableSubAcksTableName+".CONTAINER="+getFullMessageTableName()+
                 ".CONTAINER)";
     }
     
@@ -267,5 +271,6 @@
     public boolean isUseExternalMessageReferences() {
         return useExternalMessageReferences;
     }
+
 
 }



Mime
View raw message