List of usage examples for java.sql ResultSet TYPE_SCROLL_SENSITIVE
int TYPE_SCROLL_SENSITIVE
To view the source code for java.sql ResultSet TYPE_SCROLL_SENSITIVE.
Click Source Link
ResultSet
object that is scrollable and generally sensitive to changes to the data that underlies the ResultSet
. 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 . j a v a2 s .co 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:org.springframework.jdbc.object.SqlQueryTests.java
private void doTestNamedParameterCustomerQuery(final boolean namedDeclarations) throws SQLException { mockResultSet.next();//from w w w . j a v a 2 s .c om ctrlResultSet.setReturnValue(true); mockResultSet.getInt("id"); ctrlResultSet.setReturnValue(1); mockResultSet.getString("forename"); ctrlResultSet.setReturnValue("rod"); mockResultSet.next(); ctrlResultSet.setReturnValue(false); mockResultSet.close(); ctrlResultSet.setVoidCallable(); mockPreparedStatement.setObject(1, new Integer(1), Types.NUMERIC); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.setString(2, "UK"); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.executeQuery(); ctrlPreparedStatement.setReturnValue(mockResultSet); if (debugEnabled) { mockPreparedStatement.getWarnings(); ctrlPreparedStatement.setReturnValue(null); } mockPreparedStatement.close(); ctrlPreparedStatement.setVoidCallable(); mockConnection.prepareStatement(SELECT_ID_FORENAME_NAMED_PARAMETERS_PARSED, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ctrlConnection.setReturnValue(mockPreparedStatement); replay(); class CustomerQuery extends MappingSqlQuery { public CustomerQuery(DataSource ds) { super(ds, SELECT_ID_FORENAME_NAMED_PARAMETERS); setResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); if (namedDeclarations) { declareParameter(new SqlParameter("country", Types.VARCHAR)); declareParameter(new SqlParameter("id", Types.NUMERIC)); } else { declareParameter(new SqlParameter(Types.NUMERIC)); declareParameter(new SqlParameter(Types.VARCHAR)); } compile(); } protected Object mapRow(ResultSet rs, int rownum) throws SQLException { Customer cust = new Customer(); cust.setId(rs.getInt(COLUMN_NAMES[0])); cust.setForename(rs.getString(COLUMN_NAMES[1])); return cust; } public Customer findCustomer(int id, String country) { Map params = new HashMap(); params.put("id", new Integer(id)); params.put("country", country); return (Customer) executeByNamedParam(params).get(0); } } CustomerQuery query = new CustomerQuery(mockDataSource); Customer cust = query.findCustomer(1, "UK"); assertTrue("Customer id was assigned correctly", cust.getId() == 1); assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod")); }
From source file:org.springframework.jdbc.object.SqlQueryTests.java
public void testNamedParameterInListQuery() throws SQLException { mockResultSet.next();//from w w w . j a v a 2 s . c om ctrlResultSet.setReturnValue(true); mockResultSet.getInt("id"); ctrlResultSet.setReturnValue(1); mockResultSet.getString("forename"); ctrlResultSet.setReturnValue("rod"); mockResultSet.next(); ctrlResultSet.setReturnValue(true); mockResultSet.getInt("id"); ctrlResultSet.setReturnValue(2); mockResultSet.getString("forename"); ctrlResultSet.setReturnValue("juergen"); mockResultSet.next(); ctrlResultSet.setReturnValue(false); mockResultSet.close(); ctrlResultSet.setVoidCallable(); mockPreparedStatement.setObject(1, new Integer(1), Types.NUMERIC); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.setObject(2, new Integer(2), Types.NUMERIC); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.executeQuery(); ctrlPreparedStatement.setReturnValue(mockResultSet); if (debugEnabled) { mockPreparedStatement.getWarnings(); ctrlPreparedStatement.setReturnValue(null); } mockPreparedStatement.close(); ctrlPreparedStatement.setVoidCallable(); mockConnection.prepareStatement(SELECT_ID_FORENAME_WHERE_ID_IN_LIST_1, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ctrlConnection.setReturnValue(mockPreparedStatement); replay(); class CustomerQuery extends MappingSqlQuery { public CustomerQuery(DataSource ds) { super(ds, SELECT_ID_FORENAME_WHERE_ID_IN_LIST_2); setResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); declareParameter(new SqlParameter("ids", Types.NUMERIC)); compile(); } protected Object mapRow(ResultSet rs, int rownum) throws SQLException { Customer cust = new Customer(); cust.setId(rs.getInt(COLUMN_NAMES[0])); cust.setForename(rs.getString(COLUMN_NAMES[1])); return cust; } public List findCustomers(List ids) { Map params = new HashMap(); params.put("ids", ids); return (List) executeByNamedParam(params); } } CustomerQuery query = new CustomerQuery(mockDataSource); List ids = new ArrayList(); ids.add(new Integer(1)); ids.add(new Integer(2)); List cust = query.findCustomers(ids); assertEquals("We got two customers back", cust.size(), 2); Assert.assertEquals("First customer id was assigned correctly", ((Customer) cust.get(0)).getId(), 1); Assert.assertEquals("First customer forename was assigned correctly", ((Customer) cust.get(0)).getForename(), "rod"); Assert.assertEquals("Second customer id was assigned correctly", ((Customer) cust.get(1)).getId(), 2); Assert.assertEquals("Second customer forename was assigned correctly", ((Customer) cust.get(1)).getForename(), "juergen"); }
From source file:org.springframework.jdbc.object.SqlQueryTests.java
public void testNamedParameterQueryReusingParameter() throws SQLException { mockResultSet.next();/*from w w w.j a v a 2 s .c om*/ ctrlResultSet.setReturnValue(true); mockResultSet.getInt("id"); ctrlResultSet.setReturnValue(1); mockResultSet.getString("forename"); ctrlResultSet.setReturnValue("rod"); mockResultSet.next(); ctrlResultSet.setReturnValue(true); mockResultSet.getInt("id"); ctrlResultSet.setReturnValue(2); mockResultSet.getString("forename"); ctrlResultSet.setReturnValue("juergen"); mockResultSet.next(); ctrlResultSet.setReturnValue(false); mockResultSet.close(); ctrlResultSet.setVoidCallable(); mockPreparedStatement.setObject(1, new Integer(1), Types.NUMERIC); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.setObject(2, new Integer(1), Types.NUMERIC); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.executeQuery(); ctrlPreparedStatement.setReturnValue(mockResultSet); if (debugEnabled) { mockPreparedStatement.getWarnings(); ctrlPreparedStatement.setReturnValue(null); } mockPreparedStatement.close(); ctrlPreparedStatement.setVoidCallable(); mockConnection.prepareStatement(SELECT_ID_FORENAME_WHERE_ID_REUSED_1, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ctrlConnection.setReturnValue(mockPreparedStatement); replay(); class CustomerQuery extends MappingSqlQuery { public CustomerQuery(DataSource ds) { super(ds, SELECT_ID_FORENAME_WHERE_ID_REUSED_2); setResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); declareParameter(new SqlParameter("id1", Types.NUMERIC)); compile(); } protected Object mapRow(ResultSet rs, int rownum) throws SQLException { Customer cust = new Customer(); cust.setId(rs.getInt(COLUMN_NAMES[0])); cust.setForename(rs.getString(COLUMN_NAMES[1])); return cust; } public List findCustomers(Integer id) { Map params = new HashMap(); params.put("id1", id); return (List) executeByNamedParam(params); } } CustomerQuery query = new CustomerQuery(mockDataSource); List cust = query.findCustomers(new Integer(1)); assertEquals("We got two customers back", cust.size(), 2); Assert.assertEquals("First customer id was assigned correctly", ((Customer) cust.get(0)).getId(), 1); Assert.assertEquals("First customer forename was assigned correctly", ((Customer) cust.get(0)).getForename(), "rod"); Assert.assertEquals("Second customer id was assigned correctly", ((Customer) cust.get(1)).getId(), 2); Assert.assertEquals("Second customer forename was assigned correctly", ((Customer) cust.get(1)).getForename(), "juergen"); }
From source file:org.xenei.jdbc4sparql.J4SDatabaseMetaData.java
@Override public boolean supportsResultSetType(final int arg0) throws SQLException { switch (arg0) { case ResultSet.TYPE_FORWARD_ONLY: case ResultSet.CONCUR_READ_ONLY: case ResultSet.TYPE_SCROLL_INSENSITIVE: case ResultSet.HOLD_CURSORS_OVER_COMMIT: return true; case ResultSet.CLOSE_CURSORS_AT_COMMIT: case ResultSet.CONCUR_UPDATABLE: case ResultSet.TYPE_SCROLL_SENSITIVE: default://from w ww.j a v a 2s . c om return false; } }
From source file:orca.registry.DatabaseOperations.java
License:asdf
/** * Return information about actors as map indexed by actor name. If essential only set, don't * return RDFs and descriptions//w w w. ja va2s. c o m * @param actorType - one of 'actors', 'sms', 'brokers' or 'ams' * @param validOnly - only admin-validated actors are included * @param essentialOnly - provide only name, type, location and certificate * @return */ public Map<String, Map<String, String>> queryMap(String actorType, boolean validOnly, boolean essentialOnly) { HashMap<String, Map<String, String>> result = new HashMap<String, Map<String, String>>(); if (actorType == null) { result.put(STATUS_STRING, new HashMap<String, String>() { { put(STATUS_STRING, "Unknown actor type"); } }); return result; } log.debug("Inside DatabaseOperations: queryMap() - query for Actor of Type: " + actorType); Connection conn = null; try { //System.out.println("Trying to get a new instance"); log.debug("Inside DatabaseOperations: queryMap() - Trying to get a new instance"); Class.forName("com.mysql.jdbc.Driver").newInstance(); //System.out.println("Trying to get a database connection"); log.debug("Inside DatabaseOperations: queryMap() - Trying to get a database connection"); conn = DriverManager.getConnection(url, userName, password); //System.out.println ("Database connection established"); log.debug("Inside DatabaseOperations: queryMap() - Database connection established"); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); result.put(STATUS_STRING, new HashMap<String, String>() { { put(STATUS_STRING, "No actors match the query"); } }); ResultSet srs = null; if (actorType.equalsIgnoreCase(QUERY_ACTORS)) { srs = stmt.executeQuery("SELECT * FROM Actors"); } else if (actorType.equalsIgnoreCase(QUERY_ACTORS_VERIFIED)) { srs = stmt.executeQuery("SELECT * FROM Actors where act_verified='" + TRUE_STRING + "'"); } else if (actorType.equalsIgnoreCase(QUERY_SMS)) { srs = stmt.executeQuery("SELECT * FROM Actors where act_type=1"); } else if (actorType.equalsIgnoreCase(QUERY_BROKERS)) { srs = stmt.executeQuery("SELECT * FROM Actors where act_type=2"); } else if (actorType.equalsIgnoreCase(QUERY_AMS)) { srs = stmt.executeQuery("SELECT * FROM Actors where act_type=3"); } else { result.put(STATUS_STRING, new HashMap<String, String>() { { put(STATUS_STRING, "Unknown actor type"); } }); } while (srs.next()) { HashMap<String, String> tmpMap = new HashMap<String, String>(); nonNullMapPut(tmpMap, ActorName, srs.getString("act_name")); nonNullMapPut(tmpMap, ActorGuid, srs.getString("act_guid")); String act_type = srs.getString("act_type"); String actor_type = null; // These names match ConfigurationProcessor definitions in ORCA if (act_type.equalsIgnoreCase("1")) { actor_type = "sm"; } if (act_type.equalsIgnoreCase("2")) { actor_type = "broker"; } if (act_type.equalsIgnoreCase("3")) { actor_type = "site"; } nonNullMapPut(tmpMap, ActorType, actor_type); nonNullMapPut(tmpMap, ActorLocation, srs.getString("act_soapaxis2url")); nonNullMapPut(tmpMap, ActorCert64, srs.getString("act_cert64")); if (!essentialOnly) { nonNullMapPut(tmpMap, ActorFullRDF, srs.getString("act_full_rdf")); nonNullMapPut(tmpMap, ActorAllocunits, srs.getString("act_allocatable_units")); nonNullMapPut(tmpMap, ActorAbstractRDF, srs.getString("act_abstract_rdf")); nonNullMapPut(tmpMap, ActorClazz, srs.getString("act_class")); nonNullMapPut(tmpMap, ActorMapperclass, srs.getString("act_mapper_class")); nonNullMapPut(tmpMap, ActorDesc, srs.getString("act_desc")); nonNullMapPut(tmpMap, ActorPubkey, srs.getString("act_pubkey")); } // FIXME: hard code protocol for now nonNullMapPut(tmpMap, ActorProtocol, SOAPAXIS2_PROTOCOL); String act_last_update = srs.getString("act_last_update"); nonNullMapPut(tmpMap, ActorLastUpdate, act_last_update); String act_production_deployment = srs.getString("act_production_deployment"); nonNullMapPut(tmpMap, ActorProduction, act_production_deployment); String act_verified = srs.getString("act_verified"); nonNullMapPut(tmpMap, ActorVerified, act_verified); // save the result if it is a valid entry if (validOnly && isValidEntry(tmpMap)) result.put(srs.getString("act_guid"), tmpMap); else if (!validOnly) result.put(srs.getString("act_guid"), tmpMap); } srs.close(); } catch (Exception e) { //System.err.println ("Cannot query the database server"); log.error("Inside DatabaseOperations: query() - Exception while querying the database server: " + e.toString()); } finally { if (conn != null) { try { conn.close(); //System.out.println ("Database connection terminated"); log.debug("Database connection terminated"); } catch (Exception e) { /* ignore close errors */ } } } if (result.size() > 1) result.put(STATUS_STRING, new HashMap<String, String>() { { put(STATUS_STRING, STATUS_SUCCESS); } }); return result; }
From source file:org.apache.hive.jdbc.HiveConnection.java
@Override public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) { throw new SQLException( "Statement with resultset concurrency " + resultSetConcurrency + " is not supported", "HYC00"); // Optional feature not implemented }/* w w w . j av a 2 s . com*/ if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE) { throw new SQLException("Statement with resultset type " + resultSetType + " is not supported", "HYC00"); // Optional feature not implemented } return new HiveStatement(this, client, sessHandle, resultSetType == ResultSet.TYPE_SCROLL_INSENSITIVE, fetchSize); }
From source file:org.springframework.jdbc.object.SqlQueryTests.java
public void testNamedParameterUsingInvalidQuestionMarkPlaceHolders() throws SQLException { mockConnection.prepareStatement(SELECT_ID_FORENAME_WHERE_ID_REUSED_1, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ctrlConnection.setReturnValue(mockPreparedStatement); replay();//from w w w. ja v a2 s . c o m class CustomerQuery extends MappingSqlQuery { public CustomerQuery(DataSource ds) { super(ds, SELECT_ID_FORENAME_WHERE_ID_REUSED_1); setResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); declareParameter(new SqlParameter("id1", Types.NUMERIC)); compile(); } protected Object mapRow(ResultSet rs, int rownum) throws SQLException { Customer cust = new Customer(); cust.setId(rs.getInt(COLUMN_NAMES[0])); cust.setForename(rs.getString(COLUMN_NAMES[1])); return cust; } public List findCustomers(Integer id1) { Map params = new HashMap(); params.put("id1", id1); return (List) executeByNamedParam(params); } } CustomerQuery query = new CustomerQuery(mockDataSource); try { List cust = query.findCustomers(new Integer(1)); fail("Should have caused an InvalidDataAccessApiUsageException"); } catch (InvalidDataAccessApiUsageException e) { } }
From source file:org.openmrs.module.sync.api.db.hibernate.HibernateSyncDAO.java
public void importParentDB(InputStream in) { try {// ww w . ja v a 2s .c o m Connection conn = sessionFactory.getCurrentSession().connection(); Statement statement = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; StringBuffer query = new StringBuffer(); boolean queryEnds = false; while ((line = reader.readLine()) != null) { if ((line.startsWith("#") || line.startsWith("--"))) { continue; } queryEnds = line.endsWith(";"); query.append(line); if (queryEnds) { try { statement.execute(query.toString()); } catch (SQLException ex) { log.warn(ex); ex.printStackTrace(); } query.setLength(0); } } in.close(); } catch (IOException ex) { log.warn(ex); ex.printStackTrace(); } catch (SQLException ex) { log.warn(ex); ex.printStackTrace(); } }