EJB / EE :: JTA And Dynamic Persistence Unit?

Jan 26, 2015

In my application, users select the year and manage data for that year (for example, they can choose 2014 for managing invoices for 2014, then switch to 2015 and work with that year). Each year as his own database.

I'am able to change persistence unit connection at runtime with Persistence.createEntityManagerFactory(PU_NAME,map_with_connection_info) This procedure build a non-jta environment.

It is possible to create entityManager / entityManagerFactory with JTA ?

I don't want to create new persistence unit each year or each time a new database is required.

View Replies


ADVERTISEMENT

How To Call EnrolStudent Method On Unit Constructor In Another Class When Create A New Unit

Mar 29, 2014

public Unit(String code, String name)
{
enrolStudent(student);
this.unitCode = code;
this.unitName = name;
}
public void enrolStudent(Student newStudent){
students = new ArrayList<Student>();
newStudent = new Student(24662496, "Kingsley", " Iwunze");
students.add(newStudent);
}

how can I call this enrolStudent() method on this Unit constructor in another class when I create a new Unit. all I need is to enroll students in units when units are created. below is my create unit method.

public void createUnits( ){
units = new ArrayList<Unit>();
units.add(new Unit("FIT2034", "Java Programming 2"));
units.add(new Unit("FIT2024", "Software Engineering"));
units.add(new Unit("MAT1830","Discrete Maths"));
unit.enrolStudent(new Student(25486321, "Julia", "Garcia"));
unit.enrolStudent(new Student(44589736, "James", "Olivia"));
unit.enrolStudent(new Student(47852103, "Lucky", "Thyriod"));
}

View Replies View Related

Shifting Row From 2D Array Down One Unit?

Feb 24, 2014

So I have this 2D array that contains some Object foo.

[f] [f] [f][f]

[3][3][3][3]

[b][b][b][b]

[x][x][x][x]

[ ][ ][ ][ ]

[ ][ ][ ][ ]

[ ][ ][ ][ ]

I want to shift all the rows down one unit, starting for the rows containing x. So the x row is first shifted to row 4. then the b row shifted to where the x row was, row 3 and so on. My question is:

1. How can I check if the next row is empty

2. How do I shift a row down

Here's my attempt:

Java Code:

//board is the 2D array defined elsewhere
public void shiftRowDown(){
int counter = 0;
int rowCounter = 0;
for (int i = 0; i < this.board.length; i++) {

[code]....

Is this correct.

View Replies View Related

Website Interaction Using HTML UNIT

Apr 23, 2015

I am having a difficult time trying to get results from the code below. The purpose is for my program to insert the DHL tracking number in the tracking text box, and then for the program to "click" the search button and get the tracking results.

This is the code:

import com.gargoylesoftware.htmlunit.WebClient;
import java.io.*;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import java.net.*;
public class DHL {

[Code]...

These are the results I am getting in the console (in red), which look like an error:

Apr 23, 2015 7:55:49 PM com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement addbehavior
WARNING: Unimplemented behavior: #default#userdata
Exception in thread "main" com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[*] attributeName=[name] attributeValue=[sbtc]
at com.gargoylesoftware.htmlunit.html.HtmlPage.getElementByName(HtmlPage.java:1747)
at htmlTest.main(htmlTest.java:17)

I just cannot figure it out for the life of me. Also, is there a community that focuses on HTML Unit?

View Replies View Related

EJB / EE :: Bean Annotations And Unit Testing?

Mar 6, 2014

I have a bean that represents data been collected from a form on a jsp page. Currently I would like to validate my fields and write some test cases for them. As you can see from my test case example I test a string in the hope that it fails because it contains only one letter. My problem is my unit test is passing. The reason this is from what I can tell is that at runtime it fails when I try to persist my object using my entity manager. During my unit test I just I don’t call my entity manager I just try and set the field.

What I thought would happen was that when I use my bean fields set method the annotations would be checked and fail at that point. Hence why I expected my unit test in this case to fail.

What I would like to know is

1.Are annotations specifically designed to validate when I persist my object and am I using them incorrectly at this point?

2.Is this the best method to use to validate fields, is there a better way, should I write my own code to validate for me when I set my value?

a. Should I throw an exception from the set method of each bean field?

Unit Test:

@Test
public void testName(){
Human h=new Human();
try {
h.setFname("a");
} catch (Exception e) {
// TODO Auto-generated catch block
fail("failed");
e.printStackTrace();

[code]....

View Replies View Related

Time Unit Conversion Program

Feb 8, 2015

So, here is the question I have been working on: Write a java class named Time that prompts the user to input the elapsed time for an event in seconds. The program then outputs the elapsed time in hours, minutes, and seconds. (For example the elapsed time is 9630 seconds, and then the output is 2:40:30 ).Hint: an hour has 3600 seconds and a minute has 60 seconds. Use Scanner class for reading the input.

Here is my code:

import java.util.Scanner;
public class Time {
public static void main(String[] args) {
Scanner scan= new Scanner(System.in);
System.out.println("Enter the elapsed time in seconds:");
int totalseconds= scan.nextInt();

[Code] .....

Now, I know I am supposed to use the remainder operator to figure out the time in minutes and seconds, but the hours has be a little confused. Right now this code compiles but gives me an exception.

View Replies View Related

EJB / EE :: How To Unit Test MDBs And Session Beans

Apr 18, 2014

What are the best practices for unit testing MDBs and session beans ?How can they be tested without running an application server ?

View Replies View Related

JavaFX 2.0 :: VRML - Unit Of Measure Convention In 3D?

Apr 12, 2015

When creating VRML, there is a convention that one unit corresponds to 1 metre in the real world. This makes sharing models easier. Is there any similar convention for JavaFX 3D?

View Replies View Related

Write Unit Tests When Some Other Classes Are Involved And Abstraction Is Much Higher?

Mar 5, 2015

I have two classes Person and Group. Group object is suppose to contain many Persons, How can I write unit tests when some other classes are involved and abstraction is much higher?

View Replies View Related

Calculate Possible Tiles Clicked Unit Can Be Moved On And Display It To Player

May 15, 2014

Alright, so I'm having problems with lines 11 - 55. I'm trying to calculate the possible tiles the clicked unit can be moved on and display it to the player.

The field is a 9 (columns) by 5 (rows) grid. A unit with can move tiles horizontally or vertically based on its movement.

Example: (unit = o; possible tiles = x) (assuming movement of 2).

[ ][ ][ ][ ][x][ ][ ][ ][ ]
[ ][ ][ ][x][x][x][ ][ ][ ]
[ ][ ][x][x][o][x][x][ ][ ]
[ ][ ][ ][x][x][x][][ ][ ]
[ ][ ][ ][ ][x][ ][ ][ ][ ]

I tried to calculate movement by finding out what column the unit is in, subtracting the column it wants to go to, multiplying the difference by *-1 if the difference is less than 0. Then, doing the same with rows and adding the difference of columns to the difference of rows and comparing it to the unit's movement. Unfortunately, with my code, it seems to move in any directions.

@Override
public void mouseClicked(MouseEvent e) {
if (Main.cards.size() > 0) {
mainloop: for (int i = 0; i < Main.cards.size(); i++) {
Card c = (Card) Main.cards.get(i);
int startingColumn = 0;

[Code] ......

View Replies View Related

Getting NullPointer Exception In Unit Test At Activemq Connection Factory Creation

Dec 2, 2014

I have the following unit test that gives me a null pointer exception. The debugger goes to the finally block right after the line that creates a connection factory. Here's the test:

@Test
public void receiveMessage() throws Exception {
MessageConsumer consumer = null;
ConnectionFactory connectionFactory = null;
Connection connection = null;
Session session = null;
Destination destination = null;

[code]....

View Replies View Related

Dynamic Array With Input

Oct 25, 2014

Create a one dimensional array which holds 10 values. Ask the user to input an index value between 0 and 9. Print the value the user selected. Be sure to explain the output to the user. That is my assignment, and here is my code:

import java.util.Scanner;
public class Array {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int a[]= new int[9];
a[0] = 10;
a[1] = 20;

[code]....

I don't know how to use the scanner to get someone's input properly.

View Replies View Related

JSP :: Dynamic Entries In Web Form

Nov 15, 2014

I have a web form with a field Department. I want to add Sub Departments(unknown number) of one Department and then further Sub Sub Departments(unknown number) of one Sub Department. How I will make a form and how I will add this data in attached database. I have one solution:

One Department field with a button to add any sub department if any. By clicking on button, a new row will be generated with another text field and new button. In this way, it will go on. Tree like structure.

But I have another solution, JSF Tree to add or delete entries on the run time. But the problem is that I am unable to find any example of JSF tree like structure populated from database and in which we can add or delete entries on run time and on the same time these entries may also be stored in database.

View Replies View Related

Dynamic Linked List

Jan 30, 2014

I'm trying to implement an Office class that contains an inner class: WorkerNode. The WorkerNode class has a name attribute (String) and WorkerNode attributes for boss, peer and subordinate. The attributes of Office are manager and current which are WorkerNode references. The manager refers to the entry point of the structure and current is the current node in the structure. For simplicity, i'm going to try to limit it to 3 levels and assume that the names are unique. I've put together a Office class that containing main and provided the code I've worked on so far.

public class Office {
public static void main(String[] args) {
String name=Input.getString("input the manager's name: ");
Office office=new Office(name);
int option;

[code]....

View Replies View Related

Dynamic Method Creation

Aug 8, 2014

I am trying to create a Android game. The game is a card game, where each card has a different action and has a different effect. My first thought was to create a Card class and somehow dynamically change the action method for each instance. However after a little bit of research it seems that may be too difficult. A different idea is that I create a class for each different card, and therefore can define the action method different for each one. However currently there is at least 300 cards and therefore I would need 300 different classes, which seems excessive.

View Replies View Related

JavaFX 2.0 :: Is It Possible To Create Dynamic GUI?

Jul 7, 2014

I'd like the GUI to be drawn based on definition file. Is it possible to "generate" fxml (like PHP does html) so I could do this:
 
for (...) {
     command_to_generate (<button ....>);
}
 
?

Or is using legaxy javaFX code the only way to achieve it?

View Replies View Related

JSP :: Passing Dynamic Parameters Through Href Tag

Aug 3, 2011

I am trying to pass additional information through <a href> tag

<a href="welcome.jsp & param=<%=add.getID()%>">Welcome </a>

The error is : HTTP Status 404 - /WebApp/welcome.jsp & param=6

The id obtained from add.getID() is displayed in address bar on the browser.

I want to use this id on the next page. I try to use :

request.getParameter("param");

But could not get the ID....

View Replies View Related

JSF :: Dynamic Visibility Control Using SelectOneMenu

Apr 4, 2014

I'm trying to implement a functionality which will control the visibility of three outputText. I'm using a selectOneMenu, which has three options. Each option will enable visibility of one outputText, and rest will be invisible.

I used the following code

<h:selectOneMenu id="search" styleClass="select-box" value="#{empMB.showHide}" required="true" requiredMessage="Please Select an Option" >
<f:selectItem itemLabel="-----Select----"/>
<f:selectItem itemLabel="By Name" itemValue="1"/>

[Code] ....

Initially all outputText s is invisible as rendered value is false, but when I select different options, their respective outputText s are not visible.

View Replies View Related

Dynamic Initialization Of 2D Array Of Objects?

Aug 15, 2014

if, instead of an ArrayList, can I do the following to initialize a Dyanmic array ? :

First, in my class, I have :

class Example{
private int rows;
private int columns;
private AnotherClass[][] 2DArray;
public Example(int rows, int columns){
this.rows = rows;
this.columns = columns;

[code]....

View Replies View Related

Fibonacci Sequence Using Dynamic Arrays

Feb 12, 2014

public class Fibonacci {
public static void main(String[] args) {
int[] numbers;
numbers = new int[20];
numbers[0] = 0;
numbers[1] = 1;
System.out.println("

[Code] ....

I wrote this program for my Java class to print out the first 20 numbers of the Fibonacci series. My assignment then tells me to Rewrite your program using dynamic array. I'm not sure how to do this.

View Replies View Related

Implement Dynamic String Into SQL Statement

Aug 26, 2014

I have some spatial datasets which are availabe in a opensource metadata catalog software GeoNetwork and in a PostGIS database.The problem is that the student who created the database used different IDs for the same datasets. So the IDs in the GeoNetwork differs from the IDs in the postGIS database. They only have the same name So, if someone uploads a new dataset into GeoNetwork, the same dataset is uploaded into a postGis database too.

Now I want to add a ID column into the database to give the field the same ID like the ID in geonetwork. I think I can only do this with using the filename cause they are same in both cases.Now I want to alter the table in eclipse with following code:

PHP Code:

Connection con = null;
Statement stmt = null;
String query = null;
String filen = filename.substring(0, filename.indexOf('.'));
con = DriverManager.getConnection("jdbc:postgresql_postGIS://localhost:5433" + "user=postgres;password=dominik1;" + "database=geonetwork"); --> (the connection data will later be in a properties file)
query = "ALTER TABLE " + filen + " ADD GN_id INTEGER(10) ";
stmt = con.createStatement();
stmt.execute(query); mh_sh_highlight_all('php');

But i get the following findbug error:

Failed to execute goal org.codehaus.mojo:findbugs-maven-plugin:2.5.2:check (default) on project services: failed with 1 bug
org.fao.geonet.services.resources.UploadAndProcess .exec(Element, ServiceContext) passes a nonconstant String to an execute method on an SQL statement ["org.fao.geonet.services.resources.UploadAndProces s"] At UploadAndProcess.java:[lines 83-299]..

I tried to suppress this error and worked with PreparedStatement and String.Format but I can't get rid of this error.

View Replies View Related

Static And Dynamic Binding In OOPS

Mar 27, 2015

I have a question regarding static binding and dynamic binding. Say for example we have below hierarchy,

class Animal
{
public void eat() {
System.out.println("Animal Eating");
}
}

[Code] .....

1) a.eat(); // Prints Animal eating ---> Static Binding 2) a.eat(); // Prints Dog eating ----> Dynamic Binding

Static Binding means,compiler will be able to decide which method to call based on class type of reference variable at compile time.That is compiler will check whether method is available or not in class.

Dynamic binding means,at runtime JVM will run the method implementaton,based on the object which reference variable is pointing.

So basically compiler will check class type of reference variable and at runtime JVM will check what type of object reference variable is pointing.

Here my my doubt is , in below both cases,that is

1) a.eat(); // Prints Animal eating ---> Static Binding
2) a1.eat(); // Prints Dog eating ----> Dynamic Binding

At compile time,compiler will check whether method is available or not in class. Since eat() method is available ,then in both cases it should be Static binding. or at run time if JVM decides which method implementation to call,then JVM will check which object the reference variable is pointing,then in above 2 cases also JVM will check in Animal object and Dog object for the method eat(). Since eat() method available then both should be dynamic binding.

I am getting doubt on what parameters/conditions we are deciding which is static binding and which is dynamic binding .

Will compiler will check the type of reference variable and also type of object at compile time and when it is ambiguous it leaves the decision to JVM?

Or is it like if method call and method implementation belong to same class then it is static binding and if method call and method implementation belong to different class in same inheritance hierarchy then dynamic binding.

View Replies View Related

Static Vs Dynamic Class Loading

Feb 2, 2015

Understanding the difference between static and dynamic class loading.

It will be more useful if examples are given , especially for dynamic class loading(without using reflection).

View Replies View Related

Making Dynamic Website In Java

Jul 23, 2014

This might make me look pretty silly but I was curious if there was a way to make a dynamic web page in java. Basically only using pure Java, with only HTML5, CSS and mySQL.

View Replies View Related

Dynamic SQL In Java - Query Value From Database

Jun 18, 2014

I have code which query value from database, the use case is the user can enter value as 1,01,11 in database but when the user enter value in xml file he can only enter 11,01,12 in database there is two columns lets say column test1=1 and test2=2 combination of this is 12, which is the value the use will enter in xml, but sometime the use can enter test1=04 than column test2=00 how can i approach this
 
I got table called card with column crdind,crdpos1,cardpos2 as primary key. The user can enter value as
 
crdind=1
crdpos1=5
crdpos2=3
inactivedate=2013-05-24
activedate=null
 
another row
 
crdind=1
crdpos1=5
crdpos2=5
inactivedate=2013-05-24
activedate=null
 
another row

crdind=6
crdpos1=02
crdpos2=00
inactivedate=2013-05-24
activedate=null
 
The rule say if you enter one number in crdpos1 eg 2 than you must enter value in crdpos2 it can be any number 1-9 but if you enter 00-09 in crdpos1 than crdpos2 is 00
 
The challenge I have is to query this value after they been enter. I have xml file which got field crdpos the use enter 15 which is the combination of column crdpos1=1 and crdpos2=5 ... How can I split the value crdpos and got and able to query in database in two separate column ....

View Replies View Related

JSP / JSTL :: How To Display Dynamic ComboBox

Feb 6, 2013

we had a requirement to display a combobox which is filled with some values on the webpage when somebody checks the checkbox which is present on the webpage.

The approach we have taken is ajax. how we did this is, when somebody checks the checkbox on the webpage we are initiating the ajax call requesting a servlet. this servlet pulls the data from the database, places the data in the request and forwards the request to a jsp. In that jsp i am writing simple html combobox and populating the values in the combobox from the request using JSTL and this jsp will be sent as response to ajax call. The ajax gets the html as responce which contains a combobox and i am just placing that html ( the complete response) in a div which is next to checkbox.

In this approach there is lot of pain. if i have to display 10 html components dynamically based on some condition then i have to have 10 jsp's one for each component. I always feel this is a wrong way of doing things. what is the best approach to deal with the dynamic stuff on webpages.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved