⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 localmodel.java

📁 这个范例程序演示了利用j2me技术开发无线服务器支持的应用。这是一个电影票订购程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */    public Preferences getPreferences() throws ApplicationException {        if (preferences == null) {            IndexEntry indexEntry = rmsAdapter.getIndexEntry("*",                     IndexEntry.TYPE_PREFERENCES, IndexEntry.MODE_ANY);            if (indexEntry != null) {                preferences =                     rmsAdapter.loadPreferences(indexEntry.getRecordId());            } else {                preferences = new Preferences();                int recordId =                     rmsAdapter.storePreferences(preferences,                                                 indexEntry != null                                                 ? indexEntry.getRecordId()                                                 : -1);                indexEntry = new IndexEntry(recordId,                                             IndexEntry.TYPE_PREFERENCES, "*",                                             IndexEntry.MODE_PERSISTING);                rmsAdapter.addIndexEntry(indexEntry);            }         }         return preferences;    }     // public void setPreferences() throws ApplicationException {    public void setPreferences(Preferences preferences)             throws ApplicationException {        this.preferences.copy(preferences);        IndexEntry indexEntry = rmsAdapter.getIndexEntry("*",                 IndexEntry.TYPE_PREFERENCES, IndexEntry.MODE_ANY);        int recordId = rmsAdapter.storePreferences(preferences,                                                    indexEntry != null                                                    ? indexEntry.getRecordId()                                                    : -1);        if (indexEntry == null) {            indexEntry = new IndexEntry(recordId,                                         IndexEntry.TYPE_PREFERENCES, "*",                                         IndexEntry.MODE_PERSISTING);            rmsAdapter.addIndexEntry(indexEntry);        }         return;    }     public IndexedResourceBundle getResourceBundle(String baseName)             throws ApplicationException {        try {            IndexEntry indexEntry = rmsAdapter.getIndexEntry(baseName,                     IndexEntry.TYPE_RESOURCE_BUNDLE, IndexEntry.MODE_ANY);            if (indexEntry != null) {                return rmsAdapter.loadResourceBundle(indexEntry.getRecordId());            }         } catch (ApplicationException ae) {}        return null;    }     public void setResourceBundle(String baseName, IndexedResourceBundle bundle)             throws ApplicationException {        IndexEntry indexEntry = rmsAdapter.getIndexEntry(baseName,                 IndexEntry.TYPE_RESOURCE_BUNDLE, IndexEntry.MODE_ANY);        int recordId = rmsAdapter.storeResourceBundle(bundle,                 indexEntry != null ? indexEntry.getRecordId() : -1);        if (indexEntry == null) {            indexEntry = new IndexEntry(recordId,                                         IndexEntry.TYPE_RESOURCE_BUNDLE,                                         baseName, IndexEntry.MODE_PERSISTING);            rmsAdapter.addIndexEntry(indexEntry);        }         return;    }     public void setMovieRating(MovieRating movieRating)             throws ApplicationException {        IndexEntry indexEntry =             rmsAdapter.getIndexEntry(movieRating.getPrimaryKey(),                                      IndexEntry.TYPE_MOVIE_RATING,                                      IndexEntry.MODE_ANY);        int recordId = rmsAdapter.storeMovieRating(movieRating,                                                    indexEntry != null                                                    ? indexEntry.getRecordId()                                                    : -1);        if (indexEntry == null) {            indexEntry = new IndexEntry(recordId,                                         IndexEntry.TYPE_MOVIE_RATING,                                         movieRating.getPrimaryKey(),                                         IndexEntry.MODE_PERSISTING);            rmsAdapter.addIndexEntry(indexEntry);            persistRatedMovie(movieRating.getMovie());        }         return;    }     public void addMovieRating(MovieRating movieRating)             throws ApplicationException {        IndexEntry indexEntry =             rmsAdapter.getIndexEntry(movieRating.getPrimaryKey(),                                      IndexEntry.TYPE_MOVIE_RATING,                                      IndexEntry.MODE_ANY);        int recordId = -1;        if (indexEntry != null) {            recordId = indexEntry.getRecordId();            MovieRating rating = rmsAdapter.loadMovieRating(recordId);            rating.setLastViewingDate(movieRating.getLastViewingDate());            movieRating = rating;        }         recordId = rmsAdapter.storeMovieRating(movieRating, recordId);        if (indexEntry == null) {            indexEntry = new IndexEntry(recordId,                                         IndexEntry.TYPE_MOVIE_RATING,                                         movieRating.getPrimaryKey(),                                         IndexEntry.MODE_PERSISTING);            rmsAdapter.addIndexEntry(indexEntry);            persistRatedMovie(movieRating.getMovie());        }         return;    }     public void deleteMovieRating(String movieRatingKey)             throws ApplicationException {        IndexEntry indexEntry = rmsAdapter.getIndexEntry(movieRatingKey,                 IndexEntry.TYPE_MOVIE_RATING, IndexEntry.MODE_ANY);        if (indexEntry != null) {            MovieRating movieRating =                 rmsAdapter.loadMovieRating(indexEntry.getRecordId());            movieRating.setModificationStatus(Synchronizable.STATUS_DELETED);            rmsAdapter.storeMovieRating(movieRating,                                         indexEntry.getRecordId());        }         return;    }     public void purgeMovieRating(String movieRatingKey)             throws ApplicationException {        IndexEntry indexEntry = rmsAdapter.getIndexEntry(movieRatingKey,                 IndexEntry.TYPE_MOVIE_RATING, IndexEntry.MODE_ANY);        if (indexEntry != null) {            rmsAdapter.deleteMovieRating(indexEntry.getRecordId());            rmsAdapter.deleteIndexEntry(indexEntry.getKey(),                                         indexEntry.getType());        }         return;    }     public MovieRating[] getMovieRatings() throws ApplicationException {        IndexEntry[] indexEntries =             rmsAdapter.getIndexEntries(IndexEntry.TYPE_MOVIE_RATING,                                        IndexEntry.MODE_ANY);        MovieRating[] movieRatings = new MovieRating[indexEntries.length];        for (int i = 0; i < indexEntries.length; i++) {            movieRatings[i] =                 rmsAdapter.loadMovieRating(indexEntries[i].getRecordId());        }         return movieRatings;    }     private void persistRatedMovie(Movie movie) throws ApplicationException {        IndexEntry indexEntry =             rmsAdapter.getIndexEntry(movie.getPrimaryKey(),                                      IndexEntry.TYPE_MOVIE,                                      IndexEntry.MODE_ANY);        if (indexEntry == null) {            int recordId = rmsAdapter.storeMovie(movie, -1);            indexEntry = new IndexEntry(recordId, IndexEntry.TYPE_MOVIE,                                         movie.getPrimaryKey(),                                         IndexEntry.MODE_PERSISTING);            rmsAdapter.addIndexEntry(indexEntry);        } else if (indexEntry.getMode() != IndexEntry.MODE_PERSISTING) {            // since persisting: overwrite caching entries            indexEntry = new IndexEntry(indexEntry.getRecordId(),                                         indexEntry.getType(),                                         indexEntry.getKey(),                                         IndexEntry.MODE_PERSISTING);            rmsAdapter.addIndexEntry(indexEntry);        }         return;    }     public void setMovieRatingSyncAnchor(SyncAnchor syncAnchor)             throws ApplicationException {        IndexEntry indexEntry = rmsAdapter.getIndexEntry("MOVIE_RATINGS",                 IndexEntry.TYPE_SYNC_ANCHOR, IndexEntry.MODE_ANY);        int recordId = rmsAdapter.storeSyncAnchor(syncAnchor,                                                   indexEntry != null                                                   ? indexEntry.getRecordId()                                                   : -1);        if (indexEntry == null) {            indexEntry = new IndexEntry(recordId,                                         IndexEntry.TYPE_SYNC_ANCHOR,                                         "MOVIE_RATINGS",                                         IndexEntry.MODE_PERSISTING);            rmsAdapter.addIndexEntry(indexEntry);        }         return;    }     public SyncAnchor getMovieRatingSyncAnchor() throws ApplicationException {        IndexEntry indexEntry = rmsAdapter.getIndexEntry("MOVIE_RATINGS",                 IndexEntry.TYPE_SYNC_ANCHOR, IndexEntry.MODE_ANY);        return indexEntry != null                ? rmsAdapter.loadSyncAnchor(indexEntry.getRecordId()) : null;    } }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -