use of com.orientechnologies.orient.core.config.OStorageConfiguration in project orientdb by orientechnologies.
the class WriteAheadLogTest method createWAL.
private ODiskWriteAheadLog createWAL(int maxPagesCacheSize, int maxSegmentSize) throws IOException {
OLocalPaginatedStorage paginatedStorage = mock(OLocalPaginatedStorage.class);
when(paginatedStorage.getName()).thenReturn("WriteAheadLogTest");
when(paginatedStorage.getStoragePath()).thenReturn(testDir.getAbsolutePath());
OStorageConfiguration configurationMock = mock(OStorageConfiguration.class);
when(configurationMock.getLocaleInstance()).thenReturn(Locale.getDefault());
when(paginatedStorage.getConfiguration()).thenReturn(configurationMock);
when(paginatedStorage.getPerformanceStatisticManager()).thenReturn(new OPerformanceStatisticManager(paginatedStorage, Long.MAX_VALUE, -1));
return new ODiskWriteAheadLog(maxPagesCacheSize, -1, maxSegmentSize, null, true, paginatedStorage, 10);
}
use of com.orientechnologies.orient.core.config.OStorageConfiguration in project orientdb by orientechnologies.
the class OConsoleDatabaseApp method listProperties.
@ConsoleCommand(description = "Display the database properties")
public void listProperties() {
if (currentDatabase == null)
return;
final OStorage stg = currentDatabase.getStorage();
final OStorageConfiguration dbCfg = stg.getConfiguration();
message("\n\nDATABASE PROPERTIES");
if (dbCfg.getProperties() != null) {
final List<ODocument> resultSet = new ArrayList<ODocument>();
if (dbCfg.name != null)
resultSet.add(new ODocument().field("NAME", "Name").field("VALUE", dbCfg.name));
resultSet.add(new ODocument().field("NAME", "Version").field("VALUE", dbCfg.version));
resultSet.add(new ODocument().field("NAME", "Conflict-Strategy").field("VALUE", dbCfg.getConflictStrategy()));
resultSet.add(new ODocument().field("NAME", "Date-Format").field("VALUE", dbCfg.dateFormat));
resultSet.add(new ODocument().field("NAME", "Datetime-Format").field("VALUE", dbCfg.dateTimeFormat));
resultSet.add(new ODocument().field("NAME", "Timezone").field("VALUE", dbCfg.getTimeZone().getID()));
resultSet.add(new ODocument().field("NAME", "Locale-Country").field("VALUE", dbCfg.getLocaleCountry()));
resultSet.add(new ODocument().field("NAME", "Locale-Language").field("VALUE", dbCfg.getLocaleLanguage()));
resultSet.add(new ODocument().field("NAME", "Charset").field("VALUE", dbCfg.getCharset()));
resultSet.add(new ODocument().field("NAME", "Schema-RID").field("VALUE", dbCfg.schemaRecordId, OType.LINK));
resultSet.add(new ODocument().field("NAME", "Index-Manager-RID").field("VALUE", dbCfg.indexMgrRecordId, OType.LINK));
resultSet.add(new ODocument().field("NAME", "Dictionary-RID").field("VALUE", dbCfg.dictionaryRecordId, OType.LINK));
final OTableFormatter formatter = new OTableFormatter(this);
formatter.writeRecords(resultSet, -1);
message("\n");
if (!dbCfg.getProperties().isEmpty()) {
message("\n\nDATABASE CUSTOM PROPERTIES:");
final List<ODocument> dbResultSet = new ArrayList<ODocument>();
for (OStorageEntryConfiguration cfg : dbCfg.getProperties()) dbResultSet.add(new ODocument().field("NAME", cfg.name).field("VALUE", cfg.value));
final OTableFormatter dbFormatter = new OTableFormatter(this);
dbFormatter.writeRecords(dbResultSet, -1);
}
}
}
use of com.orientechnologies.orient.core.config.OStorageConfiguration in project orientdb by orientechnologies.
the class ODocumentHelper method convertField.
@SuppressWarnings("unchecked")
public static <RET> RET convertField(final ODocument iDocument, final String iFieldName, OType type, Class<?> iFieldType, Object iValue) {
if (iFieldType == null && type != null)
iFieldType = type.getDefaultJavaType();
if (iFieldType == null)
return (RET) iValue;
if (ORID.class.isAssignableFrom(iFieldType)) {
if (iValue instanceof ORID) {
return (RET) iValue;
} else if (iValue instanceof String) {
return (RET) new ORecordId((String) iValue);
} else if (iValue instanceof ORecord) {
return (RET) ((ORecord) iValue).getIdentity();
}
} else if (OIdentifiable.class.isAssignableFrom(iFieldType)) {
if (iValue instanceof ORID || iValue instanceof ORecord) {
return (RET) iValue;
} else if (iValue instanceof String) {
return (RET) new ORecordId((String) iValue);
}
} else if (Set.class.isAssignableFrom(iFieldType)) {
if (!(iValue instanceof Set)) {
// CONVERT IT TO SET
final Collection<?> newValue;
if (type.isLink())
newValue = new ORecordLazySet(iDocument);
else
newValue = new OTrackedSet<Object>(iDocument);
if (iValue instanceof Collection<?>) {
((Collection<Object>) newValue).addAll((Collection<Object>) iValue);
return (RET) newValue;
} else if (iValue instanceof Map) {
((Collection<Object>) newValue).addAll(((Map<String, Object>) iValue).values());
return (RET) newValue;
} else if (iValue instanceof String) {
final String stringValue = (String) iValue;
if (stringValue != null && !stringValue.isEmpty()) {
final String[] items = stringValue.split(",");
for (String s : items) {
((Collection<Object>) newValue).add(s);
}
}
return (RET) newValue;
} else if (OMultiValue.isMultiValue(iValue)) {
// GENERIC MULTI VALUE
for (Object s : OMultiValue.getMultiValueIterable(iValue, false)) {
((Collection<Object>) newValue).add(s);
}
return (RET) newValue;
}
} else {
return (RET) iValue;
}
} else if (List.class.isAssignableFrom(iFieldType)) {
if (!(iValue instanceof List)) {
// CONVERT IT TO LIST
final Collection<?> newValue;
if (type.isLink())
newValue = new ORecordLazyList(iDocument);
else
newValue = new OTrackedList<Object>(iDocument);
if (iValue instanceof Collection) {
((Collection<Object>) newValue).addAll((Collection<Object>) iValue);
return (RET) newValue;
} else if (iValue instanceof Map) {
((Collection<Object>) newValue).addAll(((Map<String, Object>) iValue).values());
return (RET) newValue;
} else if (iValue instanceof String) {
final String stringValue = (String) iValue;
if (stringValue != null && !stringValue.isEmpty()) {
final String[] items = stringValue.split(",");
for (String s : items) {
((Collection<Object>) newValue).add(s);
}
}
return (RET) newValue;
} else if (OMultiValue.isMultiValue(iValue)) {
// GENERIC MULTI VALUE
for (Object s : OMultiValue.getMultiValueIterable(iValue)) {
((Collection<Object>) newValue).add(s);
}
return (RET) newValue;
}
} else {
return (RET) iValue;
}
} else if (iValue instanceof Enum) {
// ENUM
if (Number.class.isAssignableFrom(iFieldType))
iValue = ((Enum<?>) iValue).ordinal();
else
iValue = iValue.toString();
if (!(iValue instanceof String) && !iFieldType.isAssignableFrom(iValue.getClass()))
throw new IllegalArgumentException("Property '" + iFieldName + "' of type '" + iFieldType + "' cannot accept value of type: " + iValue.getClass());
} else if (Date.class.isAssignableFrom(iFieldType)) {
if (iValue instanceof String && ODatabaseRecordThreadLocal.INSTANCE.isDefined()) {
final OStorageConfiguration config = ODatabaseRecordThreadLocal.INSTANCE.get().getStorage().getConfiguration();
DateFormat formatter = config.getDateFormatInstance();
if (((String) iValue).length() > config.dateFormat.length()) {
// ASSUMES YOU'RE USING THE DATE-TIME FORMATTE
formatter = config.getDateTimeFormatInstance();
}
try {
Date newValue = formatter.parse((String) iValue);
// _fieldValues.put(iFieldName, newValue);
return (RET) newValue;
} catch (ParseException pe) {
final String dateFormat = ((String) iValue).length() > config.dateFormat.length() ? config.dateTimeFormat : config.dateFormat;
throw OException.wrapException(new OQueryParsingException("Error on conversion of date '" + iValue + "' using the format: " + dateFormat), pe);
}
}
}
iValue = OType.convert(iValue, iFieldType);
return (RET) iValue;
}
Aggregations