Package org.hsqldb.lib

Examples of org.hsqldb.lib.HsqlArrayList


    private boolean setOrConditions(RangeVariableConditions conditions,
                                    ExpressionLogical orExpression,
                                    int rangeVarIndex) {

        HsqlArrayList orExprList = new HsqlArrayList();

        decomposeOrConditions(orExpression, orExprList);

        RangeVariableConditions[] conditionsArray =
            new RangeVariableConditions[orExprList.size()];

        for (int i = 0; i < orExprList.size(); i++) {
            HsqlArrayList exprList = new HsqlArrayList();
            Expression    e        = (Expression) orExprList.get(i);

            decomposeAndConditions(e, exprList);

            RangeVariableConditions c =
View Full Code Here


    }

    /** Runs a test on the hsqldb lists */
    public void testLists() {

        HsqlArrayList  arrayList  = new HsqlArrayList();
        HsqlLinkedList linkedList = new HsqlLinkedList();
        Vector         vector     = new Vector();
        Vector listCommandsCalled = new Vector(NUMBER_OF_ITERATIONS_PER_RUN);
        Integer        tempInt    = null;
        int            tempCommandCode;
        int            tempPosition;
        boolean        arrayListException  = false;
        boolean        linkedListException = false;
        boolean        vectorException     = false;
        Object         arrayListObject     = null;
        Object         linkedListObject    = null;
        Object         vectorObject        = null;

        for (int i = 0; i < getRandomInt(3, 12); i++) {    // prime the contents with a couple items
            tempInt = getRandomInteger();

            arrayList.add(tempInt);
            linkedList.add(tempInt);
            vector.addElement(tempInt);
            listCommandsCalled.addElement("Add");
        }

        compareLists(arrayList, linkedList, vector);

        for (int j = 0; j < NUMBER_OF_ITERATIONS_PER_RUN; j++) {
            tempCommandCode = getRandomInt(0, 15);    // 0 and 8 are ignored or used for a special op

            switch (tempCommandCode) {

                case ADD :
                    tempInt = getRandomInteger();

                    listCommandsCalled.addElement("Add");
                    arrayList.add(tempInt);
                    linkedList.add(tempInt);
                    vector.addElement(tempInt);
                    break;

                case ADD_AT :
                    tempInt      = getRandomInteger();
                    tempPosition = getRandomInt(0, vector.size());

                    listCommandsCalled.addElement("Add at " + tempPosition);

                    try {
                        arrayList.add(tempPosition, tempInt);
                    } catch (Exception ex) {
                        arrayListException = true;
                    }

                    try {
                        linkedList.add(tempPosition, tempInt);
                    } catch (Exception ex) {
                        linkedListException = true;
                    }

                    try {
                        vector.insertElementAt(tempInt, tempPosition);
                    } catch (Exception ex) {
                        vectorException = true;
                    }
                    break;

                case GET :
                    tempPosition = getRandomInt(0, vector.size() -1);

                    listCommandsCalled.addElement("Get " + tempPosition);

                    try {
                        arrayListObject = arrayList.get(tempPosition);
                    } catch (Exception ex) {
                        arrayListException = true;
                    }

                    try {
                        linkedListObject = linkedList.get(tempPosition);
                    } catch (Exception ex) {
                        linkedListException = true;
                    }

                    try {
                        vectorObject = vector.elementAt(tempPosition);
                    } catch (Exception ex) {
                        vectorException = true;
                    }
                    break;

                case REMOVE :
                    tempPosition = getRandomInt(0, vector.size() - 1);

                    listCommandsCalled.addElement("Remove " + tempPosition);

                    try {
                        arrayListObject = arrayList.remove(tempPosition);
                    } catch (Exception ex) {
                        arrayListException = true;
                    }

                    try {
                        linkedListObject = linkedList.remove(tempPosition);
                    } catch (Exception ex) {
                        linkedListException = true;
                    }

                    try {
                        vectorObject = vector.elementAt(tempPosition);

                        vector.removeElementAt(tempPosition);
                    } catch (Exception ex) {
                        vectorException = true;
                    }
                    break;

                case SET :
                    tempInt      = getRandomInteger();
                    tempPosition = getRandomInt(0, vector.size() -1);

                    listCommandsCalled.addElement("Set " + tempPosition);

                    try {
                        arrayList.set(tempPosition, tempInt);
                    } catch (Exception ex) {
                        arrayListException = true;
                    }

                    try {
                        linkedList.set(tempPosition, tempInt);
                    } catch (Exception ex) {
                        linkedListException = true;
                    }

                    try {
                        vector.setElementAt(tempInt, tempPosition);
                    } catch (Exception ex) {
                        vectorException = true;
                    }
                    break;

                case OPTIMIZE :
                    listCommandsCalled.addElement("Optimize");
                    arrayList.trim();
                    vector.trimToSize();
                    break;

                case REMOVE_ALL :
                    if (getRandomInt(0, 5) == 4) {    // to limit the frequency of this call
                        listCommandsCalled.addElement("Remove all");

                        if (vector.size() == 0) {
                            break;
                        }

                        for (int k = arrayList.size() - 1; k >= 0; k--) {
                            arrayList.remove(k);
                            linkedList.remove(k);
                        }

                        vector.removeAllElements();
                    }
View Full Code Here

        return true;
    }

    public void testGrowth() {

        HsqlArrayList d = new HsqlArrayList();

        for (int i = 0; i < 12; i++) {
            d.add(new Integer(i));
        }

        for (int i = 0; i < d.size(); i++) {
            System.out.println(d.get(i));
        }

        d = new HsqlArrayList();

        for (int i = 0; i < 12; i++) {
            d.add(new Integer(i));
        }

        d.set(11, new Integer(11));

        for (int i = 0; i < d.size(); i++) {
            System.out.println(d.get(i));
        }

        org.hsqldb.lib.Iterator it = d.iterator();

        for (int i = 0; it.hasNext(); i++) {
            Integer value = (Integer) it.next();

            System.out.println(value);
            assertEquals(i, value.intValue());
        }

        //-
        assertEquals(12, d.size());
    }
View Full Code Here

        randomGenerator = new Random(System.currentTimeMillis());

        int           TEST_RUNS     = 100000;
        int           LOOP_COUNT    = 1000;
        HsqlArrayList arrayList     = new HsqlArrayList(TEST_RUNS);
        ArrayList     utilArrayList = new ArrayList(TEST_RUNS);
        Vector        vector        = new Vector(TEST_RUNS);
        Integer       value         = new Integer(randomGenerator.nextInt());
        Integer       INT_0         = new Integer(0);
        StopWatch     sw            = new StopWatch();

        System.out.println(sw.currentElapsedTimeToMessage("time"));

        for (int i = 0; i < TEST_RUNS; i++) {
            arrayList.add(INT_0);
        }

        for (int i = 0; i < TEST_RUNS; i++) {
            for (int j = 0; j < LOOP_COUNT; j++) {
                arrayList.set(i, INT_0);
            }
        }

        System.out.println(sw.currentElapsedTimeToMessage("time HsqlArrayLsit"));
        sw.zero();
View Full Code Here

    }

    public void push() {

        if (stack == null) {
            stack = new HsqlArrayList(true);
        }

        stack.add(dynamicArguments);
        stack.add(routineArguments);
        stack.add(routineVariables);
View Full Code Here

        return 0;
    }

    public String[] getSQLArray() {

        HsqlArrayList list = new HsqlArrayList();

        for (int i = 0; i < routines.length; i++) {
            list.add(routines[i].getSQL());
        }

        String[] array = new String[list.size()];

        list.toArray(array);

        return array;
    }
View Full Code Here

        return array;
    }

    public String[] getTablePropsSQL(boolean withHeader) {

        HsqlArrayList tableList = getAllTables();
        HsqlArrayList list      = new HsqlArrayList();

        for (int i = 0; i < tableList.size(); i++) {
            Table t = (Table) tableList.get(i);

            if (t.isText()) {
                String[] ddl = t.getSQLForTextSource(withHeader);

                list.addAll(ddl);
            } else {
                String ddl = t.getSQLForReadOnly();

                if (ddl != null) {
                    list.add(ddl);
                }
            }
        }

        String[] array = new String[list.size()];

        list.toArray(array);

        return array;
    }
View Full Code Here

    public String[] getIndexRootsSQL() {

        Session       sysSession = database.sessionManager.getSysSession();
        int[][]       rootsArray = getIndexRoots(sysSession);
        HsqlArrayList tableList  = getAllTables();
        HsqlArrayList list       = new HsqlArrayList();

        for (int i = 0; i < rootsArray.length; i++) {
            Table t = (Table) tableList.get(i);

            if (rootsArray[i] != null && rootsArray[i].length > 0
                    && rootsArray[i][0] != -1) {
                String ddl =
                    ((Table) tableList.get(i)).getIndexRootsSQL(rootsArray[i]);

                list.add(ddl);
            }
        }

        String[] array = new String[list.size()];

        list.toArray(array);

        return array;
    }
View Full Code Here

        return array;
    }

    public String[] getCommentsArray() {

        HsqlArrayList tableList = getAllTables();
        HsqlArrayList list      = new HsqlArrayList();
        StringBuffer  sb        = new StringBuffer();

        for (int i = 0; i < tableList.size(); i++) {
            Table table = (Table) tableList.get(i);

            if (table.getTableType() == Table.SYSTEM_TABLE) {
                continue;
            }

            int colCount = table.getColumnCount();

            for (int j = 0; j < colCount; j++) {
                ColumnSchema column = table.getColumn(j);

                if (column.getName().comment == null) {
                    continue;
                }

                sb.setLength(0);
                sb.append(Tokens.T_COMMENT).append(' ').append(Tokens.T_ON);
                sb.append(' ').append(Tokens.T_COLUMN).append(' ');
                sb.append(table.getName().getSchemaQualifiedStatementName());
                sb.append('.').append(column.getName().statementName);
                sb.append(' ').append(Tokens.T_IS).append(' ');
                sb.append(
                    StringConverter.toQuotedString(
                        column.getName().comment, '\'', true));
                list.add(sb.toString());
            }

            if (table.getName().comment == null) {
                continue;
            }

            sb.setLength(0);
            sb.append(Tokens.T_COMMENT).append(' ').append(Tokens.T_ON);
            sb.append(' ').append(Tokens.T_TABLE).append(' ');
            sb.append(table.getName().getSchemaQualifiedStatementName());
            sb.append(' ').append(Tokens.T_IS).append(' ');
            sb.append(StringConverter.toQuotedString(table.getName().comment,
                    '\'', true));
            list.add(sb.toString());
        }

        Iterator it = databaseObjectIterator(SchemaObject.ROUTINE);

        while (it.hasNext()) {
            SchemaObject object = (SchemaObject) it.next();

            if (object.getName().comment == null) {
                continue;
            }

            sb.setLength(0);
            sb.append(Tokens.T_COMMENT).append(' ').append(Tokens.T_ON);
            sb.append(' ').append(Tokens.T_ROUTINE).append(' ');
            sb.append(object.getName().getSchemaQualifiedStatementName());
            sb.append(' ').append(Tokens.T_IS).append(' ');
            sb.append(StringConverter.toQuotedString(object.getName().comment,
                    '\'', true));
            list.add(sb.toString());
        }

        String[] array = new String[list.size()];

        list.toArray(array);

        return array;
    }
View Full Code Here

            tempIndexRoots = null;

            return roots;
        }

        HsqlArrayList allTables = getAllTables();
        HsqlArrayList list      = new HsqlArrayList();

        for (int i = 0, size = allTables.size(); i < size; i++) {
            Table t = (Table) allTables.get(i);

            if (t.getTableType() == TableBase.CACHED_TABLE) {
                int[] roots = t.getIndexRootsArray();

                list.add(roots);
            } else {
                list.add(null);
            }
        }

        int[][] array = new int[list.size()][];

        list.toArray(array);

        return array;
    }
View Full Code Here

TOP

Related Classes of org.hsqldb.lib.HsqlArrayList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.