@Override public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { super.configure(name, params); Object premium = params.get("premium"); _premium = (premium != null) && ((String)premium).equals("true"); return true; }
@Override public boolean removeGuestOsMapping(Long id) { GuestOSHypervisorVO guestOsHypervisor = findById(id); createForUpdate(id); guestOsHypervisor.setRemoved(new Date()); update(id, guestOsHypervisor); return super.remove(id); }
@Override public int remove(SearchCriteria<T> sc) { if (_removeSql == null) { return expunge(sc); } T vo = createForUpdate(); UpdateBuilder ub = getUpdateBuilder(vo); ub.set(vo, _removed.second(), new Date()); return update(ub, sc, null); }
@Override @DB() public List<T> listAllIncludingRemoved(final Filter filter) { final StringBuilder sql = createPartialSelectSql(null, false); addFilter(sql, filter); return executeList(sql.toString()); }
@Override @DB() public int update(final T entity, final SearchCriteria<T> sc) { final UpdateBuilder ub = getUpdateBuilder(entity); return update(ub, sc, null); }
throw new CloudRuntimeException("How can it be illegal access...come on", e); update(id, entity); return entity; index = prepareAttributes(pstmt, entity, attrs, index); insertElementCollection(entity, _idAttributes.get(_table)[0], id, ecAttributes); return _idField != null ? findByIdIncludingRemoved(id) : null;
@Override @DB() public List<T> listAll(final Filter filter) { if (_removed == null) { return listAllIncludingRemoved(filter); } final StringBuilder sql = createPartialSelectSql(null, true); sql.append(_removed.first()); addFilter(sql, filter); return executeList(sql.toString()); }
@Override public <T> T findByUuidIncludingRemoved(Class<T> entityType, String uuid) { // Finds and returns a unique VO using uuid, null if entity not found in db GenericDao<? extends T, String> dao = (GenericDao<? extends T, String>)GenericDaoBase.getDao(entityType); return dao.findByUuidIncludingRemoved(uuid); }
@Override public boolean update(String id, ItWorkVO work) { work.setUpdatedAt(InaccurateClock.getTimeInSeconds()); return super.update(id, work); }
protected void init(final Class<T> entityType, final Class<K> resultType) { _dao = (GenericDaoBase<? extends T, ? extends Serializable>)GenericDaoBase.getDao(entityType); if (_dao == null) { throw new CloudRuntimeException("Unable to find DAO for " + entityType); } _entityBeanType = entityType; _resultType = resultType; _attrs = _dao.getAllAttributes(); _entity = _dao.createSearchEntity(new Interceptor()); _conditions = new ArrayList<Condition>(); _joins = null; _specifiedAttrs = new ArrayList<Attribute>(); } /**
protected int update(ID id, UpdateBuilder ub, T entity) { if (_cache != null) { _cache.remove(id); } SearchCriteria<T> sc = createSearchCriteria(); sc.addAnd(_idAttributes.get(_table)[0], SearchCriteria.Op.EQ, id); TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start(); try { if (ub.getCollectionChanges() != null) { insertElementCollection(entity, _idAttributes.get(_table)[0], id, ub.getCollectionChanges()); } } catch (SQLException e) { throw new CloudRuntimeException("Unable to persist element collection", e); } int rowsUpdated = update(ub, sc, null); txn.commit(); return rowsUpdated; }
@Override @DB() public T findByIdIncludingRemoved(final ID id) { T result = null; if (_cache != null) { final Element element = _cache.get(id); if (element == null) { result = findById(id, true, null); } else { result = (T)element.getObjectValue(); } } else { result = findById(id, true, null); } return result; }
@Override public boolean remove(final ID id) { if (_removeSql == null) { return expunge(id); } final TransactionLegacy txn = TransactionLegacy.currentTxn(); PreparedStatement pstmt = null; try { txn.start(); pstmt = txn.prepareAutoCloseStatement(_removeSql.first()); final Attribute[] attrs = _removeSql.second(); prepareAttribute(1, pstmt, attrs[attrs.length - 1], null); for (int i = 0; i < attrs.length - 1; i++) { prepareAttribute(i + 2, pstmt, attrs[i], id); } final int result = pstmt.executeUpdate(); txn.commit(); if (_cache != null) { _cache.remove(id); } return result > 0; } catch (final SQLException e) { throw new CloudRuntimeException("DB Exception on: " + pstmt, e); } }
@Override public int deleteVM(long instanceId) { SearchCriteria<SecurityGroupVMMapVO> sc = ListByVmId.create(); sc.setParameters("instanceId", instanceId); return super.expunge(sc); }
@Override public <K> List<K> customSearchIncludingRemoved(SearchCriteria<K> sc, final Filter filter) { sc.addAnd(_typeAttr, Op.EQ, Type.Disk); return super.customSearchIncludingRemoved(sc, filter); }
@Override protected List<DiskOfferingVO> executeList(final String sql, final Object... params) { StringBuilder builder = new StringBuilder(sql); int index = builder.indexOf("WHERE"); if (index == -1) { builder.append(" WHERE type=?"); } else { builder.insert(index + 6, "type=? "); } return super.executeList(sql, Type.Disk, params); }
@Override public ServiceOfferingVO findByIdIncludingRemoved(Long vmId, long serviceOfferingId) { ServiceOfferingVO offering = super.findByIdIncludingRemoved(serviceOfferingId); if (offering.isDynamic()) { offering.setDynamicFlag(true); if (vmId == null) { throw new CloudRuntimeException("missing argument vmId"); } Map<String, String> dynamicOffering = userVmDetailsDao.listDetailsKeyPairs(vmId); return getcomputeOffering(offering, dynamicOffering); } return offering; }
sc.setParameters("sortOrder", rolePermission.getSortOrder()); final UpdateBuilder ub = getUpdateBuilder(rolePermission); ub.set(rolePermission, sortOrderAttribute, sortOrder); final int result = update(ub, sc, null);
@DB() public int update(final T entity, final SearchCriteria<T> sc, Integer rows) { final UpdateBuilder ub = getUpdateBuilder(entity); return update(ub, sc, rows); }