@Override public Collection<String> getKeys(final String entityName, final long entityId) { return getKeys(FieldMap.build( ENTITY_NAME, entityName, ENTITY_ID, entityId)); }
@EventListener @SuppressWarnings("UnusedParameters") public void onClearCache(ClearCacheEvent event) { refreshAll(); }
/** * Selects the entry from the list with the maximum value for ID, removing the all other entries and their values. * Assumptions: {@code list} is non-null and contains at least two valid entries. * * @param list the list to be scanned * @return the entry with the maximum value. * @throws GenericEntityException if {@link #removeEntryAndValue(GenericValue)} does */ private GenericValue selectMaximumIdAndRemoveOthers(@Nonnull List<GenericValue> list) throws GenericEntityException { final GenericValue winner = selectMaximumId(list); for (GenericValue other : list) { // The reference to "winner" was selected from this list, so "!=" is sane //noinspection ObjectEquality if (other != winner) { removeEntryAndValue(other); } } return winner; }
@Override public void removeEntry(String entityName, long entityId, String propertyKey) { final EntityCondition condition = new EntityFieldMap(FieldMap.build( ENTITY_NAME, entityName, ENTITY_ID, entityId, PROPERTY_KEY, propertyKey), AND); try { final List<GenericValue> list = genericDelegator.findByCondition(PROPERTY_ENTRY, condition, SELECT_ID_AND_TYPE, null); if (list != null) { for (GenericValue entry : list) { removeEntryAndValue(entry); } } } catch (GenericEntityException gee) { throw new PropertyImplementationException(gee); } finally { // remove cache entry regardless of whether or not we actually find anything invalidateCacheEntry(entityName, entityId, propertyKey); } }
private GenericValue makeUpdatedEntry(CacheKey cacheKey, Integer type) throws GenericEntityException { final FieldMap fieldMap = cacheKey.toFieldMap(); final List<GenericValue> list = genericDelegator.findByAnd(PROPERTY_ENTRY, fieldMap); if (list == null || list.isEmpty()) { final Long id = genericDelegator.getNextSeqId(PROPERTY_ENTRY); return genericDelegator.makeValue(PROPERTY_ENTRY, fieldMap .add(ID, id) .add(TYPE, type)); } final GenericValue existingPropertyEntry = (list.size() == 1) ? list.get(0) : selectMaximumIdAndRemoveOthers(list); removeOrphanedValueIfTypeChanged(type, existingPropertyEntry); return existingPropertyEntry; }
public static void flushUserCaches() { LicenseCountService licenseCountService = ComponentAccessor.getComponent(LicenseCountService.class); if (licenseCountService != null) { licenseCountService.flush(); EventPublisher eventPublisher = ComponentAccessor.getComponent(EventPublisher.class); if (eventPublisher != null) { eventPublisher.publish(new XMLRestoreFinishedEvent(licenseCountService)); } } else { log.warn("Could not find a LicenseCountService - user count data will be incorrect for up to 2 hours."); } OfBizPropertyEntryStore store = ComponentAccessor.getComponent(OfBizPropertyEntryStore.class); if (store instanceof CachingOfBizPropertyEntryStore) { ((CachingOfBizPropertyEntryStore)store).onClearCache(null); } else { final String name = (store != null) ? store.getClass().getName() : "null"; log.error("Expected to find a CachingOfBizPropertyEntryStore, but got " + name); } }
private void removeEntryAndValue(GenericValue entry) throws GenericEntityException { removeEntryAndValue(entry.getLong(ID), entry.getInteger(TYPE)); }
@Override public void setEntry(final String entityName, final long entityId, final String propertyKey, final int type, final Object value) { final CacheKey cacheKey = new CacheKey(entityName, entityId, propertyKey); try { setEntryImpl(cacheKey, type, value); } catch (GenericEntityException gee) { throw new PropertyImplementationException(gee); } finally { // remove cache entry regardless of whether or not we succeed entries.remove(cacheKey); } }
private void setEntryImpl(CacheKey cacheKey, Integer type, Object unmappedValue) throws GenericEntityException { final GenericValue propertyEntry = makeUpdatedEntry(cacheKey, type); final TypeMapper mapper = mapper(type); final Object mappedValue = (unmappedValue != null) ? mapper.getHandler().processSet(type, unmappedValue) : null; final GenericValue propertyTypeEntry = genericDelegator.makeValue(mapper.getEntityName(), FieldMap.build( ID, propertyEntry.getLong(ID), VALUE, mappedValue)); genericDelegator.storeAll(asList(propertyEntry, propertyTypeEntry)); }
removeEntryAndValue(entry); invalidateCacheEntry(entityName, entityId, entry.getString(PROPERTY_KEY));
if (store instanceof CachingOfBizPropertyEntryStore) ((CachingOfBizPropertyEntryStore)store).onClearCache(null);
@Override public void doUpgrade(final boolean setupMode) throws Exception { dbConnectionManager.execute(dbConnection -> { dbConnection.setAutoCommit(false); List<Long> propertyIds = getMinusOneUserLocalePropertyIds(dbConnection); if (!propertyIds.isEmpty()) { LOG.debug("Removing {} user locale preferences with value -1", propertyIds.size()); List<List<Long>> batches = Lists.partition(propertyIds, MAX_ROWS_IN_BATCH); for (int i = 0; i < batches.size(); i++) { LOG.debug("Deleting batch {} of {}", i + 1, batches.size()); deleteMinusOneUserLocaleProperty(batches.get(i), dbConnection); } } dbConnection.commit(); }); OfBizPropertyEntryStore entryStore = ComponentAccessor.getComponent(OfBizPropertyEntryStore.class); if (entryStore instanceof CachingOfBizPropertyEntryStore) { ((CachingOfBizPropertyEntryStore)entryStore).refreshAll(); } }
@Override public Collection<String> getKeys(final String entityName, final long entityId, final int type) { return getKeys(FieldMap.build( ENTITY_NAME, entityName, ENTITY_ID, entityId, TYPE, type)); }
void globalRefresh(boolean quickImport) { if (quickImport) { log.warn("QuickImport is on, doing a fast refresh."); final PluginPersistentStateStore pluginPersistentStateStore = ComponentAccessor.getComponentOfType(PluginPersistentStateStore.class); // We need to keep track of which plugins were disabled in the old instance of JIRA, before we clear the cache final PluginPersistentState oldState = pluginPersistentStateStore.load(); // Lets be tricky and clear the CachingOfBizPropertyEntryStore first since so much depends on these // through ApplicationProperties(that internally use it to cache its entries) and since caches // depend on it (e.g. DefaultServiceManager) (LEGO-866) ComponentAccessor.getComponentOfType(CachingOfBizPropertyEntryStore.class).refreshAll(); // Clear the state out of JIRA ComponentAccessor.getComponentOfType(EventPublisher.class).publish(ClearCacheEvent.INSTANCE); // We need to call enable/disable on the plugins which states have changed because of the newly imported data syncPluginStateWithNewData(pluginPersistentStateStore, oldState); } else { ManagerFactory.globalRefresh(); } }