View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/ebxmlrr/src/share/com/sun/ebxml/registry/persistence/rdb/InternationalStringDAO.java,v 1.12 2003/05/30 22:42:36 waikei Exp $ 3 */ 4 5 package com.sun.ebxml.registry.persistence.rdb; 6 7 import java.util.*; 8 import java.sql.*; 9 10 import org.oasis.ebxml.registry.bindings.rim.*; 11 import org.oasis.ebxml.registry.bindings.rim.types.*; 12 13 import com.sun.ebxml.registry.*; 14 15 16 public abstract class InternationalStringDAO { 17 protected abstract String getTableName(); 18 19 InternationalStringType getInternationalStringByParent(java.sql.Connection conn, String parentId) throws RegistryException { 20 InternationalStringType is = null; 21 Statement stmt = null; 22 23 String tableName = getTableName(); 24 if (tableName.equalsIgnoreCase("Name_")) { 25 is = new Name(); 26 } 27 else if (tableName.equalsIgnoreCase("Description")) { 28 is = new Description(); 29 } 30 31 try { 32 stmt = conn.createStatement(); 33 ResultSet rs = stmt.executeQuery("select * from " + getTableName() + " where parent = '" + parentId + "'"); 34 35 while(rs.next()) { 36 String charsetName = rs.getString("charset"); 37 String lang = rs.getString("lang"); 38 String value = rs.getString("value"); 39 40 LocalizedString ls = new LocalizedString(); 41 ls.setCharset(charsetName); 42 ls.setLang(lang); 43 ls.setValue(value); 44 InternationalStringTypeItem isi = new InternationalStringTypeItem(); 45 isi.setLocalizedString(ls); 46 is.addInternationalStringTypeItem(isi); 47 } 48 49 } 50 catch (SQLException e) { 51 e.printStackTrace(); 52 throw new RegistryException(e); 53 } finally { 54 try { 55 if (stmt != null) 56 stmt.close(); 57 } catch (SQLException sqle) { 58 sqle.printStackTrace(); 59 } 60 } 61 62 return is; 63 } 64 65 public void insert(User user, java.sql.Connection connection 66 , String parentId, InternationalStringType is) throws RegistryException { 67 68 PreparedStatement pstmt = null; 69 70 try { 71 String str = "INSERT INTO " + getTableName() + 72 " VALUES(?, " + // charsetName 73 "?," + // lang 74 "?, " + // value 75 "?)"; // parentId 76 pstmt = connection.prepareStatement(str); 77 78 if (is != null) { 79 80 InternationalStringTypeItem[] lsItems = is.getInternationalStringTypeItem(); 81 82 for (int i=0; i<lsItems.length; i++) { 83 LocalizedString ls = lsItems[i].getLocalizedString(); 84 String charset = ls.getCharset(); 85 String lang = ls.getLang(); 86 String value = ls.getValue(); 87 String charsetName = ls.getCharset(); 88 89 pstmt.setString(1, charsetName); 90 pstmt.setString(2, lang); 91 pstmt.setString(3, value); 92 pstmt.setString(4, parentId); 93 pstmt.addBatch(); 94 } 95 } 96 97 if (is != null) { 98 int [] updateCounts = pstmt.executeBatch(); 99 pstmt.close(); 100 } 101 } 102 catch (java.sql.SQLException e) { 103 e.printStackTrace(); 104 RegistryException exception = new RegistryException(e); 105 throw exception; 106 } finally { 107 try { 108 pstmt.close(); 109 } catch (SQLException sqle) { 110 sqle.printStackTrace(); 111 } 112 } 113 } 114 115 public void deleteByParentIds(java.sql.Connection connection, ArrayList parentIds) throws RegistryException { 116 117 Statement stmt = null; 118 119 try { 120 stmt = connection.createStatement(); 121 122 Iterator iter = parentIds.iterator(); 123 while (iter.hasNext()) { 124 String parentId = (String)iter.next(); 125 126 127 stmt.addBatch("DELETE from " + getTableName() + " WHERE parent = '" + 128 parentId + "' "); 129 } 130 131 int [] updateCounts = stmt.executeBatch(); 132 stmt.close(); 133 } 134 catch (java.sql.SQLException e) { 135 RegistryException exception = new RegistryException(e); 136 throw exception; 137 } finally { 138 try { 139 if (stmt != null) 140 stmt.close(); 141 } catch (SQLException sqle) { 142 sqle.printStackTrace(); 143 } 144 } 145 } 146 147 }

This page was automatically generated by Maven