package railo.commons.io.res.type.datasource.core;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Map;
import java.util.WeakHashMap;

import railo.commons.date.JREDateTimeUtil;
import railo.commons.io.res.type.datasource.Attr;
import railo.runtime.db.DatasourceConnection;
import railo.runtime.engine.ThreadLocalPageContext;

public abstract class CoreSupport implements Core {
	public static final Attr ATTR_ROOT = new Attr(0,null,null,true,Attr.TYPE_DIRECTORY,0,0,(short)0777,(short)0,0);
	

	public static boolean isDirectory(int type) {
		return type==Attr.TYPE_DIRECTORY;
	}

	public static boolean isFile(int type) {
		return type==Attr.TYPE_FILE;
	}

	public static boolean isLink(int type) {
		return type==Attr.TYPE_LINK;
	}

	public static Calendar getCalendar() {
		return JREDateTimeUtil.newInstance(ThreadLocalPageContext.getTimeZone());
	}

	public static void log(String s1) {
		//aprint.out(s1);
	}
	public static void log(String s1, String s2) {
		//aprint.out(s1+";"+s2);
	}
	public static void log(String s1, String s2, String s3) {
		//aprint.out(s1+";"+s2+";"+s3);
	}
	public static void log(String s1, String s2, String s3, String s4) {
		//aprint.out(s1+";"+s2+";"+s3+";"+s4);
	}

	private Map statements=new WeakHashMap();
	
	PreparedStatement prepareStatement(DatasourceConnection dc,String sql) throws SQLException {
		PreparedStatement ps=(PreparedStatement) statements.get(sql);
		if(ps!=null && ps.getConnection()==dc.getConnection()){
			//print.out("c");
			
		}
		else{
			ps= dc.getConnection().prepareStatement(sql);
			statements.put(sql,ps);
			//print.out("n");
		}
		return ps;
	}

}

@@ -325,24 +325,206 @@
 Connection;%0A
+import railo.runtime.db.DatasourceConnectionImpl;%0Aimport railo.runtime.db.DatasourceConnectionPool;%0Aimport railo.runtime.db.DatasourceConnectionPro;%0Aimport railo.runtime.db.SQLImpl;%0A
 import railo
@@ -1446,53 +1446,8 @@
 %09%7D%0A%0A
-%09private Map statements=new WeakHashMap();%0A%09%0A
 %09Pre
@@ -1542,198 +1542,56 @@
 %7B%0A%09%09
-P
 re
-paredStatement ps=(PreparedStatement) statements.get(sql);%0A%09%09if(ps!=null && ps.getConnection()==dc.getConnection())%7B%0A%09%09%09//print.out(%22c%22);%0A%09%09%09%0A%09%09%7D%0A%09%09else%7B%0A%09%09%09ps= 
+turn ((DatasourceConnectionPro)
 dc
+)
 .get
-Connection().p
+P
 repare
+d
 Stat
@@ -1600,77 +1600,38 @@
 ent(
-sql);%0A%09%09%09statements.put(sql,ps);%0A%09%09%09//print.out(%22n%22);%0A%09%09%7D%0A%09%09return ps
+new SQLImpl(sql), false, true)
 ;%0A%09%7D

use general PS creator function