1 34 35 36 package com.micronova.jsp.tag; 37 38 import java.util.*; 39 import java.util.regex.*; 40 import java.sql.*; 41 import javax.sql.*; 42 import javax.naming.*; 43 import javax.servlet.jsp.*; 44 import javax.servlet.jsp.jstl.core.Config; 45 import org.apache.taglibs.standard.tag.common.sql.ResultImpl; 46 import com.micronova.util.*; 47 48 49 50 public class UpdateTag extends EvalTag 51 { 52 protected Object _dataSource; 53 protected List _nameList; 54 protected StringBuffer _buffer; 55 56 protected void init() 57 { 58 super.init(); 59 60 _pattern = EL.DEFAULTPATTERNQUERY; 61 _dataSource = null; 62 _export = null; 63 64 _nameList = null; 65 66 if (_buffer == null) 67 { 68 _buffer = new StringBuffer (); 69 } 70 } 71 72 protected Object doSql(PreparedStatement preparedStatement) throws Exception 73 { 74 return new Integer (preparedStatement.executeUpdate()); 75 } 76 77 protected Connection getConnection(Object spec) throws Exception 78 { 79 if (spec == null) 80 { 81 spec = getConfiguration(Config.SQL_DATA_SOURCE, null); 82 } 83 84 return TransactionTag.openConnection(spec); 85 } 86 87 protected Object evaluate(Object tagValue, Pattern pattern) throws Exception 88 { 89 Object value = null; 90 String expression = tagValue.toString(); 91 92 Connection connection = null; 93 boolean doesCloseConnection = false; 94 PreparedStatement preparedStatement = null; 95 96 try 97 { 98 Object dataSource = _dataSource; 99 100 if (dataSource == null) 101 { 102 connection = TransactionTag.getAncestorConnection(this); 103 } 104 105 if (connection == null) 106 { 107 doesCloseConnection = true; 108 109 connection = getConnection(dataSource); 110 } 111 112 preparedStatement = SQLObjectSource.prepareStatement(connection, expression, pattern, this, _recursive, _allowGroup); 113 114 value = doSql(preparedStatement); 115 } 116 catch (Exception e) 117 { 118 throw e; 119 } 120 finally 121 { 122 if (doesCloseConnection) 123 { 124 if (preparedStatement != null) 125 { 126 preparedStatement.close(); 127 } 128 129 if (connection != null) 130 { 131 connection.close(); 132 } 133 } 134 } 135 136 return value; 137 } 138 139 public void setDataSource(Object expression) throws Exception 140 { 141 Object dataSource = evaluateAttribute("dataSource", expression, Object .class); 142 143 if (!isEmptyString(dataSource)) 144 { 145 _dataSource = dataSource; 146 } 147 } 148 } 149 | Popular Tags |