I have a mybatis mapper
public interface FooMapper {
#Select("select now()")
String getTime();
}
when debug I got below info
I want to get sqlSession instance. So I tried using reflection manner to get sqlSession.
Field hField = fooMapper.getClass().getDeclaredField("h");
MapperProxy mapperProxy = (MapperProxy) hField.get(fooMapper);
Field sqlSessionField = mapperProxy.getClass().getDeclaredField("sqlSession");
SqlSession sqlSession = (SqlSession) sqlSessionField.get(mapperProxy);
but actually I got below error
java.lang.NoSuch FieldException: h
at java.lang.Class.getDeclaredField(Class.java:2070)
So how to get sqlSession instance in fooMapper by reflection manner or other manner(if reflection is impossible)?
This works:
((MapperProxy)((Proxy)fooMapper).h).sqlSession
MapperProxy from org.apache.ibatis.binding
Proxy from Java.lang.reflect
Related
i have an Insert method which takes an object with 3 fields as parameter and one of the field is SiteID which i already have in 'Querystring["ID"]'
public static void ProcessIT(string Xindex, string Yindex)
{
SiteLogic SL = new SiteLogic();
Site ste = SL.SelectByID(Convert.ToInt32(Request.QueryString["ID"]));
Walkable W = new Walkable();
W.X = Convert.ToInt32(Xindex);
W.Y = Convert.ToInt32(Yindex);
W.SiteID = ste.SiteID;
WalkableLogic wlc = new WalkableLogic();
wlc.Insert(W);
}
}
now when i try to fetch the ID by Request.QueryString["ID"] it shows this error "an object reference is required for the non-static field method or property 'System.web.UI.Page.Request.get'"
Your code being static method, instead, doesn't have access to Request property, since static methods do not have access to instance members.
Use HttpContext.Current.Request.Url instead of Request.Url to make your code more universal.
I am invoking the Tridion 2011 SP1 core service via the shipped client assembly. When I attempt to list the contents of a publication, I get an exception.
The code (simplified) looks like this:
ItemsFilterData filter = new Tridion.ContentManager.CoreService
.Client.RepositoryItemsFilterData.RepositoryItemsFilterData();
filter.ItemTypes = new ItemType[] {
ItemType.Folder,
ItemType.StructureGroup
};
filter.Recursive = false;
IEnumerable<IdentifiableObjectData> childItems = core.GetList("tcm:0-15-1", filter);
Note: the variable "core" refers to an ISessionAwareCoreService which I can successfully use to call, for example core.GetSystemWideList()
When .GetList is invoked, I get the following exception:
System.ServiceModel.FaultException`1 was unhandled
Message=Unexpected list type:
Tridion.ContentManager.Data.ContentManagement.RepositoryItemsFilterData.
What are the possible causes of this problem? Can you suggest a good general approach for interpreting this kind of message?
You can't get the direct children of a Publication using GetList. Instead you should just load the PublicationData with a client.Read and then access the RootFolder and RootStructureGroup on that.
PublicationData pub = (PublicationData)core.Read("tcm:0-1-1", new ReadOptions());
string rootFolder = pub.RootFolder.IdRef;
string rootSG = pub.RootStructureGroup.IdRef;
Alternatively you can call GetListXml with your RepositoryItemsFilterData and extract the items from the XML yourself.
XElement listResult = core.GetListXml(parent.ID, filter);
I just migrated to HRD and now its telling me i cant access my own blobs...
Uncaught exception from servlet
java.lang.SecurityException: This application does not have access to that blob.
at com.google.appengine.api.blobstore.BlobstoreServiceImpl.fetchData(BlobstoreServiceImpl.java:200)
at com.droidastic.telljokes.server.servlet.ServeBlobsServlet.checkBlobKeyExists(ServeBlobsServlet.java:100)
at com.droidastic.telljokes.server.servlet.ServeBlobsServlet.doGet(ServeBlobsServlet.java:64)
I stored the keys as a string inside the datastore entities and then i create them like this:
BlobKey key = new BlobKey(this.params.blobKey);
How can i recover the blobs?
I found a solution:
public String getMigratedBlobKey(String oldKey) {
String migrationEntityKey = "__BlobMigration__";
Key createKey = KeyFactory.createKey(migrationEntityKey, oldKey);
Entity migrationEntity = datastore.get(createKey);
BlobKey newKey = (BlobKey) migrationEntity.getProperty("new_blob_key");
return newKey.getKeyString();
}
"__BlobMigration__" and "new_blob_key" are GAE constants.
I have an ASP.NET Page that updates registered User Address Details for a selected record.
Below is the update method that I am calling from my controller.
When I am calling the ApplyPropertyChanges method, I am getting an error. Did anyone run into the same error while updating the record with Entity Framework?
Appreciate your responses.
Error message:
The existing object in the ObjectContext is in the Added state. Changes can only be applied when the existing object is in an unchanged or modified state.
My Update method:
[HttpPost]
public bool UpdateAddressDetail([Bind(Prefix = "RegUser")] AddressDetail regUserAddress, FormCollection formData)
{
regUserAddress.AD_Id = 3;
regUserAddress.LastUpdated = HttpContext.User.Identity.Name;
regUserAddress.UpdatedOn = DateTime.Now;
regUserAddress.AddressType = ((AddressDetail)Session["CurrentAddress"]).AddressType ?? "Primary";
regUserAddress.Phone = ((AddressDetail)Session["CurrentAddress"]).Phone;
regUserAddress.Country = ((AddressDetail)Session["CurrentAddress"]).AddressType ?? "USA";
miEntity.ApplyPropertyChanges(regUserAddress.EntityKey.EntitySetName, regUserAddress);
miEntity.SaveChanges();
return true;
}
The error is the object is detached from the context, and ApplyPropertyChanges thinks the object is added because it isn't attached. So you would need to query from the data context or get an attached form and then apply the changes then.
HTH.
What Dave Said
+
You need to Attach() the disconnected entity to your object context:
http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.attach.aspx
miEntity.Attach(regUserAddress);
miEntity.SaveChanges();
Just add the following code before miEntity.SaveChanges():
miEntity.Entry(regUserAddress).State = EntityState.Modified;
First select the record (object entity), search by key through the ObjectContext. For example if the search ArticleSet EntitySet called for there to record, and once you get it modified its properties with new values and then call SaveChanges() of ObjectContext.
Example:
ObjectQuery<Article> myArt=Context.ArticleSet.Where myArt = (row => row.ArticleId == value);
myArt.Description=" new value ";
etc. ..
etc ...
Context.SaveChanges ();
I've started using Enterprise Library and have the following questions:
1)How do I add output parameter to this query and how do I get it back:
public int InsertDoc(HDocument document)
{
Database db = DatabaseFactory.CreateDatabase();
int result;
var reader = db.ExecuteNonQuery("sp_InsertDocument",
document.AddedDate,document.AddedBy, document.Title))
.
.
.
}
The db.AddOutParameter requires paremetrers that I don't have like DbCommand.
2)I have a few methods that work with database (I transfer from ADO.net) stored procedures,
do I have to declare : Database db = DatabaseFactory.CreateDatabase(); in each one of them or I can reuse it?
1) - You can make a DbCommand thusly:
DbCommand dbCommand = db.GetSqlStringCommand("sp_InsertDocument");
and retrieve the output parameter after execution with:
db.GetParameterValue(dbCommand, "outputParameterName");
Here's a good example of using EntLib to execute a sproc with output params:
http://www.devx.com/dotnet/Article/30910/0/page/4
2) - You can use DatabaseFactory.CreateDatabase() in each method, that's fine. EntLib will manage the connections as necessary.
As an aside, if you're only using the db variable once in a method, then you could simplify your code slightly by using an inline temp instead of declaring a variable, i.e.:
var reader = DatabaseFactory.CreateDatabase().ExecuteNonQuery(....