A client is trying to integrate some Broker Query code in to an existing web application. They have the following code:
public String doItNow(int keyA,
String schemaA,
String templateIdA) throws Exception {
loggerInfo("doItNow.start" +
", key:" + keyA +
", schema:" + schemaA +
", templateId:" + templateIdA);
StringBuffer sb = new StringBuffer();
PublicationCriteria pubCriteria = new PublicationCriteria(keyA);
loggerInfo("doItNow.PC:" + pubCriteria);
SchemaTitleCriteria schemaTitleCriteria = new SchemaTitleCriteria(schemaA);
loggerInfo("doItNow.STC:" + schemaTitleCriteria);
AndCriteria andCriteria = new AndCriteria(pubCriteria, schemaTitleCriteria);
loggerInfo("doItNow.AC:" + andCriteria);
Query query = new Query();
loggerInfo("doItNow.Query.0:" + query);
query.setCriteria(andCriteria);
loggerInfo("doItNow.Query.1:" + query);
String[] results = query.executeQuery();
for (String r : results) {
loggerInfo("doItNow.\tres:" + r);
}
ComponentPresentationAssembler cpa = new ComponentPresentationAssembler(keyA);
loggerInfo("doItNow.CPA:" + cpa);
for (String item : results) {
loggerInfo(":>" + item);
sb.append(cpa.getContent(item, templateIdA));
}
return sb.toString();
}
The code exectues as far as creating the Query object:
Query query = new Query();
At this point it hangs. No errors appear in the cd_core log file to suggest a reason for this. Can anyone suggest areas where can investigate to debug this further, or suggest a solution?
There was known issue with JRE version 1.6.0.29 and MSSQL jdbc driver. You need to either downgrade or upgrade to a different JRE version.
https://forums.oracle.com/forums/thread.jspa?threadID=2301826
The issue seems very similar to the issue reported with the driver and you do not see any error messages either.
Try changing the following line:
query.setCriteria(andCriteria);
to:
query.Criteria = andCriteria;
The SDL LiveContent example has a comment suggesting this change.
http://sdllivecontent.sdl.com/LiveContent/content/en-US/SDL_Tridion_2011_SPONE/concept_0AB6D192D7AB4EC18892631F519EF1DD
Have you added the correct includes? (Tridion.ContentDelivery.DynamicContent.Query Namespace)
Also as suggested by Chris, query in tridion 2011 does not have a property as setCriteria.
Use query.Criteria instead.
Also have you implemented the necessary changed in cd_storage_conf.xml?
Related
Good day to everyone,
I'm building an application in Xamarin.Forms Portable for iOS,Android,Windows Universal(10) .
I'm trying to use the Mono.Data.Sqlite.Portable, but I'm not able to create or connect to a local database, I've tried many solutions to fix the problem, but until now I dint find the solution..
The error is trow at "connection.open();"
The Code is :
var config = DependencyService.Get<DB.IConfig>();
var cnn = config.DirectoryDB;
using (var connection = new SqliteConnection("" +
new SqliteConnectionStringBuilder
{
DataSource = "URI=file::memory:",
Version=3,
}))
{
//connection.ChangeDatabase("hello.db");
connection.Open();
using (var transaction = connection.BeginTransaction())
{
var insertCommand = connection.CreateCommand();
insertCommand.Transaction = transaction;
insertCommand.CommandText = "CREATE TABLE TESTE(teste as varchar(10))";
insertCommand.ExecuteNonQuery();
transaction.Commit();
}
}
on the "DataSource" I've a local path, and other paths.
(Ex:. C:\Users\MyMachineName\AppData\Local\Packages\f736c883-f105-4d30-a719-4bf328872f5e_nh7s0b45jarrj\LocalState\hello.db)
The error is :
An exception of type 'System.NotImplementedException' occurred in Mono.Data.Sqlite.dll but was not handled in user code
Additional information: The method or operation is not implemented.
ImageError
Connection Extra Information
The last picture, it may give more information....
Thank you all in advance :)
I've found the solution,I hope it helps the people that may be looking for the same as I.
Just go to Nuget - And download the Portable.Data.Sqlite that relies on SQLitePCL (Latest version) .
This package (Portable.Data.Sqlite) it will use the connection and will create SqliteDataReader and other property's that we are used to use .
This will work on Visual Studio 2015 and the project must be in framework 4.51 +=
----Error Tips----
if you encounter this error : Cant use Temporary Database or Path, just download Sqlite.dll and place on the project BIN folder and System32/ SysWoW64 .
I've been building this project as the solo dev for a while, and while I'm comfortable in the front end and middle tier, I don't really think I'm doing the database the way I should be, and the reason why is because I simply don't really know of any other way. The way I'm currently getting data is by testing out queries in my MySQL workbench and copying and pasting the SQL as a string literal into a method that makes a call to the DB, pulls the data and hydrates my objects.
This hasn't really been a problem until recently, when I had to create a monster of a query and it got me thinking that maybe there's a better way to do this. I don't have a formal DAL separated out, so I know there's room for improvement there, but I was curious about what the correct way would be to store SQL strings. I assume there is a tool somewhere built into VS10 where I can manipulate and work with SQL as SQL instead of as a string.
You should be doing this in stored procedures. That will basically format and store your query. You set parameters that are passed in from your code, then read out the results.
Example:
The C# method:
private void SetNote()
{
const string sql = "sp_SelectControllerNoteByID";
using (var conn = MocSystem.GetMocDbConnection())
{
using (var comm = new SqlCommand(sql, conn))
{
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add(new SqlParameter("#ControllerNoteID", ControllerNoteId));
try
{
conn.Open();
using (var rdr = comm.ExecuteReader())
{
while (rdr.Read())
{
CommentText = rdr["NoteText"].ToString();
_commentor = new User(new Guid(rdr["NoteAuthor"].ToString()));
CommentDate = (DateTime)rdr["NoteDate"];
MocRequestId = (int)rdr["MocRequestID"];
}
}
}
catch (Exception ex)
{
HasError = true;
ErrorMessage += "\nThere was a problem building the note: " + ex.Message;
}
}
}
}
The stored procedure on the DBMS (sql server in this example):
ALTER proc [dbo].[sp_SelectControllerNoteByID]
#ControllerNoteID int
AS
SELECT
ControllerNoteID,
NoteText,
NoteDate,
NoteAuthor,
MocRequestID
FROM
ControllerNotes
WHERE
ControllerNoteID = #ControllerNoteID
So here we call the stored procedure which in this case is just a simple select statement, then we read it out into an object via ADO. Now, this way, you can modify your query without recompiling. Unless you add parameters, in which case you'll have to update those in your code as well.
Using Tridion 2009, SP1, hence the old COM+ TOM API. I'm trying to get information of a PublishTransaction but getting an error each time I call the PublishTransaction.Information property.
Here is my code:
try
{
var pubTrans = (PublishTransaction)tdse.GetObject("tcm:0-166535-66560",
EnumOpenMode.OpenModeView);
Console.WriteLine("transaction id=" + pubTrans.ID);
Console.WriteLine("transaction itemtype=" + pubTrans.itemType.ToString());
Console.WriteLine("transaction info=" + pubTrans.Information);
}
catch (Exception e)
{
Console.WriteLine(e.Message, e.StackTrace);
}
Above, the transaction ID and Item Type print fine. I have other code where the Delete method works fine, but any time I try and get the Information, it blows up.
Here is the error:
<tcm:Error xmlns:tcm="http://www.tridion.com/ContentManager/5.0" ErrorCode="D"
Category="18" Source="Kernel" Severity="1">
<tcm:Line Cause="false" MessageID="16138">
<![CDATA[Unable to get Information of Unknown (tcm:0-166535-66560).]]>
<tcm:Token>RESID_4485</tcm:Token><tcm:Token>Information</tcm:Token>
<tcm:Token>RESID_4663</tcm:Token><tcm:Token>tcm:0-166535-66560</tcm:Token>
</tcm:Line>
<tcm:Line ErrorCode="D" Cause="true"><![CDATA[Type mismatch]]></tcm:Line>
<tcm:Details>
<tcm:CallStack>
<tcm:Location>PublishTransaction.Information</tcm:Location>
<tcm:Location>PublishTransaction.Information</tcm:Location>
</tcm:CallStack>
</tcm:Details>
</tcm:Error>
I've searched the SDL Tridion World forum and couldn't find the answer. Am I missing a hotfix, should I contact Support, or is there another way to get the transaction info?
I am not really sure (without digging further at this time of night), but is the 'Information' property actually an XMLElement rather than a string as the docs say? When you use a debugger, are you able to place a watch on this property to see what it contains?
I tried this in another way to get the PublishTransaction Information. Below is the code:-
PublishTransaction pubTrans = (PublishTransaction)tdse.GetObject(
"tcm:0-4294103-66560",
EnumOpenMode.OpenModeView,
null,
XMLReadFilter.XMLReadNull);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(pubTrans.GetXML(XMLReadFilter.XMLReadAll));
XmlNamespaceManager nameSpace = new XmlNamespaceManager(xmlDoc.NameTable);
nameSpace.AddNamespace("tcm", "http://www.tridion.com/ContentManager/5.0");
nameSpace.AddNamespace("xlink", "http://www.w3.org/1999/xlink");
Console.WriteLine("transaction id=" + pubTrans.ID);
Console.WriteLine("transaction itemtype=" + pubTrans.itemType.ToString());
EnumPublishTransactionState transState = pubTrans.get_State();
if (transState == EnumPublishTransactionState.Failed)
Console.WriteLine("transaction info=" +
xmlDoc.SelectSingleNode("/tcm:PublishTransaction/tcm:Data/tcm:Information",
nameSpace).InnerText);
I don't have a working environment, so I am just looking into whatever existing code I have available. This is snippet from the Event system which deletes a Queue item only when you have Admin privileges:
public void OnPublicationPublishPost(Publication publication, IXMLDOMDocument2 publishResult)
{
TDSE tdse = Utilities.GetTDSEInstance();
publishResult.setProperty("SelectionNamespaces", "xmlns:tcm=\"http://www.tridion.com/ContentManager/5.0\"");
PublishTransaction publishTransaction = Utilities.GetTridionItem<PublishTransaction>(publishResult.selectSingleNode("/*/*").attributes[2].text, null) as PublishTransaction;
User user = Utilities.GetTridionItem<User>(publishResult.selectSingleNode("/tcm:PublishResponse/tcm:PublisherRequest/tcm:User").attributes[0].text, null) as User;
TDSPrivileges isAdmin = user.privileges;
if (isAdmin != TDSPrivileges.TdsPrivilegeSystemAdministrator)
{
publishTransaction.Delete();
}
}
I am using DataNucleus with HBase. I had a table user. It contained 4 rows. Now I added a new column to the table. Now everytime I access any old user object which does not have this column DataNucleus throws an exception as it is trying to map the column with the property in the POJO. Is there no other way than updating the old 'user' objects with dummy data? My object mapping looks something like this:
#Persistent(columns={#Column(name="next_mail_timestamp", insertValue="#NULL", defaultValue = "#NULL", allowsNull = "true")}, name="nextMailTimestamp", cacheable="false", nullValue=NullValue.DEFAULT)
private long nextMailTimestamp;
As you can see I have tried using insertValue, defaultValue , allowsNull, nullValue. But nothing seems to work.
The stacktrace looks like this:
at org.apache.hadoop.hbase.util.Bytes.toLong(Bytes.java:479)
at org.apache.hadoop.hbase.util.Bytes.toLong(Bytes.java:453)
at org.datanucleus.store.hbase.fieldmanager.FetchFieldManager.fetchLongField(FetchFieldManager.java:269)
at org.datanucleus.state.AbstractStateManager.replacingLongField(AbstractStateManager.java:2133)
at com.kuliza.sitepulse.data.User.jdoReplaceField(User.java)
at com.kuliza.sitepulse.data.User.jdoReplaceFields(User.java)
at org.datanucleus.state.JDOStateManagerImpl.replaceFields(JDOStateManagerImpl.java:1989)
at org.datanucleus.state.JDOStateManagerImpl.replaceFields(JDOStateManagerImpl.java:2009)
at org.datanucleus.store.hbase.query.HBaseQueryUtils$2.fetchFields(HBaseQueryUtils.java:226)
at org.datanucleus.state.JDOStateManagerImpl.loadFieldValues(JDOStateManagerImpl.java:803)
at org.datanucleus.state.JDOStateManagerImpl.initialiseForHollow(JDOStateManagerImpl.java:210)
at org.datanucleus.state.ObjectProviderFactory.newForHollowPopulated(ObjectProviderFactory.java:88)
at org.datanucleus.ObjectManagerImpl.findObject(ObjectManagerImpl.java:2794)
at org.datanucleus.store.hbase.query.HBaseQueryUtils.getObjectUsingApplicationIdForResult(HBaseQueryUtils.java:221)
at org.datanucleus.store.hbase.query.HBaseQueryUtils.getObjectsOfType(HBaseQueryUtils.java:168)
at org.datanucleus.store.hbase.query.HBaseQueryUtils.getObjectsOfCandidateType(HBaseQueryUtils.java:80)
at org.datanucleus.store.hbase.query.JDOQLQuery.performExecute(JDOQLQuery.java:271)
at org.datanucleus.store.query.Query.executeQuery(Query.java:1766)
at org.datanucleus.store.query.Query.executeWithArray(Query.java:1655)
at org.datanucleus.store.query.Query.execute(Query.java:1628)
at org.datanucleus.api.jdo.JDOQuery.execute(JDOQuery.java:221)
at com.kuliza.sitepulse.service.DataService.getUserWithCredentials(DataService.java:111)
at com.kuliza.sitepulse.service.AuthenticationService.getUserWithCredentials(AuthenticationService.java:46)
at com.kuliza.sitepulse.controller.AuthenticationController.signIn(AuthenticationController.java:69)
and my method is (in DataService.java:111)(which throws the exception)
#Override
public User getUserWithCredentials(String userName, String password){
PersistenceManager pm = pmf.getPersistenceManager();
Query q = pm.newQuery("SELECT FROM " + User.class.getName() + " WHERE userName == \""+userName+"\"" +" && password == " +
" \""+password + "\"");
List<User> c = (List<User>)q.execute();
pm.close();
if(c.size() > 0)
return c.get(0);
else
return null;
}
I have actually added two new columns (mailIntervalInMilliseconds, nextMailTimestamp) which are both long and in the stacktrace I see its trying to convert the db column to Long (AFAIK)
Released versions of DataNucleus HBase plugin don't currently support all modes of schema evolution. In particular the addition of fields/properties when they are of primitive types. However DataNucleus SVN does have support for this, so you could use that.
I am using SQLite for Windows Phone 7 (http://sqlitewindowsphone.codeplex.com/) and I have done every steps from this tutorial (http://dotnetslackers.com/articles/silverlight/Windows-Phone-7-Native-Database-Programming-via-Sqlite-Client-for-Windows-Phone.aspx)
Then I try to make some simple application with basic features like select and delete. App is working properly till I want to make one of this operations. After I click select or delete, compiler shows me errors that he is unable to open database file...
I have no idea why?
I used the same Sqlite client, and had the same problem. This problem occurs because the sqlite try to create file in IsolatedFileStorage "DatabaseName.sqlite-journal" and it does not have enough permissions for that. I solved the problem, so that created "DatabaseName.sqlite-journal" before copying database to IsolatedFileStorage. Here's my method that did it:
private void CopyFromContentToStorage(String assemblyName, String dbName)
{
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
string uri = dbName + "-journal";
store.CreateFile(uri);
using (Stream input = Application.GetResourceStream(new Uri("/" + assemblyName + ";component/" + dbName,UriKind.Relative)).Stream)
{
IsolatedStorageFileStream dest = new IsolatedStorageFileStream(dbName, FileMode.OpenOrCreate, FileAccess.Write, store);
input.Position = 0;
CopyStream(input, dest);
dest.Flush();
dest.Close();
dest.Dispose();
}
}
it helped me, and worked well.
hope this will help you
Are you sure the file exists?
You can check like that:
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
exists = store.FileExists(DbfileName);
}