You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2009/09/20 22:31:48 UTC
svn commit: r817097 - in
/incubator/empire-db/trunk/empire-db-codegen/src/main/java/org: ./ apache/
apache/empire/ apache/empire/db/ apache/empire/db/codegen/
apache/empire/db/codegen/CodeGen.java
apache/empire/db/codegen/CodeGenConfig.java
Author: doebele
Date: Sun Sep 20 20:31:46 2009
New Revision: 817097
URL: http://svn.apache.org/viewvc?rev=817097&view=rev
Log:
EMPIREDB-52
Added:
incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/ (with props)
incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/ (with props)
incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/ (with props)
incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/ (with props)
incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/ (with props)
incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java (with props)
incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java (with props)
Propchange: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/
------------------------------------------------------------------------------
eol-style = native
Propchange: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/
------------------------------------------------------------------------------
eol-style = native
Propchange: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/
------------------------------------------------------------------------------
eol-style = native
Propchange: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/
------------------------------------------------------------------------------
eol-style = native
Propchange: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/
------------------------------------------------------------------------------
eol-style = native
Added: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java?rev=817097&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java (added)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java Sun Sep 20 20:31:46 2009
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.db.codegen;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.util.logging.Logger;
+
+import org.apache.empire.commons.ErrorObject;
+
+public class CodeGen
+{
+ public static Logger logger = Logger.getLogger(CodeGen.class.getName());
+
+ private static CodeGenConfig config = new CodeGenConfig();
+
+ /**
+ * <PRE>
+ * This is the entry point of the Empire-DB Sample Application
+ * Please check the config.xml configuration file for Database and Connection settings.
+ * </PRE>
+ * @param args arguments
+ */
+ public static void main(String[] args)
+ {
+ Connection conn = null;
+ try
+ {
+ // Init Configuration
+ config.init((args.length > 0 ? args[0] : "config.xml" ), false, true);
+
+ // Enable Exceptions
+ ErrorObject.setExceptionsEnabled(true);
+
+ // Get a JDBC Connection
+ conn = getJDBCConnection();
+
+ // Get Metadata
+ DatabaseMetaData dmd = conn.getMetaData();
+
+ // Process Metadata
+ // ....
+
+ } catch(Exception e) {
+ // Error
+ System.out.println(e.toString());
+ e.printStackTrace();
+ } finally {
+ // done
+ if (conn!=null)
+ close(conn);
+ }
+ }
+
+ /**
+ * <PRE>
+ * Opens and returns a JDBC-Connection.
+ * JDBC url, user and password for the connection are obained from the SampleConfig bean
+ * Please use the config.xml file to change connection params.
+ * </PRE>
+ */
+ private static Connection getJDBCConnection()
+ {
+ // Establish a new database connection
+ Connection conn = null;
+ logger.info("Connecting to Database'" + config.getJdbcURL() + "' / User=" + config.getJdbcUser());
+ try
+ {
+ // Connect to the databse
+ Class.forName(config.getJdbcClass()).newInstance();
+ conn = DriverManager.getConnection(config.getJdbcURL(), config.getJdbcUser(), config.getJdbcPwd());
+ logger.info("Connected successfully");
+ // set the AutoCommit to false this session. You must commit
+ // explicitly now
+ conn.setAutoCommit(true);
+ logger.info("AutoCommit is " + conn.getAutoCommit());
+
+ } catch (Exception e)
+ {
+ logger.severe("Failed to connect directly to '" + config.getJdbcURL() + "' / User=" + config.getJdbcUser());
+ logger.severe(e.toString());
+ throw new RuntimeException(e);
+ }
+ return conn;
+ }
+
+ /**
+ * Closes a JDBC-Connection.
+ */
+ private static void close(Connection conn)
+ {
+ logger.info("Closing database connection");
+ try {
+ conn.close();
+ } catch (Exception e) {
+ logger.severe("Error closing connection");
+ logger.severe(e.toString());
+ }
+ }
+
+}
Propchange: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java
------------------------------------------------------------------------------
eol-style = native
Propchange: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGen.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java?rev=817097&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java (added)
+++ incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java Sun Sep 20 20:31:46 2009
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.db.codegen;
+
+import org.apache.empire.xml.XMLConfiguration;
+
+public class CodeGenConfig extends XMLConfiguration
+{
+ private String jdbcClass = "org.hsqldb.jdbcDriver";
+
+ private String jdbcURL = "jdbc:hsqldb:file:hsqldb/sample;shutdown=true";
+
+ private String jdbcUser = "sa";
+
+ private String jdbcPwd = "";
+
+ public String getJdbcClass()
+ {
+ return jdbcClass;
+ }
+
+ public void setJdbcClass(String jdbcClass)
+ {
+ this.jdbcClass = jdbcClass;
+ }
+
+ public String getJdbcURL()
+ {
+ return jdbcURL;
+ }
+
+ public void setJdbcURL(String jdbcURL)
+ {
+ this.jdbcURL = jdbcURL;
+ }
+
+ public String getJdbcUser()
+ {
+ return jdbcUser;
+ }
+
+ public void setJdbcUser(String jdbcUser)
+ {
+ this.jdbcUser = jdbcUser;
+ }
+
+ public String getJdbcPwd()
+ {
+ return jdbcPwd;
+ }
+
+ public void setJdbcPwd(String jdbcPwd)
+ {
+ this.jdbcPwd = jdbcPwd;
+ }
+
+}
Propchange: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java
------------------------------------------------------------------------------
eol-style = native
Propchange: incubator/empire-db/trunk/empire-db-codegen/src/main/java/org/apache/empire/db/codegen/CodeGenConfig.java
------------------------------------------------------------------------------
svn:mime-type = text/plain