@WebMethod public List<Asset> getFasilitasAset(int idAset) throws SQLException { String query = "SELECT * FROM " + FASILITAS_ASET_TABLE + " JOIN " + ASSET_TABLE + " ON " + FASILITAS_ASET_TABLE + ".id_fasilitas=" + ASSET_TABLE + ".id" + " WHERE id_aset = " + idAset; System.out.println(query); ResultSet rs = executeQuery(query); List<Asset> assets = null; while (rs.next()) { if (rs.isFirst()) assets = new ArrayList<Asset>(); Asset asset = new Asset(); asset.setId(rs.getInt("id")); asset.setNama(rs.getString("nama")); asset.setKategori(rs.getString("kategori")); asset.setKategori(rs.getString("jenis")); asset.setTanggalMasuk(rs.getDate("tanggal_masuk")); asset.setKondisi(AssetCondition.getInstance(rs.getString("kondisi"))); asset.setPemilik(rs.getString("pemilik")); asset.setVendor(getVendorAset(rs.getInt("id_vendor"))); asset.setHarga(rs.getString("harga")); asset.setPublicAsset(rs.getBoolean("is_public")); assets.add(asset); } return assets; }
@WebMethod public Response setKondisiAset(int idAset, AssetCondition kondisi) throws SQLException { String query = "UPDATE " + ASSET_TABLE + " " + "SET kondisi='" + kondisi.getCondition() + "' " + "WHERE id=" + idAset; int numRowAffected = executeUpdateQueryAndGetRowCount(query); if (numRowAffected > 0) return new Response(true); else return new Response(false); }
private Asset _getAset(int idAset) throws SQLException { String query = "SELECT * FROM " + ASSET_TABLE + " WHERE id = " + idAset; ResultSet rs = executeQuery(query); Asset asset = null; if (rs.next()) { asset = new Asset(); asset.setId(rs.getInt("id")); asset.setNama(rs.getString("nama")); asset.setKategori(rs.getString("kategori")); asset.setKategori(rs.getString("jenis")); asset.setTanggalMasuk(rs.getDate("tanggal_masuk")); asset.setKondisi(AssetCondition.getInstance(rs.getString("kondisi"))); asset.setPemilik(rs.getString("pemilik")); asset.setVendor(getVendorAset(rs.getInt("id_vendor"))); asset.setHarga(rs.getString("harga")); asset.setPublicAsset(rs.getBoolean("is_public")); } return asset; }
@WebMethod public Response registerAset( String nama, String kategori, String jenis, AssetCondition kondisi, String pemilik, int idVendor, String harga, boolean isPublic) throws SQLException { String query = "INSERT INTO " + ASSET_TABLE + " (nama, kategori, jenis, tanggal_masuk, kondisi, pemilik, id_vendor, harga, is_public) " + "VALUES ('" + nama + "', '" + kategori + "', '" + jenis + "', now(), '" + kondisi.getCondition() + "', '" + pemilik + "', " + idVendor + ", '" + harga + "', " + (isPublic ? "TRUE" : "FALSE") + ")"; int numRowAffected = executeUpdateQueryAndGetId(query); if (numRowAffected > 0) return new Response(true); else return new Response(false); }
@WebMethod public List<Asset> getAsetByJenis(String jenis) throws SQLException { String query = "SELECT * FROM " + ASSET_TABLE + " WHERE jenis= '" + jenis + "'"; ResultSet rs = executeQuery(query); List<Asset> assets = null; while (rs.next()) { if (rs.isFirst()) assets = new ArrayList<Asset>(); Asset asset = new Asset(); asset.setId(rs.getInt("id")); asset.setNama(rs.getString("nama")); asset.setKategori(rs.getString("kategori")); asset.setKategori(rs.getString("jenis")); asset.setTanggalMasuk(rs.getDate("tanggal_masuk")); asset.setKondisi(AssetCondition.getInstance(rs.getString("kondisi"))); asset.setPemilik(rs.getString("pemilik")); asset.setVendor(getVendorAset(rs.getInt("id_vendor"))); asset.setHarga(rs.getString("harga")); asset.setPublicAsset(rs.getBoolean("is_public")); assets.add(asset); } return assets; }