Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into fix/partialDeleteM…
Browse files Browse the repository at this point in the history
…ultiValueIndex
  • Loading branch information
danrub committed Mar 2, 2015
2 parents bb0eb7c + fea808f commit f1f77f3
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,18 @@
import java.io.ObjectOutput;
import java.lang.ref.WeakReference;
import java.text.ParseException;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.orientechnologies.common.collection.OMultiValue;
import com.orientechnologies.common.io.OIOUtils;
Expand All @@ -38,7 +48,19 @@
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.record.*;
import com.orientechnologies.orient.core.db.record.ODetachable;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.db.record.OMultiValueChangeListener;
import com.orientechnologies.orient.core.db.record.OMultiValueChangeTimeLine;
import com.orientechnologies.orient.core.db.record.ORecordElement;
import com.orientechnologies.orient.core.db.record.ORecordLazyList;
import com.orientechnologies.orient.core.db.record.ORecordLazyMap;
import com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue;
import com.orientechnologies.orient.core.db.record.ORecordLazySet;
import com.orientechnologies.orient.core.db.record.OTrackedList;
import com.orientechnologies.orient.core.db.record.OTrackedMap;
import com.orientechnologies.orient.core.db.record.OTrackedMultiValue;
import com.orientechnologies.orient.core.db.record.OTrackedSet;
import com.orientechnologies.orient.core.db.record.ridbag.ORidBag;
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.exception.ODatabaseException;
Expand Down Expand Up @@ -1154,7 +1176,55 @@ public ODocument merge(final ODocument iOther, boolean iUpdateOnlyMode, boolean
*/
public ODocument merge(final Map<String, Object> iOther, final boolean iUpdateOnlyMode,
boolean iMergeSingleItemsOfMultiValueFields) {
throw new UnsupportedOperationException();
checkForLoading();
checkForFields();

_source = null;

for (String f : iOther.keySet()) {
final Object value = field(f);
final Object otherValue = iOther.get(f);

if (containsField(f) && iMergeSingleItemsOfMultiValueFields) {
if (value instanceof Map<?, ?>) {
final Map<String, Object> map = (Map<String, Object>) value;
final Map<String, Object> otherMap = (Map<String, Object>) otherValue;

for (Entry<String, Object> entry : otherMap.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
continue;
} else if (OMultiValue.isMultiValue(value)) {
for (Object item : OMultiValue.getMultiValueIterable(otherValue)) {
if (!OMultiValue.contains(value, item))
OMultiValue.add(value, item);
}

// JUMP RAW REPLACE
continue;
}
}

// RESET THE FIELD TYPE
setFieldType(f, null);

boolean bagsMerged = false;
if (value instanceof ORidBag && otherValue instanceof ORidBag)
bagsMerged = ((ORidBag) value).tryMerge((ORidBag) otherValue, iMergeSingleItemsOfMultiValueFields);

if (!bagsMerged && (value != null && !value.equals(otherValue)) || (value == null && otherValue != null))
field(f, otherValue);
}

if (!iUpdateOnlyMode) {
// REMOVE PROPERTIES NOT FOUND IN OTHER DOC
for (String f : fieldNames())
if (!iOther.containsKey(f))
removeField(f);
}

return this;

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
*/
package com.orientechnologies.orient.core.serialization.serializer.record.string;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.orientechnologies.common.profiler.OProfilerMBean;
import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
Expand All @@ -38,15 +47,6 @@
import com.orientechnologies.orient.core.serialization.serializer.string.OStringSerializerEmbedded;
import com.orientechnologies.orient.core.util.ODateHelper;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@SuppressWarnings("serial")
public abstract class ORecordSerializerStringAbstract implements ORecordSerializer, Serializable {
protected static final OProfilerMBean PROFILER = Orient.instance().getProfiler();
Expand Down Expand Up @@ -325,8 +325,11 @@ else if (c == 's')

// CHECK IF THE DECIMAL NUMBER IS A FLOAT OR DOUBLE
final double dou = Double.parseDouble(iValue);
if (dou <= Float.MAX_VALUE || dou >= Float.MIN_VALUE)
if ((dou <= Float.MAX_VALUE || dou >= Float.MIN_VALUE) && new Double(new Double(dou).floatValue()).doubleValue() == dou) {
return OType.FLOAT;
} else if (!new Double(dou).toString().equals(iValue)) {
return OType.DECIMAL;
}

return OType.DOUBLE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
*/
package com.orientechnologies.orient.core.sql;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.orientechnologies.common.collection.OMultiValue;
import com.orientechnologies.common.io.OIOUtils;
import com.orientechnologies.common.parser.OBaseParser;
Expand All @@ -42,13 +50,6 @@
import com.orientechnologies.orient.core.sql.filter.OSQLPredicate;
import com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/**
* SQL Helper class
*
Expand Down Expand Up @@ -166,6 +167,8 @@ else if (t == OType.BYTE)
return Byte.parseByte(iValue);
else if (t == OType.DOUBLE)
return Double.parseDouble(iValue);
else if (t == OType.DECIMAL)
return new BigDecimal(iValue);
else if (t == OType.DATE || t == OType.DATETIME)
return new Date(Long.parseLong(iValue));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@

package com.orientechnologies.orient.core.sql;

import java.io.IOException;
import java.io.Reader;
import com.orientechnologies.orient.core.command.script.OCommandScript;

import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
import java.io.IOException;
import java.io.Reader;

/**
* Dynamic script engine for OrientDB SQL commands. This implementation is multi-threads.
Expand Down Expand Up @@ -67,7 +68,7 @@ public Object eval(Reader reader) throws ScriptException {

@Override
public Object eval(String script, Bindings n) throws ScriptException {
return new OCommandSQL(script).execute(n);
return new OCommandScript(script).execute(n);
}

@Override
Expand All @@ -80,7 +81,7 @@ public Object eval(Reader reader, Bindings n) throws ScriptException {
throw new ScriptException(e);
}

return new OCommandSQL(buffer.toString()).execute(n);
return new OCommandScript(buffer.toString()).execute(n);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.orientechnologies.orient.core.sql;

import static org.testng.AssertJUnit.assertEquals;
import java.math.BigDecimal;
import java.util.List;

import org.testng.annotations.Test;

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;

public class BigDecimalQuerySupportTest {

@Test
public void testDecimalPrecision() throws Exception {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + BigDecimalQuerySupportTest.class.getName());
db.create();
try {

db.command(new OCommandSQL("CREATE Class Test")).execute();
db.command(new OCommandSQL("CREATE Property Test.salary DECIMAL")).execute();
db.command(new OCommandSQL("INSERT INTO Test set salary = ?")).execute(new BigDecimal("179999999999.99999999999999999999"));
List<ODocument> list = db.query(new OSQLSynchQuery<ODocument>("SELECT * FROM Test"));

ODocument doc = (ODocument) list.get(0);
BigDecimal salary = doc.field("salary");

assertEquals(new BigDecimal("179999999999.99999999999999999999"), salary);
} finally {
db.drop();
}
}

}

0 comments on commit f1f77f3

Please sign in to comment.