You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2013/08/14 09:03:21 UTC

svn commit: r1513742 - in /openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli: Admin.java ConnectionProperties.java ConnectionPropertiesPatcher.java

Author: solomax
Date: Wed Aug 14 07:03:21 2013
New Revision: 1513742

URL: http://svn.apache.org/r1513742
Log:
[OPENMEETINGS-763] drop seems to be fixed

Modified:
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/Admin.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/ConnectionProperties.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/ConnectionPropertiesPatcher.java

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/Admin.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/Admin.java?rev=1513742&r1=1513741&r2=1513742&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/Admin.java (original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/Admin.java Wed Aug 14 07:03:21 2013
@@ -40,7 +40,11 @@ import org.apache.commons.cli.ParseExcep
 import org.apache.commons.cli.Parser;
 import org.apache.commons.cli.PosixParser;
 import org.apache.commons.transaction.util.FileHelper;
-import org.apache.openjpa.jdbc.meta.MappingTool;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;
+import org.apache.openjpa.jdbc.schema.SchemaTool;
+import org.apache.openjpa.lib.log.Log;
+import org.apache.openjpa.lib.log.LogFactoryImpl.LogImpl;
 import org.apache.openmeetings.data.basic.dao.ConfigurationDao;
 import org.apache.openmeetings.data.file.dao.FileExplorerItemDao;
 import org.apache.openmeetings.data.flvrecord.FlvRecordingDao;
@@ -244,7 +248,7 @@ public class Admin {
 					if (!conf.exists() || cmdl.hasOption("db-type") || cmdl.hasOption("db-host") || cmdl.hasOption("db-port") || cmdl.hasOption("db-name") || cmdl.hasOption("db-user") || cmdl.hasOption("db-pass")) {
 						String dbType = cmdl.getOptionValue("db-type", "derby");
 						File srcConf = new File(OmFileHelper.getWebinfDir(), "classes/META-INF/" + dbType + "_persistence.xml");
-						ConnectionPropertiesPatcher.getPatcher(dbType).patch(
+						ConnectionPropertiesPatcher.getPatcher(dbType, connectionProperties).patch(
 								srcConf
 								, conf
 								, cmdl.getOptionValue("db-host", "localhost")
@@ -252,7 +256,6 @@ public class Admin {
 								, cmdl.getOptionValue("db-name", null)
 								, cmdl.getOptionValue("db-user", null)
 								, cmdl.getOptionValue("db-pass", null)
-								, connectionProperties
 								);
 					} else {
 						//get properties from existent persistence.xml
@@ -578,18 +581,31 @@ public class Admin {
 		}
 	}
 	
+	private static LogImpl getLogImpl(JDBCConfiguration conf) {
+		return (LogImpl)conf.getLog(JDBCConfiguration.LOG_SCHEMA);
+	}
+
 	private static void immediateDropDB(ConnectionProperties props) throws Exception {
-		String[] args = {
-				"-schemaAction", "retain,drop"
-				, "-properties", new File(OmFileHelper.getWebinfDir(), PERSISTENCE_NAME).getCanonicalPath()
-				, "-connectionDriverName", props.getDriver()
-				, "-connectionURL", props.getURL()
-				, "-connectionUserName", props.getLogin()
-				, "-connectionPassword", props.getPassword()
-				, "-ignoreErrors", "true"};
-		MappingTool.main(args);
+    	JDBCConfigurationImpl conf = new JDBCConfigurationImpl();
+        try {
+        	conf.setPropertiesFile(new File(OmFileHelper.getWebinfDir(), PERSISTENCE_NAME));
+        	conf.setConnectionDriverName(props.getDriver());
+        	conf.setConnectionURL(props.getURL());
+        	conf.setConnectionUserName(props.getLogin());
+        	conf.setConnectionPassword(props.getPassword());
+    		//HACK to suppress all warnings
+    		getLogImpl(conf).setLevel(Log.INFO);
+    		SchemaTool st = new SchemaTool(conf, SchemaTool.ACTION_DROPDB);
+    		st.setIgnoreErrors(true);
+    		st.setOpenJPATables(true);
+    		st.setIndexes(false);
+    		st.setPrimaryKeys(false);
+    		st.run();
+        } finally {
+            conf.close();
+        }
 	}
-	
+
 	private File checkRestoreFile(String file) {
 		File backup = new File(file);
 		if (!cmdl.hasOption("file") || !backup.exists() || !backup.isFile()) {

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/ConnectionProperties.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/ConnectionProperties.java?rev=1513742&r1=1513741&r2=1513742&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/ConnectionProperties.java (original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/ConnectionProperties.java Wed Aug 14 07:03:21 2013
@@ -19,11 +19,19 @@
 package org.apache.openmeetings.cli;
 
 public class ConnectionProperties {
+	public enum DbType {
+		db2
+		, derby
+		, mysql
+		, oracle
+		, postgresql
+	}
 
 	private String driver = "org.apache.derby.jdbc.ClientDriver";
 	private String url = "jdbc:derby:openmeetings";
 	private String login = "user";
 	private String password = "secret";
+	private DbType dbType = DbType.derby;
 
 	public String getDriver() {
 		return driver;
@@ -57,9 +65,17 @@ public class ConnectionProperties {
 		this.password = connectionPass;
 	}
 
+	public DbType getDbType() {
+		return dbType;
+	}
+
+	public void setDbType(DbType dbType) {
+		this.dbType = dbType;
+	}
+	
 	@Override
 	public String toString() {
-		return "ConnectionProperties [driver=" + driver + ", url=" + url
+		return "ConnectionProperties [type=" + dbType + ", driver=" + driver + ", url=" + url
 				+ ", login=" + login + ", password=" + password + "]";
 	}
 }

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/ConnectionPropertiesPatcher.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/ConnectionPropertiesPatcher.java?rev=1513742&r1=1513741&r2=1513742&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/ConnectionPropertiesPatcher.java (original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/cli/ConnectionPropertiesPatcher.java Wed Aug 14 07:03:21 2013
@@ -33,6 +33,7 @@ import javax.xml.xpath.XPathFactory;
 
 import org.apache.commons.lang3.StringEscapeUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.openmeetings.cli.ConnectionProperties.DbType;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -41,16 +42,8 @@ public abstract class ConnectionProperti
 	protected static final String URL_PREFIX = "Url=";
 	protected ConnectionProperties connectionProperties;
 	
-	public enum PatcherType {
-		db2
-		, derby
-		, mysql
-		, oracle
-		, postgres
-	}
-	
-	static ConnectionPropertiesPatcher getPatcher(String _dbType) {
-		PatcherType dbType = PatcherType.valueOf(_dbType);
+	static ConnectionPropertiesPatcher getPatcher(String _dbType, ConnectionProperties connectionProperties) {
+		DbType dbType = DbType.valueOf(_dbType);
 		ConnectionPropertiesPatcher patcher = null;
 		switch (dbType) {
 			case db2:
@@ -62,7 +55,7 @@ public abstract class ConnectionProperti
 			case oracle:
 				patcher = new OraclePatcher();
 				break;
-			case postgres:
+			case postgresql:
 				patcher = new PostgresPatcher();
 				break;
 			case derby:
@@ -70,6 +63,7 @@ public abstract class ConnectionProperti
 				patcher = new DerbyPatcher();
 				break;
 		}
+		patcher.connectionProperties = connectionProperties;
 		return patcher;
 	}
 	
@@ -98,8 +92,7 @@ public abstract class ConnectionProperti
 		return element.getAttributeNode("value");
 	}
 	
-	public void patch(File srcXml, File destXml, String host, String port, String db, String user, String pass, ConnectionProperties connectionProperties) throws Exception {
-		this.connectionProperties = connectionProperties;
+	public void patch(File srcXml, File destXml, String host, String port, String db, String user, String pass) throws Exception {
 		Document doc = getDocument(srcXml);
 		
 		Attr val = getConnectionProperties(doc);
@@ -157,6 +150,13 @@ public abstract class ConnectionProperti
 			}
 			prop = getPropFromPersistence(tokens, i, "Url");
 			if (prop != null) {
+				try {
+					//will try to "guess" dbType
+					String[] parts = prop.split(":");
+					connectionProperties.setDbType(DbType.valueOf(parts[1]));
+				} catch (Exception e) {
+					//ignore
+				}
 				connectionProperties.setURL(prop);
 			}
 		}