Package org.tmatesoft.sqljet.core.schema

Examples of org.tmatesoft.sqljet.core.schema.ISqlJetTableDef


            final IProgress progress) throws SqlJetException {
        if (table == null) {
            return new DefaultTableModel();
        }
        final ArrayList<DataRow> data = new ArrayList<DataRow>(pageSize);
        final ISqlJetTableDef tableDef = table.getDefinition();
        final List<String> names = new ArrayList<String>();
        for (ISqlJetColumnDef column : tableDef.getColumns()) {
            names.add(column.getName());
        }
        final String[] namesArray = (String[]) names.toArray(new String[names.size()]);

        table.getDataBase().runReadTransaction(new ISqlJetTransaction() {
View Full Code Here


            return new SchemaTreeModel(root);
        }
        try {
            Set<String> tableNames = schema.getTableNames();
            for (String tableName : tableNames) {
                ISqlJetTableDef table = schema.getTable(tableName);
                SchemaTreeNode node = new SchemaTreeNode(table);               
                List<ISqlJetColumnDef> columns = table.getColumns();
                for (ISqlJetColumnDef column : columns) {
                    node.addChild(new SchemaTreeNode(table, column));
                }
                root.addChild(node);
            }
View Full Code Here

        System.out.println();
        db.beginTransaction(SqlJetTransactionMode.WRITE);
        try {
            Set<String> tables = db.getSchema().getTableNames();
            for (String tableName : tables) {
                ISqlJetTableDef tableDef = db.getSchema().getTable(tableName);
                Set<ISqlJetIndexDef> tableIndices = db.getSchema().getIndexes(tableDef.getName());
               
                for (ISqlJetIndexDef indexDef : tableIndices) {
                   
                    if (!indexDef.isImplicit()) {
                        System.out.println("dropping index: " + indexDef.getName());
                        db.dropIndex(indexDef.getName());
                    }
                }
                System.out.println("dropping table: " + tableDef.getName());
                db.dropTable(tableDef.getName());
            }
        } finally {
            db.commit();
        }
View Full Code Here

    private void bindIndexes() {
        for (ISqlJetIndexDef indexDef : indexDefs.values()) {
            if (indexDef instanceof SqlJetIndexDef) {
                SqlJetIndexDef i = (SqlJetIndexDef) indexDef;
                final String tableName = i.getTableName();
                final ISqlJetTableDef tableDef = tableDefs.get(tableName);
                if (tableDef != null) {
                    i.bindColumns(tableDef);
                }
            }
        }
View Full Code Here

        final List<ISqlJetIndexedColumn> columns = indexDef.getColumns();
        if (null == columns)
            throw new SqlJetException(SqlJetErrorCode.ERROR);

        final ISqlJetTableDef tableDef = getTable(tableName);
        if (null == tableDef)
            throw new SqlJetException(SqlJetErrorCode.ERROR);

        for (final ISqlJetIndexedColumn column : columns) {
            if (null == column.getName())
                throw new SqlJetException(SqlJetErrorCode.ERROR);
            final String columnName = column.getName();
            if ("".equals(columnName))
                throw new SqlJetException(SqlJetErrorCode.ERROR);
            if (null == tableDef.getColumn(columnName))
                throw new SqlJetException(SqlJetErrorCode.ERROR, "Column \"" + columnName + "\" not found in table \""
                        + tableName + "\"");
        }

        final ISqlJetBtreeSchemaTable schemaTable = openSchemaTable(true);
View Full Code Here

                        if (index != null) {
                            if (index instanceof SqlJetBaseIndexDef) {
                                ((SqlJetBaseIndexDef) index).setPage(page);
                            }
                        } else {
                            final ISqlJetTableDef table = getTable(nameField);
                            if (table != null) {
                                if (table instanceof SqlJetTableDef) {
                                    ((SqlJetTableDef) table).setPage(page);
                                }
                            }
View Full Code Here

    public SqlJetDb getDataBase() {
        return db;
    }

    public String getPrimaryKeyIndexName() throws SqlJetException {
        final ISqlJetTableDef definition = getDefinition();
        return definition.isRowIdPrimaryKey() ? null : definition.getPrimaryKeyIndexName();
    }
View Full Code Here

        });
    }

    @Test
    public void testInsertOrUpdate1() throws SqlJetException {
        final ISqlJetTableDef createTable = db.createTable("CREATE TABLE IF NOT EXISTS files ("
                + " name TEXT NOT NULL PRIMARY KEY, time INTEGER)");
        final ISqlJetTable table = db.getTable(createTable.getName());
        for (long actual = 1; actual < 10; actual++) {
            table.insertOr(SqlJetConflictAction.REPLACE, "test", new Long(actual));
            assertInsertedOrReplaced(table, actual, "test");
        }
        assertCount(table, 1);
View Full Code Here

    }


    @Test
    public void testInsertOrUpdate2() throws SqlJetException {
        final ISqlJetTableDef createTable = db.createTable("CREATE TABLE IF NOT EXISTS files ("
                + " id INTEGER NOT NULL PRIMARY KEY, time INTEGER)");
        final ISqlJetTable table = db.getTable(createTable.getName());
        for (long actual = 1; actual < 10; actual++) {
            table.insertOr(SqlJetConflictAction.REPLACE, 1, new Long(actual));
            assertInsertedOrReplaced(table, actual, 1);
        }
        assertCount(table, 1);
View Full Code Here

public class AutoincrementTest extends AbstractNewDbTest {

    @Test
    public void testAutoincrement() throws Exception {

        ISqlJetTableDef createTable = db.createTable(
        "CREATE TABLE `JOBLIST` (" +
        "`id` INTEGER PRIMARY KEY AUTOINCREMENT," +
        "`jobname` VARCHAR(75) NOT NULL," +
        "`startdate` LONG not null" +
        ");" );

        final ISqlJetTable table = db.getTable(createTable.getName());
        db.beginTransaction(SqlJetTransactionMode.EXCLUSIVE);
        try{
            table.insert(null, "jobname", 123456);
            table.insert(null, "jobname", 123456);
        } finally {
View Full Code Here

TOP

Related Classes of org.tmatesoft.sqljet.core.schema.ISqlJetTableDef

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.