List of usage examples for java.sql ResultSet getBoolean
boolean getBoolean(String columnLabel) throws SQLException;
ResultSet
object as a boolean
in the Java programming language. From source file:eionet.meta.dao.mysql.VocabularyFolderDAOImpl.java
/** * {@inheritDoc}/*w w w . ja va 2s . c o m*/ */ @Override public List<VocabularyFolder> getVocabularyFolders(String userName) { Map<String, Object> params = new HashMap<String, Object>(); StringBuilder sql = new StringBuilder(); sql.append( "select v.VOCABULARY_ID, v.IDENTIFIER, v.LABEL, v.REG_STATUS, v.WORKING_COPY, v.BASE_URI, v.VOCABULARY_TYPE, "); sql.append("v.WORKING_USER, v.DATE_MODIFIED, v.USER_MODIFIED, v.CHECKEDOUT_COPY_ID, v.CONTINUITY_ID, "); sql.append("v.CONCEPT_IDENTIFIER_NUMERIC, "); sql.append("f.ID, f.IDENTIFIER, f.LABEL, v.NOTATIONS_EQUAL_IDENTIFIERS "); sql.append("from VOCABULARY v "); sql.append("left join VOCABULARY_SET f on f.ID=v.FOLDER_ID "); sql.append("where "); if (StringUtils.isBlank(userName)) { sql.append("v.WORKING_COPY=FALSE "); } else { sql.append("(v.WORKING_COPY=FALSE or v.WORKING_USER=:workingUser) "); params.put("workingUser", userName); } sql.append("order by f.IDENTIFIER, v.IDENTIFIER "); List<VocabularyFolder> items = getNamedParameterJdbcTemplate().query(sql.toString(), params, new RowMapper<VocabularyFolder>() { @Override public VocabularyFolder mapRow(ResultSet rs, int rowNum) throws SQLException { VocabularyFolder vf = new VocabularyFolder(); vf.setId(rs.getInt("v.VOCABULARY_ID")); vf.setIdentifier(rs.getString("v.IDENTIFIER")); vf.setLabel(rs.getString("v.LABEL")); vf.setRegStatus(RegStatus.fromString(rs.getString("v.REG_STATUS"))); vf.setType(VocabularyType.valueOf(rs.getString("v.VOCABULARY_TYPE"))); vf.setWorkingCopy(rs.getBoolean("v.WORKING_COPY")); vf.setWorkingUser(rs.getString("v.WORKING_USER")); vf.setDateModified(rs.getTimestamp("v.DATE_MODIFIED")); vf.setUserModified(rs.getString("v.USER_MODIFIED")); vf.setCheckedOutCopyId(rs.getInt("v.CHECKEDOUT_COPY_ID")); vf.setContinuityId(rs.getString("v.CONTINUITY_ID")); vf.setNumericConceptIdentifiers(rs.getBoolean("v.CONCEPT_IDENTIFIER_NUMERIC")); vf.setNotationsEqualIdentifiers(rs.getBoolean("NOTATIONS_EQUAL_IDENTIFIERS")); vf.setBaseUri(rs.getString("v.BASE_URI")); vf.setFolderId(rs.getShort("f.ID")); vf.setFolderName(rs.getString("f.IDENTIFIER")); vf.setFolderLabel(rs.getString("f.LABEL")); return vf; } }); return items; }
From source file:eionet.meta.dao.mysql.VocabularyFolderDAOImpl.java
/** * {@inheritDoc}//ww w. j av a 2 s . c o m */ @Override public List<VocabularyFolder> getVocabularyFolders(int folderId, String userName) { Map<String, Object> params = new HashMap<String, Object>(); params.put("folderId", folderId); StringBuilder sql = new StringBuilder(); sql.append( "select v.VOCABULARY_ID, v.IDENTIFIER, v.LABEL, v.REG_STATUS, v.WORKING_COPY, v.BASE_URI, v.VOCABULARY_TYPE, "); sql.append("v.WORKING_USER, v.DATE_MODIFIED, v.USER_MODIFIED, v.CHECKEDOUT_COPY_ID, v.CONTINUITY_ID, "); sql.append("v.CONCEPT_IDENTIFIER_NUMERIC, "); sql.append("f.ID, f.IDENTIFIER, f.LABEL, v.NOTATIONS_EQUAL_IDENTIFIERS "); sql.append("from VOCABULARY v "); sql.append("left join VOCABULARY_SET f on f.ID=v.FOLDER_ID "); sql.append("where "); if (StringUtils.isBlank(userName)) { sql.append("v.WORKING_COPY=FALSE "); } else { sql.append("(v.WORKING_COPY=FALSE or v.WORKING_USER=:workingUser) "); params.put("workingUser", userName); } sql.append("and v.FOLDER_ID=:folderId "); sql.append("order by f.IDENTIFIER, v.IDENTIFIER "); List<VocabularyFolder> items = getNamedParameterJdbcTemplate().query(sql.toString(), params, new RowMapper<VocabularyFolder>() { @Override public VocabularyFolder mapRow(ResultSet rs, int rowNum) throws SQLException { VocabularyFolder vf = new VocabularyFolder(); vf.setId(rs.getInt("v.VOCABULARY_ID")); vf.setIdentifier(rs.getString("v.IDENTIFIER")); vf.setLabel(rs.getString("v.LABEL")); vf.setRegStatus(RegStatus.fromString(rs.getString("v.REG_STATUS"))); vf.setType(VocabularyType.valueOf(rs.getString("v.VOCABULARY_TYPE"))); vf.setWorkingCopy(rs.getBoolean("v.WORKING_COPY")); vf.setWorkingUser(rs.getString("v.WORKING_USER")); vf.setDateModified(rs.getTimestamp("v.DATE_MODIFIED")); vf.setUserModified(rs.getString("v.USER_MODIFIED")); vf.setCheckedOutCopyId(rs.getInt("v.CHECKEDOUT_COPY_ID")); vf.setContinuityId(rs.getString("v.CONTINUITY_ID")); vf.setNumericConceptIdentifiers(rs.getBoolean("v.CONCEPT_IDENTIFIER_NUMERIC")); vf.setNotationsEqualIdentifiers(rs.getBoolean("NOTATIONS_EQUAL_IDENTIFIERS")); vf.setBaseUri(rs.getString("v.BASE_URI")); vf.setFolderId(rs.getShort("f.ID")); vf.setFolderName(rs.getString("f.IDENTIFIER")); vf.setFolderLabel(rs.getString("f.LABEL")); return vf; } }); return items; }
From source file:eionet.meta.dao.mysql.VocabularyFolderDAOImpl.java
/** * {@inheritDoc}//from ww w.jav a 2 s . co m */ @Override public List<VocabularyFolder> getVocabularyFolderVersions(String continuityId, int vocabularyFolderId, String userName) { Map<String, Object> params = new HashMap<String, Object>(); params.put("continuityId", continuityId); params.put("vocabularyFolderId", vocabularyFolderId); StringBuilder sql = new StringBuilder(); sql.append( "select v.VOCABULARY_ID, v.IDENTIFIER, v.LABEL, v.REG_STATUS, v.WORKING_COPY, v.BASE_URI, v.VOCABULARY_TYPE, "); sql.append("v.WORKING_USER, v.DATE_MODIFIED, v.USER_MODIFIED, v.CHECKEDOUT_COPY_ID, v.CONTINUITY_ID, "); sql.append("v.CONCEPT_IDENTIFIER_NUMERIC, "); sql.append("f.ID, f.IDENTIFIER, f.LABEL, v.NOTATIONS_EQUAL_IDENTIFIERS "); sql.append("from VOCABULARY v "); sql.append("left join VOCABULARY_SET f on f.ID=v.FOLDER_ID "); sql.append("where v.CONTINUITY_ID = :continuityId and v.VOCABULARY_ID != :vocabularyFolderId "); if (StringUtils.isBlank(userName)) { sql.append("and v.WORKING_COPY=FALSE "); } else { sql.append("and (v.WORKING_COPY=FALSE or v.WORKING_USER=:workingUser) "); params.put("workingUser", userName); } List<VocabularyFolder> items = getNamedParameterJdbcTemplate().query(sql.toString(), params, new RowMapper<VocabularyFolder>() { @Override public VocabularyFolder mapRow(ResultSet rs, int rowNum) throws SQLException { VocabularyFolder vf = new VocabularyFolder(); vf.setId(rs.getInt("v.VOCABULARY_ID")); vf.setIdentifier(rs.getString("v.IDENTIFIER")); vf.setLabel(rs.getString("v.LABEL")); vf.setRegStatus(RegStatus.fromString(rs.getString("v.REG_STATUS"))); vf.setType(VocabularyType.valueOf(rs.getString("v.VOCABULARY_TYPE"))); vf.setWorkingCopy(rs.getBoolean("v.WORKING_COPY")); vf.setWorkingUser(rs.getString("v.WORKING_USER")); vf.setDateModified(rs.getTimestamp("v.DATE_MODIFIED")); vf.setUserModified(rs.getString("v.USER_MODIFIED")); vf.setCheckedOutCopyId(rs.getInt("v.CHECKEDOUT_COPY_ID")); vf.setContinuityId(rs.getString("v.CONTINUITY_ID")); vf.setNumericConceptIdentifiers(rs.getBoolean("v.CONCEPT_IDENTIFIER_NUMERIC")); vf.setNotationsEqualIdentifiers(rs.getBoolean("NOTATIONS_EQUAL_IDENTIFIERS")); vf.setBaseUri(rs.getString("v.BASE_URI")); vf.setFolderId(rs.getShort("f.ID")); vf.setFolderName(rs.getString("f.IDENTIFIER")); vf.setFolderLabel(rs.getString("f.LABEL")); return vf; } }); return items; }
From source file:com.iCo6.iConomy.java
public boolean onConversion() { if (!Constants.Nodes.Convert.getBoolean()) return false; Thrun.init(new Runnable() { @SuppressWarnings({ "rawtypes", "unchecked" }) public void run() { String from = Constants.Nodes.ConvertFrom.toString(); String table = Constants.Nodes.ConvertTable.toString(); String username = Constants.Nodes.ConvertUsername.toString(); String password = Constants.Nodes.ConvertPassword.toString(); String url = Constants.Nodes.ConvertURL.toString(); if (!Common.matches(from, "h2", "h2db", "h2sql", "mysql", "mysqldb")) return; String driver = "", dsn = ""; if (Common.matches(from, "sqlite", "h2", "h2sql", "h2db")) { driver = "org.h2.Driver"; dsn = "jdbc:h2:" + directory + File.separator + table + ";AUTO_RECONNECT=TRUE"; username = "sa"; password = "sa"; } else if (Common.matches(from, "mysql", "mysqldb")) { driver = "com.mysql.jdbc.Driver"; dsn = url + "/" + table; }// w w w . j av a 2 s . c om if (!DbUtils.loadDriver(driver)) { System.out.println("Please make sure the " + from + " driver library jar exists."); return; } Connection old = null; try { old = (username.isEmpty() && password.isEmpty()) ? DriverManager.getConnection(url) : DriverManager.getConnection(url, username, password); } catch (SQLException ex) { System.out.println(ex); return; } QueryRunner run = new QueryRunner(); try { try { run.query(old, "SELECT * FROM " + table, new ResultSetHandler() { public Object handle(ResultSet rs) throws SQLException { Account current = null; Boolean next = rs.next(); if (next) if (iConomy.Accounts.exists(rs.getString("username"))) current = iConomy.Accounts.get(rs.getString("username")); else iConomy.Accounts.create(rs.getString("username"), rs.getDouble("balance")); if (current != null) current.getHoldings().setBalance(rs.getDouble("balance")); if (next) if (iConomy.Accounts.exists(rs.getString("username"))) if (rs.getBoolean("hidden")) iConomy.Accounts.get(rs.getString("username")).setStatus(1); return true; } }); } catch (SQLException ex) { System.out.println("[iConomy] Error issueing SQL query: " + ex); } finally { DbUtils.close(old); } } catch (SQLException ex) { System.out.println("[iConomy] Database Error: " + ex); } System.out.println( "[iConomy] Conversion complete. Please update your configuration, change convert to false!"); } }); return false; }
From source file:com.l2jfree.gameserver.instancemanager.AutoSpawnManager.java
private void restoreSpawnData() { int numLoaded = 0; Connection con = null;/*from w ww .j av a2 s. c o m*/ try { PreparedStatement statement = null; PreparedStatement statement2 = null; ResultSet rs = null; ResultSet rs2 = null; con = L2DatabaseFactory.getInstance().getConnection(con); // Restore spawn group data, then the location data. statement = con.prepareStatement("SELECT * FROM random_spawn ORDER BY groupId ASC"); rs = statement.executeQuery(); while (rs.next()) { // Register random spawn group, set various options on the created spawn instance. AutoSpawnInstance spawnInst = registerSpawn(rs.getInt("npcId"), rs.getInt("initialDelay"), rs.getInt("respawnDelay"), rs.getInt("despawnDelay")); spawnInst.setSpawnCount(rs.getInt("count")); spawnInst.setBroadcast(rs.getBoolean("broadcastSpawn")); spawnInst.setRandomSpawn(rs.getBoolean("randomSpawn")); numLoaded++; // Restore the spawn locations for this spawn group/instance. statement2 = con.prepareStatement("SELECT * FROM random_spawn_loc WHERE groupId=?"); statement2.setInt(1, rs.getInt("groupId")); rs2 = statement2.executeQuery(); while (rs2.next()) { // Add each location to the spawn group/instance. spawnInst.addSpawnLocation(rs2.getInt("x"), rs2.getInt("y"), rs2.getInt("z"), rs2.getInt("heading")); } statement2.close(); } statement.close(); _log.info("AutoSpawnHandler: Loaded " + numLoaded + " spawn group(s) from the database."); } catch (Exception e) { _log.warn("AutoSpawnHandler: Could not restore spawn data: ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.flexive.core.storage.genericSQL.GenericEnvironmentLoader.java
/** * {@inheritDoc}/*from ww w .j ava2 s. com*/ */ @Override public List<FxScriptMapping> loadScriptMapping(Connection con, FxEnvironmentImpl environment) throws FxLoadException { List<FxScriptMapping> mapping = new ArrayList<FxScriptMapping>(20); List<FxScriptMappingEntry> e_ass; List<FxScriptMappingEntry> e_types; PreparedStatement ps_a = null, ps_t = null; String sql; try { // 1 2 3 4 sql = "SELECT ASSIGNMENT,DERIVED_USAGE,ACTIVE,STYPE FROM " + TBL_SCRIPT_MAPPING_ASSIGN + " WHERE SCRIPT=? ORDER BY ASSIGNMENT"; ps_a = con.prepareStatement(sql); sql = "SELECT TYPEDEF,DERIVED_USAGE,ACTIVE,STYPE FROM " + TBL_SCRIPT_MAPPING_TYPES + " WHERE SCRIPT=? ORDER BY TYPEDEF"; ps_t = con.prepareStatement(sql); ResultSet rs; for (FxScriptInfo si : environment.getScripts()) { ps_a.setLong(1, si.getId()); ps_t.setLong(1, si.getId()); rs = ps_a.executeQuery(); e_ass = new ArrayList<FxScriptMappingEntry>(20); e_types = new ArrayList<FxScriptMappingEntry>(20); while (rs != null && rs.next()) { long[] derived; if (!rs.getBoolean(2)) derived = new long[0]; else { List<FxAssignment> ass = environment.getDerivedAssignments(rs.getLong(1)); derived = new long[ass.size()]; for (int i = 0; i < ass.size(); i++) derived[i] = ass.get(i).getId(); } e_ass.add(new FxScriptMappingEntry(FxScriptEvent.getById(rs.getLong(4)), si.getId(), rs.getBoolean(3), rs.getBoolean(2), rs.getLong(1), derived)); } rs = ps_t.executeQuery(); while (rs != null && rs.next()) { long[] derived; if (!rs.getBoolean(2)) derived = new long[0]; else { // determine derived types "manually" as resolveReferences() // which sets the derived types has not been called yet List<Long> derivedList = new ArrayList<Long>(5); for (FxType t : environment.getTypes()) { if (t.isDerived() && t.getParent().getId() == rs.getLong(1)) derivedList.add(t.getId()); } derived = new long[derivedList.size()]; int i = 0; for (long l : derivedList) derived[i++] = l; } e_types.add(new FxScriptMappingEntry(FxScriptEvent.getById(rs.getLong(4)), si.getId(), rs.getBoolean(3), rs.getBoolean(2), rs.getLong(1), derived)); } mapping.add(new FxScriptMapping(si.getId(), e_types, e_ass)); } } catch (SQLException exc) { throw new FxLoadException(LOG, exc, "ex.scripting.mapping.load.failed", exc.getMessage()); } catch (FxNotFoundException e) { throw new FxLoadException(e); } finally { try { if (ps_t != null) ps_t.close(); } catch (SQLException e) { //ignore } Database.closeObjects(GenericEnvironmentLoader.class, null, ps_a); } return mapping; }
From source file:com.flexive.core.storage.genericSQL.GenericEnvironmentLoader.java
/** * {@inheritDoc}/*from w w w .j a v a2 s . com*/ */ @Override public List<FxAssignment> loadAssignments(Connection con, FxEnvironment environment) throws FxLoadException { Statement stmt = null; String curSql; ArrayList<FxAssignment> result = new ArrayList<FxAssignment>(250); try { final Map<Long, FxString[]> translations = Database.loadFxStrings(con, TBL_STRUCT_ASSIGNMENTS, "DESCRIPTION", "HINT"); final Map<Long, List<FxStructureOption>> propertyAssignmentOptions = loadAllPropertyAssignmentOptions( con); final Map<Long, List<FxStructureOption>> groupAssignmentOptions = loadAllGroupAssignmentOptions(con); final Map<Long, FxFlatStorageMapping> flatStorageEntries = FxFlatStorageManager.getInstance() .loadAllFlatStorageMappings(con); final Map<Long, FxGroupAssignment> groupAssignments = Maps.newHashMap(); // group assignment lookup map by ID // 1 2 3 4 5 6 7 8 9 curSql = "SELECT ID, ATYPE, ENABLED, TYPEDEF, MINMULT, MAXMULT, POS, XPATH, XALIAS, " + //10 11 12 13 14 15 16 17 18 19 "PARENTGROUP, AGROUP, APROPERTY, ACL, BASE, DEFLANG, SYSINTERNAL, GROUPMODE, DEFMULT, DEFAULT_VALUE FROM " + TBL_STRUCT_ASSIGNMENTS + " ORDER BY TYPEDEF, PARENTGROUP, POS"; stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(curSql); final XStream xStream = ConversionEngine.getXStream(); while (rs != null && rs.next()) { final long id = rs.getLong(1); switch (rs.getInt(2)) { //ATYPE case FxAssignment.TYPE_GROUP: if (id == FxAssignment.NO_PARENT) break; FxGroupAssignment ga = new FxGroupAssignment(rs.getLong(1), rs.getBoolean(3), environment.getType(rs.getLong(4)), rs.getString(9), rs.getString(8), rs.getInt(7), FxMultiplicity.of(rs.getInt(5), rs.getInt(6)), rs.getInt(18), new FxPreloadGroupAssignment(rs.getLong(10)), rs.getLong(14), getTranslation(translations, id, 0, false), getTranslation(translations, id, 1, true), environment.getGroup(rs.getLong(11)), GroupMode.getById(rs.getInt(17)), FxSharedUtils.get(groupAssignmentOptions, rs.getLong(1), null)); if (rs.getBoolean(16)) ga._setSystemInternal(); result.add(ga); groupAssignments.put(ga.getId(), ga); break; case FxAssignment.TYPE_PROPERTY: FxValue defaultValue = null; String _def = rs.getString(19); if (!StringUtils.isEmpty(_def) && CacheAdmin.isEnvironmentLoaded()) { try { defaultValue = (FxValue) xStream.fromXML(_def); if (defaultValue != null && defaultValue.isEmpty()) defaultValue = null; } catch (Throwable e) { defaultValue = null; LOG.warn("Failed to unmarshall default value for assignment " + rs.getString(8) + ": " + e.getMessage(), e); } } FxPropertyAssignment pa = new FxPropertyAssignment(rs.getLong(1), rs.getBoolean(3), environment.getType(rs.getLong(4)), rs.getString(9), rs.getString(8), rs.getInt(7), FxMultiplicity.of(rs.getInt(5), rs.getInt(6)), rs.getInt(18), new FxPreloadGroupAssignment(rs.getLong(10)), rs.getLong(14), getTranslation(translations, id, 0, false), getTranslation(translations, id, 1, true), defaultValue, environment.getProperty(rs.getLong(12)), environment.getACL(rs.getInt(13)), rs.getInt(15), FxSharedUtils.get(propertyAssignmentOptions, rs.getLong(1), null), flatStorageEntries.get(rs.getLong(1))); if (rs.getBoolean(16)) pa._setSystemInternal(); result.add(pa); break; default: LOG.error("Invalid assignment type " + rs.getInt(2) + " for assignment #" + rs.getLong(1)); } } for (FxAssignment as : result) as.resolveDependencies(groupAssignments); } catch (SQLException exc) { throw new FxLoadException(LOG, "Failed to load all FxAssignments: " + exc.getMessage(), exc); } catch (FxNotFoundException e) { throw new FxLoadException(e); } finally { Database.closeObjects(GenericEnvironmentLoader.class, null, stmt); } return result; }
From source file:com.mirth.connect.donkey.test.util.TestUtils.java
public static MessageContent getMessageContent(String channelId, long messageId, int metaDataId, ContentType contentType) {/*www.j av a2 s.c o m*/ long localChannelId = ChannelController.getInstance().getLocalChannelId(channelId); Connection connection = null; ResultSet result = null; PreparedStatement statement = null; try { connection = getConnection(); statement = connection.prepareStatement("SELECT content, data_type, is_encrypted FROM d_mc" + localChannelId + " WHERE message_id = ? AND metadata_id = ? AND content_type = ?"); statement.setLong(1, messageId); statement.setInt(2, metaDataId); statement.setInt(3, contentType.getContentTypeCode()); result = statement.executeQuery(); if (result.next()) { String content = result.getString("content"); String dataType = result.getString("data_type"); boolean encrypted = result.getBoolean("is_encrypted"); return new MessageContent(channelId, messageId, metaDataId, contentType, content, dataType, encrypted); } return null; } catch (SQLException e) { throw new DonkeyDaoException(e); } finally { close(result); close(statement); close(connection); } }
From source file:com.flexive.core.storage.genericSQL.GenericBinarySQLStorage.java
/** * {@inheritDoc}/*from w w w .ja v a 2 s. c o m*/ */ @Override public BinaryDescriptor loadBinaryDescriptor(List<ServerLocation> server, Connection con, long id) throws FxDbException { PreparedStatement ps = null; try { ps = con.prepareStatement(BINARY_DESC_LOAD); ps.setLong(1, id); ps.setInt(2, 1); //ver ps.setInt(3, 1); //ver ResultSet rs = ps.executeQuery(); if (rs != null && rs.next()) { return new BinaryDescriptor(server, id, 1, 1, rs.getLong(3), rs.getString(1), rs.getLong(2), null, rs.getString(4), rs.getBoolean(5), rs.getDouble(6), rs.getInt(7), rs.getInt(8), rs.getString(9)); } } catch (SQLException e) { throw new FxDbException(e, "ex.db.sqlError", e.getMessage()); } finally { Database.closeObjects(GenericBinarySQLStorage.class, ps); } throw new FxDbException("ex.content.binary.loadDescriptor.failed", id); }