Orient DB - Export database with Specified datatables - java

Im working with orient db where i have to export specified data tables using java. Here is the code im working with:
ODatabaseDocumentTx db = new ODatabaseDocumentTx("remote:localhost/sampleDB").open("admin", "admin");
try {
OCommandOutputListener listener = new OCommandOutputListener() {
#Override
public void onMessage(String iText) {
// System.out.print(iText);
}
};
Set<String> abcd = new HashSet<String>();
abcd.add("sample_demo1_OnlineShopping");
System.out.println(abcd);
ODatabaseExport export = new ODatabaseExport(db, "DataCont/Data.gz", listener);
export.setIncludeInfo(false);
export.setIncludeClusterDefinitions(false);
export.setIncludeSchema(false);
export.setIncludeIndexDefinitions(false);
export.setIncludeManualIndexes(false);
export.setIncludeClasses(abcd);
// export.exportRecords();
export.exportDatabase();
export.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
db.close();
}
The problem is, its not including any classes. Output file was like this:
{"records":[]}
But when i tries without the "setIncludeClasses" it prints all the classes available in the database. What would the issue for this problem. Thanks in advance.

Change this line to:
abcd.add("sample_demo1_OnlineShopping".toUpperCase());
I haven't found it in the documentation, but includeClasses is expecting classes in UpperCase (same for excludeClasses).
See the source code.

Related

JCO_ERROR_RESOURCE: Destination ABAP_AS_WITHOUT_POOL does not exist... error while connecting via JCo

I am working on a Java app that needs to get data from our SAP system laying in SAP table. I try to connect the SW with SAP using SAP Java Connector 3.X, but I'm having trouble with the Destination.
I used the Code-Examples that came with the SAP Java Connector.
public class CustomDestinationDataProvider {
static class MyDestinationDataProvider implements DestinationDataProvider {
private DestinationDataEventListener eL;
private HashMap<String, Properties> secureDBStorage = new HashMap<String, Properties>();
public Properties getDestinationProperties(String ABAP_AS) {
try {
//read the destination from DB
Properties p = secureDBStorage.get(ABAP_AS);
if(p!=null) {
//check if all is correct, for example
if(p.isEmpty())
throw new DataProviderException(DataProviderException.Reason.INVALID_CONFIGURATION, "destination configuration is incorrect", null);
return p;
}
return null;
} catch(RuntimeException re) {
throw new DataProviderException(DataProviderException.Reason.INTERNAL_ERROR, re);
}
}
//An implementation supporting events has to retain the eventListener instance provided
//by the JCo runtime. This listener instance shall be used to notify the JCo runtime
//about all changes in destination configurations.
public void setDestinationDataEventListener(DestinationDataEventListener eventListener) {
this.eL = eventListener;
}
public boolean supportsEvents() {
return true;
}
//implementation that saves the properties in a very secure way
void changeProperties(String ABAP_AS, Properties properties) {
synchronized(secureDBStorage) {
if(properties==null) {
if(secureDBStorage.remove(ABAP_AS)!=null)
eL.deleted(ABAP_AS);
} else {
secureDBStorage.put(ABAP_AS, properties);
eL.updated(ABAP_AS); // create or updated
}
}
}
} // end of MyDestinationDataProvider
//business logic
void executeCalls(String ABAP_AS) {
JCoDestination dest;
try {
dest = JCoDestinationManager.getDestination(ABAP_AS);
dest.ping();
System.out.println("Destination " + ABAP_AS + " works");
} catch(JCoException e) {
e.printStackTrace();
System.out.println("Execution on destination " + ABAP_AS + " failed");
}
}
static Properties getDestinationPropertiesFromUI() {
//adapt parameters in order to configure a valid destination
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "XXX");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "XX");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "XXX");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "XXX");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "XXX");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "XX");
createDestinationDataFile(ABAP_AS, connectProperties);
return connectProperties;
}
static void createDestinationDataFile(String ABAP_AS, Properties connectProperties) {
File destCfg = new File(ABAP_AS + ".jcoDestination");
try {
FileOutputStream fos = new FileOutputStream(destCfg, false);
connectProperties.store(fos, "for tests only!");
fos.close();
} catch (Exception e) {
throw new RuntimeException("Unable to create the destination files", e);
}
}
}
This is the Error-Message I get from NetBeans:
Destination ABAP_AS_WITHOUT_POOL works
Execution on destination ABAP_AS_WITHOUT_POOL failed
com.sap.conn.jco.JCoException: (106) JCO_ERROR_RESOURCE: Destination ABAP_AS_WITHOUT_POOL does not exist
at com.sap.conn.jco.rt.DefaultDestinationManager.update(DefaultDestinationManager.java:217)
at com.sap.conn.jco.rt.DefaultDestinationManager.searchDestination(DefaultDestinationManager.java:382)
at com.sap.conn.jco.rt.DefaultDestinationManager.getDestinationInstance(DefaultDestinationManager.java:100)
at com.sap.conn.jco.JCoDestinationManager.getDestination(JCoDestinationManager.java:104)
at jcotest2.CustomDestinationDataProvider.executeCalls(CustomDestinationDataProvider.java:92)
at jcotest2.Main.main(Main.java:39)
BUILD SUCCESSFUL (total time: 2 seconds)
It looks like your code keeps the logon data in the HashMap "secureDBStorage". Where do you fill this HashMap?
Also: what do you need the method "createDestinationDataFile()" for, if you are using a HashMap and not a file?
Edit: as this post got deleted by review, I'm trying to make it more precise now. So there are two problems with your code:
You keep the logon parameters of your backend systems in a HashMap named "secureDBStorage", but you did not fill this map with parameters for the system/destination named "ABAP_AS_WITHOUT_POOL".
Your code still contains the method "createDestinationDataFile()", which was probably copied from the sample program and then forgotten to delete. As your program is using a HashMap for storing the logon parameters and not the file system, you can delete this method. (Only confuses the program.)
Prior to calling the destination you should create it in Configuration Manager of SAP Java Application Server (NWA Manager) and then only call it.
https://help.sap.com/doc/saphelp_nwpi711/7.1.1/enUS/07/0d27932264284b883dab13ce1008a6/frameset.htm
Here is the sample:
static String ABAP_AS = "WD_MODELDATA_DEST";
PrintWriter out = response.getWriter();
JCoDestination destination;
try {
destination = JCoDestinationManager.getDestination(ABAP_AS);
out.println("Attributes:");
out.println(destination.getAttributes());
out.println();
} catch (JCoException e) {
e.printStackTrace();
out.println(e.getMessage());
}
I don't see where you fill ABAP_AS variable in your code like in the sample.

Java Properties Class

using java 8, tomcat 8
Hi, i am loading a file using properties, but i have a check before loading which returns the same properties object if its already been loaded (not null). which is a normal case scenario but i want to know if there is any way that if any change occur in target file, and some trigger should be called and refreshes all the properties objects. here is my code.
public static String loadConnectionFile(String keyname) {
String message = "";
getMessageFromConnectionFile();
if (propertiesForConnection.containsKey(keyname))
message = propertiesForConnection.getProperty(keyname);
return message;
}
public static synchronized void getMessageFromConnectionFile() {
if (propertiesForConnection == null) {
FileInputStream fileInput = null;
try {
File file = new File(Constants.GET_CONNECTION_FILE_PATH);
fileInput = new FileInputStream(file);
Reader reader = new InputStreamReader(fileInput, "UTF-8");
propertiesForConnection = new Properties();
propertiesForConnection.load(reader);
} catch (Exception e) {
Utilities.printErrorLog(Utilities.convertStackTraceToString(e), logger);
} finally {
try {
fileInput.close();
} catch (Exception e) {
Utilities.printErrorLog(Utilities.convertStackTraceToString(e), logger);
}
}
}
}
the loadConnectionFile method executes first and calls getMessageFromConnectionFile which has check implemented for "null", now if we remove that check it will definitely load updated file every time but it will slower the performance. i want an alternate way.
hope i explained my question.
thanks in advance.
Java has a file watcher service. It is an API. You can "listen" for changes in files and directories. So you can listen for changes to your properties file, or the directory in which your properties file is located. The Java Tutorials on Oracle's OTN Web site has a section on the watcher service.
Good Luck,
Avi.

Testing multiple environments with different data - best practice

I need to be able to run the same tests on different environments (max 3) but with different data for each one.
I have a test method:
#Test (groups = "core", description = "Login: Valid log in")
public void validLogin() {
User user = UserData.user_2();
loginPage.logOn(user);
}
In the UserData class I have:
public static User user_2() {
return new User().newUser("user2", "password");
}
"user2" does not exist on all environments. I may not be able to change the data that is available on all of the environments to match the test data.
The tests will be executed either using Maven and TestNg so I can send in the parameter for the execution environment.
My initial thought is to use:
public static User user_2() {
switch(env) {
case "env1": return new User().newUser("user2", "password"); break;
case "env2": return new User().newUser("user2Z", "password"); break;
case "env3": return new User().newUser("user2X", "password"); break;
}
I have a limited number of data classes and methods (<100) but several thousand tests.
What is the best way of setting up and handling the data required for testing against the different environments?
When it comes to different users ,
You always wish that all my test cases should remain as it is and with minimal change.
So this is what i follow.
I create a file lets say username.properties file in eclipse.
username=xyz#gmail.com
password=passswd1
You can create multiple users here with name i.e.
rohan=rohan#gmail.com
rohan's password: rohan
Now we need to call this file in our class.
See below example.
Main test
SignInPage.SendkeysMethodForSignInPAgeForPropertyFile(driver, By.cssSelector("input[id='Email']") , "username" );
SignInPage.SendkeysMethodForSignInPAgeForPropertyFile(driver, By.cssSelector("input[id='Passwd'][type='password']"), "password");
So here username will be taken from properties file.
This will go to SendkeysMethodForSignInPAgeForPropertyFile which is:
public class SignInPage {
public void SendkeysMethodForSignInPAgeForPropertyFile(WebDriver driver, By by, String Text) {
WebUtils.SendkeysForPropertyFile(driver,by, Text);
}
}
Which will go to SendkeysForPropertyFile method as:
public static void SendkeysForPropertyFile(WebDriver driver, By by, String Text) {
ReadFileData File = new ReadFileData();
Properties Values = File.ReadFile();
WebElement Element = driver.findElement(by);
Element.clear();
if (Text == "username"){
Element.sendKeys(Values.getProperty("username"));
}
else {
Element.sendKeys(Values.getProperty("password"));
}
Which will read from ReadFileData() class which is:
public class ReadFileData {
public Properties ReadFile() {
File file = new File("D:\\Selenium\\Gmail_Web_UI\\Loginproperty.properties");
FileInputStream fileInput = null;
try {
fileInput = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Properties prop = new Properties();
//load properties file
try {
prop.load(fileInput);
} catch (IOException e) {
e.printStackTrace();
}
return prop;
}
This helps to keep our username and password safe in a single file.
Reply to me for further query. Happy Learning :-)

java.lang.IllegalArgumentException: 'hello' does not contain an equals sign

I am currently using the Apache commons configuration library to write and read data from a file. I am able to save the key value pair colors=hello to the user..properties file, but when i try to read the value is get the below exception.
Exception in thread "main" java.lang.IllegalArgumentException: 'hello' does not contain an equals sign
at org.apache.commons.configuration.AbstractConfiguration.getProperties(AbstractConfiguration.java:625)
at org.apache.commons.configuration.AbstractConfiguration.getProperties(AbstractConfiguration.java:579)
at com.code.prep.CommonsMain.readProperties(CommonsMain.java:21)
at com.code.prep.CommonsMain.main(CommonsMain.java:12)
The code is as below
package com.code.prep;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
public class CommonsMain {
public static void main(String[] args) {
CommonsMain main = new CommonsMain();
main.readProperties();
// main.writeProperties();
}
public void readProperties(){
PropertiesConfiguration config = new PropertiesConfiguration();
try {
config.load("user.properties");
System.out.println(config.getProperties("colors"));
} catch (ConfigurationException e) {
e.printStackTrace();
}
}
public void writeProperties(){
PropertiesConfiguration config = new PropertiesConfiguration();
try {
config.load("user.properties");
config.setProperty("colors", "hello");
config.save("user.properties");
} catch (ConfigurationException e) {
e.printStackTrace();
}
}
}
The Jars in the class path are:
commons-configuration-1.9.jar
commons-lang-2.4.jar
commons-logging-1.1.1.jar
user.properties contains
colors = hello
user = thejavamonk
You should not be using
config.getProperties("colors")
but
config.getProperty("colors")
"getProperties(code)" is looking for (multiple) lines in your user.properties file of the form:
code key=val
so it's expecting your code as it stands to have lines like :
colors foreground=black
colors background=white
etc.
This does not look like library issue. Open your file and check whether the data is actually available. From you code it looks like you are doing -
main.readProperties();
// main.writeProperties();
Why would there be any data unless you write it? Call writeProperties() method first and then read it back.

Getting NullPointerException with row.setAttribute on Oracle ADF

I'm now trying to learn Oracle ADF and I'm getting a NullPointerException while running the following code on a Java bean.
Can you help me figure out what I'm doing wrong please? This is being invoked from a button on a JSPX page.
public String cb1_action() {
try{
BindingContext bindingctx = BindingContext.getCurrent();
BindingContainer bindings = bindingctx.getCurrentBindingsEntry();
DCBindingContainer bindingsImpl = (DCBindingContainer)bindings;
DCIteratorBinding iter = bindingsImpl.findIteratorBinding("ViewObj1Iterator");
Row row = iter.getCurrentRow();
row.setAttribute("Id", 123);
row.setAttribute("Nome", "Pedro Teste");
}
catch(Exception e) {
System.out.println("Excepcao em: ");
e.printStackTrace();
}
return null;
}
According to the Stack trace, the error occurs on the first row.setAttribute() line.
Also, I'm using the latest version of JDeveloper with the integrated WebLogic server.
Best regards,
Pedro
Row row = iter.getCurrentRow();
if(row != null){
row.setAttribute("Id", 123);
row.setAttribute("Nome", "Pedro Teste"); //name?
}
The info that you get the error at
row.setAttribute("Id", 123);
let me think that you try to alter the primary key attribute of the row, which is not allowed. Not sure about this as you did not mention the error you get.
Ok, so here's how I figured out how to get around this:
First, I asked jDeveloper to generate a class for the Application Module.
In that class, I added the following methods:
public void testEntityObject()
{
System.out.println("Let's try our Entity Object...");
try
{
EntityDefImpl entity = TesteEOImpl.getDefinitionObject();
TesteEOImpl ti = (TesteEOImpl)entity.createInstance2(getDBTransaction(), null);
ti.setId(new BigDecimal(123));
ti.setNome("Entity Object test...");
getDBTransaction().commit();
System.out.println("Looks good :-)");
}
catch(Exception e)
{
System.out.println("It seems something went wrong :-(");
e.printStackTrace();
}
}
public void testViewObject() {
System.out.println("Let's try our View Object...");
ViewObjectImpl vo = this.getTeste1();
try{
Row row = vo.createRow();
row.setAttribute("Id", 234);
row.setAttribute("Nome", "VO test");
vo.insertRow(row);
getDBTransaction().commit();
System.out.println("Looks good :-)")
}
catch(Exception e) {
System.out.println("It seems something went wrong :-(");
e.printStackTrace();
}
}
These methods are being called by a managed bean that is connected to two buttons on the page. This managed bean has the following methods. I'll post just one of them as only the method names change:
public String cb1_action() {
try{
FacesContext fctx = FacesContext.getCurrentInstance();
BindingContext bindingContext = BindingContext.getCurrent();
DCDataControl dc = bindingContext.findDataControl("AppModuleAMDataControl");
AppModuleAMImpl am = (AppModuleAMImpl)dc.getDataProvider();
am.criarTesteComEntityObject();
}
catch(Exception e) {
e.printStackTrace();
}
return null;
}
I know this is not rocket science or anything but it took a while for me to get there...
Basically, your answers helped me a lot to go and investigate what was happening. The cause? Poor design! ADF is supposed to be organized...
Thank you everyone! :D

Categories