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.concursive.connect.web.modules.documents.dao.FileItem.java

/**
 * Description of the Method/*from   ww w.j  a  va 2  s .  c  o m*/
 *
 * @param db Description of Parameter
 * @return Description of the Returned Value
 * @throws SQLException Description of Exception
 */
public boolean insert(Connection db) throws SQLException {
    if (!isValid()) {
        LOG.debug("Object validation failed");
        return false;
    }

    boolean result = false;
    boolean doCommit = false;
    try {
        if (doCommit = db.getAutoCommit()) {
            db.setAutoCommit(false);
        }
        StringBuffer sql = new StringBuffer();
        sql.append("INSERT INTO project_files "
                + "(folder_id, subject, client_filename, filename, version, size, ");
        sql.append("enabled, downloads, ");
        if (entered != null) {
            sql.append("entered, ");
        }
        if (modified != null) {
            sql.append("modified, ");
        }
        sql.append(" link_module_id, link_item_id, "
                + " enteredby, modifiedby, default_file, image_width, image_height, comment, featured_file) "
                + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ");
        if (entered != null) {
            sql.append("?, ");
        }
        if (modified != null) {
            sql.append("?, ");
        }
        sql.append("?, ?, ?, ?, ?, ?, ?, ?, ?) ");

        int i = 0;
        PreparedStatement pst = db.prepareStatement(sql.toString());
        if (folderId > 0) {
            pst.setInt(++i, folderId);
        } else {
            pst.setNull(++i, java.sql.Types.INTEGER);
        }
        pst.setString(++i, subject);
        pst.setString(++i, clientFilename);
        pst.setString(++i, filename);
        pst.setDouble(++i, version);
        pst.setInt(++i, size);
        pst.setBoolean(++i, enabled);
        pst.setInt(++i, downloads);
        if (entered != null) {
            pst.setTimestamp(++i, entered);
        }
        if (modified != null) {
            pst.setTimestamp(++i, modified);
        }
        pst.setInt(++i, linkModuleId);
        pst.setInt(++i, linkItemId);
        pst.setInt(++i, enteredBy);
        pst.setInt(++i, modifiedBy);
        pst.setBoolean(++i, defaultFile);
        pst.setInt(++i, imageWidth);
        pst.setInt(++i, imageHeight);
        pst.setString(++i, comment);
        pst.setBoolean(++i, featuredFile);
        pst.execute();
        pst.close();
        id = DatabaseUtils.getCurrVal(db, "project_files_item_id_seq", -1);
        // New default item
        if (defaultFile) {
            updateDefaultRecord(db, linkModuleId, linkItemId, id);
        }
        // Insert the version information
        if (doVersionInsert) {
            FileItemVersion thisVersion = new FileItemVersion();
            thisVersion.setId(this.getId());
            thisVersion.setSubject(subject);
            thisVersion.setClientFilename(clientFilename);
            thisVersion.setFilename(filename);
            thisVersion.setVersion(version);
            thisVersion.setSize(size);
            thisVersion.setEnteredBy(enteredBy);
            thisVersion.setModifiedBy(modifiedBy);
            thisVersion.setImageWidth(imageWidth);
            thisVersion.setImageHeight(imageHeight);
            thisVersion.setComment(comment);
            thisVersion.insert(db);
        }
        logUpload(db);
        if (doCommit) {
            db.commit();
        }
        result = true;
    } catch (Exception e) {
        e.printStackTrace(System.out);
        if (doCommit) {
            db.rollback();
        }
        throw new SQLException(e.getMessage());
    } finally {
        if (doCommit) {
            db.setAutoCommit(true);
        }
    }
    return result;
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMySql.CFAccMySqlAttachmentTable.java

public CFAccAttachmentBuff[] readBuffByMimeTypeIdx(CFAccAuthorization Authorization, Integer MimeTypeId) {
    final String S_ProcName = "readBuffByMimeTypeIdx";
    ResultSet resultSet = null;//from   w  ww.  j a  v a  2 s.  c om
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerSchemaDbName() + ".sp_read_attchmnt_by_mimetypeidx( ?, ?, ?, ?, ?"
                + ", " + "?" + " )";
        if (stmtReadBuffByMimeTypeIdx == null) {
            stmtReadBuffByMimeTypeIdx = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtReadBuffByMimeTypeIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByMimeTypeIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtReadBuffByMimeTypeIdx.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtReadBuffByMimeTypeIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtReadBuffByMimeTypeIdx.setLong(argIdx++,
                (Authorization == null) ? 0 : Authorization.getSecTenantId());
        if (MimeTypeId != null) {
            stmtReadBuffByMimeTypeIdx.setInt(argIdx++, MimeTypeId.intValue());
        } else {
            stmtReadBuffByMimeTypeIdx.setNull(argIdx++, java.sql.Types.INTEGER);
        }
        try {
            resultSet = stmtReadBuffByMimeTypeIdx.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        List<CFAccAttachmentBuff> buffList = new LinkedList<CFAccAttachmentBuff>();
        while ((resultSet != null) && resultSet.next()) {
            CFAccAttachmentBuff buff = unpackAttachmentResultSetToBuff(resultSet);
            buffList.add(buff);
        }
        int idx = 0;
        CFAccAttachmentBuff[] retBuff = new CFAccAttachmentBuff[buffList.size()];
        Iterator<CFAccAttachmentBuff> 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.CFGenKbMySqlGelPopTable.java

public CFGenKbGelPopBuff[] readBuffByCallerIdx(CFGenKbAuthorization Authorization, long TenantId,
        long CartridgeId, Integer CallerId) {
    final String S_ProcName = "readBuffByCallerIdx";
    ResultSet resultSet = null;//from  w w w .  j  ava 2s.  c  o m
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerSchemaDbName() + ".sp_read_gelpop_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<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:org.openmrs.module.sync.api.db.hibernate.HibernateSyncDAO.java

public void exportChildDB(String uuidForChild, OutputStream os) throws DAOException {
    PrintStream out = new PrintStream(os);
    Set<String> tablesToSkip = new HashSet<String>();
    {/* w  w  w  .jav  a 2  s .  c o m*/
        tablesToSkip.add("hl7_in_archive");
        tablesToSkip.add("hl7_in_queue");
        tablesToSkip.add("hl7_in_error");
        tablesToSkip.add("formentry_archive");
        tablesToSkip.add("formentry_queue");
        tablesToSkip.add("formentry_error");
        tablesToSkip.add("sync_class");
        tablesToSkip.add("sync_import");
        tablesToSkip.add("sync_record");
        tablesToSkip.add("sync_server");
        tablesToSkip.add("sync_server_class");
        tablesToSkip.add("sync_server_record");
        // TODO: figure out which other tables to skip
        // tablesToSkip.add("obs");
        // tablesToSkip.add("concept");
        // tablesToSkip.add("patient");
    }
    List<String> tablesToDump = new ArrayList<String>();
    Session session = sessionFactory.getCurrentSession();
    String schema = (String) session.createSQLQuery("SELECT schema()").uniqueResult();
    log.warn("schema: " + schema);
    // Get all tables that we'll need to dump
    {
        Query query = session.createSQLQuery(
                "SELECT tabs.table_name FROM INFORMATION_SCHEMA.TABLES tabs WHERE tabs.table_schema = '"
                        + schema + "'");
        for (Object tn : query.list()) {
            String tableName = (String) tn;
            if (!tablesToSkip.contains(tableName.toLowerCase()))
                tablesToDump.add(tableName);
        }
    }
    log.warn("tables to dump: " + tablesToDump);

    String thisServerGuid = getGlobalProperty(SyncConstants.PROPERTY_SERVER_UUID);

    // Write the DDL Header as mysqldump does
    {
        out.println("-- ------------------------------------------------------");
        out.println("-- Database dump to create an openmrs child server");
        out.println("-- Schema: " + schema);
        out.println("-- Parent GUID: " + thisServerGuid);
        out.println("-- Parent version: " + OpenmrsConstants.OPENMRS_VERSION);
        out.println("-- ------------------------------------------------------");
        out.println("");
        out.println("/*!40101 SET CHARACTER_SET_CLIENT=utf8 */;");
        out.println("/*!40101 SET NAMES utf8 */;");
        out.println("/*!40103 SET TIME_ZONE='+00:00' */;");
        out.println("/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;");
        out.println("/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;");
        out.println("/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;");
        out.println("/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;");
        out.println("/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;");
        out.println("/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;");
        out.println("/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;");
        out.println("/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;");
        out.println("");
    }
    try {
        // JDBC way of doing this
        // Connection conn =
        // DriverManager.getConnection("jdbc:mysql://localhost/" + schema,
        // "test", "test");
        Connection conn = sessionFactory.getCurrentSession().connection();
        try {
            Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

            // Get the create database statement
            ResultSet rs = st.executeQuery("SHOW CREATE DATABASE " + schema);
            for (String tableName : tablesToDump) {
                out.println();
                out.println("--");
                out.println("-- Table structure for table `" + tableName + "`");
                out.println("--");
                out.println("DROP TABLE IF EXISTS `" + tableName + "`;");
                out.println("SET @saved_cs_client     = @@character_set_client;");
                out.println("SET character_set_client = utf8;");
                rs = st.executeQuery("SHOW CREATE TABLE " + tableName);
                while (rs.next()) {
                    out.println(rs.getString("Create Table") + ";");
                }
                out.println("SET character_set_client = @saved_cs_client;");
                out.println();

                {
                    out.println("-- Dumping data for table `" + tableName + "`");
                    out.println("LOCK TABLES `" + tableName + "` WRITE;");
                    out.println("/*!40000 ALTER TABLE `" + tableName + "` DISABLE KEYS */;");
                    boolean first = true;

                    rs = st.executeQuery("select * from " + tableName);
                    ResultSetMetaData md = rs.getMetaData();
                    int numColumns = md.getColumnCount();
                    int rowNum = 0;
                    boolean insert = false;

                    while (rs.next()) {
                        if (rowNum == 0) {
                            insert = true;
                            out.print("INSERT INTO `" + tableName + "` VALUES ");
                        }
                        ++rowNum;
                        if (first) {
                            first = false;
                        } else {
                            out.print(", ");
                        }
                        if (rowNum % 20 == 0) {
                            out.println();
                        }
                        out.print("(");
                        for (int i = 1; i <= numColumns; ++i) {
                            if (i != 1) {
                                out.print(",");
                            }
                            if (rs.getObject(i) == null) {
                                out.print("NULL");
                            } else {
                                switch (md.getColumnType(i)) {
                                case Types.VARCHAR:
                                case Types.CHAR:
                                case Types.LONGVARCHAR:
                                    out.print("'");
                                    out.print(
                                            rs.getString(i).replaceAll("\n", "\\\\n").replaceAll("'", "\\\\'"));
                                    out.print("'");
                                    break;
                                case Types.BIGINT:
                                case Types.DECIMAL:
                                case Types.NUMERIC:
                                    out.print(rs.getBigDecimal(i));
                                    break;
                                case Types.BIT:
                                    out.print(rs.getBoolean(i));
                                    break;
                                case Types.INTEGER:
                                case Types.SMALLINT:
                                case Types.TINYINT:
                                    out.print(rs.getInt(i));
                                    break;
                                case Types.REAL:
                                case Types.FLOAT:
                                case Types.DOUBLE:
                                    out.print(rs.getDouble(i));
                                    break;
                                case Types.BLOB:
                                case Types.VARBINARY:
                                case Types.LONGVARBINARY:
                                    Blob blob = rs.getBlob(i);
                                    out.print("'");
                                    InputStream in = blob.getBinaryStream();
                                    while (true) {
                                        int b = in.read();
                                        if (b < 0) {
                                            break;
                                        }
                                        char c = (char) b;
                                        if (c == '\'') {
                                            out.print("\'");
                                        } else {
                                            out.print(c);
                                        }
                                    }
                                    out.print("'");
                                    break;
                                case Types.CLOB:
                                    out.print("'");
                                    out.print(
                                            rs.getString(i).replaceAll("\n", "\\\\n").replaceAll("'", "\\\\'"));
                                    out.print("'");
                                    break;
                                case Types.DATE:
                                    out.print("'" + rs.getDate(i) + "'");
                                    break;
                                case Types.TIMESTAMP:
                                    out.print("'" + rs.getTimestamp(i) + "'");
                                    break;
                                default:
                                    throw new RuntimeException("TODO: handle type code " + md.getColumnType(i)
                                            + " (name " + md.getColumnTypeName(i) + ")");
                                }
                            }
                        }
                        out.print(")");
                    }
                    if (insert) {
                        out.println(";");
                        insert = false;
                    }

                    out.println("/*!40000 ALTER TABLE `" + tableName + "` ENABLE KEYS */;");
                    out.println("UNLOCK TABLES;");
                    out.println();
                }
            }
        } finally {
            conn.close();
        }

        // Now we mark this as a child
        out.println("-- Now mark this as a child database");
        if (uuidForChild == null)
            uuidForChild = SyncUtil.generateUuid();
        out.println("update global_property set property_value = '" + uuidForChild + "' where property = '"
                + SyncConstants.PROPERTY_SERVER_UUID + "';");

        // Write the footer of the DDL script
        {
            out.println("/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;");
            out.println("/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;");
            out.println("/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;");
            out.println("/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;");
            out.println("/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;");
            out.println("/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;");
            out.println("/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;");
            out.println("/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;");
        }
        out.flush();
        out.close();
    } catch (IOException ex) {
        log.error("IOException", ex);

    } catch (SQLException ex) {
        log.error("SQLException", ex);
    }
}

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

public CFGenKbGelReferenceBuff[] readBuffByCallerIdx(CFGenKbAuthorization Authorization, long TenantId,
        long CartridgeId, Integer CallerId) {
    final String S_ProcName = "readBuffByCallerIdx";
    ResultSet resultSet = null;/*from  w  w  w .  j a  v a 2s .  c  om*/
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerSchemaDbName() + ".sp_read_gelrefer_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<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[] readBuffByCallerIdx(CFGenKbAuthorization Authorization, long TenantId,
        long CartridgeId, Integer CallerId) {
    final String S_ProcName = "readBuffByCallerIdx";
    ResultSet resultSet = null;/* ww  w.  j  a  v  a2 s.c  o m*/
    try {
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerSchemaDbName() + ".sp_read_gelprefix_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<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.cfacc.v2_0.CFAccPgSql.CFAccPgSqlAttachmentTable.java

public void updateAttachment(CFAccAuthorization Authorization, CFAccAttachmentBuff Buff) {
    final String S_ProcName = "updateAttachment";
    ResultSet resultSet = null;/*from w w w  .j  ava  2 s  .c  o m*/
    try {
        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();
        Connection cnx = schema.getCnx();
        String sql = "select * from " + schema.getLowerSchemaDbName() + ".sp_update_attchmnt( ?, ?, ?, ?, ?, ?"
                + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "cast( ? as text )"
                + ", " + "?" + " )";
        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++, "ATTC");
        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.setInt(argIdx++, Revision);
        resultSet = stmtUpdateByPKey.executeQuery();
        if (resultSet.next()) {
            CFAccAttachmentBuff updatedBuff = unpackAttachmentResultSetToBuff(resultSet);
            if (resultSet.next()) {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Did not expect multi-record response");
            }
            Buff.setRequiredContactId(updatedBuff.getRequiredContactId());
            Buff.setRequiredDescription(updatedBuff.getRequiredDescription());
            Buff.setOptionalMimeTypeId(updatedBuff.getOptionalMimeTypeId());
            Buff.setRequiredAttachment(updatedBuff.getRequiredAttachment());
            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:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public int editUser(final User user) {
    int uid = -1;

    Connection conn = null;//from  ww w  .jav  a2  s .  c  om
    CallableStatement stmt = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_EDITUSER (?,?,?,?,?,?,?)}");
        stmt.registerOutParameter(1, Types.INTEGER);
        stmt.setInt(2, user.getAuctionUid());
        stmt.setString(3, user.getBidderNumber());
        stmt.setString(4, user.getFirstName());
        stmt.setString(5, user.getLastName());
        stmt.setString(6, user.getPasswordHash());
        stmt.setInt(7, user.getRole().getId());
        stmt.execute();

        uid = stmt.getInt(1);
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
        uid = -1;
    } finally {
        DbUtils.closeQuietly(conn, stmt, null);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("USER [method:{} result:{}]", new Object[] { "add", uid });
    }

    return uid;
}

From source file:com.krawler.portal.tools.ServiceBuilder.java

public void _buildModule(DataObjectOperations dobj, String tablename, String moduleid) {
    Map mapObj = (Map) dobj.getDataObjectMapById("mbFormConfig", "moduleid", moduleid);
    String tableName = null;/*from  ww  w.j a v  a2  s  .c om*/
    List<ModuleProperty> fieldData = new ArrayList<ModuleProperty>();
    JSONArray jarray = null;
    if (mapObj != null) {
        try {
            JSONObject jobj = new JSONObject(mapObj.get("fielddata").toString());
            tableName = jobj.getString("tablename");
            jarray = jobj.getJSONArray("data");
        } catch (JSONException ex) {
            logger.warn(ex.getMessage(), ex);
            throw new RuntimeException("Module Configuration not found");
        }
    }
    if (jarray.length() == 0) {
        throw new RuntimeException("Module Configuration is incorrect");
    }

    try {
        for (int i = 0; i < jarray.length(); i++) {
            JSONObject jobjtemp = new JSONObject(jarray.get(i).toString());
            String type = jobjtemp.getString("type");
            int fieldType = 1;
            if (type.equalsIgnoreCase("String")) {
                fieldType = Types.VARCHAR;
            } else if (type.equalsIgnoreCase("double")) {
                fieldType = Types.DOUBLE;
            } else if (type.equals("boolean")) {
                fieldType = Types.BIT;
            } else if (type.equalsIgnoreCase("date")) {
                fieldType = Types.DATE;
            } else if (type.equals("int")) {
                fieldType = Types.INTEGER;
            }
            ModuleProperty moduleField = new ModuleProperty(jobjtemp.get("name").toString(), fieldType);
            moduleField.setForeignKey(jobjtemp.optBoolean("foreignid", false));
            moduleField.setPrimaryKey(jobjtemp.optBoolean("primaryid", false));
            moduleField.setDefaultValue(jobjtemp.optString("defaults", ""));
            moduleField.setRefTable(jobjtemp.optString("table", ""));
            moduleField.setRefField(jobjtemp.optString("reffield", ""));
            fieldData.add(moduleField);
        }
    } catch (JSONException ex) {
        logger.warn(ex.getMessage(), ex);
        throw new RuntimeException("Module Configuration is incorrect");
    } catch (Exception ex) {
        logger.warn(ex.getMessage(), ex);
        throw new RuntimeException("Module Configuration is incorrect");
    }

    dobj.createModuleTable(tableName, fieldData);
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWAttachmentTable.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");
    }//w w  w  .ja va 2 s. c o  m
    ResultSet resultSet = null;
    try {
        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();
        Connection cnx = schema.getCnx();
        final String sql = "CALL sp_update_attchmnt( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?"
                + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + " )";
        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++, "ATTC");
        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.setInt(argIdx++, Revision);
        resultSet = stmtUpdateByPKey.executeQuery();
        if (resultSet.next()) {
            CFAccAttachmentBuff updatedBuff = unpackAttachmentResultSetToBuff(resultSet);
            if (resultSet.next()) {
                resultSet.last();
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
            }
            Buff.setRequiredContactId(updatedBuff.getRequiredContactId());
            Buff.setRequiredDescription(updatedBuff.getRequiredDescription());
            Buff.setOptionalMimeTypeId(updatedBuff.getOptionalMimeTypeId());
            Buff.setRequiredAttachment(updatedBuff.getRequiredAttachment());
            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;
        }
    }
}