Example usage for java.sql Types INTEGER

List of usage examples for java.sql Types INTEGER

Introduction

In this page you can find the example usage for java.sql Types INTEGER.

Prototype

int INTEGER

To view the source code for java.sql Types INTEGER.

Click Source Link

Document

The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type INTEGER.

Usage

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlAttachmentTable.java

public void updateAttachment(CFAccAuthorization Authorization, CFAccAttachmentBuff Buff) {
    final String S_ProcName = "updateAttachment";
    if ("ATTC".equals(Buff.getClassCode())
            && (!schema.isTenantUser(Authorization, Buff.getRequiredTenantId(), "UpdateAttachment"))) {
        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                "Permission denied -- User not part of TSecGroup UpdateAttachment");
    }//from www .  j a  v  a  2  s  .  c  o  m
    try {
        Connection cnx = schema.getCnx();
        long TenantId = Buff.getRequiredTenantId();
        long AttachmentId = Buff.getRequiredAttachmentId();
        long ContactId = Buff.getRequiredContactId();
        String Description = Buff.getRequiredDescription();
        Integer MimeTypeId = Buff.getOptionalMimeTypeId();
        String Attachment = Buff.getRequiredAttachment();
        int Revision = Buff.getRequiredRevision();
        CFAccAttachmentPKey pkey = schema.getFactoryAttachment().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredAttachmentId(Buff.getRequiredAttachmentId());
        CFAccAttachmentBuff readBuff = lockBuff(Authorization, pkey);
        if (readBuff == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), S_ProcName,
                    "Attempted to update record which could not be locked/found",
                    schema.getLowerSchemaDbName() + "..attchmnt", pkey);
        }
        int oldRevision = readBuff.getRequiredRevision();
        if (oldRevision != Revision) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), S_ProcName,
                    Buff);
        }
        int newRevision = Revision + 1;
        String sql = "UPDATE " + schema.getLowerSchemaDbName() + "..Attchmnt " + "SET " + "tenantid = ?" + ", "
                + "attachmentid = ?" + ", " + "contactid = ?" + ", " + "description = ?" + ", "
                + "mimetypeid = ?" + ", " + "attachment = ?" + ", " + "updatedby = ?, "
                + "updatedat = sysdatetime() " + ", revision = ? " + " WHERE " + "tenantid = ? " + "AND "
                + "attachmentid = ? " + "AND " + "revision = ? ";
        if (stmtUpdateByPKey == null) {
            stmtUpdateByPKey = cnx.prepareStatement(sql);
        }
        int argIdx = 1;

        stmtUpdateByPKey.setLong(argIdx++, TenantId);
        stmtUpdateByPKey.setLong(argIdx++, AttachmentId);
        stmtUpdateByPKey.setLong(argIdx++, ContactId);
        stmtUpdateByPKey.setString(argIdx++, Description);
        if (MimeTypeId != null) {
            stmtUpdateByPKey.setInt(argIdx++, MimeTypeId.intValue());
        } else {
            stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        stmtUpdateByPKey.setString(argIdx++, Attachment);
        stmtUpdateByPKey.setString(argIdx++, Authorization.getSecUserId().toString());
        stmtUpdateByPKey.setInt(argIdx++, newRevision);
        stmtUpdateByPKey.setLong(argIdx++, TenantId);
        stmtUpdateByPKey.setLong(argIdx++, AttachmentId);
        stmtUpdateByPKey.setInt(argIdx++, Revision);
        ;
        int rowsAffected = stmtUpdateByPKey.executeUpdate();
        if (rowsAffected != 1) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Expected 1 row to be affected by update, not " + rowsAffected);
        }
        Buff.setRequiredRevision(newRevision);
        String sqlAuditUpdated = "INSERT INTO " + schema.getLowerSchemaDbName()
                + "..Attchmnt_h( auditclusterid, " + " auditsessionid, " + " auditstamp" + ", " + "tenantid"
                + ", " + "attachmentid" + ", " + "contactid" + ", " + "description" + ", " + "mimetypeid" + ", "
                + "attachment" + ", " + " revision, " + " auditaction ) " + "SELECT ?, ?, sysdatetime()" + ", "
                + "attc.tenantid" + ", " + "attc.attachmentid" + ", " + "attc.contactid" + ", "
                + "attc.description" + ", " + "attc.mimetypeid" + ", " + "attc.attachment" + ", "
                + " attc.revision, " + " 2 " + "FROM " + schema.getLowerSchemaDbName() + "..Attchmnt AS attc "
                + " WHERE " + "attc.tenantid = ? " + "AND attc.attachmentid = ? ";
        if (stmtAuditUpdatedByPKey == null) {
            stmtAuditUpdatedByPKey = cnx.prepareStatement(sqlAuditUpdated);
        }
        argIdx = 1;
        stmtAuditUpdatedByPKey.setLong(argIdx++, Authorization.getSecClusterId());
        stmtAuditUpdatedByPKey.setString(argIdx++, Authorization.getSecSessionId().toString());
        stmtAuditUpdatedByPKey.setLong(argIdx++, TenantId);
        stmtAuditUpdatedByPKey.setLong(argIdx++, AttachmentId);
        int rowsAudited = stmtAuditUpdatedByPKey.executeUpdate();
        if (rowsAudited != 1) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Expected 1 row to be affected by audit via insert-selected, not " + rowsAffected);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
}

From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbMySql.CFGenKbMySqlGelReferenceTable.java

public CFGenKbGelReferenceBuff[] readBuffByPrevIdx(CFGenKbAuthorization Authorization, long TenantId,
        long CartridgeId, Integer PrevId) {
    final String S_ProcName = "readBuffByPrevIdx";
    ResultSet resultSet = null;/*w w  w. j  ava2s.c  o m*/
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerSchemaDbName() + ".sp_read_gelrefer_by_previdx( ?, ?, ?, ?, ?"
                + ", " + "?" + ", " + "?" + ", " + "?" + " )";
        if (stmtReadBuffByPrevIdx == null) {
            stmtReadBuffByPrevIdx = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadBuffByPrevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByPrevIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadBuffByPrevIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadBuffByPrevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByPrevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadBuffByPrevIdx.setLong(argIdx++, TenantId);
        stmtReadBuffByPrevIdx.setLong(argIdx++, CartridgeId);
        if (PrevId != null) {
            stmtReadBuffByPrevIdx.setInt(argIdx++, PrevId.intValue());
        } else {
            stmtReadBuffByPrevIdx.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        try {
            resultSet = stmtReadBuffByPrevIdx.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        List<CFGenKbGelReferenceBuff> buffList = new LinkedList<CFGenKbGelReferenceBuff>();
        while ((resultSet != null) && resultSet.next()) {
            CFGenKbGelReferenceBuff buff = unpackGelReferenceResultSetToBuff(resultSet);
            buffList.add(buff);
        }
        int idx = 0;
        CFGenKbGelReferenceBuff[] retBuff = new CFGenKbGelReferenceBuff[buffList.size()];
        Iterator<CFGenKbGelReferenceBuff> 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.cfcore.v2_0.CFGenKbMySql.CFGenKbMySqlGelPrefixLineTable.java

public CFGenKbGelPrefixLineBuff[] readBuffByPrevIdx(CFGenKbAuthorization Authorization, long TenantId,
        long CartridgeId, Integer PrevId) {
    final String S_ProcName = "readBuffByPrevIdx";
    ResultSet resultSet = null;/*  w ww  .  j  av a 2 s  . c om*/
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerSchemaDbName() + ".sp_read_gelprefix_by_previdx( ?, ?, ?, ?, ?"
                + ", " + "?" + ", " + "?" + ", " + "?" + " )";
        if (stmtReadBuffByPrevIdx == null) {
            stmtReadBuffByPrevIdx = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadBuffByPrevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByPrevIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadBuffByPrevIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadBuffByPrevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByPrevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadBuffByPrevIdx.setLong(argIdx++, TenantId);
        stmtReadBuffByPrevIdx.setLong(argIdx++, CartridgeId);
        if (PrevId != null) {
            stmtReadBuffByPrevIdx.setInt(argIdx++, PrevId.intValue());
        } else {
            stmtReadBuffByPrevIdx.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        try {
            resultSet = stmtReadBuffByPrevIdx.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        List<CFGenKbGelPrefixLineBuff> buffList = new LinkedList<CFGenKbGelPrefixLineBuff>();
        while ((resultSet != null) && resultSet.next()) {
            CFGenKbGelPrefixLineBuff buff = unpackGelPrefixLineResultSetToBuff(resultSet);
            buffList.add(buff);
        }
        int idx = 0;
        CFGenKbGelPrefixLineBuff[] retBuff = new CFGenKbGelPrefixLineBuff[buffList.size()];
        Iterator<CFGenKbGelPrefixLineBuff> 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.cfcore.v2_0.CFGenKbMySql.CFGenKbMySqlGelModifierTable.java

public CFGenKbGelModifierBuff[] readBuffByCallerIdx(CFGenKbAuthorization Authorization, long TenantId,
        long CartridgeId, Integer CallerId) {
    final String S_ProcName = "readBuffByCallerIdx";
    ResultSet resultSet = null;//from   w  w w .j av a 2 s .c  o m
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerSchemaDbName()
                + ".sp_read_gelmodifier_by_calleridx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?"
                + " )";
        if (stmtReadBuffByCallerIdx == null) {
            stmtReadBuffByCallerIdx = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadBuffByCallerIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByCallerIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadBuffByCallerIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadBuffByCallerIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByCallerIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadBuffByCallerIdx.setLong(argIdx++, TenantId);
        stmtReadBuffByCallerIdx.setLong(argIdx++, CartridgeId);
        if (CallerId != null) {
            stmtReadBuffByCallerIdx.setInt(argIdx++, CallerId.intValue());
        } else {
            stmtReadBuffByCallerIdx.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        try {
            resultSet = stmtReadBuffByCallerIdx.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        List<CFGenKbGelModifierBuff> buffList = new LinkedList<CFGenKbGelModifierBuff>();
        while ((resultSet != null) && resultSet.next()) {
            CFGenKbGelModifierBuff buff = unpackGelModifierResultSetToBuff(resultSet);
            buffList.add(buff);
        }
        int idx = 0;
        CFGenKbGelModifierBuff[] retBuff = new CFGenKbGelModifierBuff[buffList.size()];
        Iterator<CFGenKbGelModifierBuff> 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:com.wso2telco.core.dbutils.AxiataDbService.java

/**
 * Insert merchant provision.//from w  w w . j av a  2 s. co  m
 *
 * @param appID the app id
 * @param subscriber the subscriber
 * @param operator the operator
 * @param merchants the merchants
 * @return true, if successful
 * @throws Exception the exception
 */
public boolean insertMerchantProvision(Integer appID, String subscriber, String operator, String[] merchants)
        throws Exception {

    Connection con = null;
    Statement st = null;
    ResultSet rs = null;
    PreparedStatement pst = null;

    try {
        con = DbUtils.getAxiataDBConnection();

        st = con.createStatement();
        String sql = "SELECT id " + "FROM operators " + "WHERE operatorname = '" + operator + "'";

        rs = st.executeQuery(sql);

        int operatorid = 0;
        if (rs.next()) {
            operatorid = rs.getInt("id");
        } else {
            throw new Exception("Operator Not Found");
        }

        pst = null;
        for (int i = 0; i < merchants.length; i++) {
            sql = "INSERT INTO merchantopco_blacklist (application_id, operator_id, subscriber, merchant) VALUES "
                    + "(?, ?, ?, ?)";

            pst = con.prepareStatement(sql);
            if (appID == null) {
                pst.setNull(1, Types.INTEGER);
            } else {
                pst.setInt(1, appID);
            }
            pst.setInt(2, operatorid);
            pst.setString(3, subscriber);
            pst.setString(4, merchants[i]);
            pst.executeUpdate();
        }

    } catch (Exception e) {
        DbUtils.handleException("Error while Provisioning Merchant", e);
    } finally {
        DbUtils.closeAllConnections(st, con, rs);
        DbUtils.closeAllConnections(pst, null, null);
    }
    return true;
}

From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbOracle.CFGenKbOracleGelExpansionTable.java

public CFGenKbGelExpansionBuff[] readBuffByPrevIdx(CFGenKbAuthorization Authorization, long TenantId,
        long CartridgeId, Integer PrevId) {
    final String S_ProcName = "readBuffByPrevIdx";
    ResultSet resultSet = null;//from   w w w . jav a 2s  .c o m
    Connection cnx = schema.getCnx();
    CallableStatement stmtReadBuffByPrevIdx = null;
    List<CFGenKbGelExpansionBuff> buffList = new LinkedList<CFGenKbGelExpansionBuff>();
    try {
        stmtReadBuffByPrevIdx = cnx.prepareCall(
                "begin " + schema.getLowerSchemaDbName() + ".rd_gelexpansionbyprevidx( ?, ?, ?, ?, ?, ?" + ", "
                        + "?" + ", " + "?" + ", " + "?" + " ); end;");
        int argIdx = 1;
        stmtReadBuffByPrevIdx.registerOutParameter(argIdx++, OracleTypes.CURSOR);
        stmtReadBuffByPrevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByPrevIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadBuffByPrevIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadBuffByPrevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByPrevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadBuffByPrevIdx.setLong(argIdx++, TenantId);
        stmtReadBuffByPrevIdx.setLong(argIdx++, CartridgeId);
        if (PrevId != null) {
            stmtReadBuffByPrevIdx.setInt(argIdx++, PrevId.intValue());
        } else {
            stmtReadBuffByPrevIdx.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        stmtReadBuffByPrevIdx.execute();
        resultSet = (ResultSet) stmtReadBuffByPrevIdx.getObject(1);
        if (resultSet != null) {
            try {
                while (resultSet.next()) {
                    CFGenKbGelExpansionBuff buff = unpackGelExpansionResultSetToBuff(resultSet);
                    buffList.add(buff);
                }
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            } catch (SQLException e) {
            }
        }
        int idx = 0;
        CFGenKbGelExpansionBuff[] retBuff = new CFGenKbGelExpansionBuff[buffList.size()];
        Iterator<CFGenKbGelExpansionBuff> 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;
        }
        if (stmtReadBuffByPrevIdx != null) {
            try {
                stmtReadBuffByPrevIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByPrevIdx = null;
        }
    }
}

From source file:com.mirth.connect.donkey.test.util.TestUtils.java

private static String typeToString(int sqlType) {
    switch (sqlType) {
    case Types.ARRAY:
        return "ARRAY";
    case Types.BIGINT:
        return "BIGINT";
    case Types.BINARY:
        return "BINARY";
    case Types.BIT:
        return "BIT";
    case Types.BLOB:
        return "BLOB";
    case Types.BOOLEAN:
        return "BOOLEAN";
    case Types.CHAR:
        return "CHAR";
    case Types.CLOB:
        return "CLOB";
    case Types.DATALINK:
        return "DATALINK";
    case Types.DATE:
        return "DATE";
    case Types.DECIMAL:
        return "DECIMAL";
    case Types.DISTINCT:
        return "DISTINCT";
    case Types.DOUBLE:
        return "DOUBLE";
    case Types.FLOAT:
        return "FLOAT";
    case Types.INTEGER:
        return "INTEGER";
    case Types.JAVA_OBJECT:
        return "JAVA_OBJECT";
    case Types.LONGNVARCHAR:
        return "LONGNVARCHAR";
    case Types.LONGVARBINARY:
        return "LONGVARBINARY";
    case Types.LONGVARCHAR:
        return "LONGVARCHAR";
    case Types.NCHAR:
        return "NCHAR";
    case Types.NCLOB:
        return "NCLOB";
    case Types.NULL:
        return "NULL";
    case Types.NUMERIC:
        return "NUMERIC";
    case Types.NVARCHAR:
        return "NVARCHAR";
    case Types.OTHER:
        return "OTHER";
    case Types.REAL:
        return "REAL";
    case Types.REF:
        return "REF";
    case Types.ROWID:
        return "ROWID";
    case Types.SMALLINT:
        return "SMALLINT";
    case Types.SQLXML:
        return "SQLXML";
    case Types.STRUCT:
        return "STRUCT";
    case Types.TIME:
        return "TIME";
    case Types.TIMESTAMP:
        return "TIMESTAMP";
    case Types.TINYINT:
        return "TINYINT";
    case Types.VARBINARY:
        return "VARBINARY";
    case Types.VARCHAR:
        return "VARCHAR";
    default:/*w ww . j  a  va  2 s.c o m*/
        return "UNKNOWN";
    }
}

From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbMySql.CFGenKbMySqlGelPopTable.java

public CFGenKbGelPopBuff[] readBuffByNextIdx(CFGenKbAuthorization Authorization, long TenantId,
        long CartridgeId, Integer NextId) {
    final String S_ProcName = "readBuffByNextIdx";
    ResultSet resultSet = null;/*from w ww .  ja v a 2 s. c  om*/
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerSchemaDbName() + ".sp_read_gelpop_by_nextidx( ?, ?, ?, ?, ?"
                + ", " + "?" + ", " + "?" + ", " + "?" + " )";
        if (stmtReadBuffByNextIdx == null) {
            stmtReadBuffByNextIdx = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadBuffByNextIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByNextIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadBuffByNextIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadBuffByNextIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByNextIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadBuffByNextIdx.setLong(argIdx++, TenantId);
        stmtReadBuffByNextIdx.setLong(argIdx++, CartridgeId);
        if (NextId != null) {
            stmtReadBuffByNextIdx.setInt(argIdx++, NextId.intValue());
        } else {
            stmtReadBuffByNextIdx.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        try {
            resultSet = stmtReadBuffByNextIdx.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        List<CFGenKbGelPopBuff> buffList = new LinkedList<CFGenKbGelPopBuff>();
        while ((resultSet != null) && resultSet.next()) {
            CFGenKbGelPopBuff buff = unpackGelPopResultSetToBuff(resultSet);
            buffList.add(buff);
        }
        int idx = 0;
        CFGenKbGelPopBuff[] retBuff = new CFGenKbGelPopBuff[buffList.size()];
        Iterator<CFGenKbGelPopBuff> 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:fr.aliacom.obm.common.contact.ContactDaoJdbcImpl.java

@Override
@AutoTruncate//from   w w w . java  2s.  c  o  m
public Contact updateContact(AccessToken token, @DatabaseEntity Contact contact)
        throws SQLException, FindException, EventNotFoundException, ServerFault {

    String q = "UPDATE Contact SET " + "contact_commonname=?, contact_firstname=?, "
            + "contact_lastname=?, contact_origin=?, contact_userupdate=?, "
            + "contact_aka=?, contact_title=?, contact_service=?, contact_company=?, contact_comment=?, "
            + "contact_suffix=?, contact_manager=?, contact_middlename=?, contact_assistant=?, contact_spouse=?, contact_anniversary_id=?, contact_birthday_id=? "
            + "WHERE contact_id=? ";
    logger.info("update contact with id=" + contact.getUid() + " entityId=" + contact.getEntityId());

    Connection con = null;
    PreparedStatement ps = null;
    try {
        con = obmHelper.getConnection();

        EventObmId anniversaryId = createOrUpdateDate(token, con, contact, contact.getAnniversary(),
                ANNIVERSARY_FIELD);
        contact.setAnniversaryId(anniversaryId);

        EventObmId birthdayId = createOrUpdateDate(token, con, contact, contact.getBirthday(), BIRTHDAY_FIELD);
        contact.setBirthdayId(birthdayId);

        ps = con.prepareStatement(q);

        int idx = 1;
        ps.setString(idx++, contact.getCommonname());
        ps.setString(idx++, contact.getFirstname());
        ps.setString(idx++, contact.getLastname());
        ps.setString(idx++, token.getOrigin());
        ps.setInt(idx++, token.getObmId());

        ps.setString(idx++, contact.getAka());
        ps.setString(idx++, contact.getTitle());
        ps.setString(idx++, contact.getService());
        ps.setString(idx++, contact.getCompany());
        ps.setString(idx++, contact.getComment());

        ps.setString(idx++, contact.getSuffix());
        ps.setString(idx++, contact.getManager());
        ps.setString(idx++, contact.getMiddlename());
        ps.setString(idx++, contact.getAssistant());
        ps.setString(idx++, contact.getSpouse());
        if (contact.getAnniversaryId() == null) {
            ps.setNull(idx++, Types.INTEGER);
        } else {
            ps.setInt(idx++, contact.getAnniversaryId().getObmId());
        }
        if (contact.getBirthdayId() == null) {
            ps.setNull(idx++, Types.INTEGER);
        } else {
            ps.setInt(idx++, contact.getBirthdayId().getObmId());
        }

        ps.setInt(idx++, contact.getUid());
        ps.executeUpdate();

        removeAndCreateAddresses(con, contact.getEntityId(), contact.getAddresses());
        removeAndCreateEmails(con, contact.getEntityId(), contact.getEmails());
        removeAndCreatePhones(con, contact.getEntityId(), contact.getPhones());
        removeAndCreateWebsites(con, contact);
        removeAndCreateIMIdentifiers(con, contact.getEntityId(), contact.getImIdentifiers());
    } finally {
        obmHelper.cleanup(con, ps, null);
    }

    indexContact(token, contact);

    return contact;
}

From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbMySql.CFGenKbMySqlGelReferenceTable.java

public CFGenKbGelReferenceBuff[] readBuffByNextIdx(CFGenKbAuthorization Authorization, long TenantId,
        long CartridgeId, Integer NextId) {
    final String S_ProcName = "readBuffByNextIdx";
    ResultSet resultSet = null;//from   ww  w . j  ava2s.  c o m
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerSchemaDbName() + ".sp_read_gelrefer_by_nextidx( ?, ?, ?, ?, ?"
                + ", " + "?" + ", " + "?" + ", " + "?" + " )";
        if (stmtReadBuffByNextIdx == null) {
            stmtReadBuffByNextIdx = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadBuffByNextIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByNextIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadBuffByNextIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadBuffByNextIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByNextIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadBuffByNextIdx.setLong(argIdx++, TenantId);
        stmtReadBuffByNextIdx.setLong(argIdx++, CartridgeId);
        if (NextId != null) {
            stmtReadBuffByNextIdx.setInt(argIdx++, NextId.intValue());
        } else {
            stmtReadBuffByNextIdx.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        try {
            resultSet = stmtReadBuffByNextIdx.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        List<CFGenKbGelReferenceBuff> buffList = new LinkedList<CFGenKbGelReferenceBuff>();
        while ((resultSet != null) && resultSet.next()) {
            CFGenKbGelReferenceBuff buff = unpackGelReferenceResultSetToBuff(resultSet);
            buffList.add(buff);
        }
        int idx = 0;
        CFGenKbGelReferenceBuff[] retBuff = new CFGenKbGelReferenceBuff[buffList.size()];
        Iterator<CFGenKbGelReferenceBuff> 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;
        }
    }
}