List of usage examples for java.sql CallableStatement getLong
long getLong(String parameterName) throws SQLException;
BIGINT
parameter as a long
in the Java programming language. From source file:net.sourceforge.msscodefactory.cfinternet.v2_1.CFInternetSybase.CFInternetSybaseClusterTable.java
public long nextHostNodeIdGen(CFInternetAuthorization Authorization, CFInternetClusterPKey PKey) { final String S_ProcName = "nextHostNodeIdGen"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); }//w w w. ja va 2 s .c om Connection cnx = schema.getCnx(); long Id = PKey.getRequiredId(); CallableStatement stmtSelectNextHostNodeIdGen = null; try { String sql = "{ call sp_next_hostnodeidgen( ?" + ", " + "?" + " ) }"; stmtSelectNextHostNodeIdGen = cnx.prepareCall(sql); int argIdx = 1; stmtSelectNextHostNodeIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT); stmtSelectNextHostNodeIdGen.setLong(argIdx++, Id); stmtSelectNextHostNodeIdGen.execute(); long nextId = stmtSelectNextHostNodeIdGen.getLong(1); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSelectNextHostNodeIdGen != null) { try { stmtSelectNextHostNodeIdGen.close(); } catch (SQLException e) { } stmtSelectNextHostNodeIdGen = null; } } }
From source file:net.sourceforge.msscodefactory.cfinternet.v2_1.CFInternetSybase.CFInternetSybaseTenantTable.java
public long nextTSecGroupMemberIdGen(CFInternetAuthorization Authorization, CFInternetTenantPKey PKey) { final String S_ProcName = "nextTSecGroupMemberIdGen"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); }// www . ja v a2 s . co m Connection cnx = schema.getCnx(); long Id = PKey.getRequiredId(); CallableStatement stmtSelectNextTSecGroupMemberIdGen = null; try { String sql = "{ call sp_next_tsecgroupmemberidgen( ?" + ", " + "?" + " ) }"; stmtSelectNextTSecGroupMemberIdGen = cnx.prepareCall(sql); int argIdx = 1; stmtSelectNextTSecGroupMemberIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT); stmtSelectNextTSecGroupMemberIdGen.setLong(argIdx++, Id); stmtSelectNextTSecGroupMemberIdGen.execute(); long nextId = stmtSelectNextTSecGroupMemberIdGen.getLong(1); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSelectNextTSecGroupMemberIdGen != null) { try { stmtSelectNextTSecGroupMemberIdGen.close(); } catch (SQLException e) { } stmtSelectNextTSecGroupMemberIdGen = null; } } }
From source file:net.sourceforge.msscodefactory.cfinternet.v2_1.CFInternetSybase.CFInternetSybaseTenantTable.java
public long nextTSecGroupIncludeIdGen(CFInternetAuthorization Authorization, CFInternetTenantPKey PKey) { final String S_ProcName = "nextTSecGroupIncludeIdGen"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); }/* w ww .j a v a 2 s . c o m*/ Connection cnx = schema.getCnx(); long Id = PKey.getRequiredId(); CallableStatement stmtSelectNextTSecGroupIncludeIdGen = null; try { String sql = "{ call sp_next_tsecgroupincludeidgen( ?" + ", " + "?" + " ) }"; stmtSelectNextTSecGroupIncludeIdGen = cnx.prepareCall(sql); int argIdx = 1; stmtSelectNextTSecGroupIncludeIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT); stmtSelectNextTSecGroupIncludeIdGen.setLong(argIdx++, Id); stmtSelectNextTSecGroupIncludeIdGen.execute(); long nextId = stmtSelectNextTSecGroupIncludeIdGen.getLong(1); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSelectNextTSecGroupIncludeIdGen != null) { try { stmtSelectNextTSecGroupIncludeIdGen.close(); } catch (SQLException e) { } stmtSelectNextTSecGroupIncludeIdGen = null; } } }
From source file:net.sourceforge.msscodefactory.cfinternet.v2_1.CFInternetSybase.CFInternetSybaseTenantTable.java
public long nextTldIdGen(CFInternetAuthorization Authorization, CFInternetTenantPKey PKey) { final String S_ProcName = "nextTldIdGen"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); }/* w w w.java2 s .com*/ Connection cnx = schema.getCnx(); long Id = PKey.getRequiredId(); CallableStatement stmtSelectNextTldIdGen = null; try { String sql = "{ call sp_next_tldidgen( ?" + ", " + "?" + " ) }"; stmtSelectNextTldIdGen = cnx.prepareCall(sql); int argIdx = 1; stmtSelectNextTldIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT); stmtSelectNextTldIdGen.setLong(argIdx++, Id); stmtSelectNextTldIdGen.execute(); long nextId = stmtSelectNextTldIdGen.getLong(1); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSelectNextTldIdGen != null) { try { stmtSelectNextTldIdGen.close(); } catch (SQLException e) { } stmtSelectNextTldIdGen = null; } } }
From source file:net.sourceforge.msscodefactory.cfinternet.v2_1.CFInternetSybase.CFInternetSybaseTenantTable.java
public long nextDomainIdGen(CFInternetAuthorization Authorization, CFInternetTenantPKey PKey) { final String S_ProcName = "nextDomainIdGen"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); }/*from w w w .ja va 2 s . c o m*/ Connection cnx = schema.getCnx(); long Id = PKey.getRequiredId(); CallableStatement stmtSelectNextDomainIdGen = null; try { String sql = "{ call sp_next_domainidgen( ?" + ", " + "?" + " ) }"; stmtSelectNextDomainIdGen = cnx.prepareCall(sql); int argIdx = 1; stmtSelectNextDomainIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT); stmtSelectNextDomainIdGen.setLong(argIdx++, Id); stmtSelectNextDomainIdGen.execute(); long nextId = stmtSelectNextDomainIdGen.getLong(1); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSelectNextDomainIdGen != null) { try { stmtSelectNextDomainIdGen.close(); } catch (SQLException e) { } stmtSelectNextDomainIdGen = null; } } }
From source file:org.apache.hadoop.metrics2.sink.SqlServerSink.java
public long getMetricRecordID(String recordTypeContext, String recordTypeName, String nodeName, String sourceIP, String clusterName, String serviceName, String tagPairs, long recordTimestamp) { CallableStatement cstmt = null; long result;/*from www .j av a 2 s .c om*/ if (recordTypeContext == null || recordTypeName == null || nodeName == null || sourceIP == null || tagPairs == null) return -1; int colid = 1; try { if (ensureConnection()) { cstmt = conn.prepareCall("{call dbo.uspGetMetricRecord(?, ?, ?, ?, ?, ?, ?, ?, ?)}"); cstmt.setNString(colid++, recordTypeContext); cstmt.setNString(colid++, recordTypeName); cstmt.setNString(colid++, nodeName); cstmt.setNString(colid++, sourceIP); cstmt.setNString(colid++, clusterName); cstmt.setNString(colid++, serviceName); cstmt.setNString(colid++, tagPairs); cstmt.setLong(colid++, recordTimestamp); cstmt.registerOutParameter(colid, java.sql.Types.BIGINT); cstmt.execute(); result = cstmt.getLong(colid); if (cstmt.wasNull()) return -1; return result; } } catch (Exception e) { if (DEBUG) logger.info("Error during getMetricRecordID call sproc: " + e.toString()); flush(); } finally { if (cstmt != null) { try { cstmt.close(); } catch (SQLException se) { if (DEBUG) logger.info("Error during getMetricRecordID close cstmt: " + se.toString()); } /* * We don't close the connection here because we are likely to be * writing * metric values next and it is more efficient to share the connection. */ } } return -1; }
From source file:org.apache.hadoop.metrics2.sink.SqlServerSinkHadoop1Test.java
@Override @Test/* w ww. j a v a 2s. c o m*/ public void testPutMetrics() throws Exception { SubsetConfiguration configuration = createNiceMock(SubsetConfiguration.class); Connection connection = createNiceMock(Connection.class); CallableStatement cstmt = createNiceMock(CallableStatement.class); MetricsRecord record = createNiceMock(MetricsRecord.class); Metric metric = createNiceMock(Metric.class); // set expectations expect(configuration.getParent()).andReturn(null); expect(configuration.getPrefix()).andReturn("prefix"); expect(configuration.getString("databaseUrl")).andReturn("url"); expect(record.context()).andReturn("context"); expect(record.name()).andReturn("typeName"); expect(record.tags()).andReturn(new HashSet<MetricsTag>()); expect(record.timestamp()).andReturn(9999L); expect(record.metrics()).andReturn(Collections.singleton(metric)); expect(metric.name()).andReturn("name").anyTimes(); expect(metric.value()).andReturn(1234); expect(connection.prepareCall("{call dbo.uspGetMetricRecord(?, ?, ?, ?, ?, ?, ?, ?, ?)}")).andReturn(cstmt); cstmt.setNString(1, "context"); cstmt.setNString(2, "typeName"); cstmt.setNString(eq(3), (String) anyObject()); cstmt.setNString(eq(4), (String) anyObject()); cstmt.setNString(eq(5), (String) anyObject()); cstmt.setNString(6, "prefix"); cstmt.setNString(7, "sourceName:prefix"); cstmt.setLong(8, 9999L); cstmt.registerOutParameter(9, java.sql.Types.BIGINT); expect(cstmt.execute()).andReturn(true); expect(cstmt.getLong(9)).andReturn(99L); expect(cstmt.wasNull()).andReturn(false); expect(connection.prepareCall("{call dbo.uspInsertMetricValue(?, ?, ?)}")).andReturn(cstmt); cstmt.setLong(1, 99L); cstmt.setNString(2, "name"); cstmt.setNString(3, "1234"); expect(cstmt.execute()).andReturn(true); // replay replay(configuration, connection, cstmt, record, metric); SqlServerSink sink = createInstance(); sink.init(configuration); SQLServerDriver.setConnection(connection); sink.putMetrics(record); verify(configuration, connection, cstmt, record, metric); }
From source file:org.apache.hadoop.metrics2.sink.SqlServerSinkHadoop2Test.java
@Override @Test// ww w. j av a 2 s. co m public void testPutMetrics() throws Exception { SubsetConfiguration configuration = createNiceMock(SubsetConfiguration.class); Connection connection = createNiceMock(Connection.class); CallableStatement cstmt = createNiceMock(CallableStatement.class); MetricsRecord record = createNiceMock(MetricsRecord.class); AbstractMetric metric = createNiceMock(AbstractMetric.class); // set expectations expect(configuration.getParent()).andReturn(null); expect(configuration.getPrefix()).andReturn("prefix"); expect(configuration.getString("databaseUrl")).andReturn("url"); expect(record.context()).andReturn("context"); expect(record.name()).andReturn("typeName"); expect(record.tags()).andReturn(new HashSet<MetricsTag>()); expect(record.timestamp()).andReturn(9999L); expect(record.metrics()).andReturn(Collections.singleton(metric)); expect(metric.name()).andReturn("name").anyTimes(); expect(metric.value()).andReturn(1234); expect(connection.prepareCall("{call dbo.uspGetMetricRecord(?, ?, ?, ?, ?, ?, ?, ?, ?)}")).andReturn(cstmt); cstmt.setNString(1, "context"); cstmt.setNString(2, "typeName"); cstmt.setNString(eq(3), (String) anyObject()); cstmt.setNString(eq(4), (String) anyObject()); cstmt.setNString(eq(5), (String) anyObject()); cstmt.setNString(6, "prefix"); cstmt.setNString(7, "sourceName:prefix"); cstmt.setLong(8, 9999L); cstmt.registerOutParameter(9, java.sql.Types.BIGINT); expect(cstmt.execute()).andReturn(true); expect(cstmt.getLong(9)).andReturn(99L); expect(cstmt.wasNull()).andReturn(false); expect(connection.prepareCall("{call dbo.uspInsertMetricValue(?, ?, ?)}")).andReturn(cstmt); cstmt.setLong(1, 99L); cstmt.setNString(2, "name"); cstmt.setNString(3, "1234"); expect(cstmt.execute()).andReturn(true); // replay replay(configuration, connection, cstmt, record, metric); SqlServerSink sink = createInstance(); sink.init(configuration); SQLServerDriver.setConnection(connection); sink.putMetrics(record); verify(configuration, connection, cstmt, record, metric); }
From source file:org.apache.hadoop.metrics2.sink.SqlServerSinkTest.java
@Test public void testGetMetricRecordID() throws Exception { SubsetConfiguration configuration = createNiceMock(SubsetConfiguration.class); Connection connection = createNiceMock(Connection.class); CallableStatement cstmt = createNiceMock(CallableStatement.class); // set expectations expect(configuration.getParent()).andReturn(null); expect(configuration.getPrefix()).andReturn("prefix"); expect(configuration.getString("databaseUrl")).andReturn("url"); expect(connection.prepareCall("{call dbo.uspGetMetricRecord(?, ?, ?, ?, ?, ?, ?, ?, ?)}")).andReturn(cstmt); cstmt.setNString(1, "context"); cstmt.setNString(2, "typeName"); cstmt.setNString(3, "nodeName"); cstmt.setNString(4, "ip"); cstmt.setNString(5, "clusterName"); cstmt.setNString(6, "serviceName"); cstmt.setNString(7, "tagPairs"); cstmt.setLong(8, 9999L);//from w w w . j av a 2s. c o m cstmt.registerOutParameter(9, java.sql.Types.BIGINT); expect(cstmt.execute()).andReturn(true); expect(cstmt.getLong(9)).andReturn(99L); expect(cstmt.wasNull()).andReturn(false); // replay replay(configuration, connection, cstmt); SqlServerSink sink = createInstance(); sink.init(configuration); SQLServerDriver.setConnection(connection); Assert.assertEquals(99, sink.getMetricRecordID("context", "typeName", "nodeName", "ip", "clusterName", "serviceName", "tagPairs", 9999L)); verify(configuration, connection, cstmt); }
From source file:org.apache.hadoop.metrics2.sink.SqlServerSinkTest.java
@Test public void testGetMetricRecordID_nullReturn() throws Exception { SubsetConfiguration configuration = createNiceMock(SubsetConfiguration.class); Connection connection = createNiceMock(Connection.class); CallableStatement cstmt = createNiceMock(CallableStatement.class); // set expectations expect(configuration.getParent()).andReturn(null); expect(configuration.getPrefix()).andReturn("prefix"); expect(configuration.getString("databaseUrl")).andReturn("url"); expect(connection.prepareCall("{call dbo.uspGetMetricRecord(?, ?, ?, ?, ?, ?, ?, ?, ?)}")).andReturn(cstmt); cstmt.setNString(1, "context"); cstmt.setNString(2, "typeName"); cstmt.setNString(3, "nodeName"); cstmt.setNString(4, "ip"); cstmt.setNString(5, "clusterName"); cstmt.setNString(6, "serviceName"); cstmt.setNString(7, "tagPairs"); cstmt.setLong(8, 9999L);/*from w ww . jav a2 s.co m*/ cstmt.registerOutParameter(9, java.sql.Types.BIGINT); expect(cstmt.execute()).andReturn(true); expect(cstmt.getLong(9)).andReturn(99L); expect(cstmt.wasNull()).andReturn(true); // replay replay(configuration, connection, cstmt); SqlServerSink sink = createInstance(); sink.init(configuration); SQLServerDriver.setConnection(connection); Assert.assertEquals(-1, sink.getMetricRecordID("context", "typeName", "nodeName", "ip", "clusterName", "serviceName", "tagPairs", 9999L)); verify(configuration, connection, cstmt); }