Example usage for java.sql SQLException getErrorCode

List of usage examples for java.sql SQLException getErrorCode

Introduction

In this page you can find the example usage for java.sql SQLException getErrorCode.

Prototype

public int getErrorCode() 

Source Link

Document

Retrieves the vendor-specific exception code for this SQLException object.

Usage

From source file:net.sourceforge.msscodefactory.cfensyntax.v2_2.CFEnSyntaxMySql.CFEnSyntaxMySqlSecDeviceTable.java

public CFEnSyntaxSecDeviceBuff[] readBuffByUserIdx(CFEnSyntaxAuthorization Authorization, UUID SecUserId) {
    final String S_ProcName = "readBuffByUserIdx";
    ResultSet resultSet = null;/*from  ww w. j  av  a2  s  . c om*/
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerDbSchemaName() + ".sp_read_secdev_by_useridx( ?, ?, ?, ?, ?"
                + ", " + "?" + " )";
        if (stmtReadBuffByUserIdx == null) {
            stmtReadBuffByUserIdx = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadBuffByUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByUserIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadBuffByUserIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadBuffByUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadBuffByUserIdx.setString(argIdx++, SecUserId.toString());
        try {
            resultSet = stmtReadBuffByUserIdx.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        List<CFEnSyntaxSecDeviceBuff> buffList = new LinkedList<CFEnSyntaxSecDeviceBuff>();
        while ((resultSet != null) && resultSet.next()) {
            CFEnSyntaxSecDeviceBuff buff = unpackSecDeviceResultSetToBuff(resultSet);
            buffList.add(buff);
        }
        int idx = 0;
        CFEnSyntaxSecDeviceBuff[] retBuff = new CFEnSyntaxSecDeviceBuff[buffList.size()];
        Iterator<CFEnSyntaxSecDeviceBuff> iter = buffList.iterator();
        while (iter.hasNext()) {
            retBuff[idx++] = iter.next();
        }
        return (retBuff);
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
    }
}

From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_1.CFFswMySql.CFFswMySqlSecDeviceTable.java

public CFFswSecDeviceBuff readBuff(CFFswAuthorization Authorization, CFFswSecDevicePKey PKey) {
    final String S_ProcName = "readBuff";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }/*www  .j av a 2 s  .  c  om*/
    ResultSet resultSet = null;
    try {
        Connection cnx = schema.getCnx();
        UUID SecUserId = PKey.getRequiredSecUserId();
        String DevName = PKey.getRequiredDevName();
        String sql = "call " + schema.getLowerDbSchemaName() + ".sp_read_secdev( ?, ?, ?, ?, ?" + ", " + "?"
                + ", " + "?" + " )";
        if (stmtReadBuffByPKey == null) {
            stmtReadBuffByPKey = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByPKey.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadBuffByPKey.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadBuffByPKey.setString(argIdx++, SecUserId.toString());
        stmtReadBuffByPKey.setString(argIdx++, DevName);
        try {
            resultSet = stmtReadBuffByPKey.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        if ((resultSet != null) && resultSet.next()) {
            CFFswSecDeviceBuff buff = 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");
            }
            return (buff);
        } else {
            return (null);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
    }
}

From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_1.CFFswMySql.CFFswMySqlSecDeviceTable.java

public CFFswSecDeviceBuff lockBuff(CFFswAuthorization Authorization, CFFswSecDevicePKey PKey) {
    final String S_ProcName = "lockBuff";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }// w  ww  .  j  av a  2  s.c om
    ResultSet resultSet = null;
    try {
        Connection cnx = schema.getCnx();
        UUID SecUserId = PKey.getRequiredSecUserId();
        String DevName = PKey.getRequiredDevName();
        String sql = "call " + schema.getLowerDbSchemaName() + ".sp_lock_secdev( ?, ?, ?, ?, ?" + ", " + "?"
                + ", " + "?" + " )";
        if (stmtLockBuffByPKey == null) {
            stmtLockBuffByPKey = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtLockBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtLockBuffByPKey.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtLockBuffByPKey.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtLockBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtLockBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtLockBuffByPKey.setString(argIdx++, SecUserId.toString());
        stmtLockBuffByPKey.setString(argIdx++, DevName);
        try {
            resultSet = stmtLockBuffByPKey.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        if ((resultSet != null) && resultSet.next()) {
            CFFswSecDeviceBuff buff = 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");
            }
            return (buff);
        } else {
            return (null);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
    }
}

From source file:net.sourceforge.msscodefactory.cfensyntax.v2_2.CFEnSyntaxMySql.CFEnSyntaxMySqlSecDeviceTable.java

public CFEnSyntaxSecDeviceBuff readBuffByIdIdx(CFEnSyntaxAuthorization Authorization, UUID SecUserId,
        String DevName) {/*from  ww  w  .  ja  v a  2 s .c  o m*/
    final String S_ProcName = "readBuffByIdIdx";
    ResultSet resultSet = null;
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerDbSchemaName() + ".sp_read_secdev_by_ididx( ?, ?, ?, ?, ?" + ", "
                + "?" + ", " + "?" + " )";
        if (stmtReadBuffByIdIdx == null) {
            stmtReadBuffByIdIdx = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadBuffByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByIdIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadBuffByIdIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadBuffByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadBuffByIdIdx.setString(argIdx++, SecUserId.toString());
        stmtReadBuffByIdIdx.setString(argIdx++, DevName);
        try {
            resultSet = stmtReadBuffByIdIdx.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        if ((resultSet != null) && resultSet.next()) {
            CFEnSyntaxSecDeviceBuff buff = 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");
            }
            return (buff);
        } else {
            return (null);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
    }
}

From source file:net.pms.dlna.DLNAMediaDatabase.java

public synchronized void insertData(String name, long modified, int type, DLNAMediaInfo media) {
    Connection conn = null;//from   w  ww  .  j av a  2 s. c  o m
    PreparedStatement ps = null;
    try {
        conn = getConnection();
        ps = conn.prepareStatement(
                "INSERT INTO FILES(FILENAME, MODIFIED, TYPE, DURATION, BITRATE, WIDTH, HEIGHT, SIZE, CODECV, FRAMERATE, ASPECT, ASPECTRATIOCONTAINER, ASPECTRATIOVIDEOTRACK, REFRAMES, AVCLEVEL, BITSPERPIXEL, THUMB, CONTAINER, MODEL, EXPOSURE, ORIENTATION, ISO, MUXINGMODE, FRAMERATEMODE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
        ps.setString(1, name);
        ps.setTimestamp(2, new Timestamp(modified));
        ps.setInt(3, type);
        if (media != null) {
            if (media.getDuration() != null) {
                ps.setDouble(4, media.getDurationInSeconds());
            } else {
                ps.setNull(4, Types.DOUBLE);
            }

            int databaseBitrate = 0;
            if (type != Format.IMAGE) {
                databaseBitrate = media.getBitrate();
                if (databaseBitrate == 0) {
                    logger.debug("Could not parse the bitrate from: " + name);
                }
            }
            ps.setInt(5, databaseBitrate);

            ps.setInt(6, media.getWidth());
            ps.setInt(7, media.getHeight());
            ps.setLong(8, media.getSize());
            ps.setString(9, left(media.getCodecV(), SIZE_CODECV));
            ps.setString(10, left(media.getFrameRate(), SIZE_FRAMERATE));
            ps.setString(11, left(media.getAspect(), SIZE_ASPECT));
            ps.setString(12, left(media.getAspect(), SIZE_ASPECTRATIO_CONTAINER));
            ps.setString(13, left(media.getAspect(), SIZE_ASPECTRATIO_VIDEOTRACK));
            ps.setByte(14, media.getReferenceFrameCount());
            ps.setString(15, left(media.getAvcLevel(), SIZE_AVC_LEVEL));
            ps.setInt(16, media.getBitsPerPixel());
            ps.setBytes(17, media.getThumb());
            ps.setString(18, left(media.getContainer(), SIZE_CONTAINER));
            if (media.getExtras() != null) {
                ps.setString(19, left(media.getExtrasAsString(), SIZE_MODEL));
            } else {
                ps.setString(19, left(media.getModel(), SIZE_MODEL));
            }
            ps.setInt(20, media.getExposure());
            ps.setInt(21, media.getOrientation());
            ps.setInt(22, media.getIso());
            ps.setString(23, left(media.getMuxingModeAudio(), SIZE_MUXINGMODE));
            ps.setString(24, left(media.getFrameRateMode(), SIZE_FRAMERATE_MODE));
        } else {
            ps.setString(4, null);
            ps.setInt(5, 0);
            ps.setInt(6, 0);
            ps.setInt(7, 0);
            ps.setLong(8, 0);
            ps.setString(9, null);
            ps.setString(10, null);
            ps.setString(11, null);
            ps.setString(12, null);
            ps.setString(13, null);
            ps.setByte(14, (byte) -1);
            ps.setString(15, null);
            ps.setInt(16, 0);
            ps.setBytes(17, null);
            ps.setString(18, null);
            ps.setString(19, null);
            ps.setInt(20, 0);
            ps.setInt(21, 0);
            ps.setInt(22, 0);
            ps.setString(23, null);
            ps.setString(24, null);
        }
        ps.executeUpdate();
        ResultSet rs = ps.getGeneratedKeys();
        int id = -1;
        while (rs.next()) {
            id = rs.getInt(1);
        }
        rs.close();
        if (media != null && id > -1) {
            PreparedStatement insert = null;
            if (media.getAudioTracksList().size() > 0) {
                insert = conn.prepareStatement(
                        "INSERT INTO AUDIOTRACKS VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
            }

            for (DLNAMediaAudio audio : media.getAudioTracksList()) {
                insert.clearParameters();
                insert.setInt(1, id);
                insert.setInt(2, audio.getId());
                insert.setString(3, left(audio.getLang(), SIZE_LANG));
                insert.setString(4, left(audio.getFlavor(), SIZE_FLAVOR));
                insert.setInt(5, audio.getAudioProperties().getNumberOfChannels());
                insert.setString(6, left(audio.getSampleFrequency(), SIZE_SAMPLEFREQ));
                insert.setString(7, left(audio.getCodecA(), SIZE_CODECA));
                insert.setInt(8, audio.getBitsperSample());
                insert.setString(9, left(trimToEmpty(audio.getAlbum()), SIZE_ALBUM));
                insert.setString(10, left(trimToEmpty(audio.getArtist()), SIZE_ARTIST));
                insert.setString(11, left(trimToEmpty(audio.getSongname()), SIZE_SONGNAME));
                insert.setString(12, left(trimToEmpty(audio.getGenre()), SIZE_GENRE));
                insert.setInt(13, audio.getYear());
                insert.setInt(14, audio.getTrack());
                insert.setInt(15, audio.getAudioProperties().getAudioDelay());
                insert.setString(16, left(trimToEmpty(audio.getMuxingModeAudio()), SIZE_MUXINGMODE));
                insert.setInt(17, audio.getBitRate());

                try {
                    insert.executeUpdate();
                } catch (JdbcSQLException e) {
                    if (e.getErrorCode() == 23505) {
                        logger.debug(
                                "A duplicate key error occurred while trying to store the following file's audio information in the database: "
                                        + name);
                    } else {
                        logger.debug(
                                "An error occurred while trying to store the following file's audio information in the database: "
                                        + name);
                    }
                    logger.debug("The error given by jdbc was: " + e);
                }
            }

            if (media.getSubtitleTracksList().size() > 0) {
                insert = conn.prepareStatement("INSERT INTO SUBTRACKS VALUES (?, ?, ?, ?, ?)");
            }
            for (DLNAMediaSubtitle sub : media.getSubtitleTracksList()) {
                if (sub.getExternalFile() == null) { // no save of external subtitles
                    insert.clearParameters();
                    insert.setInt(1, id);
                    insert.setInt(2, sub.getId());
                    insert.setString(3, left(sub.getLang(), SIZE_LANG));
                    insert.setString(4, left(sub.getFlavor(), SIZE_FLAVOR));
                    insert.setInt(5, sub.getType().getStableIndex());
                    try {
                        insert.executeUpdate();
                    } catch (JdbcSQLException e) {
                        if (e.getErrorCode() == 23505) {
                            logger.debug(
                                    "A duplicate key error occurred while trying to store the following file's subtitle information in the database: "
                                            + name);
                        } else {
                            logger.debug(
                                    "An error occurred while trying to store the following file's subtitle information in the database: "
                                            + name);
                        }
                        logger.debug("The error given by jdbc was: " + e);
                    }
                }
            }
            close(insert);
        }
    } catch (SQLException se) {
        if (se.getErrorCode() == 23001) {
            logger.debug("Duplicate key while inserting this entry: " + name + " into the database: "
                    + se.getMessage());
        } else {
            logger.error(null, se);
        }
    } finally {
        close(ps);
        close(conn);
    }
}

From source file:net.sourceforge.msscodefactory.cfensyntax.v2_2.CFEnSyntaxMySql.CFEnSyntaxMySqlSecDeviceTable.java

public CFEnSyntaxSecDeviceBuff[] readAllBuff(CFEnSyntaxAuthorization Authorization) {
    final String S_ProcName = "readAllBuff";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }//from  w  w w .  j a  va2  s.c o m
    ResultSet resultSet = null;
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerDbSchemaName() + ".sp_read_secdev_all( ?, ?, ?, ?, ? )";
        if (stmtReadAllBuff == null) {
            stmtReadAllBuff = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadAllBuff.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadAllBuff.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadAllBuff.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadAllBuff.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadAllBuff.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        try {
            resultSet = stmtReadAllBuff.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        List<CFEnSyntaxSecDeviceBuff> buffList = new LinkedList<CFEnSyntaxSecDeviceBuff>();
        while ((resultSet != null) && resultSet.next()) {
            CFEnSyntaxSecDeviceBuff buff = unpackSecDeviceResultSetToBuff(resultSet);
            buffList.add(buff);
        }
        int idx = 0;
        CFEnSyntaxSecDeviceBuff[] retBuff = new CFEnSyntaxSecDeviceBuff[buffList.size()];
        Iterator<CFEnSyntaxSecDeviceBuff> iter = buffList.iterator();
        while (iter.hasNext()) {
            retBuff[idx++] = iter.next();
        }
        return (retBuff);
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
    }
}

From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_4.CFFreeSwitchMySql.CFFreeSwitchMySqlFSSofiaTable.java

public CFFreeSwitchFSSofiaBuff readBuffByIdIdx(CFSecurityAuthorization Authorization, long TenantId,
        long FSSofiaId) {
    final String S_ProcName = "readBuffByIdIdx";
    ResultSet resultSet = null;/*from ww  w .  j a  v a 2 s. c o  m*/
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerDbSchemaName() + ".sp_read_fssofia_by_ididx( ?, ?, ?, ?, ?" + ", "
                + "?" + ", " + "?" + " )";
        if (stmtReadBuffByIdIdx == null) {
            stmtReadBuffByIdIdx = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadBuffByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByIdIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadBuffByIdIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadBuffByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadBuffByIdIdx.setLong(argIdx++, TenantId);
        stmtReadBuffByIdIdx.setLong(argIdx++, FSSofiaId);
        try {
            resultSet = stmtReadBuffByIdIdx.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        if ((resultSet != null) && resultSet.next()) {
            CFFreeSwitchFSSofiaBuff buff = unpackFSSofiaResultSetToBuff(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");
            }
            return (buff);
        } else {
            return (null);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskMySql.CFAsteriskMySqlSecDeviceTable.java

public void createSecDevice(CFSecurityAuthorization Authorization, CFSecuritySecDeviceBuff Buff) {
    final String S_ProcName = "createSecDevice";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }//from   w  w  w .j a  va 2 s .c  om
    ResultSet resultSet = null;
    try {
        UUID SecUserId = Buff.getRequiredSecUserId();
        String DevName = Buff.getRequiredDevName();
        String PubKey = Buff.getOptionalPubKey();
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerDbSchemaName() + ".sp_create_secdev( ?, ?, ?, ?, ?, ?" + ", "
                + "?" + ", " + "?" + ", " + "?" + " )";
        if (stmtCreateByPKey == null) {
            stmtCreateByPKey = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtCreateByPKey.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtCreateByPKey.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtCreateByPKey.setString(argIdx++, "SDEV");
        stmtCreateByPKey.setString(argIdx++, SecUserId.toString());
        stmtCreateByPKey.setString(argIdx++, DevName);
        if (PubKey != null) {
            stmtCreateByPKey.setString(argIdx++, PubKey);
        } else {
            stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
        }
        try {
            resultSet = stmtCreateByPKey.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        if ((resultSet != null) && resultSet.next()) {
            CFSecuritySecDeviceBuff createdBuff = 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.setRequiredSecUserId(createdBuff.getRequiredSecUserId());
            Buff.setRequiredDevName(createdBuff.getRequiredDevName());
            Buff.setOptionalPubKey(createdBuff.getOptionalPubKey());
            Buff.setRequiredRevision(createdBuff.getRequiredRevision());
            Buff.setCreatedByUserId(createdBuff.getCreatedByUserId());
            Buff.setCreatedAt(createdBuff.getCreatedAt());
            Buff.setUpdatedByUserId(createdBuff.getUpdatedByUserId());
            Buff.setUpdatedAt(createdBuff.getUpdatedAt());
        } 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;
        }
    }
}

From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_4.CFFreeSwitchMySql.CFFreeSwitchMySqlFSSofiaTable.java

public CFFreeSwitchFSSofiaBuff[] readAllBuff(CFSecurityAuthorization Authorization) {
    final String S_ProcName = "readAllBuff";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }/*from  ww  w .  j a  v a  2s. com*/
    ResultSet resultSet = null;
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerDbSchemaName() + ".sp_read_fssofia_all( ?, ?, ?, ?, ? )";
        if (stmtReadAllBuff == null) {
            stmtReadAllBuff = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadAllBuff.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadAllBuff.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadAllBuff.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadAllBuff.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadAllBuff.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        try {
            resultSet = stmtReadAllBuff.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        List<CFFreeSwitchFSSofiaBuff> buffList = new LinkedList<CFFreeSwitchFSSofiaBuff>();
        while ((resultSet != null) && resultSet.next()) {
            CFFreeSwitchFSSofiaBuff buff = unpackFSSofiaResultSetToBuff(resultSet);
            buffList.add(buff);
        }
        int idx = 0;
        CFFreeSwitchFSSofiaBuff[] retBuff = new CFFreeSwitchFSSofiaBuff[buffList.size()];
        Iterator<CFFreeSwitchFSSofiaBuff> iter = buffList.iterator();
        while (iter.hasNext()) {
            retBuff[idx++] = iter.next();
        }
        return (retBuff);
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
    }
}

From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_4.CFFreeSwitchMySql.CFFreeSwitchMySqlFSSofiaTable.java

public CFFreeSwitchFSSofiaBuff[] readBuffByTenantIdx(CFSecurityAuthorization Authorization, long TenantId) {
    final String S_ProcName = "readBuffByTenantIdx";
    ResultSet resultSet = null;//from  www .j  av a  2 s .  com
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerDbSchemaName() + ".sp_read_fssofia_by_tenantidx( ?, ?, ?, ?, ?"
                + ", " + "?" + " )";
        if (stmtReadBuffByTenantIdx == null) {
            stmtReadBuffByTenantIdx = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadBuffByTenantIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByTenantIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadBuffByTenantIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadBuffByTenantIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByTenantIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadBuffByTenantIdx.setLong(argIdx++, TenantId);
        try {
            resultSet = stmtReadBuffByTenantIdx.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        List<CFFreeSwitchFSSofiaBuff> buffList = new LinkedList<CFFreeSwitchFSSofiaBuff>();
        while ((resultSet != null) && resultSet.next()) {
            CFFreeSwitchFSSofiaBuff buff = unpackFSSofiaResultSetToBuff(resultSet);
            buffList.add(buff);
        }
        int idx = 0;
        CFFreeSwitchFSSofiaBuff[] retBuff = new CFFreeSwitchFSSofiaBuff[buffList.size()];
        Iterator<CFFreeSwitchFSSofiaBuff> iter = buffList.iterator();
        while (iter.hasNext()) {
            retBuff[idx++] = iter.next();
        }
        return (retBuff);
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
    }
}