The answer is to use a “u” flag in the expression string:
$s = preg_replace('/\s/u', $s);
There will be no such thing as web development after World War III
$s = preg_replace('/\s/u', $s);
sfGuardUser
-s. To achieve this, I had to go the usual way — add a prefix to the tables.<project-name>/plugins/sfGuardPlugin/config/schema.yml
and then rebuild stuff with propel:symfony propel:build-all
symfony propel:build-sql
symfony propel:build-form
symfony propel:build-model
JdbcDaoSupport
, Spring's nice and handy JDBC tool.lib
folder, the rest in the classpath, and make a couple of modifications to web.xml
and applicationContext.xml
files.mysql-connector
, if you don't already have it).aspectjrt-1.x.jar
cglib-nodep-2.x.jar
log4j-1.x.jar
slf4j-api-1.x.jar
slf4j-log4j12-1.x.jar
spring-2.x.jar
wicket-1.3.x.jar
wicket-ioc-1.3.x.jar
wicket-spring-1.3.x.jar
wicket-spring-annot-1.3.x.jar
$CATALINA_HOME/lib
folder. Don't put them in classpath unless you've got several hours to find out why doesn't anything work.commons-logging-1.1.x.jar
ehcache-1.2.x.jar
mysql-connector-java-5.1.x-bin.jar
META-INF/context.xml
something like this:<?xml version="1.0" encoding="UTF-8"?>
<Context path="/Chicago">
<!-- database resource -->
<Resource
name="jdbc/Chicago"
auth="Container"
driverClassName="com.mysql.jdbc.Driver"
type="javax.sql.DataSource"
username="database_user"
password="database_pass"
url="jdbc:mysql://localhost/my_database"
maxWait="10000"
maxActive="60"
minIdle = "0"
maxIdle="30"
removeAbandoned="true"
removeAbandonedTimeout="120"
testOnBorrow="false"
testOnReturn="false"
testWhileIdle="true"
validationQuery="SELECT 1"
timeBetweenEvictionRunsMillis="59000"
minEvictableIdleTimeMillis="58000"
/>
</Context>
WEB-INF/applicationContext.xml
file for Spring configuration.<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/Chicago"/>
</bean>
<!-- Wicket WebApplication setup -->
<bean id="wicketApplication" class="com.mycorp.chicago.ChicagoApplication">
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="userDaoTarget" class="com.mycorp.chicago.user.JdbcUserDao">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="userDao" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager" />
<property name="proxyTargetClass" value="true"/>
<property name="target" ref="userDaoTarget" />
<property name="transactionAttributes">
<props>
<prop key="save">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="*">PROPAGATION_REQUIRED,-Exception,readOnly</prop>
</props>
</property>
</bean>
</beans>
dataSource
object which is used in JdbcDaoSupport
, to lookup database resource via JNDI;WEB-INF/web.xml
.<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Lianet Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>Spring Application Factory Filter</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
<param-name>applicationFactoryClassName</param-name>
<param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Spring Application Factory Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
</web-app>
com.mycorp.chicago.user
package./*
* UserDao.java
*/
package com.mycorp.chicago.user;
import java.io.Serializable;
/**
*
*/
public interface UserDao extends Serializable /* UserDetailsService */ {
public void test();
}
/*
* JdbcUserDao.java
*/
package com.mycorp.chicago.user;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
/**
*
*/
public class JdbcUserDao extends JdbcDaoSupport implements UserDao {
public void test() {
getJdbcTemplate().query("SELECT name FROM my_table WHERE id=1", new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
String name = rs.getString("name");
System.out.println("Got object name: " + name);
return null;
}
});
}
}
varchar
`name` fields.UserDao
in some Wicket component. Say, an index page of the app. I'll put it in the com.mycorp.chicago.web.page
package./*
* Index.java
*/
package com.mycorp.chicago.web.page;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.spring.injection.annot.SpringBean;
import com.mycorp.chicago.user.UserDao;
/**
* Main page of the application.
*/
public class IndexPage extends WebPage {
@SpringBean(name="userDao")
private UserDao userDao;
public IndexPage() {
add(new Label("sampleLabel", "This is a text which is also a model."));
userDao.test();
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<span wicket:id="sampleLabel">Sample label</span>
</body>
</html>
WebApplication
of Wicket./*
* ChicagoApplication.java
*/
package com.mycorp.chicago;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import com.mycorp.chicago.web.page.IndexPage;
/**
*
*/
public class ChicagoApplication extends WebApplication {
@Override
public Class getHomePage() {
return IndexPage.class;
}
@Override
public void init() {
super.init();
addComponentInstantiationListener(new SpringComponentInjector(this));
}
}
ClassNotFound
exception, you probably forgot to add certain library. Wicket runtime exceptions are usually easy to fix since Wicket is very verbose in development mode.
JBOSS_HOME
variable to that directory in ~/.bashrc
.jackrabbit-jca.rar
and jackrabbit-rmi.jar
from JackRabbit downloads page and jcr-1.0.jar
. concurrent.jar
.<rar-name>jackrabbit-jca.rar</rar-name>
property would contain the actual name of the rar you've downloaded (I had jackrabbit-jca-1.4.rar
) and the homeDir
property would point to the directory where you want JackRabbit to store its stuff.jackrabbit-jca.rar
, jackrabbit-rmi.jar
and jcr-ds.xml
files to $JBOSS_HOME/server/default/deploy
and jcr-1.0.jar
to $JBOSS_HOME/server/default/lib
.jcr-ds.xml
file. I tried to name it “jcr-ds-1.4.xml” and kept getting JackRabbit deployed incompletely. Once I renamed it back to “jcr-ds.xml”, everything went smoothly.$JBOSS_HOME/bin/run.sh
.private static Session getJackrabbitSession() throws RepositoryException {
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
try {
InitialContext ctx = new InitialContext(env);
ClientAdapterFactory adapter = new ClientAdapterFactory();
RemoteRepository rr;
rr = (RemoteRepository) ctx.lookup("jnp://localhost:1099/jcrServer");
Repository repository = adapter.getRepository(rr);
Credentials credJBoss = new SimpleCredentials("username", "password".toCharArray());
return repository.login(credJBoss);
} catch (NamingException ex) {
ex.printStackTrace();
}
return null;
}
jcr-1.0.jar
, jackrabbit-jcr-rmi.jar
, jnp-client.jar
and jboss-common.jar
libraries in your classpath. The latter two can be found in $JBOSS_HOME/client
and $JBOSS_HOME/lib
respectively.Session
object done.
$ sudo apt-get install python-django
/usr/share/python-support/python-django/django/contrib/admin/media
import app_one.Something
import project_one.app_one.Something
$ apt-get install freetds-dev tdsodbc php5-sybase
$ nano /etc/odbcinst.ini
[FreeTDS]
Description = FreeTDS 0.61-5 Deb
Driver = /usr/lib/odbc/libtdsodbc.so
Setup = /usr/lib/odbc/libtdsS.so
FileUsage = 1
CPTimeout = 5
CPReuse = 5
$ nano /etc/odbc.ini
[Products]
Description = Products on The MSSQL Server
Driver = FreeTDS
Servername = FSData
Database = Products
Port = 1433
$ nano /etc/rc.local
rmmod ssb
modprobe ndiswrapper
exit 0
...$ shutdown -r now
rc.local
.
auto_increment
for an id
, you often need to get this id immediately after a new instance has been created.SELECT LAST_INSERT_ID()
query. However, most of the time you want as less database requests as possible. There is a way to avoid LAST_INSERT_ID()
code using Spring's JDBC support.
final String DEF_INSERT_USER_QUERY = "insert into users (username, password) values (?,?)";
final String firstname = createdUser.getFirstname();
final String lastname = createdUser.getLastname();
KeyHolder keyHolder = new GeneratedKeyHolder();
getJdbcTemlpate().update(new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection connection)
throws SQLException {
PreparedStatement ps = connection.prepareStatement(DEF_INSERT_USER_QUERY,
new String[] {"firstname", "lastname"});
ps.setString(1, firstname);
ps.setString(2, lastname);
return ps;
}
}, keyHolder);
createdUser.setId(keyHolder.getKey().intValue());
project.properties
file and put j2ee.version=1.5
instead of 1.4
.
JdbcTemplate
and for some reason there was this exception:
java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1973)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1940)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1925)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:773)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:566)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:767)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:825)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:833)
at com.myapplication.user.JdbcUserDao.saveData(JdbcUserDao.java:511)
...
JdbcUserDao
is configured as proxy bean and saveData
method (or any other method making updates to database) is missing its PROPAGATION_REQUIRED
flag in the applicationContext.xml
.