Example #1
0
 public override void Release()
 {
     if (IsMutable)
     {
         MutableTable.RemoveLock();
     }
 }
Example #2
0
 public override void Lock()
 {
     if (IsMutable)
     {
         MutableTable.AddLock();
     }
 }
        // @Override
        public MutableTable buildTable()
        {
            int tableObservations = getObservationCount();

            // sort column names by copying them to a TreeSet
            HashSet <String> columnNames = new HashSet <String>(_columnBuilders.Keys);  // new TreeSet<String>(_columnBuilders.keySet());

            MutableTable table        = new MutableTable(_tableName);
            int          columnNumber = 0;

            foreach (String columnName in columnNames)
            {
                InferentialColumnBuilder columnBuilder = (InferentialColumnBuilder)getColumnBuilder(columnName);
                MutableColumn            column        = columnBuilder.build();
                column.setTable(table);
                column.setColumnNumber(columnNumber);

                int columnObservations = columnBuilder.getObservationCount();
                if (tableObservations > columnObservations)
                {
                    // there may be nulls - some records does not even contain the
                    // column
                    column.setNullable(true);
                }

                table.addColumn(column);

                columnNumber++;
            }

            return(table);
        }
        // @Override
        public MutableSchema build()
        {
            MutableSchema schema = new MutableSchema(_schemaName);
            MutableTable  table  = new MutableTable(_tableName, schema);

            table.addColumn(new MutableColumn(_columnName, ColumnTypeConstants.MAP, table, 1, null, null, false, null, false, null));
            schema.addTable(table);
            return(schema);
        }
Example #5
0
        public RowId AddRow(Row row)
        {
            OnTableEvent(TriggerEventType.BeforeInsert, RowId.Null, row);

            var newRowId = MutableTable.AddRow(row);

            OnTableEvent(TriggerEventType.AfterInsert, newRowId, row);

            return(newRowId);
        }
Example #6
0
        public bool RemoveRow(RowId rowId)
        {
            OnTableEvent(TriggerEventType.BeforeDelete, rowId, null);

            // TODO: Maybe we should return the row removed here
            var result = MutableTable.RemoveRow(rowId);

            OnTableEvent(TriggerEventType.AfterDelete, rowId, null);

            return(result);
        }
Example #7
0
        // @Override
        public MutableSchema build()
        {
            MutableSchema schema = new MutableSchema(_schemaName);

            foreach (SimpleTableDef simpleTableDef in _simpleTableDefs)
            {
                MutableTable table = simpleTableDef.toTable();
                schema.addTable(table);
                table.setSchema(schema);
            }
            return(schema);
        }
        } // getSchemaByNameInternal()

        private Schema getInformationSchema()
        {
            // Create schema
            MutableSchema informationSchema  = new MutableSchema(INFORMATION_SCHEMA_NAME);
            MutableTable  tablesTable        = new MutableTable("tables", TableType.TABLE, informationSchema);
            MutableTable  columnsTable       = new MutableTable("columns", TableType.TABLE, informationSchema);
            MutableTable  relationshipsTable = new MutableTable("relationships", TableType.TABLE, informationSchema);

            informationSchema.addTable(tablesTable).addTable(columnsTable).addTable(relationshipsTable);

            // Create "tables" table: name, type, num_columns, remarks
            tablesTable.addColumn(new MutableColumn("name", ColumnTypeConstants.VARCHAR, tablesTable, 0, false));
            tablesTable.addColumn(new MutableColumn("type", ColumnTypeConstants.VARCHAR, tablesTable, 1, true));
            tablesTable.addColumn(new MutableColumn("num_columns", ColumnTypeConstants.INTEGER, tablesTable, 2, true));
            tablesTable.addColumn(new MutableColumn("remarks", ColumnTypeConstants.VARCHAR, tablesTable, 3, true));

            // Create "columns" table: name, type, native_type, size, nullable,
            // indexed, table, remarks
            columnsTable.addColumn(new MutableColumn("name", ColumnTypeConstants.VARCHAR, columnsTable, 0, false));
            columnsTable.addColumn(new MutableColumn("type", ColumnTypeConstants.VARCHAR, columnsTable, 1, true));
            columnsTable.addColumn(new MutableColumn("native_type", ColumnTypeConstants.VARCHAR, columnsTable, 2, true));
            columnsTable.addColumn(new MutableColumn("size", ColumnTypeConstants.INTEGER, columnsTable, 3, true));
            columnsTable.addColumn(new MutableColumn("nullable", ColumnTypeConstants.BOOLEAN, columnsTable, 4, true));
            columnsTable.addColumn(new MutableColumn("indexed", ColumnTypeConstants.BOOLEAN, columnsTable, 5, true));
            columnsTable.addColumn(new MutableColumn("table", ColumnTypeConstants.VARCHAR, columnsTable, 6, false));
            columnsTable.addColumn(new MutableColumn("remarks", ColumnTypeConstants.VARCHAR, columnsTable, 7, true));

            // Create "relationships" table: primary_table, primary_column,
            // foreign_table, foreign_column
            relationshipsTable
            .addColumn(new MutableColumn("primary_table", ColumnTypeConstants.VARCHAR, relationshipsTable, 0, false));
            relationshipsTable
            .addColumn(new MutableColumn("primary_column", ColumnTypeConstants.VARCHAR, relationshipsTable, 1, false));
            relationshipsTable
            .addColumn(new MutableColumn("foreign_table", ColumnTypeConstants.VARCHAR, relationshipsTable, 2, false));
            relationshipsTable
            .addColumn(new MutableColumn("foreign_column", ColumnTypeConstants.VARCHAR, relationshipsTable, 3, false));

            MutableRelationship.createRelationship(tablesTable.getColumnByName("name"),
                                                   columnsTable.getColumnByName("table"));
            MutableRelationship.createRelationship(tablesTable.getColumnByName("name"),
                                                   relationshipsTable.getColumnByName("primary_table"));
            MutableRelationship.createRelationship(tablesTable.getColumnByName("name"),
                                                   relationshipsTable.getColumnByName("foreign_table"));
            MutableRelationship.createRelationship(columnsTable.getColumnByName("name"),
                                                   relationshipsTable.getColumnByName("primary_column"));
            MutableRelationship.createRelationship(columnsTable.getColumnByName("name"),
                                                   relationshipsTable.getColumnByName("foreign_column"));

            return(informationSchema);
        } // getInformationSchema()
        } // toString()()

        /**
         * Creates a {@link MutableTable} based on this {@link SimpleTableDef}. Note
         * that the created table will not have any schema set.
         * 
         * @return a table representation of this table definition.
         */
        public MutableTable toTable()
        {
            String       name        = getName();
            String[]     columnNames = getColumnNames();
            ColumnType[] columnTypes = getColumnTypes();

            MutableTable table = new MutableTable(name, TableType.TABLE);

            for (int i = 0; i < columnNames.Length; i++)
            {
                table.addColumn(new MutableColumn(columnNames[i], columnTypes[i], table, i, true));
            }
            return table;
        } // toTable()
        } // getTableBuilder()

        // @Override
        public MutableSchema build()
        {
            MutableSchema schema = new MutableSchema(_schemaName);

            // Sort table names by moving them to a treeset
            HashSet <String> table_names = new HashSet <String>(_tableBuilders.Keys);  //new TreeSet<String>(_tableBuilders.keySet());

            foreach (String table_name in table_names)
            {
                MutableTable table = buildTable(getTableBuilder(table_name));
                table.setSchema(schema);
                schema.addTable(table);
            }

            return(schema);
        } // build()
Example #11
0
        public void UpdateRow(Row row)
        {
            if (row == null)
            {
                throw new ArgumentNullException("row");
            }

            var rowId = row.RowId;

            if (rowId.IsNull)
            {
                throw new ArgumentException("Cannot update a row with NULL ROWID");
            }

            OnTableEvent(TriggerEventType.BeforeUpdate, rowId, row);

            MutableTable.UpdateRow(row);
        }
        public void Test()
        {
            var data = new int[,]
            {
                { 2, 3, 0, 1, 0 },
                { 0, 3, 0, 0, 4 },
                { 2, 0, 5, 0, 0 },
                { 0, 0, 0, 5, 0 },
                { 2, 0, 0, 0, 4 },
            };

            var table = new MutableTable<int>(data);

            var sparseTable = new SparseTable<int>(table);

            for (int r = 0; r != table.RowCount; ++r)
                for (int c = 0; c != table.ColumnCount; ++c)
                {
                    Assert.AreEqual(table.Get(r, c), sparseTable.Get(r, c), "row=" + r +", col=" + c);
                }
        }
Example #13
0
        public void Test()
        {
            var data = new int[, ]
            {
                { 2, 3, 0, 1, 0 },
                { 0, 3, 0, 0, 4 },
                { 2, 0, 5, 0, 0 },
                { 0, 0, 0, 5, 0 },
                { 2, 0, 0, 0, 4 },
            };

            var table = new MutableTable <int>(data);

            var sparseTable = new SparseTable <int>(table);

            for (int r = 0; r != table.RowCount; ++r)
            {
                for (int c = 0; c != table.ColumnCount; ++c)
                {
                    Assert.AreEqual(table.Get(r, c), sparseTable.Get(r, c), "row=" + r + ", col=" + c);
                }
            }
        }
Example #14
0
 void IMutableTable.AssertConstraints()
 {
     MutableTable.AssertConstraints();
 }
Example #15
0
 void IMutableTable.FlushIndexes()
 {
     MutableTable.FlushIndexes();
 }
Example #16
0
 void IMutableTable.RemoveLock()
 {
     MutableTable.RemoveLock();
 }
Example #17
0
 void IMutableTable.AddLock()
 {
     MutableTable.AddLock();
 }