Skip to content

Commit

Permalink
Merged develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Feb 7, 2016
1 parent a0d11b7 commit 5f9be64
Show file tree
Hide file tree
Showing 135 changed files with 17,751 additions and 10,573 deletions.
715 changes: 628 additions & 87 deletions core/src/main/grammar/OrientSQL.jjt

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Expand Up @@ -20,6 +20,9 @@

package com.orientechnologies.orient.core.engine.local;

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import com.orientechnologies.common.exception.OException;
Expand All @@ -28,6 +31,7 @@
import com.orientechnologies.orient.core.engine.OEngineAbstract;
import com.orientechnologies.orient.core.exception.ODatabaseException;
import com.orientechnologies.orient.core.storage.OStorage;
import com.orientechnologies.orient.core.storage.cache.OReadCache;
import com.orientechnologies.orient.core.storage.cache.local.twoq.O2QCache;
import com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage;

Expand All @@ -38,7 +42,7 @@
public class OEngineLocalPaginated extends OEngineAbstract {
public static final String NAME = "plocal";

private final O2QCache readCache;
private final O2QCache readCache;

public OEngineLocalPaginated() {
readCache = new O2QCache(calculateReadCacheMaxMemory(OGlobalConfiguration.DISK_CACHE_SIZE.getValueAsLong() * 1024 * 1024),
Expand All @@ -65,12 +69,23 @@ public void changeCacheSize(final long cacheSize) {

public OStorage createStorage(final String dbName, final Map<String, String> configuration) {
try {
// GET THE STORAGE
return new OLocalPaginatedStorage(dbName, dbName, getMode(configuration), generateStorageId(), readCache);
try {
final Class<? extends OLocalPaginatedStorage> enterpriseVersion = (Class<? extends OLocalPaginatedStorage>) Class
.forName("com.orientechnologies.orient.core.storage.impl.local.paginated.OEnterpriseLocalPaginatedStorage");
final Constructor<? extends OLocalPaginatedStorage> constructor = enterpriseVersion
.getConstructor(String.class, String.class, String.class, Integer.TYPE, OReadCache.class);
return constructor.newInstance(dbName, dbName, getMode(configuration), generateStorageId(), readCache);
} catch (ClassNotFoundException cne) {
} catch (NoSuchMethodException nme) {
} catch (IllegalAccessException iae) {
} catch (InvocationTargetException ite) {
} catch (InstantiationException ie) {
}

return new OLocalPaginatedStorage(dbName, dbName, getMode(configuration), generateStorageId(), readCache);
} catch (Exception e) {
final String message = "Error on opening database: " + dbName + ". Current location is: "
+ new java.io.File(".").getAbsolutePath();
final String message =
"Error on opening database: " + dbName + ". Current location is: " + new java.io.File(".").getAbsolutePath();
OLogManager.instance().error(this, message, e);

throw OException.wrapException(new ODatabaseException(message), e);
Expand Down
Expand Up @@ -236,7 +236,7 @@ public OIndexInternal<?> create(final OIndexDefinition indexDefinition, final St
onIndexEngineChange(indexId);

if (rebuild)
rebuild(progressListener);
fillIndex(progressListener);

updateConfiguration();
} catch (Exception e) {
Expand Down Expand Up @@ -431,29 +431,9 @@ public long rebuild(final OProgressListener iProgressListener) {

onIndexEngineChange(indexId);

long documentNum = 0;
long documentTotal = 0;

for (final String cluster : clustersToIndex)
documentTotal += getDatabase().countClusterElements(cluster);

if (iProgressListener != null)
iProgressListener.onBegin(this, documentTotal, true);

// INDEX ALL CLUSTERS
for (final String clusterName : clustersToIndex) {
final long[] metrics = indexCluster(clusterName, iProgressListener, documentNum, documentIndexed, documentTotal);
documentNum = metrics[0];
documentIndexed = metrics[1];
}

if (iProgressListener != null)
iProgressListener.onCompletition(this, true);
documentIndexed = fillIndex(iProgressListener);

} catch (final Exception e) {
if (iProgressListener != null)
iProgressListener.onCompletition(this, false);

try {
if (indexId >= 0)
storage.clearIndex(indexId);
Expand All @@ -477,6 +457,35 @@ public long rebuild(final OProgressListener iProgressListener) {
return documentIndexed;
}

private long fillIndex(OProgressListener iProgressListener) {
long documentIndexed = 0;
try {
long documentNum = 0;
long documentTotal = 0;

for (final String cluster : clustersToIndex)
documentTotal += getDatabase().countClusterElements(cluster);

if (iProgressListener != null)
iProgressListener.onBegin(this, documentTotal, true);

// INDEX ALL CLUSTERS
for (final String clusterName : clustersToIndex) {
final long[] metrics = indexCluster(clusterName, iProgressListener, documentNum, documentIndexed, documentTotal);
documentNum = metrics[0];
documentIndexed = metrics[1];
}

if (iProgressListener != null)
iProgressListener.onCompletition(this, true);
} catch (final RuntimeException e) {
if (iProgressListener != null)
iProgressListener.onCompletition(this, false);
throw e;
}
return documentIndexed;
}

public boolean remove(Object key, final OIdentifiable value) {
return remove(key);
}
Expand Down
Expand Up @@ -19,6 +19,7 @@
*/
package com.orientechnologies.orient.core.metadata.schema;

import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.listener.OProgressListener;
import com.orientechnologies.common.util.OArrays;
import com.orientechnologies.common.util.OCommonConst;
Expand Down Expand Up @@ -65,6 +66,7 @@
import com.orientechnologies.orient.core.type.ODocumentWrapperNoClass;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -2136,8 +2138,8 @@ private void setNameInternal(final String name) {
if (record.recordType == ODocument.RECORD_TYPE) {
final ORecordSerializerSchemaAware2CSV serializer = (ORecordSerializerSchemaAware2CSV) ORecordSerializerFactory
.instance().getFormat(ORecordSerializerSchemaAware2CSV.NAME);

if (serializer.getClassName(OBinaryProtocol.bytes2string(record.buffer)).equalsIgnoreCase(name)) {
String persName = new String(record.buffer,"UTF-8");
if (serializer.getClassName(persName).equalsIgnoreCase(name)) {
final ODocument document = new ODocument();
document.setLazyLoad(false);
document.fromStream(record.buffer);
Expand All @@ -2157,6 +2159,8 @@ private void setNameInternal(final String name) {
}

renameCluster(oldName, this.name);
} catch (UnsupportedEncodingException e) {
throw OException.wrapException(new OSchemaException("Error reading schema"), e);
} finally {
releaseSchemaWriteLock();
}
Expand Down
Expand Up @@ -21,6 +21,7 @@

import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.annotation.OAfterDeserialization;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.exception.OSecurityAccessException;
import com.orientechnologies.orient.core.exception.OSecurityException;
Expand Down Expand Up @@ -77,7 +78,7 @@ public OUser(final ODocument iSource) {
}

public static final String encryptPassword(final String iPassword) {
return OSecurityManager.instance().createHash(iPassword, OSecurityManager.PBKDF2_ALGORITHM, true);
return OSecurityManager.instance().createHash(iPassword, OGlobalConfiguration.SECURITY_USER_PASSWORD_DEFAULT_ALGORITHM.getValueAsString(), true);
}

@Override
Expand Down
Expand Up @@ -17,15 +17,15 @@ public class ODirtyManager {

private ODirtyManager overrider;
private Map<ODocument, List<OIdentifiable>> references;
private Set<ORecord> newRecord;
private Set<ORecord> newRecords;
private Set<ORecord> updateRecords;

public void setDirty(ORecord record) {
ODirtyManager real = getReal();
if (record.getIdentity().isNew()) {
if (real.newRecord == null)
real.newRecord = Collections.newSetFromMap(new IdentityHashMap<ORecord, Boolean>());
real.newRecord.add(record);
if (real.newRecords == null)
real.newRecords = Collections.newSetFromMap(new IdentityHashMap<ORecord, Boolean>());
real.newRecords.add(record);
} else {
if (real.updateRecords == null)
real.updateRecords = Collections.newSetFromMap(new IdentityHashMap<ORecord, Boolean>());
Expand All @@ -43,8 +43,8 @@ public ODirtyManager getReal() {
return real;
}

public Set<ORecord> getNewRecord() {
return getReal().newRecord;
public Set<ORecord> getNewRecords() {
return getReal().newRecords;
}

public Set<ORecord> getUpdateRecords() {
Expand All @@ -65,10 +65,10 @@ public boolean isSame(ODirtyManager other) {
public void merge(ODirtyManager toMerge) {
if (isSame(toMerge))
return;
if (toMerge.getNewRecord() != null) {
if (newRecord == null)
newRecord = Collections.newSetFromMap(new IdentityHashMap<ORecord, Boolean>());
this.newRecord.addAll(toMerge.getNewRecord());
if (toMerge.getNewRecords() != null) {
if (newRecords == null)
newRecords = Collections.newSetFromMap(new IdentityHashMap<ORecord, Boolean>());
this.newRecords.addAll(toMerge.getNewRecords());
}
if (toMerge.getUpdateRecords() != null) {
if (updateRecords == null)
Expand Down Expand Up @@ -161,14 +161,14 @@ private void override(ODirtyManager oDirtyManager) {
if (real == oDirtyManager)
return;
real.overrider = oDirtyManager;
real.newRecord = null;
real.newRecords = null;
real.updateRecords = null;
real.references = null;
}

public void cleanForSave() {
public void clearForSave() {
ODirtyManager real = getReal();
real.newRecord = null;
real.newRecords = null;
real.updateRecords = null;
}

Expand All @@ -181,8 +181,8 @@ public List<OIdentifiable> getPointed(ORecord rec) {

public void removeNew(ORecord record) {
ODirtyManager real = getReal();
if (real.newRecord != null)
real.newRecord.remove(record);
if (real.newRecords != null)
real.newRecords.remove(record);
}

public void removePointed(ORecord record) {
Expand All @@ -194,4 +194,8 @@ public void removePointed(ORecord record) {
}
}

public void clear() {
clearForSave();
getReal().references = null;
}
}
Expand Up @@ -32,12 +32,7 @@
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.record.*;
import com.orientechnologies.orient.core.db.record.ridbag.ORidBag;
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.exception.ODatabaseException;
import com.orientechnologies.orient.core.exception.OQueryParsingException;
import com.orientechnologies.orient.core.exception.ORecordNotFoundException;
import com.orientechnologies.orient.core.exception.OSchemaException;
import com.orientechnologies.orient.core.exception.OValidationException;
import com.orientechnologies.orient.core.exception.*;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.iterator.OEmptyMapEntryIterator;
Expand Down Expand Up @@ -68,12 +63,7 @@
import com.orientechnologies.orient.core.tx.OTransaction;
import com.orientechnologies.orient.core.tx.OTransactionOptimistic;

import java.io.ByteArrayOutputStream;
import java.io.Externalizable;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.*;
import java.lang.ref.WeakReference;
import java.util.*;
import java.util.Map.Entry;
Expand Down Expand Up @@ -711,7 +701,11 @@ public String toString() {
public void fromString(final String iValue) {
_dirty = true;
_contentChanged = true;
_source = OBinaryProtocol.string2bytes(iValue);
try {
_source = iValue.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
throw OException.wrapException(new OSerializationException("Error reading content from string"), e);
}

removeAllCollectionChangeListeners();

Expand Down
Expand Up @@ -173,7 +173,7 @@ public synchronized byte[] digestSHA256(final String iInput) {

public String createHashWithSalt(final String iPassword) {
return createHashWithSalt(iPassword, OGlobalConfiguration.SECURITY_USER_PASSWORD_SALT_ITERATIONS.getValueAsInteger(),
PBKDF2_SHA256_ALGORITHM);
OGlobalConfiguration.SECURITY_USER_PASSWORD_DEFAULT_ALGORITHM.getValueAsString());
}

public String createHashWithSalt(final String iPassword, final int iIterations, final String algorithm) {
Expand All @@ -188,7 +188,7 @@ public String createHashWithSalt(final String iPassword, final int iIterations,
}

public boolean checkPasswordWithSalt(final String iPassword, final String iHash) {
return checkPasswordWithSalt(iPassword, iHash, OSecurityManager.PBKDF2_SHA256_ALGORITHM);
return checkPasswordWithSalt(iPassword, iHash, OGlobalConfiguration.SECURITY_USER_PASSWORD_DEFAULT_ALGORITHM.getValueAsString());
}

public boolean checkPasswordWithSalt(final String iPassword, final String iHash, final String algorithm) {
Expand Down

0 comments on commit 5f9be64

Please sign in to comment.