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


Java DaoManager類代碼示例

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


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

示例1: initDb

import com.j256.ormlite.dao.DaoManager; //導入依賴的package包/類
private void initDb() throws SQLException {
        // create a connection source to our database
        connectionSource = new JdbcConnectionSource(DATABASE_URL, "sa", "",
                new HsqldbDatabaseType());
        // instantiate the DAO 
        vaultDao = DaoManager.createDao(connectionSource, VaultEntry.class);
        if (!vaultDao.isTableExists()) {
            TableUtils.createTableIfNotExists(connectionSource, VaultEntry.class);
        } else {
            LOG.warning("Found existing DB for VaultEntries. Reusing it!!");
        }

        rawDao = DaoManager.createDao(connectionSource, RawEntry.class);
        if (!rawDao.isTableExists()) {
            TableUtils.createTableIfNotExists(connectionSource, RawEntry.class);
        }
//        TableUtils.createTableIfNotExists(connectionSource, SliceEntry.class);
    }
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:19,代碼來源:VaultDao.java

示例2: AnkiDatabase

import com.j256.ormlite.dao.DaoManager; //導入依賴的package包/類
AnkiDatabase(File databaseFile) throws SQLException {
    try {
        //Loading the sqlite drivers
        Class.forName("org.sqlite.JDBC");
    } catch (ClassNotFoundException e) {
        //Should never happen
        throw new SQLException(e);
    }

    //Creating a connection to the database:
    connectionSource = new JdbcConnectionSource("jdbc:sqlite:" + databaseFile.getAbsolutePath());

    //Creating DAOs
    notesDAO  = DaoManager.createDao(connectionSource, DBNote.class);
    cardsDAO  = DaoManager.createDao(connectionSource, DBCard.class);
    configDAO = DaoManager.createDao(connectionSource, DBConfig.class);
}
 
開發者ID:slavetto,項目名稱:anki-cards-web-browser,代碼行數:18,代碼來源:AnkiDatabase.java

示例3: AbstractDaoService

import com.j256.ormlite.dao.DaoManager; //導入依賴的package包/類
public AbstractDaoService(Class clazz, SpringConfiguration configuration) {

        try {
            this.clazz = clazz;

            // TODO: let user create it's own database
            connection = DatabaseUtils.getH2OrmliteConnectionPool(configuration.getDatabasePath(),
                    // please do not laugh :)
                    SpringConfiguration.DB_LOGIN, SpringConfiguration.DB_PASSWORD);

            TableUtils.createTableIfNotExists(connection, clazz);

            // instantiate the dao
            dao = DaoManager.createDao(connection, clazz);

        } catch (SQLException e) {
            throw new IllegalStateException(e);
        }
    }
 
開發者ID:remipassmoilesel,項目名稱:simple-hostel-management,代碼行數:20,代碼來源:AbstractDaoService.java

示例4: initDb

import com.j256.ormlite.dao.DaoManager; //導入依賴的package包/類
/**
     * Initializes the actual database as a {@link JdbcConnectionSource}.
     *
     * @throws SQLException Thrown if the database can not be successfully initialized.
     */
    private void initDb() throws SQLException {
        // create a connection source to our database
        connectionSource = new JdbcConnectionSource(DATABASE_URL, "sa", "",
                new HsqldbDatabaseType());
        // instantiate the DAO
        vaultDao = DaoManager.createDao(connectionSource, VaultEntry.class);
        if (!vaultDao.isTableExists()) {
            TableUtils.createTableIfNotExists(connectionSource, VaultEntry.class);
        } else {
            LOG.warning("Found existing DB for VaultEntries. Reusing it!!");
        }

        rawDao = DaoManager.createDao(connectionSource, RawEntry.class);
        if (!rawDao.isTableExists()) {
            TableUtils.createTableIfNotExists(connectionSource, RawEntry.class);
        }
//        TableUtils.createTableIfNotExists(connectionSource, SliceEntry.class);
    }
 
開發者ID:lucasbuschlinger,項目名稱:BachelorPraktikum,代碼行數:24,代碼來源:VaultDao.java

示例5: save

import com.j256.ormlite.dao.DaoManager; //導入依賴的package包/類
/**
 * Saves the user data to the database.
 *
 * @param data The user data to save.
 */
private static void save(UserData data) {
    data.setAvatarUrl(data.getAvatarUrl());
    data.setUsername(data.getUsername());

    ZLevels.async.submit(() -> {
        try {
            ConnectionSource source = Database.openConnection();
            if (source == null) return;

            Dao<UserData, String> db = DaoManager.createDao(source, UserData.class);
            db.createOrUpdate(data);
            Database.closeConnection();
        } catch (Exception e) {
            ZLogger.warn("Could not save UserData for " + data.getUserId() + "!");
            e.printStackTrace();
        }
    });
}
 
開發者ID:ZP4RKER,項目名稱:zlevels,代碼行數:24,代碼來源:UserData.java

示例6: delete

import com.j256.ormlite.dao.DaoManager; //導入依賴的package包/類
/**
 * Deletes this user data from the database and cache.
 */
public void delete() {
    UserData current = this;

    if (cache.containsKey(current.getUserId())) cache.remove(current.getUserId());

    ZLevels.async.submit(() -> {
        try {
            ConnectionSource source = Database.openConnection();
            if (source == null) return;

            Dao<UserData, String> db = DaoManager.createDao(source, UserData.class);

            db.delete(current);

            Database.closeConnection();
        } catch (Exception e) {
            ZLogger.warn("Colud not delete UserData for " + getUserId() + "!");
            e.printStackTrace();
        }
    });
}
 
開發者ID:ZP4RKER,項目名稱:zlevels,代碼行數:25,代碼來源:UserData.java

示例7: fromId

import com.j256.ormlite.dao.DaoManager; //導入依賴的package包/類
/**
 * Gets the user data by userId from the cache and database.
 *
 * @param userId The user id.
 * @return The user data.
 */
public static UserData fromId(String userId) {
    if (cache.containsKey(userId)) {
        return cache.get(userId);
    }
    try {
        ConnectionSource source = Database.openConnection();
        if (source == null) return null;

        Dao<UserData, String> db = DaoManager.createDao(source, UserData.class);

        UserData data = db.queryForEq("userId", userId).get(0);

        Database.closeConnection();

        return data;
    } catch (Exception e) {
        if (e instanceof IndexOutOfBoundsException) {
            return null;
        }

        ZLogger.warn("Could not get UserData for " + userId + "!");
        e.printStackTrace();
        return null;
    }
}
 
開發者ID:ZP4RKER,項目名稱:zlevels,代碼行數:32,代碼來源:UserData.java

示例8: setUpTest

import com.j256.ormlite.dao.DaoManager; //導入依賴的package包/類
@BeforeClass
public static void setUpTest() throws Exception {
    ServerEventService eventService = new ServerEventService();

    daoProvider = new DataSourceProvider();
    eventService.subscribe(DataSourceInitializedEvent.class, daoProvider);

    DataSourceEventSubscriber daoInitializer = new DataSourceEventSubscriber();
    eventService.subscribe(DeviceDaoCreatedEvent.class, daoInitializer);
    eventService.subscribe(AgentDaoCreatedEvent.class, daoInitializer);

    DataSourceManager dataSourceManager = new DataSourceManager(new DataSourceCallback());
    dataSourceManager.initialize();

    assertNotNull("Initialization of the database failed. ", agentDao);
    // initialize a test agent entry in the data source to attach the devices to
    agentDao.add(TEST_AGENT_ID);

    initializeTestDevices();

    // initialize an OrmLite device DAO to clear the device table after each test
    JdbcConnectionSource connectionSource = new JdbcConnectionSource(Property.DATABASE_URL);
    ormliteDeviceDao = DaoManager.createDao(connectionSource, Device.class);

}
 
開發者ID:MusalaSoft,項目名稱:atmosphere-server,代碼行數:26,代碼來源:DeviceDaoIntegrationTest.java

示例9: getDao

import com.j256.ormlite.dao.DaoManager; //導入依賴的package包/類
/**
 * This method obtains a DAO given its Class
 * <p/>
 * Source: https://goo.gl/6LIYy2
 *
 * @param clazz
 *         The DAO class
 * @param <D>
 *         DAO super class
 * @param <T>
 *         Requested DAO class
 *
 * @return The DAO instance
 *
 * @throws SQLException
 */
public <D extends Dao<T, ?>, T> D getDao(Class<T> clazz) throws SQLException {
  // lookup the dao, possibly invoking the cached database config
  Dao<T, ?> dao = DaoManager.lookupDao(connectionSource, clazz);
  if (dao == null) {
    // try to use our new reflection magic
    DatabaseTableConfig<T> tableConfig = DatabaseTableConfigUtil
            .fromClass(connectionSource, clazz);
    if (tableConfig == null) {
      /**
       * Note: We have to do this to get to see if they are using the deprecated
       * annotations like
       * {@link DatabaseFieldSimple}.
       */
      dao = (Dao<T, ?>) DaoManager.createDao(connectionSource, clazz);
    } else {
      dao = (Dao<T, ?>) DaoManager.createDao(connectionSource, tableConfig);
    }
  }

  @SuppressWarnings("unchecked")
  D castDao = (D) dao;
  return castDao;
}
 
開發者ID:aajn88,項目名稱:wakemeapp,代碼行數:40,代碼來源:DatabaseHelper.java

示例10: DatabaseManager

import com.j256.ormlite.dao.DaoManager; //導入依賴的package包/類
protected DatabaseManager() {
    String databaseUrl = "jdbc:sqlite:halgnu.db";

    try {
        m_connectionSource = new JdbcConnectionSource(databaseUrl);
        
        // Create daos
        m_memberDao = DaoManager.createDao(m_connectionSource, MemberModel.class);
        m_activityDao = DaoManager.createDao(m_connectionSource, ActivityModel.class);

        TableUtils.createTableIfNotExists(m_connectionSource, MemberModel.class);
        TableUtils.createTableIfNotExists(m_connectionSource, ActivityModel.class);

        // Check if tables need to be created
        CheckIfAdminExists();

    } catch (SQLException e) {
        e.printStackTrace();
    }
    
}
 
開發者ID:R4stl1n,項目名稱:halgnu,代碼行數:22,代碼來源:DatabaseManager.java

示例11: getCachedWebResourcesDao

import com.j256.ormlite.dao.DaoManager; //導入依賴的package包/類
@NonNull
public Dao<CachedWebResource, String> getCachedWebResourcesDao() {
    if (cachedWebResourcesDao == null) {
        synchronized (this) {
            if (cachedWebResourcesDao == null) {
                try {
                    cachedWebResourcesDao = DaoManager.createDao(getConnectionSource(), CachedWebResource.class);
                } catch (SQLException e) {
                    Log.e(TAG, "Cannot create DAO", e);
                    throw new RuntimeException(e);
                }
            }
        }
    }
    return cachedWebResourcesDao;
}
 
開發者ID:yeputons,項目名稱:ofeed,代碼行數:17,代碼來源:DbHelper.java

示例12: getCachedFeedItemDao

import com.j256.ormlite.dao.DaoManager; //導入依賴的package包/類
@NonNull
public Dao<CachedFeedItem, String> getCachedFeedItemDao() {
    if (cachedFeedItemDao == null) {
        synchronized (this) {
            if (cachedFeedItemDao == null) {
                try {
                    cachedFeedItemDao = DaoManager.createDao(getConnectionSource(), CachedFeedItem.class);
                } catch (SQLException e) {
                    Log.e(TAG, "Cannot create DAO", e);
                    throw new RuntimeException(e);
                }
            }
        }
    }
    return cachedFeedItemDao;
}
 
開發者ID:yeputons,項目名稱:ofeed,代碼行數:17,代碼來源:DbHelper.java

示例13: getCachedUserDao

import com.j256.ormlite.dao.DaoManager; //導入依賴的package包/類
@NonNull
public Dao<CachedUser, Integer> getCachedUserDao() {
    if (cachedUserDao == null) {
        synchronized (this) {
            if (cachedUserDao == null) {
                try {
                    cachedUserDao = DaoManager.createDao(getConnectionSource(), CachedUser.class);
                } catch (SQLException e) {
                    Log.e(TAG, "Cannot create DAO", e);
                    throw new RuntimeException(e);
                }
            }
        }
    }
    return cachedUserDao;
}
 
開發者ID:yeputons,項目名稱:ofeed,代碼行數:17,代碼來源:DbHelper.java

示例14: getCachedGroupDao

import com.j256.ormlite.dao.DaoManager; //導入依賴的package包/類
@NonNull
public Dao<CachedGroup, Integer> getCachedGroupDao() {
    if (cachedGroupDao == null) {
        synchronized (this) {
            if (cachedGroupDao == null) {
                try {
                    cachedGroupDao = DaoManager.createDao(getConnectionSource(), CachedGroup.class);
                } catch (SQLException e) {
                    Log.e(TAG, "Cannot create DAO", e);
                    throw new RuntimeException(e);
                }
            }
        }
    }
    return cachedGroupDao;
}
 
開發者ID:yeputons,項目名稱:ofeed,代碼行數:17,代碼來源:DbHelper.java

示例15: getCachedWebPageDao

import com.j256.ormlite.dao.DaoManager; //導入依賴的package包/類
@NonNull
public Dao<CachedWebPage, String> getCachedWebPageDao() {
    if (cachedWebPageDao == null) {
        synchronized (this) {
            if (cachedWebPageDao == null) {
                try {
                    cachedWebPageDao = DaoManager.createDao(getConnectionSource(), CachedWebPage.class);
                } catch (SQLException e) {
                    Log.e(TAG, "Cannot create DAO", e);
                    throw new RuntimeException(e);
                }
            }
        }
    }
    return cachedWebPageDao;
}
 
開發者ID:yeputons,項目名稱:ofeed,代碼行數:17,代碼來源:DbHelper.java


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