ruby-phoenix 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 22f1e6e8717db4ced58fe694aa3d29df8229c6b3
4
+ data.tar.gz: 27b7626119d9910f1a2133cf225544af7f45af3e
5
+ SHA512:
6
+ metadata.gz: 102744773e7e9918d53ad5c7d06aa5ce02b77fae5f0c6328ad7bf30d12b57c407f42471c5ba38f6cb4462578d00c0db0736cfebae0af43414ec01762c9f55e9b
7
+ data.tar.gz: 056a98cd8871c64a845839c16012bd18ca90ffeea476c9d174e10a201b2aef51bee27de5b61ad9db4fa9ecd35eb5b20ebd240f1508373ba1a34352b71c6b83b9
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://ruby.taobao.org'
2
+
3
+ # Specify your gem's dependencies in ruby-phoenix.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruby-phoenix (0.0.8)
5
+ activesupport (~> 4.2)
6
+ rake (~> 10.4)
7
+ rjb (~> 1.4)
8
+
9
+ GEM
10
+ remote: https://ruby.taobao.org/
11
+ specs:
12
+ activesupport (4.2.1)
13
+ i18n (~> 0.7)
14
+ json (~> 1.7, >= 1.7.7)
15
+ minitest (~> 5.1)
16
+ thread_safe (~> 0.3, >= 0.3.4)
17
+ tzinfo (~> 1.1)
18
+ coderay (1.1.0)
19
+ diff-lcs (1.2.5)
20
+ i18n (0.7.0)
21
+ json (1.8.3)
22
+ method_source (0.8.2)
23
+ minitest (5.8.2)
24
+ pry (0.10.1)
25
+ coderay (~> 1.1.0)
26
+ method_source (~> 0.8.1)
27
+ slop (~> 3.4)
28
+ rake (10.4.2)
29
+ rjb (1.5.3)
30
+ rspec (3.1.0)
31
+ rspec-core (~> 3.1.0)
32
+ rspec-expectations (~> 3.1.0)
33
+ rspec-mocks (~> 3.1.0)
34
+ rspec-core (3.1.7)
35
+ rspec-support (~> 3.1.0)
36
+ rspec-expectations (3.1.2)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.1.0)
39
+ rspec-mocks (3.1.3)
40
+ rspec-support (~> 3.1.0)
41
+ rspec-support (3.1.2)
42
+ slop (3.6.0)
43
+ thread_safe (0.3.5)
44
+ tzinfo (1.2.2)
45
+ thread_safe (~> 0.1)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ bundler (~> 1.7)
52
+ pry (~> 0.10)
53
+ rspec (~> 3.1)
54
+ ruby-phoenix!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 xianfeng wang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 昊淼
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # ruby-phoenix
2
+ Ruby Client To Run SQL Of Apache Phoenix.
3
+
4
+ ## Install
5
+ ```
6
+ Gemfile
7
+ gem 'ruby-phoenix', require: 'phoenix'
8
+ ```
9
+
10
+ ## Config
11
+ ```
12
+ 1, Install Java jar file
13
+ rake phoenix:install
14
+ 2, config Hbase host and port
15
+ vi config/phoenix.yml
16
+ ```
17
+
18
+ ## Usage
19
+ ```
20
+ 1, define Model
21
+ class StYunosAppCenterCntNew < Phoenix::Base
22
+ end
23
+
24
+ 2.1, Run SQL
25
+ sql = "select * from ST_YUNOS_APP_CENTER_CNT_NEW limit 10"
26
+ results = Phoenix::Rjb.execute(sql)
27
+
28
+ 2.2, OR Use Model Like ActiveRecord
29
+ StYunosAppCenterCntNew.all
30
+ ```
31
+
32
+ That's ALL, Enjoy It!!!
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Sync Files To Gitub Project"
4
+ task :sync do
5
+ system "rsync -vzrtopg --progress --exclude-from=rules.txt /data/projects/alibaba/ruby-phoenix/* /data/projects/ruby-phoenix/"
6
+ end
data/lib/phoenix.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "active_support"
2
+ require "active_support/core_ext"
3
+ require "rjb"
4
+
5
+ require "phoenix/rjb"
6
+ require "phoenix/common"
7
+ require "phoenix/relation"
8
+ require "phoenix/base"
9
+ require "phoenix/version"
10
+
11
+ load "tasks/phoenix.rake"
@@ -0,0 +1,90 @@
1
+ package phoenix;
2
+
3
+ import java.sql.Connection;
4
+ import java.sql.DriverManager;
5
+ import java.sql.ResultSet;
6
+ import java.sql.Statement;
7
+ import java.sql.DatabaseMetaData;
8
+
9
+ public class Connect {
10
+
11
+ private String host;
12
+ private String port;
13
+
14
+ private Connection connection;
15
+
16
+ public Connect(String host, String port) {
17
+ this.host = host;
18
+ this.port = port;
19
+ }
20
+
21
+ public void setHost(String host) {
22
+ this.host = host;
23
+ }
24
+
25
+ public void setPort(String port){
26
+ this.port = port;
27
+ }
28
+
29
+ public String getHost(){
30
+ return host;
31
+ }
32
+
33
+ public String getPort(){
34
+ return port;
35
+ }
36
+
37
+ public Connection connect() {
38
+ try {
39
+ Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
40
+ // String DBConnectionString = "jdbc:phoenix:10.125.51.86:2181:/hbase";
41
+ // String DBConnectionString = "jdbc:phoenix:kanbox-datacraft-cloud-compute-10.et2:2181:/hbase"; // hadoop10.cloud.cm10 | hadoop9.cloud.cm10 | hadoop8.cloud.cm10
42
+ String DBConnectionString = "jdbc:phoenix:" + this.host + ":" + this.port + ":/hbase";
43
+ connection = DriverManager.getConnection(DBConnectionString);
44
+ } catch (Exception e) {
45
+ e.printStackTrace();
46
+ }
47
+ return connection;
48
+ }
49
+
50
+ public ResultSet executeQuery(String sql) {
51
+ connect();
52
+ ResultSet rs = null;
53
+ try {
54
+ Statement statement = connection.createStatement();
55
+ rs = statement.executeQuery(sql);
56
+ } catch (Exception e) {
57
+ e.printStackTrace();
58
+ }
59
+ return rs;
60
+ }
61
+
62
+ public ResultSet getMetaData(String tableName) throws Exception {
63
+ connect();
64
+ DatabaseMetaData md = connection.getMetaData();
65
+ ResultSet rs = md.getColumns(null, null, tableName, null);
66
+ return rs;
67
+ }
68
+
69
+ public Integer executeUpdate(String sql) {
70
+ connect();
71
+ Integer i = 0;
72
+ try {
73
+ Statement statement = connection.createStatement();
74
+ i = statement.executeUpdate(sql);
75
+ connection.commit();
76
+ } catch (Exception e) {
77
+ e.printStackTrace();
78
+ }
79
+ return i;
80
+ }
81
+
82
+ public void close() {
83
+ try {
84
+ connection.close();
85
+ } catch (Exception e) {
86
+ e.printStackTrace();
87
+ }
88
+ }
89
+
90
+ }
@@ -0,0 +1,24 @@
1
+ #coding:utf-8
2
+ module Phoenix
3
+ class Base
4
+ include Common
5
+
6
+ # 类变量meta_data 记录表的字段类型
7
+ # [{:column_name=>"APP_ID", :column_type=>"UNSIGNED_INT"},
8
+ # {:column_name=>"ACCOUNT_ID", :column_type=>"VARCHAR"},
9
+ # {:column_name=>"CREATE_DATE", :column_type=>"UNSIGNED_LONG"}]
10
+ def self.inherited(base)
11
+ table_name = base.table_name
12
+ meta = Phoenix::Rjb.get_meta_data(table_name)
13
+ if meta.blank?
14
+ raise "the phoenix table #{table_name} is Not Found!!!"
15
+ end
16
+ base.class_variable_set("@@meta_data", meta)
17
+
18
+ meta.each do |row|
19
+ base.send(:attr_accessor, row[:column_name])
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,216 @@
1
+ #coding:utf-8
2
+ module Phoenix
3
+ module Common
4
+ extend ActiveSupport::Concern
5
+
6
+ module Status
7
+ Normal = 0
8
+ Forbid = 1
9
+ end
10
+
11
+ module ClassMethods
12
+
13
+ def first
14
+ sql = "select * from #{self.table_name} limit 1"
15
+ Phoenix::Rjb.execute(sql)[0]
16
+ end
17
+
18
+ def select(*fields)
19
+ sql = "SELECT #{fields.join(', ')} FROM #{table_name}"
20
+ Phoenix::Rjb.execute(sql)
21
+ end
22
+
23
+ def quote(s)
24
+ return s if s.blank?
25
+ return s if s.is_a? Integer
26
+ "'#{s.gsub(/\\/, '\&\&').gsub(/'/, "''")}'"
27
+ end
28
+
29
+ def in_cond(arr)
30
+ arr.map { |_v| self.quote(_v) }.join(',')
31
+ end
32
+
33
+ def is_int_column?(column)
34
+ meta = self.class_variable_get("@@meta_data")
35
+ if meta.blank?
36
+ table_name = self.table_name
37
+ meta = Phoenix::Rjb.get_meta_data(table_name)
38
+ self.class_variable_set("@@meta_data", meta)
39
+ end
40
+ type = meta.select { |ele| ele[:column_name] == column.to_s.upcase }.first[:column_type]
41
+ if type =~ /int|long/i
42
+ return true
43
+ end
44
+ return false
45
+ end
46
+
47
+ def table_name
48
+ last_3_letter = self.to_s[-3..-1]
49
+ if last_3_letter.downcase == 'new'
50
+ return self.to_s.tableize.singularize.upcase[0..-2]
51
+ else
52
+ return self.to_s.tableize.singularize.upcase
53
+ end
54
+ end
55
+
56
+ def associate_table_name(klass)
57
+ case klass
58
+ when "Base"
59
+ "BASE"
60
+ else
61
+ klass.tableize.singularize
62
+ end
63
+ end
64
+
65
+ def find(id)
66
+ column = "#{self.to_s}_ID"
67
+ unless self.is_int_column?(column)
68
+ id = self.quote(id)
69
+ end
70
+
71
+ sql = "SELECT * FROM #{self.to_s} WHERE #{column} = #{id}"
72
+
73
+ digest = Digest::MD5.hexdigest(sql)
74
+
75
+ Datacraft::Cache.get digest do
76
+ arr = Phoenix::Rjb.execute(sql)
77
+ arr.first
78
+ end
79
+ end
80
+
81
+ def find_by_sql(sql)
82
+ Phoenix::Rjb.execute(sql)
83
+ end
84
+
85
+ def all
86
+ sql = "SELECT * FROM #{self.table_name}"
87
+ Phoenix::Rjb.execute(sql)
88
+ end
89
+
90
+ ##
91
+ # 组装 sql
92
+ # Hash
93
+ # Model.where(field1: value1, field2: value2)
94
+ # String
95
+ # Model.where('field1 = value1 AND field2 = value2')
96
+ # Blank
97
+ # Model.where() / Model.where('')
98
+ def where(*args)
99
+ table_name = self.table_name
100
+ if args.all? { |ele| ele.blank? }
101
+ sql = %(SELECT * FROM #{table_name})
102
+ return Relation.new(sql)
103
+ end
104
+ if args.size < 2 and args[0].is_a? String
105
+ sql = %(SELECT * FROM #{table_name} WHERE #{args[0]})
106
+ return Relation.new(sql)
107
+ end
108
+ options = args.extract_options!
109
+ cond = ""
110
+ options.each_with_index do |(k,v), index|
111
+ if index > 0
112
+ if v.is_a? Array
113
+ cond << " AND #{k} IN " + " (#{v.map { |_v| self.quote(_v) }.join(',')})"
114
+ else
115
+ if self.is_int_column? k
116
+ cond << " AND #{k} = #{v} "
117
+ else
118
+ cond << " AND #{k} = '#{v}' "
119
+ end
120
+ end
121
+ else
122
+ if v.is_a? Array
123
+ cond << " #{k} IN " + " (#{v.map { |_v| self.quote(_v) }.join(',')})"
124
+ else
125
+ if self.is_int_column?(k)
126
+ cond << " #{k} = #{v} "
127
+ else
128
+ cond << " #{k} = '#{v}' "
129
+ end
130
+ end
131
+ end
132
+ end
133
+ sql = %(SELECT * FROM #{table_name} WHERE #{cond})
134
+ Relation.new(sql)
135
+ end
136
+
137
+ def build(h)
138
+ self.new(h)
139
+ end
140
+
141
+ def belongs_to(t)
142
+ self.class_eval do
143
+ define_method t do
144
+ key = "#{t.upcase}_ID"
145
+ sql = %(SELECT * FROM #{t.upcase} WHERE APP_ID = '#{self.APP_ID}' AND #{key} = '#{self.send(key)}')
146
+ digest = Digest::MD5.hexdigest(sql)
147
+ Datacraft::Cache.get digest do
148
+ arr = Phoenix::Rjb.execute(sql)
149
+ arr.first
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ def has_many(*args)
156
+ t = args[0].to_s
157
+ options = args.extract_options!
158
+ self.class_eval do
159
+ define_method t do
160
+ if options[:through]
161
+ key = "#{self.class.to_s.upcase}_ID"
162
+ assoite_sql = %(SELECT * FROM #{options[:through]} WHERE APP_ID = '#{self.APP_ID}' AND #{key} = '#{self.send(key)}')
163
+ assoite_rs = Phoenix::Rjb.execute(assoite_sql)
164
+ assoite_key = "#{t.singularize.upcase}_ID"
165
+ ids = assoite_rs.collect { |ass| ass.send("#{assoite_key}") }
166
+ if ids.present?
167
+ sql = %(SELECT * FROM #{t.singularize} WHERE APP_ID = '#{self.APP_ID}' AND #{assoite_key} IN (#{ids.map { |_v| self.class.quote(_v) }.join(',')}))
168
+ Phoenix::Rjb.execute(sql)
169
+ else
170
+ []
171
+ end
172
+ else
173
+ # table = "#{t[0..-2]}"
174
+ table = self.class.associate_table_name(t.singularize)
175
+ key = "#{self.class.to_s.upcase}_ID"
176
+ v = self.send(key)
177
+ unless self.class.is_int_column?(key)
178
+ v = self.class.quote(v)
179
+ end
180
+ sql = %(SELECT * FROM #{table} WHERE #{key} = #{v})
181
+ Phoenix::Rjb.execute(sql)
182
+ end
183
+ end
184
+ end
185
+ end
186
+
187
+ end
188
+
189
+ def initialize(h)
190
+ return self if h.blank?
191
+ h.each do |k, v|
192
+ if self.respond_to? "#{k}="
193
+ self.send("#{k}=", v)
194
+ elsif k =~ /SequenceValueExpression/
195
+ self.instance_variable_set("@next_value", v)
196
+ else
197
+ self.instance_variable_set("@#{k[/\w+/]}", v)
198
+ end
199
+ end
200
+ return self
201
+ end
202
+
203
+ def human_status
204
+ self.STATUS == '1' ? "禁用" : "正常"
205
+ end
206
+
207
+ def human_create_date
208
+ Time.at(self.CREATE_DATE.to_i/1000).strftime("%Y-%m-%d %H:%M:%S")
209
+ end
210
+
211
+ def error
212
+ self.errors.values.join("<br/>")
213
+ end
214
+
215
+ end
216
+ end
@@ -0,0 +1,37 @@
1
+ #coding:utf-8
2
+ module Phoenix
3
+ class Relation
4
+
5
+ attr_accessor :sql
6
+
7
+ def initialize(sql)
8
+ @sql = sql
9
+ end
10
+
11
+ def limit(size)
12
+ if size.to_i > 0
13
+ self.sql << " LIMIT #{size}"
14
+ end
15
+ self
16
+ end
17
+
18
+ def order(o)
19
+ self.sql << " ORDER BY #{o}"
20
+ self
21
+ end
22
+
23
+ def take
24
+ Phoenix::Rjb.execute(@sql)
25
+ end
26
+
27
+ def where(str)
28
+ self.sql << str if str.present?
29
+ self
30
+ end
31
+
32
+ def to_sql
33
+ self.sql
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,120 @@
1
+ #coding: utf-8
2
+ module Phoenix
3
+ class Rjb
4
+
5
+ def self.is_query?(s)
6
+ s and !(s.strip =~ /^select/i).nil?
7
+ end
8
+
9
+ # 查询
10
+ # return => Array [#<>, #<>, ...]
11
+ # 更新(增加, 修改,删除)
12
+ # return 1 成功, 0 失败
13
+ def self.execute(sql)
14
+ Rails.logger.info "[SQL]: #{sql}\n" if defined? Rails
15
+
16
+ h = YAML.load(File.read "#{Rails.root}/config/phoenix.yml")
17
+ host = h["host"]
18
+ port = h["port"]
19
+
20
+ c = ::Rjb::import('phoenix.Connect')
21
+ instance = c.new(host, port)
22
+ if self.is_query?(sql)
23
+ rs = instance.executeQuery(sql)
24
+ if rs.nil?
25
+ arr = []
26
+ else
27
+ arr = resultset_to_obj(rs)
28
+ end
29
+ instance.close()
30
+ return arr
31
+ else
32
+ i = instance.executeUpdate(sql)
33
+ # p i.methods - Object.methods
34
+ # p i.intValue
35
+ instance.close()
36
+ return i.intValue
37
+ end
38
+ end
39
+
40
+ def self.get_meta_data(table_name)
41
+ c = ::Rjb::import('phoenix.Connect')
42
+
43
+ h = YAML.load(File.read "#{Rails.root}/config/phoenix.yml")
44
+ host = h["host"]
45
+ port = h["port"]
46
+
47
+ instance = c.new(host, port)
48
+ rs = instance.getMetaData(table_name)
49
+ # binding.pry
50
+ # rs.java_methods
51
+ arr = resultset_to_meta(rs)
52
+ instance.close()
53
+ $stdout.print "[MetaData:#{table_name}]: #{arr.inspect}\n"
54
+ return arr
55
+ end
56
+
57
+ def self.resultset_to_meta(resultset)
58
+ columns = []
59
+ while resultset.next
60
+ column_name = resultset.getString("COLUMN_NAME")
61
+ column_type = resultset.getString("TYPE_NAME")
62
+ columns << { column_name: column_name, column_type: column_type }
63
+ end
64
+ return columns
65
+ end
66
+
67
+ # 把 Java 中的 ResultSet对象 转化为 Ruby 中的 对象
68
+ # https://gist.github.com/rjackson/1366047
69
+ def self.resultset_to_obj(resultset)
70
+ meta = resultset.meta_data
71
+ table_name = meta.table_name(1)
72
+ if table_name == "BASE_SINDEX"
73
+ table_name = "BASE"
74
+ end
75
+ rows = []
76
+
77
+ while resultset.next
78
+ row = {}
79
+ (1..meta.column_count).each do |i|
80
+ name = meta.column_name i
81
+ row[name] = case meta.column_type(i)
82
+ when -6, -5, 5, 4
83
+ # TINYINT, BIGINT, INTEGER
84
+ resultset.getLong(i).to_i
85
+ when 41
86
+ # Date
87
+ resultset.getDate(i)
88
+ when 92
89
+ # Time
90
+ resultset.getTime(i).to_i
91
+ when 93
92
+ # Timestamp
93
+ resultset.getTimestamp(i)
94
+ when 2, 3, 6
95
+ # NUMERIC, DECIMAL, FLOAT
96
+ case meta.scale(i)
97
+ when 0
98
+ resultset.getLong(i).to_i
99
+ else
100
+ BigDecimal.new(resultset.getString(i).to_s)
101
+ end
102
+ when 1, -15, -9, 12
103
+ # CHAR, NCHAR, NVARCHAR, VARCHAR
104
+ resultset.getString(i).to_s
105
+ else
106
+ resultset.getString(i).to_s
107
+ end
108
+ end
109
+
110
+ begin
111
+ rows << table_name.downcase.camelize.constantize.new(row)
112
+ rescue NameError
113
+ raise "[Error] Missing #{table_name.downcase.camelize} Model, pls define it\n"
114
+ end
115
+ end
116
+ rows
117
+ end
118
+
119
+ end
120
+ end
@@ -0,0 +1,5 @@
1
+ module Ruby
2
+ module Phoenix
3
+ VERSION = "0.0.8"
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ require "rake"
2
+
3
+ namespace :phoenix do
4
+
5
+ desc "Install ruby-phoenix jar package"
6
+ task :install do
7
+ $stdout.print "pls input password to copy jar to /Library/Java/Extensions/\n"
8
+
9
+ path = File.expand_path("../../../resources/",__FILE__)
10
+ system("sudo cp #{path}/* /Library/Java/Extensions/")
11
+
12
+ if !File.exists? "#{Rails.root}/config/phoenix.yml"
13
+ file = File.open("#{Rails.root}/config/phoenix.yml", "w")
14
+ file.write("host: your hbase host\nport: your hbase port\n")
15
+ file.close
16
+ end
17
+
18
+ end
19
+
20
+ end
Binary file
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'phoenix/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby-phoenix"
8
+ spec.version = Ruby::Phoenix::VERSION
9
+ spec.authors = ["wxianfeng"]
10
+ spec.email = ["wang.fl1429@gmail.com"]
11
+ spec.summary = %q{Ruby Client SDK For Apache Phoenix.}
12
+ spec.description = %q{Ruby Client SDK For Apache Phoenix.}
13
+ spec.homepage = "https://github.com/wxianfeng/ruby-phoenix"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rake", "~> 10.4"
22
+ spec.add_dependency "rjb", "~> 1.4"
23
+ spec.add_dependency "activesupport", "~> 4.2"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.7"
26
+ spec.add_development_dependency "rspec", "~> 3.1"
27
+ spec.add_development_dependency "pry", "~> 0.10"
28
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+
3
+ class StYunosAppCenterCnt < Phoenix::Base
4
+ end
5
+
6
+ describe Phoenix do
7
+ context "Rjb" do
8
+
9
+ context "execute sql" do
10
+ let(:sql) {
11
+ "select * from ST_YUNOS_APP_CENTER_CNT limit 2"
12
+ }
13
+
14
+ it {
15
+ rs = Phoenix::Rjb.execute(sql)
16
+ expect(rs.size).to eq(2)
17
+ }
18
+ end
19
+
20
+ context "all" do
21
+ it {
22
+ expect(StYunosAppCenterCnt.all.size).to_not eq(0)
23
+ }
24
+ end
25
+
26
+ context "first" do
27
+ it {
28
+ expect(StYunosAppCenterCnt.first).to_not be_nil
29
+ }
30
+ end
31
+
32
+ context "get one field value" do
33
+ it {
34
+ o = StYunosAppCenterCnt.first
35
+ expect(o.CLIENT_VERSION).to_not be_empty
36
+ }
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ require "phoenix"
2
+
3
+ require "pry"
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-phoenix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
+ platform: ruby
6
+ authors:
7
+ - wxianfeng
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rjb
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ description: Ruby Client SDK For Apache Phoenix.
98
+ email:
99
+ - wang.fl1429@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - Gemfile.lock
107
+ - LICENSE
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - lib/phoenix.rb
112
+ - lib/phoenix/Connect.java
113
+ - lib/phoenix/base.rb
114
+ - lib/phoenix/common.rb
115
+ - lib/phoenix/relation.rb
116
+ - lib/phoenix/rjb.rb
117
+ - lib/phoenix/version.rb
118
+ - lib/tasks/phoenix.rake
119
+ - resources/phoenix-4.0.0-incubating-client.jar
120
+ - resources/ruby-phoenix.jar
121
+ - ruby-phoenix.gemspec
122
+ - spec/phoenix_spec.rb
123
+ - spec/spec_helper.rb
124
+ homepage: https://github.com/wxianfeng/ruby-phoenix
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.2.2
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Ruby Client SDK For Apache Phoenix.
148
+ test_files:
149
+ - spec/phoenix_spec.rb
150
+ - spec/spec_helper.rb