本文整理汇总了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());
}
示例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;
}
示例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;
}
示例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;
}
示例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++;
}
}
示例6: getTables
import com.yahoo.squidb.sql.Table; //导入依赖的package包/类
@Override
protected Table[] getTables()
{
return new Table[]{
Message.TABLE, User.TABLE
};
}
示例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
};
}
示例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());
}
示例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());
}
示例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());
}
示例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
};
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}