? diff.patch Index: org/apache/juddi/datastore/DataStore.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/DataStore.java,v retrieving revision 1.1 diff -u -w -B -r1.1 DataStore.java --- org/apache/juddi/datastore/DataStore.java 3 Jul 2006 07:45:17 -0000 1.1 +++ org/apache/juddi/datastore/DataStore.java 12 Jul 2006 15:11:52 -0000 @@ -15,6 +15,7 @@ */ package org.apache.juddi.datastore; +import java.util.List; import java.util.Vector; import org.apache.juddi.datatype.CategoryBag; @@ -161,6 +162,12 @@ /** * */ + List fetchServices(List servicesKeys) + throws RegistryException; + + /** + * + */ BusinessService fetchService(String serviceKey) throws RegistryException; @@ -188,6 +195,13 @@ void saveBinding(BindingTemplate binding) throws RegistryException; + + /** + * + */ + List fetchBindings(List bindingsKeys) + throws RegistryException; + /** * */ @@ -221,6 +235,11 @@ /** * */ + List fetchTModels(List tModelsKeys) + throws RegistryException; + /** + * + */ TModel fetchTModel(String tModelKey) throws RegistryException; @@ -251,15 +270,28 @@ /** * */ + List fetchBusinessesInfos(List businessesKeys) + throws RegistryException; + + + /** + * + */ BusinessInfo fetchBusinessInfo(String businessKey) throws RegistryException; /** * */ + List fetchServicesInfos(List servicesKeys) + throws RegistryException; + /** + * + */ ServiceInfo fetchServiceInfo(String serviceKey) throws RegistryException; + /** * */ Index: org/apache/juddi/datastore/jdbc/BindingCategoryTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/BindingCategoryTable.java,v retrieving revision 1.1 retrieving revision 1.4 diff -u -w -B -r1.1 -r1.4 --- org/apache/juddi/datastore/jdbc/BindingCategoryTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/BindingCategoryTable.java 11 Jul 2006 09:13:02 -0000 1.4 @@ -18,17 +18,22 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.juddi.datatype.KeyedReference; +import org.apache.juddi.util.Config; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class BindingCategoryTable -{ +class BindingCategoryTable { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(BindingCategoryTable.class); @@ -33,7 +38,11 @@ private static Log log = LogFactory.getLog(BindingCategoryTable.class); static String insertSQL = null; + static String selectSQL = null; + + static String selectInSQL = null; + static String deleteSQL = null; static { @@ -63,6 +72,17 @@ sql.append("ORDER BY CATEGORY_ID"); selectSQL = sql.toString(); + // build selectInSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("TMODEL_KEY_REF,"); + sql.append("KEY_NAME,"); + sql.append("KEY_VALUE, "); + sql.append("CATEGORY_ID, BINDING_KEY "); + sql.append("FROM BINDING_CATEGORY "); + sql.append("WHERE BINDING_KEY IN ( "); + selectInSQL = sql.toString(); + // build deleteSQL sql = new StringBuffer(100); sql.append("DELETE FROM BINDING_CATEGORY "); @@ -73,27 +93,23 @@ /** * Insert new row into the BINDING_CATEGORY table. * - * @param bindingKey String to the parent BindingTemplate object. - * @param keyRefs A Vector of KeyedReference instances to insert. - * @param connection JDBC connection + * @param bindingKey + * String to the parent BindingTemplate object. + * @param keyRefs + * A Vector of KeyedReference instances to insert. + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void insert( - String bindingKey, - Vector keyRefs, - Connection connection) - throws java.sql.SQLException - { + public static void insert(String bindingKey, Vector keyRefs, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { statement = connection.prepareStatement(insertSQL); statement.setString(1, bindingKey.toString()); int listSize = keyRefs.size(); - for (int categoryID = 0; categoryID < listSize; categoryID++) - { + for (int categoryID = 0; categoryID < listSize; categoryID++) { KeyedReference keyRef = (KeyedReference) keyRefs.elementAt(categoryID); // extract values to insert @@ -107,33 +123,88 @@ statement.setString(4, keyRef.getKeyName()); statement.setString(5, keyRef.getKeyValue()); - log.debug( - "insert into BINDING_CATEGORY table:\n\n\t" - + insertSQL - + "\n\t BINDING_KEY=" - + bindingKey.toString() - + "\n\t CATEGORY_ID=" - + categoryID - + "\n\t TMODEL_KEY_REF=" - + tModelKeyValue - + "\n\t KEY_NAME=" - + keyRef.getKeyName() - + "\n\t KEY_VALUE=" - + keyRef.getKeyValue() - + "\n"); + log.debug("insert into BINDING_CATEGORY table:\n\n\t" + insertSQL + "\n\t BINDING_KEY=" + bindingKey.toString() + "\n\t CATEGORY_ID=" + + categoryID + "\n\t TMODEL_KEY_REF=" + tModelKeyValue + "\n\t KEY_NAME=" + keyRef.getKeyName() + "\n\t KEY_VALUE=" + + keyRef.getKeyValue() + "\n"); // insert statement.executeUpdate(); } - } - finally - { - try - { + } finally { + try { statement.close(); + } catch (Exception e) { /* ignored */ + } + } + } + + /** + * Select all rows from the BINDING_CATEGORY table for BindingKeys. + * + * @param bindingKey + * String + * @param connection + * JDBC connection + * @throws java.sql.SQLException + */ + public static Map select(List bindingsKeys, Connection connection) throws java.sql.SQLException { + Map results = new HashMap(); + + PreparedStatement statement = null; + ResultSet resultSet = null; + + try { + + DynamicQuery query = new DynamicQuery(); + query.append("(" + selectInSQL); + int count = 0; + for (Iterator i = bindingsKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + count++; + if (i.hasNext()) { + if (count > Config.getMaxInAllowed()) { + count = 0; + query.append(") UNION ALL " + selectInSQL); + } else { + query.append(", "); } - catch (Exception e) - { /* ignored */ + } + query.addValue(key); + } + + query.append(")) "); + query.append("ORDER BY BINDING_KEY, CATEGORY_ID"); + + // create a statement to query with + statement = query.buildPreparedStatement(connection); + statement.setFetchSize(500); + log.debug("select from BINDING_CATEGORY table:\n\n\t" + query.toString() + "\n"); + + // execute the statement + resultSet = statement.executeQuery(); + while (resultSet.next()) { + KeyedReference keyRef = new KeyedReference(); + keyRef.setTModelKey(resultSet.getString(1));// ("TMODEL_KEY_REF")); + keyRef.setKeyName(resultSet.getString(2));// ("KEY_NAME")); + keyRef.setKeyValue(resultSet.getString(3));// ("KEY_VALUE")); + + String bindingKey = resultSet.getString(5); + Vector keyRefList = (Vector) results.get(bindingKey); + if (keyRefList == null) { + keyRefList = new Vector(); + results.put(bindingKey, keyRefList); + } + keyRefList.add(keyRef); + + } + + return results; + } finally { + try { + resultSet.close(); + statement.close(); + } catch (Exception e) { /* ignored */ } } } @@ -141,34 +212,27 @@ /** * Select all rows from the BINDING_CATEGORY table for a given BindingKey. * - * @param bindingKey String - * @param connection JDBC connection + * @param bindingKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static Vector select(String bindingKey, Connection connection) - throws java.sql.SQLException - { + public static Vector select(String bindingKey, Connection connection) throws java.sql.SQLException { Vector keyRefList = new Vector(); PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { // create a statement to query with statement = connection.prepareStatement(selectSQL); statement.setString(1, bindingKey.toString()); - log.debug( - "select from BINDING_CATEGORY table:\n\n\t" - + selectSQL - + "\n\t BINDING_KEY=" - + bindingKey.toString() - + "\n"); + log.debug("select from BINDING_CATEGORY table:\n\n\t" + selectSQL + "\n\t BINDING_KEY=" + bindingKey.toString() + "\n"); // execute the statement resultSet = statement.executeQuery(); - while (resultSet.next()) - { + while (resultSet.next()) { KeyedReference keyRef = new KeyedReference(); keyRef.setTModelKey(resultSet.getString(1));//("TMODEL_KEY_REF")); keyRef.setKeyName(resultSet.getString(2));//("KEY_NAME")); @@ -177,57 +241,41 @@ } return keyRefList; - } - finally - { - try - { + } finally { + try { resultSet.close(); statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } /** - * Delete multiple rows from the BINDING_CATEGORY table that are assigned to the - * BindingKey specified. + * Delete multiple rows from the BINDING_CATEGORY table that are assigned to + * the BindingKey specified. * - * @param bindingKey String - * @param connection JDBC connection + * @param bindingKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void delete(String bindingKey, Connection connection) - throws java.sql.SQLException - { + public static void delete(String bindingKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(deleteSQL); statement.setString(1, bindingKey.toString()); - log.debug( - "delete from BINDING_CATEGORY table:\n\n\t" - + deleteSQL - + "\n\t BINDING_KEY=" - + bindingKey.toString() - + "\n"); + log.debug("delete from BINDING_CATEGORY table:\n\n\t" + deleteSQL + "\n\t BINDING_KEY=" + bindingKey.toString() + "\n"); // execute statement.executeUpdate(); - } - finally - { - try - { + } finally { + try { statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } Index: org/apache/juddi/datastore/jdbc/BindingDescTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/BindingDescTable.java,v retrieving revision 1.1 retrieving revision 1.4 diff -u -w -B -r1.1 -r1.4 --- org/apache/juddi/datastore/jdbc/BindingDescTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/BindingDescTable.java 11 Jul 2006 09:13:02 -0000 1.4 @@ -18,17 +18,22 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.juddi.datatype.Description; +import org.apache.juddi.util.Config; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class BindingDescTable -{ +class BindingDescTable { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(BindingDescTable.class); @@ -33,7 +38,11 @@ private static Log log = LogFactory.getLog(BindingDescTable.class); static String insertSQL = null; + static String selectSQL = null; + + static String selectInSQL = null; + static String deleteSQL = null; static { @@ -61,6 +70,16 @@ sql.append("ORDER BY BINDING_DESCR_ID"); selectSQL = sql.toString(); + // build selectInSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("LANG_CODE,"); + sql.append("DESCR, "); + sql.append("BINDING_DESCR_ID "); + sql.append("FROM BINDING_DESCR "); + sql.append("WHERE BINDING_KEY IN ( "); + selectInSQL = sql.toString(); + // build deleteSQL sql = new StringBuffer(100); sql.append("DELETE FROM BINDING_DESCR "); @@ -71,60 +90,111 @@ /** * Insert new row into the BINDING_DESCR table. * - * @param bindingKey String to the BusinessEntity object that owns the Description to be inserted - * @param descList Enumeration of Description objects to be inserted - * @param connection JDBC connection + * @param bindingKey + * String to the BusinessEntity object that owns the Description + * to be inserted + * @param descList + * Enumeration of Description objects to be inserted + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void insert( - String bindingKey, - Vector descList, - Connection connection) - throws java.sql.SQLException - { + public static void insert(String bindingKey, Vector descList, Connection connection) throws java.sql.SQLException { if ((descList == null) || (descList.size() == 0)) return; // everything is valid but no elements to insert PreparedStatement statement = null; - try - { + try { statement = connection.prepareStatement(insertSQL); statement.setString(1, bindingKey.toString()); int listSize = descList.size(); - for (int descID = 0; descID < listSize; descID++) - { + for (int descID = 0; descID < listSize; descID++) { Description desc = (Description) descList.elementAt(descID); statement.setInt(2, descID); statement.setString(3, desc.getLanguageCode()); statement.setString(4, desc.getValue()); - log.debug( - "insert into BINDING_DESCR table:\n\n\t" - + insertSQL - + "\n\t BINDING_KEY=" - + bindingKey.toString() - + "\n\t BINDING_DESCR_ID=" - + descID - + "\n\t LANG_CODE=" - + desc.getLanguageCode() - + "\n\t DESCR=" - + desc.getValue() - + "\n"); + log.debug("insert into BINDING_DESCR table:\n\n\t" + insertSQL + "\n\t BINDING_KEY=" + bindingKey.toString() + "\n\t BINDING_DESCR_ID=" + + descID + "\n\t LANG_CODE=" + desc.getLanguageCode() + "\n\t DESCR=" + desc.getValue() + "\n"); statement.executeUpdate(); } - } - finally - { - try - { + } finally { + try { statement.close(); + } catch (Exception e) { /* ignored */ + } + } + } + + /** + * Select all rows from the BINDING_DESCR table for BusinessKeys. + * + * @param bindingKey + * List + * @param connection + * JDBC connection + * @throws java.sql.SQLException + */ + public static Map select(List bindingsKeys, Connection connection) throws java.sql.SQLException { + Map results = new HashMap(); + PreparedStatement statement = null; + ResultSet resultSet = null; + + try { + + DynamicQuery query = new DynamicQuery(); + query.append("(" + selectInSQL); + int count = 0; + for (Iterator i = bindingsKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + count++; + if (i.hasNext()) { + if (count > Config.getMaxInAllowed()) { + count = 0; + query.append(") UNION ALL " + selectInSQL); + } else { + query.append(", "); } - catch (Exception e) - { /* ignored */ + } + query.addValue(key); + } + + query.append(")) "); + query.append("ORDER BY BINDING_DESCR_ID"); + + // create a statement to query with + statement = query.buildPreparedStatement(connection); + statement.setFetchSize(500); + log.debug("select from BINDING_DESCR table:\n\n\t" + query.toString() + "\n"); + + // execute the statement + resultSet = statement.executeQuery(); + while (resultSet.next()) { + Description desc = new Description(); + desc.setLanguageCode(resultSet.getString(1));// ("LANG_CODE")); + desc.setValue(resultSet.getString(2));// ("DESCR")); + + String bindingKey = resultSet.getString(3); + Vector descList = (Vector) results.get(bindingKey); + if (descList == null) { + descList = new Vector(); + results.put(bindingKey, descList); + } + descList.add(desc); + + } + + return results; + } finally { + try { + resultSet.close(); + statement.close(); + } catch (Exception e) { /* ignored */ } } } @@ -132,34 +202,27 @@ /** * Select all rows from the BINDING_DESCR table for a given BusinessKey. * - * @param bindingKey String - * @param connection JDBC connection + * @param bindingKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static Vector select(String bindingKey, Connection connection) - throws java.sql.SQLException - { + public static Vector select(String bindingKey, Connection connection) throws java.sql.SQLException { Vector descList = new Vector(); PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { // create a statement to query with statement = connection.prepareStatement(selectSQL); statement.setString(1, bindingKey.toString()); - log.debug( - "select from BINDING_DESCR table:\n\n\t" - + selectSQL - + "\n\t BINDING_KEY=" - + bindingKey.toString() - + "\n"); + log.debug("select from BINDING_DESCR table:\n\n\t" + selectSQL + "\n\t BINDING_KEY=" + bindingKey.toString() + "\n"); // execute the statement resultSet = statement.executeQuery(); - while (resultSet.next()) - { + while (resultSet.next()) { Description desc = new Description(); desc.setLanguageCode(resultSet.getString(1));//("LANG_CODE")); desc.setValue(resultSet.getString(2));//("DESCR")); @@ -167,57 +230,41 @@ } return descList; - } - finally - { - try - { + } finally { + try { resultSet.close(); statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } /** - * Delete multiple rows from the BINDING_DESCR table that are assigned - * to the BusinessKey specified. + * Delete multiple rows from the BINDING_DESCR table that are assigned to + * the BusinessKey specified. * - * @param bindingKey String - * @param connection JDBC connection + * @param bindingKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void delete(String bindingKey, Connection connection) - throws java.sql.SQLException - { + public static void delete(String bindingKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(deleteSQL); statement.setString(1, bindingKey.toString()); - log.debug( - "delete from BINDING_DESCR table:\n\n\t" - + deleteSQL - + "\n\t BINDING_KEY=" - + bindingKey.toString() - + "\n"); + log.debug("delete from BINDING_DESCR table:\n\n\t" + deleteSQL + "\n\t BINDING_KEY=" + bindingKey.toString() + "\n"); // execute statement.executeUpdate(); - } - finally - { - try - { + } finally { + try { statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } Index: org/apache/juddi/datastore/jdbc/BindingTemplateTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/BindingTemplateTable.java,v retrieving revision 1.1 retrieving revision 1.4 diff -u -w -B -r1.1 -r1.4 --- org/apache/juddi/datastore/jdbc/BindingTemplateTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/BindingTemplateTable.java 11 Jul 2006 09:13:02 -0000 1.4 @@ -19,6 +19,11 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; @@ -26,12 +31,13 @@ import org.apache.juddi.datatype.binding.AccessPoint; import org.apache.juddi.datatype.binding.BindingTemplate; import org.apache.juddi.datatype.binding.HostingRedirector; +import org.apache.juddi.util.Config; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class BindingTemplateTable -{ +class BindingTemplateTable { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(BindingTemplateTable.class); @@ -36,14 +42,22 @@ private static Log log = LogFactory.getLog(BindingTemplateTable.class); static String insertSQL = null; + static String deleteSQL = null; + static String selectSQL = null; + + static String selectInSQL = null; + static String selectByServiceKeySQL = null; + + static String selectByServicesKeysSQL = null; + static String deleteByServiceKeySQL = null; + static String verifyOwnershipSQL = null; - static - { + static { // buffer used to build SQL statements StringBuffer sql = null; @@ -76,6 +90,17 @@ sql.append("WHERE BINDING_KEY=?"); selectSQL = sql.toString(); + // build selectInSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("SERVICE_KEY,"); + sql.append("ACCESS_POINT_TYPE,"); + sql.append("ACCESS_POINT_URL,"); + sql.append("HOSTING_REDIRECTOR, BINDING_KEY "); + sql.append("FROM BINDING_TEMPLATE "); + sql.append("WHERE BINDING_KEY IN ("); + selectInSQL = sql.toString(); + // build selectByServiceKeySQL sql = new StringBuffer(200); sql.append("SELECT "); @@ -87,6 +112,17 @@ sql.append("WHERE SERVICE_KEY=?"); selectByServiceKeySQL = sql.toString(); + // build selectByServicesKeysSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("BINDING_KEY,"); + sql.append("ACCESS_POINT_TYPE,"); + sql.append("ACCESS_POINT_URL,"); + sql.append("HOSTING_REDIRECTOR, SERVICE_KEY "); + sql.append("FROM BINDING_TEMPLATE "); + sql.append("WHERE SERVICE_KEY IN ("); + selectByServicesKeysSQL = sql.toString(); + // build deleteByServiceKeySQL sql = new StringBuffer(100); sql.append("DELETE FROM BINDING_TEMPLATE "); @@ -108,24 +144,22 @@ /** * Insert new row into the BINDING_TEMPLATE table. * - * @param binding Binding Template object holding values to be inserted - * @param connection JDBC connection + * @param binding + * Binding Template object holding values to be inserted + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void insert(BindingTemplate binding,Connection connection) - throws java.sql.SQLException - { + public static void insert(BindingTemplate binding, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; Timestamp timeStamp = new Timestamp(System.currentTimeMillis()); - try - { + try { // pull the raw AccessPoint attributes out (if any) String urlType = null; String url = null; AccessPoint accessPoint = binding.getAccessPoint(); - if (accessPoint != null) - { + if (accessPoint != null) { urlType = accessPoint.getURLType(); url = accessPoint.getURL(); } @@ -133,8 +167,7 @@ // pull the raw HostingRedirector attributes out (if any) String redirectorKey = null; HostingRedirector redirector = binding.getHostingRedirector(); - if (redirector != null) - { + if (redirector != null) { if (redirector.getBindingKey() != null) redirectorKey = redirector.getBindingKey(); } @@ -148,77 +181,142 @@ statement.setString(5,redirectorKey); statement.setTimestamp(6,timeStamp); - log.debug("insert into BINDING_TEMPLATE table:\n\n\t" + insertSQL + - "\n\t SERVICE_KEY=" + binding.getServiceKey().toString() + - "\n\t BINDING_KEY=" + binding.getBindingKey().toString() + - "\n\t ACCESS_POINT_TYPE=" + urlType + - "\n\t ACCESS_POINT_URL=" + url + - "\n\t HOSTING_REDIRECTOR=" + redirectorKey + - "\n\t LAST_UPDATE=" + timeStamp.getTime() + "\n"); + log.debug("insert into BINDING_TEMPLATE table:\n\n\t" + insertSQL + "\n\t SERVICE_KEY=" + binding.getServiceKey().toString() + "\n\t BINDING_KEY=" + + binding.getBindingKey().toString() + "\n\t ACCESS_POINT_TYPE=" + urlType + "\n\t ACCESS_POINT_URL=" + url + "\n\t HOSTING_REDIRECTOR=" + + redirectorKey + "\n\t LAST_UPDATE=" + timeStamp.getTime() + "\n"); statement.executeUpdate(); + } finally { + try { + statement.close(); + } catch (Exception e) { /* ignored */ } - finally - { - try { statement.close(); } catch (Exception e) { /* ignored */ } } } /** * Delete row from the BINDING_TEMPLATE table. * - * @param bindingKey primary key value - * @param connection JDBC connection + * @param bindingKey + * primary key value + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void delete(String bindingKey,Connection connection) - throws java.sql.SQLException - { + public static void delete(String bindingKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(deleteSQL); statement.setString(1,bindingKey); - log.debug("delete from BINDING_TEMPLATE table:\n\n\t" + deleteSQL + - "\n\t BINDING_KEY=" + bindingKey + "\n"); + log.debug("delete from BINDING_TEMPLATE table:\n\n\t" + deleteSQL + "\n\t BINDING_KEY=" + bindingKey + "\n"); // execute statement.executeUpdate(); + } finally { + try { + statement.close(); + } catch (Exception e) { /* ignored */ + } + } + } + + /** + * Select from the BINDING_TEMPLATE table. + * + * @param bindingKey + * primary key value + * @param connection + * JDBC connection + * @throws java.sql.SQLException + */ + public static List select(List bindingsKeys, Connection connection) throws java.sql.SQLException { + + List results = new ArrayList(); + + PreparedStatement statement = null; + ResultSet resultSet = null; + + try { + DynamicQuery query = new DynamicQuery(); + query.append("(" + selectInSQL); + int count = 0; + for (Iterator i = bindingsKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + count++; + if (i.hasNext()) { + if (count > Config.getMaxInAllowed()) { + count = 0; + query.append(") UNION ALL " + selectInSQL); + } else { + query.append(", "); + } + } + query.addValue(key); + } + + query.append(")) "); + + statement = query.buildPreparedStatement(connection); + statement.setFetchSize(500); + log.debug("select from BINDING_TEMPLATE table:\n\n\t" + query.toString() + "\n"); + + resultSet = statement.executeQuery(); + while (resultSet.next()) { + BindingTemplate binding = null; + binding = new BindingTemplate(); + binding.setServiceKey(resultSet.getString(1));// ("SERVICE_KEY")); + binding.setBindingKey(resultSet.getString(5)); + + String urlType = resultSet.getString(2);// ("ACCESS_POINT_TYPE"); + String url = resultSet.getString(3);// ("ACCESS_POINT_URL"); + if ((urlType != null) && (url != null)) + binding.setAccessPoint(new AccessPoint(urlType, url)); + + String redirectorKey = resultSet.getString(4);// ("HOSTING_REDIRECTOR"); + if (redirectorKey != null) + binding.setHostingRedirector(new HostingRedirector(redirectorKey)); + results.add(binding); + } + + return results; + } finally { + try { + resultSet.close(); + } catch (Exception e) { /* ignored */ + } + try { + statement.close(); + } catch (Exception e) { /* ignored */ } - finally - { - try { statement.close(); } catch (Exception e) { /* ignored */ } } } /** * Select one row from the BINDING_TEMPLATE table. * - * @param bindingKey primary key value - * @param connection JDBC connection + * @param bindingKey + * primary key value + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static BindingTemplate select(String bindingKey,Connection connection) - throws java.sql.SQLException - { + public static BindingTemplate select(String bindingKey, Connection connection) throws java.sql.SQLException { BindingTemplate binding = null; PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { statement = connection.prepareStatement(selectSQL); statement.setString(1,bindingKey.toString()); - log.debug("select from BINDING_TEMPLATE table:\n\n\t" + selectSQL + - "\n\t BINDING_KEY=" + bindingKey.toString() + "\n"); + log.debug("select from BINDING_TEMPLATE table:\n\n\t" + selectSQL + "\n\t BINDING_KEY=" + bindingKey.toString() + "\n"); resultSet = statement.executeQuery(); - if (resultSet.next()) - { + if (resultSet.next()) { binding = new BindingTemplate(); binding.setServiceKey(resultSet.getString(1));//("SERVICE_KEY")); binding.setBindingKey(bindingKey); @@ -234,44 +332,128 @@ } return binding; + } finally { + try { + resultSet.close(); + } catch (Exception e) { /* ignored */ + } + try { + statement.close(); + } catch (Exception e) { /* ignored */ + } + } + } + + /** + * Select all rows from the business_service table for servicesKeys + * + * @param serviceKey + * ServiceKey + * @param connection + * JDBC connection + * @throws java.sql.SQLException + */ + public static Map selectByServicesKeys(List servicesKeys, Connection connection) throws java.sql.SQLException { + Map results = new HashMap(); + PreparedStatement statement = null; + ResultSet resultSet = null; + + try { + + DynamicQuery query = new DynamicQuery(); + query.append("(" + selectByServicesKeysSQL); + int count = 0; + for (Iterator i = servicesKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + count++; + if (i.hasNext()) { + if (count > Config.getMaxInAllowed()) { + count = 0; + query.append(") UNION ALL " + selectByServicesKeysSQL); + } else { + query.append(", "); + } + } + query.addValue(key); + } + + query.append(")) "); + + // create a statement to query with + statement = query.buildPreparedStatement(connection); + + statement.setFetchSize(500); + log.debug("select from BINDING_TEMPLATE table:\n\n\t" + query.toString() + "\n"); + + // execute the statement + resultSet = statement.executeQuery(); + + BindingTemplate binding = null; + while (resultSet.next()) { + binding = new BindingTemplate(); + String serviceKey = resultSet.getString(5); + binding.setServiceKey(serviceKey); + binding.setBindingKey(resultSet.getString(1));// ("BINDING_KEY")); + + String urlType = resultSet.getString(2);// ("ACCESS_POINT_TYPE"); + String url = resultSet.getString(3);// ("ACCESS_POINT_URL"); + if ((urlType != null) && (url != null)) + binding.setAccessPoint(new AccessPoint(urlType, url)); + + String redirectorKey = resultSet.getString(4);// ("HOSTING_REDIRECTOR"); + if (redirectorKey != null) + binding.setHostingRedirector(new HostingRedirector(redirectorKey)); + + Vector bindList = (Vector) results.get(serviceKey); + if (bindList == null) { + bindList = new Vector(); + results.put(serviceKey, bindList); + } + bindList.add(binding); + + binding = null; + } + + return results; + } finally { + try { + resultSet.close(); + } catch (Exception e) { /* ignored */ + } + try { + statement.close(); + } catch (Exception e) { /* ignored */ } - finally - { - try { resultSet.close(); } catch (Exception e) { /* ignored */ } - try { statement.close(); } catch (Exception e) { /* ignored */ } } } /** - * Select all rows from the business_service table for a given - * BusinessKey. + * Select all rows from the business_service table for a given BusinessKey. * - * @param serviceKey ServiceKey - * @param connection JDBC connection + * @param serviceKey + * ServiceKey + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static Vector selectByServiceKey(String serviceKey,Connection connection) - throws java.sql.SQLException - { + public static Vector selectByServiceKey(String serviceKey, Connection connection) throws java.sql.SQLException { Vector bindList = new Vector(); PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { // create a statement to query with statement = connection.prepareStatement(selectByServiceKeySQL); statement.setString(1,serviceKey.toString()); - log.debug("select from BINDING_TEMPLATE table:\n\n\t" + selectByServiceKeySQL + - "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); + log.debug("select from BINDING_TEMPLATE table:\n\n\t" + selectByServiceKeySQL + "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); // execute the statement resultSet = statement.executeQuery(); BindingTemplate binding = null; - while (resultSet.next()) - { + while (resultSet.next()) { binding = new BindingTemplate(); binding.setServiceKey(serviceKey); binding.setBindingKey(resultSet.getString(1));//("BINDING_KEY")); @@ -290,11 +472,15 @@ } return bindList; + } finally { + try { + resultSet.close(); + } catch (Exception e) { /* ignored */ + } + try { + statement.close(); + } catch (Exception e) { /* ignored */ } - finally - { - try { resultSet.close(); } catch (Exception e) { /* ignored */ } - try { statement.close(); } catch (Exception e) { /* ignored */ } } } @@ -302,32 +488,31 @@ * Delete multiple rows from the BINDING_TEMPLATE table that are assigned to * the BusinessKey specified. * - * @param serviceKey ServiceKey - * @param connection JDBC connection + * @param serviceKey + * ServiceKey + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void deleteByServiceKey(String serviceKey,Connection connection) - throws java.sql.SQLException - { + public static void deleteByServiceKey(String serviceKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(deleteByServiceKeySQL); statement.setString(1,serviceKey.toString()); - log.debug("delete from BINDING_TEMPLATE table:\n\n\t" + deleteByServiceKeySQL + - "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); + log.debug("delete from BINDING_TEMPLATE table:\n\n\t" + deleteByServiceKeySQL + "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); // execute int returnCode = statement.executeUpdate(); log.info("delete was successful, rows deleted=" + returnCode); + } finally { + try { + statement.close(); + } catch (Exception e) { /* ignored */ } - finally - { - try { statement.close(); } catch (Exception e) { /* ignored */ } } } @@ -340,9 +525,7 @@ * @param connection * @throws java.sql.SQLException */ - public static boolean verifyOwnership(String bindingKey,String publisherID,Connection connection) - throws java.sql.SQLException - { + public static boolean verifyOwnership(String bindingKey, String publisherID, Connection connection) throws java.sql.SQLException { if ((bindingKey == null) || (publisherID == null)) return false; @@ -350,26 +533,28 @@ PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { statement = connection.prepareStatement(verifyOwnershipSQL); statement.setString(1,bindingKey); statement.setString(2,publisherID); - log.debug("checking ownership of BINDING_TEMPLATE:\n\n\t" + verifyOwnershipSQL + - "\n\t BINDNG_KEY=" + bindingKey + - "\n\t PUBLISHER_ID=" + publisherID + "\n"); + log.debug("checking ownership of BINDING_TEMPLATE:\n\n\t" + verifyOwnershipSQL + "\n\t BINDNG_KEY=" + bindingKey + "\n\t PUBLISHER_ID=" + + publisherID + "\n"); resultSet = statement.executeQuery(); if (resultSet.next()) authorized = true; return authorized; + } finally { + try { + resultSet.close(); + } catch (Exception e) { /* ignored */ + } + try { + statement.close(); + } catch (Exception e) { /* ignored */ } - finally - { - try { resultSet.close(); } catch (Exception e) { /* ignored */ } - try { statement.close(); } catch (Exception e) { /* ignored */ } } } } Index: org/apache/juddi/datastore/jdbc/BusinessDescTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/BusinessDescTable.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/BusinessDescTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/BusinessDescTable.java 6 Jul 2006 16:09:30 -0000 1.2 @@ -18,17 +18,21 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.juddi.datatype.Description; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class BusinessDescTable -{ +class BusinessDescTable { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(BusinessDescTable.class); @@ -33,7 +37,11 @@ private static Log log = LogFactory.getLog(BusinessDescTable.class); static String insertSQL = null; + static String selectSQL = null; + + static String selectInSQL = null; + static String deleteSQL = null; static { @@ -61,6 +69,16 @@ sql.append("ORDER BY BUSINESS_DESCR_ID"); selectSQL = sql.toString(); + // build selectInSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("LANG_CODE,"); + sql.append("DESCR, "); + sql.append("BUSINESS_DESCR_ID, BUSINESS_KEY "); + sql.append("FROM BUSINESS_DESCR "); + sql.append("WHERE BUSINESS_KEY IN ( "); + selectInSQL = sql.toString(); + // build deleteSQL sql = new StringBuffer(100); sql.append("DELETE FROM BUSINESS_DESCR "); @@ -71,60 +89,103 @@ /** * Insert new row into the BUSINESS_DESCR table. * - * @param businessKey BusinessKey to the BusinessEntity object that owns the Description to be inserted - * @param descList Vector of Description objects holding values to be inserted - * @param connection JDBC connection + * @param businessKey + * BusinessKey to the BusinessEntity object that owns the + * Description to be inserted + * @param descList + * Vector of Description objects holding values to be inserted + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void insert( - String businessKey, - Vector descList, - Connection connection) - throws java.sql.SQLException - { + public static void insert(String businessKey, Vector descList, Connection connection) throws java.sql.SQLException { if ((descList == null) || (descList.size() == 0)) return; // everything is valid but no elements to insert PreparedStatement statement = null; - try - { + try { statement = connection.prepareStatement(insertSQL); statement.setString(1, businessKey.toString()); int listSize = descList.size(); - for (int descID = 0; descID < listSize; descID++) - { + for (int descID = 0; descID < listSize; descID++) { Description desc = (Description) descList.elementAt(descID); statement.setInt(2, descID); statement.setString(3, desc.getLanguageCode()); statement.setString(4, desc.getValue()); - log.debug( - "insert into BUSINESS_DESCR table:\n\n\t" - + insertSQL - + "\n\t BUSINESS_KEY=" - + businessKey.toString() - + "\n\t BUSINESS_DESCR_ID=" - + descID - + "\n\t LANG_CODE=" - + desc.getLanguageCode() - + "\n\t DESCR=" - + desc.getValue() - + "\n"); + log.debug("insert into BUSINESS_DESCR table:\n\n\t" + insertSQL + "\n\t BUSINESS_KEY=" + businessKey.toString() + "\n\t BUSINESS_DESCR_ID=" + + descID + "\n\t LANG_CODE=" + desc.getLanguageCode() + "\n\t DESCR=" + desc.getValue() + "\n"); statement.executeUpdate(); } - } - finally - { - try - { + } finally { + try { statement.close(); + } catch (Exception e) { /* ignored */ + } + } + } + + /** + * Select all rows from the BUSINESS_DESCR table for BusinessesKeys. + * + * @param businessKey + * BusinessKey + * @param connection + * JDBC connection + * @throws java.sql.SQLException + */ + public static Map select(List businessesKeys, Connection connection) throws java.sql.SQLException { + + PreparedStatement statement = null; + ResultSet resultSet = null; + Map results = new HashMap(); + + try { + DynamicQuery query = new DynamicQuery(); + query.append(selectInSQL); + + for (Iterator i = businessesKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + if (i.hasNext()) { + query.append(", "); + } + query.addValue(key); + } + + query.append(") "); + query.append("ORDER BY BUSINESS_KEY, BUSINESS_DESCR_ID"); + statement = query.buildPreparedStatement(connection); + + log.debug("select from BUSINESS_DESCR table:\n\n\t" + query.toString() + "\n"); + + // execute the statement + resultSet = statement.executeQuery(); + + Description desc = null; + while (resultSet.next()) { + desc = new Description(); + desc.setLanguageCode(resultSet.getString(1));// ("LANG_CODE")); + desc.setValue(resultSet.getString(2));// ("DESCR")); + String businessKey = resultSet.getString(4); + Vector descList = (Vector) results.get(businessKey); + if (descList == null) { + descList = new Vector(); + results.put(businessKey, descList); } - catch (Exception e) - { /* ignored */ + descList.add(desc); + } + + return results; + } finally { + try { + resultSet.close(); + statement.close(); + } catch (Exception e) { /* ignored */ } } } @@ -132,36 +193,29 @@ /** * Select all rows from the BUSINESS_DESCR table for a given BusinessKey. * - * @param businessKey BusinessKey - * @param connection JDBC connection + * @param businessKey + * BusinessKey + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static Vector select(String businessKey, Connection connection) - throws java.sql.SQLException - { + public static Vector select(String businessKey, Connection connection) throws java.sql.SQLException { Vector descList = new Vector(); PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { // create a statement to query with statement = connection.prepareStatement(selectSQL); statement.setString(1, businessKey.toString()); - log.debug( - "select from BUSINESS_DESCR table:\n\n\t" - + selectSQL - + "\n\t BUSINESS_KEY=" - + businessKey.toString() - + "\n"); + log.debug("select from BUSINESS_DESCR table:\n\n\t" + selectSQL + "\n\t BUSINESS_KEY=" + businessKey.toString() + "\n"); // execute the statement resultSet = statement.executeQuery(); Description desc = null; - while (resultSet.next()) - { + while (resultSet.next()) { desc = new Description(); desc.setLanguageCode(resultSet.getString(1));//("LANG_CODE")); desc.setValue(resultSet.getString(2));//("DESCR")); @@ -169,57 +223,41 @@ } return descList; - } - finally - { - try - { + } finally { + try { resultSet.close(); statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } /** - * Delete multiple rows from the BUSINESS_DESCR table that are assigned to the - * BusinessKey specified. + * Delete multiple rows from the BUSINESS_DESCR table that are assigned to + * the BusinessKey specified. * - * @param businessKey BusinessKey - * @param connection JDBC connection + * @param businessKey + * BusinessKey + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void delete(String businessKey, Connection connection) - throws java.sql.SQLException - { + public static void delete(String businessKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(deleteSQL); statement.setString(1, businessKey.toString()); - log.debug( - "delete from BUSINESS_DESCR table:\n\n\t" - + deleteSQL - + "\n\t BUSINESS_KEY=" - + businessKey.toString() - + "\n"); + log.debug("delete from BUSINESS_DESCR table:\n\n\t" + deleteSQL + "\n\t BUSINESS_KEY=" + businessKey.toString() + "\n"); // execute statement.executeUpdate(); - } - finally - { - try - { + } finally { + try { statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } Index: org/apache/juddi/datastore/jdbc/BusinessNameTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/BusinessNameTable.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/BusinessNameTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/BusinessNameTable.java 6 Jul 2006 16:09:30 -0000 1.2 @@ -18,17 +18,21 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.juddi.datatype.Name; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class BusinessNameTable -{ +class BusinessNameTable { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(BusinessNameTable.class); @@ -33,7 +37,11 @@ private static Log log = LogFactory.getLog(BusinessNameTable.class); static String insertSQL = null; + static String selectSQL = null; + + static String selectInSQL = null; + static String deleteSQL = null; static { @@ -61,6 +69,16 @@ sql.append("ORDER BY BUSINESS_NAME_ID"); selectSQL = sql.toString(); + // build selectInSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("LANG_CODE,"); + sql.append("NAME, "); + sql.append("BUSINESS_NAME_ID, BUSINESS_KEY "); + sql.append("FROM BUSINESS_NAME "); + sql.append("WHERE BUSINESS_KEY IN ( "); + selectInSQL = sql.toString(); + // build deleteSQL sql = new StringBuffer(100); sql.append("DELETE FROM BUSINESS_NAME "); @@ -71,60 +89,103 @@ /** * Insert new row into the BUSINESS_NAME table. * - * @param businessKey String to the BusinessEntity object that owns the Contact to be inserted - * @param nameList Vector of Phone objects holding values to be inserted - * @param connection JDBC connection + * @param businessKey + * String to the BusinessEntity object that owns the Contact to + * be inserted + * @param nameList + * Vector of Phone objects holding values to be inserted + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void insert( - String businessKey, - Vector nameList, - Connection connection) - throws java.sql.SQLException - { + public static void insert(String businessKey, Vector nameList, Connection connection) throws java.sql.SQLException { if ((nameList == null) || (nameList.size() == 0)) return; // everything is valid but no elements to insert PreparedStatement statement = null; - try - { + try { statement = connection.prepareStatement(insertSQL); statement.setString(1, businessKey.toString()); int listSize = nameList.size(); - for (int nameID = 0; nameID < listSize; nameID++) - { + for (int nameID = 0; nameID < listSize; nameID++) { Name name = (Name) nameList.elementAt(nameID); statement.setInt(2, nameID); statement.setString(3, name.getLanguageCode()); statement.setString(4, name.getValue()); - log.debug( - "insert into BUSINESS_NAME table:\n\n\t" - + insertSQL - + "\n\t BUSINESS_KEY=" - + businessKey.toString() - + "\n\t BUSINESS_NAME_ID=" - + nameID - + "\n\t LANG_CODE=" - + name.getLanguageCode() - + "\n\t NAME=" - + name.getValue() - + "\n"); + log.debug("insert into BUSINESS_NAME table:\n\n\t" + insertSQL + "\n\t BUSINESS_KEY=" + businessKey.toString() + "\n\t BUSINESS_NAME_ID=" + + nameID + "\n\t LANG_CODE=" + name.getLanguageCode() + "\n\t NAME=" + name.getValue() + "\n"); statement.executeUpdate(); } - } - finally - { - try - { + } finally { + try { statement.close(); + } catch (Exception e) { /* ignored */ + } } - catch (Exception e) - { /* ignored */ + } + + /** + * Select all rows from the BUSINESS_NAME table for BusinessesKeys. + * + * @param businessKey + * String + * @param connection + * JDBC connection + * @throws java.sql.SQLException + */ + public static Map select(List businessesKeys, Connection connection) throws java.sql.SQLException { + + PreparedStatement statement = null; + ResultSet resultSet = null; + Map results = new HashMap(); + try { + DynamicQuery query = new DynamicQuery(); + query.append(selectInSQL); + + for (Iterator i = businessesKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + if (i.hasNext()) { + query.append(", "); + } + query.addValue(key); + } + + query.append(") "); + query.append("ORDER BY BUSINESS_KEY, BUSINESS_NAME_ID"); + + // create a statement to query with + statement = query.buildPreparedStatement(connection); + + log.debug("select from the BUSINESS_NAME table:\n\n\t" + query.toString() + "\n"); + + // execute the statement + resultSet = statement.executeQuery(); + while (resultSet.next()) { + Name name = new Name(); + name.setValue(resultSet.getString(2));// ("NAME")); + name.setLanguageCode(resultSet.getString(1));// ("LANG_CODE")); + + String businessKey = resultSet.getString(4); + Vector nameList = (Vector) results.get(businessKey); + if (nameList == null) { + nameList = new Vector(); + results.put(businessKey, nameList); + } + nameList.add(name); + } + + return results; + } finally { + try { + resultSet.close(); + statement.close(); + } catch (Exception e) { /* ignored */ } } } @@ -132,34 +193,27 @@ /** * Select all rows from the BUSINESS_NAME table for a given BusinessKey. * - * @param businessKey String - * @param connection JDBC connection + * @param businessKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static Vector select(String businessKey, Connection connection) - throws java.sql.SQLException - { + public static Vector select(String businessKey, Connection connection) throws java.sql.SQLException { Vector nameList = new Vector(); PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { // create a statement to query with statement = connection.prepareStatement(selectSQL); statement.setString(1, businessKey.toString()); - log.debug( - "select from the BUSINESS_NAME table:\n\n\t" - + selectSQL - + "\n\t BUSINESS_KEY=" - + businessKey.toString() - + "\n"); + log.debug("select from the BUSINESS_NAME table:\n\n\t" + selectSQL + "\n\t BUSINESS_KEY=" + businessKey.toString() + "\n"); // execute the statement resultSet = statement.executeQuery(); - while (resultSet.next()) - { + while (resultSet.next()) { Name name = new Name(); name.setValue(resultSet.getString(2));//("NAME")); name.setLanguageCode(resultSet.getString(1));//("LANG_CODE")); @@ -167,57 +221,41 @@ } return nameList; - } - finally - { - try - { + } finally { + try { resultSet.close(); statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } /** - * Delete multiple rows from the BUSINESS_NAME table that are assigned - * to the BusinessKey specified. + * Delete multiple rows from the BUSINESS_NAME table that are assigned to + * the BusinessKey specified. * - * @param businessKey String - * @param connection JDBC connection + * @param businessKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void delete(String businessKey, Connection connection) - throws java.sql.SQLException - { + public static void delete(String businessKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(deleteSQL); statement.setString(1, businessKey.toString()); - log.debug( - "delete from the BUSINESS_NAME table:\n\n\t" - + deleteSQL - + "\n\t BUSINESS_KEY=" - + businessKey.toString() - + "\n"); + log.debug("delete from the BUSINESS_NAME table:\n\n\t" + deleteSQL + "\n\t BUSINESS_KEY=" + businessKey.toString() + "\n"); // execute statement.executeUpdate(); - } - finally - { - try - { + } finally { + try { statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } Index: org/apache/juddi/datastore/jdbc/BusinessServiceTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/BusinessServiceTable.java,v retrieving revision 1.1 retrieving revision 1.3 diff -u -w -B -r1.1 -r1.3 --- org/apache/juddi/datastore/jdbc/BusinessServiceTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/BusinessServiceTable.java 11 Jul 2006 09:13:02 -0000 1.3 @@ -19,17 +19,23 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.juddi.datatype.service.BusinessService; +import org.apache.juddi.util.Config; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class BusinessServiceTable -{ +class BusinessServiceTable { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(BusinessServiceTable.class); @@ -34,14 +40,22 @@ private static Log log = LogFactory.getLog(BusinessServiceTable.class); static String insertSQL = null; + static String deleteSQL = null; + static String selectSQL = null; + + static String selectInSQL = null; + static String selectByBusinessKeySQL = null; + + static String selectInByBusinessKeySQL = null; + static String deleteByBusinessKeySQL = null; + static String verifyOwnershipSQL = null; - static - { + static { // buffer used to build SQL statements StringBuffer sql = null; @@ -68,6 +82,14 @@ sql.append("WHERE SERVICE_KEY=?"); selectSQL = sql.toString(); + // build selectINSQL + sql = new StringBuffer(100); + sql.append("SELECT "); + sql.append("SERVICE_KEY, BUSINESS_KEY "); + sql.append("FROM BUSINESS_SERVICE "); + sql.append("WHERE SERVICE_KEY IN ("); + selectInSQL = sql.toString(); + // build selectByBusinessKeySQL sql = new StringBuffer(200); sql.append("SELECT "); @@ -76,6 +98,14 @@ sql.append("WHERE BUSINESS_KEY=?"); selectByBusinessKeySQL = sql.toString(); + // build selectInByBusinessKeySQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("SERVICE_KEY, BUSINESS_KEY "); + sql.append("FROM BUSINESS_SERVICE "); + sql.append("WHERE BUSINESS_KEY IN ("); + selectInByBusinessKeySQL = sql.toString(); + // build deleteByBusinessKeySQL sql = new StringBuffer(100); sql.append("DELETE FROM BUSINESS_SERVICE "); @@ -96,102 +126,165 @@ /** * Insert new row into the BUSINESS_ENTITIES table. * - * @param service object holding values to be inserted - * @param connection JDBC connection + * @param service + * object holding values to be inserted + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void insert(BusinessService service,Connection connection) - throws java.sql.SQLException - { + public static void insert(BusinessService service, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; Timestamp timeStamp = new Timestamp(System.currentTimeMillis()); - try - { + try { statement = connection.prepareStatement(insertSQL); statement.setString(1,service.getBusinessKey().toString()); statement.setString(2,service.getServiceKey().toString()); statement.setTimestamp(3,timeStamp); - log.debug("insert into BUSINESS_SERVICE table:\n\n\t" + insertSQL + - "\n\t BUSINESS_KEY=" + service.getBusinessKey().toString() + - "\n\t SERVICE_KEY=" + service.getServiceKey().toString() + - "\n\t LAST_UPDATE=" + timeStamp.getTime() + "\n"); + log.debug("insert into BUSINESS_SERVICE table:\n\n\t" + insertSQL + "\n\t BUSINESS_KEY=" + service.getBusinessKey().toString() + + "\n\t SERVICE_KEY=" + service.getServiceKey().toString() + "\n\t LAST_UPDATE=" + timeStamp.getTime() + "\n"); statement.executeUpdate(); + } finally { + try { + statement.close(); + } catch (Exception e) { /* ignored */ } - finally - { - try { statement.close(); } catch (Exception e) { /* ignored */ } } } /** * Delete row from the BUSINESS_SERVICE table. * - * @param serviceKey Primary key value - * @param connection JDBC connection + * @param serviceKey + * Primary key value + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void delete(String serviceKey,Connection connection) - throws java.sql.SQLException - { + public static void delete(String serviceKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare statement = connection.prepareStatement(deleteSQL); statement.setString(1,serviceKey.toString()); - log.debug("delete from BUSINESS_SERVICE table:\n\n\t" + deleteSQL + - "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); + log.debug("delete from BUSINESS_SERVICE table:\n\n\t" + deleteSQL + "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); // execute statement.executeUpdate(); + } finally { + try { + statement.close(); + } catch (Exception e) { /* ignored */ + } + } + } + + /** + * Select rows from the BUSINESS_SERVICE table. + * + * @param servicesKeys + * primary keys values + * @param connection + * JDBC connection + * @throws java.sql.SQLException + */ + public static List select(List servicesKeys, Connection connection) throws java.sql.SQLException { + + PreparedStatement statement = null; + ResultSet resultSet = null; + ArrayList services = new ArrayList(); + + try { + DynamicQuery query = new DynamicQuery(); + query.append("(" + selectInSQL); + int count=0; + + for (Iterator i = servicesKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + query.addValue(key); + + + count++; + if (i.hasNext()) { + if (count > Config.getMaxInAllowed()) { + count = 0; + query.append(") UNION ALL " + selectInSQL); + } else { + query.append(", "); + } + } + } + + query.append("))"); + + statement = query.buildPreparedStatement(connection); + + log.debug("select from BUSINESS_SERVICE table:\n\n\t" + query.toString() + "\n"); + + resultSet = statement.executeQuery(); + while (resultSet.next()) { + BusinessService service = null; + service = new BusinessService(); + service.setBusinessKey(resultSet.getString("BUSINESS_KEY")); + service.setServiceKey(resultSet.getString("SERVICE_KEY")); + services.add(service); + } + + return services; + } finally { + try { + resultSet.close(); + } catch (Exception e) { /* ignored */ + } + try { + statement.close(); + } catch (Exception e) { /* ignored */ } - finally - { - try { statement.close(); } catch (Exception e) { /* ignored */ } } } /** * Select one row from the BUSINESS_SERVICE table. * - * @param serviceKey primary key value - * @param connection JDBC connection + * @param serviceKey + * primary key value + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static BusinessService select(String serviceKey,Connection connection) - throws java.sql.SQLException - { + public static BusinessService select(String serviceKey, Connection connection) throws java.sql.SQLException { BusinessService service = null; PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { statement = connection.prepareStatement(selectSQL); statement.setString(1,serviceKey.toString()); - log.debug("select from BUSINESS_SERVICE table:\n\n\t" + selectSQL + - "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); + log.debug("select from BUSINESS_SERVICE table:\n\n\t" + selectSQL + "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); resultSet = statement.executeQuery(); - if (resultSet.next()) - { + if (resultSet.next()) { service = new BusinessService(); service.setBusinessKey(resultSet.getString(1));//("BUSINESS_KEY")); service.setServiceKey(serviceKey); } return service; + } finally { + try { + resultSet.close(); + } catch (Exception e) { /* ignored */ + } + try { + statement.close(); + } catch (Exception e) { /* ignored */ } - finally - { - try { resultSet.close(); } catch (Exception e) { /* ignored */ } - try { statement.close(); } catch (Exception e) { /* ignored */ } } } @@ -199,61 +292,123 @@ * Delete multiple rows from the BUSINESS_SERVICE table that are assigned to * the BusinessKey specified. * - * @param businessKey BusinessKey - * @param connection JDBC connection + * @param businessKey + * BusinessKey + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void deleteByBusinessKey(String businessKey,Connection connection) - throws java.sql.SQLException - { + public static void deleteByBusinessKey(String businessKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(deleteByBusinessKeySQL); statement.setString(1,businessKey.toString()); - log.debug("delet from the BUSINESS_SERVICE table:\n\n\t" + deleteByBusinessKeySQL + - "\n\t BUSINESS_KEY=" + businessKey.toString() + "\n"); + log.debug("delet from the BUSINESS_SERVICE table:\n\n\t" + deleteByBusinessKeySQL + "\n\t BUSINESS_KEY=" + businessKey.toString() + "\n"); // execute statement.executeUpdate(); + } finally { + try { + statement.close(); + } catch (Exception e) { /* ignored */ + } + } + } + + /** + * Select all rows from the business_service table for BusinessesKeys. + * + * @param businessKey + * BusinessKey + * @param connection + * JDBC connection + * @throws java.sql.SQLException + */ + public static Map selectByBusinessKey(List businessesKeys, Connection connection) throws java.sql.SQLException { + + PreparedStatement statement = null; + ResultSet resultSet = null; + + Map results = new HashMap(); + + try { + DynamicQuery query = new DynamicQuery(); + query.append(selectInByBusinessKeySQL); + + for (Iterator i = businessesKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + if (i.hasNext()) { + query.append(", "); + } + query.addValue(key); + } + + query.append(") "); + query.append("ORDER BY BUSINESS_KEY"); + + // create a statement to query with + statement = query.buildPreparedStatement(connection); + + log.debug("select from BUSINESS_SERVICE table:\n\n\t" + query.toString() + "\n"); + + // execute the statement + resultSet = statement.executeQuery(); + while (resultSet.next()) { + BusinessService service = new BusinessService(); + String businessKey = resultSet.getString(2); + service.setBusinessKey(businessKey); + service.setServiceKey(resultSet.getString(1));// ("SERVICE_KEY")); + + Vector serviceList = (Vector) results.get(businessKey); + if (serviceList == null) { + serviceList = new Vector(); + results.put(businessKey, serviceList); + } + + serviceList.add(service); + } + + return results; + } finally { + try { + resultSet.close(); + } catch (Exception e) { /* ignored */ + } + try { + statement.close(); + } catch (Exception e) { /* ignored */ } - finally - { - try { statement.close(); } catch (Exception e) { /* ignored */ } } } /** - * Select all rows from the business_service table for - * a given BusinessKey. + * Select all rows from the business_service table for a given BusinessKey. * - * @param businessKey BusinessKey - * @param connection JDBC connection + * @param businessKey + * BusinessKey + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static Vector selectByBusinessKey(String businessKey,Connection connection) - throws java.sql.SQLException - { + public static Vector selectByBusinessKey(String businessKey, Connection connection) throws java.sql.SQLException { Vector serviceList = new Vector(); PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { // create a statement to query with statement = connection.prepareStatement(selectByBusinessKeySQL); statement.setString(1,businessKey.toString()); - log.debug("select from BUSINESS_SERVICE table:\n\n\t" + selectByBusinessKeySQL + - "\n\t BUSINESS_KEY=" + businessKey.toString() + "\n"); + log.debug("select from BUSINESS_SERVICE table:\n\n\t" + selectByBusinessKeySQL + "\n\t BUSINESS_KEY=" + businessKey.toString() + "\n"); // execute the statement resultSet = statement.executeQuery(); - while (resultSet.next()) - { + while (resultSet.next()) { BusinessService service = new BusinessService(); service.setBusinessKey(businessKey); service.setServiceKey(resultSet.getString(1));//("SERVICE_KEY")); @@ -261,11 +416,15 @@ } return serviceList; + } finally { + try { + resultSet.close(); + } catch (Exception e) { /* ignored */ + } + try { + statement.close(); + } catch (Exception e) { /* ignored */ } - finally - { - try { resultSet.close(); } catch (Exception e) { /* ignored */ } - try { statement.close(); } catch (Exception e) { /* ignored */ } } } @@ -278,9 +437,7 @@ * @param connection * @throws java.sql.SQLException */ - public static boolean verifyOwnership(String serviceKey,String publisherID,Connection connection) - throws java.sql.SQLException - { + public static boolean verifyOwnership(String serviceKey, String publisherID, Connection connection) throws java.sql.SQLException { if ((serviceKey == null) || (publisherID == null)) return false; @@ -288,26 +445,28 @@ PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { statement = connection.prepareStatement(verifyOwnershipSQL); statement.setString(1,serviceKey); statement.setString(2,publisherID); - log.debug("checking ownership of BUSINESS_SERVICE:\n\n\t" + verifyOwnershipSQL + - "\n\t SERVICE_KEY=" + serviceKey + - "\n\t PUBLISHER_ID=" + publisherID + "\n"); + log.debug("checking ownership of BUSINESS_SERVICE:\n\n\t" + verifyOwnershipSQL + "\n\t SERVICE_KEY=" + serviceKey + "\n\t PUBLISHER_ID=" + + publisherID + "\n"); resultSet = statement.executeQuery(); if (resultSet.next()) authorized = true; return authorized; + } finally { + try { + resultSet.close(); + } catch (Exception e) { /* ignored */ + } + try { + statement.close(); + } catch (Exception e) { /* ignored */ } - finally - { - try { resultSet.close(); } catch (Exception e) { /* ignored */ } - try { statement.close(); } catch (Exception e) { /* ignored */ } } } } Index: org/apache/juddi/datastore/jdbc/FindBindingByCategoryQuery.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/FindBindingByCategoryQuery.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/FindBindingByCategoryQuery.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/FindBindingByCategoryQuery.java 3 Jul 2006 07:53:03 -0000 1.2 @@ -306,7 +306,7 @@ { if (keysIn == null) return; - + // TODO CORRECT IN sql.append("AND B.BINDING_KEY IN ("); int keyCount = keysIn.size(); Index: org/apache/juddi/datastore/jdbc/FindBindingByServiceKeyQuery.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/FindBindingByServiceKeyQuery.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/FindBindingByServiceKeyQuery.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/FindBindingByServiceKeyQuery.java 3 Jul 2006 07:53:03 -0000 1.2 @@ -129,7 +129,7 @@ { if (keysIn == null) return; - + // TODO CORRECT IN sql.append("AND B.BINDING_KEY IN ("); int keyCount = keysIn.size(); Index: org/apache/juddi/datastore/jdbc/FindBindingByTModelKeyQuery.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/FindBindingByTModelKeyQuery.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/FindBindingByTModelKeyQuery.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/FindBindingByTModelKeyQuery.java 3 Jul 2006 07:53:03 -0000 1.2 @@ -226,7 +226,7 @@ { if (keysIn == null) return; - + // TODO IN sql.append("AND T.BINDING_KEY IN ("); int keyCount = keysIn.size(); Index: org/apache/juddi/datastore/jdbc/FindBusinessByCategoryQuery.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/FindBusinessByCategoryQuery.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/FindBusinessByCategoryQuery.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/FindBusinessByCategoryQuery.java 3 Jul 2006 07:53:03 -0000 1.2 @@ -285,7 +285,7 @@ { if (keysIn == null) return; - + // TODO IN sql.append("AND B.BUSINESS_KEY IN ("); int keyCount = keysIn.size(); Index: org/apache/juddi/datastore/jdbc/FindBusinessByDiscoveryURLQuery.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/FindBusinessByDiscoveryURLQuery.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/FindBusinessByDiscoveryURLQuery.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/FindBusinessByDiscoveryURLQuery.java 3 Jul 2006 07:53:03 -0000 1.2 @@ -163,6 +163,7 @@ if (keysIn == null) return; + // TODO IN sql.append("AND B.BUSINESS_KEY IN ("); int keyCount = keysIn.size(); Index: org/apache/juddi/datastore/jdbc/FindBusinessByIdentifierQuery.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/FindBusinessByIdentifierQuery.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/FindBusinessByIdentifierQuery.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/FindBusinessByIdentifierQuery.java 3 Jul 2006 07:53:03 -0000 1.2 @@ -166,7 +166,7 @@ { if (keysIn == null) return; - + // TODO IN sql.append("AND B.BUSINESS_KEY IN ("); int keyCount = keysIn.size(); Index: org/apache/juddi/datastore/jdbc/FindBusinessByNameQuery.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/FindBusinessByNameQuery.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/FindBusinessByNameQuery.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/FindBusinessByNameQuery.java 3 Jul 2006 07:53:03 -0000 1.2 @@ -187,6 +187,7 @@ if (keysIn == null) return; + // TODO CORRECT IN sql.append("AND B.BUSINESS_KEY IN ("); int keyCount = keysIn.size(); Index: org/apache/juddi/datastore/jdbc/FindBusinessByTModelKeyQuery.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/FindBusinessByTModelKeyQuery.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/FindBusinessByTModelKeyQuery.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/FindBusinessByTModelKeyQuery.java 3 Jul 2006 07:53:03 -0000 1.2 @@ -228,7 +228,7 @@ { if (keysIn == null) return; - + // TODO CORRECT IN sql.append("AND B.BUSINESS_KEY IN ("); int keyCount = keysIn.size(); Index: org/apache/juddi/datastore/jdbc/FindServiceByNameQuery.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/FindServiceByNameQuery.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/FindServiceByNameQuery.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/FindServiceByNameQuery.java 11 Jul 2006 09:13:02 -0000 1.2 @@ -24,19 +24,18 @@ import org.apache.commons.logging.LogFactory; import org.apache.juddi.datatype.Name; import org.apache.juddi.datatype.request.FindQualifiers; +import org.apache.juddi.util.Config; import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class FindServiceByNameQuery -{ +class FindServiceByNameQuery { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(FindServiceByNameQuery.class); static String selectSQL; - static - { + static { // build selectSQL StringBuffer sql = new StringBuffer(200); sql.append("SELECT S.SERVICE_KEY,S.LAST_UPDATE,N.NAME "); @@ -47,16 +46,16 @@ /** * Select ... * - * @param businessKey primary key value + * @param businessKey + * primary key value * @param names * @param keysIn * @param qualifiers - * @param connection JDBC connection + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static Vector select(String businessKey,Vector names,Vector keysIn,FindQualifiers qualifiers,Connection connection) - throws java.sql.SQLException - { + public static Vector select(String businessKey, Vector names, Vector keysIn, FindQualifiers qualifiers, Connection connection) throws java.sql.SQLException { // if there is a keysIn vector but it doesn't contain // any keys then the previous query has exhausted // all possibilities of a match so skip this call. @@ -73,8 +72,7 @@ appendIn(sql,keysIn); appendOrderBy(sql,qualifiers); - try - { + try { log.debug(sql.toString()); statement = sql.buildPreparedStatement(connection); @@ -84,25 +82,17 @@ keysOut.addElement(resultSet.getString(1));//("SERVICE_KEY")); return keysOut; - } - finally - { + } finally { try { resultSet.close(); - } - catch (Exception e) - { - log.warn("An Exception was encountered while attempting to close " + - "the Find BusinessService ResultSet: "+e.getMessage(),e); + } catch (Exception e) { + log.warn("An Exception was encountered while attempting to close " + "the Find BusinessService ResultSet: " + e.getMessage(), e); } try { statement.close(); - } - catch (Exception e) - { - log.warn("An Exception was encountered while attempting to close " + - "the Find BusinessService Statement: "+e.getMessage(),e); + } catch (Exception e) { + log.warn("An Exception was encountered while attempting to close " + "the Find BusinessService Statement: " + e.getMessage(), e); } } } @@ -110,62 +100,48 @@ /** * */ - private static void appendWhere(DynamicQuery sql,String businessKey,Vector names,FindQualifiers qualifiers) - { + private static void appendWhere(DynamicQuery sql, String businessKey, Vector names, FindQualifiers qualifiers) { sql.append("WHERE N.SERVICE_KEY = S.SERVICE_KEY "); // per UDDI v2.0 Programmers API Errata (pg. 14), businessKey is // is no longer a required attribute of the find_service server. - if((businessKey != null) && (businessKey.length() > 0)) - { + if ((businessKey != null) && (businessKey.length() > 0)) { sql.append("AND S.BUSINESS_KEY = ? "); sql.addValue(businessKey); } - if (names != null) - { + if (names != null) { int nameSize = names.size(); - if (nameSize > 0) - { + if (nameSize > 0) { sql.append("AND ("); - for (int i=0; i 0)) - { + if ((text != null) && (text.length() > 0)) { if (qualifiers == null) // default { sql.append("(UPPER(NAME) LIKE ?"); sql.addValue(text.endsWith("%") ? text.toUpperCase() : text.toUpperCase()+"%"); - } - else if ((qualifiers.caseSensitiveMatch) && (qualifiers.exactNameMatch)) - { + } else if ((qualifiers.caseSensitiveMatch) && (qualifiers.exactNameMatch)) { sql.append("(NAME = ?"); sql.addValue(text); - } - else if ((!qualifiers.caseSensitiveMatch) && (qualifiers.exactNameMatch)) - { + } else if ((!qualifiers.caseSensitiveMatch) && (qualifiers.exactNameMatch)) { sql.append("(UPPER(NAME) = ?"); sql.addValue(text.toUpperCase()); - } - else if ((qualifiers.caseSensitiveMatch) && (!qualifiers.exactNameMatch)) - { + } else if ((qualifiers.caseSensitiveMatch) && (!qualifiers.exactNameMatch)) { sql.append("(NAME LIKE ?"); sql.addValue(text.endsWith("%") ? text : text+"%"); - } - else if ((!qualifiers.caseSensitiveMatch) && (!qualifiers.exactNameMatch)) - { + } else if ((!qualifiers.caseSensitiveMatch) && (!qualifiers.exactNameMatch)) { sql.append("(UPPER(NAME) LIKE ?"); sql.addValue(text.endsWith("%") ? text.toUpperCase() : text.toUpperCase()+"%"); } - // If lang is "en" we'll need to match with "en", "en_US" or "en_UK" - if ((lang != null) && (lang.length() > 0)) - { + // If lang is "en" we'll need to match with "en", + // "en_US" or "en_UK" + if ((lang != null) && (lang.length() > 0)) { sql.append(" AND (UPPER(LANG_CODE) LIKE ?)"); sql.addValue(lang.toUpperCase()+"%"); } @@ -183,31 +159,39 @@ } /** - * Utility method used to construct SQL "IN" statements such as - * the following SQL example: + * Utility method used to construct SQL "IN" statements such as the + * following SQL example: * * SELECT * FROM TABLE WHERE MONTH IN ('jan','feb','mar') * - * @param sql StringBuffer to append the final results to - * @param keysIn Vector of Strings used to construct the "IN" clause + * @param sql + * StringBuffer to append the final results to + * @param keysIn + * Vector of Strings used to construct the "IN" clause */ - private static void appendIn(DynamicQuery sql,Vector keysIn) - { + private static void appendIn(DynamicQuery sql, Vector keysIn) { if (keysIn == null) return; sql.append("AND S.SERVICE_KEY IN ("); int keyCount = keysIn.size(); - for (int i=0; i Config.getMaxInAllowed()) { + count = 0; + sql.append(") OR S.SERVICE_KEY IN ("); + } else { sql.append(","); } + } + } sql.append(") "); } @@ -215,20 +199,14 @@ /** * */ - private static void appendOrderBy(DynamicQuery sql,FindQualifiers qualifiers) - { + private static void appendOrderBy(DynamicQuery sql, FindQualifiers qualifiers) { sql.append("ORDER BY "); - if ((qualifiers == null) || - ((!qualifiers.sortByNameAsc) && (!qualifiers.sortByNameDesc) && - (!qualifiers.sortByDateAsc) && (!qualifiers.sortByDateDesc))) - { + if ((qualifiers == null) + || ((!qualifiers.sortByNameAsc) && (!qualifiers.sortByNameDesc) && (!qualifiers.sortByDateAsc) && (!qualifiers.sortByDateDesc))) { sql.append("N.NAME ASC,S.LAST_UPDATE DESC"); - } - else if (qualifiers.sortByNameAsc || qualifiers.sortByNameDesc) - { - if (qualifiers.sortByDateAsc || qualifiers.sortByDateDesc) - { + } else if (qualifiers.sortByNameAsc || qualifiers.sortByNameDesc) { + if (qualifiers.sortByDateAsc || qualifiers.sortByDateDesc) { if (qualifiers.sortByNameAsc && qualifiers.sortByDateDesc) sql.append("N.NAME ASC,S.LAST_UPDATE DESC"); else if (qualifiers.sortByNameAsc && qualifiers.sortByDateAsc) @@ -237,17 +215,13 @@ sql.append("N.NAME DESC,S.LAST_UPDATE DESC"); else sql.append("N.NAME DESC,S.LAST_UPDATE ASC"); - } - else - { + } else { if (qualifiers.sortByNameAsc) sql.append("N.NAME ASC,S.LAST_UPDATE DESC"); else sql.append("N.NAME DESC,S.LAST_UPDATE DESC"); } - } - else if (qualifiers.sortByDateAsc || qualifiers.sortByDateDesc) - { + } else if (qualifiers.sortByDateAsc || qualifiers.sortByDateDesc) { if (qualifiers.sortByDateDesc) sql.append("S.LAST_UPDATE ASC,N.NAME ASC"); else Index: org/apache/juddi/datastore/jdbc/JDBCDataStore.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/JDBCDataStore.java,v retrieving revision 1.1 retrieving revision 1.5 diff -u -w -B -r1.1 -r1.5 --- org/apache/juddi/datastore/jdbc/JDBCDataStore.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/JDBCDataStore.java 11 Jul 2006 09:13:02 -0000 1.5 @@ -17,6 +17,11 @@ import java.sql.Connection; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; @@ -64,8 +69,7 @@ * @author Steve Viens (sviens@apache.org) * @author Anil Saldhana (anil@apache.org) */ -public class JDBCDataStore implements DataStore -{ +public class JDBCDataStore implements DataStore { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(JDBCDataStore.class); @@ -76,58 +80,47 @@ private Transaction transaction = null; /** - * Create a new JDBCDataStore and aquire a JDBC - * connection from the connection pool. + * Create a new JDBCDataStore and aquire a JDBC connection from the + * connection pool. */ - public JDBCDataStore() - { + public JDBCDataStore() { try { this.connection = ConnectionManager.aquireConnection(); - } - catch(SQLException sqlex) { - log.error("Exception occured while attempting to " + - "aquire a JDBC connection: "+sqlex.getMessage()); + } catch (SQLException sqlex) { + log.error("Exception occured while attempting to " + "aquire a JDBC connection: " + sqlex.getMessage()); } } /** - * Release all JDBC connections used by this - * JDBCDataStore back into the connection pool. + * Release all JDBC connections used by this JDBCDataStore back into the + * connection pool. */ - public void release() - { + public void release() { try { - if (connection != null) - { + if (connection != null) { this.connection.close(); this.connection = null; } - } - catch(SQLException sqlex) { - log.error("Exception occured while attempting to " + - "close a JDBC connection: "+sqlex.getMessage()); + } catch (SQLException sqlex) { + log.error("Exception occured while attempting to " + "close a JDBC connection: " + sqlex.getMessage()); } } /** * */ - public Connection getConnection() - { + public Connection getConnection() { return this.connection; } /** * begin a new transaction */ - public void beginTrans() - throws org.apache.juddi.error.RegistryException - { + public void beginTrans() throws org.apache.juddi.error.RegistryException { try { this.transaction = new Transaction(); this.transaction.begin(connection); - } - catch(SQLException sqlex) { + } catch (SQLException sqlex) { throw new RegistryException(sqlex); } } @@ -135,13 +128,10 @@ /** * commit on all connections. */ - public void commit() - throws org.apache.juddi.error.RegistryException - { + public void commit() throws org.apache.juddi.error.RegistryException { try { this.transaction.commit(); - } - catch(SQLException sqlex) { + } catch (SQLException sqlex) { throw new RegistryException(sqlex); } } @@ -149,28 +139,23 @@ /** * rollback on all connections. */ - public void rollback() - throws org.apache.juddi.error.RegistryException - { + public void rollback() throws org.apache.juddi.error.RegistryException { try { this.transaction.rollback(); - } - catch(SQLException sqlex) { + } catch (SQLException sqlex) { throw new RegistryException(sqlex); } } /** - * verify that the individual or system identified by - * the 'publisherID' is a valid jUDDI user (aka publisher). + * verify that the individual or system identified by the 'publisherID' is a + * valid jUDDI user (aka publisher). * * @param publisherID * @return publisher * @throws RegistryException */ - public Publisher getPublisher(String publisherID) - throws RegistryException - { + public Publisher getPublisher(String publisherID) throws RegistryException { // a publisherID must be specified. if (publisherID == null) return null; @@ -179,8 +164,7 @@ try { publisher = PublisherTable.select(publisherID,connection); - } - catch(java.sql.SQLException sqlex) { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } @@ -198,54 +182,44 @@ * administrator priv's otherwise returns false. * @throws RegistryException */ - public boolean isAdministrator(String publisherID) - throws org.apache.juddi.error.RegistryException - { + public boolean isAdministrator(String publisherID) throws org.apache.juddi.error.RegistryException { if ((publisherID == null) || (publisherID.length() == 0)) throw new UnknownUserException("publisherID = "+publisherID); - try - { + try { Publisher publisher = PublisherTable.select(publisherID,connection); if (publisher == null) throw new UnknownUserException("publisherID = "+publisherID); else return publisher.isAdmin(); - } - catch(java.sql.SQLException sqlex) - { + } catch (java.sql.SQLException sqlex) { log.error(sqlex.getMessage()); throw new RegistryException(sqlex); } } /** - * Will return true if the publisherID parameter specified is - * currently enabled otherwise returns false. An UnknownUserException - * is thrown if the publisherID specified is null, blank or does not - * exist (can't be found in the PUBLISHER table). + * Will return true if the publisherID parameter specified is currently + * enabled otherwise returns false. An UnknownUserException is thrown if the + * publisherID specified is null, blank or does not exist (can't be found in + * the PUBLISHER table). * * @param publisherID * @return Returns true if publisherID parameter specified has jUDDI * administrator priv's otherwise returns false. * @throws RegistryException */ - public boolean isEnabled(String publisherID) - throws org.apache.juddi.error.RegistryException - { + public boolean isEnabled(String publisherID) throws org.apache.juddi.error.RegistryException { if ((publisherID == null) || (publisherID.length() == 0)) throw new UnknownUserException("publisherID = "+publisherID); - try - { + try { Publisher publisher = PublisherTable.select(publisherID,connection); if (publisher == null) throw new UnknownUserException("publisherID = "+publisherID); else return publisher.isEnabled(); - } - catch(java.sql.SQLException sqlex) - { + } catch (java.sql.SQLException sqlex) { log.error(sqlex.getMessage()); throw new RegistryException(sqlex); } @@ -257,15 +231,12 @@ * @return String * @throws RegistryException */ - public String generateToken(Publisher publisher) - throws RegistryException - { + public String generateToken(Publisher publisher) throws RegistryException { UUIDGen uuidgen = UUIDGenFactory.getUUIDGen(); String token = "authToken:"+uuidgen.uuidgen(); - log.info("Generated token '"+token+"' for user: '" + - publisher.getPublisherID()+"/"+publisher.getName()+"'"); + log.info("Generated token '" + token + "' for user: '" + publisher.getPublisherID() + "/" + publisher.getName() + "'"); return token; } @@ -273,15 +244,11 @@ /** * */ - public void storeAuthToken(String token,Publisher publisher) - throws org.apache.juddi.error.RegistryException - { - if ((token != null) && (publisher != null)) - { + public void storeAuthToken(String token, Publisher publisher) throws org.apache.juddi.error.RegistryException { + if ((token != null) && (publisher != null)) { try { AuthTokenTable.insert(token,publisher,connection); - } - catch(java.sql.SQLException sqlex) { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } } @@ -290,16 +257,12 @@ /** * */ - public void retireAuthToken(String token) - throws org.apache.juddi.error.RegistryException - { - if (token != null) - { + public void retireAuthToken(String token) throws org.apache.juddi.error.RegistryException { + if (token != null) { try { AuthTokenTable.invalidate(token,connection); AuthTokenTable.touch(token,connection); - } - catch(java.sql.SQLException sqlex) { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } } @@ -308,17 +271,13 @@ /** * */ - public Publisher getAuthTokenPublisher(String token) - throws org.apache.juddi.error.RegistryException - { + public Publisher getAuthTokenPublisher(String token) throws org.apache.juddi.error.RegistryException { Publisher publisher = null; - if (token != null) - { + if (token != null) { try { publisher = AuthTokenTable.selectPublisher(token,connection); - } - catch(java.sql.SQLException sqlex) { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } } @@ -329,15 +288,11 @@ /** * */ - public boolean isAuthTokenExpired(String token) - throws org.apache.juddi.error.RegistryException - { + public boolean isAuthTokenExpired(String token) throws org.apache.juddi.error.RegistryException { boolean expired = false; - if (token != null) - { - try - { + if (token != null) { + try { long tokenState = AuthTokenTable.selectTokenState(token, connection); if (tokenState <= 0) { return expired = true; @@ -346,13 +301,16 @@ long lastUsed = AuthTokenTable.selectLastUsed(token,connection); if (lastUsed > 0) // -1 is returned when token isn't found { - long timeOut = Config.getLongProperty("juddi.authTokenTimeout",3600) * 1000L; // convert from seconds to milliseconds + long timeOut = Config.getLongProperty("juddi.authTokenTimeout", 3600) * 1000L; // convert + // from + // seconds + // to + // milliseconds long currTime = System.currentTimeMillis(); if ((currTime-lastUsed) >= timeOut) expired = true; } - } - catch(java.sql.SQLException sqlex) { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } } @@ -363,15 +321,11 @@ /** * */ - public void touchAuthToken(String token) - throws org.apache.juddi.error.RegistryException - { - if (token != null) - { + public void touchAuthToken(String token) throws org.apache.juddi.error.RegistryException { + if (token != null) { try { AuthTokenTable.touch(token,connection); - } - catch(java.sql.SQLException sqlex) { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } } @@ -380,13 +334,9 @@ /** * */ - public void saveBusiness(BusinessEntity business,String publisherID) - throws org.apache.juddi.error.RegistryException - { - try - { - if ((business != null) && (connection != null)) - { + public void saveBusiness(BusinessEntity business, String publisherID) throws org.apache.juddi.error.RegistryException { + try { + if ((business != null) && (connection != null)) { String businessKey = business.getBusinessKey(); // insert the BusinessEntity object @@ -417,18 +367,16 @@ // insert the BusinessEntity's Contact objects & information Contacts contacts = business.getContacts(); - if (contacts != null) - { + if (contacts != null) { Vector contactVector = contacts.getContactVector(); - if ((contactVector != null) && (contactVector.size() > 0)) - { + if ((contactVector != null) && (contactVector.size() > 0)) { // insert the BusinessEntity's Contact objects ContactTable.insert(businessKey,contacts.getContactVector(),connection); - // insert the BusinessEntity's Contact Phone, Address and Email Info + // insert the BusinessEntity's Contact Phone, Address + // and Email Info int listSize = contactVector.size(); - for (int contactID=0; contactID 0)) - { + if ((addrList != null) && (addrList.size() > 0)) { AddressTable.insert(businessKey,contactID,addrList,connection); - for (int addrID=0; addrID 0) - { + if (idVector.size() > 0) { IdentifierBag identifierBag = new IdentifierBag(); identifierBag.setKeyedReferenceVector(idVector); business.setIdentifierBag(identifierBag); } Vector catVector = BusinessCategoryTable.select(businessKey,connection); - if (catVector.size() > 0) - { + if (catVector.size() > 0) { CategoryBag categoryBag = new CategoryBag(); categoryBag.setKeyedReferenceVector(catVector); business.setCategoryBag(categoryBag); @@ -513,18 +450,15 @@ DiscoveryURLs discoveryURLs = new DiscoveryURLs(); discoveryURLs.setDiscoveryURLVector(DiscoveryURLTable.select(businessKey,connection)); business.setDiscoveryURLs(discoveryURLs); - // 'select' the BusinessEntity's Contact objects Vector contactList = ContactTable.select(businessKey,connection); - for (int contactID=0; contactID 0) - { + if (catVector.size() > 0) { CategoryBag bag = new CategoryBag(); bag.setKeyedReferenceVector(catVector); service.setCategoryBag(bag); @@ -722,9 +625,7 @@ bindings.setBindingTemplateVector(bindingVector); service.setBindingTemplates(bindings); } - } - catch(java.sql.SQLException sqlex) - { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } @@ -734,14 +635,11 @@ /** * */ - public void deleteService(String serviceKey) - throws org.apache.juddi.error.RegistryException - { - try - { - if ((serviceKey != null) && (connection != null)) - { - // delete the BusinessService's BindingTemplates (and dependents) + public void deleteService(String serviceKey) throws org.apache.juddi.error.RegistryException { + try { + if ((serviceKey != null) && (connection != null)) { + // delete the BusinessService's BindingTemplates (and + // dependents) deleteBindingByServiceKey(serviceKey); // delete the immediate dependents of BusinessService @@ -752,9 +650,7 @@ // finally, delete the BusinessService itself. BusinessServiceTable.delete(serviceKey,connection); } - } - catch(java.sql.SQLException sqlex) - { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } } @@ -762,25 +658,28 @@ /** * */ - private Vector fetchServiceByBusinessKey(String businessKey) - throws org.apache.juddi.error.RegistryException - { + private Vector fetchServiceByBusinessKey(String businessKey) throws org.apache.juddi.error.RegistryException { Vector serviceList = new Vector(); - try - { - if ((businessKey != null) && (connection != null)) - { + try { + if ((businessKey != null) && (connection != null)) { + Vector tempList = BusinessServiceTable.selectByBusinessKey(businessKey,connection); - for (int i=0; i 0)) TModelDocDescTable.insert(tModelKey,descVector,connection); } } - } - catch(java.sql.SQLException sqlex) - { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } } @@ -1154,24 +1028,18 @@ /** * */ - public TModel fetchTModel(String tModelKey) - throws org.apache.juddi.error.RegistryException - { + public TModel fetchTModel(String tModelKey) throws org.apache.juddi.error.RegistryException { TModel tModel = null; - try - { - if ((tModelKey != null) && (connection != null)) - { + try { + if ((tModelKey != null) && (connection != null)) { tModel = TModelTable.select(tModelKey,connection); - if (tModel != null) - { + if (tModel != null) { tModel.setDescriptionVector(TModelDescTable.select(tModelKey,connection)); // fetch the TModel CategoryBag Vector catVector = TModelCategoryTable.select(tModelKey,connection); - if ((catVector != null) && (catVector.size() != 0)) - { + if ((catVector != null) && (catVector.size() != 0)) { CategoryBag catBag = new CategoryBag(); catBag.setKeyedReferenceVector(catVector); tModel.setCategoryBag(catBag); @@ -1179,8 +1047,7 @@ // fetch the TModel IdentifierBag Vector idVector = TModelIdentifierTable.select(tModelKey,connection); - if ((idVector != null) && (idVector.size() != 0)) - { + if ((idVector != null) && (idVector.size() != 0)) { IdentifierBag idBag = new IdentifierBag(); idBag.setKeyedReferenceVector(idVector); tModel.setIdentifierBag(idBag); @@ -1188,16 +1055,13 @@ // fetch the TModel OverviewDoc & OverviewDoc Descrptions OverviewDoc overDoc = tModel.getOverviewDoc(); - if (overDoc != null) - { + if (overDoc != null) { overDoc.setDescriptionVector(TModelDocDescTable.select(tModelKey,connection)); tModel.setOverviewDoc(overDoc); } } } - } - catch(java.sql.SQLException sqlex) - { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } @@ -1207,13 +1071,9 @@ /** * */ - public void deleteTModel(String tModelKey) - throws org.apache.juddi.error.RegistryException - { - try - { - if ((tModelKey != null) && (connection != null)) - { + public void deleteTModel(String tModelKey) throws org.apache.juddi.error.RegistryException { + try { + if ((tModelKey != null) && (connection != null)) { // delete the dependents of TModel TModelCategoryTable.delete(tModelKey,connection); TModelDescTable.delete(tModelKey,connection); @@ -1223,9 +1083,7 @@ // delete the TModel TModelTable.delete(tModelKey,connection); } - } - catch(java.sql.SQLException sqlex) - { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } } @@ -1233,19 +1091,13 @@ /** * */ - public void markTModelAsDeleted(String tModelKey) - throws org.apache.juddi.error.RegistryException - { - try - { - if ((tModelKey != null) && (connection != null)) - { + public void markTModelAsDeleted(String tModelKey) throws org.apache.juddi.error.RegistryException { + try { + if ((tModelKey != null) && (connection != null)) { // mark the TModel as deleted TModelTable.markAsDeleted(tModelKey,connection); } - } - catch(java.sql.SQLException sqlex) - { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } } @@ -1253,17 +1105,11 @@ /** * */ - public boolean isValidTModelKey(String tModelKey) - throws org.apache.juddi.error.RegistryException - { - try - { - if ((tModelKey != null) && (connection != null) && - (TModelTable.select(tModelKey,connection) != null)) + public boolean isValidTModelKey(String tModelKey) throws org.apache.juddi.error.RegistryException { + try { + if ((tModelKey != null) && (connection != null) && (TModelTable.select(tModelKey, connection) != null)) return true; - } - catch(java.sql.SQLException sqlex) - { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } @@ -1274,16 +1120,11 @@ /** * */ - public boolean isTModelPublisher(String tModelKey,String publisherID) - throws org.apache.juddi.error.RegistryException - { - try - { + public boolean isTModelPublisher(String tModelKey, String publisherID) throws org.apache.juddi.error.RegistryException { + try { if ((publisherID != null) && (tModelKey != null) && (connection != null)) return TModelTable.verifyOwnership(tModelKey,publisherID,connection); - } - catch(java.sql.SQLException sqlex) - { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } @@ -1294,23 +1135,17 @@ /** * */ - public BusinessInfo fetchBusinessInfo(String businessKey) - throws org.apache.juddi.error.RegistryException - { + public BusinessInfo fetchBusinessInfo(String businessKey) throws org.apache.juddi.error.RegistryException { BusinessInfo info = null; - if ((businessKey != null) && (connection != null)) - { - try - { + if ((businessKey != null) && (connection != null)) { + try { info = new BusinessInfo(); info.setBusinessKey(businessKey); info.setNameVector(BusinessNameTable.select(businessKey,connection)); info.setDescriptionVector(BusinessDescTable.select(businessKey,connection)); info.setServiceInfos(fetchServiceInfosByBusinessKey(businessKey)); - } - catch(java.sql.SQLException sqlex) - { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } } @@ -1321,18 +1156,88 @@ /** * */ - private ServiceInfos fetchServiceInfosByBusinessKey(String businessKey) - throws org.apache.juddi.error.RegistryException - { - Vector serviceInfoVector = new Vector(); + private Map fetchServicesInfosByBusinessesKeys(List businessesKeys) throws org.apache.juddi.error.RegistryException { - if ((businessKey != null) && (connection != null)) - { - try - { + Map results = new HashMap(); + + try { + Map servicesMap = BusinessServiceTable.selectByBusinessKey(businessesKeys, connection); + + // create a list of all services to query names only once + ArrayList allServices = new ArrayList(); + for (Iterator iter = servicesMap.entrySet().iterator(); iter.hasNext();) { + + Map.Entry entry = (Map.Entry) iter.next(); + List list = (List) entry.getValue(); + for (Iterator jter = list.iterator(); jter.hasNext();) { + BusinessService s = (BusinessService) jter.next(); + allServices.add(s.getServiceKey()); + } + } + Map servicesNamesMap = ServiceNameTable.select(allServices, connection); + + // + for (Iterator iter = businessesKeys.iterator(); iter.hasNext();) { + String businessKey = (String) iter.next(); + + Vector serviceInfoVector = new Vector(); + + if ((businessKey != null) && (connection != null)) { + + List l = (List) servicesMap.get(businessKey); + Vector services = null; + if (l == null) { + services = new Vector(); + } else + services = new Vector(l); + + for (int i = 0; i < services.size(); i++) { + // make a reference to this BusinessServce to + // easily harvest ServiceInfo data from it. + BusinessService service = (BusinessService) services.elementAt(i); + String serviceKey = service.getServiceKey(); + + // okay, create a new ServiceInfo + ServiceInfo info = new ServiceInfo(); + info.setServiceKey(serviceKey); + info.setBusinessKey(businessKey); + + Vector v = null; + l = (List) servicesNamesMap.get(serviceKey); + if (l == null) { + v = new Vector(); + } else + v = new Vector(l); + + info.setNameVector(v); + + // add this ServiceInfo to the ServiceInfo vector + serviceInfoVector.add(info); + } + + } + + ServiceInfos serviceInfos = new ServiceInfos(); + serviceInfos.setServiceInfoVector(serviceInfoVector); + results.put(businessKey, serviceInfos); + } + } catch (java.sql.SQLException sqlex) { + throw new RegistryException(sqlex); + } + + return results; + } + + /** + * + */ + private ServiceInfos fetchServiceInfosByBusinessKey(String businessKey) throws org.apache.juddi.error.RegistryException { + Vector serviceInfoVector = new Vector(); + + if ((businessKey != null) && (connection != null)) { + try { Vector services = BusinessServiceTable.selectByBusinessKey(businessKey,connection); - for (int i=0; i 0)) keyVector = FindBusinessByDiscoveryURLQuery.select(discoveryURLs,keyVector,findQualifiers,connection); - if ((findQualifiers != null) && (findQualifiers.orAllKeys)) - { + if ((findQualifiers != null) && (findQualifiers.orAllKeys)) { // orAllKeys = Use logical "OR" when searching by categoryBag // or tModelBag. See UDDI v2.04 API Specification - Appendix E. @@ -1443,33 +1356,25 @@ if ((categoryBag != null) && (categoryBag.size() > 0)) keyVector = FindBusinessByCategoryQuery.select(categoryBag,keyVector,findQualifiers,connection); - } - else - { + } else { // Default UDDI v2 behavior: Use logical "AND" when searching // by categoryBagor tModelBag. See Appendix E of the UDDI v2.04 // API Specification. - if ((tModelBag != null) && (tModelBag.size() > 0)) - { + if ((tModelBag != null) && (tModelBag.size() > 0)) { Vector tModelKeyVector = tModelBag.getTModelKeyVector(); - if (tModelKeyVector != null) - { - for (int i=0; i 0)) - { + if ((categoryBag != null) && (categoryBag.size() > 0)) { Vector keyedRefVector = categoryBag.getKeyedReferenceVector(); - if (keyedRefVector != null) - { - for (int i=0; i 0)) keyVector = FindServiceByCategoryQuery.select(businessKey,categoryBag,keyVector,findQualifiers,connection); - } - else - { + } else { // Default UDDI v2 behavior: Use logical "AND" when searching // by categoryBagor tModelBag. See Appendix E of the UDDI v2.04 // API Specification. - if ((tModelBag != null) && (tModelBag.size() > 0)) - { + if ((tModelBag != null) && (tModelBag.size() > 0)) { Vector tModelKeyVector = tModelBag.getTModelKeyVector(); - if (tModelKeyVector != null) - { - for (int i=0; i 0)) - { + if ((categoryBag != null) && (categoryBag.size() > 0)) { Vector keyedRefVector = categoryBag.getKeyedReferenceVector(); - if (keyedRefVector != null) - { - for (int i=0; i 0)) keyVector = FindTModelByCategoryQuery.select(categoryBag,keyVector,findQualifiers,connection); - } - else - { + } else { // Default UDDI v2 behavior: Use logical "AND" when searching - // by category bag. See UDDI v2.04 API Specification - Appendix E. + // by category bag. See UDDI v2.04 API Specification - Appendix + // E. // - if ((categoryBag != null) && (categoryBag.size() > 0)) - { + if ((categoryBag != null) && (categoryBag.size() > 0)) { Vector keyedRefVector = categoryBag.getKeyedReferenceVector(); - if (keyedRefVector != null) - { - for (int i=0; i 0)) keyVector = FindBindingByTModelKeyQuery.select(serviceKey,tModelBag,keyVector,findQualifiers,connection); if ((categoryBag != null) && (categoryBag.size() > 0)) keyVector = FindBindingByCategoryQuery.select(serviceKey,categoryBag,keyVector,findQualifiers,connection); - } - else - { + } else { // Default UDDI v2 behavior: Use logical "AND" when searching // by tModel bag. See UDDI v2.04 API Specification - Appendix E. - if ((tModelBag != null) && (tModelBag.size() > 0)) - { + if ((tModelBag != null) && (tModelBag.size() > 0)) { Vector tModelKeyVector = tModelBag.getTModelKeyVector(); - if (tModelKeyVector != null) - { - for (int i=0; i 0)) - { + if ((categoryBag != null) && (categoryBag.size() > 0)) { Vector keyedRefVector = categoryBag.getKeyedReferenceVector(); - if (keyedRefVector != null) - { - for (int i=0; i 0) PublisherAssertionTable.deleteDeadAssertions(connection); - } - catch(java.sql.SQLException sqlex) - { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } } @@ -1955,21 +1801,16 @@ * managing by calling: BusinessEntityTable.selectByPublisherID(publisherID) * * 2. Retrieve all PublisherAssertion's that publisherID has made by - * calling: PublisherAssertionTable.selectAssertions(Vector) where - * 'Vector' is the collection of BusinessKey's returned in step 2. + * calling: PublisherAssertionTable.selectAssertions(Vector) where 'Vector' + * is the collection of BusinessKey's returned in step 2. */ - public Vector getAssertions(String publisherID) - throws org.apache.juddi.error.RegistryException - { + public Vector getAssertions(String publisherID) throws org.apache.juddi.error.RegistryException { Vector assertions = null; - try - { + try { Vector keys = BusinessEntityTable.selectByPublisherID(publisherID,connection); assertions = PublisherAssertionTable.selectAssertions(keys,connection); - } - catch(java.sql.SQLException sqlex) - { + } catch (java.sql.SQLException sqlex) { throw new RegistryException(sqlex); } @@ -1984,12 +1825,10 @@ * 2. With the Vector of PublisherAssertions retrieved in step 1 call * DataSource.deleteAssertions(publisherID,Vector) * - * 3. With the Vector of PublisherAssertions passed into this method - * call: DataSource.addAssertions(publisherID,Vector) + * 3. With the Vector of PublisherAssertions passed into this method call: + * DataSource.addAssertions(publisherID,Vector) */ - public Vector setAssertions(String publisherID,Vector newAssertions) - throws org.apache.juddi.error.RegistryException - { + public Vector setAssertions(String publisherID, Vector newAssertions) throws org.apache.juddi.error.RegistryException { // grab all existing PublisherAssertions with this publisherID Vector oldAssertions = getAssertions(publisherID); @@ -2005,32 +1844,36 @@ /** * * 1. Retrieve Vector of BusinessKeys for BusinessEntities managed by - * publisherID by calling: BusinessEntityTable.selectByPublisherID(publisherID) + * publisherID by calling: + * BusinessEntityTable.selectByPublisherID(publisherID) * - * 2. Call PublisherAssertionTable.selectBothKeysOwnedAssertions(Vector of BusinessKeys) + * 2. Call PublisherAssertionTable.selectBothKeysOwnedAssertions(Vector of + * BusinessKeys) * - * 3. Call PublisherAssertionTable.selectFromKeyOwnedAssertions(Vector of BusinessKeys) + * 3. Call PublisherAssertionTable.selectFromKeyOwnedAssertions(Vector of + * BusinessKeys) * - * 4. Call PublisherAssertionTable.selectToKeyOwnedAssertions(Vector of BusinessKeys) + * 4. Call PublisherAssertionTable.selectToKeyOwnedAssertions(Vector of + * BusinessKeys) * * 5. Combine Vectors from steps 3, 4 and 5 above into one Vector of * AssertionStatusItem instances * - * 5. Loop through Vector from step 6 copying only AssertionStatusItem instances - * that have a CompletionStatus that matches the completionStatus requested. + * 5. Loop through Vector from step 6 copying only AssertionStatusItem + * instances that have a CompletionStatus that matches the completionStatus + * requested. */ - public Vector getAssertionStatusItems(String publisherID,String completionStatus) - throws org.apache.juddi.error.RegistryException - { + public Vector getAssertionStatusItems(String publisherID, String completionStatus) throws org.apache.juddi.error.RegistryException { Vector items = null; - try - { + try { // grab a Vector of BusinessKeys managed by PublisherID Vector keys = BusinessEntityTable.selectByPublisherID(publisherID,connection); - // grab any PublisherAssertion (as an AssertionStatusItem) that includes - // any of the BusinessKeys returned above in the TO_KEY or FROM_KEY field. + // grab any PublisherAssertion (as an AssertionStatusItem) that + // includes + // any of the BusinessKeys returned above in the TO_KEY or FROM_KEY + // field. Vector allItems = new Vector(); allItems.addAll(PublisherAssertionTable.selectBothKeysOwnedAssertion(keys,connection)); allItems.addAll(PublisherAssertionTable.selectFromKeyOwnedAssertion(keys,connection)); @@ -2041,24 +1884,20 @@ // the 'completionStatus' specified. if ((completionStatus == null) || (completionStatus.length() == 0)) items = allItems; - else - { + else { // create the Vector to return if (allItems.size() > 0) items = new Vector(); // evaluate every AssertionStatusItem - for (int i=0; i 0) { + CategoryBag bag = new CategoryBag(); + bag.setKeyedReferenceVector(catVector); + service.setCategoryBag(bag); + } + + // 'fetch' the BusinessService's BindingTemplate objects + Vector bindingVector = new Vector((List) bindingsMap.get(serviceKey)); + BindingTemplates bindings = new BindingTemplates(); + bindings.setBindingTemplateVector(bindingVector); + service.setBindingTemplates(bindings); + } + + } + } catch (java.sql.SQLException sqlex) { + throw new RegistryException(sqlex); + } + + return services; + } + + public List fetchBusinessesInfos(List businessesKeys) throws RegistryException { + + ArrayList results = new ArrayList(); + try { + Map namesMap = BusinessNameTable.select(businessesKeys, connection); + Map descMap = BusinessDescTable.select(businessesKeys, connection); + + Map infoMap = fetchServicesInfosByBusinessesKeys(businessesKeys); + + for (Iterator iter = businessesKeys.iterator(); iter.hasNext();) { + BusinessInfo info = null; + + String businessKey = (String) iter.next(); + + if ((businessKey != null) && (connection != null)) { + + info = new BusinessInfo(); + info.setBusinessKey(businessKey); + + List l = (List) namesMap.get(businessKey); + Vector v = null; + if (l == null) { + v = new Vector(); + } else + v = new Vector(l); + + info.setNameVector(v); + + l = (List) descMap.get(businessKey); + + if (l == null) { + v = new Vector(); + } else + v = new Vector(l); + + info.setDescriptionVector(v); + + ServiceInfos infos = (ServiceInfos) infoMap.get(businessKey); + + info.setServiceInfos(infos); + + } + results.add(info); + } + } catch (java.sql.SQLException sqlex) { + throw new RegistryException(sqlex); + } + return results; } + public List fetchBindings(List bindingsKeys) throws RegistryException { + + List bindings = new ArrayList(); + + try { + + List bindingTemplates = BindingTemplateTable.select(bindingsKeys, connection); + Map descMap = BindingDescTable.select(bindingsKeys, connection); + Map categMap = BindingCategoryTable.select(bindingsKeys, connection); + Map infoVectorsMap = TModelInstanceInfoTable.select(bindingsKeys, connection); + + Map infoDescMap = TModelInstanceInfoDescTable.select(bindingsKeys, connection); + + for (Iterator i = bindingTemplates.iterator(); i.hasNext();) { + BindingTemplate binding = (BindingTemplate) i.next(); + String bindingKey = binding.getBindingKey(); + if ((bindingKey != null) && (connection != null)) { + + List l = (List) descMap.get(bindingKey); + Vector v; + if (l == null) { + v = new Vector(); + } else + v = new Vector(l); + binding.setDescriptionVector(v); + + // fetch the BindingTemplate's CategoryBag (UDDI v3.0) + CategoryBag bag = new CategoryBag(); + + l = (List) categMap.get(bindingKey); + + if (l == null) { + v = new Vector(); + } else + v = new Vector(l); + + bag.setKeyedReferenceVector(v); + binding.setCategoryBag(bag); + + // fetch the BindingTemplate's TModelInstanceInfos + + l = (List) infoVectorsMap.get(bindingKey); + + Vector infoVector = null; + if (l != null) { + infoVector = new Vector(l); + Map map = (Map) infoDescMap.get(bindingKey); + + int vectorSize = infoVector.size(); + for (int infoID = 0; infoID < vectorSize; infoID++) { + TModelInstanceInfo info = (TModelInstanceInfo) infoVector.elementAt(infoID); + + // fetch the TModelInstanceInfo Descriptions + + if (map != null) { + Vector vec = (Vector) map.get(new Integer(infoID)); + if (vec == null) { + vec = new Vector(); + } + info.setDescriptionVector(vec); + } + InstanceDetails instDetails = info.getInstanceDetails(); + if (instDetails != null) { + // fetch the InstanceDetail Descriptions + instDetails.setDescriptionVector(InstanceDetailsDescTable.select(bindingKey, infoID, connection)); + + // fetch the InstanceDetail OverviewDoc + // Descrptions + OverviewDoc overDoc = instDetails.getOverviewDoc(); + if (overDoc != null) { + overDoc.setDescriptionVector(InstanceDetailsDocDescTable.select(bindingKey, infoID, connection)); + instDetails.setOverviewDoc(overDoc); + } + } + } + + TModelInstanceDetails details = new TModelInstanceDetails(); + details.setTModelInstanceInfoVector(infoVector); + binding.setTModelInstanceDetails(details); + } + bindings.add(binding); + } + + } + } catch (java.sql.SQLException sqlex) { + throw new RegistryException(sqlex); + } + + return bindings; + } + + public List fetchTModels(List tModelsKeys) throws RegistryException { + + List tModels = null; + try { + tModels = TModelTable.select(tModelsKeys, connection); + Map descMap = TModelDescTable.select(tModelsKeys, connection); + Map categMap = TModelCategoryTable.select(tModelsKeys, connection); + Map idMap = TModelIdentifierTable.select(tModelsKeys, connection); + Map docMap = TModelDocDescTable.select(tModelsKeys, connection); + + for (Iterator i = tModels.iterator(); i.hasNext();) { + TModel tModel = (TModel) i.next(); + String tModelKey = tModel.getTModelKey(); + if (tModel != null) { + + List l = (List) descMap.get(tModelKey); + Vector v = new Vector(); + if (l != null) { + v.addAll(l); + } + + tModel.setDescriptionVector(v); + + // fetch the TModel CategoryBag + l = (List) categMap.get(tModelKey); + if ((l != null) && (l.size() != 0)) { + CategoryBag catBag = new CategoryBag(); + catBag.setKeyedReferenceVector(new Vector(l)); + tModel.setCategoryBag(catBag); + } + + // fetch the TModel IdentifierBag + l = (List) idMap.get(tModelKey); + if ((l != null) && (l.size() != 0)) { + IdentifierBag idBag = new IdentifierBag(); + idBag.setKeyedReferenceVector(new Vector(l)); + tModel.setIdentifierBag(idBag); + } + + // fetch the TModel OverviewDoc & OverviewDoc + // Descrptions + OverviewDoc overDoc = tModel.getOverviewDoc(); + if (overDoc != null) { + l = (List) docMap.get(tModelKey); + v = new Vector(); + if (l != null) { + v.addAll(l); + } + + overDoc.setDescriptionVector(v); + tModel.setOverviewDoc(overDoc); + } + + } + + } + } catch (java.sql.SQLException sqlex) { + throw new RegistryException(sqlex); + } + return tModels; + } + +} Index: org/apache/juddi/datastore/jdbc/ServiceCategoryTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/ServiceCategoryTable.java,v retrieving revision 1.1 retrieving revision 1.4 diff -u -w -B -r1.1 -r1.4 --- org/apache/juddi/datastore/jdbc/ServiceCategoryTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/ServiceCategoryTable.java 11 Jul 2006 09:13:02 -0000 1.4 @@ -18,17 +18,22 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.juddi.datatype.KeyedReference; +import org.apache.juddi.util.Config; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class ServiceCategoryTable -{ +class ServiceCategoryTable { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(ServiceCategoryTable.class); @@ -33,7 +38,11 @@ private static Log log = LogFactory.getLog(ServiceCategoryTable.class); static String insertSQL = null; + static String selectSQL = null; + + static String selectInSQL = null; + static String deleteSQL = null; static { @@ -63,6 +72,17 @@ sql.append("ORDER BY CATEGORY_ID"); selectSQL = sql.toString(); + // build selectInSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("TMODEL_KEY_REF,"); + sql.append("KEY_NAME,"); + sql.append("KEY_VALUE, "); + sql.append("CATEGORY_ID, SERVICE_KEY "); + sql.append("FROM SERVICE_CATEGORY "); + sql.append("WHERE SERVICE_KEY IN ( "); + selectInSQL = sql.toString(); + // build deleteSQL sql = new StringBuffer(100); sql.append("DELETE FROM SERVICE_CATEGORY "); @@ -73,27 +93,23 @@ /** * Insert new row into the SERVICE_CATEGORY table. * - * @param serviceKey String to the parent BusinessService object. - * @param keyRefs A Vector of KeyedReference instances to insert. - * @param connection JDBC connection + * @param serviceKey + * String to the parent BusinessService object. + * @param keyRefs + * A Vector of KeyedReference instances to insert. + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void insert( - String serviceKey, - Vector keyRefs, - Connection connection) - throws java.sql.SQLException - { + public static void insert(String serviceKey, Vector keyRefs, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { statement = connection.prepareStatement(insertSQL); statement.setString(1, serviceKey.toString()); int listSize = keyRefs.size(); - for (int categoryID = 0; categoryID < listSize; categoryID++) - { + for (int categoryID = 0; categoryID < listSize; categoryID++) { KeyedReference keyRef = (KeyedReference) keyRefs.elementAt(categoryID); // extract values to insert @@ -107,33 +123,87 @@ statement.setString(4, keyRef.getKeyName()); statement.setString(5, keyRef.getKeyValue()); - log.debug( - "insert into SERVICE_CATEGORY table:\n\n\t" - + insertSQL - + "\n\t SERVICE_KEY=" - + serviceKey.toString() - + "\n\t CATEGORY_ID=" - + categoryID - + "\n\t TMODEL_KEY_REF=" - + tModelKeyValue - + "\n\t KEY_NAME=" - + keyRef.getKeyName() - + "\n\t KEY_VALUE=" - + keyRef.getKeyValue() - + "\n"); + log.debug("insert into SERVICE_CATEGORY table:\n\n\t" + insertSQL + "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n\t CATEGORY_ID=" + + categoryID + "\n\t TMODEL_KEY_REF=" + tModelKeyValue + "\n\t KEY_NAME=" + keyRef.getKeyName() + "\n\t KEY_VALUE=" + + keyRef.getKeyValue() + "\n"); // insert statement.executeUpdate(); } - } - finally - { - try - { + } finally { + try { statement.close(); + } catch (Exception e) { /* ignored */ + } } - catch (Exception e) - { /* ignored */ + } + + /** + * Select all rows from the SERVICE_CATEGORY table for ServicesKeys. + * + * @param serviceKey + * String + * @param connection + * JDBC connection + * @throws java.sql.SQLException + */ + public static Map select(List servicesKeys, Connection connection) throws java.sql.SQLException { + Map results = new HashMap(); + PreparedStatement statement = null; + ResultSet resultSet = null; + + try { + DynamicQuery query = new DynamicQuery(); + query.append("(" + selectInSQL); + int count = 0; + for (Iterator i = servicesKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + count++; + if (i.hasNext()) { + if (count > Config.getMaxInAllowed()) { + count = 0; + query.append(") UNION ALL " + selectInSQL); + } else { + query.append(", "); + } + } + query.addValue(key); + } + + query.append(")) "); + query.append("ORDER BY SERVICE_KEY, CATEGORY_ID"); + + // create a statement to query with + statement = query.buildPreparedStatement(connection); + statement.setFetchSize(500); + + log.debug("select from SERVICE_CATEGORY table:\n\n\t" + query.toString() + "\n"); + + // execute the statement + resultSet = statement.executeQuery(); + while (resultSet.next()) { + KeyedReference keyRef = new KeyedReference(); + keyRef.setTModelKey(resultSet.getString(1));// ("TMODEL_KEY_REF")); + keyRef.setKeyName(resultSet.getString(2));// ("KEY_NAME")); + keyRef.setKeyValue(resultSet.getString(3));// ("KEY_VALUE")); + + String serviceKey = resultSet.getString(5); + Vector keyRefList = (Vector) results.get(serviceKey); + if (keyRefList == null) { + keyRefList = new Vector(); + results.put(serviceKey, keyRefList); + } + keyRefList.add(keyRef); + + } + + return results; + } finally { + try { + resultSet.close(); + statement.close(); + } catch (Exception e) { /* ignored */ } } } @@ -141,34 +211,27 @@ /** * Select all rows from the SERVICE_CATEGORY table for a given ServiceKey. * - * @param serviceKey String - * @param connection JDBC connection + * @param serviceKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static Vector select(String serviceKey, Connection connection) - throws java.sql.SQLException - { + public static Vector select(String serviceKey, Connection connection) throws java.sql.SQLException { Vector keyRefList = new Vector(); PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { // create a statement to query with statement = connection.prepareStatement(selectSQL); statement.setString(1, serviceKey.toString()); - log.debug( - "select from SERVICE_CATEGORY table:\n\n\t" - + selectSQL - + "\n\t SERVICE_KEY=" - + serviceKey.toString() - + "\n"); + log.debug("select from SERVICE_CATEGORY table:\n\n\t" + selectSQL + "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); // execute the statement resultSet = statement.executeQuery(); - while (resultSet.next()) - { + while (resultSet.next()) { KeyedReference keyRef = new KeyedReference(); keyRef.setTModelKey(resultSet.getString(1));//("TMODEL_KEY_REF")); keyRef.setKeyName(resultSet.getString(2));//("KEY_NAME")); @@ -177,57 +240,41 @@ } return keyRefList; - } - finally - { - try - { + } finally { + try { resultSet.close(); statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } /** - * Delete multiple rows from the SERVICE_CATEGORY table that are assigned to the - * ServiceKey specified. + * Delete multiple rows from the SERVICE_CATEGORY table that are assigned to + * the ServiceKey specified. * - * @param serviceKey String - * @param connection JDBC connection + * @param serviceKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void delete(String serviceKey, Connection connection) - throws java.sql.SQLException - { + public static void delete(String serviceKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(deleteSQL); statement.setString(1, serviceKey.toString()); - log.debug( - "delete from SERVICE_CATEGORY table:\n\n\t" - + deleteSQL - + "\n\t SERVICE_KEY=" - + serviceKey.toString() - + "\n"); + log.debug("delete from SERVICE_CATEGORY table:\n\n\t" + deleteSQL + "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); // execute statement.executeUpdate(); - } - finally - { - try - { + } finally { + try { statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } Index: org/apache/juddi/datastore/jdbc/ServiceDescTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/ServiceDescTable.java,v retrieving revision 1.1 retrieving revision 1.3 diff -u -w -B -r1.1 -r1.3 --- org/apache/juddi/datastore/jdbc/ServiceDescTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/ServiceDescTable.java 11 Jul 2006 09:13:02 -0000 1.3 @@ -18,17 +18,22 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.juddi.datatype.Description; +import org.apache.juddi.util.Config; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class ServiceDescTable -{ +class ServiceDescTable { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(ServiceDescTable.class); @@ -33,7 +38,11 @@ private static Log log = LogFactory.getLog(ServiceDescTable.class); static String insertSQL = null; + static String selectSQL = null; + + static String selectInSQL = null; + static String deleteSQL = null; static { @@ -61,6 +70,16 @@ sql.append("ORDER BY SERVICE_DESCR_ID"); selectSQL = sql.toString(); + // build selectInSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("LANG_CODE,"); + sql.append("DESCR, "); + sql.append("SERVICE_DESCR_ID, SERVICE_KEY "); + sql.append("FROM SERVICE_DESCR "); + sql.append("WHERE SERVICE_KEY IN ( "); + selectInSQL = sql.toString(); + // build deleteSQL sql = new StringBuffer(100); sql.append("DELETE FROM SERVICE_DESCR "); @@ -71,60 +90,110 @@ /** * Insert new row into the SERVICE_DESCR table. * - * @param serviceKey String to the BusinessEntity object that owns the Description to be inserted - * @param descList Vector of Description objects holding values to be inserted - * @param connection JDBC connection + * @param serviceKey + * String to the BusinessEntity object that owns the Description + * to be inserted + * @param descList + * Vector of Description objects holding values to be inserted + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void insert( - String serviceKey, - Vector descList, - Connection connection) - throws java.sql.SQLException - { + public static void insert(String serviceKey, Vector descList, Connection connection) throws java.sql.SQLException { if ((descList == null) || (descList.size() == 0)) return; // everything is valid but no elements to insert PreparedStatement statement = null; - try - { + try { statement = connection.prepareStatement(insertSQL); statement.setString(1, serviceKey.toString()); int listSize = descList.size(); - for (int descID = 0; descID < listSize; descID++) - { + for (int descID = 0; descID < listSize; descID++) { Description desc = (Description) descList.elementAt(descID); statement.setInt(2, descID); statement.setString(3, desc.getLanguageCode()); statement.setString(4, desc.getValue()); - log.debug( - "insert into SERVICE_DESCR table:\n\n\t" - + insertSQL - + "\n\t SERVICE_KEY=" - + serviceKey.toString() - + "\n\t SERVICE_DESCR_ID=" - + descID - + "\n\t LANG_CODE=" - + desc.getLanguageCode() - + "\n\t DESCR=" - + desc.getValue() - + "\n"); + log.debug("insert into SERVICE_DESCR table:\n\n\t" + insertSQL + "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n\t SERVICE_DESCR_ID=" + + descID + "\n\t LANG_CODE=" + desc.getLanguageCode() + "\n\t DESCR=" + desc.getValue() + "\n"); statement.executeUpdate(); } - } - finally - { - try - { + } finally { + try { statement.close(); + } catch (Exception e) { /* ignored */ } - catch (Exception e) - { /* ignored */ + } + } + + /** + * Select all rows from the SERVICE_DESCR table for servicesKeys. + * + * @param serviceKey + * String + * @param connection + * JDBC connection + * @throws java.sql.SQLException + */ + public static Map select(List servicesKeys, Connection connection) throws java.sql.SQLException { + Map results = new HashMap(); + PreparedStatement statement = null; + ResultSet resultSet = null; + + try { + DynamicQuery query = new DynamicQuery(); + query.append("(" + selectInSQL); + int count = 0; + for (Iterator i = servicesKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + count++; + if (i.hasNext()) { + if (count > Config.getMaxInAllowed()) { + count = 0; + query.append(") UNION ALL " + selectInSQL); + } else { + query.append(", "); + } + } + query.addValue(key); + } + + query.append(")) "); + query.append("ORDER BY SERVICE_KEY, SERVICE_DESCR_ID"); + + // create a statement to query with + statement = query.buildPreparedStatement(connection); + + log.debug("select from SERVICE_DESCR table:\n\n\t" + query.toString() + "\n"); + + // execute the statement + resultSet = statement.executeQuery(); + + while (resultSet.next()) { + Description desc = new Description(); + desc.setLanguageCode(resultSet.getString(1));// ("LANG_CODE")); + desc.setValue(resultSet.getString(2));// ("DESCR")); + + String serviceKey = resultSet.getString(4); + Vector descList = (Vector) results.get(serviceKey); + if (descList == null) { + descList = new Vector(); + results.put(serviceKey, descList); + } + descList.add(desc); + } + + return results; + } finally { + try { + resultSet.close(); + statement.close(); + } catch (Exception e) { /* ignored */ } } } @@ -132,34 +201,27 @@ /** * Select all rows from the SERVICE_DESCR table for a given BusinessKey. * - * @param serviceKey String - * @param connection JDBC connection + * @param serviceKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static Vector select(String serviceKey, Connection connection) - throws java.sql.SQLException - { + public static Vector select(String serviceKey, Connection connection) throws java.sql.SQLException { Vector descList = new Vector(); PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { // create a statement to query with statement = connection.prepareStatement(selectSQL); statement.setString(1, serviceKey.toString()); - log.debug( - "select from SERVICE_DESCR table:\n\n\t" - + selectSQL - + "\n\t SERVICE_KEY=" - + serviceKey.toString() - + "\n"); + log.debug("select from SERVICE_DESCR table:\n\n\t" + selectSQL + "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); // execute the statement resultSet = statement.executeQuery(); - while (resultSet.next()) - { + while (resultSet.next()) { Description desc = new Description(); desc.setLanguageCode(resultSet.getString(1));//("LANG_CODE")); desc.setValue(resultSet.getString(2));//("DESCR")); @@ -167,57 +229,41 @@ } return descList; - } - finally - { - try - { + } finally { + try { resultSet.close(); statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } /** - * Delete multiple rows from the SERVICE_DESCR table that are assigned to the - * BusinessKey specified. + * Delete multiple rows from the SERVICE_DESCR table that are assigned to + * the BusinessKey specified. * - * @param serviceKey String - * @param connection JDBC connection + * @param serviceKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void delete(String serviceKey, Connection connection) - throws java.sql.SQLException - { + public static void delete(String serviceKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(deleteSQL); statement.setString(1, serviceKey.toString()); - log.debug( - "delete from SERVICE_DESCR table:\n\n\t" - + deleteSQL - + "\n\t SERVICE_KEY=" - + serviceKey.toString() - + "\n"); + log.debug("delete from SERVICE_DESCR table:\n\n\t" + deleteSQL + "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); // execute statement.executeUpdate(); - } - finally - { - try - { + } finally { + try { statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } Index: org/apache/juddi/datastore/jdbc/ServiceNameTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/ServiceNameTable.java,v retrieving revision 1.1 retrieving revision 1.3 diff -u -w -B -r1.1 -r1.3 --- org/apache/juddi/datastore/jdbc/ServiceNameTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/ServiceNameTable.java 11 Jul 2006 09:13:02 -0000 1.3 @@ -18,17 +18,22 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.juddi.datatype.Name; +import org.apache.juddi.util.Config; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class ServiceNameTable -{ +class ServiceNameTable { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(ServiceNameTable.class); @@ -33,7 +38,11 @@ private static Log log = LogFactory.getLog(ServiceNameTable.class); static String insertSQL = null; + static String selectSQL = null; + + static String selectInSQL = null; + static String deleteSQL = null; static { @@ -61,6 +70,16 @@ sql.append("ORDER BY SERVICE_NAME_ID"); selectSQL = sql.toString(); + // build selectInSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("LANG_CODE,"); + sql.append("NAME, "); + sql.append("SERVICE_NAME_ID, SERVICE_KEY "); + sql.append("FROM SERVICE_NAME "); + sql.append("WHERE SERVICE_KEY IN ( "); + selectInSQL = sql.toString(); + // build deleteSQL sql = new StringBuffer(100); sql.append("DELETE FROM SERVICE_NAME "); @@ -71,60 +90,114 @@ /** * Insert new row into the SERVICE_NAME table. * - * @param serviceKey String to the BusinessEntity object that owns the Contact to be inserted - * @param nameList Vector of Name objects holding values to be inserted - * @param connection JDBC connection + * @param serviceKey + * String to the BusinessEntity object that owns the Contact to + * be inserted + * @param nameList + * Vector of Name objects holding values to be inserted + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void insert( - String serviceKey, - Vector nameList, - Connection connection) - throws java.sql.SQLException - { + public static void insert(String serviceKey, Vector nameList, Connection connection) throws java.sql.SQLException { if ((nameList == null) || (nameList.size() == 0)) return; // everything is valid but no elements to insert PreparedStatement statement = null; - try - { + try { statement = connection.prepareStatement(insertSQL); statement.setString(1, serviceKey.toString()); int listSize = nameList.size(); - for (int nameID = 0; nameID < listSize; nameID++) - { + for (int nameID = 0; nameID < listSize; nameID++) { Name name = (Name) nameList.elementAt(nameID); statement.setInt(2, nameID); statement.setString(3, name.getLanguageCode()); statement.setString(4, name.getValue()); - log.debug( - "insert into SERVICE_NAME table:\n\n\t" - + insertSQL - + "\n\t SERVICE_KEY=" - + serviceKey.toString() - + "\n\t SERVICE_NAME_ID=" - + nameID - + "\n\t LANG_CODE=" - + name.getLanguageCode() - + "\n\t NAME=" - + name.getValue() - + "\n"); + log.debug("insert into SERVICE_NAME table:\n\n\t" + insertSQL + "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n\t SERVICE_NAME_ID=" + nameID + + "\n\t LANG_CODE=" + name.getLanguageCode() + "\n\t NAME=" + name.getValue() + "\n"); statement.executeUpdate(); } - } - finally - { - try - { + } finally { + try { statement.close(); + } catch (Exception e) { /* ignored */ + } + } } - catch (Exception e) - { /* ignored */ + + /** + * Select all rows from the SERVICE_NAME table for ServiceKeys. + * + * @param serviceKey + * String + * @param connection + * JDBC connection + * @throws java.sql.SQLException + */ + public static Map select(List servicesKeys, Connection connection) throws java.sql.SQLException { + // Vector nameList = new Vector(); + PreparedStatement statement = null; + ResultSet resultSet = null; + + Map results = new HashMap(); + + try { + DynamicQuery query = new DynamicQuery(); + query.append("("); + query.append(selectInSQL); + int count = 0; + + for (Iterator i = servicesKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + + query.addValue(key); + count++; + if (i.hasNext()) { + if (count > Config.getMaxInAllowed()) { + count = 0; + query.append(") UNION ALL " + selectInSQL); + } else { + query.append(", "); + } + } + } + + query.append(") "); + query.append(" ) ORDER BY SERVICE_KEY, SERVICE_NAME_ID"); + + // create a statement to query with + statement = query.buildPreparedStatement(connection); + + log.debug("select from SERVICE_NAME table:\n\n\t" + query.toString() + "\n"); + + // execute the statement + resultSet = statement.executeQuery(); + while (resultSet.next()) { + Name name = new Name(); + name.setLanguageCode(resultSet.getString(1)); // ("LANG_CODE")); + name.setValue(resultSet.getString(2)); // ("NAME")); + + String serviceKey = resultSet.getString(4); + Vector nameList = (Vector) results.get(serviceKey); + if (nameList == null) { + nameList = new Vector(); + results.put(serviceKey, nameList); + } + nameList.add(name); + } + + return results; + } finally { + try { + statement.close(); + resultSet.close(); + } catch (Exception e) { /* ignored */ } } } @@ -132,34 +205,27 @@ /** * Select all rows from the SERVICE_NAME table for a given ServiceKey. * - * @param serviceKey String - * @param connection JDBC connection + * @param serviceKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static Vector select(String serviceKey, Connection connection) - throws java.sql.SQLException - { + public static Vector select(String serviceKey, Connection connection) throws java.sql.SQLException { Vector nameList = new Vector(); PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { // create a statement to query with statement = connection.prepareStatement(selectSQL); statement.setString(1, serviceKey.toString()); - log.debug( - "select from SERVICE_NAME table:\n\n\t" - + selectSQL - + "\n\t SERVICE_KEY=" - + serviceKey.toString() - + "\n"); + log.debug("select from SERVICE_NAME table:\n\n\t" + selectSQL + "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); // execute the statement resultSet = statement.executeQuery(); - while (resultSet.next()) - { + while (resultSet.next()) { Name name = new Name(); name.setLanguageCode(resultSet.getString(1)); //("LANG_CODE")); name.setValue(resultSet.getString(2)); //("NAME")); @@ -167,16 +233,11 @@ } return nameList; - } - finally - { - try - { + } finally { + try { statement.close(); resultSet.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } @@ -185,39 +246,28 @@ * Delete multiple rows from the SERVICE_NAME table that are assigned to the * ServiceKey specified. * - * @param serviceKey String - * @param connection JDBC connection + * @param serviceKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void delete(String serviceKey, Connection connection) - throws java.sql.SQLException - { + public static void delete(String serviceKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(deleteSQL); statement.setString(1, serviceKey.toString()); - log.debug( - "delete from SERVICE_NAME table:\n\n\t" - + deleteSQL - + "\n\t SERVICE_KEY=" - + serviceKey.toString() - + "\n"); + log.debug("delete from SERVICE_NAME table:\n\n\t" + deleteSQL + "\n\t SERVICE_KEY=" + serviceKey.toString() + "\n"); // execute statement.executeUpdate(); - } - finally - { - try - { + } finally { + try { statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } Index: org/apache/juddi/datastore/jdbc/TModelCategoryTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/TModelCategoryTable.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/TModelCategoryTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/TModelCategoryTable.java 7 Jul 2006 12:42:25 -0000 1.2 @@ -18,17 +18,21 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.juddi.datatype.KeyedReference; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class TModelCategoryTable -{ +class TModelCategoryTable { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(TModelCategoryTable.class); @@ -33,7 +37,11 @@ private static Log log = LogFactory.getLog(TModelCategoryTable.class); static String insertSQL = null; + static String selectSQL = null; + + static String selectInSQL = null; + static String deleteSQL = null; static { @@ -63,6 +71,17 @@ sql.append("ORDER BY CATEGORY_ID"); selectSQL = sql.toString(); + // build selectInSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("TMODEL_KEY_REF,"); + sql.append("KEY_NAME,"); + sql.append("KEY_VALUE, "); + sql.append("CATEGORY_ID, TMODEL_KEY "); + sql.append("FROM TMODEL_CATEGORY "); + sql.append("WHERE TMODEL_KEY IN ( "); + selectInSQL = sql.toString(); + // build deleteSQL sql = new StringBuffer(100); sql.append("DELETE FROM TMODEL_CATEGORY "); @@ -73,27 +92,23 @@ /** * Insert new row into the TMODEL_CATEGORY table. * - * @param tModelKey String to the parent TModelEntity object. - * @param keyRefs A Vector of KeyedReference instances to insert. - * @param connection JDBC connection + * @param tModelKey + * String to the parent TModelEntity object. + * @param keyRefs + * A Vector of KeyedReference instances to insert. + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void insert( - String tModelKey, - Vector keyRefs, - Connection connection) - throws java.sql.SQLException - { + public static void insert(String tModelKey, Vector keyRefs, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { statement = connection.prepareStatement(insertSQL); statement.setString(1, tModelKey.toString()); int listSize = keyRefs.size(); - for (int categoryID = 0; categoryID < listSize; categoryID++) - { + for (int categoryID = 0; categoryID < listSize; categoryID++) { KeyedReference keyRef = (KeyedReference) keyRefs.elementAt(categoryID); // extract values to insert @@ -107,33 +122,79 @@ statement.setString(4, keyRef.getKeyName()); statement.setString(5, keyRef.getKeyValue()); - log.debug( - "insert into TMODEL_CATEGORY table:\n\n\t" - + insertSQL - + "\n\t BUSINESS_KEY=" - + tModelKey.toString() - + "\n\t CATEGORY_ID=" - + categoryID - + "\n\t TMODEL_KEY_REF=" - + tModelKeyValue - + "\n\t KEY_NAME=" - + keyRef.getKeyName() - + "\n\t KEY_VALUE=" - + keyRef.getKeyValue() - + "\n"); + log.debug("insert into TMODEL_CATEGORY table:\n\n\t" + insertSQL + "\n\t BUSINESS_KEY=" + tModelKey.toString() + "\n\t CATEGORY_ID=" + + categoryID + "\n\t TMODEL_KEY_REF=" + tModelKeyValue + "\n\t KEY_NAME=" + keyRef.getKeyName() + "\n\t KEY_VALUE=" + + keyRef.getKeyValue() + "\n"); // insert! statement.executeUpdate(); } - } - finally - { - try - { + } finally { + try { statement.close(); + } catch (Exception e) { /* ignored */ + } + } + } + + /** + * Select all rows from the TMODEL_CATEGORY table for TModelKeys. + * + * @param tModelKey + * String + * @param connection + * JDBC connection + * @throws java.sql.SQLException + */ + public static Map select(List tModelsKeys, Connection connection) throws java.sql.SQLException { + Map results = new HashMap(); + PreparedStatement statement = null; + ResultSet resultSet = null; + + try { + DynamicQuery query = new DynamicQuery(); + query.append(selectInSQL); + + for (Iterator i = tModelsKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + if (i.hasNext()) { + query.append(", "); } - catch (Exception e) - { /* ignored */ + query.addValue(key); + } + + query.append(") "); + query.append("ORDER BY TMODEL_KEY, CATEGORY_ID"); + + // create a statement to query with + statement = query.buildPreparedStatement(connection); + + log.debug("select from TMODEL_CATEGORY table:\n\n\t" + query.toString() + "\n"); + + // execute the statement + resultSet = statement.executeQuery(); + while (resultSet.next()) { + KeyedReference keyRef = new KeyedReference(); + keyRef.setTModelKey(resultSet.getString(1));// ("TMODEL_KEY_REF")); + keyRef.setKeyName(resultSet.getString(2));// ("KEY_NAME")); + keyRef.setKeyValue(resultSet.getString(3));// ("KEY_VALUE")); + String tModelKey = resultSet.getString(5); + Vector keyRefList = (Vector) results.get(tModelKey); + if (keyRefList == null) { + keyRefList = new Vector(); + results.put(tModelKey, keyRefList); + } + keyRefList.add(keyRef); + + } + + return results; + } finally { + try { + resultSet.close(); + statement.close(); + } catch (Exception e) { /* ignored */ } } } @@ -141,34 +202,27 @@ /** * Select all rows from the TMODEL_CATEGORY table for a given TModelKey. * - * @param tModelKey String - * @param connection JDBC connection + * @param tModelKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static Vector select(String tModelKey, Connection connection) - throws java.sql.SQLException - { + public static Vector select(String tModelKey, Connection connection) throws java.sql.SQLException { Vector keyRefList = new Vector(); PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { // create a statement to query with statement = connection.prepareStatement(selectSQL); statement.setString(1, tModelKey.toString()); - log.debug( - "select from TMODEL_CATEGORY table:\n\n\t" - + selectSQL - + "\n\t TMODEL_KEY=" - + tModelKey.toString() - + "\n"); + log.debug("select from TMODEL_CATEGORY table:\n\n\t" + selectSQL + "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n"); // execute the statement resultSet = statement.executeQuery(); - while (resultSet.next()) - { + while (resultSet.next()) { KeyedReference keyRef = new KeyedReference(); keyRef.setTModelKey(resultSet.getString(1));//("TMODEL_KEY_REF")); keyRef.setKeyName(resultSet.getString(2));//("KEY_NAME")); @@ -177,57 +231,41 @@ } return keyRefList; - } - finally - { - try - { + } finally { + try { resultSet.close(); statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } /** - * Delete multiple rows from the TMODEL_CATEGORY table that are assigned to the - * TModelKey specified. + * Delete multiple rows from the TMODEL_CATEGORY table that are assigned to + * the TModelKey specified. * - * @param tModelKey String - * @param connection JDBC connection + * @param tModelKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void delete(String tModelKey, Connection connection) - throws java.sql.SQLException - { + public static void delete(String tModelKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(deleteSQL); statement.setString(1, tModelKey.toString()); - log.debug( - "delete from TMODEL_CATEGORY table:\n\n\t" - + deleteSQL - + "\n\t TMODEL_KEY=" - + tModelKey.toString() - + "\n"); + log.debug("delete from TMODEL_CATEGORY table:\n\n\t" + deleteSQL + "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n"); // execute statement.executeUpdate(); - } - finally - { - try - { + } finally { + try { statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } Index: org/apache/juddi/datastore/jdbc/TModelDescTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/TModelDescTable.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/TModelDescTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/TModelDescTable.java 7 Jul 2006 12:42:25 -0000 1.2 @@ -18,11 +18,16 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.juddi.datatype.Description; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) @@ -34,6 +39,7 @@ static String insertSQL = null; static String selectSQL = null; + static String selectInSQL = null; static String deleteSQL = null; static { @@ -61,6 +67,16 @@ sql.append("ORDER BY TMODEL_DESCR_ID"); selectSQL = sql.toString(); + // build selectInSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("LANG_CODE,"); + sql.append("DESCR, "); + sql.append("TMODEL_DESCR_ID, TMODEL_KEY "); + sql.append("FROM TMODEL_DESCR "); + sql.append("WHERE TMODEL_KEY IN ( "); + selectInSQL = sql.toString(); + // build deleteSQL sql = new StringBuffer(100); sql.append("DELETE FROM TMODEL_DESCR "); @@ -129,6 +145,84 @@ } } + /** + * Select all rows from the TMODEL_DESCR table for TModelKeys. + * + * @param tModelKey String + * @param connection JDBC connection + * @throws java.sql.SQLException + */ + public static Map select(List tModelsKeys, Connection connection) + throws java.sql.SQLException + { + PreparedStatement statement = null; + ResultSet resultSet = null; + Map results=new HashMap(); + + try + { + DynamicQuery query=new DynamicQuery(); + query.append(selectInSQL); + + for (Iterator i=tModelsKeys.iterator();i.hasNext();) + { + String key=(String)i.next(); + query.append("?"); + if (i.hasNext()) + { + query.append(", "); + } + query.addValue(key); + } + + query.append(") "); + query.append("ORDER BY TMODEL_KEY, TMODEL_DESCR_ID"); + + + // create a statement to query with + statement = query.buildPreparedStatement(connection); + + log.debug( + "select from TMODEL_DESCR table:\n\n\t" + + query.toString() + + "\n"); + + // execute the statement + resultSet = statement.executeQuery(); + while (resultSet.next()) + { + Description desc = new Description(); + desc.setLanguageCode(resultSet.getString(1));//("LANG_CODE")); + desc.setValue(resultSet.getString(2));//("DESCR")); + + String tModelKey=resultSet.getString(4); + Vector descList = (Vector)results.get(tModelKey); + if (descList==null) + { + descList=new Vector(); + results.put(tModelKey,descList); + } + descList.add(desc); + } + + return results; + } + finally + { + try + { + resultSet.close(); + statement.close(); + } + catch (Exception e) + { /* ignored */ + } + } + } + + + + /** * Select all rows from the TMODEL_DESCR table for a given TModelKey. * Index: org/apache/juddi/datastore/jdbc/TModelDocDescTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/TModelDocDescTable.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/TModelDocDescTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/TModelDocDescTable.java 7 Jul 2006 12:42:25 -0000 1.2 @@ -18,17 +18,21 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.juddi.datatype.Description; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class TModelDocDescTable -{ +class TModelDocDescTable { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(TModelDocDescTable.class); @@ -33,7 +37,11 @@ private static Log log = LogFactory.getLog(TModelDocDescTable.class); static String insertSQL = null; + static String selectSQL = null; + + static String selectInSQL = null; + static String deleteSQL = null; static { @@ -61,6 +69,16 @@ sql.append("ORDER BY TMODEL_DOC_DESCR_ID"); selectSQL = sql.toString(); + // build selectInSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("LANG_CODE,"); + sql.append("DESCR, "); + sql.append("TMODEL_DOC_DESCR_ID, TMODEL_KEY "); + sql.append("FROM TMODEL_DOC_DESCR "); + sql.append("WHERE TMODEL_KEY IN ( "); + selectInSQL = sql.toString(); + // build deleteSQL sql = new StringBuffer(100); sql.append("DELETE FROM TMODEL_DOC_DESCR "); @@ -71,61 +89,103 @@ /** * Insert new row into the TMODEL_DOC_DESCR table. * - * @param tModelKey TModelKey to the TModel object that owns the info to be inserted - * @param descList Vector of Description objects holding values to be inserted - * @param connection JDBC connection + * @param tModelKey + * TModelKey to the TModel object that owns the info to be + * inserted + * @param descList + * Vector of Description objects holding values to be inserted + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void insert( - String tModelKey, - Vector descList, - Connection connection) - throws java.sql.SQLException - { + public static void insert(String tModelKey, Vector descList, Connection connection) throws java.sql.SQLException { if ((descList == null) || (descList.size() == 0)) return; // everything is valid but no elements to insert PreparedStatement statement = null; - try - { + try { statement = connection.prepareStatement(insertSQL); statement.setString(1, tModelKey.toString()); int listSize = descList.size(); - for (int descID = 0; descID < listSize; descID++) - { + for (int descID = 0; descID < listSize; descID++) { Description desc = (Description) descList.elementAt(descID); // okay, set the values to be inserted - statement.setInt(2, descID); // Sequence Number aka Description ID + statement.setInt(2, descID); // Sequence Number aka + // Description ID statement.setString(3, desc.getLanguageCode()); statement.setString(4, desc.getValue()); - log.debug( - "insert into TMODEL_DOC_DESCR table:\n\n\t" - + insertSQL - + "\n\t TMODEL_KEY=" - + tModelKey.toString() - + "\n\t TMODEL_DOC_DESCR_ID=" - + descID - + "\n\t LANG_CODE=" - + desc.getLanguageCode() - + "\n\t DESCR=" - + desc.getValue() - + "\n"); + log.debug("insert into TMODEL_DOC_DESCR table:\n\n\t" + insertSQL + "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n\t TMODEL_DOC_DESCR_ID=" + + descID + "\n\t LANG_CODE=" + desc.getLanguageCode() + "\n\t DESCR=" + desc.getValue() + "\n"); statement.executeUpdate(); } - } - finally - { - try - { + } finally { + try { statement.close(); + } catch (Exception e) { /* ignored */ + } + } + } + + /** + * Select all rows from the TMODEL_DOC_DESCR table for TModelKeys. + * + * @param tModelsKeys + * List + * @param connection + * JDBC connection + * @throws java.sql.SQLException + */ + public static Map select(List tModelsKeys, Connection connection) throws java.sql.SQLException { + PreparedStatement statement = null; + ResultSet resultSet = null; + Map results = new HashMap(); + + try { + DynamicQuery query = new DynamicQuery(); + query.append(selectInSQL); + + for (Iterator i = tModelsKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + if (i.hasNext()) { + query.append(", "); } - catch (Exception e) - { /* ignored */ + query.addValue(key); + } + + query.append(") "); + query.append("ORDER BY TMODEL_KEY, TMODEL_DOC_DESCR_ID"); + statement = query.buildPreparedStatement(connection); + + log.debug("select from TMODEL_DOC_DESCR table:\n\n\t" + query.toString() + "\n"); + + // execute the statement + resultSet = statement.executeQuery(); + while (resultSet.next()) { + Description desc = new Description(); + desc.setLanguageCode(resultSet.getString(1));// ("LANG_CODE")); + desc.setValue(resultSet.getString(2));// ("DESCR")); + + String tModelKey = resultSet.getString(4); + Vector descList = (Vector) results.get(tModelKey); + if (descList == null) { + descList = new Vector(); + results.put(tModelKey, descList); + } + descList.add(desc); + } + + return results; + } finally { + try { + resultSet.close(); + statement.close(); + } catch (Exception e) { /* ignored */ } } } @@ -133,35 +193,27 @@ /** * Select all rows from the TMODEL_DOC_DESCR table for a given TModelKey. * - * @param tModelKey TModelKey - * @param connection JDBC connection + * @param tModelKey + * TModelKey + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static Vector select(String tModelKey, Connection connection) - throws java.sql.SQLException - { + public static Vector select(String tModelKey, Connection connection) throws java.sql.SQLException { Vector descList = new Vector(); PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { // create a statement to query with statement = connection.prepareStatement(selectSQL); statement.setString(1, tModelKey.toString()); - log.debug( - "select from TMODEL_DOC_DESCR table:\n\n\t" - + selectSQL - + "\n\t TMODEL_KEY=" - + tModelKey.toString() - + "\n\t TMODEL_DOC_DESCR_ID=" - + "\n"); + log.debug("select from TMODEL_DOC_DESCR table:\n\n\t" + selectSQL + "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n\t TMODEL_DOC_DESCR_ID=" + "\n"); // execute the statement resultSet = statement.executeQuery(); - while (resultSet.next()) - { + while (resultSet.next()) { Description desc = new Description(); desc.setLanguageCode(resultSet.getString(1));//("LANG_CODE")); desc.setValue(resultSet.getString(2));//("DESCR")); @@ -169,57 +221,41 @@ } return descList; - } - finally - { - try - { + } finally { + try { resultSet.close(); statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } /** - * Delete multiple rows from the TMODEL_DOC_DESCR table that are assigned to the - * TModelKey specified. + * Delete multiple rows from the TMODEL_DOC_DESCR table that are assigned to + * the TModelKey specified. * - * @param tModelKey TModelKey - * @param connection JDBC connection + * @param tModelKey + * TModelKey + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void delete(String tModelKey, Connection connection) - throws java.sql.SQLException - { + public static void delete(String tModelKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(deleteSQL); statement.setString(1, tModelKey.toString()); - log.debug( - "delete from TMODEL_DOC_DESCR table:\n\n\t" - + deleteSQL - + "\n\t TMODEL_KEY=" - + tModelKey.toString() - + "\n"); + log.debug("delete from TMODEL_DOC_DESCR table:\n\n\t" + deleteSQL + "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n"); // execute statement.executeUpdate(); - } - finally - { - try - { + } finally { + try { statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } Index: org/apache/juddi/datastore/jdbc/TModelIdentifierTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/TModelIdentifierTable.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/TModelIdentifierTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/TModelIdentifierTable.java 7 Jul 2006 12:42:25 -0000 1.2 @@ -18,17 +18,21 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.juddi.datatype.KeyedReference; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class TModelIdentifierTable -{ +class TModelIdentifierTable { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(TModelIdentifierTable.class); @@ -33,7 +37,11 @@ private static Log log = LogFactory.getLog(TModelIdentifierTable.class); static String insertSQL = null; + static String selectSQL = null; + + static String selectInSQL = null; + static String deleteSQL = null; static { @@ -63,6 +71,17 @@ sql.append("ORDER BY IDENTIFIER_ID"); selectSQL = sql.toString(); + // build selectInSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("TMODEL_KEY_REF,"); + sql.append("KEY_NAME,"); + sql.append("KEY_VALUE, "); + sql.append("IDENTIFIER_ID, TMODEL_KEY "); + sql.append("FROM TMODEL_IDENTIFIER "); + sql.append("WHERE TMODEL_KEY IN ( "); + selectInSQL = sql.toString(); + // build deleteSQL sql = new StringBuffer(100); sql.append("DELETE FROM TMODEL_IDENTIFIER "); @@ -73,29 +92,24 @@ /** * Insert new row into the TMODEL_IDENTIFIER table. * - * @param tModelKey String to the parent TModelEntity object. - * @param keyRefs A Vector of KeyedReference instances to insert. - * @param connection JDBC connection + * @param tModelKey + * String to the parent TModelEntity object. + * @param keyRefs + * A Vector of KeyedReference instances to insert. + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void insert( - String tModelKey, - Vector keyRefs, - Connection connection) - throws java.sql.SQLException - { + public static void insert(String tModelKey, Vector keyRefs, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { statement = connection.prepareStatement(insertSQL); statement.setString(1, tModelKey.toString()); int listSize = keyRefs.size(); - for (int identifierID = 0; identifierID < listSize; identifierID++) - { - KeyedReference keyRef = - (KeyedReference) keyRefs.elementAt(identifierID); + for (int identifierID = 0; identifierID < listSize; identifierID++) { + KeyedReference keyRef = (KeyedReference) keyRefs.elementAt(identifierID); // extract values to insert String tModelKeyValue = null; @@ -108,33 +122,77 @@ statement.setString(4, keyRef.getKeyName()); statement.setString(5, keyRef.getKeyValue()); - log.debug( - "insert into TMODEL_IDENTIFIER table:\n\n\t" - + insertSQL - + "\n\t BUSINESS_KEY=" - + tModelKey.toString() - + "\n\t IDENTIFIER_ID=" - + identifierID - + "\n\t TMODEL_KEY_REF=" - + tModelKeyValue - + "\n\t KEY_NAME=" - + keyRef.getKeyName() - + "\n\t KEY_VALUE=" - + keyRef.getKeyValue() - + "\n"); + log.debug("insert into TMODEL_IDENTIFIER table:\n\n\t" + insertSQL + "\n\t BUSINESS_KEY=" + tModelKey.toString() + "\n\t IDENTIFIER_ID=" + + identifierID + "\n\t TMODEL_KEY_REF=" + tModelKeyValue + "\n\t KEY_NAME=" + keyRef.getKeyName() + "\n\t KEY_VALUE=" + + keyRef.getKeyValue() + "\n"); // insert! statement.executeUpdate(); } - } - finally - { - try - { + } finally { + try { statement.close(); + } catch (Exception e) { /* ignored */ + } + } + } + + /** + * Select all rows from the TMODEL_IDENTIFIER table for TModelKeys. + * + * @param tModelKey + * List + * @param connection + * JDBC connection + * @throws java.sql.SQLException + */ + public static Map select(List tModelsKeys, Connection connection) throws java.sql.SQLException { + PreparedStatement statement = null; + ResultSet resultSet = null; + Map results = new HashMap(); + try { + DynamicQuery query = new DynamicQuery(); + query.append(selectInSQL); + + for (Iterator i = tModelsKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + if (i.hasNext()) { + query.append(", "); } - catch (Exception e) - { /* ignored */ + query.addValue(key); + } + + query.append(") "); + query.append("ORDER BY TMODEL_KEY, IDENTIFIER_ID"); + statement = query.buildPreparedStatement(connection); + + log.debug("select from TMODEL_IDENTIFIER table:\n\n\t" + query.toString() + "\n"); + + // execute the statement + resultSet = statement.executeQuery(); + while (resultSet.next()) { + KeyedReference keyRef = new KeyedReference(); + keyRef.setTModelKey(resultSet.getString(1));// ("TMODEL_KEY_REF")); + keyRef.setKeyName(resultSet.getString(2));// ("KEY_NAME")); + keyRef.setKeyValue(resultSet.getString(3));// ("KEY_VALUE")); + + String tModelKey = resultSet.getString(5); + Vector keyRefList = (Vector) results.get(tModelKey); + if (keyRefList == null) { + keyRefList = new Vector(); + results.put(tModelKey, keyRefList); + } + keyRefList.add(keyRef); + + } + + return results; + } finally { + try { + resultSet.close(); + statement.close(); + } catch (Exception e) { /* ignored */ } } } @@ -142,34 +200,27 @@ /** * Select all rows from the TMODEL_IDENTIFIER table for a given TModelKey. * - * @param tModelKey String - * @param connection JDBC connection + * @param tModelKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static Vector select(String tModelKey, Connection connection) - throws java.sql.SQLException - { + public static Vector select(String tModelKey, Connection connection) throws java.sql.SQLException { Vector keyRefList = new Vector(); PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { // create a statement to query with statement = connection.prepareStatement(selectSQL); statement.setString(1, tModelKey.toString()); - log.debug( - "select from TMODEL_IDENTIFIER table:\n\n\t" - + selectSQL - + "\n\t TMODEL_KEY=" - + tModelKey.toString() - + "\n"); + log.debug("select from TMODEL_IDENTIFIER table:\n\n\t" + selectSQL + "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n"); // execute the statement resultSet = statement.executeQuery(); - while (resultSet.next()) - { + while (resultSet.next()) { KeyedReference keyRef = new KeyedReference(); keyRef.setTModelKey(resultSet.getString(1));//("TMODEL_KEY_REF")); keyRef.setKeyName(resultSet.getString(2));//("KEY_NAME")); @@ -178,57 +229,41 @@ } return keyRefList; - } - finally - { - try - { + } finally { + try { resultSet.close(); statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } /** - * Delete multiple rows from the TMODEL_IDENTIFIER table that are assigned to the - * TModelKey specified. + * Delete multiple rows from the TMODEL_IDENTIFIER table that are assigned + * to the TModelKey specified. * - * @param tModelKey String - * @param connection JDBC connection + * @param tModelKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void delete(String tModelKey, Connection connection) - throws java.sql.SQLException - { + public static void delete(String tModelKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare statement = connection.prepareStatement(deleteSQL); statement.setString(1, tModelKey.toString()); - log.debug( - "delete from TMODEL_IDENTIFIER table:\n\n\t" - + deleteSQL - + "\n\t TMODEL_KEY=" - + tModelKey.toString() - + "\n"); + log.debug("delete from TMODEL_IDENTIFIER table:\n\n\t" + deleteSQL + "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n"); // execute statement.executeUpdate(); - } - finally - { - try - { + } finally { + try { statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } Index: org/apache/juddi/datastore/jdbc/TModelInstanceInfoDescTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/TModelInstanceInfoDescTable.java,v retrieving revision 1.1 retrieving revision 1.4 diff -u -w -B -r1.1 -r1.4 --- org/apache/juddi/datastore/jdbc/TModelInstanceInfoDescTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/TModelInstanceInfoDescTable.java 11 Jul 2006 09:13:02 -0000 1.4 @@ -18,17 +18,22 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.juddi.datatype.Description; +import org.apache.juddi.util.Config; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class TModelInstanceInfoDescTable -{ +class TModelInstanceInfoDescTable { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(TModelInstanceInfoDescTable.class); @@ -33,7 +38,11 @@ private static Log log = LogFactory.getLog(TModelInstanceInfoDescTable.class); static String insertSQL = null; + static String selectSQL = null; + + static String selectInSQL = null; + static String deleteSQL = null; static { @@ -63,6 +72,17 @@ sql.append("ORDER BY TMODEL_INSTANCE_INFO_DESCR_ID"); selectSQL = sql.toString(); + // build selectInSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("LANG_CODE,"); + sql.append("DESCR, "); + sql.append("TMODEL_INSTANCE_INFO_DESCR_ID, BINDING_KEY, TMODEL_INSTANCE_INFO_ID "); + sql.append("FROM TMODEL_INSTANCE_INFO_DESCR "); + sql.append("WHERE BINDING_KEY IN ( "); + + selectInSQL = sql.toString(); + // build deleteSQL sql = new StringBuffer(100); sql.append("DELETE FROM TMODEL_INSTANCE_INFO_DESCR "); @@ -73,32 +93,28 @@ /** * Insert new row into the TMODEL_INSTANCE_INFO_DESCR table. * - * @param bindingKey String to the BusinessEntity object that owns the Contact to be inserted - * @param descList Vector of Description objects holding values to be inserted - * @param connection JDBC connection + * @param bindingKey + * String to the BusinessEntity object that owns the Contact to + * be inserted + * @param descList + * Vector of Description objects holding values to be inserted + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void insert( - String bindingKey, - int tModelInstanceInfoID, - Vector descList, - Connection connection) - throws java.sql.SQLException - { + public static void insert(String bindingKey, int tModelInstanceInfoID, Vector descList, Connection connection) throws java.sql.SQLException { if ((descList == null) || (descList.size() == 0)) return; // everything is valid but no elements to insert PreparedStatement statement = null; - try - { + try { statement = connection.prepareStatement(insertSQL); statement.setString(1, bindingKey.toString()); statement.setInt(2, tModelInstanceInfoID); int listSize = descList.size(); - for (int descID = 0; descID < listSize; descID++) - { + for (int descID = 0; descID < listSize; descID++) { Description desc = (Description) descList.elementAt(descID); // insert sequence number @@ -106,74 +122,131 @@ statement.setString(4, desc.getLanguageCode()); statement.setString(5, desc.getValue()); - log.debug( - "insert into TMODEL_INSTANCE_INFO_DESCR table:\n\n\t" - + insertSQL - + "\n\t BINDING_KEY=" - + bindingKey.toString() - + "\n\t TMODEL_INSTANCE_INFO_ID=" - + tModelInstanceInfoID - + "\n\t TMODEL_INSTANCE_INFO_DESCR_ID=" - + descID - + "\n\t LANG_CODE=" - + desc.getLanguageCode() - + "\n\t DESCR=" - + desc.getValue() - + "\n"); + log.debug("insert into TMODEL_INSTANCE_INFO_DESCR table:\n\n\t" + insertSQL + "\n\t BINDING_KEY=" + bindingKey.toString() + + "\n\t TMODEL_INSTANCE_INFO_ID=" + tModelInstanceInfoID + "\n\t TMODEL_INSTANCE_INFO_DESCR_ID=" + descID + "\n\t LANG_CODE=" + + desc.getLanguageCode() + "\n\t DESCR=" + desc.getValue() + "\n"); statement.executeUpdate(); } - } - finally - { - try - { + } finally { + try { statement.close(); + } catch (Exception e) { /* ignored */ + } + } + } + + /** + * Select all rows from the TMODEL_INSTANCE_INFO_DESCR table for + * BindingKeys. + * + * @param bindingKey + * String + * @param tModelInstanceInfoID + * ID (sequence number) of the parent tModelInstanceInfo object + * @param connection + * JDBC connection + * @throws java.sql.SQLException + * @return map of map of vector + */ + public static Map select(List bindingsKeys, Connection connection) throws java.sql.SQLException { + // Vector descList = new Vector(); + PreparedStatement statement = null; + ResultSet resultSet = null; + Map results = new HashMap(); + + try { + + DynamicQuery query = new DynamicQuery(); + query.append("(" + selectInSQL); + int count = 0; + for (Iterator i = bindingsKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + count++; + if (i.hasNext()) { + if (count > Config.getMaxInAllowed()) { + count = 0; + query.append(") UNION ALL " + selectInSQL); + } else { + query.append(", "); + } } - catch (Exception e) - { /* ignored */ + query.addValue(key); + } + + query.append(")) "); + query.append("ORDER BY BINDING_KEY, TMODEL_INSTANCE_INFO_ID, TMODEL_INSTANCE_INFO_DESCR_ID"); + + // create a statement to query with + statement = query.buildPreparedStatement(connection); + statement.setFetchSize(500); + log.debug("select from TMODEL_INSTANCE_INFO_DESCR table:\n\n\t" + query.toString() + "\n"); + + // execute the statement + resultSet = statement.executeQuery(); + while (resultSet.next()) { + Description desc = new Description(); + desc.setLanguageCode(resultSet.getString(1));// ("LANG_CODE")); + desc.setValue(resultSet.getString(2));// ("DESCR")); + + String bindingKey = resultSet.getString(4); + + int infoId = resultSet.getInt(5); + + Map descMap = (Map) results.get(bindingKey); + if (descMap == null) { + descMap = new HashMap(); + results.put(bindingKey, descMap); + } + Vector vec = (Vector) descMap.get(new Integer(infoId)); + if (vec == null) { + vec = new Vector(); + descMap.put(new Integer(infoId), vec); + } + vec.add(desc); + + } + + return results; + } finally { + try { + resultSet.close(); + statement.close(); + } catch (Exception e) { /* ignored */ } } } /** - * Select all rows from the TMODEL_INSTANCE_INFO_DESCR table for a given BindingKey. + * Select all rows from the TMODEL_INSTANCE_INFO_DESCR table for a given + * BindingKey. * - * @param bindingKey String - * @param tModelInstanceInfoID ID (sequence number) of the parent tModelInstanceInfo object - * @param connection JDBC connection + * @param bindingKey + * String + * @param tModelInstanceInfoID + * ID (sequence number) of the parent tModelInstanceInfo object + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static Vector select( - String bindingKey, - int tModelInstanceInfoID, - Connection connection) - throws java.sql.SQLException - { + public static Vector select(String bindingKey, int tModelInstanceInfoID, Connection connection) throws java.sql.SQLException { Vector descList = new Vector(); PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { // create a statement to query with statement = connection.prepareStatement(selectSQL); statement.setString(1, bindingKey.toString()); statement.setInt(2, tModelInstanceInfoID); - log.debug( - "select from TMODEL_INSTANCE_INFO_DESCR table:\n\n\t" - + selectSQL - + "\n\t BINDING_KEY=" - + bindingKey.toString() - + "\n\t TMODEL_INSTANCE_INFO_ID=" - + tModelInstanceInfoID - + "\n"); + log.debug("select from TMODEL_INSTANCE_INFO_DESCR table:\n\n\t" + selectSQL + "\n\t BINDING_KEY=" + bindingKey.toString() + + "\n\t TMODEL_INSTANCE_INFO_ID=" + tModelInstanceInfoID + "\n"); // execute the statement resultSet = statement.executeQuery(); - while (resultSet.next()) - { + while (resultSet.next()) { Description desc = new Description(); desc.setLanguageCode(resultSet.getString(1));//("LANG_CODE")); desc.setValue(resultSet.getString(2));//("DESCR")); @@ -181,16 +254,11 @@ } return descList; - } - finally - { - try - { + } finally { + try { resultSet.close(); statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } @@ -199,39 +267,28 @@ * Delete multiple rows from the TMODEL_INSTANCE_INFO_DESCR table that are * assigned to the BindingKey specified. * - * @param bindingKey String - * @param connection JDBC connection + * @param bindingKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void delete(String bindingKey, Connection connection) - throws java.sql.SQLException - { + public static void delete(String bindingKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(deleteSQL); statement.setString(1, bindingKey.toString()); - log.debug( - "delete from TMODEL_INSTANCE_INFO_DESCR table:\n\n\t" - + deleteSQL - + "\n\t BINDING_KEY=" - + bindingKey.toString() - + "\n"); + log.debug("delete from TMODEL_INSTANCE_INFO_DESCR table:\n\n\t" + deleteSQL + "\n\t BINDING_KEY=" + bindingKey.toString() + "\n"); // execute statement.executeUpdate(); - } - finally - { - try - { + } finally { + try { statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } Index: org/apache/juddi/datastore/jdbc/TModelInstanceInfoTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/TModelInstanceInfoTable.java,v retrieving revision 1.1 retrieving revision 1.4 diff -u -w -B -r1.1 -r1.4 --- org/apache/juddi/datastore/jdbc/TModelInstanceInfoTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/TModelInstanceInfoTable.java 11 Jul 2006 09:13:02 -0000 1.4 @@ -18,6 +18,10 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Vector; import org.apache.commons.logging.Log; @@ -26,12 +30,13 @@ import org.apache.juddi.datatype.binding.InstanceDetails; import org.apache.juddi.datatype.binding.InstanceParms; import org.apache.juddi.datatype.binding.TModelInstanceInfo; +import org.apache.juddi.util.Config; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class TModelInstanceInfoTable -{ +class TModelInstanceInfoTable { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(TModelInstanceInfoTable.class); @@ -36,7 +41,11 @@ private static Log log = LogFactory.getLog(TModelInstanceInfoTable.class); static String insertSQL = null; + static String selectSQL = null; + + static String selectInSQL = null; + static String deleteSQL = null; static { @@ -66,6 +75,17 @@ sql.append("ORDER BY TMODEL_INSTANCE_INFO_ID"); selectSQL = sql.toString(); + // build selectInSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("TMODEL_KEY,"); + sql.append("OVERVIEW_URL,"); + sql.append("INSTANCE_PARMS, "); + sql.append("TMODEL_INSTANCE_INFO_ID, BINDING_KEY "); + sql.append("FROM TMODEL_INSTANCE_INFO "); + sql.append("WHERE BINDING_KEY IN ( "); + selectInSQL = sql.toString(); + // build deleteSQL sql = new StringBuffer(100); sql.append("DELETE FROM TMODEL_INSTANCE_INFO "); @@ -76,42 +96,37 @@ /** * Insert new row into the TMODEL_INSTANCE_INFO table. * - * @param bindingKey String to the BusinessEntity object that owns the Contact to be inserted - * @param infoList Vector of Contact objects holding values to be inserted - * @param connection JDBC connection + * @param bindingKey + * String to the BusinessEntity object that owns the Contact to + * be inserted + * @param infoList + * Vector of Contact objects holding values to be inserted + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void insert( - String bindingKey, - Vector infoList, - Connection connection) - throws java.sql.SQLException - { + public static void insert(String bindingKey, Vector infoList, Connection connection) throws java.sql.SQLException { if ((infoList == null) || (infoList.size() == 0)) return; // everything is valid but no elements to insert PreparedStatement statement = null; - try - { + try { statement = connection.prepareStatement(insertSQL); statement.setString(1, bindingKey.toString()); int listSize = infoList.size(); - for (int infoID = 0; infoID < listSize; infoID++) - { + for (int infoID = 0; infoID < listSize; infoID++) { String tModelKey = null; String overURL = null; String instParms = null; - TModelInstanceInfo info = - (TModelInstanceInfo) infoList.elementAt(infoID); + TModelInstanceInfo info = (TModelInstanceInfo) infoList.elementAt(infoID); if (info.getTModelKey() != null) tModelKey = info.getTModelKey().toString(); InstanceDetails details = info.getInstanceDetails(); - if (details != null) - { + if (details != null) { if (details.getOverviewDoc() != null) overURL = details.getOverviewDoc().getOverviewURLString(); @@ -125,32 +140,112 @@ statement.setString(4, overURL); statement.setString(5, instParms); - log.debug( - "insert into TMODEL_INSTANCE_INFO table:\n\n\t" - + insertSQL - + "\n\t BINDING_KEY=" - + bindingKey.toString() - + "\n\t TMODEL_INSTANCE_INFO_ID=" - + infoID - + "\n\t TMODEL_KEY=" - + tModelKey - + "\n\t OVERVIEW_URL=" - + overURL - + "\n\t INSTANCE_PARMS=" - + instParms - + "\n"); + log.debug("insert into TMODEL_INSTANCE_INFO table:\n\n\t" + insertSQL + "\n\t BINDING_KEY=" + bindingKey.toString() + + "\n\t TMODEL_INSTANCE_INFO_ID=" + infoID + "\n\t TMODEL_KEY=" + tModelKey + "\n\t OVERVIEW_URL=" + overURL + "\n\t INSTANCE_PARMS=" + + instParms + "\n"); statement.executeUpdate(); } - } - finally - { - try - { + } finally { + try { statement.close(); + } catch (Exception e) { /* ignored */ + } + } } - catch (Exception e) - { /* ignored */ + + /** + * Select all rows from the TMODEL_INST_INFO table for bindingKeys. + * + * @param bindingsKeys + * List + * @param connection + * JDBC connection + * @throws java.sql.SQLException + */ + public static Map select(List bindingsKeys, Connection connection) throws java.sql.SQLException { + // Vector infoList = new Vector(); + PreparedStatement statement = null; + ResultSet resultSet = null; + Map results = new HashMap(); + + try { + DynamicQuery query = new DynamicQuery(); + query.append("(" + selectInSQL); + int count = 0; + + for (Iterator i = bindingsKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + count++; + if (i.hasNext()) { + if (count > Config.getMaxInAllowed()) { + count = 0; + query.append(") UNION ALL " + selectInSQL); + } else { + query.append(", "); + } + } + query.addValue(key); + } + + query.append(")) "); + query.append("ORDER BY BINDING_KEY, TMODEL_INSTANCE_INFO_ID"); + + // create a statement to query with + statement = query.buildPreparedStatement(connection); + statement.setFetchSize(500); + log.debug("select from TMODEL_INSTANCE_INFO table:\n\n\t" + query.toString() + "\n"); + + // execute the statement + resultSet = statement.executeQuery(); + + while (resultSet.next()) { + String tModelKey = resultSet.getString(1);// ("TMODEL_KEY"); + String overURL = resultSet.getString(2);// ("OVERVIEW_URL"); + String instParms = resultSet.getString(3);// ("INSTANCE_PARMS"); + + if (tModelKey != null) { + TModelInstanceInfo info = new TModelInstanceInfo(); + info.setTModelKey(tModelKey); + + OverviewDoc overviewDoc = null; + if (overURL != null) { + overviewDoc = new OverviewDoc(); + overviewDoc.setOverviewURL(overURL); + } + + InstanceParms instanceParms = null; + if (instParms != null) { + instanceParms = new InstanceParms(); + instanceParms.setText(instParms); + } + + InstanceDetails details = null; + if ((overviewDoc != null) || (instanceParms != null)) { + details = new InstanceDetails(); + details.setOverviewDoc(overviewDoc); + details.setInstanceParms(instanceParms); + info.setInstanceDetails(details); + } + + String bindingKey = resultSet.getString(5); + Vector infoList = (Vector) results.get(bindingKey); + if (infoList == null) { + infoList = new Vector(); + results.put(bindingKey, infoList); + } + + infoList.add(info); + } + } + + return results; + } finally { + try { + resultSet.close(); + statement.close(); + } catch (Exception e) { /* ignored */ } } } @@ -158,61 +253,50 @@ /** * Select all rows from the TMODEL_INST_INFO table for a given BusinessKey. * - * @param bindingKey String - * @param connection JDBC connection + * @param bindingKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static Vector select(String bindingKey, Connection connection) - throws java.sql.SQLException - { + public static Vector select(String bindingKey, Connection connection) throws java.sql.SQLException { Vector infoList = new Vector(); PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { // create a statement to query with statement = connection.prepareStatement(selectSQL); statement.setString(1, bindingKey.toString()); - log.debug( - "select from TMODEL_INSTANCE_INFO table:\n\n\t" - + selectSQL - + "\n\t BINDING_KEY=" - + bindingKey.toString() - + "\n"); + log.debug("select from TMODEL_INSTANCE_INFO table:\n\n\t" + selectSQL + "\n\t BINDING_KEY=" + bindingKey.toString() + "\n"); // execute the statement resultSet = statement.executeQuery(); - while (resultSet.next()) - { + while (resultSet.next()) { String tModelKey = resultSet.getString(1);//("TMODEL_KEY"); String overURL = resultSet.getString(2);//("OVERVIEW_URL"); String instParms = resultSet.getString(3);//("INSTANCE_PARMS"); - if (tModelKey != null) - { + if (tModelKey != null) { TModelInstanceInfo info = new TModelInstanceInfo(); info.setTModelKey(tModelKey); OverviewDoc overviewDoc = null; - if (overURL != null) - { + if (overURL != null) { overviewDoc = new OverviewDoc(); overviewDoc.setOverviewURL(overURL); } InstanceParms instanceParms = null; - if (instParms != null) - { + if (instParms != null) { instanceParms = new InstanceParms(); instanceParms.setText(instParms); } InstanceDetails details = null; - if ((overviewDoc != null) || (instanceParms != null)) - { + if ((overviewDoc != null) || (instanceParms != null)) { details = new InstanceDetails(); details.setOverviewDoc(overviewDoc); details.setInstanceParms(instanceParms); @@ -224,57 +308,41 @@ } return infoList; - } - finally - { - try - { + } finally { + try { resultSet.close(); statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } /** - * Delete multiple rows from the TMODEL_INST_INFO table that are assigned to the - * BusinessKey specified. + * Delete multiple rows from the TMODEL_INST_INFO table that are assigned to + * the BusinessKey specified. * - * @param bindingKey String - * @param connection JDBC connection + * @param bindingKey + * String + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void delete(String bindingKey, Connection connection) - throws java.sql.SQLException - { + public static void delete(String bindingKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(deleteSQL); statement.setString(1, bindingKey.toString()); - log.debug( - "delete from TMODEL_INSTANCE_INFO table:\n\n\t" - + deleteSQL - + "\n\t BINDING_KEY=" - + bindingKey.toString() - + "\n"); + log.debug("delete from TMODEL_INSTANCE_INFO table:\n\n\t" + deleteSQL + "\n\t BINDING_KEY=" + bindingKey.toString() + "\n"); // execute statement.executeUpdate(); - } - finally - { - try - { + } finally { + try { statement.close(); - } - catch (Exception e) - { /* ignored */ + } catch (Exception e) { /* ignored */ } } } Index: org/apache/juddi/datastore/jdbc/TModelTable.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/datastore/jdbc/TModelTable.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/datastore/jdbc/TModelTable.java 3 Jul 2006 07:45:12 -0000 1.1 +++ org/apache/juddi/datastore/jdbc/TModelTable.java 7 Jul 2006 12:42:25 -0000 1.2 @@ -19,18 +19,21 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.juddi.datatype.OverviewDoc; import org.apache.juddi.datatype.tmodel.TModel; +import org.apache.juddi.util.jdbc.DynamicQuery; /** * @author Steve Viens (sviens@apache.org) */ -class TModelTable -{ +class TModelTable { // private reference to the jUDDI logger private static Log log = LogFactory.getLog(TModelTable.class); @@ -35,14 +38,20 @@ private static Log log = LogFactory.getLog(TModelTable.class); static String insertSQL = null; + static String deleteSQL = null; + static String updateSQL = null; + static String selectSQL = null; + + static String selectInSQL = null; + static String selectByPublisherSQL = null; + static String verifyOwnershipSQL = null; - static - { + static { // buffer used to build SQL statements StringBuffer sql = null; @@ -85,6 +94,18 @@ sql.append("AND DELETED IS NULL"); selectSQL = sql.toString(); + // build selectInSQL + sql = new StringBuffer(200); + sql.append("SELECT "); + sql.append("AUTHORIZED_NAME,"); + sql.append("OPERATOR,"); + sql.append("NAME,"); + sql.append("OVERVIEW_URL,"); + sql.append("DELETED, TMODEL_KEY "); + sql.append("FROM TMODEL "); + sql.append("WHERE DELETED IS NULL AND TMODEL_KEY IN ( "); + selectInSQL = sql.toString(); + // build selectByPublisherSQL sql = new StringBuffer(200); sql.append("SELECT "); @@ -108,14 +129,14 @@ /** * Insert new row into the TMODEL table. * - * @param tModel TModel object holding values to be inserted + * @param tModel + * TModel object holding values to be inserted * @param publisherID - * @param connection JDBC connection + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void insert(TModel tModel,String publisherID,Connection connection) - throws java.sql.SQLException - { + public static void insert(TModel tModel, String publisherID, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; Timestamp timeStamp = new Timestamp(System.currentTimeMillis()); @@ -123,8 +144,7 @@ if ((tModel.getOverviewDoc() != null) && (tModel.getOverviewDoc().getOverviewURL() != null)) overviewURL = tModel.getOverviewDoc().getOverviewURL().getValue(); - try - { + try { statement = connection.prepareStatement(insertSQL); statement.setString(1,tModel.getTModelKey().toString()); statement.setString(2,tModel.getAuthorizedName()); @@ -134,24 +154,17 @@ statement.setString(6,overviewURL); statement.setTimestamp(7,timeStamp); - log.debug(insertSQL + - "\n\t TMODEL_KEY=" + tModel.getTModelKey().toString() + - "\n\t AUTHORIZED_NAME=" + tModel.getAuthorizedName() + - "\n\t PUBLISHER_ID=" + publisherID + - "\n\t OPERATOR=" + tModel.getOperator() + - "\n\t NAME=" + tModel.getName() + - "\n\t OVERVIEW_URL=" + overviewURL + - "\n\t LAST_UPDATE=" + timeStamp.getTime() + "\n"); + log.debug(insertSQL + "\n\t TMODEL_KEY=" + tModel.getTModelKey().toString() + "\n\t AUTHORIZED_NAME=" + tModel.getAuthorizedName() + + "\n\t PUBLISHER_ID=" + publisherID + "\n\t OPERATOR=" + tModel.getOperator() + "\n\t NAME=" + tModel.getName() + "\n\t OVERVIEW_URL=" + + overviewURL + "\n\t LAST_UPDATE=" + timeStamp.getTime() + "\n"); // insert statement.executeUpdate(); - } - finally - { + } finally { try { statement.close(); + } catch (Exception e) { /* ignored */ } - catch (Exception e) { /* ignored */ } } } @@ -159,65 +172,113 @@ * Delete row from the TMODEL table. * * @param tModelKey - * @param connection JDBC connection + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void delete(String tModelKey,Connection connection) - throws java.sql.SQLException - { + public static void delete(String tModelKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(deleteSQL); statement.setString(1,tModelKey.toString()); - log.debug(deleteSQL + - "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n"); + log.debug(deleteSQL + "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n"); // execute statement.executeUpdate(); - } - finally - { + } finally { try { statement.close(); + } catch (Exception e) { /* ignored */ } - catch (Exception e) { /* ignored */ } } } /** - * Update the TMODEL table setting the value of the DELETED column to 'true'. + * Update the TMODEL table setting the value of the DELETED column to + * 'true'. * * @param tModelKey - * @param connection JDBC connection + * @param connection + * JDBC connection * @throws java.sql.SQLException */ - public static void markAsDeleted(String tModelKey,Connection connection) - throws java.sql.SQLException - { + public static void markAsDeleted(String tModelKey, Connection connection) throws java.sql.SQLException { PreparedStatement statement = null; - try - { + try { // prepare the delete statement = connection.prepareStatement(updateSQL); statement.setString(1,tModelKey.toString()); - log.debug(updateSQL + - "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n"); + log.debug(updateSQL + "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n"); // execute statement.executeUpdate(); + } finally { + try { + statement.close(); + } catch (Exception e) { /* ignored */ + } + } } - finally - { + + /** + * Select rows from the TMODEL table. + * + * @param tModelKey + * @param connection + * @throws java.sql.SQLException + */ + public static List select(List tModelsKeys, Connection connection) throws java.sql.SQLException { + ArrayList results = new ArrayList(); + PreparedStatement statement = null; + ResultSet resultSet = null; + try { + DynamicQuery query = new DynamicQuery(); + query.append(selectInSQL); + + for (Iterator i = tModelsKeys.iterator(); i.hasNext();) { + String key = (String) i.next(); + query.append("?"); + if (i.hasNext()) { + query.append(", "); + } + query.addValue(key); + } + + query.append(") "); + + // create a statement to query with + statement = query.buildPreparedStatement(connection); + + log.debug(selectSQL + "\n\t" + query.toString() + "\n"); + + resultSet = statement.executeQuery(); + while (resultSet.next()) { + TModel tModel = null; + tModel = new TModel(); + tModel.setTModelKey(resultSet.getString(6)); + tModel.setAuthorizedName(resultSet.getString(1));// ("AUTHORIZED_NAME")); + tModel.setOperator(resultSet.getString(2));// ("OPERATOR")); + tModel.setName(resultSet.getString(3));// ("NAME")); + + OverviewDoc overviewDoc = new OverviewDoc(); + overviewDoc.setOverviewURL(resultSet.getString(4));// ("OVERVIEW_URL")); + tModel.setOverviewDoc(overviewDoc); + results.add(tModel); + } + + return results; + } finally { + try { + resultSet.close(); statement.close(); + } catch (Exception e) { /* ignored */ } - catch (Exception e) { /* ignored */ } } } @@ -228,24 +289,19 @@ * @param connection * @throws java.sql.SQLException */ - public static TModel select(String tModelKey,Connection connection) - throws java.sql.SQLException - { + public static TModel select(String tModelKey, Connection connection) throws java.sql.SQLException { TModel tModel = null; PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { statement = connection.prepareStatement(selectSQL); statement.setString(1,tModelKey.toString()); - log.debug(selectSQL + - "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n"); + log.debug(selectSQL + "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n"); resultSet = statement.executeQuery(); - if (resultSet.next()) - { + if (resultSet.next()) { tModel = new TModel(); tModel.setTModelKey(tModelKey); tModel.setAuthorizedName(resultSet.getString(1));//("AUTHORIZED_NAME")); @@ -258,14 +314,12 @@ } return tModel; - } - finally - { + } finally { try { resultSet.close(); statement.close(); + } catch (Exception e) { /* ignored */ } - catch (Exception e) { /* ignored */ } } } @@ -273,25 +327,23 @@ * Select all TModelKeys from the business_entities table for a given * 'publisherID' value. * - * @param publisherID The User ID of the TModel owner. - * @param connection JDBC The JDBC connection + * @param publisherID + * The User ID of the TModel owner. + * @param connection + * JDBC The JDBC connection * @throws java.sql.SQLException */ - public static Vector selectByPublisherID(String publisherID,Connection connection) - throws java.sql.SQLException - { + public static Vector selectByPublisherID(String publisherID, Connection connection) throws java.sql.SQLException { Vector keyList = new Vector(); PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { // create a statement to query with statement = connection.prepareStatement(selectByPublisherSQL); statement.setString(1,publisherID.toString()); - log.debug(selectByPublisherSQL + - "\n\t PUBLISHER_ID=" + publisherID + "\n"); + log.debug(selectByPublisherSQL + "\n\t PUBLISHER_ID=" + publisherID + "\n"); // execute the statement resultSet = statement.executeQuery(); @@ -299,29 +351,25 @@ keyList.add(resultSet.getString(1));//("TMODEL_KEY")); return keyList; - } - finally - { + } finally { try { resultSet.close(); statement.close(); + } catch (Exception e) { /* ignored */ } - catch (Exception e) { /* ignored */ } } } /** - * Verify that 'publisherID' has the authority to update or delete - * TModel identified by the tModelKey parameter + * Verify that 'publisherID' has the authority to update or delete TModel + * identified by the tModelKey parameter * * @param tModelKey * @param publisherID * @param connection * @throws java.sql.SQLException */ - public static boolean verifyOwnership(String tModelKey,String publisherID,Connection connection) - throws java.sql.SQLException - { + public static boolean verifyOwnership(String tModelKey, String publisherID, Connection connection) throws java.sql.SQLException { if ((tModelKey == null) || (publisherID == null)) return false; @@ -329,29 +377,24 @@ PreparedStatement statement = null; ResultSet resultSet = null; - try - { + try { statement = connection.prepareStatement(verifyOwnershipSQL); statement.setString(1,tModelKey); statement.setString(2,publisherID); - log.debug(verifyOwnershipSQL + - "\n\t TMODEL_KEY=" + tModelKey + - "\n\t PUBLISHER_ID=" + publisherID + "\n"); + log.debug(verifyOwnershipSQL + "\n\t TMODEL_KEY=" + tModelKey + "\n\t PUBLISHER_ID=" + publisherID + "\n"); resultSet = statement.executeQuery(); if (resultSet.next()) authorized = true; return authorized; - } - finally - { + } finally { try { resultSet.close(); statement.close(); + } catch (Exception e) { /* ignored */ } - catch (Exception e) { /* ignored */ } } } } Index: org/apache/juddi/function/FindBusinessFunction.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/function/FindBusinessFunction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/function/FindBusinessFunction.java 3 Jul 2006 07:45:11 -0000 1.1 +++ org/apache/juddi/function/FindBusinessFunction.java 6 Jul 2006 16:09:30 -0000 1.2 @@ -15,6 +15,7 @@ */ package org.apache.juddi.function; +import java.util.List; import java.util.Vector; import org.apache.commons.logging.Log; @@ -44,44 +45,40 @@ /** * "This [FindBusiness] API call returns a businessList on success. This - * structure contains information about each matching business, and - * summaries of the businessServices exposed by the individual businesses. - * If a tModelBag was used in the search, the resulting serviceInfos - * structure will only reflect data for the businessServices that - * actually contained a matching bindingTemplate. In the event that - * no matches were located for the specified criteria, a businessList - * structure with zero businessInfo structures is returned. If no - * arguments are passed, a zero-match result set will be returned." + * structure contains information about each matching business, and summaries of + * the businessServices exposed by the individual businesses. If a tModelBag was + * used in the search, the resulting serviceInfos structure will only reflect + * data for the businessServices that actually contained a matching + * bindingTemplate. In the event that no matches were located for the specified + * criteria, a businessList structure with zero businessInfo structures is + * returned. If no arguments are passed, a zero-match result set will be + * returned." * - * "In the event of a large number of matches, (as determined by each - * Operator Site), or if the number of matches exceeds the value of the - * 'maxRows' attribute, the Operator Site will truncate the result set. - * If this occurs, the businessList will contain the 'truncated' attribute - * with the value 'true'". + * "In the event of a large number of matches, (as determined by each Operator + * Site), or if the number of matches exceeds the value of the 'maxRows' + * attribute, the Operator Site will truncate the result set. If this occurs, + * the businessList will contain the 'truncated' attribute with the value + * 'true'". * * From UDDI Version 2 Programmers API Specification (Pg. 18) * * @author Steve Viens (sviens@apache.org) */ -public class FindBusinessFunction extends AbstractFunction -{ +public class FindBusinessFunction extends AbstractFunction { // private reference to jUDDI Logger private static Log log = LogFactory.getLog(FindBusinessFunction.class); /** * */ - public FindBusinessFunction(RegistryEngine registry) - { + public FindBusinessFunction(RegistryEngine registry) { super(registry); } /** * */ - public RegistryObject execute(RegistryObject regObject) - throws RegistryException - { + public RegistryObject execute(RegistryObject regObject) throws RegistryException { FindBusiness request = (FindBusiness) regObject; String generic = request.getGeneric(); Vector nameVector = request.getNameVector(); @@ -95,12 +92,9 @@ // make sure we need to continue with this request. If // no arguments were passed in then we'll simply return // an empty BusinessList (aka "a zero match result set"). - if (((nameVector == null) || (nameVector.size() == 0)) - && ((discoveryURLs == null) || (discoveryURLs.size() == 0)) - && ((identifierBag == null) || (identifierBag.size() == 0)) - && ((categoryBag == null) || (categoryBag.size() == 0)) - && ((tModelBag == null) || (tModelBag.size() == 0))) - { + if (((nameVector == null) || (nameVector.size() == 0)) && ((discoveryURLs == null) || (discoveryURLs.size() == 0)) + && ((identifierBag == null) || (identifierBag.size() == 0)) && ((categoryBag == null) || (categoryBag.size() == 0)) + && ((tModelBag == null) || (tModelBag.size() == 0))) { BusinessList list = new BusinessList(); list.setGeneric(generic); list.setBusinessInfos(new BusinessInfos()); @@ -109,17 +103,14 @@ return list; } - // Validate CategoryBag and (if neccessary) add TModelKey for: uddiorg:general_keywords - if (categoryBag != null) - { + // Validate CategoryBag and (if neccessary) add TModelKey for: + // uddiorg:general_keywords + if (categoryBag != null) { Vector keyedRefVector = categoryBag.getKeyedReferenceVector(); - if (keyedRefVector != null) - { + if (keyedRefVector != null) { int vectorSize = keyedRefVector.size(); - if (vectorSize > 0) - { - for (int i=0; i 0) { + for (int i = 0; i < vectorSize; i++) { KeyedReference keyedRef = (KeyedReference)keyedRefVector.elementAt(i); String key = keyedRef.getTModelKey(); @@ -137,63 +128,50 @@ // aquire a jUDDI datastore instance DataStore dataStore = DataStoreFactory.getDataStore(); - try - { + try { dataStore.beginTrans(); - // validate the 'name' parameters as much as possible up-front before + // validate the 'name' parameters as much as possible up-front + // before // calling into the data layer for relational validation. - if (nameVector != null) - { + if (nameVector != null) { // only allowed to specify a maximum of 5 names (implementation // dependent). This value is configurable in jUDDI. int maxNames = Config.getMaxNameElementsAllowed(); if ((nameVector != null) && (nameVector.size() > maxNames)) - throw new TooManyOptionsException("find_business: "+ - "names="+nameVector.size()+", "+ - "maxNames=" + maxNames); + throw new TooManyOptionsException("find_business: " + "names=" + nameVector.size() + ", " + "maxNames=" + maxNames); - // names can not exceed the maximum character length specified by the - // UDDI specification (v2.0 specifies a max character length of 255). This + // names can not exceed the maximum character length specified + // by the + // UDDI specification (v2.0 specifies a max character length of + // 255). This // value is configurable in jUDDI. int maxNameLength = Config.getMaxNameLengthAllowed(); - for (int i = 0; i < nameVector.size(); i++) - { + for (int i = 0; i < nameVector.size(); i++) { String name = ((Name) nameVector.elementAt(i)).getValue(); if (name.length() > maxNameLength) - throw new NameTooLongException("find_business: "+ - "name="+name+", "+ - "length="+name.length()+", "+ - "maxNameLength="+maxNameLength); + throw new NameTooLongException("find_business: " + "name=" + name + ", " + "length=" + name.length() + ", " + "maxNameLength=" + + maxNameLength); } } - // validate the 'qualifiers' parameter as much as possible up-front before + // validate the 'qualifiers' parameter as much as possible up-front + // before // calling into the data layer for relational validation. - if (qualifiers != null) - { + if (qualifiers != null) { Vector qVector = qualifiers.getFindQualifierVector(); - if ((qVector!=null) && (qVector.size() > 0)) - { - for (int i = 0; i < qVector.size(); i++) - { + if ((qVector != null) && (qVector.size() > 0)) { + for (int i = 0; i < qVector.size(); i++) { FindQualifier qualifier = (FindQualifier) qVector.elementAt(i); String qValue = qualifier.getValue(); - if ((!qValue.equals(FindQualifier.EXACT_NAME_MATCH)) - && (!qValue.equals(FindQualifier.CASE_SENSITIVE_MATCH)) - && (!qValue.equals(FindQualifier.OR_ALL_KEYS)) - && (!qValue.equals(FindQualifier.OR_LIKE_KEYS)) - && (!qValue.equals(FindQualifier.AND_ALL_KEYS)) - && (!qValue.equals(FindQualifier.SORT_BY_NAME_ASC)) - && (!qValue.equals(FindQualifier.SORT_BY_NAME_DESC)) - && (!qValue.equals(FindQualifier.SORT_BY_DATE_ASC)) - && (!qValue.equals(FindQualifier.SORT_BY_DATE_DESC)) - && (!qValue.equals(FindQualifier.SERVICE_SUBSET)) - && (!qValue - .equals(FindQualifier.COMBINE_CATEGORY_BAGS))) - throw new UnsupportedException("find_business: "+ - "findQualifier="+qValue); + if ((!qValue.equals(FindQualifier.EXACT_NAME_MATCH)) && (!qValue.equals(FindQualifier.CASE_SENSITIVE_MATCH)) + && (!qValue.equals(FindQualifier.OR_ALL_KEYS)) && (!qValue.equals(FindQualifier.OR_LIKE_KEYS)) + && (!qValue.equals(FindQualifier.AND_ALL_KEYS)) && (!qValue.equals(FindQualifier.SORT_BY_NAME_ASC)) + && (!qValue.equals(FindQualifier.SORT_BY_NAME_DESC)) && (!qValue.equals(FindQualifier.SORT_BY_DATE_ASC)) + && (!qValue.equals(FindQualifier.SORT_BY_DATE_DESC)) && (!qValue.equals(FindQualifier.SERVICE_SUBSET)) + && (!qValue.equals(FindQualifier.COMBINE_CATEGORY_BAGS))) + throw new UnsupportedException("find_business: " + "findQualifier=" + qValue); } } } @@ -201,34 +179,31 @@ Vector infoVector = null; boolean truncatedResults = false; - // perform the search for matching business entities (returns only business keys in the order requested) - Vector keyVector = - dataStore.findBusiness( - nameVector, - discoveryURLs, - identifierBag, - categoryBag, - tModelBag, - qualifiers); - if ((keyVector != null) && (keyVector.size() > 0)) - { + // perform the search for matching business entities (returns only + // business keys in the order requested) + Vector keyVector = dataStore.findBusiness(nameVector, discoveryURLs, identifierBag, categoryBag, tModelBag, qualifiers); + if ((keyVector != null) && (keyVector.size() > 0)) { // if a maxRows value has been specified and it's less than // the number of rows we are about to return then only return // maxRows specified. int rowCount = keyVector.size(); - if ((maxRows > 0) && (maxRows < rowCount)) - { + if ((maxRows > 0) && (maxRows < rowCount)) { rowCount = maxRows; truncatedResults = true; } + // ArrayList keys=new ArrayList(); // iterate through the business entity keys fetching // each associated BusinessInfo in sequence. - infoVector = new Vector(rowCount); - for (int i = 0; i < rowCount; i++) - infoVector.addElement( - dataStore.fetchBusinessInfo( - (String) keyVector.elementAt(i))); + /* + * infoVector = new Vector(rowCount); for (int i = 0; i < + * rowCount; i++) { + * infoVector.addElement(dataStore.fetchBusinessInfo((String) + * keyVector.elementAt(i))); } + */ + + List l = dataStore.fetchBusinessesInfos(keyVector); + infoVector = new Vector(l); } dataStore.commit(); @@ -246,39 +221,42 @@ list.setOperator(Config.getOperator()); list.setTruncated(truncatedResults); return list; + } catch (TooManyOptionsException tmoex) { + try { + dataStore.rollback(); + } catch (Exception e) { } - catch(TooManyOptionsException tmoex) - { - try { dataStore.rollback(); } catch(Exception e) { } log.info(tmoex.getMessage()); throw (RegistryException)tmoex; + } catch (NameTooLongException ntlex) { + try { + dataStore.rollback(); + } catch (Exception e) { } - catch(NameTooLongException ntlex) - { - try { dataStore.rollback(); } catch(Exception e) { } log.info(ntlex.getMessage()); throw (RegistryException)ntlex; + } catch (UnsupportedException suppex) { + try { + dataStore.rollback(); + } catch (Exception e) { } - catch(UnsupportedException suppex) - { - try { dataStore.rollback(); } catch(Exception e) { } log.info(suppex.getMessage()); throw (RegistryException)suppex; + } catch (RegistryException regex) { + try { + dataStore.rollback(); + } catch (Exception e) { } - catch(RegistryException regex) - { - try { dataStore.rollback(); } catch(Exception e) { } log.error(regex); throw (RegistryException)regex; + } catch (Exception ex) { + try { + dataStore.rollback(); + } catch (Exception e) { } - catch(Exception ex) - { - try { dataStore.rollback(); } catch(Exception e) { } log.error(ex); throw new RegistryException(ex); - } - finally - { + } finally { if (dataStore != null) dataStore.release(); } @@ -288,14 +266,12 @@ /***************************** TEST DRIVER *********************************/ /***************************************************************************/ - public static void main(String[] args) - { + public static void main(String[] args) { // initialize the registry RegistryEngine reg = new RegistryEngine(); reg.init(); - try - { + try { // create a request Vector nameVector = new Vector(5); nameVector.addElement(new Name("InflexionPoint")); @@ -303,11 +279,11 @@ nameVector.addElement(new Name("Liberty Mutual")); nameVector.addElement(new Name("Bowstreet")); nameVector.addElement(new Name("CMGi")); - //nameVector.addElement(new Name("BusinessName #6 (1 over the maximum)")); + // nameVector.addElement(new Name("BusinessName #6 (1 over the + // maximum)")); Vector qualifierVector = new Vector(1); - qualifierVector.add( - new FindQualifier(FindQualifier.EXACT_NAME_MATCH)); + qualifierVector.add(new FindQualifier(FindQualifier.EXACT_NAME_MATCH)); //qualifierVector.add(new FindQualifier("anInvalidFindQualifier")); FindQualifiers qualifiers = new FindQualifiers(); @@ -330,10 +306,8 @@ identifierBag.setKeyedReferenceVector(identifierVector); Vector tModelKeyVector = new Vector(); - tModelKeyVector.addElement( - new String("6240b6f0-d4dd-4091-851b-d59fedbd0491")); - tModelKeyVector.addElement( - new String("ee0a154b-43ed-47be-b24f-878ab2956a31")); + tModelKeyVector.addElement(new String("6240b6f0-d4dd-4091-851b-d59fedbd0491")); + tModelKeyVector.addElement(new String("ee0a154b-43ed-47be-b24f-878ab2956a31")); TModelBag tModelBag = new TModelBag(); tModelBag.setTModelKeyVector(tModelKeyVector); @@ -356,17 +330,12 @@ request.setFindQualifiers(qualifiers); // invoke the server - BusinessList response = - (BusinessList) (new FindBusinessFunction(reg).execute(request)); + BusinessList response = (BusinessList) (new FindBusinessFunction(reg).execute(request)); System.out.println(response); - } - catch (Exception ex) - { + } catch (Exception ex) { // write execption to the console ex.printStackTrace(); - } - finally - { + } finally { // destroy the registry reg.dispose(); } Index: org/apache/juddi/function/FindServiceFunction.java =================================================================== RCS file: g:/local/cvs/cvs-uddi/juddi/src/java/org/apache/juddi/function/FindServiceFunction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -B -r1.1 -r1.2 --- org/apache/juddi/function/FindServiceFunction.java 3 Jul 2006 07:45:11 -0000 1.1 +++ org/apache/juddi/function/FindServiceFunction.java 7 Jul 2006 13:45:16 -0000 1.2 @@ -191,11 +191,14 @@ truncatedResults = true; } + infoVector=new Vector(dataStore.fetchServicesInfos(keyVector)); + + // iterate through the business server keys fetching // each associated ServiceInfo in sequence. - infoVector = new Vector(rowCount); + /* infoVector = new Vector(rowCount); for (int i=0; i