@Test public void testGetInstanceById() { try { InstanceElement ie = applicationElement.getInstanceById(ODSHelper.asODSLongLong(58)); assertEquals("1/3 Octave - Zusammenfassung", ie.getName()); assertEquals(58, ODSHelper.asJLong(ie.getId())); } catch (AoException e) { fail(e.reason); } // query non existing instance try { applicationElement.getInstanceById(ODSHelper.asODSLongLong(999)); fail("AoException expected"); } catch (AoException e) { } }
@Test public void testRemoveInstance() { try { assertEquals(3, applicationElement.getInstances("*").getCount()); InstanceElement ie = applicationElement.createInstance("new_instance"); assertEquals(4, applicationElement.getInstances("*").getCount()); assertEquals(ie.getName(), applicationElement.getInstanceByName("new_instance").getName()); applicationElement.removeInstance(ie.getId(), false); assertEquals(3, applicationElement.getInstances("*").getCount()); assertEquals(null, applicationElement.getInstanceByName("new_instance")); } catch (AoException e) { fail(e.reason); } // non existing instance try { applicationElement.removeInstance(ODSHelper.asODSLongLong(999), false); fail("AoException expected"); } catch (AoException e) { } }
public TS_Value readValues(AtfxCache atfxCache, long iidLc, DataType targetDataType) throws AoException { // read external component instances long aidLc = atfxCache.getAidsByBaseType("aolocalcolumn").iterator().next(); ApplicationRelation relExtComps = atfxCache.getApplicationRelationByBaseName(aidLc, "external_component"); List<Long> iidExtComps = atfxCache.getRelatedInstanceIds(aidLc, iidLc, relExtComps); if (iidExtComps.size() > 0) { Collections.sort(iidExtComps, new ExternalComponentComparator(atfxCache)); } TS_Value tsValue = new TS_Value(); tsValue.flag = (short) 15; tsValue.u = new TS_Union(); // get raw data type DataType rawDataType = targetDataType; Integer attrNo = atfxCache.getAttrNoByBaName(aidLc, "raw_datatype"); if (attrNo != null) { TS_Value valRawDatatype = atfxCache.getInstanceValue(aidLc, attrNo, iidLc); if (valRawDatatype != null && valRawDatatype.flag == 15) { int val = valRawDatatype.u.enumVal(); if (val == 1) { // DT_STRING rawDataType = DataType.DS_STRING; } else if (val == 2) { // DT_SHORT rawDataType = DataType.DS_SHORT; } else if (val == 3) { // DT_FLOAT rawDataType = DataType.DS_FLOAT; } else if (val == 4) { // DT_BOOLEAN rawDataType = DataType.DS_BOOLEAN; } else if (val == 5) { // DT_BYTE rawDataType = DataType.DS_BYTE; } else if (val == 6) { // DT_LONG rawDataType = DataType.DS_LONG; } else if (val == 7) { // DT_DOUBLE rawDataType = DataType.DS_DOUBLE; } else if (val == 8) { // DT_LONGLONG rawDataType = DataType.DS_LONGLONG; } else if (val == 10) { // DT_DATE rawDataType = DataType.DS_DATE; } else if (val == 11) { // DT_BYTESTR rawDataType = DataType.DS_BYTESTR; } else if (val == 13) { // DT_COMPLEX rawDataType = DataType.DS_COMPLEX; } else if (val == 14) { // DT_DCOMPLEX rawDataType = DataType.DS_DCOMPLEX; } else if (val == 28) { // DT_EXTERNALREFERENCE rawDataType = DataType.DS_EXTERNALREFERENCE; } else if (val == 30) { // DT_ENUM rawDataType = DataType.DS_ENUM; } } } // DS_STRING if (rawDataType == DataType.DS_STRING || rawDataType == DataType.DS_BYTESTR) { List<String> list = new ArrayList<String>(); for (long iidExtComp : iidExtComps) { list.addAll(readStringValues(atfxCache, iidExtComp)); } tsValue.u.stringSeq(list.toArray(new String[0])); } // DS_DATE else if (rawDataType == DataType.DS_DATE) { List<String> list = new ArrayList<String>(); for (long iidExtComp : iidExtComps) { list.addAll(readStringValues(atfxCache, iidExtComp)); } tsValue.u.dateSeq(list.toArray(new String[0])); } // DS_NUMBER else { List<Number> list = new ArrayList<Number>(); for (long iidExtComp : iidExtComps) { list.addAll(readNumberValues(atfxCache, iidExtComp, rawDataType)); } // DS_BOOLEAN if (rawDataType == DataType.DS_BOOLEAN) { boolean[] ar = new boolean[list.size()]; for (int i = 0; i < list.size(); i++) { ar[i] = list.get(i).byteValue() != 0; } tsValue.u.booleanSeq(ar); } // DS_BYTE else if (rawDataType == DataType.DS_BYTE) { byte[] ar = new byte[list.size()]; for (int i = 0; i < list.size(); i++) { ar[i] = list.get(i).byteValue(); } tsValue.u.byteSeq(ar); } // DS_SHORT else if (rawDataType == DataType.DS_SHORT) { short[] ar = new short[list.size()]; for (int i = 0; i < list.size(); i++) { ar[i] = list.get(i).shortValue(); } tsValue.u.shortSeq(ar); } // DS_LONG else if (rawDataType == DataType.DS_LONG) { int[] ar = new int[list.size()]; for (int i = 0; i < list.size(); i++) { ar[i] = list.get(i).intValue(); } tsValue.u.longSeq(ar); } // DS_DOUBLE else if (rawDataType == DataType.DS_DOUBLE) { double[] ar = new double[list.size()]; for (int i = 0; i < list.size(); i++) { ar[i] = list.get(i).doubleValue(); } tsValue.u.doubleSeq(ar); } // DS_LONGLONG else if (rawDataType == DataType.DS_LONGLONG) { T_LONGLONG[] ar = new T_LONGLONG[list.size()]; for (int i = 0; i < list.size(); i++) { ar[i] = ODSHelper.asODSLongLong(list.get(i).longValue()); } tsValue.u.longlongSeq(ar); } // DS_FLOAT else if (rawDataType == DataType.DS_FLOAT) { float[] ar = new float[list.size()]; for (int i = 0; i < list.size(); i++) { ar[i] = list.get(i).floatValue(); } tsValue.u.floatSeq(ar); } // DS_COMPLEX else if (rawDataType == DataType.DS_COMPLEX) { int size = list.size() / 2; T_COMPLEX[] ar = new T_COMPLEX[size]; for (int i = 0; i < size; i++) { ar[i] = new T_COMPLEX(); ar[i].r = list.get(i * 2).floatValue(); ar[i].i = list.get(i * 2 + 1).floatValue(); } tsValue.u.complexSeq(ar); } // DS_DCOMPLEX else if (rawDataType == DataType.DS_DCOMPLEX) { int size = list.size() / 2; T_DCOMPLEX[] ar = new T_DCOMPLEX[size]; for (int i = 0; i < size; i++) { ar[i] = new T_DCOMPLEX(); ar[i].r = list.get(i * 2).doubleValue(); ar[i].i = list.get(i * 2 + 1).doubleValue(); } tsValue.u.dcomplexSeq(ar); } // unsupported else { throw new AoException( ErrorCode.AO_NOT_IMPLEMENTED, SeverityFlag.ERROR, 0, "Reading values from external component not yet supported for datatype: " + ODSHelper.dataType2String(targetDataType)); } } return tsValue; }