java.net.URL r = this.getClass().getClassLoader().getResource("web.xml"); returns null - jboss5.x

java.net.URL r = this.getClass().getClassLoader().getResource("web.xml");
String filePath = r.getFile();
log.info("filePath :"+filePath);
System.out.println("filePath :"+filePath);
String result = new File(new File(new File(filePath).getParent()).getParent()).getParent();
System.out.println("result :"+result);
When running on JBoss5 it has a value containing a path of application, but when I am running it on JBoss6 it has a null value

Related

How to check Azure blob storage path exists or not using scala spark or python spark

Please let me know how to check below blob file exists or not.
file path name : "wasbs://containername#storageaccountname.blob.core.windows.net/directoryname/meta_loaddate=20190512/"
Below is a code that would work for you, feel to free to edit/customize per your needs:
from azure.storage.blob import BlockBlobService
session = SparkSession.builder.getOrCreate() #setup spark session
session.conf.set("fs.azure.account.key.storage-account-name.blob.core.windows.net","<storage-account-key>")
sdf = session.read.parquet("wasbs://<container-name>#<storage-account-name>.blob.core.windows.net/<prefix>")
block_blob_service = BlockBlobService(account_name='', account_key='')
def blob_exists():
container_name = ""
blob_name = ""
exists=(block_blob_service.exists(container_name, blob_name))
return exists
blobstat = blob_exists()
print(blobstat)# will return a boolean if the blob exists = True, else False
private val storageConnectionString = s"DefaultEndpointsProtocol=http;AccountName=$account;AccountKey=$accessKey"
private val cloudStorageAccount = CloudStorageAccount.parse(storageConnectionString)
private val serviceClient = cloudStorageAccount.createCloudBlobClient
private val container = serviceClient.getContainerReference("data")
val ref = container.getBlockBlobReference(path)
val existOrNot = ref.exist()

Cannot convert instance of a document class to instance of its subclass - Mongoengine

I am using Flask + mongoengine to create a web application. Here is a part of my models
class Order(Document):
placed_on=DateTimeField(required=True)
order_id = SequenceField()
status = StringField(default="Request Received")
cart = ListField(DictField())
userMobile = StringField(required=True)
userEmail = StringField(required=True)
address = ReferenceField(Address)
sheet_id = IntField(default=0)
remarks = StringField(default="")
meta = {'allow_inheritance': True}
class ConfirmedOrder(Order):
delivery_slot_start = DateTimeField()
delivery_slot_end = DateTimeField()
meta = {'allow_inheritance': True}
I have an instance of class Order as order. I now want to convert it to a ConfirmedOrder.This is the code I am using for the conversion
try:
order = Order.objects.get(id=order_id)
cOrder = ConfirmedOrder(**order.to_mongo())
cOrder.delivery_slot_start = timest
cOrder.delivery_slot_end = timend
cOrder.save();
except Exception as e:
print e
I However, get this error:
The field '_id' does not exist on the document 'Order.ConfirmedOrder'

Connection String Error in OleDB

I am trying to Import Excel file through asp.net code. but I am getting ArgumentException when I am trying to create OleDbConnection
An OLE DB Provider was not specified in the ConnectionString. An
example would be, 'Provider=SQLOLEDB;'.
Here is the code
if (FileUpload1.HasFile)
{
string path = string.Concat((Server.MapPath("~/temp/"+FileUpload1.FileName)));
FileUpload1.PostedFile.SaveAs(path);
OleDbConnection oleCon = new OleDbConnection("Povider=Microsoft.Ace.OLEDB.12.0;Data Source="+path+";Extended Properties = Excel 12.0;");
OleDbCommand cmd = new OleDbCommand("select * from [Sheet1$]",oleCon);
OleDbDataAdapter dtap = new OleDbDataAdapter(cmd);
oleCon.Open();
DbDataReader rdr = cmd.ExecuteReader();
string con_str = #"Data source = .;Initial Catalog=practiceDB;Integrated security=True";
SqlBulkCopy bulkInsert = new SqlBulkCopy(con_str);
bulkInsert.DestinationTableName="Excel";
bulkInsert.WriteToServer(rdr);
oleCon.Close();
Array.ForEach(Directory.GetFiles((Server.MapPath("~/temp/"))),File.Delete);
Response.Write("<script>alert('Inserted')</script>");

Custom procedure fails to collect properties of a class parameter; why?

OK, first of all, I'm a rookie with Caché, so the code will probably be poor, but...
I need to be able to query the Caché database in Java in order to rebuild source files out of the Studio.
I can dump methods etc without trouble, however there is one thing which escapes me... For some reason, I cannot dump the properties of parameter EXTENTQUERYSPEC from class Samples.Person (namespace: SAMPLES).
The class reads like this in Studio:
Class Sample.Person Extends (%Persistent, %Populate, %XML.Adaptor)
{
Parameter EXTENTQUERYSPEC = "Name,SSN,Home.City,Home.State";
// etc etc
}
Here is the code of the procedure:
CREATE PROCEDURE CacheQc.getParamDesc(
IN className VARCHAR(50),
IN methodName VARCHAR(50),
OUT description VARCHAR(8192),
OUT type VARCHAR(50),
OUT defaultValue VARCHAR(1024)
) RETURNS NUMBER LANGUAGE COS {
set ref = className _ "||" _ methodName
set row = ##class(%Dictionary.ParameterDefinition).%OpenId(ref)
if (row = "") {
quit 1
}
set description = row.Description
set type = row.Type
set defaultValue = row.Default
quit 0
}
And the Java code:
private void getParamDetail(final String className, final String paramName)
throws SQLException
{
final String call
= "{ ? = call CacheQc.getParamDesc(?, ?, ?, ?, ?) }";
try (
final CallableStatement statement = connection.prepareCall(call);
) {
statement.registerOutParameter(1, Types.INTEGER);
statement.setString(2, className);
statement.setString(3, paramName);
statement.registerOutParameter(4, Types.VARCHAR);
statement.registerOutParameter(5, Types.VARCHAR);
statement.registerOutParameter(6, Types.VARCHAR);
statement.executeUpdate();
final int ret = statement.getInt(1);
// HERE
if (ret != 0)
throw new SQLException("failed to read parameter");
System.out.println(" description: " + statement.getString(4));
System.out.println(" type : " + statement.getString(5));
System.out.println(" default : " + statement.getString(6));
}
}
Now, for the aforementioned class/parameter pair the condition marked // HERE is always triggered and therefore the exception thrown... If I comment the whole line then I see that all three of OUT parameters are null, even defaultValue!
I'd have expected the latter to have the value mentioned in Studio...
So, why does this happen? Is my procedure broken somewhat?
In first you should check that you send right value for className and paramName, full name and in right case and. Why you choose storage procedures, when you can use select? And you can call your procedure in System Management Portal to see about probable errors.
select description, type,_Default "Default" from %Dictionary.ParameterDefinition where id='Sample.Person||EXTENTQUERYSPEC'
Your example, works well for me.
package javaapplication3;
import com.intersys.jdbc.CacheDataSource;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
public class JavaApplication3 {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws SQLException {
CacheDataSource ds = new CacheDataSource();
ds.setURL("jdbc:Cache://127.0.0.1:56775/Samples");
ds.setUser("_system");
ds.setPassword("SYS");
Connection dbconnection = ds.getConnection();
String call = "{ ? = call CacheQc.getParamDesc(?, ?, ?, ?, ?)}";
CallableStatement statement = dbconnection.prepareCall(call);
statement.registerOutParameter(1, Types.INTEGER);
statement.setString(2, "Sample.Person");
statement.setString(3, "EXTENTQUERYSPEC");
statement.registerOutParameter(4, Types.VARCHAR);
statement.registerOutParameter(5, Types.VARCHAR);
statement.registerOutParameter(6, Types.VARCHAR);
statement.executeUpdate();
int ret = statement.getInt(1);
System.out.println("ret = " + ret);
System.out.println(" description: " + statement.getString(4));
System.out.println(" type : " + statement.getString(5));
System.out.println(" default : " + statement.getString(6));
}
}
end result
ret = 0
description: null
type : null
default : Name,SSN,Home.City,Home.State
UPD:
try to change code of your procedure and add some debug like here
Class CacheQc.procgetParamDesc Extends %Library.RegisteredObject [ ClassType = "", DdlAllowed, Owner = {UnknownUser}, Not ProcedureBlock ]
{
ClassMethod getParamDesc(className As %Library.String(MAXLEN=50), methodName As %Library.String(MAXLEN=50), Output description As %Library.String(MAXLEN=8192), Output type As %Library.String(MAXLEN=50), Output defaultValue As %Library.String(MAXLEN=1024)) As %Library.Numeric(SCALE=0) [ SqlName = getParamDesc, SqlProc ]
{
set ref = className _ "||" _ methodName
set row = ##class(%Dictionary.ParameterDefinition).%OpenId(ref)
set ^debug($i(^debug))=$lb(ref,row,$system.Status.GetErrorText($g(%objlasterror)))
if (row = "") {
quit 1
}
set description = row.Description
set type = row.Type
set defaultValue = row.Default
quit 0
}
}
and after some test from java, check zw ^debug
SAMPLES>zw ^debug
^debug=4
^debug(3)=$lb("Sample.Person||EXTENTQUERYSPEC","31#%Dictionary.ParameterDefinition","ERROR #00: (no error description)")
Well, uh, I found the problem... Talk about stupid.
It happens that I had the Samples.Person class open in Studio and had made a "modification" to it; and deleted it just afterwards. Therefore the file was "as new"...
But the procedure doesn't seem to agree with this statement.
I closed the Studio where that file was, selected not to modify the "changes", reran the procedure again, and it worked...
Strangely enough, the SQL query worked even with my "fake modification". I guess it's a matter of some cache problem...

Groovy sql to byte

I have to get a document that's stored in a postgres database and put it into a byte array.
In Java this works just fine
PreparedStatement ps = conn1.prepareStatement("SELECT document FROM documents WHERE documentname = ?");
ps.setString(1, "dingbatdocument.docx");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
byte[] documentBytes = rs.getBytes(1);
}
but I have to use groovy for this code and know nothing about how to do it, so far I've tried this
def newSpelling = "dingbatdocument.docx";
def val = sql.execute("SELECT document FROM documents WHERE documentname = ?", [newSpelling]) as byte[];
and get this error:
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'true' with class 'java.lang.Boolean' to class 'byte'
at korg.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:146)
which to me says it is trying to asset that it has worked rather than giving me and actual byte array,
and this
def newSpelling = "dingbatdocument.docx";
byte[] val = sql.execute("SELECT document FROM documents WHERE documentname = ?", [newSpelling]);
and get this error:
Groovy script throws an exception of type class org.postgresql.util.PSQLException with message = This ResultSet is closed.
and finally this:
def reqdColName = "document";
def reqdDocument = "dingbatdocument.docx";
def query1 = "SELECT $reqdColName FROM documents WHERE documentname = '$reqdDocument'";
def documentBytes = conn1.executeQuery(query1).getArray(reqdColName);
which also gives me
Groovy script throws an exception of type class org.postgresql.util.PSQLException with message = This ResultSet is closed.
So my question is how do I get the same result in groovy as I do in java, a byte[] variable from my sql resultset?
Thanks in advance.
In the end it was quite easy, but not knowing Groovy it's different. Here is how I did it in the end,
def reqdColName = "document";
def reqdDocument = "documentName.docx";
def query1 = "SELECT * FROM documents WHERE documentname = '$reqdDocument'";
byte[] myData;
conn1.eachRow(query1){
row ->
if(debug){logger.severe(dI+thisTrace+"myData \n"
+"\t"+row.documentid+"\n"
+"\t"+row.documentname
+"\t"+row.versionmajor +"\n"
+"\t"+row.versionminor +"\n"
+"\t"+row.versionmini +"\n"
+"\t"+row.uploader +"\n"
+"\t"+row.approver +"\n"
+"\t"+row.uploaddate +"\n"
+"\t"+row.approvaldate +"\n"
// +"\t"+row.document+"\n"
);}
myData = row.document
}
myData is the byte[] repesentation of the document I needed.