How can i recover Blobs after migration to HRD - google-cloud-datastore

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.

Related

Entity Framework not recognizing stored procedure, showing invalid object SQL error

I have working code where I use EF to connect with my database. Recently the database has been moved to a different server. I started getting errors on few stored procedures from the EF DBContext ('Invalid object name');
I tried to look into the EDMX however can not make out any difference. There are a few stored procedures which run just fine, but another few do not.
public List<DTO_SRS_Roles_Result> AllRolesData()
{
// Invalid object name 'aspnet_NPMS_DEV..Aspnet_Roles'.
var query = (from a in ctx.ASPNET_Get_SRS_Roles()
select a).Distinct();
List<DTO_SRS_Roles_Result> "lstRoles" =
new List<DTO_SRS_Roles_Result>();
query.ToList().ForEach(rec =>
{
lstRoles.Add(new DTO_SRS_Roles_Result
{
RoleId = rec.RoleId,
RoleName = rec.RoleName.TrimEnd().TrimStart().Trim()
});
});
return lstRoles;
}
Procedure name is ASPNET_Get_SRS_Roles, but it says
Invalid object name 'aspnet_NPMS_DEV..Aspnet_Roles'
What could be the reason?

Embedding a readonly SQLite Database in a DLL and conenct via Entity Framework

I have a requirement that my DLL should have a readonly database. I made my database as a embedded resource but i am not able to figure it out to connect to the database via entity framework.
try
{
var dataSet = ConfigurationManager.GetSection("system.data") as System.Data.DataSet;
dataSet.Tables[0].Rows.Add("SQLite Data Provider"
, ".Net Framework Data Provider for SQLite"
, "System.Data.SQLite"
, "System.Data.SQLite.SQLiteFactory, System.Data.SQLite");
}
catch (System.Data.ConstraintException) { }
string providerName = "System.Data.SQLite";
string serverName = "NameSpace.DB.sqlite";
// Initialize the connection string builder for the
// underlying provider.
SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();
// Set the properties for the data source.
sqlBuilder.DataSource = serverName;
sqlBuilder.InitialCatalog = "DB.sqlite";
sqlBuilder.IntegratedSecurity = true;
// Build the SqlConnection connection string.
string providerString = sqlBuilder.ToString();
// Initialize the EntityConnectionStringBuilder.
EntityConnectionStringBuilder entityBuilder =
new EntityConnectionStringBuilder();
//Set the provider name.
entityBuilder.Provider = providerName;
// Set the provider-specific connection string.
entityBuilder.ProviderConnectionString = providerString;
// Set the Metadata location.
entityBuilder.Metadata = #"res://*/DataModel.DB.csdl|
res://*/DataModel.DB.ssdl|
res://*/DataModel.DB.msl";
Console.WriteLine(entityBuilder.ToString());
using (EntityConnection conn =
new EntityConnection(entityBuilder.ToString()))
{
conn.Open();
Console.WriteLine("Just testing the connection.");
_container = new MyEntities(conn);
var usersList = _container.UserTable.ToList();
}
It works only when we are copying the database to the client application. I don't want to provide the database as a separate file. I want to embedded it in the dll and give only the dll to other applications.
Regards,
Vivek
As CL. said SQLite has to be in an independent .sqlite file, It cannot be embedded. Take a look at SQL Server Compact. It is all you need, an embedded SQL Database that you can access using Entity Framework.
Here's a tutorial in how to connect to EF.
SQLite databases are based on files.
The SQLite library has the ability to access files through a virtual file system, which would allow redirecting file accessing to somewhere else. So it would be possible to implement a VFS that accesses a resource.
However, System.Data.SQLite does not appear to allow registering your own VFS.

Unable to get data from WCF service using entity framework

I am using a web application where user pass one argument to the service and it will return string datatype which is query result. In the service i am using Entity Framework to query based on the user input but i am unable to get the data instead throwing an exception in my webapplication saying.....
The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.
Webapplication and service are two different solutions.
Code in My WCF service
public string GetFunctionality(string UserId)
{
string strRoleName = string.Empty;
objEntity = new SYMPHONY_TVEntities();
var Function = from t1 in objEntity.Users join t2 in objEntity.User_Role on t1.Role equals t2.User_Role1 where t1.UserID == UserId select t2;
var UserName = from it in objEntity.Users where it.UserID == UserId select it;
//Here i am getting exception
User_Role objRole = Function.First();
User objUser = UserName.First();
if (objRole.User_Function != null && objUser.User_Name != null)
{
strRoleName = objRole.User_Function + "$" + objUser.User_Name;
}
return strRoleName;
}
My connection string WCF service
<add name="SYMPHONY_TVEntities" connectionString="metadata=res://*/UsersModel.csdl|res://*/UsersModel.ssdl|res://*/UsersModel.msl;provider=System.Data.SqlClient;provider connection string='Data Source=inhi1u-hd0212\;Initial Catalog="SYMPHONY TV";Integrated Security=True;MultipleActiveResultSets=True'" providerName="System.Data.EntityClient" /></connectionStrings>
You code looks ok. The exception says it is unable to connect to the db. This means your connection string might be wrong, please verify your connection string. If this fails try adding this line of code after your objEntity. (Why?)
objEntity = new SYMPHONY_TVEntities();
objEntity.Connection.Open();

SQLITE_BUSY The database file is locked (database is locked) in wicket

I am doing a project in wicket
How to solve the problem.
I came across such a message:
WicketMessage: Can't instantiate page using constructor public itucs.blg361.g03.HomePage()
Root cause:
java.lang.UnsupportedOperationException: [SQLITE_BUSY] The database file is locked (database is locked)
at itucs.blg361.g03.CategoryEvents.CategoryEventCollection.getCategoryEvents(CategoryEventCollection.java:41)
public List<CategoryEvent> getCategoryEvents() {
List<CategoryEvent> categoryEvents = new
LinkedList<CategoryEvent>();
try {
String query = "SELECT id, name, group_id"
+ " FROM event_category";
Statement statement = this.db.createStatement();
ResultSet result = statement.executeQuery(query);
while (result.next()) {
int id = result.getInt("id");
String name = result.getString("name");
int group_id = result.getInt("group_id");
categoryEvents.add(new CategoryEvent(id, name, group_id));
}
} catch (SQLException ex) {
throw new UnsupportedOperationException(ex.getMessage());
}
return categoryEvents;
}
at itucs.blg361.g03.HomePage.(HomePage.java:71)
categories = categoryCollection.getCategoryEvents();
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
Sqlite allows only one writer to the whole database at a time and, unless you selected "WAL" journal mode, no reader while writing. Moreover unless you explicitly ask it to wait, it simply returns the SQLITE_BUSY status for any attempt to access the database while conflicting operation is running.
You can tell sqlite to wait for the database to become available for a specified amount of time. The C-level API is sqlite3_busy_timeout; I never used sqlite from Java though, so I don't know where to find it there.
(...) tell sqlite to wait for the database to become available for specified amount of time.
In order to do it from Java, run the following statement just like a simple SQL statement:
pragma busy_timeout=30000; -- Busy timeout set to 30000 milliseconds

Datanucleus exception adding new column to hbase table

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.

Resources