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:com.streamsets.pipeline.lib.jdbc.multithread.TestMultithreadedTableProvider.java

@NotNull
private static TableContext createTableContext(String schema, String tableName, String offsetColumn,
        String partitionSize, String minOffsetColValue, int maxActivePartitions, boolean enablePartitioning,
        boolean enableNonIncremental, long offset) {
    LinkedHashMap<String, Integer> offsetColumnToType = new LinkedHashMap<>();
    Map<String, String> offsetColumnToStartOffset = new HashMap<>();
    Map<String, String> offsetColumnToPartitionSizes = new HashMap<>();
    Map<String, String> offsetColumnToMinValues = new HashMap<>();

    if (offsetColumn != null) {
        offsetColumnToType.put(offsetColumn, Types.INTEGER);
        if (minOffsetColValue != null) {
            offsetColumnToMinValues.put(offsetColumn, minOffsetColValue);
        }/*from  ww w  .ja  v a2 s .  c  o m*/
        offsetColumnToPartitionSizes.put(offsetColumn, partitionSize);
    }
    String extraOffsetColumnConditions = null;

    return new TableContext(schema, tableName, offsetColumnToType, offsetColumnToStartOffset,
            offsetColumnToPartitionSizes, offsetColumnToMinValues, enableNonIncremental,
            enablePartitioning ? PartitioningMode.BEST_EFFORT : PartitioningMode.DISABLED, maxActivePartitions,
            extraOffsetColumnConditions, offset);
}

From source file:com.enonic.vertical.engine.handlers.MenuHandler.java

private int createMenuItem(User user, CopyContext copyContext, Element menuItemElement, SiteKey siteKey,
        int order, MenuItemKey parentKey, boolean useOldKey)
        throws VerticalCreateException, VerticalSecurityException {

    // security check:
    if (!getSecurityHandler().validateMenuItemCreate(user, siteKey.toInt(),
            parentKey == null ? -1 : parentKey.toInt())) {
        VerticalEngineLogger.errorSecurity(this.getClass(), 10,
                "Not allowed to create menuitem in this position.", null);
    }/*  w w w.j  a v a  2 s.  c  om*/

    String menuItemName = XMLTool
            .getElementText(XMLTool.getElement(menuItemElement, ELEMENT_NAME_MENUITEM_NAME));

    if (StringUtils.isEmpty(menuItemName)) {
        menuItemName = generateMenuItemName(menuItemElement);
    }

    menuItemName = ensureUniqueMenuItemName(siteKey, parentKey, menuItemName, null);

    // check whether name is unique for this parent
    if (menuItemNameExists(siteKey, parentKey, menuItemName, null)) {
        VerticalEngineLogger.errorCreate(this.getClass(), 20, "Menu item name already exists on this level: %0",
                new Object[] { menuItemName }, null);
    }

    Element tmp_element;
    Hashtable<String, Integer> menuItemTypes = getMenuItemTypesAsHashtable();

    // Get menuitem type:
    String miType = menuItemElement.getAttribute("type");
    Integer type = menuItemTypes.get(miType);
    if (type == null) {
        VerticalEngineLogger.errorCreate(this.getClass(), 20, "Invalid menu item type %0.",
                new Object[] { type }, null);
    }

    Connection con = null;
    PreparedStatement preparedStmt = null;
    MenuItemKey menuItemKey = null;

    try {
        con = getConnection();

        // key
        String keyStr = menuItemElement.getAttribute("key");
        if (!useOldKey || keyStr == null || keyStr.length() == 0) {
            try {
                menuItemKey = new MenuItemKey(getNextKey(MENU_ITEM_TABLE));
            } catch (VerticalKeyException e) {
                VerticalEngineLogger.errorCreate(this.getClass(), 30, "Error generating key for tMenuItem.", e);
            }
        } else {
            menuItemKey = new MenuItemKey(keyStr);
        }
        if (copyContext != null) {
            copyContext.putMenuItemKey(Integer.parseInt(keyStr), menuItemKey.toInt());
        }

        String tmp;

        preparedStmt = con.prepareStatement(MENU_ITEM_INSERT);

        preparedStmt.setInt(1, menuItemKey.toInt());

        // element: name
        validateMenuItemName(menuItemName);
        preparedStmt.setString(2, menuItemName);

        // menu key:
        preparedStmt.setInt(3, siteKey.toInt());

        // attribute: menu item type
        preparedStmt.setInt(4, type);

        // parent
        if (parentKey == null) {
            preparedStmt.setNull(5, Types.INTEGER);
        } else {
            preparedStmt.setInt(5, parentKey.toInt());
        }

        // order:
        preparedStmt.setInt(6, order);

        // pre-fetch data element
        Element dataElem = XMLTool.getElement(menuItemElement, "data");

        // element: parameters
        tmp_element = XMLTool.getElement(menuItemElement, "parameters");
        if (tmp_element != null) {
            dataElem.appendChild(tmp_element);
        }

        // alternative name:
        tmp_element = XMLTool.getElement(menuItemElement, ELEMENT_NAME_MENU_NAME);
        if (tmp_element != null) {
            tmp = XMLTool.getElementText(tmp_element);
            preparedStmt.setString(7, tmp);
        } else {
            preparedStmt.setNull(7, Types.VARCHAR);
        }

        // visibility:
        tmp = menuItemElement.getAttribute("visible");
        if ("no".equals(tmp)) {
            preparedStmt.setInt(8, 1);
        } else {
            preparedStmt.setInt(8, 0);
        }

        // description:
        tmp_element = XMLTool.getElement(menuItemElement, "description");
        String data = XMLTool.getElementText(tmp_element);
        if (data != null) {
            StringReader reader = new StringReader(data);
            preparedStmt.setCharacterStream(9, reader, data.length());
        } else {
            preparedStmt.setNull(9, Types.VARCHAR);
        }

        if (type == 4) {
            Element docElem = XMLTool.getElement(menuItemElement, "document");

            if (docElem != null) {
                dataElem.appendChild(docElem);
            }
        }

        // attribute: owner/modifier
        String ownerKey = menuItemElement.getAttribute("owner");
        preparedStmt.setString(10, ownerKey);
        preparedStmt.setString(11, ownerKey);

        // data
        if (dataElem != null) {
            Document dataDoc = XMLTool.createDocument();
            dataDoc.appendChild(dataDoc.importNode(dataElem, true));

            byte[] bytes = XMLTool.documentToBytes(dataDoc, "UTF-8");
            preparedStmt.setBinaryStream(12, new ByteArrayInputStream(bytes), bytes.length);
        } else {
            preparedStmt.setNull(12, Types.BLOB);
        }

        // keywords
        tmp_element = XMLTool.getElement(menuItemElement, "keywords");
        String keywords = XMLTool.getElementText(tmp_element);
        if (keywords == null || keywords.length() == 0) {
            preparedStmt.setNull(13, Types.VARCHAR);
        } else {
            StringReader keywordReader = new StringReader(keywords);
            preparedStmt.setCharacterStream(13, keywordReader, keywords.length());
        }

        // language
        String lanKey = menuItemElement.getAttribute("languagekey");
        if ((lanKey != null) && (lanKey.length() > 0)) {
            preparedStmt.setInt(14, Integer.parseInt(lanKey));
        } else {
            preparedStmt.setNull(14, Types.INTEGER);
        }

        RunAsType runAs = RunAsType.INHERIT;
        String runAsStr = menuItemElement.getAttribute("runAs");
        if (StringUtils.isNotEmpty(runAsStr)) {
            runAs = RunAsType.valueOf(runAsStr);
        }
        preparedStmt.setInt(15, runAs.getKey());

        // Display-name
        String displayName = getElementValue(menuItemElement, ELEMENT_NAME_DISPLAY_NAME);
        preparedStmt.setString(16, displayName);

        // execute statement:
        preparedStmt.executeUpdate();

        // Create type specific data.
        switch (type) {
        case 1:
            // page
            createPage(con, menuItemElement, type, menuItemKey);
            break;

        case 2:
            // URL
            createOrUpdateURL(con, menuItemElement, menuItemKey);
            break;

        case 4:
            // document: nothing
            // page
            Element pageElem = XMLTool.getElement(menuItemElement, "page");
            PageTemplateKey pageTemplateKey = new PageTemplateKey(pageElem.getAttribute("pagetemplatekey"));
            PageTemplateType pageTemplateType = getPageTemplateHandler().getPageTemplateType(pageTemplateKey);
            if (pageTemplateType == PageTemplateType.SECTIONPAGE
                    || pageTemplateType == PageTemplateType.NEWSLETTER) {
                createSection(menuItemElement, menuItemKey);
            }
            createPage(con, menuItemElement, type, menuItemKey);
            break;

        case 5:
            // label
            break;

        case 6:
            // section
            createSection(menuItemElement, menuItemKey);
            break;

        case 7:
            // shortcut
            createOrOverrideShortcut(menuItemElement, menuItemKey);
            break;

        default:
            VerticalEngineLogger.errorCreate(this.getClass(), 70, "Unknown menuitem type: %0",
                    new Object[] { type }, null);
        }

        // set contentkey if present
        String contentKeyStr = menuItemElement.getAttribute("contentkey");
        if (contentKeyStr.length() == 0) {
            contentKeyStr = "-1";
        }
        setMenuItemContentKey(menuItemKey, Integer.parseInt(contentKeyStr));

        // fire event
        if (multicaster.hasListeners() && copyContext == null) {
            MenuHandlerEvent e = new MenuHandlerEvent(user, siteKey.toInt(), menuItemKey.toInt(), menuItemName,
                    this);
            multicaster.createdMenuItem(e);
        }

        UserSpecification userSpecification = new UserSpecification();
        userSpecification.setDeletedState(UserSpecification.DeletedState.ANY);
        userSpecification.setKey(new UserKey(ownerKey));
        UserEntity owner = userDao.findSingleBySpecification(userSpecification);
        String ownerGroupKey = null;
        if (owner.getUserGroup() != null) {
            ownerGroupKey = owner.getUserGroup().getGroupKey().toString();
        }

        getSecurityHandler().inheritMenuItemAccessRights(siteKey.toInt(),
                parentKey == null ? -1 : parentKey.toInt(), menuItemKey.toInt(), ownerGroupKey);

        // Create other
        Element menuItemsElement = XMLTool.getElement(menuItemElement, "menuitems");
        if (menuItemsElement != null) {
            Element[] elems = XMLTool.getElements(menuItemsElement);
            for (int i = 0; i < elems.length; i++) {
                createMenuItem(user, copyContext, elems[i], siteKey, i, menuItemKey, useOldKey);
            }
        }
    } catch (SQLException e) {
        VerticalEngineLogger.errorCreate(this.getClass(), 40, "A database error occurred: %t", e);
    } finally {
        close(preparedStmt);
        close(con);
    }

    return menuItemKey.toInt();
}

From source file:com.jabyftw.lobstercraft.player.PlayerHandlerService.java

/**
 * This should run on server close, so we don't need to synchronize as every player join is denied before.
 *
 * @param connection MySQL connection//from w  w  w . ja v  a 2 s .  co  m
 * @throws SQLException in case of something going wrong
 */
private void saveChangedPlayers(@NotNull Connection connection) throws SQLException {
    long start = System.nanoTime();
    int numberOfPlayersUpdated = 0;

    // Prepare statement
    PreparedStatement preparedStatement = connection.prepareStatement(
            "UPDATE `minecraft`.`user_profiles` SET `playerName` = ?, `password` = ?, `moneyAmount` = ?, `city_cityId` = ?,"
                    + " `cityOccupation` = ?, `lastTimeOnline` = ?, `timePlayed` = ?, `lastIp` = ? WHERE `playerId` = ?;");

    // Iterate through all players
    for (OfflinePlayer offlinePlayer : registeredOfflinePlayers_id.values())
        // Filter the ones needing updates => REGISTERED PLAYERS: they have money amount, passwords, last time online, last IP
        if (offlinePlayer.getDatabaseState() == DatabaseState.UPDATE_DATABASE) {
            preparedStatement.setString(1, offlinePlayer.getPlayerName());
            preparedStatement.setString(2, offlinePlayer.getEncryptedPassword());
            preparedStatement.setDouble(3, offlinePlayer.getMoneyAmount());
            preparedStatement.setObject(4, offlinePlayer.getCityId(), Types.INTEGER); // Will write null if is null
            preparedStatement.setObject(5,
                    offlinePlayer.getCityOccupation() != null
                            ? offlinePlayer.getCityOccupation().getOccupationId()
                            : null,
                    Types.TINYINT);
            preparedStatement.setLong(6, offlinePlayer.getLastTimeOnline());
            preparedStatement.setLong(7, offlinePlayer.getTimePlayed());
            preparedStatement.setString(8, offlinePlayer.getLastIp());
            preparedStatement.setLong(9, offlinePlayer.getPlayerId());

            // Add batch
            preparedStatement.addBatch();

            // Update their database state
            offlinePlayer.databaseState = DatabaseState.ON_DATABASE;
            numberOfPlayersUpdated++;
        }

    // Execute and announce
    if (numberOfPlayersUpdated > 0) {
        preparedStatement.executeBatch();
        LobsterCraft.logger.info(Util.appendStrings("Took us ",
                Util.formatDecimal(
                        (double) (System.nanoTime() - start) / (double) TimeUnit.MILLISECONDS.toNanos(1)),
                "ms to update ", numberOfPlayersUpdated, " players."));
    }

    // Close statement
    preparedStatement.close();
}

From source file:com.zimbra.cs.db.DbMailItem.java

public static void setParent(MailItem[] children, MailItem parent) throws ServiceException {
    if (children == null || children.length == 0) {
        return;/*from   w w  w . j  a v a 2s.c o m*/
    }
    Mailbox mbox = children[0].getMailbox();
    if (parent != null && mbox != parent.getMailbox()) {
        throw MailServiceException.WRONG_MAILBOX();
    }
    DbConnection conn = mbox.getOperationConnection();
    PreparedStatement stmt = null;
    try {
        for (int i = 0; i < children.length; i += Db.getINClauseBatchSize()) {
            int count = Math.min(Db.getINClauseBatchSize(), children.length - i);
            stmt = conn.prepareStatement("UPDATE " + getMailItemTableName(mbox)
                    + " SET parent_id = ?, mod_metadata = ?, change_date = ?" + " WHERE " + IN_THIS_MAILBOX_AND
                    + DbUtil.whereIn("id", count));
            int pos = 1;
            if (parent == null || parent instanceof VirtualConversation) {
                stmt.setNull(pos++, Types.INTEGER);
            } else {
                stmt.setInt(pos++, parent.getId());
            }
            stmt.setInt(pos++, mbox.getOperationChangeID());
            stmt.setInt(pos++, mbox.getOperationTimestamp());
            pos = setMailboxId(stmt, mbox, pos);
            for (int index = i; index < i + count; index++) {
                stmt.setInt(pos++, children[index].getId());
            }
            stmt.executeUpdate();
            stmt.close();
            stmt = null;
        }
    } catch (SQLException e) {
        throw ServiceException
                .FAILURE("adding children to parent " + (parent == null ? "NULL" : parent.getId() + ""), e);
    } finally {
        DbPool.closeStatement(stmt);
    }
}

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

public CFGenKbGelIteratorBuff[] readBuffByPrevIdx(CFGenKbAuthorization Authorization, long TenantId,
        long CartridgeId, Integer PrevId) {
    final String S_ProcName = "readBuffByPrevIdx";
    ResultSet resultSet = null;//w w  w . j a  va2s .  c  o m
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerSchemaDbName() + ".sp_read_geliter_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<CFGenKbGelIteratorBuff> buffList = new LinkedList<CFGenKbGelIteratorBuff>();
        while ((resultSet != null) && resultSet.next()) {
            CFGenKbGelIteratorBuff buff = unpackGelIteratorResultSetToBuff(resultSet);
            buffList.add(buff);
        }
        int idx = 0;
        CFGenKbGelIteratorBuff[] retBuff = new CFGenKbGelIteratorBuff[buffList.size()];
        Iterator<CFGenKbGelIteratorBuff> 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.zimbra.cs.db.DbMailItem.java

public static void reparentChildren(MailItem oldParent, MailItem newParent) throws ServiceException {
    if (oldParent == newParent) {
        return;//w  w  w  .j  a  v a2s. c o m
    }
    Mailbox mbox = oldParent.getMailbox();
    if (mbox != newParent.getMailbox()) {
        throw MailServiceException.WRONG_MAILBOX();
    }
    DbConnection conn = mbox.getOperationConnection();
    PreparedStatement stmt = null;
    try {
        String relation = (oldParent instanceof VirtualConversation ? "id = ?" : "parent_id = ?");

        stmt = conn.prepareStatement("UPDATE " + getMailItemTableName(oldParent)
                + " SET parent_id = ?, mod_metadata = ?, change_date = ?" + " WHERE " + IN_THIS_MAILBOX_AND
                + relation);
        int pos = 1;
        if (newParent instanceof VirtualConversation) {
            stmt.setNull(pos++, Types.INTEGER);
        } else {
            stmt.setInt(pos++, newParent.getId());
        }
        stmt.setInt(pos++, mbox.getOperationChangeID());
        stmt.setInt(pos++, mbox.getOperationTimestamp());
        pos = setMailboxId(stmt, mbox, pos);
        stmt.setInt(pos++,
                oldParent instanceof VirtualConversation ? ((VirtualConversation) oldParent).getMessageId()
                        : oldParent.getId());
        stmt.executeUpdate();
    } catch (SQLException e) {
        throw ServiceException.FAILURE("writing new parent for children of item " + oldParent.getId(), e);
    } finally {
        DbPool.closeStatement(stmt);
    }
}

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

public void updateGelPop(CFGenKbAuthorization Authorization, CFGenKbGelPopBuff Buff) {
    final String S_ProcName = "updateGelPop";
    ResultSet resultSet = null;//from  w ww  . j  a  v a 2s . c om
    try {
        String ClassCode = Buff.getClassCode();
        long TenantId = Buff.getRequiredTenantId();
        long CartridgeId = Buff.getRequiredCartridgeId();
        int GelInstId = Buff.getRequiredGelInstId();
        Integer CallerId = Buff.getOptionalCallerId();
        Integer PrevId = Buff.getOptionalPrevId();
        Integer NextId = Buff.getOptionalNextId();
        String SourceText = Buff.getRequiredSourceText();
        String GoalTypeName = Buff.getRequiredGoalTypeName();
        Integer RemainderInstId = Buff.getOptionalRemainderInstId();
        int Revision = Buff.getRequiredRevision();
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerSchemaDbName() + ".sp_update_gelpop( ?, ?, ?, ?, ?, ?" + ", "
                + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"
                + ", " + "?" + ", " + "?" + " )";
        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++, ClassCode);
        stmtUpdateByPKey.setLong(argIdx++, TenantId);
        stmtUpdateByPKey.setLong(argIdx++, CartridgeId);
        stmtUpdateByPKey.setInt(argIdx++, GelInstId);
        if (CallerId != null) {
            stmtUpdateByPKey.setInt(argIdx++, CallerId.intValue());
        } else {
            stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        if (PrevId != null) {
            stmtUpdateByPKey.setInt(argIdx++, PrevId.intValue());
        } else {
            stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        if (NextId != null) {
            stmtUpdateByPKey.setInt(argIdx++, NextId.intValue());
        } else {
            stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        stmtUpdateByPKey.setString(argIdx++, SourceText);
        stmtUpdateByPKey.setString(argIdx++, GoalTypeName);
        if (RemainderInstId != null) {
            stmtUpdateByPKey.setInt(argIdx++, RemainderInstId.intValue());
        } else {
            stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        stmtUpdateByPKey.setInt(argIdx++, Revision);
        try {
            resultSet = stmtUpdateByPKey.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        if ((resultSet != null) && resultSet.next()) {
            CFGenKbGelPopBuff updatedBuff = unpackGelPopResultSetToBuff(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.setOptionalCallerId(updatedBuff.getOptionalCallerId());
            Buff.setOptionalPrevId(updatedBuff.getOptionalPrevId());
            Buff.setOptionalNextId(updatedBuff.getOptionalNextId());
            Buff.setRequiredSourceText(updatedBuff.getRequiredSourceText());
            Buff.setRequiredGoalTypeName(updatedBuff.getRequiredGoalTypeName());
            Buff.setOptionalRemainderInstId(updatedBuff.getOptionalRemainderInstId());
            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;
        }
    }
}

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

public CFGenKbGelModifierBuff[] readBuffByFirstInstIdx(CFGenKbAuthorization Authorization, long TenantId,
        long CartridgeId, Integer FirstInstId) {
    final String S_ProcName = "readBuffByFirstInstIdx";
    ResultSet resultSet = null;//from   w w  w. j  a v  a  2  s. c  o  m
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerSchemaDbName()
                + ".sp_read_gelmodifier_by_firstinstidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?"
                + " )";
        if (stmtReadBuffByFirstInstIdx == null) {
            stmtReadBuffByFirstInstIdx = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadBuffByFirstInstIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByFirstInstIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadBuffByFirstInstIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadBuffByFirstInstIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByFirstInstIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtReadBuffByFirstInstIdx.setLong(argIdx++, TenantId);
        stmtReadBuffByFirstInstIdx.setLong(argIdx++, CartridgeId);
        if (FirstInstId != null) {
            stmtReadBuffByFirstInstIdx.setInt(argIdx++, FirstInstId.intValue());
        } else {
            stmtReadBuffByFirstInstIdx.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        try {
            resultSet = stmtReadBuffByFirstInstIdx.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:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbOracle.CFGenKbOracleGelExpansionTable.java

public void updateGelExpansion(CFGenKbAuthorization Authorization, CFGenKbGelExpansionBuff Buff) {
    final String S_ProcName = "updateGelExpansion";
    ResultSet resultSet = null;/*w  ww .  j av a2s . co  m*/
    Connection cnx = schema.getCnx();
    CallableStatement stmtUpdateByPKey = null;
    List<CFGenKbGelExpansionBuff> buffList = new LinkedList<CFGenKbGelExpansionBuff>();
    try {
        String ClassCode = Buff.getClassCode();
        long TenantId = Buff.getRequiredTenantId();
        long CartridgeId = Buff.getRequiredCartridgeId();
        int GelInstId = Buff.getRequiredGelInstId();
        Integer CallerId = Buff.getOptionalCallerId();
        Integer PrevId = Buff.getOptionalPrevId();
        Integer NextId = Buff.getOptionalNextId();
        String SourceText = Buff.getRequiredSourceText();
        String MacroName = Buff.getRequiredMacroName();
        int Revision = Buff.getRequiredRevision();
        stmtUpdateByPKey = cnx.prepareCall("begin " + schema.getLowerSchemaDbName()
                + ".upd_gelexpansion( ?, ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"
                + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "? ); end;");
        int argIdx = 1;
        stmtUpdateByPKey.registerOutParameter(argIdx++, OracleTypes.CURSOR);
        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++, ClassCode);
        stmtUpdateByPKey.setLong(argIdx++, TenantId);
        stmtUpdateByPKey.setLong(argIdx++, CartridgeId);
        stmtUpdateByPKey.setInt(argIdx++, GelInstId);
        if (CallerId != null) {
            stmtUpdateByPKey.setInt(argIdx++, CallerId.intValue());
        } else {
            stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        if (PrevId != null) {
            stmtUpdateByPKey.setInt(argIdx++, PrevId.intValue());
        } else {
            stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        if (NextId != null) {
            stmtUpdateByPKey.setInt(argIdx++, NextId.intValue());
        } else {
            stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        stmtUpdateByPKey.setString(argIdx++, SourceText);
        stmtUpdateByPKey.setString(argIdx++, MacroName);
        stmtUpdateByPKey.setInt(argIdx++, Revision);
        stmtUpdateByPKey.execute();
        resultSet = (ResultSet) stmtUpdateByPKey.getObject(1);
        if (resultSet != null) {
            try {
                if (resultSet.next()) {
                    CFGenKbGelExpansionBuff updatedBuff = unpackGelExpansionResultSetToBuff(resultSet);
                    if (resultSet.next()) {
                        resultSet.last();
                        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                                "Did not expect multi-record response, " + resultSet.getRow()
                                        + " rows selected");
                    }
                    Buff.setOptionalCallerId(updatedBuff.getOptionalCallerId());
                    Buff.setOptionalPrevId(updatedBuff.getOptionalPrevId());
                    Buff.setOptionalNextId(updatedBuff.getOptionalNextId());
                    Buff.setRequiredSourceText(updatedBuff.getRequiredSourceText());
                    Buff.setRequiredMacroName(updatedBuff.getRequiredMacroName());
                    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().newRuntimeException(getClass(), S_ProcName,
                        "upd_gelexpansion() did not return a valid result cursor");
            } finally {
                if (resultSet != null) {
                    try {
                        resultSet.close();
                    } catch (SQLException e) {
                    }
                    resultSet = null;
                }
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "upd_gelexpansion() did not return a result cursor");
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
        if (stmtUpdateByPKey != null) {
            try {
                stmtUpdateByPKey.close();
            } catch (SQLException e) {
            }
            stmtUpdateByPKey = null;
        }
    }
}

From source file:com.alibaba.wasp.jdbc.TestJdbcResultSet.java

public void testDatetimeWithCalendar() throws SQLException {
    trace("test DATETIME with Calendar");
    ResultSet rs;//  w w  w  .  jav a2s . com

    stat = conn.createStatement();
    stat.execute("CREATE TABLE test(ID INT PRIMARY KEY, D DATE, T TIME, TS TIMESTAMP)");
    PreparedStatement prep = conn.prepareStatement("INSERT INTO test VALUES(?, ?, ?, ?)");
    Calendar regular = Calendar.getInstance();
    Calendar other = null;
    // search a locale that has a _different_ raw offset
    long testTime = java.sql.Date.valueOf("2001-02-03").getTime();
    for (String s : TimeZone.getAvailableIDs()) {
        TimeZone zone = TimeZone.getTimeZone(s);
        long rawOffsetDiff = regular.getTimeZone().getRawOffset() - zone.getRawOffset();
        // must not be the same timezone (not 0 h and not 24 h difference
        // as for Pacific/Auckland and Etc/GMT+12)
        if (rawOffsetDiff != 0 && rawOffsetDiff != 1000 * 60 * 60 * 24) {
            if (regular.getTimeZone().getOffset(testTime) != zone.getOffset(testTime)) {
                other = Calendar.getInstance(zone);
                break;
            }
        }
    }

    trace("regular offset = " + regular.getTimeZone().getRawOffset() + " other = "
            + other.getTimeZone().getRawOffset());

    prep.setInt(1, 0);
    prep.setDate(2, null, regular);
    prep.setTime(3, null, regular);
    prep.setTimestamp(4, null, regular);
    prep.execute();

    prep.setInt(1, 1);
    prep.setDate(2, null, other);
    prep.setTime(3, null, other);
    prep.setTimestamp(4, null, other);
    prep.execute();

    prep.setInt(1, 2);
    prep.setDate(2, java.sql.Date.valueOf("2001-02-03"), regular);
    prep.setTime(3, java.sql.Time.valueOf("04:05:06"), regular);
    prep.setTimestamp(4, Timestamp.valueOf("2007-08-09 10:11:12.131415"), regular);
    prep.execute();

    prep.setInt(1, 3);
    prep.setDate(2, java.sql.Date.valueOf("2101-02-03"), other);
    prep.setTime(3, java.sql.Time.valueOf("14:05:06"), other);
    prep.setTimestamp(4, Timestamp.valueOf("2107-08-09 10:11:12.131415"), other);
    prep.execute();

    prep.setInt(1, 4);
    prep.setDate(2, java.sql.Date.valueOf("2101-02-03"));
    prep.setTime(3, java.sql.Time.valueOf("14:05:06"));
    prep.setTimestamp(4, Timestamp.valueOf("2107-08-09 10:11:12.131415"));
    prep.execute();

    rs = stat.executeQuery("SELECT * FROM test ORDER BY ID");
    assertResultSetMeta(rs, 4, new String[] { "ID", "D", "T", "TS" },
            new int[] { Types.INTEGER, Types.DATE, Types.TIME, Types.TIMESTAMP }, new int[] { 10, 8, 6, 23 },
            new int[] { 0, 0, 0, 10 });

    rs.next();
    assertEquals(0, rs.getInt(1));
    assertTrue(rs.getDate(2, regular) == null && rs.wasNull());
    assertTrue(rs.getTime(3, regular) == null && rs.wasNull());
    assertTrue(rs.getTimestamp(3, regular) == null && rs.wasNull());

    rs.next();
    assertEquals(1, rs.getInt(1));
    assertTrue(rs.getDate(2, other) == null && rs.wasNull());
    assertTrue(rs.getTime(3, other) == null && rs.wasNull());
    assertTrue(rs.getTimestamp(3, other) == null && rs.wasNull());

    rs.next();
    assertEquals(2, rs.getInt(1));
    assertEquals("2001-02-03", rs.getDate(2, regular).toString());
    assertEquals("04:05:06", rs.getTime(3, regular).toString());
    assertFalse(rs.getTime(3, other).toString().equals("04:05:06"));
    assertEquals("2007-08-09 10:11:12.131415", rs.getTimestamp(4, regular).toString());
    assertFalse(rs.getTimestamp(4, other).toString().equals("2007-08-09 10:11:12.131415"));

    rs.next();
    assertEquals(3, rs.getInt("ID"));
    assertFalse(rs.getTimestamp("TS", regular).toString().equals("2107-08-09 10:11:12.131415"));
    assertEquals("2107-08-09 10:11:12.131415", rs.getTimestamp("TS", other).toString());
    assertFalse(rs.getTime("T", regular).toString().equals("14:05:06"));
    assertEquals("14:05:06", rs.getTime("T", other).toString());
    // checkFalse(rs.getDate(2, regular).toString(), "2101-02-03");
    // check(rs.getDate("D", other).toString(), "2101-02-03");

    rs.next();
    assertEquals(4, rs.getInt("ID"));
    assertEquals("2107-08-09 10:11:12.131415", rs.getTimestamp("TS").toString());
    assertEquals("14:05:06", rs.getTime("T").toString());
    assertEquals("2101-02-03", rs.getDate("D").toString());

    assertFalse(rs.next());
    stat.execute("DROP TABLE test");
}