use of com.orientechnologies.orient.core.conflict.ORecordConflictStrategyFactory in project orientdb by orientechnologies.
the class OStorageConfiguration method fromStream.
public void fromStream(final byte[] stream, int offset, int length) {
clear();
final String[] values = new String(stream, offset, length).split("\\|");
int index = 0;
version = Integer.parseInt(read(values[index++]));
name = read(values[index++]);
schemaRecordId = read(values[index++]);
dictionaryRecordId = read(values[index++]);
if (version > 0)
indexMgrRecordId = read(values[index++]);
else
// @COMPATIBILITY
indexMgrRecordId = null;
localeLanguage = read(values[index++]);
localeCountry = read(values[index++]);
dateFormat = read(values[index++]);
dateTimeFormat = read(values[index++]);
// @COMPATIBILITY 1.2.0
if (version >= 4) {
timeZone = TimeZone.getTimeZone(read(values[index++]));
charset = read(values[index++]);
}
final ORecordConflictStrategyFactory conflictStrategyFactory = Orient.instance().getRecordConflictStrategy();
if (version >= 12)
conflictStrategy = conflictStrategyFactory.getStrategy(read(values[index++])).getName();
else
conflictStrategy = conflictStrategyFactory.getDefaultStrategy();
// @COMPATIBILITY
if (version > 1)
index = phySegmentFromStream(values, index, fileTemplate);
int size = Integer.parseInt(read(values[index++]));
// PREPARE THE LIST OF CLUSTERS
clusters.clear();
String determineStorageCompression = null;
for (int i = 0; i < size; ++i) {
final int clusterId = Integer.parseInt(read(values[index++]));
if (clusterId == -1)
continue;
final String clusterName = read(values[index++]);
final int targetDataSegmentId = version >= 3 ? Integer.parseInt(read(values[index++])) : 0;
final String clusterType = read(values[index++]);
final OStorageClusterConfiguration currentCluster;
if (clusterType.equals("d")) {
final boolean cc = Boolean.valueOf(read(values[index++]));
final float bb = Float.valueOf(read(values[index++]));
final float aa = Float.valueOf(read(values[index++]));
final String clusterCompression = read(values[index++]);
if (determineStorageCompression == null)
// TRY TO DETERMINE THE STORAGE COMPRESSION. BEFORE VERSION 11 IT WASN'T STORED IN STORAGE CFG, SO GET FROM THE FIRST
// CLUSTER
determineStorageCompression = clusterCompression;
String clusterEncryption = null;
if (version >= 15)
clusterEncryption = read(values[index++]);
final String clusterConflictStrategy;
if (version >= 12)
clusterConflictStrategy = read(values[index++]);
else
// INHERIT THE STRATEGY IN STORAGE
clusterConflictStrategy = null;
OStorageClusterConfiguration.STATUS status = OStorageClusterConfiguration.STATUS.ONLINE;
if (version >= 13)
status = OStorageClusterConfiguration.STATUS.valueOf(read(values[index++]));
currentCluster = new OStoragePaginatedClusterConfiguration(this, clusterId, clusterName, null, cc, bb, aa, clusterCompression, clusterEncryption, configuration.getValueAsString(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY), clusterConflictStrategy, status);
} else if (clusterType.equals("p"))
// PHYSICAL CLUSTER
throw new IllegalArgumentException("Cluster of storage 'local' are not supported since 2.0");
else
throw new IllegalArgumentException("Unsupported cluster type: " + clusterType);
// MAKE ROOMS, EVENTUALLY FILLING EMPTIES ENTRIES
for (int c = clusters.size(); c <= clusterId; ++c) clusters.add(null);
clusters.set(clusterId, currentCluster);
}
if (version < 13) {
// OLD: READ DATA-SEGMENTS
size = Integer.parseInt(read(values[index++]));
for (int i = 0; i < size; ++i) {
int dataId = Integer.parseInt(read(values[index++]));
if (dataId == -1)
continue;
read(values[index++]);
read(values[index++]);
read(values[index++]);
read(values[index++]);
}
// READ TX_SEGMENT STUFF
read(values[index++]);
read(values[index++]);
read(values[index++]);
read(values[index++]);
read(values[index++]);
}
size = Integer.parseInt(read(values[index++]));
clearProperties();
for (int i = 0; i < size; ++i) setProperty(read(values[index++]), read(values[index++]));
if (version >= 7)
binaryFormatVersion = Integer.parseInt(read(values[index++]));
else if (version == 6)
binaryFormatVersion = 9;
else
binaryFormatVersion = 8;
if (version >= 8)
clusterSelection = read(values[index++]);
else
// DEFAULT = ROUND-ROBIN
clusterSelection = ORoundRobinClusterSelectionStrategy.NAME;
if (version >= 9)
setMinimumClusters(Integer.parseInt(read(values[index++])));
else
// DEFAULT = 1
setMinimumClusters(1);
autoInitClusters();
if (version >= 10) {
recordSerializer = read(values[index++]);
recordSerializerVersion = Integer.parseInt(read(values[index++]));
}
if (version >= 11) {
// READ THE CONFIGURATION
final int cfgSize = Integer.parseInt(read(values[index++]));
for (int i = 0; i < cfgSize; ++i) {
final String key = read(values[index++]);
final Object value = read(values[index++]);
final OGlobalConfiguration cfg = OGlobalConfiguration.findByKey(key);
if (cfg != null) {
if (value != null)
configuration.setValue(key, OType.convert(value, cfg.getType()));
} else
OLogManager.instance().warn(this, "Ignored storage configuration because not supported: %s=%s", key, value);
}
} else
// SAVE STORAGE COMPRESSION METHOD AS PROPERTY
configuration.setValue(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD, determineStorageCompression);
if (version > 15) {
final int enginesSize = Integer.parseInt(read(values[index++]));
for (int i = 0; i < enginesSize; i++) {
final String name = read(values[index++]);
final String algorithm = read(values[index++]);
final String indexType;
if (version > 16)
indexType = read(values[index++]);
else
indexType = "";
final byte valueSerializerId = Byte.parseByte(read(values[index++]));
final byte keySerializerId = Byte.parseByte(read(values[index++]));
final boolean isAutomatic = Boolean.parseBoolean(read((values[index++])));
final Boolean durableInNonTxMode;
if (read(values[index]) == null) {
durableInNonTxMode = null;
index++;
} else
durableInNonTxMode = Boolean.parseBoolean(read(values[index++]));
final int version = Integer.parseInt(read(values[index++]));
final boolean nullValuesSupport = Boolean.parseBoolean(read((values[index++])));
final int keySize = Integer.parseInt(read(values[index++]));
final int typesLength = Integer.parseInt(read(values[index++]));
final OType[] types = new OType[typesLength];
for (int n = 0; n < types.length; n++) {
final OType type = OType.valueOf(read(values[index++]));
types[n] = type;
}
final int propertiesSize = Integer.parseInt(read(values[index++]));
final Map<String, String> engineProperties;
if (propertiesSize == 0)
engineProperties = null;
else {
engineProperties = new HashMap<String, String>(propertiesSize);
for (int n = 0; n < propertiesSize; n++) {
final String key = read(values[index++]);
final String value = read(values[index++]);
engineProperties.put(key, value);
}
}
final IndexEngineData indexEngineData = new IndexEngineData(name, algorithm, indexType, durableInNonTxMode, version, valueSerializerId, keySerializerId, isAutomatic, types, nullValuesSupport, keySize, engineProperties);
indexEngines.put(name.toLowerCase(getLocaleInstance()), indexEngineData);
}
}
}
Aggregations