Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jruby support? #15

Open
chriskilding opened this issue May 9, 2014 · 4 comments
Open

Jruby support? #15

chriskilding opened this issue May 9, 2014 · 4 comments

Comments

@chriskilding
Copy link

When I tried to use this gem on Jruby 1.7.10 I got the following error, basically it looks like this gem has a hard requirement on the MRI / cruby 'pg' gem at the moment. Could this be fixed to support running on Jruby?

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /Users/me/.rbenv/versions/jruby-1.7.10/bin/jruby extconf.rb 
NotImplementedError: C extension support is not enabled. Pass -Xcext.enabled=true to JRuby or set JRUBY_OPTS.

   (root) at /Users/me/.rbenv/versions/jruby-1.7.10/lib/ruby/shared/mkmf.rb:8
  require at org/jruby/RubyKernel.java:1083
   (root) at /Users/me/.rbenv/versions/jruby-1.7.10/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:1
   (root) at extconf.rb:2


Gem files will remain installed in /Users/me/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/gems/pg-0.17.1 for inspection.
Results logged to /Users/me/.rbenv/versions/jruby-1.7.10/lib/ruby/gems/shared/gems/pg-0.17.1/ext/gem_make.out
An error occurred while installing pg (0.17.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.
@diogob
Copy link
Owner

diogob commented May 9, 2014

The thing is, I don't have a JRuby env to test the gem, but I believe it could work with a JDBC adapter and some tweaks in the code. Beware that I use some methods of the pg raw interface, that's why there is a dependency. But If you want to do this and send me a PR I'll gladly merge it ;)

@diogob diogob closed this as completed May 9, 2014
@chriskilding
Copy link
Author

Not able to do a full PR for you at this time, but here's some code that Worked For Me:

require 'java'
require "jdbc/postgres"
...
# Ensure you are using absolute path for safety
path = File.expand_path [some path], __FILE__

# Load DB driver
Jdbc::Postgres.load_driver

# Load the JDBC underlying connection
connection = [some model].connection.jdbc_connection

# Invoke some Java to let us use the COPY command
# not allowed to do that normally by the JDBC driver.
copier = org.postgresql.copy.CopyManager.new(connection)
istream = java.io.FileInputStream.new path
copier.copyIn("COPY [pluralised lower case model name] FROM STDIN WITH (FORMAT CSV, HEADER TRUE, DELIMITER ',')", istream)

If you want to have a crack at integrating this into the gem, setting up a jruby env is trivial - rbenv install jruby-[version] will do, the rvm equivalent is probably also a one-liner.

@aditya-sanghi
Copy link

@themasterchef I am doing copier.copyIn("\copy order_transactions TO '/tmp/foo.csv' DELIMITER E'\t' CSV HEADER")

but getting following error:

Java::OrgPostgresqlUtil::PSQLException: ERROR: syntax error at or near ""

@diogob
Copy link
Owner

diogob commented Feb 23, 2017

JRuby support will require some major refactoring. The current code is too brittle to accept different database drivers.
The interface could also receive some love (I would drop the acts_as pattern and pass the model as a dependency).
I see that the test cases are a valuable thing that could be shared between a common gem for MRI and JRuby.
Having said that I'll reopen the issue as a possible enhancement.
If you are reading this thread and would like to see this gem supporting jruby please add a 👍 reaction to this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants