Given that django-nonrel has got JOINs working, does this mean we have M2M fields workable with Django now in GAE?
What other current restrictions does Django have in GAE?
I'm looking for a doc comment that would define the scope/context of the current php template. (similar to @var)
Example View Class:
<?php
class ExampleView {
protected $pageTitle;
public function __construct($title) {
$this->pageTitle = $title;
}
public function render() {
require_once 'template.php';
}
}
--
<?php
// template.php
/** @var $this ExampleView */
echo $this->pageTitle;
PHPStorm gives an inspection error because the access on $pageTitle is protected.
Is there a hint to give scope? Something like:
<?php
// template.php
/** @scope ExampleView */ // <---????
/** @var $this ExampleView */
echo $this->pageTitle;
I know how to mark a group of fields as primary key in ADO.NET entities but i haven't found a way to declare unique constraints or check constraints.
Is this feature missing on the designer or on the framework?
Thanx.
I have the following code.
What I want to achieve is to update the shown list when I click an entry so I can traverse through the list.
I found the two uncommented ways to do it here on stackoverflow, but neither works.
I also got the advice to create a new ListActivity on the data update, but that sounds like wasting resources?
EDIT: I found the solution myself. All you need to do is call "SimpleCursorAdapter.changeCursor(new Cursor);". No notifying, no things in UI-Thread or whatever.
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class MyActivity extends ListActivity {
private DepartmentDbAdapter mDbHelper;
private Cursor cursor;
private String[] from = new String[] { DepartmentDbAdapter.KEY_NAME };
private int[] to = new int[] { R.id.text1 };
private SimpleCursorAdapter notes;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.departments_list);
mDbHelper = new DepartmentDbAdapter(this);
mDbHelper.open();
// Get all of the departments from the database and create the item list
cursor = mDbHelper.fetchSubItemByParentId(1);
this.startManagingCursor(cursor);
// Now create an array adapter and set it to display using our row
notes = new SimpleCursorAdapter(this, R.layout.department_row, cursor, from, to);
this.setListAdapter(notes);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// get new data and update the list
this.updateData(safeLongToInt(id));
}
/**
* update data for the list
*
* @param int departmentId id of the parent department
*/
private void updateData(int departmentId) {
// close the old one, get a new one
cursor.close();
cursor = mDbHelper.fetchSubItemByParentId(departmentId);
// change the cursor of the adapter to the new one
notes.changeCursor(cursor);
}
/**
* safely convert long to in to save memory
*
* @param long l the long variable
*
* @return integer
*/
public static int safeLongToInt(long l) {
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
throw new IllegalArgumentException
(l + " cannot be cast to int without changing its value.");
}
return (int) l;
}
}
hello friends,
I have two databases at two different places, both databases are same with table name as well as fields. now I want to synchronise both database. Is there any java code or we can achieve that directly from mysql or sql ? How ?
I have two Entities , with the following JPA annotations :
@Entity
@Table(name = "Owner")
public class Owner implements Serializable
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private long id;
@OneToOne(fetch=FetchType.EAGER , cascade=CascadeType.ALL)
@JoinColumn(name="Data_id")
private Data Data;
}
@Entity
@Table(name = "Data")
public class Data implements Serializable
{
@Id
private long id;
}
Owner and Data has one-to-one mapping , the owning side is Owner.
The problem occurs when I execute : owner.setData(null) ; ownerDao.update(owner) ;
The "Owner" table's Data_id becomes null , that's correct.
But the "Data" row is not deleted automatically.
I have to write another DataDao , and another service layer to wrap the two actions ( ownerDao.update(owner) ; dataDao.delete(data); )
Is it possible to make a data row automatically deleted when the owning Owner set it to null ?
not sure why this program isn't working. it compiles, but doesn't provide the expected output. the input file is basically just this:
Smith 80000
Jones 100000
Scott 75000
Washington 110000
Duffy 125000
Jacobs 67000
Here is the program:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
/**
*
* @author Leslie
*/
public class Election {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException {
// TODO code application logic here
File inputFile = new File("C:\\Users\\Leslie\\Desktop\\votes.txt");
Scanner in = new Scanner(inputFile);
int x = 0;
String line = "";
Scanner lineScanner = new Scanner(line);
line = in.nextLine();
while (in.hasNextLine())
{
line = in.nextLine();
x++;
}
String[] senatorName = new String[x];
int[] votenumber = new int[x];
double[] votepercent = new double[x];
System.out.printf("%44s", "Election Results for State Senator");
System.out.println();
System.out.printf("%-22s", "Candidate"); //Prints the column headings to the screen
System.out.printf("%22s", "Votes Received");
System.out.printf("%22s", "%of Total Votes");
int i;
for(i=0; i<x; i++)
{
while(in.hasNextLine())
{
line = in.nextLine();
String candidateName = lineScanner.next();
String candidate = candidateName.trim();
senatorName[i] = candidate;
int votevalue = lineScanner.nextInt();
votenumber[i] = votevalue;
}
}
votepercent = percentages(votenumber, x);
for (i = 0; i < x; i++)
{
System.out.println();
System.out.printf("%-22s", senatorName[i]);
System.out.printf("%22d", votenumber[i]);
System.out.printf("%22.2f", votepercent[i]);
System.out.println();
}
}
public static double [] percentages(int[] votenumber, int z)
{
double [] percentage = new double [z];
double total = 0;
for (double element : votenumber)
{
total = total + element;
}
for(int i=0; i < votenumber.length; i++)
{
int y = votenumber[i];
percentage[i] = (y/total) * 100;
}
return percentage;
}
}
In a class which has a lazy loaded property, such as:
private Collection<int> someInts;
public Collection<int> SomeInts
{
get
{
if (this.someInts == null) this.someInts = new Collection<int>();
return this.someInts;
}
}
Is it worth also having a property such as:
public bool SomeIntsExist
{
get { return (this.someInts != null && this.someInts.Count > 0); }
}
And then using that property.. eg:
if (thatClass.SomeIntsExist)
{
// do something with thatClass.SomeInts collection
}
or is this premature optimisation. Its certainly easier to roll with something like below, but it will instantiate the collection needlessly:
if (thatClass.SomeInts.Count > 0)
{
// do something with thatClass.SomeInts collection
}
Is the compiler smart enough to figure things like this out? Is there a better way?
I've created a custom control that subclasses TreeView. Right now it's completely empty, doesn't override anything. However when I place an instance in the designer the 'Auto' value for the Width and Height fields is no longer available as it is with the default TreeView. What am I missing?
i have this two button.as i press the first it plays an mp3 file.but if i press the second and the first mp3 hasnt finished yet,they play both together.how could i fix it??this is my btn code!!thanks
Button button = (Button) findViewById(R.id.btn);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
MediaPlayer mp = MediaPlayer.create(olympiakos.this, R.raw.myalo);
mp.start();
Toast.makeText(olympiakos.this, "Eisai sto myalo", Toast.LENGTH_SHORT).show();
}
});
Button button2 = (Button) findViewById(R.id.btn2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
MediaPlayer mp = MediaPlayer.create(olympiakos.this, R.raw.thryleole);
mp.start();
Toast.makeText(olympiakos.this, "thryle ole trelenomai", Toast.LENGTH_SHORT).show();
}
Basically, I want to have a database that's lightweight and I won't need to install a million other things on my clients computers for them to access this.
I just need a simple method of reading and writing values so that they're not hardcoded into the program. I could do MySQL (which is what I'm very familiar with), but it doesn't need to be making calls remotely.
I would have less than 10 fields and one table, if that matters.
Thanks!
Hi all, I'm at my wit's end here with virtual hosting. I'm trying to install redmine and it works with the webrick test server, but when I tried to use passenger (mod_rails) to host and go to the address I specified when in the virtualhost part of my apache config file nothing happens. Here is the relavent section of /etc/httpd/conf/httpd.conf where I try to set up the virtual host:
<VirtualHost *:80>
SetEnv RAILS_ENV production
ServerName redmine.MYSITE.com:80
DocumentRoot /opt/redmine-1.0.5/public/
<Directory /opt/redmine-1.0.5/public/>
Options -MultiViews
Allow from all
AllowOverride none
</Directory>
However, when I got to redmine.MYSITE.com:80 nothing happens, I just get our normal home page. I have no idea what the problem is, any help our guidance would be greatly appreciated. If you need any other information, please tell me and I'll provide it.
I have an Enum for Days of week (with Everyday, weekend and weekdays) as follows where each entry has an int value.
public enum DaysOfWeek {
Everyday(127),
Weekend(65),
Weekdays(62),
Monday(2),
Tuesday(4),
Wednesday(8),
Thursday(16),
Friday(32),
Saturday(64),
Sunday(1);
private int bitValue;
private DaysOfWeek(int n){
this.bitValue = n;
}
public int getBitValue(){
return this.bitValue;
}
}
Given a TOTAL of any combination of the entries, what would be the simplest way to calculate all individual values and make an arraylist from it. For example given the number 56 (i.e. Wed+Thur+Fri), how to calculate the list of individual values.
Is there a way to make the DataContractSerializer serialize a [MessageContract] the same way it appears when transmitted over SOAP?
I have a class that appears as follows on the wire for a WCF call:
<TestRequest xmlns="http://webservices.test.com/ServiceTest/1.1">
<Name>Just Me</Name>
</TestRequest>
When serializing using the DCS, it looks like this:
<TestRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance" z:Id="1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" xmlns="http://schemas.datacontract.org/2004/07/ServiceTest">
<_x003C_Name_x003E_k__BackingField z:Id="2">Just Me</_x003C_Name_x003E_k__BackingField>
</TestRequest>
I'm convinced this inconsistency is because my class is marked up as a message contract instead of a data contract:
[MessageContract]
[Serializable]
public class TestRequest
{
[MessageBodyMember]
public string Name { get; set; }
}
Is there a way to make the DCS serialize messages the same way WCF does when it creates a SOAP message?
Hey Guys,
I have a nested multimodel form right now, using Users and Profiles.
Users has_one profile, and Profile belongs_to Users.
When the form is submitted, a new user is created, and a new profile is created, but they are not linked (this is the first obvious issue). The user's model has a profile_id row, and the profile's model has a user_id row.
Here is the code for the form:
<%= form_for(@user, :url => teams_path) do |f| %>
<p><%= f.label :email %><br />
<%= f.text_field :email %></p>
<p><%= f.label :password %><br />
<%= f.password_field :password %></p>
<p><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></p>
<%= f.hidden_field :role_id, :value => @role.id %></p>
<%= f.hidden_field :company_id, :value => current_user.company_id %></p>
<%= fields_for @user.profile do |profile_fields| %>
<div class="field">
<%= profile_fields.label :first_name %><br />
<%= profile_fields.text_field :first_name %>
</div>
<div class="field">
<%= profile_fields.label :last_name %><br />
<%= profile_fields.text_field :last_name %>
</div>
<% end %>
<p><%= f.submit "Sign up" %></p>
<% end %>
A second issue, is even though the username, and password are successfully created through the form for the user model, the hidden fields (role_id & company_id - which are also links to other models) are not created (even though they are part of the model) - the values are successfully shown in the HTML for those fields however.
Any help would be great!
I came across the following program and it behaving in unexpected manner.
public class ShiftProgram
{
public static void main(String[] args)
{
int i = 0;
while(-1 << i != 0)
i++;
System.out.println(i);
}
}
If we think about this program output, when it reaches 32 while loop condition should return false and terminate and it should print 32.
If you ran this program, it does not print anything but goes into an infinite loop. Any idea whats going on? Thank you in advance.
I have a very simple properties file test I am trying to get working: (the following is TestProperties.java)
package com.example.test;
import java.util.ResourceBundle;
public class TestProperties {
public static void main(String[] args) {
ResourceBundle myResources =
ResourceBundle.getBundle("TestProperties");
for (String s : myResources.keySet())
{
System.out.println(s);
}
}
}
and TestProperties.properties in the same directory:
something=this is something
something.else=this is something else
which I have also saved as TestProperties_en_US.properties
When I run TestProperties.java from Eclipse, it can't find the properties file:
java.util.MissingResourceException:
Can't find bundle for base name TestProperties, locale en_US
Am I doing something wrong?
Why would you use such abstract? Does it speed up work or what exactly its for?
// file1.php
abstract class Search_Adapter_Abstract {
private $ch = null;
abstract private function __construct()
{
}
abstract public funciton __destruct() {
curl_close($this->ch);
}
abstract public function search($searchString,$offset,$count);
}
// file2.php
include("file1.php");
class abc extends Search_Adapter_Abstract
{
// Will the curl_close now automatically be closed?
}
What is the reason of extending abstract here? Makes me confused. What can i get from it now?
Hello All!
I have a query with grouping on one of the fields in Crystal Reports. My question is - is there a way to pass that value into a subreport?
I.e. if there are three values in that field, there will be three groups in report. I want a subreport in every group to have that value as its parameter.
Is that possible to accomplish with CR 2008?
My program
class Building {
Building() {
System.out.print("b ");
}
Building(String name) {
this();
System.out.print("bn " + name);
}
};
public class House extends Building {
House() {
System.out.print("h "); // this is line# 1
}
House(String name) {
this(); // This is line#2
System.out.print("hn " + name);
}
public static void main(String[] args) {
new House("x ");
}
}
We know that compiler will write a call to super() as the first line in the child class's constructor. Therefore should not the output be:
b (call from compiler written call to super(), before line#2
b (again from compiler written call to super(),before line#1 )
h hn x
But the output is
b h hn x
Why is that?
Im doing a program in GWT. Here is the snippet where Im having problem
private String[] populateRSSData() {
1==>> String[] data = null;
try {
new RequestBuilder(RequestBuilder.GET,
"../database.php?action=populaterss").sendRequest(null,
new RequestCallback() {
@Override
public void onResponseReceived(Request request,
Response response) {
2==>> data=response.getText().split("~");
}
@Override
public void onError(Request request, Throwable exception) {
Window.alert(exception.getMessage());
}
});
} catch (RequestException e) {
Window.alert(e.getMessage());
}
return data;
}
Now the problem arises that I get an error that the variable 1==>> data should be declared final. But if I declare it as final then i cannot store the datas in 2==>>
The error i get
Cannot refer to a non-final variable data inside an inner class defined in a different method RSS_Manager.java
Please suggest
gorup by query issue
i have one table,
which has three fields and data.
Name , Top , total
cat , 1 ,10
dog , 2, 7
cat , 3 ,20
hourse 4, 4
cat, 5,10
Dog 6 9
i want to select record which has highest value of "total" for each Name
so my result should be like this.
Name , Top , total
cat , 3 , 20
hourse , 4 , 4
Dog , 6 , 9
i tried group by name order by total, but it give top most record of group by result.
any one can guide me , please!!!!
I have one table, which has three fields and data.
Name , Top , Total
cat , 1 , 10
dog , 2 , 7
cat , 3 , 20
horse , 4 , 4
cat , 5 , 10
dog , 6 , 9
I want to select the record which has highest value of Total for each Name, so my result should be like this:
Name , Top , Total
cat , 3 , 20
horse , 4 , 4
Dog , 6 , 9
I tried group by name order by total, but it give top most record of group by result. Can anyone guide me, please?
Let's assume I have a table magazine:
CREATE TABLE magazine
(
magazine_id integer NOT NULL DEFAULT nextval(('public.magazine_magazine_id_seq'::text)::regclass),
longname character varying(1000),
shortname character varying(200),
issn character varying(9),
CONSTRAINT pk_magazine PRIMARY KEY (magazine_id)
);
And another table issue:
CREATE TABLE issue
(
issue_id integer NOT NULL DEFAULT nextval(('public.issue_issue_id_seq'::text)::regclass),
number integer,
year integer,
volume integer,
fk_magazine_id integer,
CONSTRAINT pk_issue PRIMARY KEY (issue_id),
CONSTRAINT fk_magazine_id FOREIGN KEY (fk_magazine_id)
REFERENCES magazine (magazine_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
Current INSERTS:
INSERT INTO magazine (longname,shotname,issn)
VALUES ('a long name','ee','1111-2222');
INSERT INTO issue (fk_magazine_id,number,year,volume)
VALUES (currval('magazine_magazine_id_seq'),'8','1982','6');
Now a row should only be inserted into 'magazine', if it does not already exist. However if it exists, the table 'issue' needs to get the 'magazine_id' of the row that already exists in order to establish the reference.
How can i do this?
Thx in advance!