-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: SqlArray.java
PostPosted: Wed Apr 18, 2012 8:57 am 
Newbie

Joined: Wed Apr 18, 2012 8:44 am
Posts: 5
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.netree;

import java.io.Serializable;
import java.sql.*;
import java.util.*;
import java.util.Date;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Settings;
import org.hibernate.impl.SessionFactoryImpl;


import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import java.sql.Array;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.sql.Types;

/**
*
* @author Netree
*/
public class SqlArray<T> implements Array,Serializable{

private List<T> data;
private int baseType;
private String baseTypeName = null;

protected SqlArray(List<T> data, int baseType){
this.data = data;
this.baseType = baseType;
}

protected SqlArray(List<T> data, int baseType, String baseTypeName){
this(data, baseType);
this.baseTypeName = baseTypeName;
}

@Override
public void free() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}

public static class BOOLEAN extends SqlArray<Boolean>{
public BOOLEAN(List<Boolean> data){
super(data, Types.BIT);
}
}

public static class INTEGER extends SqlArray<Integer>{
public INTEGER(List<Integer> data){
super(data, Types.INTEGER);
}
}

public static class FLOAT extends SqlArray<Float>{
public FLOAT(List<Float> data){
super(data, Types.FLOAT);
}
}

public static class DOUBLE extends SqlArray<Double>{
public DOUBLE(List<Double> data){
super(data, Types.DOUBLE);
}
}

public static class STRING extends SqlArray<String>{
public STRING(List<String> data){
super(data, Types.VARCHAR, "text");
}
}

public static class DATE extends SqlArray<Date>{
public DATE(List<Date> data){
super(data, Types.TIMESTAMP);
}
}


@Override
public String getBaseTypeName(){
if( baseTypeName != null )
return baseTypeName;
return SessionManager.getSettings().getDialect().getTypeName( baseType );



}

// public static Settings getSettings(){
//
// return ((SessionFactoryImpl)factory).getSettings();
//
// }

@Override
public int getBaseType(){
return baseType;
}

@Override
public Object getArray(){
return data.toArray();
}

@Override
public Object getArray(long index, int count){
int lastIndex = count-(int)index;
if( lastIndex > data.size() )
lastIndex = data.size();

return data.subList((int)(index-1), lastIndex).toArray();
}

@SuppressWarnings("unused")
@Override
public Object getArray(Map<String, Class<?>> arg0){
throw new UnsupportedOperationException();
}

@SuppressWarnings("unused")
@Override
public Object getArray(long arg0, int arg1, Map<String, Class<?>> arg2){
throw new UnsupportedOperationException();
}

@Override
public ResultSet getResultSet(){
throw new UnsupportedOperationException();
}

@SuppressWarnings("unused")
@Override
public ResultSet getResultSet(Map<String, Class<?>> arg0){
throw new UnsupportedOperationException();
}

@SuppressWarnings("unused")
@Override
public ResultSet getResultSet(long index, int count){
throw new UnsupportedOperationException();
}

@SuppressWarnings("unused")
@Override
public ResultSet getResultSet(long arg0, int arg1, Map<String, Class<?>> arg2){
throw new UnsupportedOperationException();
}

@Override
public String toString(){
StringBuilder result = new StringBuilder();
result.append('{');
boolean first = true;

for(T t: data){
if( first )
first = false;
else
result.append( ',' );

if( t == null ){
result.append( "null" );
continue;
}

switch( baseType ){
case Types.BIT:
case Types.BOOLEAN:
result.append(((Boolean)t).booleanValue() ? "true" : "false");
break;

case Types.INTEGER:
case Types.FLOAT:
case Types.DOUBLE:
case Types.REAL:
case Types.NUMERIC:
case Types.DECIMAL:
result.append( t );
break;

case Types.VARCHAR:
String s = (String)t;
// Escape the string
result.append('\"');
for(int p=0; p < s.length(); ++p){
char ch = s.charAt( p );
if( ch == '\0' )
throw new IllegalArgumentException( "Zero bytes may not occur in string parameters." );
if( ch == '\\' || ch == '"' )
result.append('\\');
result.append(ch);
}
result.append('\"');
break;

case Types.TIMESTAMP:
Date d = (Date)t;
result.append('\'');
appendDate(result, d);
result.append( d );
result.append('\'');
break;

default:
throw new UnsupportedOperationException("Unsupported type "+baseType+" / "+getBaseTypeName());
}
}

result.append('}');

return result.toString();
}

private static GregorianCalendar calendar = null;
protected void appendDate(StringBuilder sb, Date date){
if (calendar == null)
calendar = new GregorianCalendar();

calendar.setTime( date );

// Append Date
{
int l_year = calendar.get(Calendar.YEAR);
// always use at least four digits for the year so very
// early years, like 2, don't get misinterpreted
//
int l_yearlen = String.valueOf(l_year).length();
for(int i = 4; i > l_yearlen; i--)
sb.append("0");

sb.append(l_year);
sb.append('-');
int l_month = calendar.get(Calendar.MONTH) + 1;
if( l_month < 10 )
sb.append('0');
sb.append(l_month);
sb.append('-');
int l_day = calendar.get(Calendar.DAY_OF_MONTH);
if (l_day < 10)
sb.append('0');
sb.append(l_day);
}

sb.append(' ');

// Append Time
{
int hours = calendar.get(Calendar.HOUR_OF_DAY);
if (hours < 10)
sb.append('0');
sb.append(hours);

sb.append(':');
int minutes = calendar.get(Calendar.MINUTE);
if (minutes < 10)
sb.append('0');
sb.append(minutes);

sb.append(':');
int seconds = calendar.get(Calendar.SECOND);
if (seconds < 10)
sb.append('0');
sb.append(seconds);

if( date instanceof Timestamp ){
// Add nanoseconds.
// This won't work for postgresql versions < 7.2 which only want
// a two digit fractional second.

Timestamp t = (Timestamp) date;
char[] decimalStr = {'0', '0', '0', '0', '0', '0', '0', '0', '0'};
char[] nanoStr = Integer.toString( t.getNanos() ).toCharArray();
System.arraycopy(nanoStr, 0, decimalStr, decimalStr.length - nanoStr.length, nanoStr.length);
sb.append('.');
sb.append(decimalStr, 0, 6);
}
}

// Append Time Zone offset
{
//int offset = -(date.getTimezoneOffset());
int offset = (calendar.get(Calendar.ZONE_OFFSET)+calendar.get(Calendar.DST_OFFSET)) / (60 * 1000);
int absoff = Math.abs(offset);
int hours = absoff / 60;
int mins = absoff - hours * 60;

sb.append((offset >= 0) ? "+" : "-");

if (hours < 10)
sb.append('0');
sb.append(hours);

if (mins < 10)
sb.append('0');
sb.append(mins);
}

// Append Era
if( calendar.get(Calendar.ERA) == GregorianCalendar.BC )
sb.append(" BC");
}
}





cannot find symbol
symbol : variable SessionManager
location: class com.netree.SqlArray<T>
return SessionManager.getSettings().getDialect().getTypeName( baseType );



I am Facing this Problem.. How can I resolve this ERROR.. Please help me.

Advance Thank Q.


Top
 Profile  
 
 Post subject: Re: SqlArray.java
PostPosted: Thu Apr 19, 2012 2:20 am 
Newbie

Joined: Wed Apr 18, 2012 8:44 am
Posts: 5
cannot find symbol
symbol : method getSettings()
location: class org.eclipse.persistence.sessions.factories.SessionManager
return SessionManager.getSettings().getDialect().getTypeName( baseType );


I am facing this problem..How can I resolve this ERROR.. Could you please help me.

Advance Thanks.


Top
 Profile  
 
 Post subject: Re: SqlArray.java
PostPosted: Thu Apr 19, 2012 9:14 am 
Newbie

Joined: Wed Apr 18, 2012 9:38 am
Posts: 3
It looks like you missed a jar file in your build path. Check it.


Top
 Profile  
 
 Post subject: Re: SqlArray.java
PostPosted: Thu Apr 19, 2012 11:59 pm 
Newbie

Joined: Wed Apr 18, 2012 8:44 am
Posts: 5
Thanks for Reply..

I am Using Net beans IDE Kalyan. I set all the related jars..


Still I am getting same error..


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.