List of usage examples for org.springframework.jdbc.support.rowset SqlRowSet getInt
int getInt(String columnLabel) throws InvalidResultSetAccessException;
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
public List<PhraseUnitInternal> findPhraseUnits(Phrase phrase) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_PHRASE_UNIT + "," + SELECT_PHRASE_SUBUNIT + " FROM ftb_phrase_unit pu" + " LEFT JOIN ftb_phrase_subunit psu ON pu.punit_id = psu.psubunit_punit_id" + " WHERE punit_phrase_id = :phrase_id" + " ORDER BY punit_position, psubunit_position"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("phrase_id", phrase.getId()); LOG.info(sql);//from ww w . java 2 s .c o m TreebankDaoImpl.LogParameters(paramSource); SqlRowSet rowSet = jt.queryForRowSet(sql, paramSource); PhraseUnitMapper phraseUnitMapper = new PhraseUnitMapper(this.treebankServiceInternal); PhraseSubUnitMapper phraseSubUnitMapper = new PhraseSubUnitMapper(this.treebankServiceInternal); List<PhraseUnitInternal> phraseUnits = new ArrayList<PhraseUnitInternal>(); int currentPunitId = 0; PhraseUnitInternal currentPhraseUnit = null; while (rowSet.next()) { int phraseUnitId = rowSet.getInt("punit_id"); if (phraseUnitId != currentPunitId) { currentPhraseUnit = phraseUnitMapper.mapRow(rowSet); currentPhraseUnit.setSubunitsInternal(new ArrayList<PhraseSubunit>()); phraseUnits.add(currentPhraseUnit); currentPunitId = phraseUnitId; } int phraseSubunitId = rowSet.getInt("psubunit_id"); if (phraseSubunitId != 0) { PhraseSubunit psubunit = phraseSubUnitMapper.mapRow(rowSet); currentPhraseUnit.getSubunitsInternal().add(psubunit); } } return phraseUnits; }
From source file:com.emc.ecs.sync.EndToEndTest.java
protected long verifyDbObjects(JdbcTemplate jdbcTemplate, List<TestSyncObject> objects) { Date now = new Date(); long count = 0; for (TestSyncObject object : objects) { count++;// w w w . j a v a 2s . c o m SqlRowSet rowSet = jdbcTemplate.queryForRowSet( "SELECT * FROM " + DbService.DEFAULT_OBJECTS_TABLE_NAME + " WHERE target_id=?", object.getSourceIdentifier()); Assert.assertTrue(rowSet.next()); Assert.assertEquals(object.getSourceIdentifier(), rowSet.getString("target_id")); Assert.assertEquals(object.isDirectory(), rowSet.getBoolean("is_directory")); Assert.assertEquals(object.getMetadata().getContentLength(), rowSet.getLong("size")); // mtime in the DB is actually pulled from the target system, so we don't know what precision it will be in // or if the target system's clock is in sync, but let's assume it will always be within 5 minutes Assert.assertTrue( Math.abs(object.getMetadata().getModificationTime().getTime() - rowSet.getLong("mtime")) < 5 * 60 * 1000); Assert.assertEquals(ObjectStatus.Verified.getValue(), rowSet.getString("status")); Assert.assertTrue(now.getTime() - rowSet.getLong("transfer_start") < 10 * 60 * 1000); // less than 10 minutes ago Assert.assertTrue(now.getTime() - rowSet.getLong("transfer_complete") < 10 * 60 * 1000); // less than 10 minutes ago Assert.assertTrue(now.getTime() - rowSet.getLong("verify_start") < 10 * 60 * 1000); // less than 10 minutes ago Assert.assertTrue(now.getTime() - rowSet.getLong("verify_complete") < 10 * 60 * 1000); // less than 10 minutes ago Assert.assertEquals(object.getFailureCount(), rowSet.getInt("retry_count")); if (object.getFailureCount() > 0) { String error = rowSet.getString("error_message"); Assert.assertNotNull(error); log.warn("{} was retried {} time{}; error: {}", object.getRelativePath(), object.getFailureCount(), object.getFailureCount() > 1 ? "s" : "", error); } if (object.isDirectory()) count += verifyDbObjects(jdbcTemplate, object.getChildren()); } return count; }
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
public List<List<Entity>> findStuff(List<String> tablesToReturn, List<String> tables, List<String> conditions, List<String> orderBy) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); List<String> tableNames = new ArrayList<String>(); List<String> aliases = new ArrayList<String>(); for (String tableToReturn : tablesToReturn) { StringTokenizer st = new StringTokenizer(tableToReturn, " ", false); String tableName = st.nextToken().trim(); st.nextElement(); // skip the word "as" String alias = st.nextToken().trim(); tableNames.add(tableName);/*from w w w . j a v a 2 s . c om*/ aliases.add(alias); } String sql = "SELECT DISTINCT "; boolean firstOne = true; int i = 0; for (String tableName : tableNames) { String alias = aliases.get(i++); List<String> columns = null; if (tableName.equals("ftb_phrase")) columns = DaoUtils.getSelectArray(SELECT_PHRASE, alias); else if (tableName.equals("ftb_phrase_unit")) columns = DaoUtils.getSelectArray(SELECT_PHRASE_UNIT, alias); else if (tableName.equals("ftb_word")) columns = DaoUtils.getSelectArray(SELECT_WORD, alias); else if (tableName.equals("ftb_sentence")) columns = DaoUtils.getSelectArray(SELECT_SENTENCE, alias); else throw new TreebankException("Unsupported table for findStuff: " + tableName); for (String column : columns) { if (firstOne) { sql += column; firstOne = false; } else sql += ", " + column; } } firstOne = true; for (String table : tables) { if (firstOne) { sql += " FROM " + table; firstOne = false; } else sql += ", " + table; } firstOne = true; for (String condition : conditions) { if (firstOne) { sql += " WHERE " + condition; firstOne = false; } else { sql += " AND " + condition; } } if (orderBy.size() > 0) { firstOne = true; for (String column : orderBy) { if (firstOne) { sql += " ORDER BY " + column; firstOne = false; } else { sql += ", " + column; } } } LOG.info(sql); SqlRowSet rowSet = jt.queryForRowSet(sql, paramSource); List<List<Entity>> stuff = new ArrayList<List<Entity>>(); while (rowSet.next()) { List<Entity> oneRow = new ArrayList<Entity>(); i = 0; for (String tableName : tableNames) { String alias = aliases.get(i++); Entity entity = null; if (tableName.equals("ftb_phrase")) { PhraseMapper phraseMapper = new PhraseMapper(alias, this.treebankServiceInternal); Phrase phrase = phraseMapper.mapRow(rowSet); entity = phrase; } else if (tableName.equals("ftb_phrase_unit")) { PhraseUnitMapper phraseUnitMapper = new PhraseUnitMapper(alias, this.treebankServiceInternal); PhraseUnit phraseUnit = phraseUnitMapper.mapRow(rowSet); entity = phraseUnit; } else if (tableName.equals("ftb_word")) { WordMapper wordMapper = new WordMapper(alias, this.treebankServiceInternal); Word word = wordMapper.mapRow(rowSet); entity = word; } oneRow.add(entity); } i = 0; for (String tableName : tableNames) { String alias = aliases.get(i++); if (tableName.equals("ftb_sentence")) { // need to replace the phrase already created with a sentence int sentenceId = rowSet.getInt(alias + "_sentence_id"); PhraseInternal sentencePhrase = null; for (Entity entity : oneRow) { if (entity instanceof PhraseInternal) { if (entity.getId() == sentenceId) { sentencePhrase = (PhraseInternal) entity; break; } } } if (sentencePhrase == null) throw new TreebankException("Cannot return ftb_sentence without associated ftb_phrase"); SentenceMapper sentenceMapper = new SentenceMapper(alias, this.treebankServiceInternal, sentencePhrase); Sentence sentence = sentenceMapper.mapRow(rowSet); oneRow.remove(sentencePhrase); oneRow.add(sentence); } } stuff.add(oneRow); } return stuff; }
From source file:com.ardhi.businessgame.services.BusinessGameService.java
public String buySectorBlueprint(HttpServletRequest req) { String val = "", idInc, sqls[]; double money, price, cost; int level, userLevel; ArrayList<String> sqlL = new ArrayList<String>(); //0=internal error //1=uang ga cukup //2=level belum cukup SqlRowSet srs = db.getJdbc().queryForRowSet( "select money,[level] from businessgame.dbo.[user] where name='" + req.getParameter("user") + "'"); if (srs.next()) { money = srs.getDouble("money"); userLevel = srs.getInt("level"); } else/*from ww w . j ava2 s . c om*/ return "0"; srs = db.getJdbc().queryForRowSet("select [value] from info_values where name='sector'"); if (srs.next()) { price = Double.parseDouble(srs.getString("value")); } else return "0"; srs = db.getJdbc() .queryForRowSet("select [level] from info_sector where name='" + req.getParameter("sector") + "'"); if (srs.next()) level = srs.getInt("level"); else return "0"; srs = db.getJdbc().queryForRowSet( "select sector from user_sector_blueprint where [user]='" + req.getParameter("user") + "'"); ArrayList<String> userSectors = new ArrayList<String>(); while (srs.next()) { userSectors.add(srs.getString("sector")); } price *= userSectors.size(); if (money < price) return "1"; if (userLevel < level) return "2"; money -= price; if (userLevel == level) userLevel = level + 1; idInc = getUniqueIncrementIdNew("user_sector_blueprint"); sqlL.add("insert into user_sector_blueprint values ('" + KEY_USER_SECTOR_BLUEPRINT + idInc + "','" + req.getParameter("user") + "','" + req.getParameter("sector") + "')"); sqlL.add("update businessgame.dbo.[user] set money='" + money + "', [level]='" + userLevel + "' where name='" + req.getParameter("user") + "'"); System.out.println("update businessgame.dbo.[user] set money='" + money + "', [level]='" + userLevel + "' where name='" + req.getParameter("user") + "'"); sqls = new String[sqlL.size()]; sqlL.toArray(sqls); db.getJdbc().batchUpdate(sqls); srs = db.getJdbc() .queryForRowSet("select cost from info_sector where name='" + req.getParameter("sector") + "'"); if (srs.next()) { cost = srs.getDouble("cost"); } else return "0"; ArrayList<String> data = new ArrayList<String>(); data.add(gson.toJson(money)); data.add(KEY_USER_SECTOR_BLUEPRINT + idInc); data.add(gson.toJson(cost)); val = gson.toJson(data); sqlL = null; sqls = null; idInc = null; srs = null; gc(); return val; }
From source file:com.ardhi.businessgame.services.BusinessGameService.java
public String loadHeadquarterData(HttpServletRequest req) { String val = "0", contractType, user, zone; SqlRowSet srs1 = db.getJdbc().queryForRowSet("select name,[level] from info_sector"), srs2, srs3; ArrayList<String> sectors = new ArrayList<String>(); ArrayList<Integer> sectorsLvl = new ArrayList<Integer>(); while (srs1.next()) { sectors.add(srs1.getString("name")); sectorsLvl.add(srs1.getInt("level")); }/* w w w .j av a 2 s . c o m*/ srs1 = db.getJdbc().queryForRowSet("select [value] from info_values where name='sector'"); double price; if (srs1.next()) { price = Double.parseDouble(srs1.getString("value")); } else return "0"; srs1 = db.getJdbc().queryForRowSet( "select user_contract.id,request_storage,supplier_storage,product,quality,size,user_contract.price,turn from user_contract,storage,desc_product where accept='1' and [user]='" + req.getParameter("user") + "' and product_desc=desc_product.id and (request_storage=storage.id or supplier_storage=storage.id)"); ArrayList<Contract> contracts = new ArrayList<Contract>(); while (srs1.next()) { srs2 = db.getJdbc().queryForRowSet("select [user],[zone] from storage where id='" + srs1.getString("request_storage") + "' union select [user],[zone] from storage where id='" + srs1.getString("supplier_storage") + "'"); if (srs2.next()) { if (srs2.getString("user").equals(req.getParameter("user"))) { contractType = "from"; srs2.next(); user = srs2.getString("user"); zone = srs2.getString("zone"); } else { contractType = "to"; user = srs2.getString("user"); zone = srs2.getString("zone"); } contracts .add(new Contract(srs1.getString("id"), user, zone, contractType, srs1.getString("product"), srs1.getInt("quality"), srs1.getDouble("size"), srs1.getDouble("price"))); } else return "0"; } srs1 = db.getJdbc().queryForRowSet( "select user_contract.id,request_storage,supplier_storage,product,quality,size,user_contract.price,turn from user_contract,storage,desc_product where accept='0' and [user]='" + req.getParameter("user") + "' and product_desc=desc_product.id and (request_storage=storage.id or supplier_storage=storage.id)"); ArrayList<Contract> pendingContracts = new ArrayList<Contract>(); while (srs1.next()) { srs2 = db.getJdbc().queryForRowSet("select [user],[zone] from storage where id='" + srs1.getString("request_storage") + "' union select [user],[zone] from storage where id='" + srs1.getString("supplier_storage") + "'"); if (srs2.next()) { if (srs2.getString("user").equals(req.getParameter("user"))) { contractType = "from"; srs2.next(); user = srs2.getString("user"); zone = srs2.getString("zone"); } else { contractType = "to"; user = srs2.getString("user"); zone = srs2.getString("zone"); } pendingContracts .add(new Contract(srs1.getString("id"), user, zone, contractType, srs1.getString("product"), srs1.getInt("quality"), srs1.getDouble("size"), srs1.getDouble("price"))); } else return "0"; } double sales = 0, raw = 0, electricity = 0, fixed = 0, wage = 0, operation = 0, transport = 0, retribution = 0, advertisement = 0, interest = 0, depreciation = 0, tax = 0; srs1 = db.getJdbc().queryForRowSet( "select type,total from user_finance where [user]='" + req.getParameter("user") + "'"); while (srs1.next()) { if (srs1.getString("type").equals("Sales")) sales = srs1.getDouble("total"); else if (srs1.getString("type").equals("Raw Material")) raw = srs1.getDouble("total"); else if (srs1.getString("type").equals("Electricity")) electricity = srs1.getDouble("total"); else if (srs1.getString("type").equals("Fixed")) fixed = srs1.getDouble("total"); else if (srs1.getString("type").equals("Wage")) wage = srs1.getDouble("total"); else if (srs1.getString("type").equals("Operation")) operation = srs1.getDouble("total"); else if (srs1.getString("type").equals("Transport")) transport = srs1.getDouble("total"); else if (srs1.getString("type").equals("Retribution")) retribution = srs1.getDouble("total"); else if (srs1.getString("type").equals("Advertisement")) advertisement = srs1.getDouble("total"); else if (srs1.getString("type").equals("Interest")) interest = srs1.getDouble("total"); else if (srs1.getString("type").equals("Depreciation")) depreciation = srs1.getDouble("total"); } srs1 = db.getJdbc().queryForRowSet("select [value] from info_values where name='tax'"); if (srs1.next()) tax = Double.parseDouble(srs1.getString("value")); else return "0"; double cash, rawOnStorage = 0, equipmentOnStorage = 0, loan = 0, storage = 0, equipment = 0, sector = 0, tmpd1, tmpd2, tmpd3; srs1 = db.getJdbc().queryForRowSet( "select money from businessgame.dbo.[user] where name='" + req.getParameter("user") + "'"); if (srs1.next()) cash = srs1.getDouble("money"); else return "0"; srs1 = db.getJdbc().queryForRowSet( "select [value] from info_values where name='cost_storage' union select [value] from info_values where name='cost_storage_upgrade'"); if (srs1.next()) tmpd1 = Double.parseDouble(srs1.getString("value")); else return "0"; if (srs1.next()) tmpd2 = Double.parseDouble(srs1.getString("value")); else return "0"; srs1 = db.getJdbc() .queryForRowSet("select id,[level] from storage where [user]='" + req.getParameter("user") + "'"); while (srs1.next()) { srs2 = db.getJdbc().queryForRowSet( "select size,avg_price from storage_product where storage='" + srs1.getString("id") + "'"); while (srs2.next()) { rawOnStorage += (srs2.getDouble("size") * srs2.getDouble("avg_price")); } srs2 = db.getJdbc().queryForRowSet( "select buy_price,durability from storage_equipment,list_equipment where storage='" + srs1.getString("id") + "' and storage_equipment.id=list_equipment.id"); while (srs2.next()) { equipmentOnStorage += srs2.getDouble("buy_price") * (srs2.getDouble("durability") / 100.00); } storage += tmpd1; for (int i = 1; i < srs1.getLong("level"); i++) { storage += tmpd2; } } srs1 = db.getJdbc() .queryForRowSet("select borrow from borrow_bank where [user]='" + req.getParameter("user") + "'"); while (srs1.next()) { loan += srs1.getDouble("borrow") * -1; } srs1 = db.getJdbc().queryForRowSet( "select installment.id,info_zone.cost,info_sector.cost from installment,info_zone,info_sector where [user]='" + req.getParameter("user") + "' and info_zone.id=[zone] and info_sector.name=type"); while (srs1.next()) { sector += srs1.getDouble(2) + srs1.getDouble(3); srs2 = db.getJdbc().queryForRowSet( "select buy_price,durability from installment_equipment,list_equipment where installment='" + srs1.getString(1) + "' and installment_equipment.id=list_equipment.id"); while (srs2.next()) { equipment += srs2.getDouble("buy_price") * (srs2.getDouble("durability") / 100.00); } } srs1 = db.getJdbc().queryForRowSet("select name from info_product"); ArrayList<String> products = new ArrayList<String>(); while (srs1.next()) { products.add(srs1.getString("name")); } srs1 = db.getJdbc().queryForRowSet("select id,advertise,price from desc_advertisement"); ArrayList<String> advertises = new ArrayList<String>(), idAds = new ArrayList<String>(); ArrayList<Double> prices = new ArrayList<Double>(); while (srs1.next()) { idAds.add(srs1.getString("id")); advertises.add(srs1.getString("advertise")); prices.add(srs1.getDouble("price")); } srs1 = db.getJdbc().queryForRowSet( "select name from businessgame.dbo.[user] where [zone]=(select [zone] from businessgame.dbo.[user] where name='" + req.getParameter("user") + "')"); ArrayList<String> players = new ArrayList<String>(); ArrayList<Double> assets = new ArrayList<Double>(); while (srs1.next()) { tmpd3 = 0; srs2 = db.getJdbc().queryForRowSet( "select money from businessgame.dbo.[user] where name='" + srs1.getString("name") + "'"); if (srs2.next()) tmpd3 += srs2.getDouble("money"); else return "0"; srs2 = db.getJdbc() .queryForRowSet("select id,[level] from storage where [user]='" + srs1.getString("name") + "'"); while (srs2.next()) { srs3 = db.getJdbc().queryForRowSet( "select size,avg_price from storage_product where storage='" + srs2.getString("id") + "'"); while (srs3.next()) { tmpd3 += (srs3.getDouble("size") * srs3.getDouble("avg_price")); } srs3 = db.getJdbc().queryForRowSet( "select buy_price,durability from storage_equipment,list_equipment where storage='" + srs2.getString("id") + "' and storage_equipment.id=list_equipment.id"); while (srs3.next()) { tmpd3 += srs3.getDouble("buy_price") * (srs3.getDouble("durability") / 100.00); } tmpd3 += tmpd1; for (int i = 1; i < srs2.getLong("level"); i++) { tmpd3 += tmpd2 * i; } } srs2 = db.getJdbc() .queryForRowSet("select borrow from borrow_bank where [user]='" + srs1.getString("name") + "'"); while (srs2.next()) { tmpd3 += srs2.getDouble("borrow") * -1; } srs2 = db.getJdbc().queryForRowSet( "select installment.id,info_zone.cost,info_sector.cost from installment,info_zone,info_sector where [user]='" + srs1.getString("name") + "' and info_zone.id=[zone] and info_sector.name=type"); while (srs2.next()) { tmpd3 += srs2.getDouble(2) + srs2.getDouble(3); srs3 = db.getJdbc().queryForRowSet( "select buy_price,durability from installment_equipment,list_equipment where installment='" + srs2.getString(1) + "' and installment_equipment.id=list_equipment.id"); while (srs3.next()) { tmpd3 += srs3.getDouble("buy_price") * (srs3.getDouble("durability") / 100.00); } } players.add(srs1.getString("name")); assets.add(tmpd3); } for (int i = 0; i < assets.size(); i++) { for (int j = i + 1; j < assets.size(); j++) { if (assets.get(i) < assets.get(j)) { user = players.get(i); tmpd3 = assets.get(i); players.set(i, players.get(j)); assets.set(i, assets.get(j)); players.set(j, user); assets.set(j, tmpd3); } } } ArrayList<String> data = new ArrayList<String>(); data.add(gson.toJson(sectors)); data.add(gson.toJson(sectorsLvl)); data.add(gson.toJson(price)); data.add(gson.toJson(contracts)); data.add(gson.toJson(pendingContracts)); data.add(gson.toJson(sales)); data.add(gson.toJson(raw)); data.add(gson.toJson(electricity)); data.add(gson.toJson(fixed)); data.add(gson.toJson(wage)); data.add(gson.toJson(operation)); data.add(gson.toJson(transport)); data.add(gson.toJson(retribution)); data.add(gson.toJson(advertisement)); data.add(gson.toJson(interest)); data.add(gson.toJson(depreciation)); data.add(gson.toJson(tax)); data.add(gson.toJson(cash)); data.add(gson.toJson(rawOnStorage)); data.add(gson.toJson(equipmentOnStorage)); data.add(gson.toJson(loan)); data.add(gson.toJson(storage)); data.add(gson.toJson(equipment)); data.add(gson.toJson(sector)); data.add(gson.toJson(products)); data.add(gson.toJson(idAds)); data.add(gson.toJson(advertises)); data.add(gson.toJson(prices)); data.add(gson.toJson(players)); val = gson.toJson(data); sectors = null; sectorsLvl = null; contracts = null; pendingContracts = null; data = null; contractType = null; user = null; products = null; advertises = null; prices = null; players = null; assets = null; zone = null; srs1 = null; srs2 = null; gc(); return val; }
From source file:com.ardhi.businessgame.services.BusinessGameService.java
public String loadInstallmentDetails(HttpServletRequest req) { String val = "0"; ArrayList<InstallmentEmployee> employees = new ArrayList<InstallmentEmployee>(); ArrayList<InstallmentEquipment> equipments = new ArrayList<InstallmentEquipment>(); ArrayList<String> data = new ArrayList<String>(); SqlRowSet srs1 = db.getJdbc().queryForRowSet( "select installment_employee.id,employee,quality,operational,draw from installment_employee,list_employee,desc_employee,info_employee where installment='" + req.getParameter("id") + "' and installment_employee.id=list_employee.id and list_employee.[desc]=desc_employee.id and name=employee"), srs2;//from w ww . j a v a 2s . c o m while (srs1.next()) { employees.add(new InstallmentEmployee(srs1.getString("id"), srs1.getString("employee"), srs1.getInt("quality"), srs1.getDouble("operational"), srs1.getString("draw"))); } srs1 = db.getJdbc().queryForRowSet( "select installment_equipment.id,equipment,quality,durability,size,operational,draw from installment_equipment,desc_equipment,list_equipment,info_equipment where installment='" + req.getParameter("id") + "' and installment_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id and name=equipment"); while (srs1.next()) { equipments.add(new InstallmentEquipment(srs1.getString("id"), srs1.getString("equipment"), srs1.getInt("quality"), srs1.getDouble("durability"), srs1.getDouble("size"), srs1.getDouble("operational"), srs1.getString("draw"))); } ArrayList<String> installmentIOdata = calculateInstallmentAndIOByIdInstallment(req.getParameter("id")); data.add(installmentIOdata.get(0)); data.add(installmentIOdata.get(1)); data.add(installmentIOdata.get(2)); data.add(installmentIOdata.get(3)); data.add(installmentIOdata.get(4)); data.add(installmentIOdata.get(5)); data.add(installmentIOdata.get(6)); data.add(installmentIOdata.get(7)); data.add(gson.toJson(equipments)); data.add(gson.toJson(employees)); if (installmentIOdata.get(0).equals("Petrol Power Plant")) { srs1 = db.getJdbc().queryForRowSet( "select subscription,tariff from installment where id='" + req.getParameter("id") + "'"); double tariff, subscription; if (srs1.next()) { subscription = srs1.getDouble("subscription"); tariff = srs1.getDouble("tariff"); } else return "0"; srs1 = db.getJdbc() .queryForRowSet("select id,type,[user],planned_supply from installment where supply='" + req.getParameter("id") + "'"); ArrayList<String> types = new ArrayList<String>(), users = new ArrayList<String>(), idSupplies = new ArrayList<String>(); ArrayList<Double> supplies = new ArrayList<Double>(); while (srs1.next()) { idSupplies.add(srs1.getString("id")); types.add(srs1.getString("type")); users.add(srs1.getString("user")); supplies.add(srs1.getDouble("planned_supply")); } data.add(gson.toJson(subscription)); data.add(gson.toJson(tariff)); data.add(gson.toJson(types)); data.add(gson.toJson(users)); data.add(gson.toJson(supplies)); data.add(gson.toJson(idSupplies)); val = gson.toJson(data); types = null; users = null; supplies = null; idSupplies = null; } else { srs1 = db.getJdbc().queryForRowSet( "select supply,planned_supply from installment where id='" + req.getParameter("id") + "'"); ArrayList<String> idSupplies = new ArrayList<String>(), users = new ArrayList<String>(), tmpSupplies; ArrayList<Double> subscriptions = new ArrayList<Double>(), tariffs = new ArrayList<Double>(), availables = new ArrayList<Double>(); JsonParser parser = new JsonParser(); JsonArray array1; int tmp; double available, currentKwh; String currentSupply; if (srs1.next()) { currentKwh = srs1.getDouble("planned_supply"); currentSupply = srs1.getString("supply"); } else return "0"; srs1 = db.getJdbc().queryForRowSet( "select id,[user],subscription,tariff from installment where type='Petrol Power Plant'"); while (srs1.next()) { tmp = 0; tmpSupplies = calculateInstallmentAndIOByIdInstallment(srs1.getString("id")); array1 = parser.parse(tmpSupplies.get(5)).getAsJsonArray(); for (int i = 0; i < array1.size(); i++) { if ((new Gson().fromJson(array1.get(i), String.class)).equals("Energy")) { tmp = i; break; } } array1 = parser.parse(tmpSupplies.get(6)).getAsJsonArray(); available = new Gson().fromJson(array1.get(tmp), Double.class); srs2 = db.getJdbc().queryForRowSet( "select planned_supply from installment where supply='" + srs1.getString("id") + "'"); while (srs2.next()) available -= srs2.getDouble("planned_supply"); idSupplies.add(srs1.getString("id")); users.add(srs1.getString("user")); subscriptions.add(srs1.getDouble("subscription")); tariffs.add(srs1.getDouble("tariff")); availables.add(new BigDecimal(Double.valueOf(available)).setScale(2, BigDecimal.ROUND_HALF_EVEN) .doubleValue()); tmpSupplies = null; } data.add(gson.toJson(idSupplies)); data.add(gson.toJson(users)); data.add(gson.toJson(subscriptions)); data.add(gson.toJson(tariffs)); data.add(gson.toJson(availables)); data.add(gson.toJson(currentKwh)); data.add(gson.toJson(currentSupply)); val = gson.toJson(data); idSupplies = null; users = null; tariffs = null; availables = null; currentSupply = null; } installmentIOdata = null; employees = null; equipments = null; data = null; srs1 = null; srs2 = null; gc(); return val; }
From source file:com.ardhi.businessgame.services.BusinessGameService.java
public String checkUserStorage(HttpServletRequest req) { String val = "No", id = ""; boolean isAvailable; SqlRowSet srs1, srs2; double tmp = 0; ArrayList<String> data = new ArrayList<String>(); srs1 = db.getJdbc()//from w ww . j a v a 2s . co m .queryForRowSet("select [level] from storage where id='" + req.getParameter("storage") + "'"); isAvailable = srs1.next(); if (isAvailable) { id = req.getParameter("storage"); } else { srs1 = db.getJdbc().queryForRowSet("select id,[level] from storage where [user]='" + req.getParameter("user") + "' and [zone]='" + req.getParameter("zone") + "'"); isAvailable = srs1.next(); if (isAvailable) id = srs1.getString("id"); } if (isAvailable) { int level = srs1.getInt("level") - 1; double capacity = 0, fill = 0, upgrade = 0, inc = 0; srs1 = db.getJdbc().queryForRowSet( "select [value] from info_values where name='storage' union select [value] from info_values where name='storage_inc' union select [value] from info_values where name='cost_storage_upgrade'"); if (srs1.next()) { capacity = Double.parseDouble(srs1.getString("value")); } else return "0"; if (srs1.next()) { capacity += level * Double.parseDouble(srs1.getString("value")); inc = Double.parseDouble(srs1.getString("value")); } else return "0"; if (srs1.next()) { upgrade = Double.parseDouble(srs1.getString("value")); } else return "0"; srs1 = db.getJdbc().queryForRowSet( "select storage_product.id,product,quality,size,draw from storage_product,desc_product,info_product where storage='" + id + "' and desc_product.id=storage_product.[desc] and product=name"); ArrayList<StorageProduct> storageProducts = new ArrayList<StorageProduct>(); ArrayList<MarketProduct> marketProducts = new ArrayList<MarketProduct>(); while (srs1.next()) { tmp = srs1.getDouble("size"); srs2 = db.getJdbc().queryForRowSet( "select market_product.id,product,market_product.price,quality,market_product.size,draw from market_product,desc_product,info_product,storage_product where storage_product_id='" + srs1.getString("id") + "' and storage_product_id=storage_product.id and desc_product.id=storage_product.[desc] and product=name"); while (srs2.next()) { tmp -= srs2.getDouble("size"); marketProducts.add(new MarketProduct(srs2.getString("id"), "", srs2.getString("product"), srs2.getDouble("price"), srs2.getInt("quality"), srs2.getDouble("size"), srs2.getString("draw"))); } if (tmp > 0) storageProducts.add(new StorageProduct(srs1.getString("id"), srs1.getString("product"), srs1.getInt("quality"), new BigDecimal(Double.valueOf(tmp)) .setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(), srs1.getString("draw"))); fill += srs1.getDouble("size"); } srs1 = db.getJdbc().queryForRowSet( "select storage_equipment.id,equipment,quality,durability,size,operational,draw from storage_equipment,list_equipment,desc_equipment,info_equipment where storage='" + id + "' and storage_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id and name=equipment"); ArrayList<StorageEquipment> storageEquipments = new ArrayList<StorageEquipment>(); ArrayList<MarketEquipment> marketEquipments = new ArrayList<MarketEquipment>(); while (srs1.next()) { srs2 = db.getJdbc().queryForRowSet( "select market_equipment.id,equipment,market_equipment.price,quality,durability,size,operational,draw from storage_equipment,market_equipment,desc_equipment,list_equipment,info_equipment where storage_equipment_id='" + srs1.getString("id") + "' and storage_equipment.id=storage_equipment_id and list_equipment.id=storage_equipment.id and list_equipment.[desc]=desc_equipment.id and equipment=name"); if (srs2.next()) { marketEquipments.add(new MarketEquipment(srs2.getString("id"), "", srs2.getString("equipment"), srs2.getDouble("price"), srs2.getInt("quality"), srs2.getDouble("durability"), srs2.getDouble("size"), srs2.getDouble("operational"), srs2.getString("draw"))); } else { storageEquipments.add(new StorageEquipment(srs1.getString("id"), srs1.getString("equipment"), srs1.getInt("quality"), srs1.getDouble("durability"), srs1.getDouble("size"), srs1.getDouble("operational"), srs1.getString("draw"))); } fill += srs1.getDouble("size"); } data.add(gson.toJson(isAvailable)); data.add(gson.toJson(capacity)); data.add(gson.toJson(fill)); data.add(gson.toJson(upgrade)); data.add(gson.toJson(inc)); data.add(gson.toJson(level + 1)); data.add(gson.toJson(storageProducts)); data.add(gson.toJson(storageEquipments)); data.add(gson.toJson(marketProducts)); data.add(gson.toJson(marketEquipments)); val = gson.toJson(data); storageProducts = null; storageEquipments = null; marketProducts = null; marketEquipments = null; } else { srs2 = db.getJdbc().queryForRowSet("select [value] from info_values where name='cost_storage'"); if (srs2.next()) { data.add(gson.toJson(isAvailable)); data.add(gson.toJson(Double.parseDouble(srs2.getString("value")))); val = gson.toJson(data); } else return "0"; } data = null; srs1 = null; srs2 = null; gc(); return val; }
From source file:com.ardhi.businessgame.services.BusinessGameService.java
public String attachEquipmentToInstallment(HttpServletRequest req) { String val = "0", sqls[]; ArrayList<String> sqlL = new ArrayList<String>(); sqlL.add("insert into installment_equipment values ('" + req.getParameter("idEquipment") + "','" + req.getParameter("idInstallment") + "')"); sqlL.add("delete from storage_equipment where id='" + req.getParameter("idEquipment") + "'"); sqls = new String[sqlL.size()]; sqlL.toArray(sqls);//www. ja v a 2 s .c o m db.getJdbc().batchUpdate(sqls); SqlRowSet srs1, srs2; srs1 = db.getJdbc().queryForRowSet( "select storage_equipment.id,equipment,quality,durability,size,operational,draw from storage_equipment,list_equipment,desc_equipment,info_equipment where storage='" + req.getParameter("storage") + "' and storage_equipment.id=list_equipment.id and list_equipment.[desc]=desc_equipment.id and name=equipment"); ArrayList<StorageEquipment> equipments = new ArrayList<StorageEquipment>(); while (srs1.next()) { srs2 = db.getJdbc().queryForRowSet( "select id from market_equipment where storage_equipment_id='" + srs1.getString("id") + "'"); if (!srs2.next()) equipments.add(new StorageEquipment(srs1.getString("id"), srs1.getString("equipment"), srs1.getInt("quality"), srs1.getDouble("durability"), srs1.getDouble("size"), srs1.getDouble("operational"), srs1.getString("draw"))); } Installment installment = getSingleUserInstallments(req.getParameter("idInstallment")); ArrayList<String> data = new ArrayList<String>(); data.add(gson.toJson(equipments)); data.add(gson.toJson(installment)); val = gson.toJson(data); sqlL = null; equipments = null; srs1 = null; srs2 = null; sqls = null; installment = null; data = null; gc(); return val; }
From source file:com.ardhi.businessgame.services.BusinessGameService.java
public String cancelRejectContract(HttpServletRequest req) { String val = "0"; SqlRowSet srs1 = db.getJdbc() .queryForRowSet("select request_storage,supplier_storage,turn from user_contract where id='" + req.getParameter("id") + "' and accept='1'"), srs2, srs3;/*from www .j a v a 2 s . co m*/ if (srs1.next()) { srs2 = db.getJdbc().queryForRowSet("select [user],[zone] from storage where id='" + srs1.getString("request_storage") + "' union select [user],[zone] from storage where id='" + srs1.getString("supplier_storage") + "'"); if (srs2.next()) { if (!srs2.getString("user").equals(req.getParameter("user"))) { srs3 = db.getJdbc().queryForRowSet("select rep from businessgame.dbo.[user] where name='" + req.getParameter("user") + "'"); db.getJdbc() .execute("update businessgame.dbo.[user] set rep='" + (srs3.getLong("rep") - (srs1.getInt("turn") * 5)) + "' where name='" + req.getParameter("user") + "'"); } } else return "0"; } db.getJdbc().execute("delete from user_contract where id='" + req.getParameter("id") + "'"); val = "Ok"; srs1 = null; srs2 = null; srs3 = null; gc(); return val; }
From source file:com.ardhi.businessgame.services.BusinessGameService.java
public String loadMarketContent(HttpServletRequest req) { String val = "0"; SqlRowSet srs; // srs = db.getJdbc().queryForRowSet("select market_product.id,storage.[user],product,market_product.price,quality,market_product.size,draw from market_product,storage_product,desc_product,storage,info_product where market_product.[zone]='"+req.getParameter("zone")+"' and storage_product.id=storage_product_id and desc_product.id=storage_product.[desc] and storage.id=storage_product.storage and product=name union select market_product.id,'',product,market_product.price,quality,market_product.size,draw from market_product,desc_product,info_product where market_product.[zone]='"+req.getParameter("zone")+"' and desc_product.id=market_product.[desc] and product=name"); srs = db.getJdbc().queryForRowSet(//from www . j a v a 2 s . c om "select market_product.id,storage.[user],product,market_product.price,quality,market_product.size,draw from market_product,storage_product,desc_product,storage,info_product where market_product.[zone]='" + req.getParameter("zone") + "' and storage_product.id=storage_product_id and desc_product.id=storage_product.[desc] and storage.id=storage_product.storage and product=name"); ArrayList<MarketProduct> products = new ArrayList<MarketProduct>(); while (srs.next()) { products.add(new MarketProduct(srs.getString("id"), srs.getString("user"), srs.getString("product"), srs.getDouble("price"), srs.getInt("quality"), srs.getDouble("size"), srs.getString("draw"))); } // srs = db.getJdbc().queryForRowSet("select market_equipment.id,storage.[user],equipment,market_equipment.price,quality,durability,size,operational,draw from market_equipment,storage_equipment,desc_equipment,list_equipment,storage,info_equipment where market_equipment.[zone]='"+req.getParameter("zone")+"' and storage_equipment.id=storage_equipment_id and list_equipment.id=storage_equipment.id and list_equipment.[desc]=desc_equipment.id and storage.id=storage_equipment.storage and equipment=name union select market_equipment.id,'',equipment,market_equipment.price,quality,durability,size,operational,draw from market_equipment,desc_equipment,list_equipment,info_equipment where market_equipment.[zone]='"+req.getParameter("zone")+"' and list_equipment.id=market_equipment.[desc] and list_equipment.[desc]=desc_equipment.id and equipment=name"); srs = db.getJdbc().queryForRowSet( "select market_equipment.id,storage.[user],equipment,market_equipment.price,quality,durability,size,operational,draw from market_equipment,storage_equipment,desc_equipment,list_equipment,storage,info_equipment where market_equipment.[zone]='" + req.getParameter("zone") + "' and storage_equipment.id=storage_equipment_id and list_equipment.id=storage_equipment.id and list_equipment.[desc]=desc_equipment.id and storage.id=storage_equipment.storage and equipment=name"); ArrayList<MarketEquipment> equipments = new ArrayList<MarketEquipment>(); while (srs.next()) { equipments .add(new MarketEquipment(srs.getString("id"), srs.getString("user"), srs.getString("equipment"), srs.getDouble("price"), srs.getInt("quality"), srs.getDouble("durability"), srs.getDouble("size"), srs.getDouble("operational"), srs.getString("draw"))); } srs = db.getJdbc().queryForRowSet( "select market_employee.id,employee,market_employee.price,quality,operational,draw from market_employee,desc_employee,list_employee,info_employee where [zone]='" + req.getParameter("zone") + "' and list_employee.id=market_employee.[desc] and desc_employee.id=list_employee.[desc] and name=employee"); ArrayList<MarketEmployee> employees = new ArrayList<MarketEmployee>(); while (srs.next()) { employees.add(new MarketEmployee(srs.getString("id"), srs.getString("employee"), srs.getDouble("price"), srs.getInt("quality"), srs.getDouble("operational"), srs.getString("draw"))); } ArrayList<String> data = new ArrayList<String>(); data.add(gson.toJson(products)); data.add(gson.toJson(equipments)); data.add(gson.toJson(employees)); val = gson.toJson(data); products = null; equipments = null; employees = null; data = null; srs = null; gc(); return val; }