當前位置: 首頁>>代碼示例>>Java>>正文


Java Table類代碼示例

本文整理匯總了Java中com.yahoo.squidb.sql.Table的典型用法代碼示例。如果您正苦於以下問題:Java Table類的具體用法?Java Table怎麽用?Java Table使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Table類屬於com.yahoo.squidb.sql包,在下文中一共展示了Table類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: tryCreateIndex

import com.yahoo.squidb.sql.Table; //導入依賴的package包/類
/**
 * Create a new {@link Index} in the database
 *
 * @param indexName name for the Index
 * @param table the table to create the index on
 * @param unique true if the index is a unique index on the specified columns
 * @param properties the columns to create the index on
 * @return true if the statement executed without error, false otherwise
 */
protected boolean tryCreateIndex(String indexName, Table table, boolean unique, Property<?>... properties) {
    if (properties == null || properties.length == 0) {
        onError(String.format("Cannot create index %s: no properties specified", indexName), null);
        return false;
    }
    StringBuilder sql = new StringBuilder(STRING_BUILDER_INITIAL_CAPACITY);
    sql.append("CREATE ");
    if (unique) {
        sql.append("UNIQUE ");
    }
    sql.append("INDEX IF NOT EXISTS ").append(indexName).append(" ON ").append(table.getExpression())
            .append("(");
    for (Property<?> p : properties) {
        sql.append(p.getName()).append(",");
    }
    sql.deleteCharAt(sql.length() - 1);
    sql.append(")");
    return tryExecSql(sql.toString());
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:29,代碼來源:SquidDatabase.java

示例2: updateWithOnConflict

import com.yahoo.squidb.sql.Table; //導入依賴的package包/類
/**
 * Update all rows matching the given {@link Criterion}, setting values based on the provided template model. Any
 * constraint violations will be resolved using the specified
 * {@link com.yahoo.squidb.sql.TableStatement.ConflictAlgorithm ConflictAlgorithm}.
 *
 * @param where the criterion to match. Note: passing null will update all rows!
 * @param template a model containing new values for the properties (columns) that should be updated
 * @param conflictAlgorithm the conflict algorithm to use
 * @return the number of updated rows
 * @see #update(Criterion, TableModel)
 */
public int updateWithOnConflict(Criterion where, TableModel template,
        TableStatement.ConflictAlgorithm conflictAlgorithm) {
    Class<? extends TableModel> modelClass = template.getClass();
    Table table = getTable(modelClass);
    Update update = Update.table(table).fromTemplate(template);
    if (where != null) {
        update.where(where);
    }
    if (conflictAlgorithm != null) {
        update.onConflict(conflictAlgorithm);
    }

    int rowsUpdated = updateInternal(update);
    if (rowsUpdated > 0) {
        notifyForTable(DataChangedNotifier.DBOperation.UPDATE, template, table, TableModel.NO_ID);
    }
    return rowsUpdated;
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:30,代碼來源:SquidDatabase.java

示例3: updateRow

import com.yahoo.squidb.sql.Table; //導入依賴的package包/類
/**
 * Same as {@link #updateRow(TableModel)} with the ability to specify a ConflictAlgorithm for handling constraint
 * violations
 *
 * @param item the model to save
 * @param conflictAlgorithm the conflict algorithm to use
 * @return true if success, false otherwise
 */
protected final boolean updateRow(TableModel item, TableStatement.ConflictAlgorithm conflictAlgorithm) {
    if (!item.isModified()) { // nothing changed
        return true;
    }
    if (!item.isSaved()) {
        return false;
    }

    Class<? extends TableModel> modelClass = item.getClass();
    Table table = getTable(modelClass);
    Update update = Update.table(table).fromTemplate(item).where(table.getRowIdProperty().eq(item.getRowId()));
    if (conflictAlgorithm != null) {
        update.onConflict(conflictAlgorithm);
    }
    boolean result = updateInternal(update) > 0;
    if (result) {
        notifyForTable(DataChangedNotifier.DBOperation.UPDATE, item, table, item.getRowId());
        item.markSaved();
    }
    return result;
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:30,代碼來源:SquidDatabase.java

示例4: getPreparedInsert

import com.yahoo.squidb.sql.Table; //導入依賴的package包/類
ISQLitePreparedStatement getPreparedInsert(SquidDatabase db, Table table,
        TableStatement.ConflictAlgorithm conflictAlgorithm) {

    Class<? extends TableModel> modelClass = table.getModelClass();
    ISQLitePreparedStatement[] preparedStatements = preparedStatementCache.get(modelClass);

    if (preparedStatements == null) {
        preparedStatements = new ISQLitePreparedStatement[TableStatement.ConflictAlgorithm.values().length];
        preparedStatementCache.put(modelClass, preparedStatements);
    }

    if (conflictAlgorithm == null) {
        conflictAlgorithm = TableStatement.ConflictAlgorithm.NONE;
    }

    ISQLitePreparedStatement toReturn = preparedStatements[conflictAlgorithm.ordinal()];
    if (toReturn == null) {
        toReturn = prepareInsert(db, table, conflictAlgorithm);
        preparedStatements[conflictAlgorithm.ordinal()] = toReturn;
    }
    return toReturn;
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:23,代碼來源:PreparedInsertCache.java

示例5: bindValuesForInsert

import com.yahoo.squidb.sql.Table; //導入依賴的package包/類
void bindValuesForInsert(Table table, ISQLitePreparedStatement preparedInsert) {
    LongProperty rowidProperty = getRowIdProperty();
    Property<?>[] allProperties = table.getProperties();

    ModelAndIndex modelAndIndex = new ModelAndIndex(this);
    for (Property<?> property : allProperties) {
        if (property == rowidProperty) {
            long rowid = getRowId();
            if (rowid == TableModel.NO_ID) {
                preparedInsert.bindNull(modelAndIndex.index);
            } else {
                preparedInsert.bindLong(modelAndIndex.index, rowid);
            }
        } else {
            property.accept(valueBindingVisitor, preparedInsert, modelAndIndex);
        }
        modelAndIndex.index++;
    }
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:20,代碼來源:TableModel.java

示例6: getTables

import com.yahoo.squidb.sql.Table; //導入依賴的package包/類
@Override
protected Table[] getTables()
{
    return new Table[]{
        Message.TABLE, User.TABLE
    };
}
 
開發者ID:touchlab,項目名稱:android-orm-benchmark-updated,代碼行數:8,代碼來源:MyDatabase.java

示例7: getTables

import com.yahoo.squidb.sql.Table; //導入依賴的package包/類
@Override
protected Table[] getTables() {
    return new Table[]{
            TestModel.TABLE,
            Thing.TABLE,
            Employee.TABLE,
            TriggerTester.TABLE,
            BasicData.TABLE,
            TestVirtualModel.TABLE
    };
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:12,代碼來源:TestReactiveDatabase.java

示例8: testObservableWithInitialSubscribeFlagEmitsOnFirstSubscribe

import com.yahoo.squidb.sql.Table; //導入依賴的package包/類
public void testObservableWithInitialSubscribeFlagEmitsOnFirstSubscribe() {
    final AtomicBoolean called = new AtomicBoolean(false);
    Observable<Table> observable = database.observeTable(TestModel.TABLE, true);
    observable.subscribe(new Action1<Table>() {
        @Override
        public void call(Table table) {
            called.set(true);
        }
    });
    assertTrue(called.get());
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:12,代碼來源:ReactiveSquidDatabaseTest.java

示例9: testSimpleObservableEmitsTable

import com.yahoo.squidb.sql.Table; //導入依賴的package包/類
public void testSimpleObservableEmitsTable() {
    final AtomicBoolean tablesMatch = new AtomicBoolean(false);
    Observable<Table> observable = database.observeTable(TestModel.TABLE, true);
    observable.subscribe(new Action1<Table>() {
        @Override
        public void call(Table table) {
            tablesMatch.set(TestModel.TABLE.equals(table));
        }
    });
    assertTrue(tablesMatch.get());
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:12,代碼來源:ReactiveSquidDatabaseTest.java

示例10: testMultipleStatements

import com.yahoo.squidb.sql.Table; //導入依賴的package包/類
private void testMultipleStatements(boolean useTransaction, boolean successfulTransaction) {
    final AtomicInteger callCount = new AtomicInteger();
    Observable<Table> observable = database.observeTable(TestModel.TABLE);
    observable.subscribe(new Action1<Table>() {
        @Override
        public void call(Table table) {
            callCount.incrementAndGet();
        }
    });
    assertEquals(0, callCount.get());
    if (useTransaction) {
        database.beginTransaction();
    }
    try {
        database.persist(new TestModel().setFirstName("A").setLastName("B")
                .setBirthday(System.currentTimeMillis() - 2));
        database.persist(new TestModel().setFirstName("C").setLastName("D")
                .setBirthday(System.currentTimeMillis() - 1));
        if (useTransaction && successfulTransaction) {
            database.setTransactionSuccessful();
        }
    } finally {
        if (useTransaction) {
            database.endTransaction();
        }
    }
    int expectedCount;
    if (useTransaction) {
        expectedCount = successfulTransaction ? 1 : 0;
    } else {
        expectedCount = 2;
    }
    assertEquals(expectedCount, callCount.get());
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:35,代碼來源:ReactiveSquidDatabaseTest.java

示例11: getTables

import com.yahoo.squidb.sql.Table; //導入依賴的package包/類
@Override
protected Table[] getTables() {
    return new Table[]{
            TestModel.TABLE,
            Thing.TABLE,
            Employee.TABLE,
            TriggerTester.TABLE,
            BasicData.TABLE,
            TestVirtualModel.TABLE,
            TestMultiColumnKey.TABLE,
            TestNonIntegerPrimaryKey.TABLE
    };
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:14,代碼來源:TestDatabase.java

示例12: onCreate

import com.yahoo.squidb.sql.Table; //導入依賴的package包/類
/**
 * Called to create the database tables
 */
public void onCreate(ISQLiteDatabase db) {
    setDatabase(db);
    StringBuilder sql = new StringBuilder(STRING_BUILDER_INITIAL_CAPACITY);
    SqlConstructorVisitor sqlVisitor = new SqlConstructorVisitor();

    // create tables
    Table[] tables = getTables();
    if (tables != null) {
        for (Table table : tables) {
            table.appendCreateTableSql(getCompileContext(), sql, sqlVisitor);
            db.execSQL(sql.toString());
            sql.setLength(0);
        }
    }

    View[] views = getViews();
    if (views != null) {
        for (View view : views) {
            view.createViewSql(getCompileContext(), sql);
            db.execSQL(sql.toString());
            sql.setLength(0);
        }
    }

    Index[] indexes = getIndexes();
    if (indexes != null) {
        for (Index idx : indexes) {
            tryCreateIndex(idx);
        }
    }

    // post-table-creation
    SquidDatabase.this.onTablesCreated(db);
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:38,代碼來源:SquidDatabase.java

示例13: tryCreateTable

import com.yahoo.squidb.sql.Table; //導入依賴的package包/類
/**
 * Create a new {@link Table} or {@link VirtualTable} in the database
 *
 * @param table the Table or VirtualTable to create
 * @return true if the statement executed without error, false otherwise
 */
protected boolean tryCreateTable(Table table) {
    SqlConstructorVisitor sqlVisitor = new SqlConstructorVisitor();
    StringBuilder sql = new StringBuilder(STRING_BUILDER_INITIAL_CAPACITY);
    table.appendCreateTableSql(getCompileContext(), sql, sqlVisitor);
    return tryExecSql(sql.toString());
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:13,代碼來源:SquidDatabase.java

示例14: delete

import com.yahoo.squidb.sql.Table; //導入依賴的package包/類
/**
 * Delete the row with the given row ID
 *
 * @param modelClass the model class corresponding to the table to delete from
 * @param id the row ID of the record
 * @return true if delete was successful
 */
public boolean delete(Class<? extends TableModel> modelClass, long id) {
    Table table = getTable(modelClass);
    int rowsUpdated = deleteInternal(Delete.from(table).where(table.getRowIdProperty().eq(id)));
    if (rowsUpdated > 0) {
        notifyForTable(DataChangedNotifier.DBOperation.DELETE, null, table, id);
    }
    return rowsUpdated > 0;
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:16,代碼來源:SquidDatabase.java

示例15: deleteWhere

import com.yahoo.squidb.sql.Table; //導入依賴的package包/類
/**
 * Delete all rows matching the given {@link Criterion}
 *
 * @param modelClass model class for the table to delete from
 * @param where the Criterion to match. Note: passing null will delete all rows!
 * @return the number of deleted rows
 */
public int deleteWhere(Class<? extends TableModel> modelClass, Criterion where) {
    Table table = getTable(modelClass);
    Delete delete = Delete.from(table);
    if (where != null) {
        delete.where(where);
    }
    int rowsUpdated = deleteInternal(delete);
    if (rowsUpdated > 0) {
        notifyForTable(DataChangedNotifier.DBOperation.DELETE, null, table, TableModel.NO_ID);
    }
    return rowsUpdated;
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:20,代碼來源:SquidDatabase.java


注:本文中的com.yahoo.squidb.sql.Table類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。