• Stars
    star
    462
  • Rank 94,832 (Top 2 %)
  • Language
    Ruby
  • License
    BSD 2-Clause "Sim...
  • Created over 16 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JRuby's ActiveRecord adapter using JDBC.

ActiveRecord JDBC Adapter

Gem Version

ActiveRecord-JDBC-Adapter (AR-JDBC) is the main database adapter for Rails' ActiveRecord component that can be used with JRuby. ActiveRecord-JDBC-Adapter provides full or nearly full support for: MySQL, PostgreSQL, SQLite3 and MSSQL* (SQLServer).

Unless we get more contributions we will not be supporting more adapters. Note that the amount of work needed to get another adapter is not huge but the amount of testing required to make sure that adapter continues to work is not something we can do with the resources we currently have.

Versions are targeted at certain versions of Rails and live on their own branches.

Gem Version Rails Version Branch min JRuby min Java
50.x 5.0.x 50-stable 9.1.x 7
51.x 5.1.x 51-stable 9.1.x 7
52.x 5.2.x 52-stable 9.1.x 7
60.x 6.0.x 60-stable 9.2.7 8
61.x 6.1.x 61-stable 9.2.7 8
70.x 7.0.x 70-stable 9.3.0 8
71.x 7.1.x master 9.4.3 8

Note: 71.x is still under development and not supported yet.

Note that JRuby 9.1.x and JRuby 9.2.x are at end-of-life. We recommend Java 8 at a minimum for all versions.

Using ActiveRecord JDBC

Inside Rails

To use AR-JDBC with JRuby on Rails:

  1. Choose the adapter you wish to gem install. The following pre-packaged adapters are available:
  • MySQL (activerecord-jdbcmysql-adapter)
  • PostgreSQL (activerecord-jdbcpostgresql-adapter)
  • SQLite3 (activerecord-jdbcsqlite3-adapter)
  • MSSQL (activerecord-jdbcsqlserver-adapter)
  1. If you're generating a new Rails application, use the following command:

    jruby -S rails new sweetapp

  2. Configure your database.yml in the normal Rails style:

development:
  adapter: mysql2 # or mysql
  database: blog_development
  username: blog
  password: 1234

For JNDI data sources, you may simply specify the JNDI location as follows, it's recommended to use the same adapter: setting as one would configure when using "bare" (JDBC) connections e.g. :

production:
  adapter: postgresql
  jndi: jdbc/PostgreDS

NOTE: any other settings such as database:, username:, properties: make no difference since everything is already configured on the JNDI DataSource end.

JDBC driver specific properties might be set if you use an URL to specify the DB or preferably using the properties: syntax:

production:
  adapter: mysql
  username: blog
  password: blog
  url: "jdbc:mysql://localhost:3306/blog?profileSQL=true"
  properties: # specific to com.mysql.jdbc.Driver
    socketTimeout:  60000
    connectTimeout: 60000

MySQL specific notes

Depending on the MySQL server configuration, it might be required to set additional connection properties for date/time support to work correctly. If you encounter problems, try adding this to your database configuration:

  properties:
    serverTimezone: <%= java.util.TimeZone.getDefault.getID %>

The correct timezone depends on the system setup, but the one shown is a good place to start and is actually the correct setting for many systems.

Standalone with ActiveRecord

Once the setup is made (see below) you can establish a JDBC connection like this (e.g. for activerecord-jdbcderby-adapter):

ActiveRecord::Base.establish_connection(
  adapter: 'sqlite3',
  database: 'db/my-database'
)

Using Bundler

Proceed as with Rails; specify ActiveRecord in your Bundle along with the chosen JDBC adapter(s), this time sample Gemfile for MySQL:

gem 'activerecord', '~> 6.0.3'
gem 'activerecord-jdbcmysql-adapter', '~> 60.2', :platform => :jruby

When you require 'bundler/setup' everything will be set up for you as expected.

Without Bundler

Install the needed gems with JRuby, for example:

gem install activerecord -v "~> 6.0.3"
gem install activerecord-jdbc-adapter -v "~> 60.2" --ignore-dependencies

If you wish to use the adapter for a specific database, you can install it directly and the (jdbc-) driver gem (dependency) will be installed as well:

jruby -S gem install activerecord-jdbcmysql-adapter -v "~> 60.2"

Your program should include:

require 'active_record'
require 'activerecord-jdbc-adapter' if defined? JRUBY_VERSION

Source

The source for activerecord-jdbc-adapter is available using git:

git clone git://github.com/jruby/activerecord-jdbc-adapter.git

Please note that the project manages multiple gems from a single repository, if you're using Bundler >= 1.2 it should be able to locate all gemspecs from the git repository. Sample Gemfile for running with (MySQL) master:

gem 'activerecord-jdbc-adapter', :github => 'jruby/activerecord-jdbc-adapter'
gem 'activerecord-jdbcmysql-adapter', :github => 'jruby/activerecord-jdbc-adapter'

Getting Involved

Please read our CONTRIBUTING & RUNNING_TESTS guides for starters. You can always help us by maintaining AR-JDBC's wiki.

Feedback

Please report bugs at our issue tracker. If you're not sure if something's a bug, feel free to pre-report it on the mailing lists or ask on the #JRuby IRC channel on http://freenode.net/ (try web-chat).

Authors

This project was originally written by Nick Sieger and Ola Bini with lots of help from the JRuby community. Polished 3.x compatibility and 4.x support (for AR-JDBC >= 1.3.0) was managed by Karol Bucek among others. Support for Rails 6.0 and 6.1 was contributed by shellyBits GmbH

License

ActiveRecord-JDBC-Adapter is open-source released under the BSD/MIT license. See LICENSE.txt included with the distribution for details.

Open-source driver gems within AR-JDBC's sources are licensed under the same license the database's drivers are licensed. See each driver gem's LICENSE.txt.

More Repositories

1

jruby

JRuby, an implementation of Ruby on the JVM
Ruby
3,776
star
2

warbler

Warbler chirpily constructs .war files of your Ruby applications.
Ruby
881
star
3

jruby-rack

Rack for JRuby and Java appservers
Ruby
397
star
4

joni

Java port of Oniguruma regexp library
Java
166
star
5

jrubyfx

JavaFX JRuby binding
Ruby
144
star
6

jruby-maven-plugins

maven plugin to handle rubygems in a maven way. including support for rspec, rails, cucumber, rake, etc
Java
112
star
7

jruby-lint

See how ready your Ruby code is to run on JRuby
Ruby
101
star
8

heroku-buildpack-jruby

Shell
63
star
9

jruby-ossl

DEFUNCT, new repository at:
47
star
10

jruby-openssl

JRuby's OpenSSL gem
Java
45
star
11

jruby-parser

JRuby's parser customized for IDE usage
Java
44
star
12

maven_gem

A RubyGems plugin (and a utility) to install Maven artifacts as RubyGems
Ruby
40
star
13

perfer

Ruby
31
star
14

image_voodoo

ImageScience-compatible image processing for JRuby
Ruby
26
star
15

jruby-launcher

JRuby's native launcher executable
C++
24
star
16

jcodings

Java-based codings helper classes for Joni and JRuby
Java
20
star
17

using_jruby

Code samples from the "Using JRuby" book
Ruby
19
star
18

java_inline

JVM language support for RubyInline
Ruby
19
star
19

docker-jruby

Dockerfile
18
star
20

jruby-debug

JRuby-based backend for ruby-debug
Java
15
star
21

jruby-rails-templates

App templates for JRuby on Rails applications
Ruby
14
star
22

maven-tools

ruby helpers for maven related tasks
Ruby
14
star
23

jruby-mains

a couple of main methods for embedded (j)ruby inside a jar/war file
Ruby
10
star
24

jruby-ldap

JRuby/LDAP is a native LDAP implementation that uses JNDI to implement a Ruby/LDAP compatible API.
Ruby
10
star
25

bytelist

DEPRECATED: JRuby no longer maintains org.jruby.util.ByteList as a separate library
Java
10
star
26

rubygems-servlets

webapp which hosts rubygems or a proxy to rubygems. delivers gem maven artifacts as well
Java
9
star
27

jruby-demos

Demos for JRuby presentations at conferences
Ruby
8
star
28

jruby-dashboard

A Dashing dashboard for JRuby applications.
JavaScript
8
star
29

rubybench

Ruby
7
star
30

jrubyhub

Rails 3 + JRuby open source application
Ruby
7
star
31

blog.jruby.org

This is the site and data for blog.jruby.org
CSS
7
star
32

jruby-cext

The MRI C extension subsystem for JRuby
C++
7
star
33

collateral

Public collateral for JRuby
6
star
34

jruby-examples

A collection of examples to help you get the most out of JRuby
Java
5
star
35

jruby-workshop

Course material for JRuby workshop at RubyConf AU 2013
Ruby
4
star
36

jruby-startup

A collection of utilities to help improve JRuby startup time
Ruby
4
star
37

jruby-cdc

A stripped-down version of JRuby that runs on Java ME's CDC profile
Ruby
4
star
38

jruby-graal

Java
4
star
39

jruby-visualizer

Visualize JRuby's runtime in action
Ruby
4
star
40

jrubyconf.com

JRubyConf web sites and collateral
JavaScript
3
star
41

mavengem

Mavengem protocol and mavengem wagon
Ruby
3
star
42

jay

Jay grammar/parser tool
C
2
star
43

jruby-mac-installer

Ruby
2
star
44

dbm

DBM extension for JRuby
Java
2
star
45

jruby-prism

Java parts of integrating the Prism parser into JRuby. Plugs in using an SPI
Java
2
star
46

jruby-async-profiler

A Ruby gem for JRuby that installs the JVM async-profiler extension
Ruby
1
star
47

ruby-maven

Ruby
1
star
48

jzlib

JRuby's fork of the jzlib pure-Java zlib library
Java
1
star
49

gitosis-admin

Gitosis setup for jruby.org
1
star
50

jbang-catalog

Catalog for jbang command line launcher
1
star
51

jruby-readline

JRuby's `readline` library
Java
1
star