1 32 33 package com.knowgate.hipergate; 34 35 import java.sql.SQLException ; 36 import java.sql.PreparedStatement ; 37 import java.sql.ResultSet ; 38 import java.sql.ResultSetMetaData ; 39 40 import com.knowgate.debug.DebugFile; 41 import com.knowgate.jdc.JDCConnection; 42 import com.knowgate.dataobjs.DB; 43 import com.knowgate.dataobjs.DBPersist; 44 import com.knowgate.misc.Gadgets; 45 46 54 public class MetaAttribute extends DBPersist { 55 56 59 public MetaAttribute() { 60 super(DB.k_lu_meta_attrs, "MetaAttribute"); 61 } 62 63 71 public MetaAttribute(JDCConnection oConn, String sOwnerGUID, String sTableName, String sSectionName) throws SQLException { 72 super(DB.k_lu_meta_attrs, "MetaAttribute"); 73 PreparedStatement oStmt = oConn.prepareStatement("SELECT * FROM "+DB.k_lu_meta_attrs+" WHERE "+DB.gu_owner+"=? AND "+DB.nm_table+"=? AND "+DB.id_section+"=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 74 oStmt.setString(1, sOwnerGUID); 75 oStmt.setString(2, sTableName); 76 oStmt.setString(3, sSectionName); 77 ResultSet oRSet = oStmt.executeQuery(); 78 boolean bFound = oRSet.next(); 79 if (bFound) { 80 ResultSetMetaData oMDat = oRSet.getMetaData(); 81 int iColCount = oMDat.getColumnCount(); 82 for (int c=1; c<=iColCount; c++) { 83 put(oMDat.getColumnName(c).toLowerCase(), oRSet.getObject(c)); 84 } oRSet.close(); 86 oStmt.close(); 87 } 88 else { 89 oRSet.close(); 90 oStmt.close(); 91 throw new SQLException (DB.k_lu_meta_attrs + " No data found for "+sTableName+"."+sSectionName+" at WorkArea "+sOwnerGUID,"42S02",100); 92 } 93 } 94 95 97 103 public boolean delete(JDCConnection oConn) 104 throws SQLException ,NullPointerException { 105 PreparedStatement oStmt; 106 boolean bRetVal; 107 108 if (DebugFile.trace) { 109 DebugFile.writeln("Begin MetaAttribute.delete([Connection])"); 110 } 111 112 if (isNull(DB.nm_table)) 113 throw new NullPointerException ("Base table for meta-attribute not set"); 114 if (isNull(DB.gu_owner)) 115 throw new NullPointerException ("Owner WorkArea for meta-attribute not set"); 116 if (isNull(DB.id_section)) 117 throw new NullPointerException ("Section for meta-attribute not set"); 118 119 if (DebugFile.trace) { 120 DebugFile.incIdent(); 121 DebugFile.writeln("Connection.prepareStatement(DELETE FROM " + DB.k_lu_meta_attrs + " WHERE " + DB.gu_owner + "='"+getStringNull(DB.gu_owner,"null")+"' AND " + DB.nm_table + "='" + getStringNull(DB.nm_table,"null")+"' AND " + DB.id_section + "='" + getStringNull(DB.id_section,"null") + "'"); 122 } 123 124 oStmt = oConn.prepareStatement("DELETE FROM " + DB.k_lu_meta_attrs + " WHERE " + DB.gu_owner + "=? AND " + DB.nm_table + "=? AND " + DB.id_section + "=?"); 125 oStmt.setString(1, getString(DB.gu_owner)); 126 oStmt.setString(2, getString(DB.nm_table)); 127 oStmt.setString(3, getString(DB.id_section)); 128 oStmt.executeUpdate(); 129 oStmt.close(); 130 131 bRetVal = super.delete(oConn); 132 133 if (DebugFile.trace) { 134 DebugFile.decIdent(); 135 DebugFile.writeln("End MetaAttribute.delete() : " + String.valueOf(bRetVal)); 136 } 137 138 return bRetVal; 139 } 141 143 150 public boolean store(JDCConnection oConn) throws SQLException { 151 PreparedStatement oStmt; 152 ResultSet oRSet; 153 Object oMax; 154 Integer iMax; 155 boolean bRetVal; 156 157 if (DebugFile.trace) { 158 DebugFile.writeln("Begin MetaAttribute.stor([Connection])"); 159 DebugFile.incIdent(); 160 DebugFile.writeln("Connection.prepareStatement(SELECT MAX(" + DB.pg_attr + ")+1 FROM " + DB.k_lu_meta_attrs + " WHERE " + DB.gu_owner + "='" + getStringNull(DB.gu_owner, "") + "' AND " + DB.nm_table + "='" + getStringNull(DB.nm_table,"") + "')"); 161 } 162 163 if (!AllVals.containsKey(DB.pg_attr)) { 164 oStmt = oConn.prepareStatement("SELECT MAX(" + DB.pg_attr + ")+1 FROM " + DB.k_lu_meta_attrs + " WHERE " + DB.gu_owner + "=? AND " + DB.nm_table + "=?"); 165 oStmt.setString(1, getString(DB.gu_owner)); 166 oStmt.setString(2, getString(DB.nm_table)); 167 oRSet = oStmt.executeQuery(); 168 if (oRSet.next()) { 169 oMax = oRSet.getObject(1); 170 if (oRSet.wasNull()) 171 iMax = new Integer (1); 172 else 173 iMax = new Integer (oMax.toString()); 174 } 175 else 176 iMax = new Integer (1); 177 oRSet.close(); 178 oStmt.close(); 179 180 if (oConn.getDataBaseProduct()==JDCConnection.DBMS_ORACLE) 181 put (DB.pg_attr, new java.math.BigDecimal (iMax.toString())); 182 else 183 put (DB.pg_attr, new Short (iMax.toString())); 184 } 185 186 bRetVal = super.store(oConn); 187 188 if (DebugFile.trace) { 189 DebugFile.decIdent(); 190 DebugFile.writeln("End MetaAttribute.store() : " + String.valueOf(bRetVal)); 191 } 192 193 return bRetVal; 194 } 196 199 public static final short ClassId = 12; 200 } 201 | Popular Tags |