研究了几天Guice和NetMind,于是针对前段时间javaeye中关于ActiveRecord的讨论实现了一个简单的ActiveRecord模型。
Guice:
http://code.google.com/p/google-guice/
NetMind:
http://netmind.hu/persistence/
java 代码
- public class ActiveRecord {
-
- @Inject
- protected static transient Store store;
-
- public void save() {
- store.save(this);
- }
-
- public void delete() {
- store.remove(this);
- }
-
-
-
-
- public Long getPersistenceId() {
- return this.persistenceId;
- }
- }
-
- public class User extends ActiveRecord {
- private String name;
-
- public User() {}
- public User(String name) {
- this.name = name;
- }
-
- public String getName() {
- return this.name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @SuppressWarning("unchecked")
- public static List findAll() {
- return (List<User>)store.find("find user");
- }
-
- public static User findByName(String name) {
- return (User)store.findSingle("find user where name=?", new Object[] {name});
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class ExampleModule extends AbstractModule {
- protected void configure() {
- bind(Store.class).toInstance(new Store("org.hsqldb.jdbcDriver", "jdbc:hsqldb:file:temp"));
- binder().requestStaticInjection(ActiveRecord.class);
- }
- }
<user><user></user>
分享到:
相关推荐
关于数据库操作的第三方类库比比谐是,比如有名的NHibernate,ActiveRecord,等等。ActiveRecord在开发项目中也用,但感觉不是很好用,最大的优点是,基本的添加修改,删除等操作,不需要写任何代码,但对于一些复杂的...
安装不幸的是,已经有一个名为simple_filter的 gem,但不用担心,您只需要在 Gemfile 中引入 lib: gem 'simple-filter' , require : 'simple_filter'用法使用搜索类非常简单: FooSearch . new ( params = { } ) . ...
simple_enum, 支持ActiveModel的简单 enum ( 包括验证和 i18n ) SimpleEnum 对于ActiveRecord和 ruby,低调的枚举像字段一样,给ActiveRecord和Mongoid模型( 为 Rails 4 构建) 带来了枚举功能。从 2.0版本开始,...
允许您在 ActiveRecord 模型上定义魔法scope ,而无需提供where条件。 条件源自scope的名称。 多个条件可以通过名字被他们用分离来定义and很像魔术find_by_attribute1_and_attribute2方法。 安装 将此行添加到应用...
从2.0版开始,simple_enum不再与Rails 3.x或Ruby 1.8兼容,请改用1.6版: : 注意:最近在github上搜索enum结果是,有很多类似的解决方案。 实际上,从Rails 4.1开始,有ActiveRecord::Enum提供了一些功能,但是恕...
非常简单的聊天服务器 一个非常简单的服务器,用于将消息发布到聊天室。 使用Sinatra和ActiveRecord的开发/学习工具。 有用的资源
版本流星 1.0.3.1安装 # Should be as simple as cloning the repository... git clone https://github.com/awatson1978/clinical-activerecord.git# And then running it...meteor许可麻省理工学院许可证。 随意...
SimpleAdmin No frills安装 gem install simple_admin_rails许可证 这个项目震撼并使用 MIT-LICENSE。文件维基 说明 用于 Rails 项目的简单(单一模型)Rails Engine 嵌入式管理界面。 关于¶ ↑ 这个 gem 的动机是...
simple_presenter安装gem install simple_presenter用法class User < ActiveRecord :: Base # implements the following attributes: name, email, password_hash, password_saltendclass UserPresenter < ...
SmoothOperator Ruby gem,它模仿... 使用simple_form gem形成错误; 使用茧宝石嵌套的对象; 用kaminari宝石进行无尽分页 和别的... 1)安装 将此行添加到您的应用程序的Gemfile中: gem 'smooth_operator'
描述SMQ使用ActiveRecord提供基于数据库的,基于JSON的和工作程序平台; 请勿将其与诸如或类的相混淆。 还存在其他简单的消息队列系统,但是这些系统通常使用无法转移到其他平台的元帅Ruby对象,或者作为单独的...
它不依赖于任何ORM,因此您可以自由地将其与ActiveRecord,Mongoid,任何其他ORM或纯Ruby对象一起使用。 感谢所有贡献者的出色帮助! 安装 只需将其添加到您的Gemfile中,然后进行捆绑安装即可: gem "simple_...
ArMailerAWS 守护程序,用于使用ActiveRecord通过SMTP,Amazon Simple Email Service(Amazon SES)或Mandrill发送批次的电子邮件,用于存储消息。 ArMailerAWS处理每日配额,每秒发送的最大电子邮件数(最大发送...
这个 gem 为您的 ActiveRecord 关系提供了简单的列表对象。 为什么 通常,应用程序列表具有可排序、可过滤和可分页的功能。 我需要一种简单直接的方法来为我的应用程序编写灵活的过滤器和排序,所以我创建了这个 ...
Connect forms to models by setting up a database, and use Rails' ActiveRecord to create code that maps to database structures • Use Rails scaffolding to build applications from a view-centric ...
RoR ActiveRecord style syntax Ambient transaction Dynamic object Partial update 1:1 1:Many Many:Many relations Auto create table Anti sql injection Multiple data source Object validation ...
A simple utility to generate NHibernate mapping files and corresponding domain classes from existing DB tables. Features: 1. Supports Oracle, SqlServer, PostgreSQL, MySQL, SQLite, Sybase, Ingres, ...
安装简而言之首先安装并使用所需的任何模块进行配置,然后将gem添加到Gemfile并bundle install : # Gemfilegem 'simple_token_authentication' , '~> 1.0' # see semver.org 完成此操作后,只需两个步骤即可设置...
smart_json_style ( :with_detail , :simple , author : :only_name , comments : :with_user ) end class User < ActiveRecord :: Base smart_json_style ( :only_name ) { { name : name } } smart_json_...
:gem_stone: Simple MySQLi Class This is a simple MySQL Abstraction Layer compatible with PHP 7+ that provides a simple and secure interaction with your database using mysqli_* functions at its core. ...