I'm developing a portlet that is deployed as WAR. Database models are created by service builder. How can I insert initial data models to the database when the WAR is installed?
Add to the project a portal.properties file with the property:
application.startup.events=com.my.project.MyStartupAction
and impliment the startup import as extension of SimpleAction:
package com.my.project;
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.events.SimpleAction;
public class MyStartupAction extends SimpleAction {
#Override
public void run(String[] arg0) throws ActionException {
if(startupDataNotExist()) {
createStartupData();
}
}
...
You can do this either as StartupAction, executed on startup of the plugin (read: during deployment AND during subsequent server starts) or as an UpgradeAction.
A good example for this is the sevencogs-hook that comes with Liferay CE and has the source code included. This is implemented as an UpgradeAction - e.g. on first start your database content will be "upgraded" to contain the sevencogs sample data.
Also you can do it with UpgradingProcess. Here are step-by-step instructions
Related
I am running ASP.NET Core 2 application.
I have a local instance of SQL Server where I have a table with a column of type Geometry.
When I go to read this table I get the following errors:
Type Udt is not supported on this platform.
Error parsing column 4 (MyLocation)
However this issue only seems to occur in my API project which calls to a custom made Nuget package that handles the CRUD operations.
If I test the same code in the project that does the CRUD it reads and maps my object.
It is not a connection issue in the API for I can successfully read/write other tables that do not have a Geometry field in it.
What could I possible be missing?
Code:
MyController:
public async Task<IActionResult> Get(Guid Id)
{
var rec = await myRepo.Get<MyData>(id);
// then do stuff
}
*myRepo is injected into my controller.
public class MyData
{
public Guid Id {get;set;}
public IGeometry MyLocation {get;set;}
}
myRepo:
public async Task<TEntity> Get<TEntity>(object id)
where TEntity : class
{
_conn.Open();
return await _conn.GetAsync<TEntity>(id);
}
If this is .NET Core, then I suspect you could have significant issues using sqlgeography etc; UDTs essentially aren't yet implemented in .NET Core:
Additionally, the underlying types that you would want to load use native code; the geo/etc types are not, AFAIK, available in .NET Core.
If I'm wrong, I'm more than happy to try to make whatever changes we need to help make this work, but at the time of writing: I don't think this is going to work through any API (it is not specific to Dapper).
You might want to consider using ASP.NET Core on .NET Framework for today? reference .Net framework 4.5.2 from .Net Core 2.0 project
If this data does actually load from ADO.NET in .NET Core, then I'd be happy to fix whatever I've missed.
I'm trying to create a simple backend for a html/JavaScript app. I started off by creating a new visual Studio Project using the azure mobile Service template. I created a simple DataObject class called 'ProjectItem' which is looking like this:
public class ProjectItem : Microsoft.WindowsAzure.Mobile.Service.EntityData
{
public string Title { get; set; }
public string Description { get; set; }
}
After that I added a table Controller and there was no need to touch any Code in that class.
In the web api config I added this peace of Code:
List<ProjectItem> projectItems = new List<ProjectItem>
{
new ProjectItem {Id = Guid.NewGuid().ToString(), Title = "First Project", Description = "My First Project Description" },
new ProjectItem {Id = Guid.NewGuid().ToString(), Title = "Second Project", Description = "My Second Project Description" }
};
foreach (ProjectItem projectItem in projectItems)
{
context.Set<ProjectItem>().Add(projectItem);
}
I debugged the Service on my localhost and it was working just fine.
Now I wanted to host it on azure and there the Problems started for me.
Here the stepps I did using azure:
I created an empty database on the new Portal
In visual Studio I clicked publish (my solution) and created a new mobile Service selecting the empty database - I didn't touch the rest of the Settings. The mobile Service is now "up and running".
I only have worked with sqlite since now so I opened the database in visual Studio and wanted to look at the test items I created (the 2 Project Items).
But there is no ProjectItem table and no ToDoItem table either!
How can this happen?
What did I do wrong?
Why is it creating the tables running on localhost but when
Publishing on azure it isn't?
I believe that it is not that simple as to create the object model and it will create the same table in the backend (SQL Azure to be clear, or Azure Storage). You need to create it using Azure dashboard, or do the custom API and do as described here. You may do the same in the Visual Studio, i think, or from the SQL Server Management Studio connected to the SQL Azure db.
For Mobile Services, however, if you set the dynamic schema on the dashboard, it will be able to create new columns when they are in the object, but it is not recommended in the production.
So, you did not anything wrong, it looks that the creation of the table programmatically is just not a supported way (only by dashboard or any type of the explorer like SSMS or VS). Anyway (by the way), they will be not in the System Tables branch.
I have been developing and application and I create all the web services using google endpoints.
For default is using Cloud DataStorage, and i want to change it to Cloud SQL storage. I'm following this steps from the documentation https://cloud.google.com/appengine/docs/java/cloud-sql/
import java.util.Map;
import java.util.HashMap;
import com.google.appengine.api.utils.SystemProperty;
...
// Set the persistence driver and url based on environment, production or local.
Map<String, String> properties = new HashMap();
if (SystemProperty.environment.value() ==
SystemProperty.Environment.Value.Production) {
properties.put("javax.persistence.jdbc.driver",
"com.mysql.jdbc.GoogleDriver");
properties.put("javax.persistence.jdbc.url",
"jdbc:google:mysql://your-project-id:your-instance-name/demo");
} else {
properties.put("javax.persistence.jdbc.driver",
"com.mysql.jdbc.Driver");
properties.put("javax.persistence.jdbc.url",
"jdbc:mysql://127.0.0.1:3306/demo");
}
// Create a EntityManager which will perform operations on the database.
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(propertiesMap, "persistence-unit-name");
What "persistence-unit-name" means in the last line?
As per the definition, A persistence unit defines a set of all entity classes that are managed by EntityManager instances in an application.
Please refer to the following link for more details.
Now, once your application is built and since this is a web application, as per the link above "If you package the persistence unit as a set of classes in a WAR file, persistence.xml should be located in the WAR file’s WEB-INF/classes/META-INF directory." Look inside the META-INF folder under src directory and you should see a persistence.xml file, which will have the persistent unit name defined as the one you specified while getting the PMF.
Hope this helps.
Dear fellow programmers,
I am very new to programming and i am following the tutorial on using app engine backend tutorial. However i face some problem along the way.
I have Setup App Engine Backend Application Project, created a CheckIn entity class.
After which, i follow the instruction to create a new class with the name CheckInEndPoint.java
I copy the code from the snippet over to the Class.
When i try to Generate Cloud Endpoint Class, i faced an error message.
Error Generating API
This is not a JDO/JPA entity class.
Kindly seek your advice on how to troubleshoot it.
https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial#ecdp
The instructions as provided by Google are confusing. What the instructions intended to say is after creating CheckIn.java, right-click on the CheckIn.java file and select Google->Generate Cloud Endpoint Class. This will then automatically create the CheckInEndpoint.java file.
Read through the entire "Entity Design Class Pattern" paragraph as given in the link you provided. You'll recognise that their instructions are ambiguous and is actually meant to be carried out from point 6.
Try adding this annotation to your CheckIn class:
import javax.jdo.annotations.PersistenceCapable;
#PersistenceCapable
public class CheckIn ...
This way it will find it as a JDO entity class and it will generate your CheckInEndPoint class.
I had the same error, I have first renamed the class CheckInEndPoint I've created manually to avoid any kind of conflicts. After that I have right clicked on
CheckIn class -> Google ->Generate Cloud Endpoint Class.
If you get some dependencies errors, please try check whether all the classes like ApiKeysAndIds.java, UserAccount.java are in the package.
I came to know GAE cloud endpoints yesterday. From that time I am trying to generate APIs for my current web application. I am using JPA2.0, I chose one of my entity classes right clicked on it and then "generate Google endpoint class" . So now I have another class for this entity with #API annotations, etc.
But the problem is after deploying the app when I go to : https://developers.google.com/apis-explorer/?base=https://myAppId.appspot.com/_ah/api#p/
the services tab is empty. Same thing when I check it locally(Image below)
You need to Generate Cloud Endpoints Library (in Eclipse, right click on the Project, it's under Google) as well.
I had similar issue and it was caused by missing public attribute in methods.
#Api
public class MyApi {
#ApiMethod
void myMethod() { }
}
caused that I saw no methods. While added
#Api
public class MyApi {
#ApiMethod
public void myMethod() { }
}
methods started to be visible.
1.Login appengine
https://appengine.google.com/
2.Click the [Version] link in a Main category
3.Select your version and [Make Default] button
4.You can access the api explorer
https://myAppId.appspot.com/_ah/api/explorer
Best Regard.
I actually managed to resolve the above issue. So I had a web application existing and I thought I could just add annotations to it and have the APIs represented for it after deployment. But I realized that I had to start from scratch by creating an android app and then generate the back-end for that app and add my classes there. It now works. Thank you.
Points to remember before working on endpoints :
Need to create an endpoint client library before running your project.(In Eclipse : Project -> Right click -> Google -> Generate cloud endpoints library)
Check whether you are using latest Google Plugin or not. Because files required by endpoints will be executed from the plugin. If you are not able to generate the endpoint library. problem is with the plugin .Try updating it.
Endpoints will work only on default versions. Make sure that you made your version default.
finally try loading http://myApp.appspot.com/_ah/api/explorer. Everything should be fine now.