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; 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 java.util.Map;


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


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


private final O2QCache readCache; private final O2QCache readCache;


public OEngineLocalPaginated() { public OEngineLocalPaginated() {
readCache = new O2QCache(calculateReadCacheMaxMemory(OGlobalConfiguration.DISK_CACHE_SIZE.getValueAsLong() * 1024 * 1024), 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) { public OStorage createStorage(final String dbName, final Map<String, String> configuration) {
try { try {
// GET THE STORAGE try {
return new OLocalPaginatedStorage(dbName, dbName, getMode(configuration), generateStorageId(), readCache); 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) { } catch (Exception e) {
final String message = "Error on opening database: " + dbName + ". Current location is: " final String message =
+ new java.io.File(".").getAbsolutePath(); "Error on opening database: " + dbName + ". Current location is: " + new java.io.File(".").getAbsolutePath();
OLogManager.instance().error(this, message, e); OLogManager.instance().error(this, message, e);


throw OException.wrapException(new ODatabaseException(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); onIndexEngineChange(indexId);


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


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


onIndexEngineChange(indexId); onIndexEngineChange(indexId);


long documentNum = 0; documentIndexed = fillIndex(iProgressListener);
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 Exception e) { } catch (final Exception e) {
if (iProgressListener != null)
iProgressListener.onCompletition(this, false);

try { try {
if (indexId >= 0) if (indexId >= 0)
storage.clearIndex(indexId); storage.clearIndex(indexId);
Expand All @@ -477,6 +457,35 @@ public long rebuild(final OProgressListener iProgressListener) {
return documentIndexed; 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) { public boolean remove(Object key, final OIdentifiable value) {
return remove(key); return remove(key);
} }
Expand Down
Expand Up @@ -19,6 +19,7 @@
*/ */
package com.orientechnologies.orient.core.metadata.schema; package com.orientechnologies.orient.core.metadata.schema;


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


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

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


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


import com.orientechnologies.common.log.OLogManager; import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.annotation.OAfterDeserialization; 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.db.record.OIdentifiable;
import com.orientechnologies.orient.core.exception.OSecurityAccessException; import com.orientechnologies.orient.core.exception.OSecurityAccessException;
import com.orientechnologies.orient.core.exception.OSecurityException; 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) { 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 @Override
Expand Down
Expand Up @@ -17,15 +17,15 @@ public class ODirtyManager {


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


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


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


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


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


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


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


public void removePointed(ORecord 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.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.record.*; import com.orientechnologies.orient.core.db.record.*;
import com.orientechnologies.orient.core.db.record.ridbag.ORidBag; import com.orientechnologies.orient.core.db.record.ridbag.ORidBag;
import com.orientechnologies.orient.core.exception.OConfigurationException; import com.orientechnologies.orient.core.exception.*;
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.id.ORID; import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.id.ORecordId; import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.iterator.OEmptyMapEntryIterator; 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.OTransaction;
import com.orientechnologies.orient.core.tx.OTransactionOptimistic; import com.orientechnologies.orient.core.tx.OTransactionOptimistic;


import java.io.ByteArrayOutputStream; import java.io.*;
import java.io.Externalizable;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
Expand Down Expand Up @@ -711,7 +701,11 @@ public String toString() {
public void fromString(final String iValue) { public void fromString(final String iValue) {
_dirty = true; _dirty = true;
_contentChanged = 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(); removeAllCollectionChangeListeners();


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


public String createHashWithSalt(final String iPassword) { public String createHashWithSalt(final String iPassword) {
return createHashWithSalt(iPassword, OGlobalConfiguration.SECURITY_USER_PASSWORD_SALT_ITERATIONS.getValueAsInteger(), 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) { 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) { 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) { public boolean checkPasswordWithSalt(final String iPassword, final String iHash, final String algorithm) {
Expand Down

0 comments on commit 5f9be64

Please sign in to comment.