working on it ...


Explore Public Snippets

Sort by

Found 1,767 snippets matching: entity

    public by PLAT.ONE @ PLAT.ONE  324316  3  6  0

    How to save a custom property on PLAT.ONE, aka to enhance the data model of a device

    Custom properties are key-value pairs associated to an entity in PLAT.ONE. You can attach at runtime those new properties
    import java.util.ArrayList;
    import java.util.List;
    import com.abodata.plat1.nodeInfo.WSNNodeType;
    import com.abodata.plat1.system.ICredentialUtils;
    import com.abodata.plat1.utils.APIFilter;
    import com.abodata.plat1.velocity.client.IPlatoneAPI;
    public class AddCustomPropertyExample {
    	public void addProperty() throws Exception {
    		IPlatoneAPI apiMan = YourServiceActivator.getApiMan();
    		ICredentialUtils creds = YourServiceActivator.getCredentialUtils();
    		//let's retrieve the first available camera:
    		List<APIFilter> filters = new ArrayList<APIFilter>();
    		filters.add(new APIFilter("type", new String[] { WSNNodeType.ENDPOINT.getType() + "", WSNNodeType.ROUTER.getType() + "" }));
    		List<IProxyPhysicalNode> cameras = apiMan.DB_GetVisiblePhysicalNode(null, filters, true, 0, 1);
    		IProxyPhysicalNode camera =	cameras.get(0);
    		//get the current user:
    		IProxyPlatUser curUser = apiMan.DB_GetPlatUser(creds.getUserName(), creds.getPsw());
    		//add a property to the camera:
    		IProxyCustomProperty p = apiMan.DB_AddCustomProperty(creds.getAppGardenId(), "resolution", false, "1280x768", 
    				ProxyObjType.customProperty, curUser.getId(), camera.getId(), ProxyObjType.physNode, CPAllowable.all, 
    		if (p != null)
    			System.out.println("Property added!");
    			System.out.println("Something wrong...");

    public by AnghelLeonard  212359  3  5  0

    Hibernate JPA - programmatically set the transaction isolation level for the current connection

    Hibernate JPA - programmatically set the transaction isolation level for the current connection
    entityManager = entityManagerFactory.createEntityManager();
                Session session = (Session) entityManager.getDelegate();            
                session.doWork((Connection connection) -> {

    public by lbottaro  2187  0  6  1

    A simple java entity - Person class

    This is a simple POJO class. Since it contains data to be saved on database, use the annotation Entity. The entity is annotated as RequestScoped. Its data will be stored and retrieved from database, using JPA.
    package com.test.example.person;
    import javax.enterprise.context.RequestScoped;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    public class Person implements Serializable {
    	private static final long serialVersionUID = 1L;
        private int id;
        private String firstName;
        private String lastName;
        private String address;
        private int age;
        public Person() {
        public Person(String id) {
   = Integer.parseInt(id);
        public Person(int id) {
   = id;
        public Person(int id, String firstName, String lastName, String address, int age) {
   = id;
            this.firstName = firstName;
            this.lastName = lastName;
            this.address = address;
            this.age = age;
        public int getId() {
            return id;
        public void setId(int id) {
   = id;
        public String getFirstName() {
            return firstName;
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        public String getLastName() {
            return lastName;
        public void setLastName(String lastName) {
            this.lastName = lastName;
        public String getAddress() {
            return address;
        public void setAddress(String address) {
            this.address = address;
        public int getAge() {
            return age;
        public void setAge(int age) {
            this.age = age;
        public String toString() {
            return "Person {" + "id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", address=" + address + ", age=" + age + '}';

    public by AnghelLeonard  1484  0  5  0

    EntityManager joining a JTA transaction

    EntityManager joining a JTA transaction
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("foo_PU");
    EntityManager em = emf.createEntityManager();
    // specific to JBossStandAloneJtaPlatform
    javax.transaction.TransactionManager tx = 
    // or
    javax.transaction.UserTransaction tx_ = 
    try {

    public by passh  3421  1  5  0

    foreach ENTITY in a REPO

    namespace lacueva\BlogBundle\Controller;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use lacueva\BlogBundle\Entity\Entries;
    class DefaultController extends Controller
        public function indexAction()
    		$em = $this->getDoctrine()->getManager();
    		$entry_repo = $em->getRepository('BlogBundle:Entries');
    		$entries = $entry_repo->findAll();
    		$e = new \lacueva\BlogBundle\Entity\Entries;
    		foreach ($entries as $e)
    			echo $e->getTitle();
    		 //       return $this->render('BlogBundle:Default:index.html.twig');

    public by kla  3262  0  5  1

    VHDL Entity

    Example of generic VHDL entity
    ENTITY entityName IS
       generic1    : positive range 1 to 128:=4;
       generic2    : std_logic:='0';
       generic3    : integer range 1 to 32:=1
      PORT (
        signal1    : IN  STD_LOGIC;
        signal2    : OUT STD_LOGIC_VECTOR(15 DOWNTO 0)
    END entityName;

    public by lbottaro  1827  0  6  1

    How to persist java class - JPA PersonManager

    This class manage the data entity Person using java JPA framework. The annotation PersistenceContext will set the Persistence Unit name for the EntityManager. The name must match the one set in persistence.xml. This manager can persist, delete, find and search Person entity.
    package com.test.example.person.manager;
    import java.util.Collection;
    import java.util.List;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    import javax.persistence.TypedQuery;
    import com.test.example.interfaces.IPerson;
    import com.test.example.person.Person;
    public class PersonManager implements IPerson {
        @PersistenceContext(unitName = "PersonWebAppEJB_FinalPU")
        private EntityManager em;
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    	public Person getPerson(int id) {
    		return em.find(Person.class, id);
    	public List<Person> getPersonList() {
    		TypedQuery<Person> q = em.createQuery("select p from Person p", Person.class);
            List<Person> personList = q.getResultList();
            return personList;
    	public Person addPerson(Person p) {
    		return p;
    	public Person updatePerson(Person p) {
    		p = em.merge(p);
            return p;
    	public void deletePerson(int id) {
    		Person p = em.find(Person.class, id);
    	public Collection<Person> searchPersons(String completeName) {
    		String[] nameParts = completeName.split(" ");
    		String firstName = nameParts[0];
    		String lastName = nameParts.length > 1 ? nameParts[1] : "";
    		TypedQuery<Person> q = em
    						"select p from Person p where p.firstName like :firstName and p.lastName like :lastName",
    		q.setParameter("firstName", firstName.concat("%"));
    		q.setParameter("lastName", lastName.concat("%"));
    		List<Person> personList = q.getResultList();
    		return personList;

    public by AnghelLeonard  1755  0  5  0

    Execute a Hibernate SQLQuery via EntityManager

    Execute a Hibernate SQLQuery via EntityManager
    List results = ((Session)this.entityManager.getDelegate()).createSQLQuery(
                    "SELECT AS namep, AS names, AS namet"
                            + " FROM secondarycategory b"
                            + " INNER JOIN topcategory a ON"
                            + " INNER JOIN thirdcategory c ON").list();

    public by lbottaro  4524  2  8  5

    Functions as first class objects in Python

    Python allows the coder to treat functions as objects, also known as first class objects. Usually a first class object is an entity that can be dynamically created, destroyed, passed to a function, returned as a value, and have all the rights as other variables in the programming language have. In this case the functional programming paradigm al
    def add(a, b):
      return a + b
    def subtract(a, b):
      return a - b
    def multiply(a, b):
      return a * b
    def divide(a, b):
      if b:
        return a /b
        return "Error, divide by zero!"
    def power(a, b):
      return a ** b
    def modulus(a, b):
      return a % b
    functions = [add, subtract, multiply, divide, power, modulus]
    for function in functions:
      name = function.__name__
      result = function(4.0,5.0)
      print(name + ": " + str(result))

    public by lbottaro  2501  0  7  2

    How to execute a simple JPQL query in JPA

    The code shows a simple JPQL query in java. You need to instance an EntityManager object and invoke its createQuery method. This will manage a JPQL statement, where the parameters are passed using colon (:) format. Query setParameter method is used to set such parameters and getSingleResult returns the single record.
    private static final String PERSISTENCE_UNIT_NAME = "User";
    private static EntityManagerFactory factory;
    factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
    EntityManager em = factory.createEntityManager();
    Query q = em.createQuery("SELECT u FROM User u WHERE u.Name = :name AND u.Password = :pass");
    q.setParameter("name", userName);
    q.setParameter("pass", password);
    User user = (User) q.getSingleResult();
    • Public Snippets
    • Channels Snippets