public void deleteSecDevice(CFSecurityAuthorization Authorization, CFSecuritySecDeviceBuff Buff) { final String S_ProcName = "deleteSecDevice"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); UUID SecUserId = Buff.getRequiredSecUserId(); String DevName = Buff.getRequiredDevName(); String sql = "call " + schema.getLowerDbSchemaName() + ".sp_delete_secdev( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + " )"; if (stmtDeleteByPKey == null) { stmtDeleteByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByPKey.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByPKey.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByPKey.setString(argIdx++, SecUserId.toString()); stmtDeleteByPKey.setString(argIdx++, DevName); stmtDeleteByPKey.setInt(argIdx++, Buff.getRequiredRevision()); ; stmtDeleteByPKey.executeUpdate(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try { // Common XML Attributes String attrId = null; String attrRevision = null; // SecDevice Attributes String attrSecUserId = null; String attrDevName = null; String attrPubKey = null; String attrCreatedAt = null; String attrCreatedBy = null; String attrUpdatedAt = null; String attrUpdatedBy = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("RspnSecDeviceCreated"); CFCrmXMsgRspnHandler xmsgRspnHandler = (CFCrmXMsgRspnHandler) getParser(); if (xmsgRspnHandler == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFCrmSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()"); } // Extract Attributes numAttrs = attrs.getLength(); for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) { attrLocalName = attrs.getLocalName(idxAttr); if (attrLocalName.equals("Id")) { if (attrId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Revision")) { if (attrRevision != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrRevision = attrs.getValue(idxAttr); } else if (attrLocalName.equals("CreatedAt")) { if (attrCreatedAt != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCreatedAt = attrs.getValue(idxAttr); } else if (attrLocalName.equals("CreatedBy")) { if (attrCreatedBy != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCreatedBy = attrs.getValue(idxAttr); } else if (attrLocalName.equals("UpdatedAt")) { if (attrUpdatedAt != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrUpdatedAt = attrs.getValue(idxAttr); } else if (attrLocalName.equals("UpdatedBy")) { if (attrUpdatedBy != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrUpdatedBy = attrs.getValue(idxAttr); } else if (attrLocalName.equals("SecUserId")) { if (attrSecUserId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrSecUserId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("DevName")) { if (attrDevName != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrDevName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("PubKey")) { if (attrPubKey != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrPubKey = attrs.getValue(idxAttr); } else if (attrLocalName.equals("schemaLocation")) { // ignored } else { throw CFLib.getDefaultExceptionFactory() .newUnrecognizedAttributeException( getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName); } } // Ensure that required attributes have values if ((attrSecUserId == null) || (attrSecUserId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "SecUserId"); } if (attrDevName == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "DevName"); } if ((attrRevision == null) || (attrRevision.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "Revision"); } // Save named attributes to context CFLibXmlCoreContext curContext = getParser().getCurContext(); // Convert string attributes to native Java types UUID natSecUserId = UUID.fromString(attrSecUserId); String natDevName = attrDevName; String natPubKey = attrPubKey; int natRevision = Integer.parseInt(attrRevision); UUID createdBy = null; if (attrCreatedBy != null) { createdBy = UUID.fromString(attrCreatedBy); } Calendar createdAt = null; if (attrCreatedAt != null) { createdAt = CFLibXmlUtil.parseTimestamp(attrCreatedAt); } UUID updatedBy = null; if (attrUpdatedBy != null) { updatedBy = UUID.fromString(attrUpdatedBy); } Calendar updatedAt = null; if (attrUpdatedAt != null) { updatedAt = CFLibXmlUtil.parseTimestamp(attrUpdatedAt); } // Instantiate a buffer for the parsed information ICFCrmSecDeviceObj obj = (ICFCrmSecDeviceObj) schemaObj.getSecDeviceTableObj().newInstance(); CFSecuritySecDeviceBuff dataBuff = obj.getSecDeviceBuff(); dataBuff.setRequiredSecUserId(natSecUserId); dataBuff.setRequiredDevName(natDevName); dataBuff.setOptionalPubKey(natPubKey); dataBuff.setRequiredRevision(natRevision); if (createdBy != null) { dataBuff.setCreatedByUserId(createdBy); } if (createdAt != null) { dataBuff.setCreatedAt(createdAt); } if (updatedBy != null) { dataBuff.setUpdatedByUserId(updatedBy); } if (updatedAt != null) { dataBuff.setUpdatedAt(updatedAt); } obj.copyBuffToPKey(); ICFCrmSecDeviceObj realized = (ICFCrmSecDeviceObj) obj.realize(); xmsgRspnHandler.setLastObjectProcessed(realized); } catch (RuntimeException e) { throw new RuntimeException( "Near " + getParser().getLocationInfo() + ": Caught and rethrew " + e.getClass().getName() + " - " + e.getMessage(), e); } catch (Error e) { throw new Error( "Near " + getParser().getLocationInfo() + ": Caught and rethrew " + e.getClass().getName() + " - " + e.getMessage(), e); } }
protected CFSecuritySecDeviceBuff unpackSecDeviceResultSetToBuff(ResultSet resultSet) throws SQLException { final String S_ProcName = "unpackSecDeviceResultSetToBuff"; int idxcol = 1; CFSecuritySecDeviceBuff buff = schema.getFactorySecDevice().newBuff(); { String colString = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setCreatedAt(null); } else if ((colString == null) || (colString.length() <= 0)) { buff.setCreatedAt(null); } else { buff.setCreatedAt(CFSecurityMySqlSchema.convertTimestampString(colString)); } } idxcol++; { String colString = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setCreatedByUserId(null); } else if ((colString == null) || (colString.length() <= 0)) { buff.setCreatedByUserId(null); } else { buff.setCreatedByUserId(UUID.fromString(colString)); } } idxcol++; { String colString = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setUpdatedAt(null); } else if ((colString == null) || (colString.length() <= 0)) { buff.setUpdatedAt(null); } else { buff.setUpdatedAt(CFSecurityMySqlSchema.convertTimestampString(colString)); } } idxcol++; { String colString = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setUpdatedByUserId(null); } else if ((colString == null) || (colString.length() <= 0)) { buff.setUpdatedByUserId(null); } else { buff.setUpdatedByUserId(UUID.fromString(colString)); } } idxcol++; buff.setRequiredSecUserId(CFSecurityMySqlSchema.convertUuidString(resultSet.getString(idxcol))); idxcol++; buff.setRequiredDevName(resultSet.getString(idxcol)); idxcol++; { String colVal = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setOptionalPubKey(null); } else { buff.setOptionalPubKey(colVal); } } idxcol++; buff.setRequiredRevision(resultSet.getInt(idxcol)); return (buff); }
public void updateSecDevice(CFSecurityAuthorization Authorization, CFSecuritySecDeviceBuff Buff) { final String S_ProcName = "updateSecDevice"; ResultSet resultSet = null; try { UUID SecUserId = Buff.getRequiredSecUserId(); String DevName = Buff.getRequiredDevName(); String PubKey = Buff.getOptionalPubKey(); int Revision = Buff.getRequiredRevision(); Connection cnx = schema.getCnx(); String sql = "call " + schema.getLowerDbSchemaName() + ".sp_update_secdev( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + " )"; if (stmtUpdateByPKey == null) { stmtUpdateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtUpdateByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtUpdateByPKey.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtUpdateByPKey.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtUpdateByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtUpdateByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtUpdateByPKey.setString(argIdx++, "SDEV"); stmtUpdateByPKey.setString(argIdx++, SecUserId.toString()); stmtUpdateByPKey.setString(argIdx++, DevName); if (PubKey != null) { stmtUpdateByPKey.setString(argIdx++, PubKey); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } stmtUpdateByPKey.setInt(argIdx++, Revision); try { resultSet = stmtUpdateByPKey.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } if ((resultSet != null) && resultSet.next()) { CFSecuritySecDeviceBuff updatedBuff = unpackSecDeviceResultSetToBuff(resultSet); if ((resultSet != null) && resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setOptionalPubKey(updatedBuff.getOptionalPubKey()); Buff.setRequiredRevision(updatedBuff.getRequiredRevision()); } else { throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
public void deleteSecDevice(CFSecurityAuthorization Authorization, CFSecuritySecDeviceBuff Buff) { final String S_ProcName = "deleteSecDevice"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); UUID SecUserId = Buff.getRequiredSecUserId(); String DevName = Buff.getRequiredDevName(); String sql = "SELECT " + schema.getLowerDbSchemaName() + ".sp_delete_secdev( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + " ) as DeletedFlag"; if (stmtDeleteByPKey == null) { stmtDeleteByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByPKey.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByPKey.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByPKey.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByPKey.setString(argIdx++, SecUserId.toString()); stmtDeleteByPKey.setString(argIdx++, DevName); stmtDeleteByPKey.setInt(argIdx++, Buff.getRequiredRevision()); ; resultSet = stmtDeleteByPKey.executeQuery(); if (resultSet.next()) { boolean deleteFlag = resultSet.getBoolean(1); if (resultSet.next()) { throw CFLib.getDefaultExceptionFactory() .newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response"); } } else { throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }