1 21 22 package org.opensubsystems.blog.persist.db.mysql; 23 24 import java.sql.Connection ; 25 import java.sql.SQLException ; 26 import java.sql.Statement ; 27 import java.util.logging.Level ; 28 import java.util.logging.Logger ; 29 30 import org.opensubsystems.blog.persist.db.BlogDatabaseSchema; 31 import org.opensubsystems.core.error.OSSException; 32 import org.opensubsystems.core.persist.db.DatabaseImpl; 33 import org.opensubsystems.core.util.DatabaseUtils; 34 import org.opensubsystems.core.util.Log; 35 36 45 public class MySQLBlogDatabaseSchema extends BlogDatabaseSchema 46 { 47 93 94 96 99 private static Logger s_logger = Log.getInstance(MySQLBlogDatabaseSchema.class); 100 101 103 108 public MySQLBlogDatabaseSchema( 109 ) throws OSSException 110 { 111 super(); 112 } 113 114 116 119 public void create( 120 Connection cntDBConnection, 121 String strUserName 122 ) throws SQLException 123 { 124 Statement stmQuery = null; 125 try 126 { 127 stmQuery = cntDBConnection.createStatement(); 128 if (stmQuery.execute( 129 "create table BF_BLOG" + NL + 130 "(" + NL + 131 " ID INTEGER NOT NULL AUTO_INCREMENT," + NL + 132 " DOMAIN_ID INTEGER NOT NULL," + NL + 133 " FOLDER VARCHAR(50) NOT NULL," + NL + 134 " CAPTION TEXT NOT NULL," + NL + 135 " COMMENTS TEXT NOT NULL," + NL + 136 " CREATION_DATE TIMESTAMP NOT NULL," + NL + 137 " MODIFICATION_DATE TIMESTAMP NOT NULL," + NL + 138 " CONSTRAINT BF_BLOG_PK PRIMARY KEY (ID)," + NL + 139 " CONSTRAINT BF_BLOG_FLDR_UQ UNIQUE (FOLDER)" + NL + 140 ") TYPE=INNODB")) 144 { 145 stmQuery.getMoreResults(Statement.CLOSE_ALL_RESULTS); 147 } 148 s_logger.log(Level.FINEST, "Table BF_BLOG created."); 149 158 159 161 if (stmQuery.execute( 162 "create table BF_BLOG_ENTRY" + NL + 163 "(" + NL + 164 " ID INTEGER NOT NULL AUTO_INCREMENT," + NL + 165 " DOMAIN_ID INTEGER NOT NULL," + NL + 166 " BLOG_ID INTEGER NOT NULL," + NL + 167 " CAPTION TEXT NOT NULL," + NL + 168 " COMMENTS TEXT NOT NULL," + NL + 169 " IMAGEURL TEXT NOT NULL," + NL + 170 " TARGETURL TEXT NOT NULL," + NL + 171 " CREATION_DATE TIMESTAMP NOT NULL," + NL + 172 " MODIFICATION_DATE TIMESTAMP NOT NULL," + NL + 173 " CONSTRAINT BF_BLOGENTR_PK PRIMARY KEY (ID)," + NL + 174 " INDEX IND_BLGENTR_BLG_ID (BLOG_ID)," + NL + 176 " CONSTRAINT BF_BLOGENTR_FK FOREIGN KEY (BLOG_ID)" + NL + 177 " REFERENCES BF_BLOG (ID) ON DELETE CASCADE" + NL + 178 ") TYPE=INNODB")) 181 { 182 stmQuery.getMoreResults(Statement.CLOSE_ALL_RESULTS); 184 } 185 s_logger.log(Level.FINEST, "Table BF_BLOG_ENTRY created."); 186 195 } 196 catch (SQLException sqleExc) 197 { 198 s_logger.log(Level.WARNING, 199 "Failed to create schema " + BLOG_SCHEMA_NAME, sqleExc); 200 throw sqleExc; 201 } 202 finally 203 { 204 DatabaseUtils.closeStatement(stmQuery); 205 } 206 } 207 208 211 public String getInsertBlogAndFetchGeneratedValues( 212 ) throws OSSException 213 { 214 return getInsertBlog(); 215 } 216 217 220 public String getUpdateBlogAndFetchGeneratedValues( 221 ) throws OSSException 222 { 223 StringBuffer buffer = new StringBuffer (); 224 225 buffer.append("update BF_BLOG set FOLDER = ?, CAPTION = ?, COMMENTS = ?," + 226 " MODIFICATION_DATE = "); 227 buffer.append(DatabaseImpl.getInstance().getCurrentTimestampFunctionCall()); 228 buffer.append(" where ID = ? and DOMAIN_ID = ? and MODIFICATION_DATE = ?"); 229 230 return buffer.toString(); 231 } 232 233 236 public String getInsertBlog( 237 ) throws OSSException 238 { 239 StringBuffer buffer = new StringBuffer (); 240 241 buffer.append("INSERT INTO BF_BLOG("); 243 buffer.append(BLOG_COLUMNS); 244 buffer.append(") VALUES (null, ?, ?, ?, ?, "); 245 buffer.append(DatabaseImpl.getInstance().getCurrentTimestampFunctionCall()); 246 buffer.append(","); 247 buffer.append(DatabaseImpl.getInstance().getCurrentTimestampFunctionCall()); 248 buffer.append(")"); 249 250 return buffer.toString(); 251 } 252 253 256 public String getInsertEntry( 257 ) throws OSSException 258 { 259 StringBuffer buffer = new StringBuffer (); 260 261 buffer.append("INSERT INTO BF_BLOG_ENTRY("); 263 buffer.append(ENTRY_COLUMNS); 264 buffer.append(") VALUES (null, ?, ?, ?, ?, ?, ?, "); 265 buffer.append(DatabaseImpl.getInstance().getCurrentTimestampFunctionCall()); 266 buffer.append(","); 267 buffer.append(DatabaseImpl.getInstance().getCurrentTimestampFunctionCall()); 268 buffer.append(")"); 269 270 return buffer.toString(); 271 } 272 273 276 public String getInsertEntryAndFetchGeneratedValues( 277 ) throws OSSException 278 { 279 return getInsertEntry(); 280 } 281 282 285 public String getUpdateEntryAndFetchGeneratedValues( 286 ) throws OSSException 287 { 288 StringBuffer buffer = new StringBuffer (); 289 290 buffer.append("update BF_BLOG_ENTRY set CAPTION = ?, COMMENTS = ?," + 291 " IMAGEURL = ?, TARGETURL = ?, MODIFICATION_DATE = "); 292 buffer.append(DatabaseImpl.getInstance().getCurrentTimestampFunctionCall()); 293 buffer.append(" where ID = ? and DOMAIN_ID = ? and MODIFICATION_DATE = ?"); 294 295 return buffer.toString(); 296 } 297 } 298 | Popular Tags |