| | |
| | | |
| | | public List<Map<String, Object>> search(String runAsUser, String ticket, |
| | | Map<String, String> whereParams) throws HSAdminException { |
| | | String user = runAsUser; |
| | | Transaction transaction = new Transaction(user); |
| | | final String user = runAsUser; |
| | | final Transaction transaction = new Transaction(user); |
| | | try { |
| | | if (transaction.login(user, ticket)) { |
| | | ModuleInterface module = new GenericModuleImpl(transaction); |
| | | UnixUser unixUser = transaction.getLoginUser(); |
| | | List<AbstractEntity> list = module.search(getEntityClass(), |
| | | final ModuleInterface module = new GenericModuleImpl(transaction); |
| | | final UnixUser unixUser = transaction.getLoginUser(); |
| | | final List<AbstractEntity> list = module.search(getEntityClass(), |
| | | buildQueryCondition(whereParams), null); |
| | | if (list == null) { |
| | | throw new HSAdminException("result list is null, runtime-error?"); |
| | | } |
| | | ArrayList<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); |
| | | final ArrayList<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); |
| | | for (AbstractEntity e : list) { |
| | | HashMap<String, Object> entry = new HashMap<String, Object>(); |
| | | final HashMap<String, Object> entry = new HashMap<String, Object>(); |
| | | entity2map(transaction, e, entry); |
| | | if (e.isReadAllowedFor(unixUser)) { |
| | | result.add(entry); |
| | |
| | | |
| | | public Map<String, Object> add(String runAsUser, String ticket, |
| | | Map<String, Object> setParams) throws HSAdminException { |
| | | String user = runAsUser; |
| | | Transaction transaction = new Transaction(user); |
| | | final String user = runAsUser; |
| | | final Transaction transaction = new Transaction(user); |
| | | try { |
| | | if (transaction.login(user, ticket)) { |
| | | ModuleInterface module = new GenericModuleImpl(transaction); |
| | | Constructor<? extends AbstractEntity> constructor = |
| | | final ModuleInterface module = new GenericModuleImpl(transaction); |
| | | final Constructor<? extends AbstractEntity> constructor = |
| | | getEntityClass().getConstructor(); |
| | | AbstractEntity entity = constructor.newInstance(); |
| | | final AbstractEntity entity = constructor.newInstance(); |
| | | module.initialize(entity); |
| | | map2entity(transaction, setParams, entity); |
| | | transaction.beginTransaction(); |
| | | AbstractEntity insertedEntity = module.add(entity); |
| | | final AbstractEntity insertedEntity = module.add(entity); |
| | | transaction.commitTransaction(); |
| | | HashMap<String, Object> entry = new HashMap<String, Object>(); |
| | | final HashMap<String, Object> entry = new HashMap<String, Object>(); |
| | | entity2map(transaction, insertedEntity, entry); |
| | | return entry; |
| | | } else { |
| | |
| | | |
| | | public void delete(String runAsUser, String ticket, |
| | | Map<String, String> whereParams) throws HSAdminException { |
| | | String user = runAsUser; |
| | | Transaction transaction = new Transaction(user); |
| | | final String user = runAsUser; |
| | | final Transaction transaction = new Transaction(user); |
| | | try { |
| | | if (transaction.login(user, ticket)) { |
| | | ModuleInterface module = new GenericModuleImpl(transaction); |
| | | UnixUser unixUser = transaction.getLoginUser(); |
| | | String queryCondition = buildQueryCondition(whereParams); |
| | | final ModuleInterface module = new GenericModuleImpl(transaction); |
| | | final UnixUser unixUser = transaction.getLoginUser(); |
| | | final String queryCondition = buildQueryCondition(whereParams); |
| | | if (queryCondition == null || queryCondition.length() == 0) { |
| | | throw new HSAdminException( |
| | | "better safe than sorry: no where parameter found"); |
| | | } |
| | | List<AbstractEntity> list = module.search(getEntityClass(), |
| | | final List<AbstractEntity> list = module.search(getEntityClass(), |
| | | queryCondition, null); |
| | | transaction.beginTransaction(); |
| | | for (AbstractEntity e : list) { |
| | |
| | | public List<Map<String, Object>> update(String runAsUser, String ticket, |
| | | Map<String, Object> setParams, Map<String, String> whereParams) |
| | | throws HSAdminException { |
| | | String user = runAsUser; |
| | | Transaction transaction = new Transaction(user); |
| | | final String user = runAsUser; |
| | | final Transaction transaction = new Transaction(user); |
| | | try { |
| | | if (transaction.login(user, ticket)) { |
| | | ModuleInterface module = new GenericModuleImpl(transaction); |
| | | UnixUser unixUser = transaction.getLoginUser(); |
| | | ArrayList<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); |
| | | String queryCondition = buildQueryCondition(whereParams); |
| | | final ModuleInterface module = new GenericModuleImpl(transaction); |
| | | final UnixUser unixUser = transaction.getLoginUser(); |
| | | final ArrayList<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); |
| | | final String queryCondition = buildQueryCondition(whereParams); |
| | | if (queryCondition == null || queryCondition.length() == 0) { |
| | | throw new HSAdminException( |
| | | "better safe than sorry: no where parameter found"); |
| | | } |
| | | List<AbstractEntity> list = module.search(getEntityClass(), |
| | | final List<AbstractEntity> list = module.search(getEntityClass(), |
| | | queryCondition, getOrderBy()); |
| | | transaction.beginTransaction(); |
| | | for (AbstractEntity update : list) { |
| | |
| | | transaction.detach(update); |
| | | map2entity(transaction, setParams, update); |
| | | update = module.update(update); |
| | | HashMap<String, Object> entry = new HashMap<String, Object>(); |
| | | final HashMap<String, Object> entry = new HashMap<String, Object>(); |
| | | entity2map(transaction, update, entry); |
| | | result.add(entry); |
| | | } else { |
| | |
| | | |
| | | protected void replaceKey(Map<String, String> whereParams, String shortKey, String regularKey) { |
| | | if (whereParams.containsKey(shortKey)) { |
| | | String value = whereParams.get(shortKey); |
| | | final String value = whereParams.get(shortKey); |
| | | whereParams.remove(shortKey); |
| | | whereParams.put(regularKey, value); |
| | | } |
| | |
| | | |
| | | private String buildQueryCondition(Map<String, String> whereParams) { |
| | | regularizeKeys(whereParams); |
| | | StringBuffer cond = new StringBuffer(); |
| | | Iterator<String> keyIterator = whereParams.keySet().iterator(); |
| | | final StringBuffer cond = new StringBuffer(); |
| | | final Iterator<String> keyIterator = whereParams.keySet().iterator(); |
| | | while (keyIterator.hasNext()) { |
| | | if (cond.length() > 0) { |
| | | cond.append(" AND "); |
| | | } |
| | | String field = keyIterator.next(); |
| | | String value = whereParams.get(field).replaceAll("'", "\'"); |
| | | final String field = keyIterator.next(); |
| | | final String value = whereParams.get(field).replaceAll("'", "\'"); |
| | | cond.append("obj."); |
| | | cond.append(field); |
| | | cond.append(" = "); |
| | | boolean numeric = "id".equals(field); |
| | | final boolean numeric = "id".equals(field); |
| | | if (!numeric) cond.append("'"); |
| | | cond.append(value); |
| | | if (!numeric) cond.append("'"); |