Example usage for java.sql Types BIGINT

List of usage examples for java.sql Types BIGINT

Introduction

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

Prototype

int BIGINT

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

Click Source Link

Document

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

Usage

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseClusterTable.java

public long nextSecGroupIncludeIdGen(CFAstAuthorization Authorization, CFAstClusterPKey PKey) {
    final String S_ProcName = "nextSecGroupIncludeIdGen";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Not in a transaction");
    }//from  w w w. j  a  v a  2  s  .c  o  m
    Connection cnx = schema.getCnx();
    long Id = PKey.getRequiredId();

    CallableStatement stmtSelectNextSecGroupIncludeIdGen = null;
    try {
        String sql = "{ call sp_next_secgroupincludeidgen( ?" + ", " + "?" + " ) }";
        stmtSelectNextSecGroupIncludeIdGen = cnx.prepareCall(sql);
        int argIdx = 1;
        stmtSelectNextSecGroupIncludeIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT);
        stmtSelectNextSecGroupIncludeIdGen.setLong(argIdx++, Id);
        stmtSelectNextSecGroupIncludeIdGen.execute();
        long nextId = stmtSelectNextSecGroupIncludeIdGen.getLong(1);
        return (nextId);
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (stmtSelectNextSecGroupIncludeIdGen != null) {
            try {
                stmtSelectNextSecGroupIncludeIdGen.close();
            } catch (SQLException e) {
            }
            stmtSelectNextSecGroupIncludeIdGen = null;
        }
    }
}

From source file:org.cloudfoundry.workers.stocks.batch.BatchConfiguration.java

/***
 * The Spring Batch {@link org.springframework.batch.item.ItemWriter item
 * writer} persists the {@link StockSymbolLookup} lookup results into a
 * table (<CODE>STOCKS_DATA</CODE>).
 * /*w ww. ja  v  a  2s.c o  m*/
 * @param dateOfAnalysis
 */
@Bean(name = "writer")
@Scope("step")
public JdbcBatchItemWriter<StockSymbolLookup> writer(
        final @Value("#{jobParameters['date']}") Date dateOfAnalysis) {
    JdbcBatchItemWriter<StockSymbolLookup> jdbcBatchItemWriter = new JdbcBatchItemWriter<StockSymbolLookup>();
    jdbcBatchItemWriter.setSql(
            "INSERT INTO STOCKS_DATA( DATE_ANALYSED, HIGH_PRICE, LOW_PRICE,  CLOSING_PRICE, SYMBOL) VALUES ( :da, :hp, :lp,  :cp, :s ) ");
    jdbcBatchItemWriter.setDataSource(dsConfig.dataSource());
    jdbcBatchItemWriter
            .setItemSqlParameterSourceProvider(new ItemSqlParameterSourceProvider<StockSymbolLookup>() {
                @Override
                public SqlParameterSource createSqlParameterSource(StockSymbolLookup item) {
                    return new MapSqlParameterSource()
                            .addValue("da", new java.sql.Date(dateOfAnalysis.getTime()), Types.DATE)
                            .addValue("hp", item.getHighPrice(), Types.DOUBLE)
                            .addValue("lp", item.getLowPrice(), Types.DOUBLE).addValue("s", item.getTicker())
                            .addValue("si", item.getId(), Types.BIGINT)
                            .addValue("cp", item.getLastValueWhileOpen(), Types.DOUBLE);

                }
            });
    return jdbcBatchItemWriter;
}

From source file:com.alibaba.otter.node.etl.common.db.utils.SqlUtils.java

/**
 * Check whether the given SQL type is numeric.
 *///from ww w .j a  v  a2  s.c  om
public static boolean isNumeric(int sqlType) {
    return (Types.BIT == sqlType) || (Types.BIGINT == sqlType) || (Types.DECIMAL == sqlType)
            || (Types.DOUBLE == sqlType) || (Types.FLOAT == sqlType) || (Types.INTEGER == sqlType)
            || (Types.NUMERIC == sqlType) || (Types.REAL == sqlType) || (Types.SMALLINT == sqlType)
            || (Types.TINYINT == sqlType);
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSybase.CFAsteriskSybaseClusterTable.java

public long nextSecGroupFormIdGen(CFSecurityAuthorization Authorization, CFSecurityClusterPKey PKey) {
    final String S_ProcName = "nextSecGroupFormIdGen";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Not in a transaction");
    }/*w ww.j  ava 2  s  . c  o m*/
    Connection cnx = schema.getCnx();
    long Id = PKey.getRequiredId();

    CallableStatement stmtSelectNextSecGroupFormIdGen = null;
    try {
        String sql = "{ call sp_next_secgroupformidgen( ?" + ", " + "?" + " ) }";
        stmtSelectNextSecGroupFormIdGen = cnx.prepareCall(sql);
        int argIdx = 1;
        stmtSelectNextSecGroupFormIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT);
        stmtSelectNextSecGroupFormIdGen.setLong(argIdx++, Id);
        stmtSelectNextSecGroupFormIdGen.execute();
        long nextId = stmtSelectNextSecGroupFormIdGen.getLong(1);
        return (nextId);
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (stmtSelectNextSecGroupFormIdGen != null) {
            try {
                stmtSelectNextSecGroupFormIdGen.close();
            } catch (SQLException e) {
            }
            stmtSelectNextSecGroupFormIdGen = null;
        }
    }
}

From source file:com.splicemachine.derby.utils.SpliceAdmin.java

public static void SYSCS_GET_REGION_SERVER_STATS_INFO(final ResultSet[] resultSet) throws SQLException {
    Collection<PartitionServer> load = getLoad();

    ExecRow template = new ValueRow(6);
    template.setRowArray(new DataValueDescriptor[] { new SQLVarchar(), new SQLInteger(), new SQLLongint(),
            new SQLLongint(), new SQLLongint(), new SQLLongint(), new SQLReal() });
    int i = 0;//w  w  w. j a v  a 2s.  c  o  m
    List<ExecRow> rows = new ArrayList<>(load.size());
    for (PartitionServer ps : load) {
        template.resetRowArray();
        DataValueDescriptor[] dvds = template.getRowArray();
        try {
            PartitionServerLoad psLoad = ps.getLoad();
            int idx = 0;
            dvds[idx++].setValue(ps.getHostname());
            Set<PartitionLoad> partitionLoads = psLoad.getPartitionLoads();
            long storeFileCount = 0L;
            for (PartitionLoad pLoad : partitionLoads) {
                storeFileCount += pLoad.getStorefileSizeMB();
            }
            dvds[idx++].setValue(partitionLoads.size());
            dvds[idx++].setValue(storeFileCount);
            dvds[idx++].setValue(psLoad.totalWriteRequests());
            dvds[idx++].setValue(psLoad.totalReadRequests());
            dvds[idx++].setValue(psLoad.totalRequests());

        } catch (StandardException se) {
            throw PublicAPI.wrapStandardException(se);
        } catch (Exception e) {
            throw PublicAPI.wrapStandardException(Exceptions.parseException(e));
        }
        rows.add(template.getClone());
        i++;
    }
    ResultColumnDescriptor[] columnInfo = new ResultColumnDescriptor[6];
    int idx = 0;
    columnInfo[idx++] = new GenericColumnDescriptor("host",
            DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR));
    columnInfo[idx++] = new GenericColumnDescriptor("regionCount",
            DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.BIGINT));
    columnInfo[idx++] = new GenericColumnDescriptor("storeFileCount",
            DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.BIGINT));
    columnInfo[idx++] = new GenericColumnDescriptor("writeRequestCount",
            DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.BIGINT));
    columnInfo[idx++] = new GenericColumnDescriptor("readRequestCount",
            DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.BIGINT));
    columnInfo[idx++] = new GenericColumnDescriptor("totalRequestCount",
            DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.BIGINT));
    EmbedConnection defaultConn = (EmbedConnection) BaseAdminProcedures.getDefaultConn();
    Activation lastActivation = defaultConn.getLanguageConnection().getLastActivation();
    IteratorNoPutResultSet resultsToWrap = new IteratorNoPutResultSet(rows, columnInfo, lastActivation);
    try {
        resultsToWrap.openCore();
    } catch (StandardException e) {
        throw PublicAPI.wrapStandardException(e);
    }
    EmbedResultSet ers = new EmbedResultSet40(defaultConn, resultsToWrap, false, null, true);

    resultSet[0] = ers;
}

From source file:at.alladin.rmbt.controlServer.ResultResource.java

@Post("json")
public String request(final String entity) {
    final String secret = getContext().getParameters().getFirstValue("RMBT_SECRETKEY");

    addAllowOrigin();/*from   ww  w.ja v a  2s  .co m*/

    JSONObject request = null;

    final ErrorList errorList = new ErrorList();
    final JSONObject answer = new JSONObject();

    System.out.println(MessageFormat.format(labels.getString("NEW_RESULT"), getIP()));

    if (entity != null && !entity.isEmpty())
        // try parse the string to a JSON object
        try {
            request = new JSONObject(entity);
            System.out.println(request);

            final String lang = request.optString("client_language");

            // Load Language Files for Client

            final List<String> langs = Arrays
                    .asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*"));

            if (langs.contains(lang)) {
                errorList.setLanguage(lang);
                labels = ResourceManager.getSysMsgBundle(new Locale(lang));
            }

            //                System.out.println(request.toString(4));

            if (conn != null) {

                conn.setAutoCommit(false);

                final Test test = new Test(conn);

                if (request.optString("test_token").length() > 0) {

                    final String[] token = request.getString("test_token").split("_");

                    try {

                        // Check if UUID
                        final UUID testUuid = UUID.fromString(token[0]);

                        final String data = token[0] + "_" + token[1];

                        final String hmac = Helperfunctions.calculateHMAC(secret, data);
                        if (hmac.length() == 0)
                            errorList.addError("ERROR_TEST_TOKEN");

                        if (token[2].length() > 0 && hmac.equals(token[2])) {

                            final List<String> clientNames = Arrays
                                    .asList(settings.getString("RMBT_CLIENT_NAME").split(",\\s*"));
                            final List<String> clientVersions = Arrays
                                    .asList(settings.getString("RMBT_VERSION_NUMBER").split(",\\s*"));

                            if (test.getTestByUuid(testUuid) > 0)
                                if (clientNames.contains(request.optString("client_name"))
                                        && clientVersions.contains(request.optString("client_version"))) {

                                    test.setFields(request);

                                    final String networkOperator = request
                                            .optString("telephony_network_operator");
                                    if (MCC_MNC_PATTERN.matcher(networkOperator).matches())
                                        test.getField("network_operator").setString(networkOperator);
                                    else
                                        test.getField("network_operator").setString(null);

                                    final String networkSimOperator = request
                                            .optString("telephony_network_sim_operator");
                                    if (MCC_MNC_PATTERN.matcher(networkSimOperator).matches())
                                        test.getField("network_sim_operator").setString(networkSimOperator);
                                    else
                                        test.getField("network_sim_operator").setString(null);

                                    // RMBTClient Info

                                    final String ipLocalRaw = request.optString("test_ip_local", null);
                                    if (ipLocalRaw != null) {
                                        final InetAddress ipLocalAddress = InetAddresses.forString(ipLocalRaw);
                                        // original address (not filtered)
                                        test.getField("client_ip_local")
                                                .setString(InetAddresses.toAddrString(ipLocalAddress));
                                        // anonymized local address
                                        final String ipLocalAnonymized = Helperfunctions
                                                .anonymizeIp(ipLocalAddress);
                                        test.getField("client_ip_local_anonymized")
                                                .setString(ipLocalAnonymized);
                                        // type of local ip
                                        test.getField("client_ip_local_type")
                                                .setString(Helperfunctions.IpType(ipLocalAddress));
                                        // public ip
                                        final InetAddress ipPublicAddress = InetAddresses
                                                .forString(test.getField("client_public_ip").toString());
                                        test.getField("nat_type").setString(
                                                Helperfunctions.getNatType(ipLocalAddress, ipPublicAddress));
                                    }

                                    final String ipServer = request.optString("test_ip_server", null);
                                    if (ipServer != null) {
                                        final InetAddress testServerInetAddress = InetAddresses
                                                .forString(ipServer);
                                        test.getField("server_ip")
                                                .setString(InetAddresses.toAddrString(testServerInetAddress));
                                    }

                                    //log IP address
                                    final String ipSource = getIP();
                                    test.getField("source_ip").setString(ipSource);

                                    //log anonymized address
                                    try {
                                        final InetAddress ipSourceIP = InetAddress.getByName(ipSource);
                                        final String ipSourceAnonymized = Helperfunctions
                                                .anonymizeIp(ipSourceIP);
                                        test.getField("source_ip_anonymized").setString(ipSourceAnonymized);
                                    } catch (UnknownHostException e) {
                                        System.out.println("Exception thrown:" + e);
                                    }

                                    // Additional Info

                                    //////////////////////////////////////////////////
                                    // extended test stats:
                                    //////////////////////////////////////////////////
                                    final TestStat extendedTestStat = TestStat
                                            .checkForSubmittedTestStats(request, test.getUid());
                                    if (extendedTestStat != null) {
                                        final TestStatDao testStatDao = new TestStatDao(conn);
                                        testStatDao.save(extendedTestStat);
                                    }

                                    //////////////////////////////////////////////////

                                    JSONArray speedData = request.optJSONArray("speed_detail");

                                    if (speedData != null && !test.hasError()) {
                                        final PreparedStatement psSpeed = conn.prepareStatement(
                                                "INSERT INTO test_speed (test_id, upload, thread, time, bytes) VALUES (?,?,?,?,?)");
                                        psSpeed.setLong(1, test.getUid());
                                        for (int i = 0; i < speedData.length(); i++) {
                                            final JSONObject item = speedData.getJSONObject(i);

                                            final String direction = item.optString("direction");
                                            if (direction != null && (direction.equals("download")
                                                    || direction.equals("upload"))) {
                                                psSpeed.setBoolean(2, direction.equals("upload"));
                                                psSpeed.setInt(3, item.optInt("thread"));
                                                psSpeed.setLong(4, item.optLong("time"));
                                                psSpeed.setLong(5, item.optLong("bytes"));

                                                psSpeed.executeUpdate();
                                            }
                                        }
                                    }

                                    final JSONArray pingData = request.optJSONArray("pings");

                                    if (pingData != null && !test.hasError()) {
                                        final PreparedStatement psPing = conn.prepareStatement(
                                                "INSERT INTO ping (test_id, value, value_server, time_ns) "
                                                        + "VALUES(?,?,?,?)");
                                        psPing.setLong(1, test.getUid());

                                        for (int i = 0; i < pingData.length(); i++) {

                                            final JSONObject pingDataItem = pingData.getJSONObject(i);

                                            long valueClient = pingDataItem.optLong("value", -1);
                                            if (valueClient >= 0)
                                                psPing.setLong(2, valueClient);
                                            else
                                                psPing.setNull(2, Types.BIGINT);

                                            long valueServer = pingDataItem.optLong("value_server", -1);
                                            if (valueServer >= 0)
                                                psPing.setLong(3, valueServer);
                                            else
                                                psPing.setNull(3, Types.BIGINT);

                                            long timeNs = pingDataItem.optLong("time_ns", -1);
                                            if (timeNs >= 0)
                                                psPing.setLong(4, timeNs);
                                            else
                                                psPing.setNull(4, Types.BIGINT);

                                            psPing.executeUpdate();
                                        }
                                    }

                                    final JSONArray geoData = request.optJSONArray("geoLocations");

                                    if (geoData != null && !test.hasError())
                                        for (int i = 0; i < geoData.length(); i++) {

                                            final JSONObject geoDataItem = geoData.getJSONObject(i);

                                            if (geoDataItem.optLong("tstamp", 0) != 0
                                                    && geoDataItem.optDouble("geo_lat", 0) != 0
                                                    && geoDataItem.optDouble("geo_long", 0) != 0) {

                                                final GeoLocation geoloc = new GeoLocation(conn);

                                                geoloc.setTest_id(test.getUid());

                                                final long clientTime = geoDataItem.optLong("tstamp");
                                                final Timestamp tstamp = java.sql.Timestamp
                                                        .valueOf(new Timestamp(clientTime).toString());

                                                geoloc.setTime(tstamp, test.getField("timezone").toString());
                                                geoloc.setAccuracy(
                                                        (float) geoDataItem.optDouble("accuracy", 0));
                                                geoloc.setAltitude(geoDataItem.optDouble("altitude", 0));
                                                geoloc.setBearing((float) geoDataItem.optDouble("bearing", 0));
                                                geoloc.setSpeed((float) geoDataItem.optDouble("speed", 0));
                                                geoloc.setProvider(geoDataItem.optString("provider", ""));
                                                geoloc.setGeo_lat(geoDataItem.optDouble("geo_lat", 0));
                                                geoloc.setGeo_long(geoDataItem.optDouble("geo_long", 0));
                                                geoloc.setTime_ns(geoDataItem.optLong("time_ns", 0));

                                                geoloc.storeLocation();

                                                // Store Last Geolocation as
                                                // Testlocation
                                                if (i == geoData.length() - 1) {
                                                    if (geoDataItem.has("geo_lat"))
                                                        test.getField("geo_lat").setField(geoDataItem);

                                                    if (geoDataItem.has("geo_long"))
                                                        test.getField("geo_long").setField(geoDataItem);

                                                    if (geoDataItem.has("accuracy"))
                                                        test.getField("geo_accuracy").setField(geoDataItem);

                                                    if (geoDataItem.has("provider"))
                                                        test.getField("geo_provider").setField(geoDataItem);
                                                }

                                                if (geoloc.hasError()) {
                                                    errorList.addError(geoloc.getError());
                                                    break;
                                                }

                                            }

                                        }

                                    final JSONArray cellData = request.optJSONArray("cellLocations");

                                    if (cellData != null && !test.hasError())
                                        for (int i = 0; i < cellData.length(); i++) {

                                            final JSONObject cellDataItem = cellData.getJSONObject(i);

                                            final Cell_location cellloc = new Cell_location(conn);

                                            cellloc.setTest_id(test.getUid());

                                            final long clientTime = cellDataItem.optLong("time");
                                            final Timestamp tstamp = java.sql.Timestamp
                                                    .valueOf(new Timestamp(clientTime).toString());

                                            cellloc.setTime(tstamp, test.getField("timezone").toString());

                                            cellloc.setTime_ns(cellDataItem.optLong("time_ns", 0));

                                            cellloc.setLocation_id(cellDataItem.optInt("location_id", 0));
                                            cellloc.setArea_code(cellDataItem.optInt("area_code", 0));

                                            cellloc.setPrimary_scrambling_code(
                                                    cellDataItem.optInt("primary_scrambling_code", 0));

                                            cellloc.storeLocation();

                                            if (cellloc.hasError()) {
                                                errorList.addError(cellloc.getError());
                                                break;
                                            }

                                        }

                                    int signalStrength = Integer.MAX_VALUE; //measured as RSSI (GSM,UMTS,Wifi)
                                    int lteRsrp = Integer.MAX_VALUE; // signal strength measured as RSRP
                                    int lteRsrq = Integer.MAX_VALUE; // signal quality of LTE measured as RSRQ
                                    int linkSpeed = UNKNOWN;
                                    final int networkType = test.getField("network_type").intValue();

                                    final JSONArray signalData = request.optJSONArray("signals");

                                    if (signalData != null && !test.hasError()) {

                                        for (int i = 0; i < signalData.length(); i++) {

                                            final JSONObject signalDataItem = signalData.getJSONObject(i);

                                            final Signal signal = new Signal(conn);

                                            signal.setTest_id(test.getUid());

                                            final long clientTime = signalDataItem.optLong("time");
                                            final Timestamp tstamp = java.sql.Timestamp
                                                    .valueOf(new Timestamp(clientTime).toString());

                                            signal.setTime(tstamp, test.getField("timezone").toString());

                                            final int thisNetworkType = signalDataItem.optInt("network_type_id",
                                                    0);
                                            signal.setNetwork_type_id(thisNetworkType);

                                            final int thisSignalStrength = signalDataItem
                                                    .optInt("signal_strength", UNKNOWN);
                                            if (thisSignalStrength != UNKNOWN)
                                                signal.setSignal_strength(thisSignalStrength);
                                            signal.setGsm_bit_error_rate(
                                                    signalDataItem.optInt("gsm_bit_error_rate", 0));
                                            final int thisLinkSpeed = signalDataItem.optInt("wifi_link_speed",
                                                    0);
                                            signal.setWifi_link_speed(thisLinkSpeed);
                                            final int rssi = signalDataItem.optInt("wifi_rssi", UNKNOWN);
                                            if (rssi != UNKNOWN)
                                                signal.setWifi_rssi(rssi);

                                            lteRsrp = signalDataItem.optInt("lte_rsrp", UNKNOWN);
                                            lteRsrq = signalDataItem.optInt("lte_rsrq", UNKNOWN);
                                            final int lteRssnr = signalDataItem.optInt("lte_rssnr", UNKNOWN);
                                            final int lteCqi = signalDataItem.optInt("lte_cqi", UNKNOWN);
                                            final long timeNs = signalDataItem.optLong("time_ns", UNKNOWN);
                                            signal.setLte_rsrp(lteRsrp);
                                            signal.setLte_rsrq(lteRsrq);
                                            signal.setLte_rssnr(lteRssnr);
                                            signal.setLte_cqi(lteCqi);
                                            signal.setTime_ns(timeNs);

                                            signal.storeSignal();

                                            if (networkType == 99) // wlan
                                            {
                                                if (rssi < signalStrength && rssi != UNKNOWN)
                                                    signalStrength = rssi;
                                            } else if (thisSignalStrength < signalStrength
                                                    && thisSignalStrength != UNKNOWN)
                                                signalStrength = thisSignalStrength;

                                            if (thisLinkSpeed != 0
                                                    && (linkSpeed == UNKNOWN || thisLinkSpeed < linkSpeed))
                                                linkSpeed = thisLinkSpeed;

                                            if (signal.hasError()) {
                                                errorList.addError(signal.getError());
                                                break;
                                            }

                                        }
                                        // set rssi value (typically GSM,UMTS, but also old LTE-phones)
                                        if (signalStrength != Integer.MAX_VALUE && signalStrength != UNKNOWN
                                                && signalStrength != 0) // 0 dBm is out of range
                                            ((IntField) test.getField("signal_strength"))
                                                    .setValue(signalStrength);
                                        // set rsrp value (typically LTE)
                                        if (lteRsrp != Integer.MAX_VALUE && lteRsrp != UNKNOWN && lteRsrp != 0) // 0 dBm is out of range
                                            ((IntField) test.getField("lte_rsrp")).setValue(lteRsrp);
                                        // set rsrq value (LTE)
                                        if (lteRsrq != Integer.MAX_VALUE && lteRsrq != UNKNOWN)
                                            ((IntField) test.getField("lte_rsrq")).setValue(lteRsrq);

                                        if (linkSpeed != Integer.MAX_VALUE && linkSpeed != UNKNOWN)
                                            ((IntField) test.getField("wifi_link_speed")).setValue(linkSpeed);
                                    }

                                    // use max network type

                                    final String sqlMaxNetworkType = "SELECT nt.uid" + " FROM signal s"
                                            + " JOIN network_type nt" + " ON s.network_type_id=nt.uid"
                                            + " WHERE test_id=?" + " ORDER BY nt.technology_order DESC"
                                            + " LIMIT 1";

                                    final PreparedStatement psMaxNetworkType = conn
                                            .prepareStatement(sqlMaxNetworkType);
                                    psMaxNetworkType.setLong(1, test.getUid());
                                    if (psMaxNetworkType.execute()) {
                                        final ResultSet rs = psMaxNetworkType.getResultSet();
                                        if (rs.next()) {
                                            final int maxNetworkType = rs.getInt("uid");
                                            if (maxNetworkType != 0)
                                                ((IntField) test.getField("network_type"))
                                                        .setValue(maxNetworkType);
                                        }
                                    }

                                    /*
                                     * check for different types (e.g.
                                     * 2G/3G)
                                     */
                                    final String sqlAggSignal = "WITH agg AS"
                                            + " (SELECT array_agg(DISTINCT nt.group_name ORDER BY nt.group_name) agg"
                                            + " FROM signal s"
                                            + " JOIN network_type nt ON s.network_type_id=nt.uid WHERE test_id=?)"
                                            + " SELECT uid FROM agg JOIN network_type nt ON nt.aggregate=agg";

                                    final PreparedStatement psAgg = conn.prepareStatement(sqlAggSignal);
                                    psAgg.setLong(1, test.getUid());
                                    if (psAgg.execute()) {
                                        final ResultSet rs = psAgg.getResultSet();
                                        if (rs.next()) {
                                            final int newNetworkType = rs.getInt("uid");
                                            if (newNetworkType != 0)
                                                ((IntField) test.getField("network_type"))
                                                        .setValue(newNetworkType);
                                        }
                                    }

                                    if (test.getField("network_type").intValue() <= 0)
                                        errorList.addError("ERROR_NETWORK_TYPE");

                                    final IntField downloadField = (IntField) test.getField("speed_download");
                                    if (downloadField.isNull() || downloadField.intValue() <= 0
                                            || downloadField.intValue() > 10000000) // 10 gbit/s limit
                                        errorList.addError("ERROR_DOWNLOAD_INSANE");

                                    final IntField upField = (IntField) test.getField("speed_upload");
                                    if (upField.isNull() || upField.intValue() <= 0
                                            || upField.intValue() > 10000000) // 10 gbit/s limit
                                        errorList.addError("ERROR_UPLOAD_INSANE");

                                    //clients still report eg: "test_ping_shortest":9195040 (note the 'test_' prefix there!)
                                    final LongField pingField = (LongField) test.getField("ping_shortest");
                                    if (pingField.isNull() || pingField.longValue() <= 0
                                            || pingField.longValue() > 60000000000L) // 1 min limit
                                        errorList.addError("ERROR_PING_INSANE");

                                    if (errorList.isEmpty())
                                        test.getField("status").setString("FINISHED");
                                    else
                                        test.getField("status").setString("ERROR");

                                    test.storeTestResults(false);

                                    if (test.hasError())
                                        errorList.addError(test.getError());

                                } else
                                    errorList.addError("ERROR_CLIENT_VERSION");
                        } else
                            errorList.addError("ERROR_TEST_TOKEN_MALFORMED");
                    } catch (final IllegalArgumentException e) {
                        e.printStackTrace();
                        errorList.addError("ERROR_TEST_TOKEN_MALFORMED");
                    }

                } else
                    errorList.addError("ERROR_TEST_TOKEN_MISSING");

                conn.commit();
            } else
                errorList.addError("ERROR_DB_CONNECTION");

        } catch (final JSONException e) {
            errorList.addError("ERROR_REQUEST_JSON");
            System.out.println("Error parsing JSDON Data " + e.toString());
            e.printStackTrace();
        } catch (final SQLException e) {
            System.out.println("Error while storing data " + e.toString());
            e.printStackTrace();
        }
    else
        errorList.addErrorString("Expected request is missing.");

    try {
        answer.putOpt("error", errorList.getList());
    } catch (final JSONException e) {
        System.out.println("Error saving ErrorList: " + e.toString());
    }

    return answer.toString();
}

From source file:com.nabla.wapp.server.auth.UserManager.java

public boolean updateUserDefinition(final Integer objectId, final Integer userId, final SelectionDelta delta)
        throws SQLException {
    Assert.argumentNotNull(userId);//  w  w  w  .j  av a2 s .c  o m
    Assert.argumentNotNull(delta);

    final LockTableGuard lock = new LockTableGuard(conn, LOCK_USER_TABLES);
    try {
        final ConnectionTransactionGuard guard = new ConnectionTransactionGuard(conn);
        try {
            if (delta.isRemovals()) {
                if (objectId == null)
                    Database.executeUpdate(conn,
                            "DELETE FROM user_definition WHERE object_id IS NULL AND user_id=? AND role_id IN (?);",
                            userId, delta.getRemovals());
                else
                    Database.executeUpdate(conn,
                            "DELETE FROM user_definition WHERE object_id=? AND user_id=? AND role_id IN (?);",
                            objectId, userId, delta.getRemovals());
            }
            if (delta.isAdditions()) {
                final PreparedStatement stmt = conn.prepareStatement(
                        "INSERT INTO user_definition (object_id, user_id, role_id) VALUES(?,?,?);");
                try {
                    stmt.clearBatch();
                    if (objectId == null)
                        stmt.setNull(1, Types.BIGINT);
                    else
                        stmt.setInt(1, objectId);
                    stmt.setInt(2, userId);
                    for (final Integer childId : delta.getAdditions()) {
                        stmt.setInt(3, childId);
                        stmt.addBatch();
                    }
                    if (!Database.isBatchCompleted(stmt.executeBatch()))
                        return false;
                } finally {
                    stmt.close();
                }
            }
            return guard.setSuccess(updateUserRoleTable());
        } finally {
            guard.close();
        }
    } finally {
        lock.close();
    }
}

From source file:jeeves.resources.dbms.Dbms.java

private Element buildElement(ResultSet rs, int col, String name, int type, Hashtable<String, String> formats)
        throws SQLException {
    String value = null;/*from  ww w. j  av  a  2 s .  c  o m*/

    switch (type) {
    case Types.DATE:
        Date date = rs.getDate(col + 1);
        if (date == null)
            value = null;
        else {
            String format = formats.get(name);
            SimpleDateFormat df = (format == null) ? new SimpleDateFormat(DEFAULT_DATE_FORMAT)
                    : new SimpleDateFormat(format);
            value = df.format(date);
        }
        break;

    case Types.TIME:
        Time time = rs.getTime(col + 1);
        if (time == null)
            value = null;
        else {
            String format = formats.get(name);
            SimpleDateFormat df = (format == null) ? new SimpleDateFormat(DEFAULT_TIME_FORMAT)
                    : new SimpleDateFormat(format);
            value = df.format(time);
        }
        break;

    case Types.TIMESTAMP:
        Timestamp timestamp = rs.getTimestamp(col + 1);
        if (timestamp == null)
            value = null;
        else {
            String format = formats.get(name);
            SimpleDateFormat df = (format == null) ? new SimpleDateFormat(DEFAULT_TIMESTAMP_FORMAT)
                    : new SimpleDateFormat(format);
            value = df.format(timestamp);
        }
        break;

    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
    case Types.BIGINT:
        long l = rs.getLong(col + 1);
        if (rs.wasNull())
            value = null;
        else {
            String format = formats.get(name);
            if (format == null)
                value = l + "";
            else {
                DecimalFormat df = new DecimalFormat(format);
                value = df.format(l);
            }
        }
        break;

    case Types.DECIMAL:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.REAL:
    case Types.NUMERIC:
        double n = rs.getDouble(col + 1);

        if (rs.wasNull())
            value = null;
        else {
            String format = formats.get(name);

            if (format == null) {
                value = n + "";

                // --- this fix is mandatory for oracle
                // --- that shit returns integers like xxx.0

                if (value.endsWith(".0"))
                    value = value.substring(0, value.length() - 2);
            } else {
                DecimalFormat df = new DecimalFormat(format);
                value = df.format(n);
            }
        }
        break;

    default:
        value = rs.getString(col + 1);
        if (value != null) {
            value = stripIllegalChars(value);
        }

        break;
    }
    return new Element(name).setText(value);
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseClusterTable.java

public long nextSecGroupFormIdGen(CFAstAuthorization Authorization, CFAstClusterPKey PKey) {
    final String S_ProcName = "nextSecGroupFormIdGen";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Not in a transaction");
    }// w w w  .  java2  s . c o  m
    Connection cnx = schema.getCnx();
    long Id = PKey.getRequiredId();

    CallableStatement stmtSelectNextSecGroupFormIdGen = null;
    try {
        String sql = "{ call sp_next_secgroupformidgen( ?" + ", " + "?" + " ) }";
        stmtSelectNextSecGroupFormIdGen = cnx.prepareCall(sql);
        int argIdx = 1;
        stmtSelectNextSecGroupFormIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT);
        stmtSelectNextSecGroupFormIdGen.setLong(argIdx++, Id);
        stmtSelectNextSecGroupFormIdGen.execute();
        long nextId = stmtSelectNextSecGroupFormIdGen.getLong(1);
        return (nextId);
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (stmtSelectNextSecGroupFormIdGen != null) {
            try {
                stmtSelectNextSecGroupFormIdGen.close();
            } catch (SQLException e) {
            }
            stmtSelectNextSecGroupFormIdGen = null;
        }
    }
}

From source file:com.tesora.dve.db.NativeType.java

public boolean isNumericType() {
    return dataType == Types.BIGINT || dataType == Types.DECIMAL || dataType == Types.DOUBLE
            || dataType == Types.FLOAT || dataType == Types.INTEGER || dataType == Types.NUMERIC
            || dataType == Types.REAL || dataType == Types.TINYINT || dataType == Types.SMALLINT;
}