1 32 33 package com.knowgate.billing; 34 35 import java.sql.SQLException ; 36 import java.sql.Statement ; 37 import java.sql.CallableStatement ; 38 import java.sql.ResultSet ; 39 import java.sql.Types ; 40 41 import com.knowgate.jdc.JDCConnection; 42 import com.knowgate.dataobjs.DB; 43 import com.knowgate.dataobjs.DBBind; 44 import com.knowgate.dataobjs.DBPersist; 45 46 import com.knowgate.misc.Gadgets; 47 48 53 54 public class Account extends DBPersist { 55 public Account() { 56 super(DB.k_accounts, "Account"); 57 } 58 59 61 public boolean store(JDCConnection oConn) throws SQLException { 62 java.sql.Timestamp dtNow = new java.sql.Timestamp (DBBind.getTime()); 63 java.math.BigDecimal d; 64 65 if (!AllVals.containsKey(DB.id_account)) { 66 String sNextAccount = Gadgets.leftPad(String.valueOf(DBBind.nextVal(oConn, "seq_" + DB.k_accounts)), '0', 10); 67 put (DB.id_account, sNextAccount); 68 } 69 70 replace(DB.dt_modified, dtNow); 71 72 return super.store(oConn); 73 } 75 78 89 public static String getUserAccountType(JDCConnection oConn, String sUserId) throws SQLException { 90 Statement oStmt; 91 ResultSet oRSet; 92 CallableStatement oCall; 93 String sTp; 94 95 if (oConn.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL) { 96 oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 97 oRSet = oStmt.executeQuery("SELECT k_get_account_tp ('" + sUserId + "')"); 98 oRSet.next(); 99 sTp = oRSet.getString(1); 100 oRSet.close(); 101 oStmt.close(); 102 } 103 else { 104 oCall = oConn.prepareCall("{ call k_get_account_tp (?,?) }"); 105 106 oCall.setString(1, sUserId); 107 oCall.registerOutParameter(2, Types.CHAR); 108 109 oCall.execute(); 110 111 if (JDCConnection.DBMS_ORACLE==oConn.getDataBaseProduct()) 112 sTp = oCall.getString(2); 113 else 114 sTp = oCall.getString(2); 115 116 if (sTp!=null) sTp = sTp.trim(); 117 118 oCall.close(); 119 } 120 return sTp; 121 } 123 125 132 public static boolean checkStatus (JDCConnection oConn, String sAccId) throws SQLException { 133 Statement oStmt; 134 ResultSet oRSet; 135 CallableStatement oCall; 136 short iActive; 137 138 if (oConn.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL) { 139 oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 140 oRSet = oStmt.executeQuery("SELECT k_check_account ('" + sAccId + "')"); 141 oRSet.next(); 142 iActive = oRSet.getShort(1); 143 oRSet.close(); 144 oStmt.close(); 145 } 146 else { 147 oCall = oConn.prepareCall("{ call k_check_account (?,?) }"); 148 oCall.setString(1, sAccId); 149 oCall.registerOutParameter(2, Types.SMALLINT); 150 oCall.execute(); 151 iActive = oCall.getShort(2); 152 oCall.close(); 153 } 154 155 return ((short)0!=iActive); 156 157 } 159 161 168 public static int daysLeft (JDCConnection oConn, String sAccId) throws SQLException { 169 Statement oStmt; 170 ResultSet oRSet; 171 CallableStatement oCall; 172 int iDaysLeft; 173 174 if (oConn.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL) { 175 oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 176 oRSet = oStmt.executeQuery("SELECT k_get_account_days_left ('" + sAccId + "')"); 177 oRSet.next(); 178 iDaysLeft = oRSet.getInt(1); 179 oRSet.close(); 180 oStmt.close(); 181 } 182 else { 183 oCall = oConn.prepareCall("{ call k_get_account_days_left (?,?) }"); 184 oCall.setString(1, sAccId); 185 oCall.registerOutParameter(2, Types.INTEGER); 186 oCall.execute(); 187 iDaysLeft = oCall.getInt(2); 188 oCall.close(); 189 } 190 191 return iDaysLeft; 192 } 194 196 203 public static boolean isTrial (JDCConnection oConn, String sAccId) throws SQLException { 204 Statement oStmt; 205 ResultSet oRSet; 206 CallableStatement oCall; 207 short iTrial; 208 209 if (oConn.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL) { 210 oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 211 oRSet = oStmt.executeQuery("SELECT k_get_account_trial ('" + sAccId + "')"); 212 oRSet.next(); 213 iTrial = oRSet.getShort(1); 214 oRSet.close(); 215 oStmt.close(); 216 } 217 else { 218 oCall = oConn.prepareCall("{ call k_get_account_trial (?,?) }"); 219 oCall.setString(1, sAccId); 220 oCall.registerOutParameter(2, Types.SMALLINT); 221 oCall.execute(); 222 iTrial = oCall.getShort(2); 223 oCall.close(); 224 } 225 226 return ((short)0!=iTrial); 227 } 229 232 public static final short ClassId = 6; 233 234 }
| Popular Tags
|