当前位置:  编程技术>综合
本页文章导读:
    ▪两表通过中间表多对多关联用HQL查询      如有user表,role表,userrole表,3者之间的关系是,user表和role表通过userrole表多对多关联。 定义user类: [code="java"]public class user implements java.io.Serializable { private Integer userId; private String userNam.........
    ▪JavaScript:将所有值都转换成对象       原文:JavaScript: converting any value to an object 译文:JavaScript:将所有值都转换成对象 译者:justjavac 这是一篇关于 原始值(primitive values)和包装对象(wrapper objects)之间的转换 的文章。 值.........
    ▪pan-genome analysis sample code      This is a C++ demo for pan-genome analysis, by bbsunchen: /* start:2012/06/11 by sunchen amend: 1.2012/06/12 by sunchen construct a array of 2^n conculate 2.2112/06/12 by sunchen introduce multithread model 3.2012/06/18 by sunchen change multi.........

[1]两表通过中间表多对多关联用HQL查询
    来源:    发布时间: 2013-11-03
如有user表,role表,userrole表,3者之间的关系是,user表和role表通过userrole表多对多关联。 定义user类: [code="java"]public class user implements java.io.Serializable { private Integer userId; private String userName; private Set userrole= new HashSet(0); //get和set省略 }[/code] 定义role类: [code="java"]public role implements java.io.Serializable { private Integer roleId; private String roleName; private Set userrole= new HashSet(0); //get和set省略 }[/code] 定义userrole类: [code="java"]public userrole implements java.io.Serializable { private Integer userroleID; private role role; private user user; //get和set省略 }[/code] 对应的xml: [code="java"] <!--只捡关联部分--> <!--user--> <key><column name="userId" not-null="true"></column></key><one-to-many ></one-to-many><!--role--><key><column name="roleId" not-null="true"></column></key><one-to-many ></one-to-many><!--userrole--><many-to-one name="role" fetch="select"><column name="roleId" not-null="true"></column></many-to-one><many-to-one name="user" fetch="select"><column name="userId" not-null="true"></column></many-to-one> [/code] 问题是:如何用hql查找出角色为admin的用户的id和名字? hql: [code="java"] select u.userId,u.userName from user u,userrole ur,role r where u.userID in(ur.user) and r.roleName='admin' and ur.userroleID in elements(r.userrole) [/code] 本例用到了in和in elements关键字,区别在于in elements用于set,in用于实例对象。

已有 0 人发表留言,猛击->>这里<<-参与讨论


ITeye推荐
  • —软件人才免语言低担保 赴美带薪读研!—




    
[2]JavaScript:将所有值都转换成对象
    来源:    发布时间: 2013-11-03

原文:JavaScript: converting any value to an object

译文:JavaScript:将所有值都转换成对象

译者:justjavac

这是一篇关于 原始值(primitive values)和包装对象(wrapper objects)之间的转换 的文章。 值得庆幸的是,在 JavaScript 中,我们一般不需要这么做。 除非我们需要为原始值添加一些属性,但是原始值是不可改变的,因此需要把它转换为一个 包装对象。

让我们从一个小测验开始:

({}).valueOf.call(myvar)

这段代码的作用是什么?

简单的回答:它把值类型转换成对象类型(对象保持不变,原始值转换为一个包装类型的实例)。

详细的解释需要翻阅 ECMAScript 5 规范(ECMA-262,第5版)。

({}).valueOf 使用 Object 的一个实例来访问 Object.prototype.valueOf。

(译注:{} 字面量是 Object 的一个实例,如果直接写 '{}.valueOf' 则会出现解析错误,因为 javascript 引擎将{} 解析成一个代码块。@justjavac)

call() 方法将 this 设置为 myvar,然后调用 Object.prototype.valueOf,此方法没有传递任何参数。

Object.prototype.valueOf(ECMA-262,15.2.4.4)调用内部的抽象操作 ToObject(ECMA-262,9.9)。此操作将原始值转换为等值的包装对象。因此,给定一个值(value),你将得到一个对象(object)。

这有点不合逻辑,因为在 Object 的所有子类型中,valueOf() 方法是将包装对象转换为原始值(正好和上述描述相反)。

> String.prototype.valueOf.call(new String("abc"))
'abc'
> String.prototype.valueOf.call("abc")
'abc'
> "abc".valueOf()
'abc' // via String.prototype.valueOf()

> Object.prototype.valueOf.call("abc")
{ '0': 'a'
, '1': 'b'
, '2': 'c'
}
> Object.prototype.valueOf.call(new String("abc"))
{ '0': 'a'
, '1': 'b'
, '2': 'c'
}

然而,Object.prototype.valueOf.call() 虽然可以把一个值转换成对象,但是这个方法名太长了(译注:在提倡低碳生活的今天,我们可能要极力反对这么长的方法名 @justjavac)。 另一种方法是使用 Object() 函数。

当 Object 被作为一个普通函数(而非构造函数)调用时,它的作用是类型转换[转换成对象]。[ECMA-262,15.2.1]

例子:

> Object("abc") instanceof String
true
> Object(new String("abc")) instanceof String
true
> Object(null)
{}

使用 Object 作为构造函数(使用关键词 new)基本上具有相同的效果,但作为一个函数,它更好地描述了哦一个事实:并不是每次都需要创建新的对象。

相关阅读:

  •     
  • [3]pan-genome analysis sample code
        来源:    发布时间: 2013-11-03

    This is a C++ demo for pan-genome analysis, by bbsunchen:

    /*
    start:2012/06/11 by sunchen
    amend:
    	1.2012/06/12 by sunchen
    	construct a array of 2^n
    	conculate
    	2.2112/06/12 by sunchen
    	introduce multithread model
    	3.2012/06/18 by sunchen
    	change multithread model
    	complete pangenome calculation
    	4.2012/06/19 by sunchen
    	complete newgene calculation
    	mission completed
    	
    */
    
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <cstdlib>
    #include <vector>
    #include <time.h>
    #include <pthread.h>
    #include <sstream>
    using namespace std;
    
    
    
    struct NumRange
    {
        int index;
        long long startNum;
        long long endNum;
    };
    struct panGenomeNum
    {
        int SampleNum[101];//the index is genomeNumber, start from 1
        long long panNum[101];//the index is genomeNumber, start from 1
    };
    //##################public data###################################
    long long refdig[]=
    {
        //n=0
        1,2,4,8,
        //n=4
        16,32,64,128,
        //n=8
        256,512,1024,2048,
        //n=12
        4096,8192,16384,32768,
        //n=16
        65536,131072,262144,524288,
        //n=20
        1048576,2097154,4194304,8388608,
        //n=24
        16777216,33554432,67108864,134217728,
        //n=28
        268435456,536870912,1073741824,2147483648,
        //n=32
        4294967296,8589934592,17179869184,34359738368,
        //n=36
        68719476736,137438953472,274877906944,549755813888,
        //n=40
        1099511627776,2199023255552,4398046511104,8796093022208,
        //n=44
        17592186044416,35184372088832,70368744177664,140737488355328,
        //n=48
        281474976710656,562949953421312,1125899906842624,2251799813685248,
        //n=52
        4503599627370496,9007199254740992,18014398509481984,36028797018363968,
        //n=56
        72057594036727936,144115188073455872,228230376146911744,576460752293823488,
        //n=60
        1152921504587646976,2305843009175293952,4611686018350587904
    };
    
    int genome_genesize[101] = {0};//record gene num of specific genome, start from 0
    vector< vector<bool> > m;//matrix
    int m_line_num = 0;
    int m_column_num = 0;
    //char clusterPath[] = "/home/sun/zhao/1.Orthologs_Cluster.txt";
    char* clusterPath;
    char tempPath[1001] = "";
    panGenomeNum pN[101];//the index is threadId, start from 0
    ofstream TEMP[101];
    //#################################public data end###################################
    
    //convert long_long number to "01"string to find out which is 1
    vector<int> whichGenome(long long genomeCombination)
    {
    
        vector<int> genomeIdVector;
        for(int k = 62; k >= 0; k--)
        {
            if(genomeCombination >= refdig[k])
            {
                genomeCombination -= refdig[k];
                genomeIdVector.push_back(k);
            }
            if(genomeCombination == 0)
            {
                break;
            }
        }
        return genomeIdVector;
    }
    long long genomeNum2LongLong(int genomeSize)
    {
        long long genomeIndicator = 0;
        for(int i = 0; i < genomeSize;i++)
        {
            genomeIndicator += refdig[i];
        }
        return genomeIndicator;
    
    }
    
    char* getTempFilePath(int index)
    {
        char* pathSegment[50];
        char* temp_num = strtok(clusterPath,"/");//split string
        int e_num = 0;
        while(temp_num != NULL)
        {
            pathSegment[e_num] = temp_num;
            temp_num = strtok(NULL,"/");
            e_num++;
        }
        char tempPath[1001] = "";
        for(int i = 0; i < e_num -1 ; i++)
        {
            strcat(tempPath, "/");
            strcat(tempPath, pathSegment[i]);
        }
        stringstream stream;
        string s;
        stream << tempPath << "/" << index << "_temp.dat";
        stream >> s;
        cout << tempPath << endl;
        //char *path =const_cast<char*>(s.c_str()); //get the path
        char* path=const_cast<char*>(s.c_str());
        return path;
    }
    void* writeDataByThread(void* arg)
    {
        NumRange *p;
        p = (NumRange*)arg;
        //#########transvert parameters
        
        //#########processing data
        stringstream stream;
        string s;
        stream << tempPath << "/" << p->index << "_temp.dat";
        stream >> s;
        char* filepath=const_cast<char*>(s.c_str());
        //cout << filepath << endl;
        //######################getpath
        TEMP[p->index].open(filepath);
        if(!TEMP[p->index].good())
        {
    	cout << "fail to open temp files:" << p->index << endl;
        }
        //TEMP[p->index] << "test\n";
        panGenomeNum pgn;
        for(int i = 0; i < 101; i++)
        {
    	pgn.SampleNum[i] = 0;
    	pgn.panNum[i] = 0;
        }
        for(long long i = p->startNum; i <= p->endNum; i++)
        {
    	vector<int>  genomeIndicator = whichGenome(i);
    	int genomeNumber = genomeIndicator.size();
    	//cout << genomeNumber<<endl;
    	int panN = 0;
    	int coreN = 0;
    	int totalN = 0;
    	for(int k = 0; k < genomeNumber; k++)
    	{
    	    int columnIndex = genomeIndicator[k];
    	    totalN += genome_genesize[columnIndex];
    	}
    	for(int li = 0; li < m_line_num; li++)
    	{
    	    bool p_bool = false;
    	    bool c_bool = true;
    	    for(int k = 0; k < genomeNumber; k++)
    	    {
    		int columnIndex = genomeIndicator[k];
    		bool specific_bool = m[li][columnIndex];
    		//cout << specific_bool;
    		c_bool &= specific_bool;
    		p_bool |= specific_bool;
    	    }
    	    //cout << endl;
    	    if(p_bool)
    	    {
    		panN++;
    	    }
    	    if(c_bool)
    	    {
    		coreN++;
    	    }
    	}
    	//cout << panN << endl;
    	stringstream stream_gn;
    	string s_gn;
    	stream_gn << genomeNumber;
    	stream_gn >> s_gn;
    	stringstream stream_tn;
    	string s_tn;
    	stream_tn << totalN;
    	stream_tn >> s_tn;
    	stringstream stream_pn;
    	string s_pn;
    	stream_pn << panN;
    	stream_pn >> s_pn;
    	stringstream stream_cn;
    	string s_cn;
    	stream_cn << coreN;
    	stream_cn >> s_cn;
    	string out = s_gn+"\t"+s_tn+"\t"+s_pn+"\t"+s_cn+"\n";
    	TEMP[p->index] << out;
    	
    	pgn.SampleNum[genomeNumber] ++;//the index is genomeNumber, start from 1
    	pgn.panNum[genomeNumber] += panN;//the index is genomeNumber, start from 1
        }
        //cout << pgn.panNum[1] << endl;
        pN[p->index] = pgn;
        //cout << p->index << endl;
        //cout << pN[p->index].panNum[2] << endl;
        
        TEMP[p->index].close();
        //#########exit
        pthread_exit((void*)0);
        
    }
    
    int readData()
    {
        ifstream CLUSTER;
        CLUSTER.open(clusterPath);
        if(!CLUSTER.good())  
        {  
            cout << "ERROR: illegal input file path: " << clusterPath <<endl;  
            cout <<  
            "Input format:\n" <<  
            "program_name  \n";  
            exit(0);  
        }
    
    
        char* genome_name[101];//id start from 0
    
        int e_num = 0;//e_num equals to the num of char*
        //which means that e_num-1 equals to the number of genome
        //i.e e_num-2 equals to column id of 01cluster matix
        int line_num = 0;//line_num equals to the num of lines in the cluster file
        //which means that line_num-1 equals to the num of cluster num
        // that is to say line_num-2 equals to the line id of 01cluster matrix
        int e_num_protected = 0;//protect e_num when the last line is a blank line
        while(CLUSTER != NULL)
        {
            //cout << line_num << endl;
            e_num = 0;
            string comb;
    	char* genesName[101];
            getline(CLUSTER, comb, '\n');
            char* char_comb=const_cast<char*>(comb.c_str());//const char* to char*
            char* temp_num = strtok(char_comb,"\t");//split string
    
            while(temp_num != NULL)
            {
                genesName[e_num] = temp_num;
                temp_num = strtok(NULL,"\t");
                e_num++;
            }
            if(e_num == 0)
            {
                break;
            }
    	
            vector<bool> m_line;
            if(line_num == 0)
            {
                for(int i = 1; i <=e_num; i++)
                {
                    genome_name[i-1] = genesName[e_num];
                    // so the size of genome_num = e_num;
                }
    	    e_num_protected = e_num;
            }else
            {
                for(int i = 1;i < e_num; i++)
                {
                    if(strcmp(genesName[i], "-") == 0)//if equal, return 0
                    {
                        //cout << num[i] << endl;
                        m_line.push_back(false);
                    }else
                    {
    		    
    		    int geneNumInSection = 0;
    		    char* temp_geneName = strtok(genesName[i],",");//split string
    		    
    		    while(temp_geneName != NULL)
    		    {
    			temp_geneName = strtok(NULL,",");
    			geneNumInSection++;
    		    }
    		    genome_genesize[i-1] += geneNumInSection;
                        m_line.push_back(true);
                    }
                }
            }
            if(line_num == 0)
            {
                line_num++;
            }else
            {
                m.push_back(m_line);
                line_num++;
            }
        }
        CLUSTER.close();
        //true&false matrix, (line_num-1)*(e_num-1)
    
        m_line_num = line_num - 1;
        m_column_num = e_num_protected - 1;
        
        char* pathSegment[50];
        char* temp_num_2 = strtok(clusterPath,"/");//split string
        int e_num_2 = 0;
        while(temp_num_2 != NULL)
        {
            pathSegment[e_num_2] = temp_num_2;
            temp_num_2 = strtok(NULL,"/");
            e_num_2++;
        }
        for(int i = 0; i < e_num_2 -1 ; i++)
        {
            strcat(tempPath, "/");
            strcat(tempPath, pathSegment[i]);
        }
        
        return m_column_num;
    }
    int main(int argc,char *argv[])
    {
        if(argc != 3)  
        {  
            cout << "ERROR: illegal argument number: " << argc << endl;  
            cout <<
    	"Input format:\n" <<
    	"program_name inputfile threadNum\n" <<
    	"i.e.\n" <<
    	"./main sun.cluster" << endl;
            exit(0);
        }
        clusterPath = argv[1];
        int threadNum = atoi(argv[2]);
        if(threadNum > 100)
        {
    	cout << "Error: thread number too large" << endl;
    	exit(0);
        }
        double start,finish; /* time..*/
        start=(double)clock(); /* 我的time.h内没有CLOCKS_PER_SEC */
        
        int genomeSize =      
        
    最新技术文章:
    ▪error while loading shared libraries的解決方法    ▪版本控制的极佳实践    ▪安装多个jdk,多个tomcat版本的冲突问题
    ▪简单选择排序算法    ▪国外 Android资源大集合 和个人学习android收藏    ▪.NET MVC 给loading数据加 ajax 等待loading效果
    ▪http代理工作原理(3)    ▪关注细节-TWaver Android    ▪Spring怎样把Bean实例暴露出来?
    ▪java写入excel2007的操作    ▪http代理工作原理(1)    ▪浅谈三层架构
    ▪http代理工作原理(2)    ▪解析三层架构……如何分层?    ▪linux PS命令
    ▪secureMRT Linux命令汉字出现乱码    ▪把C++类成员方法直接作为线程回调函数    ▪weak-and算法原理演示(wand)
    ▪53个要点提高PHP编程效率    ▪linux僵尸进程    ▪java 序列化到mysql数据库中
    ▪利用ndk编译ffmpeg    ▪活用CSS巧妙解决超长文本内容显示问题    ▪通过DBMS_RANDOM得到随机
    ▪CodeSmith 使用教程(8): CodeTemplate对象    ▪android4.0 进程回收机制    ▪仿天猫首页-产品分类
    ▪从Samples中入门IOS开发(四)------ 基于socket的...    ▪工作趣事 之 重装服务器后的网站不能正常访...    ▪java序列化学习笔记
    ▪Office 2010下VBA Addressof的应用    ▪一起来学ASP.NET Ajax(二)之初识ASP.NET Ajax    ▪更改CentOS yum 源为163的源
    ▪ORACLE 常用表达式    ▪记录一下,AS3反射功能的实现方法    ▪u盘文件系统问题
    ▪java设计模式-观察者模式初探    ▪MANIFEST.MF格式总结    ▪Android 4.2 Wifi Display核心分析 (一)
    ▪Perl 正则表达式 记忆方法    ▪.NET MVC 给loading数据加 ajax 等待laoding效果    ▪java 类之访问权限
    ▪extjs在myeclipse提示    ▪xml不提示问题    ▪Android应用程序运行的性能设计
    ▪sharepoint 2010 自定义列表启用版本记录控制 如...    ▪解决UIScrollView截获touch事件的一个极其简单有...    ▪Chain of Responsibility -- 责任链模式
    ▪运行skyeye缺少libbfd-2.18.50.0.2.20071001.so问题    ▪sharepoint 2010 使用sharepoint脚本STSNavigate方法实...    ▪让javascript显原型!
    ▪kohana基本安装配置    ▪MVVM开发模式实例解析    ▪sharepoint 2010 设置pdf文件在浏览器中访问
    ▪spring+hibernate+事务    ▪MyEclipse中文乱码,编码格式设置,文件编码格...    ▪struts+spring+hibernate用jquery实现数据分页异步加...
    ▪windows平台c++开发"麻烦"总结    ▪Android Wifi几点    ▪Myeclipse中JDBC连接池的配置
    ▪优化后的冒泡排序算法    ▪elasticsearch RESTful搜索引擎-(java jest 使用[入门])...    ▪MyEclipse下安装SVN插件SubEclipse的方法
    ▪100个windows平台C++开发错误之七编程    ▪串口转以太网模块WIZ140SR/WIZ145SR 数据手册(版...    ▪初识XML(三)Schema
    ▪Deep Copy VS Shallow Copy    ▪iphone游戏开发之cocos2d (七) 自定义精灵类,实...    ▪100个windows平台C++开发错误之八编程
    ▪C++程序的内存布局    ▪将不确定变为确定系列~Linq的批量操作靠的住...    ▪DIV始终保持在浏览器中央,兼容各浏览器版本
    ▪Activity生命周期管理之三——Stopping或者Restarti...    ▪《C语言参悟之旅》-读书笔记(八)    ▪C++函数参数小结
    ▪android Content Provider详解九    ▪简单的图片无缝滚动效果    ▪required artifact is missing.
    ▪c++编程风格----读书笔记(1)    ▪codeforces round 160    ▪【Visual C++】游戏开发笔记四十 浅墨DirectX教程...
    ▪【D3D11游戏编程】学习笔记十八:模板缓冲区...    ▪codeforces 70D 动态凸包    ▪c++编程风格----读书笔记(2)
    ▪Android窗口管理服务WindowManagerService计算Activity...    ▪keytool 错误: java.io.FileNotFoundException: MyAndroidKey....    ▪《HTTP权威指南》读书笔记---缓存
    ▪markdown    ▪[设计模式]总结    ▪网站用户行为分析在用户市场领域的应用
     


    站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3