/** * Return a shallow copy of this object - value is NOT cloned! * @return Shallow copy of object */ public Object clone() { Constant copy = new Constant(getValue(), getType()); copy.multiValued = multiValued; copy.bindEligible = bindEligible; return copy; }
/** * Return a shallow copy of this object - value is NOT cloned! * @return Shallow copy of object */ public Object clone() { Constant copy = new Constant(getValue(), getType()); copy.multiValued = multiValued; copy.bindEligible = bindEligible; return copy; }
/** * Return a shallow copy of this object - value is NOT cloned! * @return Shallow copy of object */ public Object clone() { Constant copy = new Constant(getValue(), getType()); copy.multiValued = multiValued; copy.bindEligible = bindEligible; return copy; }
@Override public void visit(Constant c) { if (c.isMultiValued()) { notCachable(); } else if (DataTypeManager.isLOB(c.getType())) { if (parameters == null) { parameters = new ArrayList<Object>(); } parameters.add(c.getValue()); } }
@Override public void visit(Constant c) { if (c.isMultiValued()) { notCachable(); } else if (DataTypeManager.isLOB(c.getType())) { if (parameters == null) { parameters = new ArrayList<Object>(); } parameters.add(c.getValue()); } }
@Override public void visit(Constant c) { if (c.isMultiValued()) { notCachable(); } else if (DataTypeManager.isLOB(c.getType())) { if (parameters == null) { parameters = new ArrayList<Object>(); } parameters.add(c.getValue()); } }
@Override public void visit( Constant obj ) { Class<?> type = obj.getType(); boolean multiValued = obj.isMultiValued(); Object value = obj.getValue(); outputLiteral(type, multiValued, value); }
@Override public void visit( Constant obj ) { Class<?> type = obj.getType(); boolean multiValued = obj.isMultiValued(); Object value = obj.getValue(); outputLiteral(type, multiValued, value); }
@Override public void visit( Constant obj ) { Class<?> type = obj.getType(); boolean multiValued = obj.isMultiValued(); Object value = obj.getValue(); outputLiteral(type, multiValued, value); }
/** * TODO: does not check for escape char * or if it will contain single match chars */ private static float estimateMatchCost(float childCost, float ndv, MatchCriteria criteria) { Expression matchExpression = criteria.getRightExpression(); if(matchExpression instanceof Constant && ((Constant)matchExpression).getType().equals(DataTypeManager.DefaultDataClasses.STRING)) { String compareValue = (String) ((Constant)matchExpression).getValue(); if(criteria.getMode() != MatchMode.REGEX && criteria.getEscapeChar() == MatchCriteria.NULL_ESCAPE_CHAR && compareValue != null && compareValue.indexOf('%') < 0) { return (childCost / 2) * (1 / 3f + 1 / ndv); //without knowing length constraints we'll make an average guess } } else if (EvaluatableVisitor.willBecomeConstant(criteria.getLeftExpression())) { if (ndv > Math.sqrt(childCost)) { return (float) Math.sqrt(childCost - ndv); } return childCost/ndv; } return childCost / 3; }
/** * TODO: does not check for escape char * or if it will contain single match chars */ private static float estimateMatchCost(float childCost, float ndv, MatchCriteria criteria) { Expression matchExpression = criteria.getRightExpression(); if(matchExpression instanceof Constant && ((Constant)matchExpression).getType().equals(DataTypeManager.DefaultDataClasses.STRING)) { String compareValue = (String) ((Constant)matchExpression).getValue(); if(criteria.getMode() != MatchMode.REGEX && criteria.getEscapeChar() == MatchCriteria.NULL_ESCAPE_CHAR && compareValue != null && compareValue.indexOf('%') < 0) { return (childCost / 2) * (1 / 3f + 1 / ndv); //without knowing length constraints we'll make an average guess } } else if (EvaluatableVisitor.willBecomeConstant(criteria.getLeftExpression())) { if (ndv > Math.sqrt(childCost)) { return (float) Math.sqrt(childCost - ndv); } return childCost/ndv; } return childCost / 3; }
/** * TODO: does not check for escape char * or if it will contain single match chars */ private static float estimateMatchCost(float childCost, float ndv, MatchCriteria criteria) { Expression matchExpression = criteria.getRightExpression(); if(matchExpression instanceof Constant && ((Constant)matchExpression).getType().equals(DataTypeManager.DefaultDataClasses.STRING)) { String compareValue = (String) ((Constant)matchExpression).getValue(); if(criteria.getMode() != MatchMode.REGEX && criteria.getEscapeChar() == MatchCriteria.NULL_ESCAPE_CHAR && compareValue != null && compareValue.indexOf('%') < 0) { return (childCost / 2) * (1 / 3f + 1 / ndv); //without knowing length constraints we'll make an average guess } } else if (EvaluatableVisitor.willBecomeConstant(criteria.getLeftExpression())) { if (ndv > Math.sqrt(childCost)) { return (float) Math.sqrt(childCost - ndv); } return childCost/ndv; } return childCost / 3; }
public static Literal example(int val) { Constant c = helpExample(val); return new Literal(c.getValue(), c.getType()); }
public static Literal example(Object val) { Constant c = helpExample(val); return new Literal(c.getValue(), c.getType()); }
@Test public void testArrayImplType() { Constant c = new Constant(new ArrayImpl(new Integer[0])); assertEquals(DataTypeManager.getArrayType(DefaultDataClasses.OBJECT), c.getType()); }
@Test public void testArrayCompare() { Constant c = new Constant(new ArrayImpl(new Integer[0])); assertEquals(DataTypeManager.getArrayType(DefaultDataClasses.OBJECT), c.getType()); }
@Test public void testInteger() { Integer i = new Integer(5); Constant c = new Constant(i); assertEquals("Value is incorrect: ", i, c.getValue()); //$NON-NLS-1$ assertEquals("Type is incorrect: ", DataTypeManager.DefaultDataClasses.INTEGER, c.getType()); //$NON-NLS-1$ assertEquals("Should be non-null: ", false, c.isNull()); //$NON-NLS-1$ assertEquals("Object does not equal itself", c, c); //$NON-NLS-1$ Constant c2 = new Constant(i); assertEquals("Constants for same object aren't equal: ", c, c2); //$NON-NLS-1$ Constant cc = (Constant) c.clone(); assertEquals("Cloned object not equal to original: ", c, cc); //$NON-NLS-1$ }
@Test public void testNoTypeNull() { Constant c = new Constant(null); assertEquals("Value is incorrect: ", null, c.getValue()); //$NON-NLS-1$ assertEquals("Type is incorrect: ", DataTypeManager.DefaultDataClasses.NULL, c.getType()); //$NON-NLS-1$ assertEquals("Should be null: ", true, c.isNull()); //$NON-NLS-1$ assertEquals("Object does not equal itself", c, c); //$NON-NLS-1$ Constant c2 = new Constant(null); assertEquals("Constants for same object aren't equal: ", c, c2); //$NON-NLS-1$ Constant cc = (Constant) c.clone(); assertEquals("Cloned object not equal to original: ", c, cc); //$NON-NLS-1$ }
@Test public void testString() { String s = "the string"; //$NON-NLS-1$ Constant c = new Constant(s); assertEquals("Value is incorrect: ", s, c.getValue()); //$NON-NLS-1$ assertEquals("Type is incorrect: ", DataTypeManager.DefaultDataClasses.STRING, c.getType()); //$NON-NLS-1$ assertEquals("Should be non-null: ", false, c.isNull()); //$NON-NLS-1$ assertEquals("Object does not equal itself", c, c); //$NON-NLS-1$ Constant c2 = new Constant(s); assertEquals("Constants for same object aren't equal: ", c, c2); //$NON-NLS-1$ Constant cc = (Constant) c.clone(); assertEquals("Cloned object not equal to original: ", c, cc); //$NON-NLS-1$ }
@Test public void testTypedNull() { Constant c = new Constant(null, DataTypeManager.DefaultDataClasses.STRING); assertEquals("Value is incorrect: ", null, c.getValue()); //$NON-NLS-1$ assertEquals("Type is incorrect: ", DataTypeManager.DefaultDataClasses.STRING, c.getType()); //$NON-NLS-1$ assertEquals("Should be null: ", true, c.isNull()); //$NON-NLS-1$ assertEquals("Object does not equal itself", c, c); //$NON-NLS-1$ Constant c2 = new Constant(null, DataTypeManager.DefaultDataClasses.STRING); assertEquals("Constants for same object aren't equal: ", c, c2); //$NON-NLS-1$ Constant cc = (Constant) c.clone(); assertEquals("Cloned object not equal to original: ", c, cc); //$NON-NLS-1$ Constant c3 = new Constant(null); assertEquals("Typed null not equal to non-typed null: ", c, c3); //$NON-NLS-1$ }