Lines 43-48
Link Here
|
43 |
|
43 |
|
44 |
import java.util.ArrayList; |
44 |
import java.util.ArrayList; |
45 |
import java.util.Collection; |
45 |
import java.util.Collection; |
|
|
46 |
import java.util.Collections; |
46 |
import java.util.HashMap; |
47 |
import java.util.HashMap; |
47 |
import java.util.List; |
48 |
import java.util.List; |
48 |
import java.util.Map; |
49 |
import java.util.Map; |
Lines 137-152
Link Here
|
137 |
} |
138 |
} |
138 |
|
139 |
|
139 |
/** |
140 |
/** |
140 |
* Returns existing or new instance of DataStorage |
141 |
* Returns existing or new instance of DataStorage |
141 |
* for requested schema (if it can be found within all available DataStorages) |
142 |
* for requested schema (if it can be found within all available DataStorages) |
|
|
143 |
* |
144 |
* If collector requires several storages and infrastructure cannot provide |
145 |
* *all* of them, then an empty list is returned. |
146 |
* So this method guarantees to return either fully loaded map or nothing. |
147 |
* |
142 |
*/ |
148 |
*/ |
143 |
public synchronized Map<DataStorageType, DataStorage> getDataStoragesFor(DLightSession session, DataCollector<?> collector) { |
149 |
public synchronized Map<DataStorageType, DataStorage> getDataStoragesFor(DLightSession session, DataCollector<?> collector) { |
|
|
150 |
if (session == null || collector == null) { |
151 |
return Collections.<DataStorageType, DataStorage>emptyMap(); |
152 |
} |
153 |
|
144 |
Map<DataStorageType, DataStorage> result = new HashMap<DataStorageType, DataStorage>(); |
154 |
Map<DataStorageType, DataStorage> result = new HashMap<DataStorageType, DataStorage>(); |
|
|
155 |
|
145 |
for (DataStorageType type : collector.getRequiredDataStorageTypes()) { |
156 |
for (DataStorageType type : collector.getRequiredDataStorageTypes()) { |
146 |
result.put(type, getDataStorageFor(session, type, collector.getDataTablesMetadata())); |
157 |
final DataStorage dataStorage = getDataStorageFor(session, type, collector.getDataTablesMetadata()); |
147 |
} |
158 |
|
148 |
return result; |
159 |
if (dataStorage == null) { |
149 |
} |
160 |
DLightLogger.getLogger(DataStorageManager.class).log(Level.INFO, |
|
|
161 |
"DataStorageManager.getDataStoragesFor(DLightSession, DataCollector<?>):" // NOI18N |
162 |
+ " cannot find storage of type {0} [session={1}, collector={2}]." // NOI18N |
163 |
+ " NO storages will be returned", // NOI18N |
164 |
new Object[]{type, session.getDisplayName(), collector.getName()}); |
165 |
return Collections.<DataStorageType, DataStorage>emptyMap(); |
166 |
} |
167 |
|
168 |
result.put(type, dataStorage); |
169 |
} |
170 |
|
171 |
return result; |
172 |
} |
150 |
|
173 |
|
151 |
public synchronized ServiceInfoDataStorage getServiceInfoDataStorageFor(String uniqueKey) { |
174 |
public synchronized ServiceInfoDataStorage getServiceInfoDataStorageFor(String uniqueKey) { |
152 |
if (uniqueKey == null) { |
175 |
if (uniqueKey == null) { |
Lines 484-492
Link Here
|
484 |
DataStorage newStorage = storage.createStorage(); |
507 |
DataStorage newStorage = storage.createStorage(); |
485 |
if (newStorage instanceof ProxyDataStorage) { |
508 |
if (newStorage instanceof ProxyDataStorage) { |
486 |
ProxyDataStorage proxyStorage = (ProxyDataStorage) newStorage; |
509 |
ProxyDataStorage proxyStorage = (ProxyDataStorage) newStorage; |
487 |
DataStorage backendStorage = getDataStorageFor(session, proxyStorage.getBackendDataStorageType(), proxyStorage.getBackendTablesMetadata()); |
510 |
DataStorageType requiredStorageType = proxyStorage.getBackendDataStorageType(); |
|
|
511 |
List<DataTableMetadata> requiredTables = proxyStorage.getBackendTablesMetadata(); |
512 |
DataStorage backendStorage = getDataStorageFor(session, requiredStorageType, requiredTables); |
513 |
if (backendStorage == null) { |
514 |
// Means that required (for this proxy) storage cannot be found ... |
515 |
continue; |
516 |
} |
488 |
proxyStorage.attachTo(backendStorage); |
517 |
proxyStorage.attachTo(backendStorage); |
489 |
} |
518 |
} |
|
|
519 |
|
490 |
if (newStorage != null) { |
520 |
if (newStorage != null) { |
491 |
newStorage.createTables(tableMetadatas); |
521 |
newStorage.createTables(tableMetadatas); |
492 |
if (activeSessionStorages == null) { |
522 |
if (activeSessionStorages == null) { |
Lines 507-515
Link Here
|
507 |
if (newStorage != null) { |
537 |
if (newStorage != null) { |
508 |
if (newStorage instanceof ProxyDataStorage) { |
538 |
if (newStorage instanceof ProxyDataStorage) { |
509 |
ProxyDataStorage proxyStorage = (ProxyDataStorage) newStorage; |
539 |
ProxyDataStorage proxyStorage = (ProxyDataStorage) newStorage; |
510 |
DataStorage backendStorage = getDataStorageFor(session, proxyStorage.getBackendDataStorageType(), proxyStorage.getBackendTablesMetadata()); |
540 |
DataStorageType requiredStorageType = proxyStorage.getBackendDataStorageType(); |
|
|
541 |
List<DataTableMetadata> requiredTables = proxyStorage.getBackendTablesMetadata(); |
542 |
DataStorage backendStorage = getDataStorageFor(session, requiredStorageType, requiredTables); |
543 |
if (backendStorage == null) { |
544 |
continue; |
545 |
} |
511 |
proxyStorage.attachTo(backendStorage); |
546 |
proxyStorage.attachTo(backendStorage); |
512 |
} |
547 |
} |
|
|
548 |
|
513 |
newStorage.createTables(tableMetadatas); |
549 |
newStorage.createTables(tableMetadatas); |
514 |
|
550 |
|
515 |
return newStorage; |
551 |
return newStorage; |