tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwilli...@apache.org
Subject svn commit: r367764 - in /incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb: Command.java impl/CommandImpl.java impl/InsertList.java impl/Parameters.java impl/Statement.java
Date Tue, 10 Jan 2006 20:00:05 GMT
Author: kwilliams
Date: Tue Jan 10 12:00:02 2006
New Revision: 367764

URL: http://svn.apache.org/viewcvs?rev=367764&view=rev
Log:
Adding changes made since contrib snapshot

Modified:
    incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/Command.java
    incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandImpl.java
    incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/InsertList.java
    incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Parameters.java
    incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Statement.java

Modified: incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/Command.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/Command.java?rev=367764&r1=367763&r2=367764&view=diff
==============================================================================
--- incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/Command.java
(original)
+++ incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/Command.java
Tue Jan 10 12:00:02 2006
@@ -83,7 +83,27 @@
 	 */
 	public void setParameterValue(int index, Object value);
 
-	/**
+    /**
+     * Sets the "type" of the associated Parameter
+     * 
+     * @param name
+     *            the name of this Parameter
+     * @param type
+     *            the SDODataTypes-defined "type" for the Parameter.
+     */
+    public void setParameterType(String string, Type dataType);
+     
+     /**
+     * Sets the "type" of the associated Parameter
+     * 
+     * @param index
+     *            the index of the Parameter
+     * @param type
+     *            the SDODataTypes-defined "type" for the Parameter.
+     */
+    public void setParameterType(int index, Type dataType);
+    
+    /**
 	 * Returns the value of the associated Parameter
 	 * 
 	 * @param name
@@ -257,5 +277,7 @@
 	 * should be called when the application is done with this command.
 	 */
 	public void close();
+
+
 
 }

Modified: incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandImpl.java?rev=367764&r1=367763&r2=367764&view=diff
==============================================================================
--- incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandImpl.java
(original)
+++ incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandImpl.java
Tue Jan 10 12:00:02 2006
@@ -50,13 +50,20 @@
 
 	public void setParameterValue(String name, Object value) {
 		parameters.setParameter(name, value);
-		
 	}
 	public void setParameterValue(int index, Object value) {
 		parameters.setParameter(index, value);
 	}
 
-	public void addParameter(int index, Type sdoType) {
+    public void setParameterType(String name, Type dataType) {
+        parameters.setParameterWithType(name, dataType);
+    }
+    
+    public void setParameterType(int index, Type dataType) {
+        parameters.setParameterWithType(index, dataType);
+    }
+
+    public void addParameter(int index, Type sdoType) {
 		addParameter(index, Parameter.IN, sdoType);
 	}
 

Modified: incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/InsertList.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/InsertList.java?rev=367764&r1=367763&r2=367764&view=diff
==============================================================================
--- incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/InsertList.java
(original)
+++ incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/InsertList.java
Tue Jan 10 12:00:02 2006
@@ -23,7 +23,6 @@
 
 import org.apache.tuscany.das.rdb.util.DebugUtil;
 
-
 /**
  * InsertList will sort ChangeOperation objects so that parents are inserted
  * before children
@@ -32,44 +31,50 @@
  */
 public class InsertList {
 
-	private HashMap opsByTableName = new HashMap();
-	private ArrayList insertOperations = new ArrayList();
-	private ArrayList order;
-	private static final boolean debug = false;
-
-
-	public void add(ChangeOperation op) {
-		DebugUtil.debugln(getClass(), debug , "Adding insert operation ");
-		if ( ( order.size() == 0 ) || ( op.getTableName() == null) ) {
-			insertOperations.add(op);
-		} else {
-			String name = op.getTableName();
-			ArrayList ops = (ArrayList) opsByTableName.get(name);
-			if ( ops == null ) 
-				ops = new ArrayList();
-		
-			ops.add(op);
-			opsByTableName.put(name, ops);
-		}
-	}
-
-	public Collection getSortedList() {
-		DebugUtil.debugln(getClass(), debug, "Getting sorted insert list");
-		if (( order.size() > 0 ) && opsByTableName.keySet().size() > 0 ) {	
-			Iterator i = this.order.iterator(); 
-			while ( i.hasNext() ) {
-				String name = (String) i.next();
-				DebugUtil.debugln(getClass(), debug, "Adding operations for table " + name);
-				insertOperations.addAll((Collection) opsByTableName.get(name));
-			}
-		}
-		DebugUtil.debugln(getClass(), debug, "Returning " + insertOperations.size() + " insert
operations");
-		return insertOperations;
-	}
-
-	public void setOrder(ArrayList insertOrder) {
-		this.order = insertOrder;
-	}
+    private HashMap opsByTableName = new HashMap();
+
+    private ArrayList insertOperations = new ArrayList();
+
+    private ArrayList order;
+
+    private static final boolean debug = false;
 
+    public void add(ChangeOperation op) {
+        DebugUtil.debugln(getClass(), debug, "Adding insert operation ");
+        if ((order.size() == 0) || (op.getTableName() == null)) {
+            insertOperations.add(op);
+        } else {
+            String name = op.getTableName();
+            ArrayList ops = (ArrayList) opsByTableName.get(name);
+            if (ops == null)
+                ops = new ArrayList();
+
+            ops.add(op);
+            opsByTableName.put(name, ops);
+        }
+    }
+
+    public Collection getSortedList() {
+        DebugUtil.debugln(getClass(), debug, "Getting sorted insert list");
+        if ((order.size() > 0) && opsByTableName.keySet().size() > 0) {
+            Iterator i = this.order.iterator();
+            while (i.hasNext()) {
+                String name = (String) i.next();
+                DebugUtil.debugln(getClass(), debug,
+                        "Adding operations for table " + name);
+                // TODO - KJW added null check ... Brent to verify.
+                if (opsByTableName.get(name) != null)
+                    insertOperations.addAll((Collection) opsByTableName
+                            .get(name));
+            }
+        }
+        DebugUtil.debugln(getClass(), debug, "Returning "
+                + insertOperations.size() + " insert operations");
+        return insertOperations;
+    }
+
+    public void setOrder(ArrayList insertOrder) {
+        this.order = insertOrder;
+    }
 
 }

Modified: incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Parameters.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Parameters.java?rev=367764&r1=367763&r2=367764&view=diff
==============================================================================
--- incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Parameters.java
(original)
+++ incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Parameters.java
Tue Jan 10 12:00:02 2006
@@ -129,7 +129,14 @@
 		p.setType(sdoType);
 	}
 
-	public Parameter parameterWithIndex(int index) {
+    public void setParameterWithType(int index, Type sdoType) {
+        if (index == 0)
+            throw new RuntimeException("Null parameter index not allowed");
+        Parameter p = findOrCreateParameterWithIndex(index);
+        p.setType(sdoType);
+    }
+    
+    public Parameter parameterWithIndex(int index) {
 		Iterator i = parameters.iterator();
 		while (i.hasNext()) {
 			Parameter param = (Parameter) i.next();

Modified: incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Statement.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Statement.java?rev=367764&r1=367763&r2=367764&view=diff
==============================================================================
--- incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Statement.java
(original)
+++ incubator/tuscany/contrib/java/trunk/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Statement.java
Tue Jan 10 12:00:02 2006
@@ -25,188 +25,180 @@
 import org.apache.tuscany.das.rdb.Parameter;
 import org.apache.tuscany.das.rdb.util.DebugUtil;
 
-
 public class Statement {
 
-	protected final QueryString queryString;
+    protected final QueryString queryString;
 
-	protected ConnectionImpl jdbcConnection;
+    protected ConnectionImpl jdbcConnection;
 
-	private static final boolean debug = false;
+    private static final boolean debug = false;
 
-	private PreparedStatement preparedStatement;
+    private PreparedStatement preparedStatement;
 
-	private boolean isPaging = false;
-
-	public Statement(String sqlString) {
-		this.queryString = new QueryString(sqlString);
-	}
-
-	public ResultSet executeQuery(Parameters parameters) throws SQLException {
-
-		PreparedStatement ps = getPreparedStatement();
-		ps = setParameters(ps, parameters);
-		ResultSet rs = ps.executeQuery();
-
-		return rs;
-	}
-
-	public ResultSet executeCall(Parameters parameters) throws SQLException {
-		try {
-			CallableStatement cs = jdbcConnection.prepareCall(queryString);
-
-			Iterator inParams = parameters.inParams().iterator();
-			while (inParams.hasNext()) {
-				Parameter param = (Parameter) inParams.next();
-				if (param.getIndex() == 0)
-					param.setIndex(queryString.getParameterIndex(param
-							.getName()));
-				cs.setObject(param.getIndex(), param.getValue());
-			}
-
-			// register out parameters
-			Iterator outParams = parameters.outParams().iterator();
-			while (outParams.hasNext()) {
-				Parameter param = (Parameter) outParams.next();
-				if (param.getIndex() == 0)
-					param.setIndex(queryString.getParameterIndex(param
-							.getName()));
-				DebugUtil.debugln(getClass(), debug, "Registering parameter "
-						+ param.getName());
-				cs.registerOutParameter(param.getIndex(), SDODataTypeHelper
-						.sqlTypeFor(param.getType()));
-			}
-
-			// Using execute because Derby does not currenlty support
-			// executeQuery
-			// for SP
-			cs.execute();
-			ResultSet results = cs.getResultSet();
-
-			Iterator i = parameters.outParams().iterator();
-			while (i.hasNext()) {
-				Parameter param = (Parameter) i.next();
-				param.setValue(cs.getObject(param.getIndex()));
-			}
-
-			return results;
-		} catch (SQLException ex) {
-			ex.printStackTrace();
-			throw ex;
-		}
-
-	}
-
-	public void executeUpdateCall(Parameters parameters) throws SQLException {
-		CallableStatement cs = jdbcConnection.prepareCall(queryString);
-
-		Iterator inParams = parameters.inParams().iterator();
-		while (inParams.hasNext()) {
-			Parameter param = (Parameter) inParams.next();
-			if (param.getIndex() == 0)
-				param.setIndex(queryString.getParameterIndex(param.getName()));
-			cs.setObject(param.getIndex(), param.getValue());
-		}
-
-		// register out parameters
-		Iterator outParams = parameters.outParams().iterator();
-		while (outParams.hasNext()) {
-			Parameter param = (Parameter) outParams.next();
-			if (param.getIndex() == 0)
-				param.setIndex(queryString.getParameterIndex(param.getName()));
-			DebugUtil.debugln(getClass(), debug, "Registering parameter "
-					+ param.getName());
-			cs.registerOutParameter(param.getIndex(), SDODataTypeHelper
-					.sqlTypeFor(param.getType()));
-		}
-
-		cs.execute();
-
-		Iterator out = parameters.outParams().iterator();
-		while (out.hasNext()) {
-			Parameter param = (Parameter) out.next();
-			param.setValue(cs.getObject(param.getIndex()));
-		}
-
-	}
-
-	public int executeUpdate(Parameters parameters) throws SQLException {
-		DebugUtil.debugln(getClass(), debug, "Executing statement "
-				+ queryString.getPreparedString());
-		PreparedStatement ps = getPreparedStatement();
-		Iterator i = parameters.inParams().iterator();
-		while (i.hasNext()) {
-			Parameter param = (Parameter) i.next();
-			if (param.getIndex() == 0)
-				param.setIndex(queryString.getParameterIndex(param.getName()));
-			Object value = param.getValue();
-			DebugUtil.debugln(getClass(), debug, "Setting parameter "
-					+ param.getIndex() + " to " + value);
-			if (value == null) {
-				// System.out.println(param.getType());
-				ps.setNull(param.getIndex(), SDODataTypeHelper.sqlTypeFor(param
-						.getType()));
-			} else
-				ps.setObject(param.getIndex(), value);
-		}
-		return ps.executeUpdate();
-	}
-
-	protected PreparedStatement setParameters(PreparedStatement ps,
-			Parameters parameters) throws SQLException {
-		Iterator i = parameters.inParams().iterator();
-		while (i.hasNext()) {
-			Parameter param = (Parameter) i.next();
-			param.setIndex(queryString.getParameterIndex(param.getName()));
-			ps.setObject(param.getIndex(), param.getValue());
-		}
-		return ps;
-	}
-
-	public void setConnection(ConnectionImpl jdbcConnection) {
-		this.jdbcConnection = jdbcConnection;
-	}
-
-	public ConnectionImpl getConnection() {
-		return this.jdbcConnection;
-	}
-
-	private PreparedStatement getPreparedStatement() throws SQLException {
-		DebugUtil.debugln(getClass(), debug, "Getting prepared statement");
-		if (preparedStatement == null)
-			if (isPaging)
-				preparedStatement = jdbcConnection
-						.preparePagedStatement(queryString);
-			else
-				preparedStatement = jdbcConnection
-						.prepareStatement(queryString);
-
-		return preparedStatement;
-	}
-
-	public Integer getGeneratedKey() throws SQLException {
-
-		ResultSet rs = getPreparedStatement().getGeneratedKeys();
-		if (rs.next())
-			return new Integer(rs.getInt(1));
-
-		return null;
-	}
-
-	protected void enablePaging() {
-		isPaging = true;
-	}
-
-	public void close() {
-
-		if (this.preparedStatement != null) {
-			try {
-				preparedStatement.close();
-			} catch (SQLException e) {
-				throw new RuntimeException(e);
-			}
-		}
+    private boolean isPaging = false;
+
+    public Statement(String sqlString) {
+        this.queryString = new QueryString(sqlString);
+    }
+
+    public ResultSet executeQuery(Parameters parameters) throws SQLException {
+
+        PreparedStatement ps = getPreparedStatement();
+        ps = setParameters(ps, parameters);
+        ResultSet rs = ps.executeQuery();
+
+        return rs;
+    }
+
+    public ResultSet executeCall(Parameters parameters) throws SQLException {
+        try {
+            CallableStatement cs = jdbcConnection.prepareCall(queryString);
+
+            Iterator inParams = parameters.inParams().iterator();
+            while (inParams.hasNext()) {
+                Parameter param = (Parameter) inParams.next();
+                if (param.getIndex() == 0)
+                    param.setIndex(queryString.getParameterIndex(param.getName()));
+                cs.setObject(param.getIndex(), param.getValue());
+            }
+
+            // register out parameters
+            Iterator outParams = parameters.outParams().iterator();
+            while (outParams.hasNext()) {
+                Parameter param = (Parameter) outParams.next();
+                if (param.getIndex() == 0)
+                    param.setIndex(queryString.getParameterIndex(param.getName()));
+                DebugUtil.debugln(getClass(), debug, "Registering parameter " + param.getName());
+                cs.registerOutParameter(param.getIndex(), SDODataTypeHelper.sqlTypeFor(param.getType()));
+            }
+
+            // Using execute because Derby does not currenlty support
+            // executeQuery
+            // for SP
+            cs.execute();
+            ResultSet results = cs.getResultSet();
+
+            Iterator i = parameters.outParams().iterator();
+            while (i.hasNext()) {
+                Parameter param = (Parameter) i.next();
+                param.setValue(cs.getObject(param.getIndex()));
+            }
+
+            return results;
+        } catch (SQLException ex) {
+            ex.printStackTrace();
+            throw ex;
+        }
+
+    }
+
+    public void executeUpdateCall(Parameters parameters) throws SQLException {
+        CallableStatement cs = jdbcConnection.prepareCall(queryString);
+
+        Iterator inParams = parameters.inParams().iterator();
+        while (inParams.hasNext()) {
+            Parameter param = (Parameter) inParams.next();
+            if (param.getIndex() == 0)
+                param.setIndex(queryString.getParameterIndex(param.getName()));
+            cs.setObject(param.getIndex(), param.getValue());
+        }
+
+        // register out parameters
+        Iterator outParams = parameters.outParams().iterator();
+        while (outParams.hasNext()) {
+            Parameter param = (Parameter) outParams.next();
+            if (param.getIndex() == 0)
+                param.setIndex(queryString.getParameterIndex(param.getName()));
+            DebugUtil.debugln(getClass(), debug, "Registering parameter " + param.getName());
+            cs.registerOutParameter(param.getIndex(), SDODataTypeHelper.sqlTypeFor(param.getType()));
+        }
+
+        cs.execute();
+
+        Iterator out = parameters.outParams().iterator();
+        while (out.hasNext()) {
+            Parameter param = (Parameter) out.next();
+            param.setValue(cs.getObject(param.getIndex()));
+        }
+
+    }
+
+    /**
+     * TODO - We need to look at using specific ps.setXXX methods when a type
+     * has been specified and try setObject otherwise.
+     */
+    public int executeUpdate(Parameters parameters) throws SQLException {
+        DebugUtil.debugln(getClass(), debug, "Executing statement " + queryString.getPreparedString());
+        PreparedStatement ps = getPreparedStatement();
+        Iterator i = parameters.inParams().iterator();
+        while (i.hasNext()) {
+            Parameter param = (Parameter) i.next();
+            if (param.getIndex() == 0)
+                param.setIndex(queryString.getParameterIndex(param.getName()));
+            Object value = param.getValue();
+            DebugUtil.debugln(getClass(), debug, "Setting parameter " + param.getIndex()
+ " to " + value);
+            if (value == null) {
+                // System.out.println(param.getType());
+                ps.setNull(param.getIndex(), SDODataTypeHelper.sqlTypeFor(param.getType()));
+            } else
+                ps.setObject(param.getIndex(), value);
+        }
+        return ps.executeUpdate();
+    }
+
+    protected PreparedStatement setParameters(PreparedStatement ps, Parameters parameters)
+            throws SQLException {
+        Iterator i = parameters.inParams().iterator();
+        while (i.hasNext()) {
+            Parameter param = (Parameter) i.next();
+            param.setIndex(queryString.getParameterIndex(param.getName()));
+            ps.setObject(param.getIndex(), param.getValue());
+        }
+        return ps;
+    }
+
+    public void setConnection(ConnectionImpl jdbcConnection) {
+        this.jdbcConnection = jdbcConnection;
+    }
+
+    public ConnectionImpl getConnection() {
+        return this.jdbcConnection;
+    }
+
+    private PreparedStatement getPreparedStatement() throws SQLException {
+        DebugUtil.debugln(getClass(), debug, "Getting prepared statement");
+        if (preparedStatement == null)
+            if (isPaging)
+                preparedStatement = jdbcConnection.preparePagedStatement(queryString);
+            else
+                preparedStatement = jdbcConnection.prepareStatement(queryString);
+
+        return preparedStatement;
+    }
+
+    public Integer getGeneratedKey() throws SQLException {
+
+        ResultSet rs = getPreparedStatement().getGeneratedKeys();
+        if (rs.next())
+            return new Integer(rs.getInt(1));
+
+        return null;
+    }
+
+    protected void enablePaging() {
+        isPaging = true;
+    }
+
+    public void close() {
+
+        if (this.preparedStatement != null) {
+            try {
+                preparedStatement.close();
+            } catch (SQLException e) {
+                throw new RuntimeException(e);
+            }
+        }
 
-	}
+    }
 
 }



Mime
View raw message