Search in sources :

Example 6 with OStorageConfiguration

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);
}
Also used : OLocalPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage) OStorageConfiguration(com.orientechnologies.orient.core.config.OStorageConfiguration) OPerformanceStatisticManager(com.orientechnologies.orient.core.storage.impl.local.statistic.OPerformanceStatisticManager)

Example 7 with OStorageConfiguration

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);
        }
    }
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) OStorageEntryConfiguration(com.orientechnologies.orient.core.config.OStorageEntryConfiguration) OStorageConfiguration(com.orientechnologies.orient.core.config.OStorageConfiguration) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 8 with OStorageConfiguration

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;
}
Also used : OStorageConfiguration(com.orientechnologies.orient.core.config.OStorageConfiguration) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ORecord(com.orientechnologies.orient.core.record.ORecord) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) OQueryParsingException(com.orientechnologies.orient.core.exception.OQueryParsingException) ORID(com.orientechnologies.orient.core.id.ORID) ParseException(java.text.ParseException)

Aggregations

OStorageConfiguration (com.orientechnologies.orient.core.config.OStorageConfiguration)8 OStorage (com.orientechnologies.orient.core.storage.OStorage)4 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)3 OException (com.orientechnologies.common.exception.OException)2 OQueryParsingException (com.orientechnologies.orient.core.exception.OQueryParsingException)2 ORID (com.orientechnologies.orient.core.id.ORID)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)1 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)1 OModificationOperationProhibitedException (com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)1 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)1 OIOException (com.orientechnologies.common.io.OIOException)1 OStorageEntryConfiguration (com.orientechnologies.orient.core.config.OStorageEntryConfiguration)1 OCurrentStorageComponentsFactory (com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)1 OTokenException (com.orientechnologies.orient.core.metadata.security.OTokenException)1