Search in sources :

Example 1 with OStorageConfiguration

use of com.orientechnologies.orient.core.config.OStorageConfiguration in project orientdb by orientechnologies.

the class OStorageRemote method open.

public void open(final String iUserName, final String iUserPassword, final Map<String, Object> iOptions) {
    stateLock.acquireWriteLock();
    addUser();
    try {
        OStorageRemoteSession session = getCurrentSession();
        if (status == STATUS.CLOSED || !iUserName.equals(session.connectionUserName) || !iUserPassword.equals(session.connectionUserPassword) || session.sessions.isEmpty()) {
            OCredentialInterceptor ci = OSecurityManager.instance().newCredentialInterceptor();
            if (ci != null) {
                ci.intercept(getURL(), iUserName, iUserPassword);
                session.connectionUserName = ci.getUsername();
                session.connectionUserPassword = ci.getPassword();
            } else // Do Nothing
            {
                session.connectionUserName = iUserName;
                session.connectionUserPassword = iUserPassword;
            }
            parseOptions(iOptions);
            openRemoteDatabase();
            final OStorageConfiguration storageConfiguration = new OStorageRemoteConfiguration(this, recordFormat);
            storageConfiguration.load(iOptions);
            configuration = storageConfiguration;
            componentsFactory = new OCurrentStorageComponentsFactory(configuration);
        } else {
            reopenRemoteDatabase();
        }
    } catch (Exception e) {
        removeUser();
        if (e instanceof RuntimeException)
            // PASS THROUGH
            throw (RuntimeException) e;
        else
            throw OException.wrapException(new OStorageException("Cannot open the remote storage: " + name), e);
    } finally {
        stateLock.releaseWriteLock();
    }
}
Also used : OCredentialInterceptor(com.orientechnologies.orient.core.security.OCredentialInterceptor) OCurrentStorageComponentsFactory(com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory) OStorageConfiguration(com.orientechnologies.orient.core.config.OStorageConfiguration) OException(com.orientechnologies.common.exception.OException) NamingException(javax.naming.NamingException) OTokenException(com.orientechnologies.orient.core.metadata.security.OTokenException) ODistributedRedirectException(com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException) OInterruptedException(com.orientechnologies.common.concur.lock.OInterruptedException) OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) OModificationOperationProhibitedException(com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)

Example 2 with OStorageConfiguration

use of com.orientechnologies.orient.core.config.OStorageConfiguration in project orientdb by orientechnologies.

the class OSQLFilterCondition method getDate.

protected Date getDate(final Object value) {
    if (value == null) {
        return null;
    }
    final OStorageConfiguration config = ODatabaseRecordThreadLocal.INSTANCE.get().getStorage().getConfiguration();
    if (value instanceof Long) {
        Calendar calendar = Calendar.getInstance(config.getTimeZone());
        calendar.setTimeInMillis(((Long) value));
        return calendar.getTime();
    }
    String stringValue = value.toString();
    if (NULL_VALUE.equals(stringValue)) {
        return null;
    }
    if (stringValue.length() <= 0) {
        return null;
    }
    if (Pattern.matches("^\\d+$", stringValue)) {
        return new Date(Long.valueOf(stringValue).longValue());
    }
    SimpleDateFormat formatter = config.getDateFormatInstance();
    if (stringValue.length() > config.dateFormat.length()) // ASSUMES YOU'RE USING THE DATE-TIME FORMATTE
    {
        formatter = config.getDateTimeFormatInstance();
    }
    try {
        return formatter.parse(stringValue);
    } catch (ParseException pe) {
        try {
            return new Date(new Double(stringValue).longValue());
        } catch (Exception pe2) {
            throw OException.wrapException(new OQueryParsingException("Error on conversion of date '" + stringValue + "' using the format: " + formatter.toPattern()), pe2);
        }
    }
}
Also used : OQueryParsingException(com.orientechnologies.orient.core.exception.OQueryParsingException) ParseException(java.text.ParseException) OStorageConfiguration(com.orientechnologies.orient.core.config.OStorageConfiguration) SimpleDateFormat(java.text.SimpleDateFormat) OException(com.orientechnologies.common.exception.OException) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ParseException(java.text.ParseException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OQueryParsingException(com.orientechnologies.orient.core.exception.OQueryParsingException)

Example 3 with OStorageConfiguration

use of com.orientechnologies.orient.core.config.OStorageConfiguration in project orientdb by orientechnologies.

the class OIndexDefinitionFactory method getServerLocale.

private static Locale getServerLocale() {
    ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
    OStorage storage = db.getStorage();
    OStorageConfiguration configuration = storage.getConfiguration();
    return configuration.getLocaleInstance();
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) OStorageConfiguration(com.orientechnologies.orient.core.config.OStorageConfiguration) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 4 with OStorageConfiguration

use of com.orientechnologies.orient.core.config.OStorageConfiguration in project orientdb by orientechnologies.

the class OIndexManagerAbstract method getServerLocale.

protected Locale getServerLocale() {
    ODatabaseDocumentInternal db = getDatabase();
    OStorage storage = db.getStorage();
    OStorageConfiguration configuration = storage.getConfiguration();
    return configuration.getLocaleInstance();
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) OStorageConfiguration(com.orientechnologies.orient.core.config.OStorageConfiguration) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 5 with OStorageConfiguration

use of com.orientechnologies.orient.core.config.OStorageConfiguration in project orientdb by orientechnologies.

the class ODatabaseCompare method compareRecords.

@SuppressFBWarnings("NP_NULL_ON_SOME_PATH")
private boolean compareRecords(ODocumentHelper.RIDMapper ridMapper) {
    listener.onMessage("\nStarting deep comparison record by record. This may take a few minutes. Wait please...");
    Collection<String> clusterNames1 = makeDbCall(databaseOne, new ODbRelatedCall<Collection<String>>() {

        @Override
        public Collection<String> call(ODatabaseDocumentInternal database) {
            return database.getClusterNames();
        }
    });
    for (final String clusterName : clusterNames1) {
        // CHECK IF THE CLUSTER IS INCLUDED
        if (includeClusters != null) {
            if (!includeClusters.contains(clusterName))
                continue;
        } else if (excludeClusters != null) {
            if (excludeClusters.contains(clusterName))
                continue;
        }
        final int clusterId1 = makeDbCall(databaseOne, new ODbRelatedCall<Integer>() {

            @Override
            public Integer call(ODatabaseDocumentInternal database) {
                return database.getClusterIdByName(clusterName);
            }
        });
        final long[] db1Range = makeDbCall(databaseOne, new ODbRelatedCall<long[]>() {

            @Override
            public long[] call(ODatabaseDocumentInternal database) {
                return database.getStorage().getClusterDataRange(clusterId1);
            }
        });
        final long[] db2Range = makeDbCall(databaseTwo, new ODbRelatedCall<long[]>() {

            @Override
            public long[] call(ODatabaseDocumentInternal database) {
                return database.getStorage().getClusterDataRange(clusterId1);
            }
        });
        final long db1Max = db1Range[1];
        final long db2Max = db2Range[1];
        databaseOne.activateOnCurrentThread();
        final ODocument doc1 = new ODocument();
        databaseTwo.activateOnCurrentThread();
        final ODocument doc2 = new ODocument();
        final ORecordId rid = new ORecordId(clusterId1);
        // TODO why this maximums can be different?
        final long clusterMax = Math.max(db1Max, db2Max);
        final OStorage storage;
        ODatabaseDocumentInternal selectedDatabase;
        if (clusterMax == db1Max)
            selectedDatabase = databaseOne;
        else
            selectedDatabase = databaseTwo;
        OPhysicalPosition[] physicalPositions = makeDbCall(selectedDatabase, new ODbRelatedCall<OPhysicalPosition[]>() {

            @Override
            public OPhysicalPosition[] call(ODatabaseDocumentInternal database) {
                return database.getStorage().ceilingPhysicalPositions(clusterId1, new OPhysicalPosition(0));
            }
        });
        OStorageConfiguration configuration1 = makeDbCall(databaseOne, new ODbRelatedCall<OStorageConfiguration>() {

            @Override
            public OStorageConfiguration call(ODatabaseDocumentInternal database) {
                return database.getStorage().getConfiguration();
            }
        });
        OStorageConfiguration configuration2 = makeDbCall(databaseTwo, new ODbRelatedCall<OStorageConfiguration>() {

            @Override
            public OStorageConfiguration call(ODatabaseDocumentInternal database) {
                return database.getStorage().getConfiguration();
            }
        });
        String storageType1 = makeDbCall(databaseOne, new ODbRelatedCall<String>() {

            @Override
            public String call(ODatabaseDocumentInternal database) {
                return database.getStorage().getType();
            }
        });
        String storageType2 = makeDbCall(databaseTwo, new ODbRelatedCall<String>() {

            @Override
            public String call(ODatabaseDocumentInternal database) {
                return database.getStorage().getType();
            }
        });
        long recordsCounter = 0;
        while (physicalPositions.length > 0) {
            for (OPhysicalPosition physicalPosition : physicalPositions) {
                try {
                    recordsCounter++;
                    final long position = physicalPosition.clusterPosition;
                    rid.setClusterPosition(position);
                    if (rid.equals(new ORecordId(configuration1.indexMgrRecordId)) && rid.equals(new ORecordId(configuration2.indexMgrRecordId)))
                        continue;
                    if (rid.equals(new ORecordId(configuration1.schemaRecordId)) && rid.equals(new ORecordId(configuration2.schemaRecordId)))
                        continue;
                    if (rid.getClusterId() == 0 && rid.getClusterPosition() == 0) {
                        // Skip the compare of raw structure if the storage type are different, due the fact that are different by definition.
                        if (!storageType1.equals(storageType2))
                            continue;
                    }
                    final ORecordId rid2;
                    if (ridMapper == null)
                        rid2 = rid;
                    else {
                        final ORID newRid = ridMapper.map(rid);
                        if (newRid == null)
                            rid2 = rid;
                        else
                            rid2 = new ORecordId(newRid);
                    }
                    final ORawBuffer buffer1 = makeDbCall(databaseOne, new ODbRelatedCall<ORawBuffer>() {

                        @Override
                        public ORawBuffer call(ODatabaseDocumentInternal database) {
                            return database.getStorage().readRecord(rid, null, true, false, null).getResult();
                        }
                    });
                    final ORawBuffer buffer2 = makeDbCall(databaseTwo, new ODbRelatedCall<ORawBuffer>() {

                        @Override
                        public ORawBuffer call(ODatabaseDocumentInternal database) {
                            return database.getStorage().readRecord(rid2, null, true, false, null).getResult();
                        }
                    });
                    if (buffer1 == null && buffer2 == null)
                        // BOTH RECORD NULL, OK
                        continue;
                    else if (buffer1 == null && buffer2 != null) {
                        // REC1 NULL
                        listener.onMessage("\n- ERR: RID=" + clusterId1 + ":" + position + " is null in DB1");
                        ++differences;
                    } else if (buffer1 != null && buffer2 == null) {
                        // REC2 NULL
                        listener.onMessage("\n- ERR: RID=" + clusterId1 + ":" + position + " is null in DB2");
                        ++differences;
                    } else {
                        if (buffer1.recordType != buffer2.recordType) {
                            listener.onMessage("\n- ERR: RID=" + clusterId1 + ":" + position + " recordType is different: " + (char) buffer1.recordType + " <-> " + (char) buffer2.recordType);
                            ++differences;
                        }
                        if (buffer1.buffer == null && buffer2.buffer == null) {
                        } else if (buffer1.buffer == null && buffer2.buffer != null) {
                            listener.onMessage("\n- ERR: RID=" + clusterId1 + ":" + position + " content is different: null <-> " + buffer2.buffer.length);
                            ++differences;
                        } else if (buffer1.buffer != null && buffer2.buffer == null) {
                            listener.onMessage("\n- ERR: RID=" + clusterId1 + ":" + position + " content is different: " + buffer1.buffer.length + " <-> null");
                            ++differences;
                        } else {
                            if (buffer1.recordType == ODocument.RECORD_TYPE) {
                                // DOCUMENT: TRY TO INSTANTIATE AND COMPARE
                                makeDbCall(databaseOne, new ODocumentHelper.ODbRelatedCall<Object>() {

                                    public Object call(ODatabaseDocumentInternal database) {
                                        doc1.reset();
                                        doc1.fromStream(buffer1.buffer);
                                        return null;
                                    }
                                });
                                makeDbCall(databaseTwo, new ODocumentHelper.ODbRelatedCall<Object>() {

                                    public Object call(ODatabaseDocumentInternal database) {
                                        doc2.reset();
                                        doc2.fromStream(buffer2.buffer);
                                        return null;
                                    }
                                });
                                if (rid.toString().equals(configuration1.schemaRecordId) && rid.toString().equals(configuration2.schemaRecordId)) {
                                    makeDbCall(databaseOne, new ODocumentHelper.ODbRelatedCall<java.lang.Object>() {

                                        public Object call(ODatabaseDocumentInternal database) {
                                            convertSchemaDoc(doc1);
                                            return null;
                                        }
                                    });
                                    makeDbCall(databaseTwo, new ODocumentHelper.ODbRelatedCall<java.lang.Object>() {

                                        public Object call(ODatabaseDocumentInternal database) {
                                            convertSchemaDoc(doc2);
                                            return null;
                                        }
                                    });
                                }
                                if (!ODocumentHelper.hasSameContentOf(doc1, databaseOne, doc2, databaseTwo, ridMapper)) {
                                    listener.onMessage("\n- ERR: RID=" + clusterId1 + ":" + position + " document content is different");
                                    listener.onMessage("\n--- REC1: " + new String(buffer1.buffer));
                                    listener.onMessage("\n--- REC2: " + new String(buffer2.buffer));
                                    listener.onMessage("\n");
                                    ++differences;
                                }
                            } else {
                                if (buffer1.buffer.length != buffer2.buffer.length) {
                                    // CHECK IF THE TRIMMED SIZE IS THE SAME
                                    final String rec1 = new String(buffer1.buffer).trim();
                                    final String rec2 = new String(buffer2.buffer).trim();
                                    if (rec1.length() != rec2.length()) {
                                        listener.onMessage("\n- ERR: RID=" + clusterId1 + ":" + position + " content length is different: " + buffer1.buffer.length + " <-> " + buffer2.buffer.length);
                                        if (buffer1.recordType == ODocument.RECORD_TYPE)
                                            listener.onMessage("\n--- REC1: " + rec1);
                                        if (buffer2.recordType == ODocument.RECORD_TYPE)
                                            listener.onMessage("\n--- REC2: " + rec2);
                                        listener.onMessage("\n");
                                        ++differences;
                                    }
                                } else {
                                    // CHECK BYTE PER BYTE
                                    for (int b = 0; b < buffer1.buffer.length; ++b) {
                                        if (buffer1.buffer[b] != buffer2.buffer[b]) {
                                            listener.onMessage("\n- ERR: RID=" + clusterId1 + ":" + position + " content is different at byte #" + b + ": " + buffer1.buffer[b] + " <-> " + buffer2.buffer[b]);
                                            listener.onMessage("\n--- REC1: " + new String(buffer1.buffer));
                                            listener.onMessage("\n--- REC2: " + new String(buffer2.buffer));
                                            listener.onMessage("\n");
                                            ++differences;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                } catch (RuntimeException e) {
                    OLogManager.instance().error(this, "Error during data comparison of records with rid " + rid);
                    throw e;
                }
            }
            final OPhysicalPosition[] curPosition = physicalPositions;
            physicalPositions = makeDbCall(selectedDatabase, new ODbRelatedCall<OPhysicalPosition[]>() {

                @Override
                public OPhysicalPosition[] call(ODatabaseDocumentInternal database) {
                    return database.getStorage().higherPhysicalPositions(clusterId1, curPosition[curPosition.length - 1]);
                }
            });
            if (recordsCounter % 10000 == 0)
                listener.onMessage("\n" + recordsCounter + " records were processed for cluster " + clusterName + " ...");
        }
        listener.onMessage("\nCluster comparison was finished, " + recordsCounter + " records were processed for cluster " + clusterName + " ...");
    }
    return true;
}
Also used : ODbRelatedCall(com.orientechnologies.orient.core.record.impl.ODocumentHelper.ODbRelatedCall) ODocumentHelper(com.orientechnologies.orient.core.record.impl.ODocumentHelper) OStorage(com.orientechnologies.orient.core.storage.OStorage) OStorageConfiguration(com.orientechnologies.orient.core.config.OStorageConfiguration) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition) ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Collection(java.util.Collection) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

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