Java tutorial
package com.its.web.services; import java.sql.SQLException; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.its.web.db.mappings.LicenseType; import com.its.web.orm.Database; @Service public class LicensesTypesService { private Logger log = Logger.getLogger(this.getClass()); @Autowired Database database; public List<LicenseType> findByName(LicenseType licenseType) { Map<String, Object> fieldValues = new HashMap<String, Object>(); fieldValues.put("name", licenseType.getName()); fieldValues.put("product_id", licenseType.getProductId()); try { return database.getLicenseTypeDao().queryForFieldValues(fieldValues); } catch (SQLException e) { e.printStackTrace(); return null; } } public boolean saveOrUpdate(LicenseType licenseType) { try { if (licenseType.getId() == null) { database.getLicenseTypeDao().create(licenseType); } else { database.getLicenseTypeDao().update(licenseType); } } catch (SQLException e) { e.printStackTrace(); return false; } return true; } public LicenseType getById(Long id) { LicenseType licenseType = null; try { licenseType = database.getLicenseTypeDao().queryForId(id); } catch (SQLException e1) { } return licenseType; } public List<LicenseType> findByProduct(Long productId) { Map<String, Object> fieldValues = new HashMap<String, Object>(); fieldValues.put("product_id", productId); try { return database.getLicenseTypeDao().queryForFieldValues(fieldValues); } catch (SQLException e) { e.printStackTrace(); return null; } } public List<LicenseType> readAll() { try { return database.getLicenseTypeDao().queryForAll(); } catch (SQLException e) { e.printStackTrace(); return null; } } public boolean remove(Long id) { try { database.getLicenseTypeDao().deleteIds(Arrays.asList(id)); return true; } catch (SQLException e) { e.printStackTrace(); return false; } } public List<LicenseType> findFullTypeByProduct(Long productId) { Map<String, Object> fieldValues = new HashMap<String, Object>(); fieldValues.put("product_id", productId); fieldValues.put("type_is_full", true); try { return database.getLicenseTypeDao().queryForFieldValues(fieldValues); } catch (SQLException e) { e.printStackTrace(); return null; } } public List<LicenseType> findTrialTypeByProduct(Long productId) { Map<String, Object> fieldValues = new HashMap<String, Object>(); fieldValues.put("product_id", productId); fieldValues.put("type_is_full", false); try { return database.getLicenseTypeDao().queryForFieldValues(fieldValues); } catch (SQLException e) { e.printStackTrace(); return null; } } }