Permalink
Browse files

lesson 15

  • Loading branch information...
angryziber committed May 19, 2011
1 parent 39d138a commit 7f67f930c626dbced96c0fbcd04898754d8919b1
View
@@ -2,6 +2,22 @@
<project version="4">
<component name="AntConfiguration">
<defaultAnt bundledAnt="true" />
<buildFile url="file://$PROJECT_DIR$/build-demo.xml">
<additionalClassPath />
<antReference projectDefault="true" />
<customJdkName value="" />
<maximumHeapSize value="128" />
<maximumStackSize value="2" />
<properties />
</buildFile>
<buildFile url="file://$PROJECT_DIR$/build.xml">
<additionalClassPath />
<antReference projectDefault="true" />
<customJdkName value="" />
<maximumHeapSize value="128" />
<maximumStackSize value="2" />
<properties />
</buildFile>
</component>
</project>
View
@@ -37,6 +37,16 @@
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
<option name="USE_RELATIVE_INDENTS" value="false" />
</ADDITIONAL_INDENT_OPTIONS>
<ADDITIONAL_INDENT_OPTIONS fileType="jsp">
<option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
<option name="USE_RELATIVE_INDENTS" value="false" />
</ADDITIONAL_INDENT_OPTIONS>
<ADDITIONAL_INDENT_OPTIONS fileType="xml">
<option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
View
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<project name="HelloAnt" default="sayHello" basedir=".">
<property name="text.hello" value="Hello, Ant!"/>
<target name="sayHello">
<echo>${text.hello}</echo>
</target>
<target name="compile" depends="sayHello">
<javac srcdir="src" destdir="bin"/>
</target>
</project>
View
Binary file not shown.
View
BIN +307 KB lib/dom4j.jar
Binary file not shown.
View
Binary file not shown.
View
BIN +2.94 MB lib/hibernate-core.jar
Binary file not shown.
View
Binary file not shown.
View
BIN +580 KB lib/javassist.jar
Binary file not shown.
View
BIN +14.7 KB lib/jta.jar
Binary file not shown.
View
BIN +24.9 KB lib/slf4j-api.jar
Binary file not shown.
View
BIN +226 KB lib/spring-tx.jar
Binary file not shown.
@@ -2,12 +2,20 @@
public class Person {
enum Sex {M, F}
Long id;
String name;
int age;
Sex sex;
public Long getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return name + ":" + sex + ":" + age;
@@ -0,0 +1,21 @@
package net.azib.java.lessons.scripting;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.util.Date;
/**
* @author anton
*/
public class JavaScriptDemo {
public static void main(String[] args) throws ScriptException {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine js = manager.getEngineByExtension("js");
js.put("anotherDate", new Date());
js.eval("importPackage(java.util);" +
"var date = new Date();" +
"println(date.toString());" +
"println(anotherDate)");
}
}
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-access="field">
<class name="net.azib.java.lessons.db.Person" table="persons">
<id name="id">
<generator class="increment"/>
</id>
<property name="name"/>
<property name="age"/>
</class>
<query name="Person.allJohns">
from Person p where name like 'John%'
</query>
<sql-query name="Person.fromProcedure">
<return class="net.azib.java.lessons.db.Person" alias="p"/>
select {p.*} from table(get_all_people(123))
</sql-query>
</hibernate-mapping>
@@ -0,0 +1,57 @@
package net.azib.java.lessons.spring;
import net.azib.java.lessons.db.FakeDB;
import net.azib.java.lessons.db.Person;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.simple.SimpleJdbcOperations;
import org.springframework.orm.hibernate3.HibernateOperations;
import java.sql.SQLException;
import java.util.List;
/**
* @author anton
*/
public class SpringDemo {
private SimpleJdbcOperations jdbc;
private HibernateOperations hibernate;
private void doSomething() throws SQLException {
System.out.println(jdbc.queryForInt("select count(*) from persons") + " people in the DB");
Person extraPerson = new Person();
extraPerson.setName("Josh Smith");
hibernate.save(extraPerson);
System.out.println("new id: " + extraPerson.getId());
Person examplePerson = new Person();
examplePerson.setName("Josh Smith");
for (Person person : (List<Person>)hibernate.findByExample(examplePerson)) {
System.out.println(person);
}
//hibernate.findByNamedQuery("Person.allJohns");
for (Person person : hibernate.loadAll(Person.class)) {
System.out.println(person);
}
}
public void setJdbc(SimpleJdbcOperations jdbc) {
this.jdbc = jdbc;
}
public void setHibernate(HibernateOperations hibernate) {
this.hibernate = hibernate;
}
public static void main(String[] args) throws SQLException {
FakeDB.prepare();
XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("beans.xml", SpringDemo.class));
SpringDemo demo = beanFactory.getBean(SpringDemo.class);
demo.doSomething();
}
}
@@ -2,5 +2,28 @@
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean name="mainDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="url" value="jdbc:hsqldb:mem:DemoDB"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
<bean class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
<constructor-arg ref="mainDataSource"/>
</bean>
<bean id="sessionFactoryBean" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="mainDataSource"/>
<property name="mappingLocations">
<list>
<value>classpath:net/azib/java/lessons/spring/Person.hbm.xml</value>
</list>
</property>
</bean>
<bean class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactoryBean"/>
</bean>
<bean class="net.azib.java.lessons.spring.SpringDemo" autowire="byType"/>
</beans>

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,19 @@
package net.azib.java.lessons.text;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
/**
* @author anton
*/
public class UserInput {
Reader reader = new InputStreamReader(System.in);
public String askForName() throws IOException {
System.out.print("Please enter your name: ");
BufferedReader reader = new BufferedReader(this.reader);
return reader.readLine();
}
}
@@ -0,0 +1,20 @@
package net.azib.java.lessons.text;
import org.junit.Test;
import java.io.IOException;
import java.io.StringReader;
import static org.junit.Assert.assertEquals;
/**
* @author anton
*/
public class UserInputTest {
@Test
public void readName() throws IOException {
UserInput input = new UserInput();
input.reader = new StringReader("John Doe\n");
assertEquals("John Doe", input.askForName());
}
}

0 comments on commit 7f67f93

Please sign in to comment.