Java Code Examples for com.j256.ormlite.table.TableUtils#createTable()
The following examples show how to use
com.j256.ormlite.table.TableUtils#createTable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DBEmailQueueTest.java From passopolis-server with GNU General Public License v3.0 | 6 votes |
@Test public void testTimeZone() throws SQLException { // create a temporary H2 connection JdbcConnectionSource connection = new JdbcConnectionSource("jdbc:h2:mem:"); TableUtils.createTable(connection, DBEmailQueue.class); Dao<DBEmailQueue, Integer> dao = DaoManager.createDao(connection, DBEmailQueue.class); DBEmailQueue email = DBEmailQueue.makeInvitation("[email protected]", "[email protected]", "pw"); dao.create(email); // Force a daylight savings time string in the DB setRawDate(connection, email.getId(), "2013-05-17T14:47:59.864022"); Date t = dao.queryForId(email.getId()).getAttemptedTime(); assertEquals("2013-05-17T14:47:59.864Z", DBEmailQueue.getUtcIsoFormat().format(t)); assertEquals(1368802079864L, t.getTime()); // Set a date/time in standard time, not daylight time setRawDate(connection, email.getId(), "2013-11-04T15:38:11.997012"); t = dao.queryForId(email.getId()).getAttemptedTime(); assertEquals("2013-11-04T15:38:11.997Z", DBEmailQueue.getUtcIsoFormat().format(t)); assertEquals(1383579491997L, t.getTime()); }
Example 2
Source File: DatabaseHelper.java From ormlite-android-gradle-plugin with Apache License 2.0 | 6 votes |
/** * This is called when the database is first created. Usually you should call createTable statements here to create * the tables that will store your data. */ @Override public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) { try { Log.i(DatabaseHelper.class.getName(), "onCreate"); TableUtils.createTable(connectionSource, SimpleData.class); } catch (SQLException e) { Log.e(DatabaseHelper.class.getName(), "Can't create database", e); throw new RuntimeException(e); } // here we try inserting data in the on-create as a test RuntimeExceptionDao<SimpleData, Integer> dao = getSimpleDataDao(); long millis = System.currentTimeMillis(); // create some entries in the onCreate SimpleData simple = new SimpleData(millis); dao.create(simple); simple = new SimpleData(millis + 1); dao.create(simple); Log.i(DatabaseHelper.class.getName(), "created new entries in onCreate: " + millis); }
Example 3
Source File: DataBaseHelper.java From privacy-friendly-shopping-list with Apache License 2.0 | 6 votes |
@Override public void onCreate(SQLiteDatabase database, final ConnectionSource connectionSource) { try { setupClasses(); PFALogger.debug(getClass().getName(), ON_CREATE, START); for ( Class aClass : entityClasses ) { TableUtils.createTable(connectionSource, aClass); } } catch ( Exception e ) { PFALogger.error(getClass().getName(), ON_CREATE, e); } }
Example 4
Source File: DatabaseHelperImpl.java From marvel with MIT License | 5 votes |
@Override public void onCreate(SQLiteDatabase sqliteDatabase, ConnectionSource connectionSource) { try { // Create tables. This onCreate() method will be invoked only once of the application life time i.e. the first time when the application starts. TableUtils.createTable(connectionSource, CharacterModel.class); } catch (SQLException e) { Log.e(DatabaseHelper.class.getName(), "Unable to create database", e); } }
Example 5
Source File: DatabaseHelper.java From AndroidDatabaseLibraryComparison with MIT License | 5 votes |
/** * This is called when the database is first created. Usually you should call createTable statements here to create * the tables that will store your data. */ @Override public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) { try { Log.i(DatabaseHelper.class.getName(), "onCreate"); TableUtils.createTable(connectionSource, AddressBook.class); TableUtils.createTable(connectionSource, AddressItem.class); TableUtils.createTable(connectionSource, Contact.class); TableUtils.createTable(connectionSource, SimpleAddressItem.class); } catch (SQLException e) { Log.e(DatabaseHelper.class.getName(), "Can't create database", e); throw new RuntimeException(e); } }
Example 6
Source File: SimpleMain.java From ormlite-jdbc with ISC License | 5 votes |
/** * Setup our database and DAOs */ private void setupDatabase(ConnectionSource connectionSource) throws Exception { accountDao = DaoManager.createDao(connectionSource, Account.class); // if you need to create the table TableUtils.createTable(connectionSource, Account.class); }
Example 7
Source File: DataPersisterMain.java From ormlite-jdbc with ISC License | 5 votes |
/** * Setup our database and DAOs */ private void setupDatabase(ConnectionSource connectionSource) throws Exception { /* * We register our own persister for DateTime objects. ORMLite actually has a built in one but it has to use * reflection. */ DataPersisterManager.registerDataPersisters(DateTimePersister.getSingleton()); userDao = DaoManager.createDao(connectionSource, User.class); // if you need to create the table TableUtils.createTable(connectionSource, User.class); }
Example 8
Source File: DatabaseHelper.java From iSCAU-Android with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource) { try{ TableUtils.createTable(connectionSource, ClassModel.class); }catch (SQLException e) { Log.e(DatabaseHelper.class.getName(), "Unable to create datbases", e); } }
Example 9
Source File: DatabaseHelperAndroidStarter.java From AndroidStarter with Apache License 2.0 | 5 votes |
@DebugLog @Override public void onCreate(@NonNull final SQLiteDatabase poDatabase, @NonNull final ConnectionSource poConnectionSource) { try { TableUtils.createTable(poConnectionSource, RepoEntity.class); } catch (final SQLException loException) { if (BuildConfig.DEBUG && DEBUG) { Logger.t(TAG).e(loException, ""); } } }
Example 10
Source File: DatabaseHelper.java From XMPPSample_Studio with Apache License 2.0 | 5 votes |
public void onCreate(SQLiteDatabase paramSQLiteDatabase, ConnectionSource paramConnectionSource) { for (int i = 0; i < daoList.length; i++) { try { TableUtils.createTable(paramConnectionSource, daoList[i]); } catch (SQLException e) { e.printStackTrace(); } } }
Example 11
Source File: ORMLiteExecutor.java From android-orm-benchmark-updated with Apache License 2.0 | 5 votes |
@Override public long createDbStructure() throws SQLException { long start = System.nanoTime(); ConnectionSource connectionSource = mHelper.getConnectionSource(); TableUtils.createTable(connectionSource, User.class); TableUtils.createTable(connectionSource, Message.class); return System.nanoTime() - start; }
Example 12
Source File: LocalSqliteDriverImpl.java From mae-annotation with GNU General Public License v3.0 | 5 votes |
public void createAllTables(ConnectionSource source) throws MaeDBException { for (Dao dao : allDaos) { try { TableUtils.createTable(source, dao.getDataClass()); } catch (SQLException e) { throw catchSQLException(e); } } }
Example 13
Source File: DBHelper.java From OkhttpDownloader with Apache License 2.0 | 5 votes |
@Override public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) { try { TableUtils.createTable(connectionSource, DownloadInfo.class); } catch (SQLException e) { e.printStackTrace(); } }
Example 14
Source File: DatabaseHelper.java From Walrus with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) { try { TableUtils.createTable(connectionSource, Card.class); } catch (SQLException e) { throw new RuntimeException(e); } }
Example 15
Source File: DbHelperUtils.java From q-municate-android with Apache License 2.0 | 5 votes |
public static void onCreate(ConnectionSource connectionSource, Class<?>[] tables) { try { for (Class clazz : tables) { TableUtils.createTable(connectionSource, clazz); } } catch (SQLException e) { ErrorUtils.logError(e); } }
Example 16
Source File: ExtentTagTest.java From mae-annotation with GNU General Public License v3.0 | 5 votes |
protected void setupDatabase(ConnectionSource source) throws Exception { eTagDao = DaoManager.createDao(source, ExtentTag.class); tagTypeDao = DaoManager.createDao(source, TagType.class); attTypeDao = DaoManager.createDao(source, AttributeType.class); attDao = DaoManager.createDao(source, Attribute.class); charIndexDao = DaoManager.createDao(source, CharIndex.class); lTagDao = DaoManager.createDao(source, LinkTag.class); argTypeDao = DaoManager.createDao(source, ArgumentType.class); argDao = DaoManager.createDao(source, Argument.class); dropAllTables(source); TableUtils.createTable(source, CharIndex.class); TableUtils.createTable(source, ExtentTag.class); TableUtils.createTable(source, TagType.class); TableUtils.createTable(source, AttributeType.class); TableUtils.createTable(source, Attribute.class); TableUtils.createTable(source, LinkTag.class); TableUtils.createTable(source, ArgumentType.class); TableUtils.createTable(source, Argument.class); noun = new TagType("NOUN", "N", false); verb = new TagType("VERB", "V", false); tagTypeDao.create(noun); tagTypeDao.create(verb); }
Example 17
Source File: BaseDaoImplTest.java From ormlite-core with ISC License | 5 votes |
@Test public void testIsTableExists() throws Exception { Dao<TableExists, Integer> dao = createDao(TableExists.class, false); assertFalse(dao.isTableExists()); TableUtils.createTable(connectionSource, TableExists.class); assertTrue(dao.isTableExists()); TableUtils.dropTable(connectionSource, TableExists.class, true); assertFalse(dao.isTableExists()); }
Example 18
Source File: DatabaseHelper.java From mOrgAnd with GNU General Public License v2.0 | 5 votes |
@Override public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) { try { Log.i(DatabaseHelper.class.getName(), "onCreate"); TableUtils.createTable(connectionSource, OrgNode.class); TableUtils.createTable(connectionSource, OrgFile.class); } catch (SQLException e) { Log.e(DatabaseHelper.class.getName(), "Can't create database", e); throw new RuntimeException(e); } }
Example 19
Source File: OrmLiteDatabaseHelper.java From android-atleap with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) { try { List<Class<?>> classes = getUriMatcher().getClasses(); for (Class clazz : classes) { TableUtils.dropTable(connectionSource, clazz, true); TableUtils.createTable(connectionSource, clazz); } } catch (SQLException e) { Log.e(TAG, "Cannot upgrade database", e); } }
Example 20
Source File: DBHelper.java From ShadowsocksRR with Apache License 2.0 | 4 votes |
@Override public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) { if (oldVersion != newVersion) { try { if (oldVersion < 7) { profileDao.executeRawNoArgs("DROP TABLE IF EXISTS 'profile';"); onCreate(database, connectionSource); return; } if (oldVersion < 8) { profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN udpdns SMALLINT;"); } if (oldVersion < 9) { profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN route VARCHAR DEFAULT 'all';"); } else if (oldVersion < 19) { profileDao.executeRawNoArgs("UPDATE `profile` SET route = 'all' WHERE route IS NULL;"); } if (oldVersion < 10) { profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN auth SMALLINT;"); } if (oldVersion < 11) { profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN ipv6 SMALLINT;"); } if (oldVersion < 12) { profileDao.executeRawNoArgs("BEGIN TRANSACTION;"); profileDao.executeRawNoArgs("ALTER TABLE `profile` RENAME TO `tmp`;"); TableUtils.createTable(connectionSource, Profile.class); profileDao.executeRawNoArgs( "INSERT INTO `profile`(id, name, host, localPort, remotePort, password, method, route, proxyApps, bypass," + " udpdns, auth, ipv6, individual) " + "SELECT id, name, host, localPort, remotePort, password, method, route, 1 - global, bypass, udpdns, auth," + " ipv6, individual FROM `tmp`;"); profileDao.executeRawNoArgs("DROP TABLE `tmp`;"); profileDao.executeRawNoArgs("COMMIT;"); } else if (oldVersion < 13) { profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN tx LONG;"); profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN rx LONG;"); profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN date VARCHAR;"); } if (oldVersion < 15) { if (oldVersion >= 12) { profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN userOrder LONG;"); } int i = 0; for (Profile profile : profileDao.queryForAll()) { if (oldVersion < 14) { profile.individual = updateProxiedApps(context, profile.individual); } profile.userOrder = i; profileDao.update(profile); i += 1; } } if (oldVersion < 16) { profileDao.executeRawNoArgs("UPDATE `profile` SET route = 'bypass-lan-china' WHERE route = 'bypass-china'"); } if (oldVersion < 19) { profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN dns VARCHAR DEFAULT '8.8.8.8:53';"); } if (oldVersion < 20) { profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN china_dns VARCHAR DEFAULT '114.114.114.114:53,223.5.5.5:53';"); } if (oldVersion < 21) { profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN protocol_param VARCHAR DEFAULT '';"); } if (oldVersion < 22) { profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN elapsed LONG DEFAULT 0;"); } if (oldVersion < 23) { profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN url_group VARCHAR DEFAULT '';"); } if (oldVersion < 24) { TableUtils.createTable(connectionSource, SSRSub.class); } } catch (Exception e) { VayLog.e(TAG, "onUpgrade", e); app.track(e); try { profileDao.executeRawNoArgs("DROP TABLE IF EXISTS 'profile';"); } catch (SQLException e1) { VayLog.e(TAG, "onUpgrade", e); } onCreate(database, connectionSource); } } }