1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.types.BitDataValue; 25 import org.apache.derby.iapi.types.TypeId; 26 import org.apache.derby.iapi.types.DataValueFactory; 27 28 import org.apache.derby.iapi.error.StandardException; 29 30 import org.apache.derby.iapi.services.compiler.MethodBuilder; 31 32 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 33 34 import org.apache.derby.iapi.services.io.FormatableBitSet; 35 import org.apache.derby.iapi.util.ReuseFactory; 36 import org.apache.derby.iapi.reference.ClassName; 37 import org.apache.derby.iapi.services.classfile.VMOpcode; 38 39 import java.sql.Types ; 40 41 public class BitConstantNode extends ConstantNode 42 { 43 44 private int bitLength; 45 46 47 54 55 public void init( 56 Object arg1) 57 throws StandardException 58 { 59 super.init( 60 arg1, 61 Boolean.TRUE, 62 ReuseFactory.getInteger(0)); 63 } 64 65 public void init( 66 Object arg1, Object arg2) 67 throws StandardException 68 { 69 String a1 = (String ) arg1; 70 71 byte[] nv = org.apache.derby.iapi.util.StringUtil.fromHexString(a1, 0, a1.length()); 72 73 Integer bitLengthO = (Integer ) arg2; 74 bitLength = bitLengthO.intValue(); 75 76 init( 77 TypeId.getBuiltInTypeId(Types.BINARY), 78 Boolean.FALSE, 79 bitLengthO); 80 81 org.apache.derby.iapi.types.BitDataValue dvd = getDataValueFactory().getBitDataValue(nv); 82 83 dvd.setWidth(bitLength, 0, false); 84 85 setValue(dvd); 86 } 87 88 97 public void init( 98 Object typeId, 99 Object nullable, 100 Object maximumWidth) 101 throws StandardException 102 { 103 init( 104 typeId, 105 ReuseFactory.getInteger(0), 106 ReuseFactory.getInteger(0), 107 nullable, 108 maximumWidth); 109 } 110 111 112 124 Object getConstantValueAsObject() 125 throws StandardException 126 { 127 return value.getBytes(); 128 } 129 130 138 void generateConstant(ExpressionClassBuilder acb, MethodBuilder mb) 139 throws StandardException 140 { 141 byte[] bytes = value.getBytes(); 142 143 String hexLiteral = org.apache.derby.iapi.util.StringUtil.toHexString(bytes, 0, bytes.length); 144 145 mb.push(hexLiteral); 146 mb.push(0); 147 mb.push(hexLiteral.length()); 148 149 mb.callMethod(VMOpcode.INVOKESTATIC, "org.apache.derby.iapi.util.StringUtil", "fromHexString", 150 "byte[]", 3); 151 } 152 } 153 | Popular Tags |