Jruby "RuntimeHelpers" class is deprecated - java

I am having a project based on JRuby on rails, now I am migrating this project to jruby-9.0.5.0 version.
In the code, ruby is called from Java file as shown below:
String source = new StringBuilder("require 'java'\n" +
"\n" +
"java_package 'jrubysource'\n" +
"class SystemFilePath\n" +
" attr_accessor :topDirCmd, :topDirNames\n" +
" java_signature 'SystemFilePath(String topDirCmd)'\n" +
" def initialize(topDirCmd)\n" +
" #topDirCmd = topDirCmd\n" +
" setTopDirectoryNames()\n" +
" end\n" +
"\n" +
" java_signature 'void setTopDirectoryNames()'\n" +
" def setTopDirectoryNames\n" +
" Open3.popen3(#topDirCmd) { |stdin, stdout, stderr, wait_thread|\n" +
" out = stdout.read\n" +
" err = stderr.read\n" +
" if err.size > 0 || out.size == 0\n" +
" #topDirNames = nil\n" +
" return\n" +
" end\n" +
" out = out.split(/\\n/).select{|a| a.match(/system_1/) && !a.match(/system_1\\/sim/)}.join(\"\\n\") + \"\\n\";\n" +
" topDirNames = out.split(/\\//).select{|a| a.match(/\\n$/) }.map(&:chomp)\n" +
" if topDirNames.size == 0 then\n" +
" #topDirNames = nil\n" +
" return\n" +
" end\n" +
" #topDirNames = topDirNames.sort.reverse\n" +
" }\n" +
" rescue Exception => e\n" +
" #topDirNames = nil\n" +
" end\n" +
"\n" +
"end\n" +
"").toString();
__ruby__.executeScript(source, "system_file_path.rb");
RubyClass metaclass = __ruby__.getClass("SystemFilePath");
metaclass.setRubyStaticAllocator(SystemFilePath.class);
if (metaclass == null) throw new NoClassDefFoundError("Could not load Ruby class: SystemFilePath");
__metaclass__ = metaclass;
}
public void setTopDirectoryNames() {
#SuppressWarnings("unused")
IRubyObject ruby_result = RuntimeHelpers.invoke(__ruby__.getCurrentContext(), this, "setTopDirectoryNames"); //Here i am calling ruby code from java file.
return;
}
Now, according to a JRuby API document "RuntimeHelpers" class is deprecated.
The document provides no alternative API. Please guide me towards an alternative as this is a blocker for me.

its an internal JRuby API ... you have a similar API available for every IRubyObject :
instead of
RuntimeHelpers.invoke(__ruby__.getCurrentContext(), this, "setTopDirectoryNames")
try :
this.callMethod(__ruby__.getCurrentContext(), "setTopDirectoryNames")

Related

how to remove this error (android.content.res.Resources$NotFoundException: String resource ID #0xffffffff)

I'm building an Android app that contain SQLite DB and I was having a problem with translating SQLite saved data then I find a solution which is a method to get resource id of strings, and it worked just fine, the app was working fine then suddenly this error showed I don't know why, please help
The method, I used to get resource for string:
public static int getResId(String resName, Class<?> c) {
try {
Field idField = c.getDeclaredField(resName);
return idField.getInt(idField);
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
The code in the adapter
textViewname.setText(context.getString(R.string.product_Name)+" " + repo.getName());
textViewquantity.setText(context.getString(R.string.last_added_qty)+" " + repo.getQuantity() + " " + context.getResources().getString(mdatabase.getResId(repo.getItemsType(),R.string.class)));
textViewdate.setText(context.getString(R.string.entry_date)+" " + repo.getDate()+ " /"+context.getResources().getString(mdatabase.getResId(repo.getInOrOut(),R.string.class)));
textViewTotal.setText(context.getString(R.string.total_qty)+" " + repo.getTotal() + " " + context.getResources().getString(mdatabase.getResId(repo.getItemsType(),R.string.class)));
textviewlastUpdated.setText(context.getString(R.string.last_updated_date)+" " + repo.getUpdateDate() +" /"+context.getResources().getString(mdatabase.getResId(repo.getInOrOut(),R.string.class)));
textViewid.setText(context.getString(R.string.id)+" " + repo.getId());
textViewOutputqty.setText(context.getString(R.string.last_out_qty)+" " + repo.getOutputqty() + " " + context.getResources().getString(mdatabase.getResId(repo.getItemsType(),R.string.class)));
textViewpriceofsingleitem.setText(context.getString(R.string.retail_price)+" " + repo.getPrice() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewpriceofMultipleitem.setText(context.getString(R.string.wholesale_price)+" " + repo.getPriceofmultipleInput() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewProfitSIngle.setText(context.getString(R.string.retail_profit)+" " + repo.getProfitSingle() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewProfitMultiple.setText(context.getString(R.string.wholesale_profit)+" " + repo.getProfitMultiple() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewPurchasingPrice.setText(context.getString(R.string.purchasing_price)+" " + repo.getPurchasingPricePeranItem() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewTotalPurchasingPrice.setText(context.getString(R.string.total_purchase_price)+" " + repo.getTotalPurchasingPrice() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewTotalProfitSingle.setText(context.getString(R.string.total_retail_profit)+" " + repo.getTotalProfitperSingle() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewTotalProfitMultiple.setText(context.getString(R.string.total_wholesale_profit)+" "+ repo.getTotalProfitPerMultiple() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewitemsIBox.setText(context.getString(R.string.num_unitsInBox)+" "+ repo.getItemsInBox());
textViewSinglePriceOfiteminBox.setText(context.getString(R.string.retail_price_perUnit)+ " " + repo.getSinglePriceofItemInBox()+" " +context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewMultipriceOfItemInBox.setText(context.getString(R.string.wholesale_price_perUnit)+" "+repo.getMultiplePriceofitemInBox()+" "+context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewtotalItemsInBoexs.setText(context.getString(R.string.total_units)+" "+ repo.getTotalitemsInboxes() +" "+ context.getResources().getString(R.string.Pieces));
This error happens because you are trying to get resource that does not exist. It is because you store memory address which allocate to your string resource and possible it will change next time. I do not know what is your scenario but why you store it already in your strings it will never lost. I can help you to build another logic only when you tell what are you trying to achieve.

How to create stored function from Spring using JdbcTemplate?

For administration needs, I need to create and replace stored procedures from Spring Repository. Has anyone already done this?
I tried to use following code(unfinished):
#Component
public class JdbcRepository {
#Autowired
private JdbcTemplate jdbc;
public void checkConn(){
jdbc.execute("create or replace package Z$CLIENT_INTERFACE_API as \n" +
" function CL_ORG_SEARCH_CREATE(p_request in clob) return clob;\n" +
"end Z$CLIENT_INTERFACE_API;\n" +
"/\n" +
"create or replace package body Z$CLIENT_INTERFACE_API as\n" +
" function CL_ORG_SEARCH_CREATE(p_request in clob) return clob\n" +
" is\n" +
" content_xml VARCHAR2(4000);\n" +
" p Dbms_Xmlparser.Parser;\n" +
" v_Doc Dbms_Xmldom.Domdocument;\n" +
" v_Root_Element Dbms_Xmldom.Domelement;\n" +
" v_Child_Nodes Dbms_Xmldom.Domnodelist;\n" +
" v_Child_Node Dbms_Xmldom.Domnode;\n" +
" v_Message_Id VARCHAR2(36);\n" +
" v_First_Char VARCHAR2(1);\n" +
" begin\n" +
" content_xml:= CAST(p_request as VARCHAR2);\n" +
" p := Dbms_Xmlparser.Newparser;\n" +
" dbms_xmlparser.setvalidationmode(p,False);\n" +
" dbms_xmlparser.parsebuffer(p,content_xml);\n" +
" v_Doc := dbms_xmlparser.getdocument(p);\n" +
" v_Root_Element := Dbms_Xmldom.getdocumentelement(v_Doc);\n" +
" return 'aaaaaaaaaaaaaaaaaaaaaaaaaa1';\n" +
" end;\n" +
"end Z$CLIENT_INTERFACE_API;\n" +
"/");
}
}
But whan I execute it, i take broken package in db. In same time, whan I run this from SQLDeveloper - all works perfect.
You are separating statements by both semicolon ; and slash /.
Try using only one of those, but not both. If that doesn't work either, try executing each statement separately with execute( )
This works perfect:
jdbc.execute("create or replace package Z$CLIENT_INTERFACE_API as \n" +
" function CL_ORG_SEARCH_CREATE(p_request in clob) return clob;\n" +
"end Z$CLIENT_INTERFACE_API;\n");
jdbc.execute("create or replace package body Z$CLIENT_INTERFACE_API as\n" +
" function CL_ORG_SEARCH_CREATE(p_request in clob) return clob\n" +
" is\n" +
" content_xml VARCHAR2(4000);\n" +
" p Dbms_Xmlparser.Parser;\n" +
" v_Doc Dbms_Xmldom.Domdocument;\n" +
" v_Root_Element Dbms_Xmldom.Domelement;\n" +
" v_Child_Nodes Dbms_Xmldom.Domnodelist;\n" +
" v_Child_Node Dbms_Xmldom.Domnode;\n" +
" v_Message_Id VARCHAR2(36);\n" +
" v_First_Char VARCHAR2(1);\n" +
" begin\n" +
" content_xml:= CAST(p_request as VARCHAR2);\n" +
" p := Dbms_Xmlparser.Newparser;\n" +
" dbms_xmlparser.setvalidationmode(p,False);\n" +
" dbms_xmlparser.parsebuffer(p,content_xml);\n" +
" v_Doc := dbms_xmlparser.getdocument(p);\n" +
" v_Root_Element := Dbms_Xmldom.getdocumentelement(v_Doc);\n" +
" return 'aaaaaaaaaaaaaaaaaaaaaaaaaa1';\n" +
" end;\n" +
"end Z$CLIENT_INTERFACE_API;");

Sqlite update operations can I add value existing value?

"UPDATE " + DatabaseFıelds.TABLE_NAME +
" SET " + DatabaseFıelds.SUBJECT_PROGRESS + " = " +
point + " WHERE " + DatabaseFıelds.SUBJECT_ID + " = " + id;
this query updates my value, but I want it to add to existing value. How can I fix this problem ?
I guess you want to add the value of point to the existing value of DatabaseFıelds.SUBJECT_PROGRESS, right? You can do it like this:
"UPDATE " + DatabaseFıelds.TABLE_NAME +
" SET " + DatabaseFıelds.SUBJECT_PROGRESS + " = " +
DatabaseFıelds.SUBJECT_PROGRESS + " + " + point +
" WHERE " + DatabaseFıelds.SUBJECT_ID + " = " + id;
it's works Thank you forpas"UPDATE " + DatabaseFıelds.TABLE_NAME +
" SET " + DatabaseFıelds.SUBJECT_PROGRESS + " = " +
DatabaseFıelds.SUBJECT_PROGRESS + " + " + point +
" WHERE " + DatabaseFıelds.SUBJECT_ID + " = " + id;

Losing focus on SwingX JCOMBO BOX

I want to achieve AutoSuggest ComboBox 2 problems I am facing
1st getting an array of id and name both want the name only.
Array i am receiving
2nd losing focus on typing the text.
Please help
database Query
public SentenceList getAutoProductList() {
return new StaticSentence(s, "SELECT "
+ "P.ID, "
+ "P.REFERENCE, "
+ "P.CODE, "
+ "P.CODETYPE, "
+ "P.NAME, "
+ "P.PRICEBUY, "
+ "P.PRICESELL, "
+ "P.CATEGORY, "
+ "P.TAXCAT, "
+ "P.ATTRIBUTESET_ID, "
+ "P.STOCKCOST, "
+ "P.STOCKVOLUME, "
+ "P.IMAGE, "
+ "P.ISCOM, "
+ "P.ISSCALE, "
+ "P.ISKITCHEN, "
+ "P.PRINTKB, "
+ "P.SENDSTATUS, "
+ "P.ISSERVICE, "
+ "P.ATTRIBUTES, "
+ "P.DISPLAY, "
+ "P.ISVPRICE, "
+ "P.ISVERPATRIB, "
+ "P.TEXTTIP, "
+ "P.WARRANTY, "
+ "P.STOCKUNITS "
+ "FROM PRODUCTS P "
+ "ORDER BY NAME", null, ProductInfoExt.getSerializerRead());
}
Auto Complete JcomboBox Code
SentenceList sentProductNames = dlSales.getAutoProductList();
m_JComboProductName.setEditable(true);
ComboBoxValModel m_jProductNameModel = new ComboBoxValModel();
editor = (JTextComponent) m_JComboProductName.getEditor().getEditorComponent();
List productList = null;
try {
productList = sentProductNames.list();
} catch (Exception e) {
}
productList.add(0, null);
m_jProductNameModel = new ComboBoxValModel(productList);
m_JComboProductName.setModel(m_jProductNameModel);
AutoCompleteDecorator.decorate(m_JComboProductName);
System.out.println("product List "+ productList);
if(m_JComboProductName.getItemCount()>0){
m_JComboProductName.setSelectedIndex(0);
}

sqLite error when using update statement

I am busy using a SQLite database with a java application and after updating the database successfully I get the following error
org.sqlite.jdbc4.JDBC4PreparedStatement#4e1c6f
Below is my update code
PreparedStatement update = con.prepareStatement("UPDATE highLeaker SET " + cyc + " = "
+ dataArray[3] + " , "
+ "gasSurveyOperator" + " = "
+ dataArray[1] + " , "
+ "gasSurveySerial" + " = "
+ dataArray[2] + " , "
+ "loss" + " = "
+ dataArray[4] + " , "
+ "comment" + " = "
+ dataArray[5] + " , "
+ "cycle" + " = '"
+ cycleT + "' , "
+ "date" + " = "
+ dataArray[6]
+ " WHERE leakerID = " + dataArray[0]+";");
System.out.println(update);
update.executeUpdate();
dataRow = CSVFile.readLine(); // Read next line of data.
You printed out the object. Also, I would highly recommend using place holders instead when executing SQL queries.

Categories